[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
Tue Nov 24 23:41:09 PST 2020


burnus updated this revision to Diff 307520.
burnus added a comment.
Herald added a subscriber: jdoerfert.

Address review comments.

I also added the example from https://sourceware.org/pipermail/binutils/2020-March/110441.html for which the previous patch gave (as with GNU as) no error:
`.section .foo,"", at progbits; .byte 2`

I fixed that example by using: `(Flags || Size || !TypeName.empty()) &&`. However, to handle even more, some boolean flag needs to be set during the parsing, which I didn't do (and seems to be overly complex just for diagnostics).


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-entsize-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,21 @@
+# RUN: llvm-mc -triple=x86_64 %s -o - | FileCheck %s
+
+// CHECK: .section        .foo,"aM", at progbits,1
+// CHECK: .section        .bar,"aM", at progbits,4
+
+foo:
+.section .foo,"aM", at progbits,1
+
+.section .foo
+
+.pushsection .foo
+
+.pushsection .foo
+
+.section .bar,"aM", at progbits,4
+
+.section .bar
+
+.pushsection .bar,"aM", at progbits,4
+
+.pushsection .bar
Index: llvm/test/MC/ELF/section-entsize-changed.s
===================================================================
--- llvm/test/MC/ELF/section-entsize-changed.s
+++ llvm/test/MC/ELF/section-entsize-changed.s
@@ -10,3 +10,26 @@
 .pushsection .foo,"aM", at progbits,4
 
 .pushsection .foo,"aM", at progbits,1
+
+
+bar:
+.section .bar,"ax", at progbits
+
+.section .bar
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .bar, expected: 0x6
+.section .bar,"awx", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .bar, expected: 0x6
+.pushsection .bar,"a", at progbits
+
+.pushsection .bar
+
+foobar:
+.section .foobar,"ax", at progbits; .byte 1
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foobar, expected: 0x6
+.section .foobar,"", at progbits; .byte 2
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foobar, expected: 0x6
+.section .foobar,"a", at progbits; .byte 3
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.307520.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201125/9670f382/attachment.bin>


More information about the llvm-commits mailing list