aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-04-24 16:25:45 -0700
committerFangrui Song <i@maskray.me>2024-04-24 16:25:45 -0700
commitb9f2c16b50f68c978e90190f46a7c0db3f39e98c (patch)
tree44d67b06eefd8a17ebca6ebc2c5360c7167a63ea /llvm/lib/MC/ELFObjectWriter.cpp
parent4c8ec8f8bc3fb4dda4fd36c3b2ad745bd3451970 (diff)
downloadllvm-b9f2c16b50f68c978e90190f46a7c0db3f39e98c.zip
llvm-b9f2c16b50f68c978e90190f46a7c0db3f39e98c.tar.gz
llvm-b9f2c16b50f68c978e90190f46a7c0db3f39e98c.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.cpp6
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) {