Skip to content
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

RV64: Implement TLS relaxation #461

Closed
rui314 opened this issue Apr 25, 2022 · 10 comments
Closed

RV64: Implement TLS relaxation #461

rui314 opened this issue Apr 25, 2022 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@rui314
Copy link
Owner

rui314 commented Apr 25, 2022

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 rui314 added the enhancement New feature or request label Apr 25, 2022
@ksco
Copy link
Contributor

ksco commented Sep 2, 2022

Hi Rui,

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

@rui314
Copy link
Owner Author

rui314 commented Sep 2, 2022

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

@ksco
Copy link
Contributor

ksco commented Sep 2, 2022

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.

ksco@ac878cb#diff-8d8a35fafde296bbdfcf817940e5559dc0fb2a1bc4aaea5822870253cdbaac74R68

@rui314
Copy link
Owner Author

rui314 commented Sep 2, 2022

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

rui314 added a commit that referenced this issue Sep 2, 2022
For RISC-V, DTPOFF is computed 0x800 off from the start of each TLS block
to maximize the accessible range for memory access instructions with
signed 12-bit immediate. DTPMOD is usually computed by the dynamic loader,
but when we do for static binaries, we need to subtract 0x800 to offset
the offset.

#461
@rui314
Copy link
Owner Author

rui314 commented Sep 2, 2022

I fixed the issue in the above commit.

@ksco
Copy link
Contributor

ksco commented Sep 2, 2022

That's amazing!

@ksco
Copy link
Contributor

ksco commented Sep 4, 2022

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

@rui314
Copy link
Owner Author

rui314 commented Sep 4, 2022

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 (riscv-non-isa/riscv-elf-psabi-doc#308), so maybe this is infeasible. It's a spec bug, though.

@ksco
Copy link
Contributor

ksco commented Sep 4, 2022

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

@rui314
Copy link
Owner Author

rui314 commented Sep 30, 2023

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

@rui314 rui314 closed this as completed Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants