Skip to content

Commit 5d03745

Browse files
committed
[RISCV] Make empty name symbols SF_FormatSpecific so that llvm-symbolizer ignores them for symbolization
On RISC-V, clang emits empty name symbols used for label differences. (In GCC the symbols are typically `.L0`) After D95916, the empty name symbols can show up in llvm-symbolizer's symbolization output. They have no names and thus not useful. Set `SF_FormatSpecific` so that llvm-symbolizer will ignore them. `SF_FormatSpecific` is also used in LTO but that case should not matter. Corresponding addr2line problem: https://sourceware.org/bugzilla/show_bug.cgi?id=27585 Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D98669
1 parent f5e6182 commit 5d03745

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,15 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
728728
}
729729
if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
730730
Result |= SymbolRef::SF_Thumb;
731+
} else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
732+
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
733+
// Mark empty name symbols used for label differences.
734+
if (NameOrErr->empty())
735+
Result |= SymbolRef::SF_FormatSpecific;
736+
} else {
737+
// TODO: Actually report errors helpfully.
738+
consumeError(NameOrErr.takeError());
739+
}
731740
}
732741

733742
if (ESym->st_shndx == ELF::SHN_UNDEF)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# REQUIRES: riscv-registered-target
2+
## Ignore empty name symbols.
3+
4+
# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t
5+
# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYM
6+
7+
# SYM: 0000000000000004 0 NOTYPE LOCAL DEFAULT [[#]] {{$}}
8+
# SYM: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [[#]] foo
9+
10+
## Make sure we test at an address larger than or equal to an empty name symbol.
11+
# RUN: llvm-symbolizer --obj=%t 0 4 | FileCheck %s
12+
13+
# CHECK: foo
14+
# CHECK-NEXT: ??:0:0
15+
# CHECK-EMPTY:
16+
# CHECK-NEXT: foo
17+
# CHECK-NEXT: ??:0:0
18+
19+
.globl foo
20+
foo:
21+
nop
22+
.file 1 "/tmp" "a.s"
23+
.loc 1 1 0
24+
nop
25+
26+
.section .debug_line,"",@progbits

0 commit comments

Comments
 (0)