mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 12:19:53 +00:00
78c4ef5120
As is described at http://llvm.org/bugs/show_bug.cgi?id=22408, the GNU linkers ld.bfd and ld.gold currently only support a subset of the whole range of AArch64 ELF TLS relocations. Furthermore, they assume that some of the code sequences to access thread-local variables are produced in a very specific sequence. When the sequence is not as the linker expects, it can silently mis-relaxe/mis-optimize the instructions. Even if that wouldn't be the case, it's good to produce the exact sequence, as that ensures that linkers can perform optimizing relaxations. This patch: * implements support for 16MiB TLS area size instead of 4GiB TLS area size. Ideally clang would grow an -mtls-size option to allow support for both, but that's not part of this patch. * by default doesn't produce local dynamic access patterns, as even modern ld.bfd and ld.gold linkers do not support the associated relocations. An option (-aarch64-elf-ldtls-generation) is added to enable generation of local dynamic code sequence, but is off by default. * makes sure that the exact expected code sequence for local dynamic and general dynamic accesses is produced, by making use of a new pseudo instruction. The patch also removes two (AArch64ISD::TLSDESC_BLR, AArch64ISD::TLSDESC_CALL) pre-existing AArch64-specific pseudo SDNode instructions that are superseded by the new one (TLSDESC_CALLSEQ). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231227 91177308-0d34-0410-b5e6-96231b3b80d8
63 lines
2.0 KiB
LLVM
63 lines
2.0 KiB
LLVM
; RUN: llc -mtriple=arm64-none-linux-gnu -verify-machineinstrs -show-mc-encoding < %s | FileCheck %s
|
|
; RUN: llc -mtriple=arm64-none-linux-gnu -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s
|
|
|
|
@initial_exec_var = external thread_local(initialexec) global i32
|
|
|
|
define i32 @test_initial_exec() {
|
|
; CHECK-LABEL: test_initial_exec:
|
|
%val = load i32, i32* @initial_exec_var
|
|
|
|
; CHECK: adrp x[[GOTADDR:[0-9]+]], :gottprel:initial_exec_var
|
|
; CHECK: ldr x[[TP_OFFSET:[0-9]+]], [x[[GOTADDR]], :gottprel_lo12:initial_exec_var]
|
|
; CHECK: mrs x[[TP:[0-9]+]], TPIDR_EL0
|
|
; CHECK: ldr w0, [x[[TP]], x[[TP_OFFSET]]]
|
|
|
|
; CHECK-RELOC: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
|
|
; CHECK-RELOC: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
|
|
|
|
ret i32 %val
|
|
}
|
|
|
|
define i32* @test_initial_exec_addr() {
|
|
; CHECK-LABEL: test_initial_exec_addr:
|
|
ret i32* @initial_exec_var
|
|
|
|
; CHECK: adrp x[[GOTADDR:[0-9]+]], :gottprel:initial_exec_var
|
|
; CHECK: ldr [[TP_OFFSET:x[0-9]+]], [x[[GOTADDR]], :gottprel_lo12:initial_exec_var]
|
|
; CHECK: mrs [[TP:x[0-9]+]], TPIDR_EL0
|
|
; CHECK: add x0, [[TP]], [[TP_OFFSET]]
|
|
|
|
; CHECK-RELOC: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
|
|
; CHECK-RELOC: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
|
|
|
|
}
|
|
|
|
@local_exec_var = thread_local(localexec) global i32 0
|
|
|
|
define i32 @test_local_exec() {
|
|
; CHECK-LABEL: test_local_exec:
|
|
%val = load i32, i32* @local_exec_var
|
|
|
|
; CHECK: mrs x[[R1:[0-9]+]], TPIDR_EL0
|
|
; CHECK: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
|
|
; CHECK: add x[[R3:[0-9]+]], x[[R2]], :tprel_lo12_nc:local_exec_var
|
|
; CHECK: ldr w0, [x[[R3]]]
|
|
|
|
; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
|
|
; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
|
|
ret i32 %val
|
|
}
|
|
|
|
define i32* @test_local_exec_addr() {
|
|
; CHECK-LABEL: test_local_exec_addr:
|
|
ret i32* @local_exec_var
|
|
|
|
; CHECK: mrs x[[R1:[0-9]+]], TPIDR_EL0
|
|
; CHECK: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
|
|
; CHECK: add x0, x[[R2]], :tprel_lo12_nc:local_exec_var
|
|
; CHECK: ret
|
|
|
|
; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
|
|
; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
|
|
}
|