[lld] [lld][Hexagon] Fix TLS GD PLT to only create PLT entry for __tls_get_addr (PR #180297)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 19:19:39 PST 2026
================
@@ -978,7 +978,25 @@ void RelocScan::process(RelExpr expr, RelType type, uint64_t offset,
sym.setFlags(NEEDS_GOT | NEEDS_GOT_NONAUTH);
}
} else if (needsPlt(expr)) {
- sym.setFlags(NEEDS_PLT);
+ // For Hexagon TLS GD PLT relocations (call foo at GDPLT), the PLT entry should
+ // be for __tls_get_addr, not the TLS symbol. Create __tls_get_addr here
+ // with NEEDS_PLT so its PLT entry is created during postScanRelocations.
+ // hexagonTLSSymbolUpdate() will rebind the relocations later.
+ if (ctx.arg.emachine == EM_HEXAGON && sym.isTls() &&
+ (type == R_HEX_GD_PLT_B22_PCREL || type == R_HEX_GD_PLT_B22_PCREL_X ||
+ type == R_HEX_GD_PLT_B32_PCREL_X)) {
+ Symbol *s = ctx.symtab->find("__tls_get_addr");
+ if (!s) {
+ s = ctx.symtab->addSymbol(Undefined{ctx.internalFile, "__tls_get_addr",
----------------
MaskRay wrote:
Relocation scanning is parallel, so adding a symbol to `ctx.symtab` is unsafe.
If you need custom logic, do it in Hexagon.cpp instead of in this generic code. I've created #181596 to isolate target-specific special cases.
https://github.com/llvm/llvm-project/pull/180297
More information about the llvm-commits
mailing list