1## Tests for the --coff-tls-directory flag. 2 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 8 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 11 12# I386: Arch: 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) 22# I386-NEXT: ] 23# I386-NEXT: } 24 25 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. 29 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 32 33# I386-WRONG-SIZE-ERR: error: '{{.*}}': TLS Directory size (10) is not the expected size (24). 34 35--- !COFF 36OptionalHeader: 37 AddressOfEntryPoint: 0 38 ImageBase: 0 39 SectionAlignment: 4096 40 FileAlignment: 512 41 MajorOperatingSystemVersion: 0 42 MinorOperatingSystemVersion: 0 43 MajorImageVersion: 0 44 MinorImageVersion: 0 45 MajorSubsystemVersion: 0 46 MinorSubsystemVersion: 0 47 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI 48 DLLCharacteristics: [] 49 SizeOfStackReserve: 0 50 SizeOfStackCommit: 0 51 SizeOfHeapReserve: 0 52 SizeOfHeapCommit: 0 53 TlsTable: 54 RelativeVirtualAddress: [[TLSRVA]] 55 Size: [[TLSSIZE]] 56header: 57 Machine: IMAGE_FILE_MACHINE_I386 58 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE ] 59sections: 60 - Name: .rdata 61 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] 62 VirtualAddress: 10000 63 VirtualSize: 24 64 SectionData: '004040000840400000204000000000000000000000003000' 65symbols: [] 66 67 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 73 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 76 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) 87# X86-64-NEXT: ] 88# X86-64-NEXT: } 89 90 91## Test that the output of --coff-tls-directory errors on malformed input. 92 93## On x86-64, the TLS directory should be 40 bytes. 94## This test has an erroneously lengthened TLS directory. 95 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 98 99# X86-64-WRONG-SIZE-ERR: error: '{{.*}}': TLS Directory size (80) is not the expected size (40). 100 101 102## This test has a correct TLS Directory size but the RVA is invalid. 103 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 106 107# BAD-TLS-RVA-ERR: error: '[[FILE]]': RVA 0xf423f for TLS directory not found 108 109--- !COFF 110OptionalHeader: 111 AddressOfEntryPoint: 0 112 ImageBase: 0 113 SectionAlignment: 4096 114 FileAlignment: 512 115 MajorOperatingSystemVersion: 0 116 MinorOperatingSystemVersion: 0 117 MajorImageVersion: 0 118 MinorImageVersion: 0 119 MajorSubsystemVersion: 0 120 MinorSubsystemVersion: 0 121 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI 122 DLLCharacteristics: [] 123 SizeOfStackReserve: 0 124 SizeOfStackCommit: 0 125 SizeOfHeapReserve: 0 126 SizeOfHeapCommit: 0 127 TlsTable: 128 RelativeVirtualAddress: [[TLSRVA]] 129 Size: [[TLSSIZE]] 130header: 131 Machine: IMAGE_FILE_MACHINE_AMD64 132 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ] 133sections: 134 - Name: .rdata 135 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] 136 VirtualAddress: 10000 137 VirtualSize: 40 138 SectionData: '00400040010000000840004001000000002000400100000000000000000000000000000000003000' 139symbols: [] 140 141 142## Test that --coff-tls-directory doesn't output anything if there's no TLS directory. 143 144## Case 1: TlsTable.RelativeVirtualAddress/Size = 0. 145 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 148 149## Case 2: There's no TlsTable listed in the COFF header. 150 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 153 154# NO-TLS: TLSDirectory { 155# NO-TLS-NEXT: } 156 157--- !COFF 158header: 159 Machine: IMAGE_FILE_MACHINE_AMD64 160 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ] 161sections: [] 162symbols: [] 163