Skip to content

Commit

Permalink
[MC][ELF] Fix accepting abbreviated form with Type change
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tob2 authored and abidh committed Nov 30, 2021
1 parent 6e2aecd commit c01c62c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/MC/MCParser/ELFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,14 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
IsComdat, UniqueID, LinkedToSym);
getStreamer().SwitchSection(Section, Subsection);
if (Section->getType() != Type &&
// 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 (!TypeName.empty() && Section->getType() != Type &&
!allowSectionTypeMismatch(getContext().getTargetTriple(), SectionName,
Type))
Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
utohexstr(Section->getType()));
// 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 ((extraFlags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
utohexstr(Section->getFlags()));
Expand Down
5 changes: 5 additions & 0 deletions llvm/test/MC/ELF/section-omitted-attributes.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# CHECK: .section .foo,"aM",@progbits,1
# CHECK: .section .rodata.cst8,"aM",@progbits,8
# CHECK: .section .lds_bss,"w",@nobits

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

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

.section .rodata.cst8

# Likewise for Type changes
.section .lds_bss,"w",@nobits
.section .lds_bss

0 comments on commit c01c62c

Please sign in to comment.