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

Tobias Burnus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 4 03:16:38 PST 2020


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

@MaskRay: Thanks for  the review. I hope it now makes sense.

As only '.section .foobar,"", at progbits`' is kind of a new check ("" was not tested before), I kept it but added it to `section-flags-changed.s` instead of `section-entsize-changed.s`. In `section-omitted-attributes.s`, I removed the only slightly different variant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92052

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


Index: llvm/test/MC/ELF/section-omitted-attributes.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-omitted-attributes.s
@@ -0,0 +1,9 @@
+# RUN: llvm-mc -triple=x86_64 %s -o - | FileCheck %s
+
+# CHECK: .section        .foo,"aM", at progbits,1
+
+.section .foo,"aM", at progbits,1
+
+.section .foo
+
+.pushsection .foo
Index: llvm/test/MC/ELF/section-flags-changed.s
===================================================================
--- llvm/test/MC/ELF/section-flags-changed.s
+++ llvm/test/MC/ELF/section-flags-changed.s
@@ -9,4 +9,7 @@
 # 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
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -652,10 +652,13 @@
       !(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()));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92052.309504.patch
Type: text/x-patch
Size: 1974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201204/bdc060fd/attachment.bin>


More information about the llvm-commits mailing list