mold icon indicating copy to clipboard operation
mold copied to clipboard

RV64: Implement TLS relaxation

Open rui314 opened this issue 3 years ago • 9 comments

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.

rui314 avatar Apr 25 '22 02:04 rui314

Hi Rui,

I would like to implement this but it may take some time as I am not familiar with the ELF TLS model.

ksco avatar Sep 02 '22 01:09 ksco

Sure. I'll assign this bug to you to avoid duplicate effort. Feel free to ask any questions.

rui314 avatar Sep 02 '22 02:09 rui314

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

ksco avatar Sep 02 '22 08:09 ksco

TLS is super tricky. I don't know what's wrong, let me take a look.

rui314 avatar Sep 02 '22 08:09 rui314

I fixed the issue in the above commit.

rui314 avatar Sep 02 '22 09:09 rui314

That's amazing!

ksco avatar Sep 02 '22 10:09 ksco

I think this is done since we already handled the Thread-pointer Relaxation, right?

ksco avatar Sep 04 '22 08:09 ksco

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.

rui314 avatar Sep 04 '22 08:09 rui314

Oh, seems they're gonna add this mechanism after spec 1.0 is released, so I think I'll just wait till that happens.

ksco avatar Sep 04 '22 08:09 ksco

TLSDESC for RISC-V has now been ratified, and we've implement it to mold. I think we can close this issue now.

rui314 avatar Sep 30 '23 03:09 rui314