1## Show that llvm-readobj/llvm-readelf tools sometimes can dump the 2## dynamic table when it is not in a PT_DYNAMIC segment. 3 4## Case 1: The dynamic table found using the dynamic program header is corrupted 5## (<size of data> % <size of dynamic entry> != 0). So the table is taken 6## from the section header. 7 8# RUN: yaml2obj --docnum=1 %s -o %t1.o 9# RUN: llvm-readobj --dynamic-table %t1.o 2>&1 \ 10# RUN: | FileCheck -DFILE=%t1.o --check-prefixes=WARNING1,LLVM1 %s 11# RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \ 12# RUN: | FileCheck -DFILE=%t1.o --check-prefixes=WARNING1,GNU1 %s 13 14# WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment 15# WARNING1: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x1){{$}} 16# WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table 17# WARNING1: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used 18 19# LLVM1: DynamicSection [ (2 entries) 20# LLVM1-NEXT: Tag Type Name/Value 21# LLVM1-NEXT: 0x0000000000000018 BIND_NOW 0x1 22# LLVM1-NEXT: 0x0000000000000000 NULL 0x0 23# LLVM1-NEXT: ] 24 25# GNU1: Dynamic section at offset 0x{{.*}} contains 2 entries: 26# GNU1-NEXT: Tag Type Name/Value 27# GNU1-NEXT: 0x0000000000000018 (BIND_NOW) 0x1 28# GNU1-NEXT: 0x0000000000000000 (NULL) 0x0 29 30--- !ELF 31FileHeader: 32 Class: ELFCLASS64 33 Data: ELFDATA2LSB 34 Type: ET_EXEC 35Sections: 36 - Name: .dynamic 37 Type: SHT_DYNAMIC 38 Flags: [SHF_ALLOC] 39 Address: 0x1000 40 AddressAlign: 0x1000 41 Entries: 42 - Tag: DT_BIND_NOW 43 Value: 0x1 44 - Tag: DT_NULL 45 Value: 0x0 46 - Name: .text 47 Type: SHT_PROGBITS 48 Flags: [SHF_ALLOC] 49 Address: 0x1100 50 AddressAlign: 0x100 51 Content: "00" 52ProgramHeaders: 53 - Type: PT_LOAD 54 VAddr: 0x1000 55 FirstSec: .dynamic 56 LastSec: .text 57 - Type: PT_DYNAMIC 58 VAddr: 0x1000 59 FirstSec: .text 60 LastSec: .text 61 62## Case 2: The dynamic table found using the dynamic program header is different from the 63## table found using the section header table. 64 65# RUN: yaml2obj --docnum=2 %s -o %t2.o 66# RUN: llvm-readobj --dynamic-table %t2.o 2>&1 \ 67# RUN: | FileCheck -DFILE=%t2.o --check-prefixes=WARNING2,LLVM2 %s 68# RUN: llvm-readelf --dynamic-table %t2.o 2>&1 \ 69# RUN: | FileCheck -DFILE=%t2.o --check-prefixes=WARNING2,GNU2 %s 70 71# WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment 72# WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table 73 74# LLVM2: DynamicSection [ (1 entries) 75# LLVM2-NEXT: Tag Type Name/Value 76# LLVM2-NEXT: 0x0000000000000000 NULL 0x0 77# LLVM2-NEXT: ] 78 79# GNU2: Dynamic section at offset 0x{{.*}} contains 1 entries: 80# GNU2-NEXT: Tag Type Name/Value 81# GNU2-NEXT: 0x0000000000000000 (NULL) 0x0 82 83--- !ELF 84FileHeader: 85 Class: ELFCLASS64 86 Data: ELFDATA2LSB 87 Type: ET_EXEC 88Sections: 89 - Name: .dynamic 90 Type: SHT_DYNAMIC 91 Flags: [SHF_ALLOC] 92 Address: 0x1000 93 AddressAlign: 0x1000 94 Entries: 95 - Tag: DT_BIND_NOW 96 Value: 0x1 97 - Tag: DT_NULL 98 Value: 0x0 99 - Name: .text 100 Type: SHT_PROGBITS 101 Flags: [SHF_ALLOC] 102 Address: 0x1100 103 AddressAlign: 0x100 104 Content: "00000000000000000000000000000000" 105ProgramHeaders: 106 - Type: PT_LOAD 107 VAddr: 0x1000 108 FirstSec: .dynamic 109 LastSec: .text 110 - Type: PT_DYNAMIC 111 VAddr: 0x1000 112 FirstSec: .text 113 LastSec: .text 114 115## Case 3: Both dynamic tables found using SHT_DYNAMIC/PT_DYNAMIC are corrupted. 116 117# RUN: yaml2obj --docnum=3 %s -o %t3.o 118# RUN: llvm-readobj --dynamic-table %t3.o 2>&1 \ 119# RUN: | FileCheck -DFILE=%t3.o --check-prefix=WARNING3 --implicit-check-not="Dynamic" %s 120# RUN: llvm-readelf --dynamic-table %t3.o 2>&1 \ 121# RUN: | FileCheck -DFILE=%t3.o --check-prefix=WARNING3 --implicit-check-not="Dynamic" %s 122 123# WARNING3: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x1){{$}} 124# WARNING3: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table 125# WARNING3: warning: '[[FILE]]': no valid dynamic table was found 126 127--- !ELF 128FileHeader: 129 Class: ELFCLASS64 130 Data: ELFDATA2LSB 131 Type: ET_EXEC 132Sections: 133 - Name: .dynamic 134 Type: SHT_DYNAMIC 135 Flags: [SHF_ALLOC] 136 Address: 0x1000 137 AddressAlign: 0x1000 138 Content: "00" 139 - Name: .text 140 Type: SHT_PROGBITS 141 Flags: [SHF_ALLOC] 142 Address: 0x1100 143 AddressAlign: 0x100 144 Content: "00" 145ProgramHeaders: 146 - Type: PT_LOAD 147 VAddr: 0x1000 148 FirstSec: .dynamic 149 LastSec: .text 150 - Type: PT_DYNAMIC 151 VAddr: 0x1000 152 FirstSec: .text 153 LastSec: .text 154