[llvm] 70ea15b - [MC][ELF] Fix accepting abbreviated form with sh_flags and sh_entsize

Hafiz Abid Qadeer via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 07:05:45 PST 2021


Author: Tobias Burnus
Date: 2021-01-28T14:54:43Z
New Revision: 70ea15b88953e56681b997373fb11c97eeb05c4e

URL: https://github.com/llvm/llvm-project/commit/70ea15b88953e56681b997373fb11c97eeb05c4e
DIFF: https://github.com/llvm/llvm-project/commit/70ea15b88953e56681b997373fb11c97eeb05c4e.diff

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

Followup to 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 / commit 75af9da755721123e62b45cd0bc0c5e688a9722a
  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 / commit 1deff4009e0ae661b03682901bf6932297ce7ea1
   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

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D94072

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 65ac1d6b5ba0..544d6e6ba337 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -500,6 +500,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
   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 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
       Lex();
     }
 
-    unsigned extraFlags;
-
     if (getLexer().isNot(AsmToken::String)) {
       if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
           || getLexer().isNot(AsmToken::Hash))
@@ -655,10 +654,11 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
   // 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()));
 

diff  --git a/llvm/test/MC/ELF/section-omitted-attributes.s b/llvm/test/MC/ELF/section-omitted-attributes.s
index 72b7c9121387..5f89cdabd84f 100644
--- a/llvm/test/MC/ELF/section-omitted-attributes.s
+++ b/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


        


More information about the llvm-commits mailing list