1# REQUIRES: x86 2# RUN: rm -rf %t; split-file %s %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/regular.s -o %t/regular.o 4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/tbss.s -o %t/tbss.o 5 6# RUN: %lld -lSystem -no_pie -o %t/regular-no-pie %t/regular.o 7# RUN: llvm-otool -hv %t/regular-no-pie | FileCheck %s --check-prefix=HEADER 8# RUN: llvm-objdump -d --bind --rebase %t/regular-no-pie | FileCheck %s --check-prefixes=REG,LINKEDIT 9# RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-no-pie | \ 10# RUN: FileCheck %s --check-prefix=REG-TLVP 11 12# RUN: %lld -lSystem %t/regular.o -o %t/regular-pie 13# RUN: llvm-otool -hv %t/regular-pie | FileCheck %s --check-prefix=HEADER 14# RUN: llvm-objdump -d --bind --rebase %t/regular-pie | FileCheck %s --check-prefixes=REG,LINKEDIT 15# RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-pie | \ 16# RUN: FileCheck %s --check-prefix=REG-TLVP 17 18# RUN: %lld -lSystem %t/tbss.o -o %t/tbss -e _f 19# RUN: llvm-objdump -d --bind --rebase %t/tbss | FileCheck %s --check-prefixes=TBSS,LINKEDIT 20# RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/tbss | \ 21# RUN: FileCheck %s --check-prefix=TBSS-TLVP 22 23# RUN: %lld -lSystem %t/regular.o %t/tbss.o -o %t/regular-and-tbss 24# RUN: llvm-objdump -d --bind --rebase %t/regular-and-tbss | FileCheck %s --check-prefixes=REG,TBSS,LINKEDIT 25# RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-and-tbss | \ 26# RUN: FileCheck %s --check-prefix=REG-TBSS-TLVP 27# RUN: llvm-objdump --section-headers %t/regular-and-tbss | FileCheck %s --check-prefix=SECTIONS 28 29## Check that we always put __thread_bss immediately after __thread_data, 30## regardless of the order of the input files. 31# RUN: %lld -lSystem %t/tbss.o %t/regular.o -o %t/regular-and-tbss 32# RUN: llvm-objdump --section-headers %t/regular-and-tbss | FileCheck %s --check-prefix=SECTIONS 33 34# HEADER: MH_HAS_TLV_DESCRIPTORS 35 36# REG: <_main>: 37# REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_foo> 38# REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_bar> 39# REG-NEXT: retq 40 41# TBSS: <_f>: 42# TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_baz> 43# TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_qux> 44# TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_hoge> 45# TBSS-NEXT: retq 46 47# REG-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48# REG-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49# REG-TLVP-NEXT: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 50 51# TBSS-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52# TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53# TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 54 55# REG-TBSS-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 56# REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 57# REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 58# REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59# REG-TBSS-TLVP-NEXT: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60# REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 61# REG-TBSS-TLVP-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 62# REG-TBSS-TLVP-NEXT: 30 00 00 00 00 00 00 00 63 64## Make sure we don't emit rebase opcodes for relocations in __thread_vars. 65# LINKEDIT: Rebase table: 66# LINKEDIT-NEXT: segment section address type 67# LINKEDIT-EMPTY: 68# LINKEDIT-NEXT: Bind table: 69# LINKEDIT: __DATA __thread_vars 0x{{[0-9a-f]*}} pointer 0 libSystem __tlv_bootstrap 70# LINKEDIT: __DATA __thread_vars 0x{{[0-9a-f]*}} pointer 0 libSystem __tlv_bootstrap 71 72## Make sure we have an odd number of tlv vars, and that the __thread_vars 73## section starts 16-bytes aligned. This is the setup required for __thread_data 74## not to be automatically 16-bytes aligned, ensuring the linker does its 75## expected job of aligning _hoge$tlv$init. 76# SECTIONS: __thread_vars {{[0-9]+}}8 {{[0-9]+}}0 77# SECTIONS: __thread_data 78# SECTIONS: more_thread_data 79# SECTIONS-NEXT: __thread_bss 80 81#--- regular.s 82.globl _main 83_main: 84 mov _foo@TLVP(%rip), %rax 85 mov _bar@TLVP(%rip), %rax 86 ret 87 88.section __DATA,__thread_data,thread_local_regular 89_foo$tlv$init: 90 .quad 123 91 92.section __DATA,more_thread_data,thread_local_regular 93_bar$tlv$init: 94 .quad 123 95 96.section __DATA,__thread_vars,thread_local_variables 97.globl _foo, _bar 98_foo: 99 .quad __tlv_bootstrap 100 .quad 0 101 .quad _foo$tlv$init 102_bar: 103 .quad __tlv_bootstrap 104 .quad 0 105 .quad _bar$tlv$init 106 107#--- tbss.s 108 109.globl _f 110_f: 111 mov _baz@TLVP(%rip), %rax 112 mov _qux@TLVP(%rip), %rax 113 mov _hoge@TLVP(%rip), %rax 114 ret 115 116.tbss _baz$tlv$init, 8, 3 117.tbss _qux$tlv$init, 8, 3 118.tbss _hoge$tlv$init, 16, 4 119 120.section __DATA,__thread_vars,thread_local_variables 121_baz: 122 .quad __tlv_bootstrap 123 .quad 0 124 .quad _baz$tlv$init 125_qux: 126 .quad __tlv_bootstrap 127 .quad 0 128 .quad _qux$tlv$init 129_hoge: 130 .quad __tlv_bootstrap 131 .quad 0 132 .quad _hoge$tlv$init 133