163 lines · plain
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 contains5## only the IMAGE_TLS_DIRECTORY structure and hence we should have that6## TlsTable.RelativeVirtualAddress == .rdata section VirtualAddress.7## Also note that the .rdata section VirtualSize == sizeof(coff_tls_directory32) == sizeof(IMAGE_TLS_DIRECTORY32) == 248 9# RUN: yaml2obj %s --docnum=1 -o %t.32.exe -DTLSRVA=10000 -DTLSSIZE=2410# RUN: llvm-readobj --coff-tls-directory %t.32.exe | FileCheck %s --check-prefix I38611 12# I386: Arch: i38613# I386-NEXT: AddressSize: 32bit14# I386-NEXT: TLSDirectory {15# I386-NEXT: StartAddressOfRawData: 0x40400016# I386-NEXT: EndAddressOfRawData: 0x40400817# I386-NEXT: AddressOfIndex: 0x40200018# I386-NEXT: AddressOfCallBacks: 0x019# I386-NEXT: SizeOfZeroFill: 0x020# 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=1031# RUN: not llvm-readobj --coff-tls-directory %t.wrong-size.32.exe 2>&1 | FileCheck %s --check-prefix I386-WRONG-SIZE-ERR32 33# I386-WRONG-SIZE-ERR: error: '{{.*}}': TLS Directory size (10) is not the expected size (24).34 35--- !COFF36OptionalHeader:37 AddressOfEntryPoint: 038 ImageBase: 039 SectionAlignment: 409640 FileAlignment: 51241 MajorOperatingSystemVersion: 042 MinorOperatingSystemVersion: 043 MajorImageVersion: 044 MinorImageVersion: 045 MajorSubsystemVersion: 046 MinorSubsystemVersion: 047 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI48 DLLCharacteristics: []49 SizeOfStackReserve: 050 SizeOfStackCommit: 051 SizeOfHeapReserve: 052 SizeOfHeapCommit: 053 TlsTable:54 RelativeVirtualAddress: [[TLSRVA]]55 Size: [[TLSSIZE]]56header:57 Machine: IMAGE_FILE_MACHINE_I38658 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE ]59sections:60 - Name: .rdata61 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]62 VirtualAddress: 1000063 VirtualSize: 2464 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 contains70## only the IMAGE_TLS_DIRECTORY structure and hence we should have that71## TlsTable.RelativeVirtualAddress == .rdata section VirtualAddress.72## Also note that the .rdata section VirtualSize == sizeof(coff_tls_directory64) == sizeof(IMAGE_TLS_DIRECTORY64) == 4073 74# RUN: yaml2obj %s --docnum=2 -o %t.64.exe -DTLSRVA=10000 -DTLSSIZE=4075# RUN: llvm-readobj --coff-tls-directory %t.64.exe | FileCheck %s --check-prefix X86-6476 77# X86-64: Arch: x86_6478# X86-64-NEXT: AddressSize: 64bit79# X86-64-NEXT: TLSDirectory {80# X86-64-NEXT: StartAddressOfRawData: 0x14000400081# X86-64-NEXT: EndAddressOfRawData: 0x14000400882# X86-64-NEXT: AddressOfIndex: 0x14000200083# X86-64-NEXT: AddressOfCallBacks: 0x084# X86-64-NEXT: SizeOfZeroFill: 0x085# 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=8097# RUN: not llvm-readobj --coff-tls-directory %t.wrong-size.64.exe 2>&1 | FileCheck %s --check-prefix X86-64-WRONG-SIZE-ERR98 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=40105# 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-ERR106 107# BAD-TLS-RVA-ERR: error: '[[FILE]]': RVA 0xf423f for TLS directory not found108 109--- !COFF110OptionalHeader:111 AddressOfEntryPoint: 0112 ImageBase: 0113 SectionAlignment: 4096114 FileAlignment: 512115 MajorOperatingSystemVersion: 0116 MinorOperatingSystemVersion: 0117 MajorImageVersion: 0118 MinorImageVersion: 0119 MajorSubsystemVersion: 0120 MinorSubsystemVersion: 0121 Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI122 DLLCharacteristics: []123 SizeOfStackReserve: 0124 SizeOfStackCommit: 0125 SizeOfHeapReserve: 0126 SizeOfHeapCommit: 0127 TlsTable:128 RelativeVirtualAddress: [[TLSRVA]]129 Size: [[TLSSIZE]]130header:131 Machine: IMAGE_FILE_MACHINE_AMD64132 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]133sections:134 - Name: .rdata135 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]136 VirtualAddress: 10000137 VirtualSize: 40138 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=0147# RUN: llvm-readobj --coff-tls-directory %t.no-tls1.exe | FileCheck %s --check-prefix NO-TLS148 149## Case 2: There's no TlsTable listed in the COFF header.150 151# RUN: yaml2obj %s --docnum=3 -o %t.no-tls2.exe152# RUN: llvm-readobj --coff-tls-directory %t.no-tls2.exe | FileCheck %s --check-prefix NO-TLS153 154# NO-TLS: TLSDirectory {155# NO-TLS-NEXT: }156 157--- !COFF158header:159 Machine: IMAGE_FILE_MACHINE_AMD64160 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]161sections: []162symbols: []163