Skip to content

Commit 1deff40

Browse files
tob2abidh
authored andcommitted
[MC][ELF] Accept abbreviated form with sh_flags and sh_entsize
D73999 / commit 75af9da 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
1 parent 4d956af commit 1deff40

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,13 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
652652
!(SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS))
653653
Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
654654
utohexstr(Section->getType()));
655-
if (Section->getFlags() != Flags)
655+
// Check that flags are used consistently. However, the GNU assembler permits
656+
// to leave out in subsequent uses of the same sections; for compatibility,
657+
// do likewise.
658+
if ((Flags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
656659
Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
657660
utohexstr(Section->getFlags()));
658-
if (Section->getEntrySize() != Size)
661+
if ((Flags || Size || !TypeName.empty()) && Section->getEntrySize() != Size)
659662
Error(loc, "changed section entsize for " + SectionName +
660663
", expected: " + Twine(Section->getEntrySize()));
661664

llvm/test/MC/ELF/section-flags-changed.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ foo:
99
# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
1010
.pushsection .foo,"a",@progbits
1111

12+
# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
13+
.section .foo,"",@progbits
14+
1215
.pushsection .foo,"ax",@progbits
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: llvm-mc -triple=x86_64 %s -o - | FileCheck %s
2+
3+
# If section flags and other attributes are omitted, don't error.
4+
5+
# CHECK: .section .foo,"aM",@progbits,1
6+
7+
.section .foo,"aM",@progbits,1
8+
9+
.section .foo
10+
11+
.pushsection .foo

0 commit comments

Comments
 (0)