Fangrui Song | b6772b8 | 2018-06-26 22:20:04 | [diff] [blame] | 1 | // REQUIRES: arm |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 2 | // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 3 | // RUN: ld.lld %t.o -o %t.so -shared |
Fangrui Song | b159906 | 2019-05-01 05:49:01 | [diff] [blame] | 4 | // RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 5 | // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 6 | |
| 7 | // Test the handling of the global-dynamic TLS model. Dynamic Loader finds |
| 8 | // module index R_ARM_TLS_DTPMOD32 and the offset within the module |
| 9 | // R_ARM_TLS_DTPOFF32. One of the variables is hidden which permits relaxation |
| 10 | // to local dynamic |
| 11 | |
| 12 | .text |
| 13 | .syntax unified |
| 14 | .globl func |
| 15 | .p2align 2 |
| 16 | .type func,%function |
| 17 | func: |
| 18 | .L0: |
| 19 | nop |
| 20 | .L1: |
| 21 | nop |
| 22 | .L2: |
| 23 | nop |
| 24 | |
| 25 | .p2align 2 |
| 26 | // Generate R_ARM_TLS_GD32 relocations |
| 27 | // Allocates a pair of GOT entries dynamically relocated by R_ARM_TLS_DTPMOD32 |
| 28 | // and R_ARM_TLS_DTPOFF32 respectively. The literal contains the offset of the |
| 29 | // first GOT entry from the place |
| 30 | .Lt0: .word x(TLSGD) + (. - .L0 - 8) |
| 31 | .Lt1: .word y(TLSGD) + (. - .L1 - 8) |
| 32 | .Lt2: .word z(TLSGD) + (. - .L2 - 8) |
| 33 | |
| 34 | // __thread int x = 10 |
| 35 | // __thread int y; |
| 36 | // __thread int z __attribute((visibility("hidden"))) |
| 37 | |
| 38 | .hidden z |
| 39 | .globl z |
| 40 | .globl y |
| 41 | .globl x |
| 42 | |
| 43 | .section .tbss,"awT",%nobits |
| 44 | .p2align 2 |
| 45 | .TLSSTART: |
| 46 | .type z, %object |
| 47 | z: |
| 48 | .space 4 |
| 49 | .type y, %object |
| 50 | y: |
| 51 | .space 4 |
| 52 | .section .tdata,"awT",%progbits |
| 53 | .p2align 2 |
| 54 | .type x, %object |
| 55 | x: |
| 56 | .word 10 |
| 57 | |
| 58 | // SEC: Name: .tdata |
| 59 | // SEC-NEXT: Type: SHT_PROGBITS |
| 60 | // SEC-NEXT: Flags [ |
| 61 | // SEC-NEXT: SHF_ALLOC |
| 62 | // SEC-NEXT: SHF_TLS |
| 63 | // SEC-NEXT: SHF_WRITE |
| 64 | // SEC-NEXT: ] |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 65 | // SEC-NEXT: Address: 0x2210 |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 66 | // SEC: Size: 4 |
| 67 | // SEC: Name: .tbss |
| 68 | // SEC-NEXT: Type: SHT_NOBITS |
| 69 | // SEC-NEXT: Flags [ |
| 70 | // SEC-NEXT: SHF_ALLOC |
| 71 | // SEC-NEXT: SHF_TLS |
| 72 | // SEC-NEXT: SHF_WRITE |
| 73 | // SEC-NEXT: ] |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 74 | // SEC-NEXT: Address: 0x2214 |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 75 | // SEC: Size: 8 |
| 76 | |
| 77 | // SEC: Name: .got |
| 78 | // SEC-NEXT: Type: SHT_PROGBITS |
| 79 | // SEC-NEXT: Flags [ |
| 80 | // SEC-NEXT: SHF_ALLOC |
| 81 | // SEC-NEXT: SHF_WRITE |
| 82 | // SEC-NEXT: ] |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 83 | // SEC-NEXT: Address: 0x2264 |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 84 | // SEC: Size: 24 |
| 85 | |
| 86 | // SEC: Dynamic Relocations { |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 87 | // SEC-NEXT: 0x2274 R_ARM_TLS_DTPMOD32 - |
| 88 | // SEC-NEXT: 0x2264 R_ARM_TLS_DTPMOD32 x |
| 89 | // SEC-NEXT: 0x2268 R_ARM_TLS_DTPOFF32 x |
| 90 | // SEC-NEXT: 0x226C R_ARM_TLS_DTPMOD32 y |
| 91 | // SEC-NEXT: 0x2270 R_ARM_TLS_DTPOFF32 y |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 92 | |
| 93 | |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 94 | // CHECK-LABEL: 000011f8 func: |
| 95 | // CHECK-NEXT: 11f8: 00 f0 20 e3 nop |
| 96 | // CHECK-NEXT: 11fc: 00 f0 20 e3 nop |
| 97 | // CHECK-NEXT: 1200: 00 f0 20 e3 nop |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 98 | |
Fangrui Song | 024bf27d | 2019-08-27 11:52:36 | [diff] [blame^] | 99 | // (0x2264 - 0x1204) + (0x1204 - 0x11f8 - 8) = 0x1064 |
| 100 | // CHECK: 1204: 64 10 00 00 |
| 101 | // (0x226c - 0x1204) + (0x1204 - 0x11fc - 8) = 0x1068 |
| 102 | // CHECK-NEXT: 1208: 68 10 00 00 |
| 103 | // (0x2274 - 0x1204) + (0x1204 - 0x1200 - 8) = 0x106c |
| 104 | // CHECK-NEXT: 120c: 6c 10 00 00 |
Peter Smith | 9d45025 | 2016-07-20 08:52:27 | [diff] [blame] | 105 | |