Skip to content

Commit 25e9125

Browse files
luqmanacuviper
authored andcommitted
[LLD] Add baseline test for TLS alignment. NFC.
Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D88646
1 parent 7f288db commit 25e9125

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

lld/test/COFF/Inputs/tlssup-32.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; We manually create these here if we're not linking against
2+
; the CRT which would usually provide these.
3+
4+
target triple = "i686-pc-windows-msvc"
5+
6+
%IMAGE_TLS_DIRECTORY32 = type {
7+
i32, ; StartAddressOfRawData
8+
i32, ; EndAddressOfRawData
9+
i32, ; AddressOfIndex
10+
i32, ; AddressOfCallBacks
11+
i32, ; SizeOfZeroFill
12+
i32 ; Characteristics
13+
}
14+
15+
@_tls_start = global i8 zeroinitializer, section ".tls"
16+
@_tls_end = global i8 zeroinitializer, section ".tls$ZZZ"
17+
@_tls_index = global i32 0
18+
19+
@_tls_used = global %IMAGE_TLS_DIRECTORY32 {
20+
i32 ptrtoint (i8* @_tls_start to i32),
21+
i32 ptrtoint (i8* @_tls_end to i32),
22+
i32 ptrtoint (i32* @_tls_index to i32),
23+
i32 0,
24+
i32 0,
25+
i32 0
26+
}, section ".rdata$T"
27+
28+
; MSVC target uses a direct offset (0x58) for x86-64 but expects
29+
; __tls_array to hold the offset (0x2C) on x86.
30+
module asm ".global __tls_array"
31+
module asm "__tls_array = 44"

lld/test/COFF/Inputs/tlssup-64.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; We manually create these here if we're not linking against
2+
; the CRT which would usually provide these.
3+
4+
target triple = "x86_64-pc-windows-msvc"
5+
6+
%IMAGE_TLS_DIRECTORY64 = type {
7+
i64, ; StartAddressOfRawData
8+
i64, ; EndAddressOfRawData
9+
i64, ; AddressOfIndex
10+
i64, ; AddressOfCallBacks
11+
i32, ; SizeOfZeroFill
12+
i32 ; Characteristics
13+
}
14+
15+
@_tls_start = global i8 zeroinitializer, section ".tls"
16+
@_tls_end = global i8 zeroinitializer, section ".tls$ZZZ"
17+
@_tls_index = global i64 0
18+
19+
@_tls_used = global %IMAGE_TLS_DIRECTORY64 {
20+
i64 ptrtoint (i8* @_tls_start to i64),
21+
i64 ptrtoint (i8* @_tls_end to i64),
22+
i64 ptrtoint (i64* @_tls_index to i64),
23+
i64 0,
24+
i32 0,
25+
i32 0
26+
}, section ".rdata$T"

lld/test/COFF/tls-alignment-32.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; This test is to make sure that the necessary alignment for thread locals
2+
; gets reflected in the TLS Directory of the generated executable on x86.
3+
;
4+
; aligned_thread_local specifies 'align 32' and so the generated
5+
; exe should reflect that with a value of IMAGE_SCN_ALIGN_32BYTES
6+
; in the Characteristics field of the IMAGE_TLS_DIRECTORY
7+
8+
; RUN: llc -filetype=obj %S/Inputs/tlssup-32.ll -o %t.tlssup.obj
9+
; RUN: llc -filetype=obj %s -o %t.obj
10+
; RUN: lld-link %t.tlssup.obj %t.obj -entry:main -nodefaultlib -out:%t.exe
11+
; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
12+
13+
; CHECK: TLSDirectory {
14+
; CHECK: Characteristics [ (0x0)
15+
16+
target triple = "i686-pc-windows-msvc"
17+
18+
@aligned_thread_local = thread_local global i32 42, align 32
19+
20+
define i32 @main() {
21+
%t = load i32, i32* @aligned_thread_local
22+
ret i32 %t
23+
}

lld/test/COFF/tls-alignment-64.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; This test is to make sure that the necessary alignment for thread locals
2+
; gets reflected in the TLS Directory of the generated executable on x86-64.
3+
;
4+
; aligned_thread_local specifies 'align 64' and so the generated
5+
; exe should reflect that with a value of IMAGE_SCN_ALIGN_64BYTES
6+
; in the Characteristics field of the IMAGE_TLS_DIRECTORY
7+
8+
; RUN: llc -filetype=obj %S/Inputs/tlssup-64.ll -o %t.tlssup.obj
9+
; RUN: llc -filetype=obj %s -o %t.obj
10+
; RUN: lld-link %t.tlssup.obj %t.obj -entry:main -nodefaultlib -out:%t.exe
11+
; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
12+
13+
; CHECK: TLSDirectory {
14+
; CHECK: Characteristics [ (0x0)
15+
16+
target triple = "x86_64-pc-windows-msvc"
17+
18+
@aligned_thread_local = thread_local global i32 42, align 64
19+
20+
define i32 @main() {
21+
%t = load i32, i32* @aligned_thread_local
22+
ret i32 %t
23+
}

0 commit comments

Comments
 (0)