[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 11:58:49 PST 2020
burnus created this revision.
burnus added reviewers: grimar, jhenderson, bd1976llvm, psmith, MaskRay.
Herald added subscribers: llvm-commits, hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
burnus requested review of this revision.
D73999 <https://reviews.llvm.org/D73999> / commit 75af9da755721123e62b45cd0bc0c5e688a9722a <https://reviews.llvm.org/rG75af9da755721123e62b45cd0bc0c5e688a9722a>
added for LLVM 10 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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92052
Files:
llvm/lib/MC/MCParser/ELFAsmParser.cpp
llvm/test/MC/ELF/section-entsize-not-repeated.s
llvm/test/MC/ELF/section-flags-changed-2.s
Index: llvm/test/MC/ELF/section-flags-changed-2.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-flags-changed-2.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
+
+foo:
+.section .foo,"ax", at progbits
+
+.section .foo
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
+.section .foo,"awx", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
+.pushsection .foo,"a", at progbits
+
+.pushsection .foo
Index: llvm/test/MC/ELF/section-entsize-not-repeated.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-entsize-not-repeated.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/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -652,10 +652,15 @@
!(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) &&
+ Section->getFlags() != Flags)
Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
utohexstr(Section->getFlags()));
- if (Section->getEntrySize() != Size)
+ if ((Flags || Size) &&
+ Section->getEntrySize() != Size)
Error(loc, "changed section entsize for " + SectionName +
", expected: " + Twine(Section->getEntrySize()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92052.307421.patch
Type: text/x-patch
Size: 2256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201124/5b6ceb69/attachment.bin>
More information about the llvm-commits
mailing list