[llvm-branch-commits] [llvm] 700baa0 - [MC][ELF] Accept abbreviated form with sh_flags and sh_entsize

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 14 14:32:04 PST 2020


Author: Tobias Burnus
Date: 2020-12-14T17:31:14-05:00
New Revision: 700baa009dc685a0adc5f94d258be4ae24742471

URL: https://github.com/llvm/llvm-project/commit/700baa009dc685a0adc5f94d258be4ae24742471
DIFF: https://github.com/llvm/llvm-project/commit/700baa009dc685a0adc5f94d258be4ae24742471.diff

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

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.

However, GNU assembler accepts and GCC generates an abbreviated form:
while the first .section contains the flags and entsize, subsequent
sections simply contain the name without repeating entsize or flags.

Do likewise for better compatibility.

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

Reviewed By: jhenderson, MaskRay

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

(cherry picked from commit 1deff4009e0ae661b03682901bf6932297ce7ea1)

Added: 
    llvm/test/MC/ELF/section-omitted-attributes.s

Modified: 
    llvm/lib/MC/MCParser/ELFAsmParser.cpp
    llvm/test/MC/ELF/section-flags-changed.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index e5ab13bc719d..fb8215ef2281 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -644,10 +644,13 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
       !(SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS))
     Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getType()));
-  if (Section->getFlags() != Flags)
+  // 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)
     Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getFlags()));
-  if (Section->getEntrySize() != Size)
+  if ((Flags || 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-flags-changed.s b/llvm/test/MC/ELF/section-flags-changed.s
index 65f52cc29a6d..d2964ef046d1 100644
--- a/llvm/test/MC/ELF/section-flags-changed.s
+++ b/llvm/test/MC/ELF/section-flags-changed.s
@@ -9,4 +9,7 @@ foo:
 # CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
 .pushsection .foo,"a", at progbits
 
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
+.section .foo,"", at progbits
+
 .pushsection .foo,"ax", at progbits

diff  --git a/llvm/test/MC/ELF/section-omitted-attributes.s b/llvm/test/MC/ELF/section-omitted-attributes.s
new file mode 100644
index 000000000000..72b7c9121387
--- /dev/null
+++ b/llvm/test/MC/ELF/section-omitted-attributes.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -triple=x86_64 %s -o - | FileCheck %s
+
+# If section flags and other attributes are omitted, don't error.
+
+# CHECK: .section        .foo,"aM", at progbits,1
+
+.section .foo,"aM", at progbits,1
+
+.section .foo
+
+.pushsection .foo


        


More information about the llvm-branch-commits mailing list