Skip to content

Commit 5932c00

Browse files
tob2MaskRay
authored andcommitted
[MC][ELF] Fix accepting abbreviated form with Type change
Follow up to D92052 and D94072, exposed due to D107707 Many assemblers to permit that only the first .section contains all the attributes like '.lds_bss,"w",@nobits' and later section only use the name ('.lds_bss') inheriting those attributes from the first section. I turned out that the case that Type changed was missed when implementing it - and D107707 make it much more likely to hit that issue. That's fixed by this commit. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D114717 (cherry picked from commit c01c62c)
1 parent 2927649 commit 5932c00

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,14 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
676676
getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
677677
IsComdat, UniqueID, LinkedToSym);
678678
getStreamer().SwitchSection(Section, Subsection);
679-
if (Section->getType() != Type &&
679+
// Check that flags are used consistently. However, the GNU assembler permits
680+
// to leave out in subsequent uses of the same sections; for compatibility,
681+
// do likewise.
682+
if (!TypeName.empty() && Section->getType() != Type &&
680683
!allowSectionTypeMismatch(getContext().getTargetTriple(), SectionName,
681684
Type))
682685
Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
683686
utohexstr(Section->getType()));
684-
// Check that flags are used consistently. However, the GNU assembler permits
685-
// to leave out in subsequent uses of the same sections; for compatibility,
686-
// do likewise.
687687
if ((extraFlags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
688688
Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
689689
utohexstr(Section->getFlags()));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# CHECK: .section .foo,"aM",@progbits,1
66
# CHECK: .section .rodata.cst8,"aM",@progbits,8
7+
# CHECK: .section .lds_bss,"w",@nobits
78

89
.section .foo,"aM",@progbits,1
910

@@ -15,3 +16,7 @@
1516
.section .rodata.cst8,"aM",@progbits,8
1617

1718
.section .rodata.cst8
19+
20+
# Likewise for Type changes
21+
.section .lds_bss,"w",@nobits
22+
.section .lds_bss

0 commit comments

Comments
 (0)