Skip to content

Commit 990e802

Browse files
committed
[MC][ELF] Do not error on parsing .debug_* section directive for MIPS
MIPS .debug_* sections should have SHT_MIPS_DWARF section type to distinguish among sections contain DWARF and ECOFF debug formats, but in assembly files these sections have SHT_PROGBITS (@progbits) type. Now assembler shows 'changed section type for ...' error when parsing `.section .debug_*,"",@progbits` directive for MIPS targets. The same problem exists for x86-64 target and this patch extends workaround implemented in D76151. The patch adds one more case when assembler ignores section types mismatch after `SwitchSection()` call. Differential Revision: https://reviews.llvm.org/D107707
1 parent fcf2d5f commit 990e802

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,23 @@ static bool hasPrefix(StringRef SectionName, StringRef Prefix) {
502502
return SectionName.startswith(Prefix) || SectionName == Prefix.drop_back();
503503
}
504504

505+
static bool allowSectionTypeMismatch(const Triple &TT, StringRef SectionName,
506+
unsigned Type) {
507+
if (TT.getArch() == Triple::x86_64) {
508+
// x86-64 psABI names SHT_X86_64_UNWIND as the canonical type for .eh_frame,
509+
// but GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't
510+
// error for SHT_PROGBITS .eh_frame
511+
return SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS;
512+
}
513+
if (TT.isMIPS()) {
514+
// MIPS .debug_* sections should have SHT_MIPS_DWARF section type to
515+
// distinguish among sections contain DWARF and ECOFF debug formats,
516+
// but in assembly files these sections have SHT_PROGBITS type.
517+
return hasPrefix(SectionName, ".debug_") && Type == ELF::SHT_PROGBITS;
518+
}
519+
return false;
520+
}
521+
505522
bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
506523
StringRef SectionName;
507524

@@ -659,11 +676,9 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
659676
getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
660677
IsComdat, UniqueID, LinkedToSym);
661678
getStreamer().SwitchSection(Section, Subsection);
662-
// x86-64 psABI names SHT_X86_64_UNWIND as the canonical type for .eh_frame,
663-
// but GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't error
664-
// for SHT_PROGBITS .eh_frame
665679
if (Section->getType() != Type &&
666-
!(SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS))
680+
!allowSectionTypeMismatch(getContext().getTargetTriple(), SectionName,
681+
Type))
667682
Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
668683
utohexstr(Section->getType()));
669684
// Check that flags are used consistently. However, the GNU assembler permits

llvm/test/MC/Mips/elf-debug-section.s

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
# RUN: llvm-mc -filetype=obj -triple=mips-linux-gnu -g %s -o - \
22
# RUN: | llvm-readobj -S - | FileCheck %s
33

4+
# MIPS .debug_* sections should have SHT_MIPS_DWARF section type
5+
# to distinguish among sections contain DWARF and ECOFF debug formats,
6+
# but in assembly files these sections have SHT_PROGBITS type.
7+
8+
.section .debug_abbrev,"",@progbits
9+
.section .debug_addr,"",@progbits
10+
.section .debug_aranges,"",@progbits
11+
.section .debug_info,"",@progbits
12+
.section .debug_line,"",@progbits
13+
.section .debug_loclists,"",@progbits
14+
.section .debug_pubnames,"",@progbits
15+
.section .debug_pubtypes,"",@progbits
16+
.section .debug_ranges,"",@progbits
17+
.section .debug_rnglists,"",@progbits
18+
.section .debug_str,"MS",@progbits,1
19+
420
# CHECK: Section {
21+
# CHECK: Name: .debug_abbrev
22+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
23+
# CHECK: Name: .debug_addr
24+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
25+
# CHECK: Name: .debug_aranges
26+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
27+
# CHECK: Name: .debug_info
28+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
529
# CHECK: Name: .debug_line
6-
# CHECK-NEXT: Type: SHT_MIPS_DWARF (0x7000001E)
30+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
31+
# CHECK: Name: .debug_loclists
32+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
33+
# CHECK: Name: .debug_pubnames
34+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
35+
# CHECK: Name: .debug_pubtypes
36+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
37+
# CHECK: Name: .debug_ranges
38+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
39+
# CHECK: Name: .debug_rnglists
40+
# CHECK-NEXT: Type: SHT_MIPS_DWARF
41+
# CHECK: Name: .debug_str
42+
# CHECK-NEXT: Type: SHT_MIPS_DWARF

0 commit comments

Comments
 (0)