Skip to content

Commit bf60953

Browse files
committed
[MC][X86] Allow SHT_PROGBITS for .eh_frame on x86-64
GNU as emits SHT_PROGBITS .eh_frame by default for .cfi_* directives. We follow x86-64 psABI and use SHT_X86_64_UNWIND for .eh_frame Don't error for SHT_PROGBITS .eh_frame on x86-64. This keeps compatibility with `.section .eh_frame,"a",@progbits` in existing assembly files. See https://groups.google.com/d/msg/x86-64-abi/7sr4E6THl3g/zUU2UPHOAQAJ for more discussions. Reviewed By: joerg Differential Revision: https://reviews.llvm.org/D76151
1 parent 2e94a64 commit bf60953

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,11 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
637637
MCSectionELF *Section = getContext().getELFSection(
638638
SectionName, Type, Flags, Size, GroupName, UniqueID, LinkedToSym);
639639
getStreamer().SwitchSection(Section, Subsection);
640-
if (Section->getType() != Type)
640+
// x86-64 psABI names SHT_X86_64_UNWIND as the canonical type for .eh_frame,
641+
// but GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't error
642+
// for SHT_PROGBITS .eh_frame
643+
if (Section->getType() != Type &&
644+
!(SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS))
641645
Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
642646
utohexstr(Section->getType()));
643647
if (Section->getFlags() != Flags)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
.pushsection .foo,"a",@nobits
1010

1111
.pushsection .foo,"a",@progbits
12+
13+
## GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't error.
14+
.section .eh_frame,"a",@progbits
15+
.section .eh_frame,"a",@unwind
16+
.pushsection .eh_frame,"a",@progbits
17+
18+
# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section type for .eh_frame, expected: 0x70000001
19+
.section .eh_frame,"a",@nobits

0 commit comments

Comments
 (0)