Skip to content

Commit

Permalink
[MCParser] Reject processor-specific section flags not known by the c…
Browse files Browse the repository at this point in the history
…urrent target

Catch accidentally used flags and match MCSectionELF.cpp
`MCSectionELF::printSwitchToSection`.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D148386
  • Loading branch information
MaskRay committed Apr 14, 2023
1 parent 3e55950 commit a4ad6a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/lib/MC/MCParser/ELFAsmParser.cpp
Expand Up @@ -317,15 +317,23 @@ static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr,
flags |= ELF::SHF_TLS;
break;
case 'c':
if (TT.getArch() != Triple::xcore)
return -1U;
flags |= ELF::XCORE_SHF_CP_SECTION;
break;
case 'd':
if (TT.getArch() != Triple::xcore)
return -1U;
flags |= ELF::XCORE_SHF_DP_SECTION;
break;
case 'y':
if (!(TT.isARM() || TT.isThumb()))
return -1U;
flags |= ELF::SHF_ARM_PURECODE;
break;
case 's':
if (TT.getArch() != Triple::hexagon)
return -1U;
flags |= ELF::SHF_HEX_GPREL;
break;
case 'G':
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/MC/ELF/section-flags-unknown.s
@@ -0,0 +1,14 @@
## Some section flags are processor-specific. Reject them for other targets.
# RUN: not llvm-mc -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:

# CHECK: {{.*}}.s:[[# @LINE+1]]:34: error: unknown flag
.section XCORE_SHF_CP_SECTION,"c",@progbits

# CHECK: {{.*}}.s:[[# @LINE+1]]:34: error: unknown flag
.section XCORE_SHF_CP_SECTION,"d",@progbits

# CHECK: {{.*}}.s:[[# @LINE+1]]:27: error: unknown flag
.section SHF_HEX_GPREL,"s",@progbits

# CHECK: {{.*}}.s:[[# @LINE+1]]:30: error: unknown flag
.section SHF_ARM_PURECODE,"y",@progbits

0 comments on commit a4ad6a3

Please sign in to comment.