forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Implement R_RISCV_TLSDESC for RISC-V
Support R_RISCV_TLSDESC_HI20/R_RISCV_TLSDESC_LOAD_LO12_I/R_RISCV_TLSDESC_ADD_LO12_I/R_RISCV_TLSDESC_CALL. LOAD_LO12_I/ADD_LO12_I/CALL relocations reference a label at the HI20 location, which requires special handling. We save the value of HI20 to be reused. For -no-pie/-pie links, TLSDESC to initial-exec or local-exec optimizations are eligible. Implement the relevant hooks (R_RELAX_TLS_GD_TO_LE, R_RELAX_TLS_GD_TO_IE). AUIPC/L[DW] for initial-exec uses GOT offsets, which may be adjusted in the presence of linker relaxation. ``` // TLSDESC to LE/IE optimization .Ltlsdesc_hi2: auipc a4, %tlsdesc_hi(c) # if R_RISCV_RELAX: remove; otherwise, NOP load a5, %tlsdesc_load_lo(.Ltlsdesc_hi2)(a4) # if R_RISCV_RELAX: remove; otherwise, NOP addi a0, a4, %tlsdesc_add_lo(.Ltlsdesc_hi2) jalr t0, 0(a5), %tlsdesc_call(.Ltlsdesc_hi2) add a0, a0, tp ``` * `riscv64-tlsdesc.s` is inspired by `i386-tlsdesc-gd.s` (https://reviews.llvm.org/D112582). * `riscv64-tlsdesc-relax.s` tests linker relaxation. DO NOT SUBMIT: rebase after llvm#66915 lands
- Loading branch information
Showing
5 changed files
with
492 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# REQUIRES: riscv | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o | ||
# RUN: ld.lld -shared %t.o -o %t.so | ||
# RUN: llvm-readobj -r %t.so | FileCheck %s --check-prefix=RELA | ||
|
||
## Both TLSDESC and DTPMOD64/DTPREL64 should be present. | ||
# RELA: .rela.dyn { | ||
# RELA-NEXT: 0x[[#%X,ADDR:]] R_RISCV_TLSDESC a 0x0 | ||
# RELA-NEXT: 0x[[#ADDR+16]] R_RISCV_TLS_DTPMOD64 a 0x0 | ||
# RELA-NEXT: 0x[[#ADDR+24]] R_RISCV_TLS_DTPREL64 a 0x0 | ||
# RELA-NEXT: } | ||
|
||
la.tls.gd a0,a | ||
call __tls_get_addr@plt | ||
|
||
.Ltlsdesc_hi0: | ||
auipc a2, %tlsdesc_hi(a) | ||
ld a3, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a2) | ||
addi a0, a2, %tlsdesc_add_lo(.Ltlsdesc_hi0) | ||
jalr t0, 0(a3), %tlsdesc_call(.Ltlsdesc_hi0) | ||
|
||
.section .tbss,"awT",@nobits | ||
.globl a | ||
.zero 8 | ||
a: | ||
.zero 4 |
Oops, something went wrong.