mold
mold copied to clipboard
RV64: Implement TLS relaxation
mold currently doesn't relax any TLS relocations at all. We should implement GD → LE and LD → LE relaxations just like we did to x86-64.
Hi Rui,
I would like to implement this but it may take some time as I am not familiar with the ELF TLS model.
Sure. I'll assign this bug to you to avoid duplicate effort. Feel free to ask any questions.
Firstly, I'm trying to open all the tls-* tests for RV32 and RV64 and everything works fine except for one issue.
In tls-gd.sh, in the end, we are trying to statically link the three PIC object files together. In this very case, the output becomes 0 2 0 0 0 0 instead of the expected 1 2 3 4 5 6, I haven't found the reason yet.
https://github.com/ksco/mold/commit/ac878cb8ce615c101304c74139238eb3e893d894#diff-8d8a35fafde296bbdfcf817940e5559dc0fb2a1bc4aaea5822870253cdbaac74R68
TLS is super tricky. I don't know what's wrong, let me take a look.
I fixed the issue in the above commit.
That's amazing!
I think this is done since we already handled the Thread-pointer Relaxation, right?
By TLS relaxation, I meant conversion of General Dynamic → Local Exec and Local Dynamic → Local Exec, and not the RISC-V-specific %tp optimization. But I found that the RISC-V psABI lacks a mechanism to allow GD → LD (https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/308), so maybe this is infeasible. It's a spec bug, though.
Oh, seems they're gonna add this mechanism after spec 1.0 is released, so I think I'll just wait till that happens.
TLSDESC for RISC-V has now been ratified, and we've implement it to mold. I think we can close this issue now.