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

[pauthabielf64] Define static AUTH TLSDESC relocations #293

Open
kovdan01 opened this issue Oct 25, 2024 · 6 comments · May be fixed by #295
Open

[pauthabielf64] Define static AUTH TLSDESC relocations #293

kovdan01 opened this issue Oct 25, 2024 · 6 comments · May be fixed by #295

Comments

@kovdan01
Copy link

In pauthabielf64, dynamic AUTH TLSDESC relocation R_AARCH64_AUTH_TLSDESC is defined https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#auth-variant-got-generating-relocations.

However, the section with AUTH variant GOT-generating relocations does not contain definitions for static TLSDESC relocs: https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#auth-variant-got-generating-relocations.

Particularly, the following relocation types are missing and should be defined:

  1. R_AARCH64_AUTH_TLSDESC_ADR_PAGE21
  2. R_AARCH64_AUTH_TLSDESC_LD64_LO12
  3. R_AARCH64_AUTH_TLSDESC_ADD_LO12
@kovdan01
Copy link
Author

Tagging @smithp35 @asl

@kovdan01
Copy link
Author

kovdan01 commented Oct 25, 2024

@smithp35 I've submitted a PR to llvm-project repo adding the relocs with the following codes (the latest code for previously defined GOT-generating relocs was 0x811d) - see llvm/llvm-project#113716:

R_AARCH64_AUTH_TLSDESC_ADR_PAGE21 0x811e
R_AARCH64_AUTH_TLSDESC_LD64_LO12  0x811f
R_AARCH64_AUTH_TLSDESC_ADD_LO12   0x8120

Please let me know if these code are OK.

@smithp35
Copy link
Contributor

My apologies, I'll be out of office for the the week of 28th October to the 1st November so this is a quick response at the weekend. I'll get back to this when I'm back in the office in a week's time.

The relocation codes are OK for now [1] as they are in the private space reserved for experiments https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#5714private-and-platform-specific-relocations

The GOT signing relocations are currently in the private space. As I understand it there's a high chance that these will be needed. When they stabilise we'll need to move them to the space reserved for PAuthABI https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#5716pauthabi-relocations

What I think needs doing:

  • There are more non-auth TLSDESC relocations defined in AAELF64. Is it worth defining AUTH equivalents for these (assuming they are relevant to PAuth; I've not checked)?
  • Make sure we're happy with the names. From a glance they look fine.
  • Update the PAuthABI spec.

There's a separate topic of moving the relocations from the private experiment space.

@kovdan01
Copy link
Author

@smithp35 Thanks for your feedback!

  • There are more non-auth TLSDESC relocations defined in AAELF64. Is it worth defining AUTH equivalents for these (assuming they are relevant to PAuth; I've not checked)?

These three should be enough for working TLSDESC implementation - we have llvm codegen llvm/llvm-project#113813, lld linker llvm/llvm-project#113817 and musl dynamic loader access-softek/musl#2 patches for that, and the functionality was also tested in runtime, not only by lit tests.

It actually looks like that other non-auth TLSDESC-related relocs from this section https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#57115thread-local-storage-descriptors are not even used by llvm-project. Some of them (R_<CLS>_TLSDESC_ LD_PREL19, R_<CLS>_TLSDESC_ ADR_PREL21) seem to be intended for usage with tiny code model, for some others (R_<CLS>_TLSDESC_ OFF_G1, R_<CLS>_TLSDESC_ OFF_G0_NC) I'm not even sure what's their purpose. Anyway, the three relocs listed above should definitely be enough for "default" implementation matching existing non-auth implementation in llvm's backend.

  • Make sure we're happy with the names. From a glance they look fine.

I've just added AUTH to the following non-auth reloc names: R_<CLS>_TLSDESC_ADR_PAGE21, R_<CLS>_TLSDESC_LD64_LO12, R_<CLS>_TLSDESC_ADD_LO12. I would be happy if you double-check that it's OK :)

  • Update the PAuthABI spec.

I can submit a corresponding PR if you wish - just let me know if you want me to do that or if you plan to do it by yourself later.

@smithp35
Copy link
Contributor

smithp35 commented Nov 4, 2024

Just got back to the office today, apologies for the delay in responding.

I can post a patch to the ABI tomorrow.

Looking at the initial proposals for the relocation, the code sequences for the tiny and large code-models use these relocations. Although to the best of my knowledge both clang and GCC only implement the small code-model for accessing TLS.

I agree that we don't need to specify relocations for these until someone wants to optimise TLSDESC for the tiny code-model.

Tiny:

ldr   x1, :tlsdesc:var                        R_AARCH64_TLSDESC_LD_PREL19  var
adr   x0, :tlsdesc:var                        R_AARCH64_TLSDESC_ADR_PREL21 var
.tlsdesccall var
blr   x1                                      R_AARCH64_TLSDESC_CALL       var

Large:

# gp = register containing address of GOT.
movz  x0, #:tlsdesc_off_g1:var                R_AARCH64_TLSDESC_OFF_G1    var
movk  x0, #:tlsdesc_off_g0_nc:var             R_AARCH64_TLSDESC_OFF_G0_NC var
.tlsdescldr var
ldr   x1, [gp, x0]                            R_AARCH64_TLSDESC_LDR       var
.tlsdescadd var
add   x0, gp, x0                              R_AARCH64_TLSDESC_ADD       var
.tlsdesccall var
blr   x1                                      R_AARCH64_TLSDESC_CALL      var

smithp35 added a commit to smithp35/abi-aa that referenced this issue Nov 5, 2024
Add static Auth equivalents of the existing relocations:
* R_AARCH64_TLSDESC_ADR_PAGE21
* R_AARCH64_TLSDESC_LD64_LO12
* R_AARCH64_TLSDESC_ADD_LO12

These are sufficient to implement the small code-model for TLSDESC
using the PAuthABI. Support for the tiny and large code-model is
not implemented for the PAuthABI, or for the normal ABI in both
clang and GCC so we defer from specifiying Auth variants of all
possible relocations.

I've followed the convention that non-zero addends are not
permitted for GOT generating relocations. As each unique S+A
combination needs its own pair of GOT slots indexed by S+A and
no static linker supports that.

Fixes ARM-software#293
@smithp35
Copy link
Contributor

smithp35 commented Nov 5, 2024

I've submitted #295 for review

smithp35 added a commit to smithp35/abi-aa that referenced this issue Nov 29, 2024
Add static Auth equivalents of the existing relocations:
* R_AARCH64_TLSDESC_ADR_PAGE21
* R_AARCH64_TLSDESC_LD64_LO12
* R_AARCH64_TLSDESC_ADD_LO12

These are sufficient to implement the small code-model for TLSDESC
using the PAuthABI. Support for the tiny and large code-model is
not implemented for the PAuthABI, or for the normal ABI in both
clang and GCC so we defer from specifiying Auth variants of all
possible relocations.

I've followed the convention that non-zero addends are not
permitted for GOT generating relocations. As each unique S+A
combination needs its own pair of GOT slots indexed by S+A and
no static linker supports that.

Fixes ARM-software#293
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants