diff options
author | Fangrui Song <i@maskray.me> | 2024-04-24 13:16:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 13:16:02 -0700 |
commit | 96c45a7fa12619c3abd6b81effe4c80f0916b78b (patch) | |
tree | 21a236905743cfb4af1ff6e6bcaa4de03c7ede69 /llvm/lib/MC/ELFObjectWriter.cpp | |
parent | 13188bcd9f748dee13cf848340833f6eec2d90d4 (diff) | |
download | llvm-96c45a7fa12619c3abd6b81effe4c80f0916b78b.zip llvm-96c45a7fa12619c3abd6b81effe4c80f0916b78b.tar.gz llvm-96c45a7fa12619c3abd6b81effe4c80f0916b78b.tar.bz2 |
[MC] Rename temporary symbols of empty name to ".L0 " (#89693)
Temporary symbols generated for .eh_frame and .debug_line have an empty
name, which appear in .symtab in the presence of RISC-V style linker
relaxation and will not be discarded by ld/objcopy --discard-locals
(-X).
In contrast, GNU assembler's riscv port assigns a fake name ".L0 " (with
a trailing space) to these symbols so that will be discarded by
ld/objcopy --discard-locals.
This patch matches the GNU behavior. Since Clang's RISC-V targets pass
-X to ld, and GNU ld defaults to -X for RISC-V targets, these ".L0 "
symbols will be discarded after linking by default, as expected by
users.
The llvm-symbolizer special case for RISC-V `SF_FormatSpecific` symbols
https://reviews.llvm.org/D98669 needs to be adjusted.
Note: `"":` in assembly currently crashes.
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 005521ba..b8ef265 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -725,7 +725,13 @@ void ELFWriter::computeSymbolTable( HasLargeSectionIndex = true; } + // Temporary symbols generated for certain assembler features (.eh_frame, + // .debug_line) of an empty name may be referenced by relocations due to + // linker relaxation. Rename them to ".L0 " to match the gas fake label name + // and allow ld/objcopy --discard-locals to discard such symbols. StringRef Name = Symbol.getName(); + if (Name.empty()) + Name = ".L0 "; // Sections have their own string table if (Symbol.getType() != ELF::STT_SECTION) { |