diff --git a/lld/test/COFF/tls-alignment.ll b/lld/test/COFF/tls-alignment.ll new file mode 100644 --- /dev/null +++ b/lld/test/COFF/tls-alignment.ll @@ -0,0 +1,47 @@ +; This test is to make sure that the necessary alignment for thread locals +; gets reflected in the TLS Directory of the generated executable. +; +; aligned_thread_local specifies 'align 32' and so the generated +; exe should reflect that with a value of IMAGE_SCN_ALIGN_32BYTES +; in the Characteristics field of the IMAGE_TLS_DIRECTORY + +; RUN: llc -filetype=obj %s -o %t.obj +; RUN: lld-link %t.obj -entry:main -nodefaultlib -out:%t.exe +; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s + +; CHECK: Characteristics [ (0x0) + +target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +%IMAGE_TLS_DIRECTORY = type { + i64, ; StartAddressOfRawData + i64, ; EndAddressOfRawData + i64, ; AddressOfIndex + i64, ; AddressOfCallBacks + i32, ; SizeOfZeroFill + i32 ; Characteristics +} + +; We manually create these here as we're not linking against +; the CRT which would usually provide these. +@_tls_start = global i8 zeroinitializer, section ".tls" +@_tls_end = global i8 zeroinitializer, section ".tls$ZZZ" +@_tls_index = global i64 1 +@_tls_used = global %IMAGE_TLS_DIRECTORY { + i64 ptrtoint (i8* @_tls_start to i64), + i64 ptrtoint (i8* @_tls_end to i64), + i64 ptrtoint (i64* @_tls_index to i64), + i64 0, + i32 0, + i32 0 +}, section ".rdata$T" + +@_fltused = global i8 zeroinitializer + +@aligned_thread_local = thread_local global [32 x i8] zeroinitializer, align 32 + +define i32 @main() #0 { + store <8 x float> zeroinitializer, <8 x float>* bitcast ([32 x i8]* @aligned_thread_local to <8 x float>*), align 32 + ret i32 0 +}