From 5d037458a318db4a15a7732513ab7d88bde04dc6 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 16 Mar 2021 14:12:18 -0700 Subject: [PATCH] [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 --- llvm/include/llvm/Object/ELFObjectFile.h | 9 ++++++++ .../Symbolize/ELF/riscv-empty-name-symbol.s | 26 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 llvm/test/DebugInfo/Symbolize/ELF/riscv-empty-name-symbol.s diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h index fd93ed4..f4d7a2e 100644 --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -728,6 +728,15 @@ Expected ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const { } if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1) Result |= SymbolRef::SF_Thumb; + } else if (EF.getHeader().e_machine == ELF::EM_RISCV) { + if (Expected NameOrErr = getSymbolName(Sym)) { + // Mark empty name symbols used for label differences. + if (NameOrErr->empty()) + Result |= SymbolRef::SF_FormatSpecific; + } else { + // TODO: Actually report errors helpfully. + consumeError(NameOrErr.takeError()); + } } if (ESym->st_shndx == ELF::SHN_UNDEF) diff --git a/llvm/test/DebugInfo/Symbolize/ELF/riscv-empty-name-symbol.s b/llvm/test/DebugInfo/Symbolize/ELF/riscv-empty-name-symbol.s new file mode 100644 index 0000000..1e0fa8a --- /dev/null +++ b/llvm/test/DebugInfo/Symbolize/ELF/riscv-empty-name-symbol.s @@ -0,0 +1,26 @@ +# REQUIRES: riscv-registered-target +## Ignore empty name symbols. + +# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t +# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYM + +# SYM: 0000000000000004 0 NOTYPE LOCAL DEFAULT [[#]] {{$}} +# SYM: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [[#]] foo + +## Make sure we test at an address larger than or equal to an empty name symbol. +# RUN: llvm-symbolizer --obj=%t 0 4 | FileCheck %s + +# CHECK: foo +# CHECK-NEXT: ??:0:0 +# CHECK-EMPTY: +# CHECK-NEXT: foo +# CHECK-NEXT: ??:0:0 + +.globl foo +foo: + nop + .file 1 "/tmp" "a.s" + .loc 1 1 0 + nop + +.section .debug_line,"",@progbits -- 2.7.4