1// Test checks that BOLT can process binaries with TLS relocations
2
3__thread struct str {
4 int a;
5 int b;
6} tbssstruct = {}, tdatastruct = {4, 2};
7
8extern __thread struct str extstruct;
9
10extern void processAddr(volatile void *);
11
12int main() {
13 // R_AARCH64_TLSDESC_ADR_PAGE21 and R_AARCH64_TLSDESC_LD64_LO12_NC are
14 // produced for pie binaries in all cases below.
15
16 // The R_TLSLE_ADD_TPREL_HI12 and R_TLSLE_ADD_TPREL_LO12_NC for
17 // relocations in .tbss and .tdata
18 processAddr(&tbssstruct.b);
19 processAddr(&tdatastruct.b);
20
21 // The R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 and
22 // R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC relocations
23 processAddr(&extstruct.b);
24}
25
26// REQUIRES: system-linux
27// RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q \
28// RUN: -Wl,--unresolved-symbols=ignore-all \
29// RUN: -fuse-ld=lld \
30// RUN: -nostdlib
31// RUN: llvm-bolt %t.exe -o %t.bolt
32// RUN: %clang %cflags -fPIC -pie %s -o %t_pie.exe -Wl,-q \
33// RUN: -Wl,--unresolved-symbols=ignore-all \
34// RUN: -target aarch64-linux -fuse-ld=lld \
35// RUN: -nostdlib
36// RUN: llvm-bolt %t_pie.exe -o %t.bolt
37

source code of bolt/test/AArch64/tls.c