Skip to content

Commit

Permalink
[MC][ELF] Accept abbreviated form with sh_flags and sh_entsize
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tob2 authored and abidh committed Dec 11, 2020
1 parent 4d956af commit 1deff40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions llvm/lib/MC/MCParser/ELFAsmParser.cpp
Expand Up @@ -652,10 +652,13 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
!(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()));

Expand Down
3 changes: 3 additions & 0 deletions llvm/test/MC/ELF/section-flags-changed.s
Expand Up @@ -9,4 +9,7 @@ foo:
# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
.pushsection .foo,"a",@progbits

# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6
.section .foo,"",@progbits

.pushsection .foo,"ax",@progbits
11 changes: 11 additions & 0 deletions llvm/test/MC/ELF/section-omitted-attributes.s
@@ -0,0 +1,11 @@
# RUN: llvm-mc -triple=x86_64 %s -o - | FileCheck %s

# If section flags and other attributes are omitted, don't error.

# CHECK: .section .foo,"aM",@progbits,1

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

.section .foo

.pushsection .foo

0 comments on commit 1deff40

Please sign in to comment.