Skip to content

[AArch64] Implement TLS relaxations#1213

Open
deepakshirkem wants to merge 5 commits into
qualcomm:mainfrom
deepakshirkem:fix/tls-relaxation-aarch64-1004
Open

[AArch64] Implement TLS relaxations#1213
deepakshirkem wants to merge 5 commits into
qualcomm:mainfrom
deepakshirkem:fix/tls-relaxation-aarch64-1004

Conversation

@deepakshirkem
Copy link
Copy Markdown
Contributor

@deepakshirkem deepakshirkem commented May 23, 2026

Fixes part of #1004

Implements TLS relaxations for AArch64 covering all TLS access models supported by the AArch64 ABI

Implementation follows LLD's AArch64 TLS relaxation in lld/ELF/Arch/AArch64.cpp (relaxTlsGdToLe, relaxTlsGdToIe,
relaxTlsIeToLe).

CC @parth-07 @quic-seaswara @quic-areg

Extend IE->LE relaxation in tls_gottprel_page and tls_gottprel_lo
to cover global TLS symbols in static executables. Previously only
local symbols (without ReserveGOT) were relaxed.

Fixes part of qualcomm#1004

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
Preserve destination register (Rd) when relaxing TLSDESC_LD64_LO12
to movk in static executables. Previously x0 was hardcoded.

Also extend relaxation to cover global symbols in static executables
by adding isCodeStatic() check, matching the IE->LE fix.

Fixes part of qualcomm#1004

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
…cutables

Extend TLSDESC->LE relaxation in tls_tlsdesc_page to cover global
TLS symbols in static executables by adding isCodeStatic() check.

Also fix tls_tlsdesc_lo to always use x0 for the relaxed movk
instruction, matching LLD behavior and ensuring the TLS offset
is in the correct register after relaxation.

Add test for TLSDESC->LE relaxation covering both global and
local TLS symbols.

Fixes part of qualcomm#1004

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
For PIE executables, relax TLSDESC sequences to Initial Exec (IE)
instead of keeping the expensive TLSDESC runtime resolver call.

Changes:
- scanLocalReloc/scanGlobalReloc: detect isPIE() and create IE GOT
  entry with R_AARCH64_TLS_TPREL64 dynamic relocation instead of
  TLSDESC GOT with R_AARCH64_TLSDESC
- tls_tlsdesc_lo: rewrite ldr to IE GOT load into x0 for PIE
- tls_tlsdesc_add: emit nop for PIE (matching static behavior)
- tls_call: emit nop for PIE (matching static behavior)
- Update DESC.test placeholder with correct CHECK lines
- Add TLS_DESC_PIE.test to verify TLSDESC->IE relaxation

Fixes part of qualcomm#1004

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
Add TLS_Relaxation_Verify test using real compiler-generated TLS
relocations to verify end-to-end correctness of relaxations:
- TLSDESC->LE for static executables (movz+movk+nop+nop)
- TLSDESC->IE for PIE executables (adrp+ldr+nop+nop)
- R_AARCH64_TLS_TPREL64 dynamic reloc present in PIE

Add IE_PIE test to verify IE relocations remain as GOT-indirect
adrp+ldr in PIE executables.

Fixes part of qualcomm#1004

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
@deepakshirkem deepakshirkem marked this pull request as ready for review May 27, 2026 15:01
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 this pull request may close these issues.

1 participant