[PATCH] D94072: [MC][ELF] Fix accepting abbreviated form with sh_flags and sh_entsize

Tobias Burnus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 27 06:11:53 PST 2021


burnus updated this revision to Diff 319549.
burnus added a comment.

**Change:** Add comment line to `test/MC/ELF/section-omitted-attributes.s`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94072/new/

https://reviews.llvm.org/D94072

Files:
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/test/MC/ELF/section-omitted-attributes.s


Index: llvm/test/MC/ELF/section-omitted-attributes.s
===================================================================
--- llvm/test/MC/ELF/section-omitted-attributes.s
+++ llvm/test/MC/ELF/section-omitted-attributes.s
@@ -3,9 +3,15 @@
 # If section flags and other attributes are omitted, don't error.
 
 # CHECK: .section        .foo,"aM", at progbits,1
+# CHECK: .section        .rodata.cst8,"aM", at progbits,8
 
 .section .foo,"aM", at progbits,1
 
 .section .foo
 
 .pushsection .foo
+
+# Likewise, except that the '.rodata' prefix implies SHF_ALLOC
+.section .rodata.cst8,"aM", at progbits,8
+
+.section .rodata.cst8
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -500,6 +500,7 @@
   int64_t Size = 0;
   StringRef GroupName;
   unsigned Flags = 0;
+  unsigned extraFlags = 0;
   const MCExpr *Subsection = nullptr;
   bool UseLastGroup = false;
   MCSymbolELF *LinkedToSym = nullptr;
@@ -532,8 +533,6 @@
       Lex();
     }
 
-    unsigned extraFlags;
-
     if (getLexer().isNot(AsmToken::String)) {
       if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
           || getLexer().isNot(AsmToken::Hash))
@@ -655,10 +654,11 @@
   // Check that flags are used consistently. However, the GNU assembler permits
   // to leave out in subsequent uses of the same sections; for compatibility,
   // do likewise.
-  if ((Flags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
+  if ((extraFlags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
     Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getFlags()));
-  if ((Flags || Size || !TypeName.empty()) && Section->getEntrySize() != Size)
+  if ((extraFlags || Size || !TypeName.empty()) &&
+      Section->getEntrySize() != Size)
     Error(loc, "changed section entsize for " + SectionName +
                    ", expected: " + Twine(Section->getEntrySize()));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94072.319549.patch
Type: text/x-patch
Size: 2077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210127/a173570b/attachment.bin>


More information about the llvm-commits mailing list