-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RISC-V psABI doesn't seem to allow relaxation of TLS GD #308
Comments
My first impression is adding a R_RISCV_PCREL_LO12_I-like relocation maybe R_RISCV_TLS_CALL_LINK which point to label, then linker will know the auipc linked with addi and call? Need inputs from all other linker hackers @MaskRay @jrtc27 @Nelson1225
|
If we have to make a change to the toolchain to fix this problem, I believe the best approach is to define TLSDESC (#94) and implement it instead, and keep the existing TLSGD as-is for backward compatibility. |
From my side, this is the right way to do. There are many PRs in the sourceware for this topic, https://sourceware.org/bugzilla/show_bug.cgi?id=27953. Just that I am not sure if we should do these while relaxing, or just do these while relocating. Maybe we also can do these while relaxing, but like the alignment relaxation that cannot be disabled.
Yeah, if there are any patterns that need to chain all the related instructions, then currently define a new relocation like pcrel_lo is the way, or refer to the corresponding symbol directly is another way (like R_RISCV_TLS_ADD). Personally I prefer the later. BTW, for this case, we will have two relocations for the call, R_RISCV_CALL_PLT and R_RISCV_TLS_CALL_LINK (label or symbol), so make sure they are both together should be necessary. |
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#global-dynamic
In TLS GD access model, the address of a thread-local variable is obtained using three instructions
However, if a linker knows the the thread-local variable's offset from
tp
, it can relax the instructions by setting the offset directly toa0
and replacescall ___tls_get_addr@plt
with a nop.The problem here is this: in this RISC-V psABI, there seems to be no way to find a
call
instruction for anauipc
with aR_RISCV_TLS_GD_HI20
relocation. It doesn't mandate that thecall
instruction immediately follow theaddi
instruction, so thecall
can be placed at any place afteraddi
(as long asa0
is preserved).As a result, it's impossible to relax TLS GD to TLS LE. All TLS accesses has to be resolved using a function call at runtime which is pretty expensive.
The text was updated successfully, but these errors were encountered: