[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
Tue Jan 5 02:28:37 PST 2021


burnus created this revision.
burnus added reviewers: MaskRay, jhenderson.
Herald added subscribers: jdoerfert, hiraditya, emaste.
Herald added a reviewer: espindola.
burnus requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Followup to D92052 <https://reviews.llvm.org/D92052> as I missed an issue as shown via GCC bug https://gcc.gnu.org/PR97827, namely: (e.g.) ".rodata." implies ELF::SHF_ALLOC.

Crossref:

- D73999 <https://reviews.llvm.org/D73999> / commit 75af9da755721123e62b45cd0bc0c5e688a9722a <https://reviews.llvm.org/rG75af9da755721123e62b45cd0bc0c5e688a9722a> added for LLVM 11 a check that sh_flags and sh_entsize (and sh_type) changes are an error, in line with GNU assembler.

- D92052 <https://reviews.llvm.org/D92052> / commit 1deff4009e0ae661b03682901bf6932297ce7ea1 <https://reviews.llvm.org/rG1deff4009e0ae661b03682901bf6932297ce7ea1> permitted the abbreviated form which many assemblers accept and GCC generates: while the first .section contains the flags and entsize, subsequent sections simply contain the name without repeating entsize or flags.

However, the latter patch missed in the check that some flags are automatically set, e.g. '.rodata." implies ELF::SHF_ALLOC.

Related https://bugs.llvm.org/show_bug.cgi?id=48201


Repository:
  rG LLVM Github Monorepo

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,14 @@
 # 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
+
+.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.314544.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210105/f07e8f88/attachment.bin>


More information about the llvm-commits mailing list