[llvm-dev] [LLD][ELF] Symbol/Relocation manipulation.

Fangrui Song via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 27 09:48:05 PST 2019

On 2019-12-27, Sid Manning wrote:
>I'd like to convert the following
>call A at GDPLT  //R_HEX_GD_PLT_B22_PCREL
>call __tls_get_addr  //R_HEX_B22_PCREL
>"A" is a TLS variable and preceding code has prepared for the call.
>When the R_HEX_GD_PLT_B22_PCREL is found it will initially point to the TLS
>variable so at that point I'd like to define a __tls_get_addr symbol and update
>the relocation's type and symbol to point to it.
>Is there an existing mechanism to do this?  It would happen during relaxation I

For newer psABI, it is recommended implementing TLSDESC directly. It is
strictly superior to the traditional General Dynamic and Local Dynamic
TLS models. This applies to RISC-V
https://github.com/riscv/riscv-elf-psabi-doc/issues/94 as well, which
seems to copy from ARM or MIPS.

If you have to implement the traditional General Dynamic and Local Dynamic TLS models (__tls_get_addr):

call __tls_get_addr  //R_HEX_B22_PCREL

IMO the generated assembly should mention __tls_get_addr directly, i.e.
the assembler should create an undefined symbol __tls_get_addr and
create call-typed relocations which reference it.

The linker should not be responsible for synthesizing a symbol called
__tls_get_addr. No existing architecture (AFAIK) does this.

More information about the llvm-dev mailing list