1 ## Tests for the --coff-tls-directory flag.
3 ## Test that the output of --coff-tls-directory works on x86.
4 ## The binary created from this yaml definition is such that .rdata contains
5 ## only the IMAGE_TLS_DIRECTORY structure and hence we should have that
6 ## TlsTable.RelativeVirtualAddress == .rdata section VirtualAddress.
7 ## Also note that the .rdata section VirtualSize == sizeof(coff_tls_directory32) == sizeof(IMAGE_TLS_DIRECTORY32) == 24
9 # RUN: yaml2obj %s --docnum=1 -o %t.32.exe -DTLSRVA=10000 -DTLSSIZE=24
10 # RUN: llvm-readobj --coff-tls-directory %t.32.exe | FileCheck %s --check-prefix I386
13 # I386-NEXT: AddressSize: 32bit
14 # I386-NEXT: TLSDirectory {
15 # I386-NEXT: StartAddressOfRawData: 0x404000
16 # I386-NEXT: EndAddressOfRawData: 0x404008
17 # I386-NEXT: AddressOfIndex: 0x402000
18 # I386-NEXT: AddressOfCallBacks: 0x0
19 # I386-NEXT: SizeOfZeroFill: 0x0
20 # I386-NEXT: Characteristics [ (0x300000)
21 # I386-NEXT: IMAGE_SCN_ALIGN_4BYTES (0x300000)
26 ## Test that the output of --coff-tls-directory errors on malformed input.
27 ## On x86, the TLS directory should be 24 bytes.
28 ## This test has a truncated TLS directory.
30 # RUN: yaml2obj %s --docnum=1 -o %t.wrong-size.32.exe -DTLSRVA=10000 -DTLSSIZE=10
31 # RUN: not llvm-readobj --coff-tls-directory %t.wrong-size.32.exe 2>&1 | FileCheck %s --check-prefix I386-WRONG-SIZE-ERR
33 # I386-WRONG-SIZE-ERR: error: '{{.*}}': TLS Directory size (10) is not the expected size (24).
37 AddressOfEntryPoint: 0
39 SectionAlignment: 4096
41 MajorOperatingSystemVersion: 0
42 MinorOperatingSystemVersion: 0
45 MajorSubsystemVersion: 0
46 MinorSubsystemVersion: 0
47 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
48 DLLCharacteristics: []
54 RelativeVirtualAddress: [[TLSRVA]]
57 Machine: IMAGE_FILE_MACHINE_I386
58 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE ]
61 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
64 SectionData: '004040000840400000204000000000000000000000003000'
68 ## Test that the output of --coff-tls-directory works on x86_64.
69 ## The binary created from this yaml definition is such that .rdata contains
70 ## only the IMAGE_TLS_DIRECTORY structure and hence we should have that
71 ## TlsTable.RelativeVirtualAddress == .rdata section VirtualAddress.
72 ## Also note that the .rdata section VirtualSize == sizeof(coff_tls_directory64) == sizeof(IMAGE_TLS_DIRECTORY64) == 40
74 # RUN: yaml2obj %s --docnum=2 -o %t.64.exe -DTLSRVA=10000 -DTLSSIZE=40
75 # RUN: llvm-readobj --coff-tls-directory %t.64.exe | FileCheck %s --check-prefix X86-64
77 # X86-64: Arch: x86_64
78 # X86-64-NEXT: AddressSize: 64bit
79 # X86-64-NEXT: TLSDirectory {
80 # X86-64-NEXT: StartAddressOfRawData: 0x140004000
81 # X86-64-NEXT: EndAddressOfRawData: 0x140004008
82 # X86-64-NEXT: AddressOfIndex: 0x140002000
83 # X86-64-NEXT: AddressOfCallBacks: 0x0
84 # X86-64-NEXT: SizeOfZeroFill: 0x0
85 # X86-64-NEXT: Characteristics [ (0x300000)
86 # X86-64-NEXT: IMAGE_SCN_ALIGN_4BYTES (0x300000)
91 ## Test that the output of --coff-tls-directory errors on malformed input.
93 ## On x86-64, the TLS directory should be 40 bytes.
94 ## This test has an erroneously lengthened TLS directory.
96 # RUN: yaml2obj %s --docnum=2 -o %t.wrong-size.64.exe -DTLSRVA=10000 -DTLSSIZE=80
97 # RUN: not llvm-readobj --coff-tls-directory %t.wrong-size.64.exe 2>&1 | FileCheck %s --check-prefix X86-64-WRONG-SIZE-ERR
99 # X86-64-WRONG-SIZE-ERR: error: '{{.*}}': TLS Directory size (80) is not the expected size (40).
102 ## This test has a correct TLS Directory size but the RVA is invalid.
104 # RUN: yaml2obj %s --docnum=2 -o %t.bad-tls-rva.exe -DTLSRVA=999999 -DTLSSIZE=40
105 # RUN: not llvm-readobj --coff-tls-directory %t.bad-tls-rva.exe 2>&1 | FileCheck -DFILE=%t.bad-tls-rva.exe %s --check-prefix BAD-TLS-RVA-ERR
107 # BAD-TLS-RVA-ERR: error: '[[FILE]]': RVA 0xf423f for TLS directory not found
111 AddressOfEntryPoint: 0
113 SectionAlignment: 4096
115 MajorOperatingSystemVersion: 0
116 MinorOperatingSystemVersion: 0
119 MajorSubsystemVersion: 0
120 MinorSubsystemVersion: 0
121 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
122 DLLCharacteristics: []
123 SizeOfStackReserve: 0
128 RelativeVirtualAddress: [[TLSRVA]]
131 Machine: IMAGE_FILE_MACHINE_AMD64
132 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
135 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
136 VirtualAddress: 10000
138 SectionData: '00400040010000000840004001000000002000400100000000000000000000000000000000003000'
142 ## Test that --coff-tls-directory doesn't output anything if there's no TLS directory.
144 ## Case 1: TlsTable.RelativeVirtualAddress/Size = 0.
146 # RUN: yaml2obj %s --docnum=2 -o %t.no-tls1.exe -DTLSRVA=0 -DTLSSIZE=0
147 # RUN: llvm-readobj --coff-tls-directory %t.no-tls1.exe | FileCheck %s --check-prefix NO-TLS
149 ## Case 2: There's no TlsTable listed in the COFF header.
151 # RUN: yaml2obj %s --docnum=3 -o %t.no-tls2.exe
152 # RUN: llvm-readobj --coff-tls-directory %t.no-tls2.exe | FileCheck %s --check-prefix NO-TLS
154 # NO-TLS: TLSDirectory {
159 Machine: IMAGE_FILE_MACHINE_AMD64
160 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]