|
| 1 | +# Test handling of a dynamic section size which is not a multiple of its entry size. |
| 2 | +# RUN: yaml2obj %s --docnum=1 -o %t.bad-size |
| 3 | +# RUN: not llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE |
| 4 | +# RUN: not llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE |
| 5 | + |
| 6 | +# ERR-SIZE: Error reading file: Invalid entity size. |
| 7 | + |
| 8 | +--- !ELF |
| 9 | +FileHeader: |
| 10 | + Class: ELFCLASS64 |
| 11 | + Data: ELFDATA2LSB |
| 12 | + Type: ET_EXEC |
| 13 | + Machine: EM_X86_64 |
| 14 | +Sections: |
| 15 | + - Name: .dynamic |
| 16 | + Type: SHT_DYNAMIC |
| 17 | + Address: 0x1000 |
| 18 | + Content: "01234567" |
| 19 | +ProgramHeaders: |
| 20 | + - Type: PT_LOAD |
| 21 | + VAddr: 0x1000 |
| 22 | + Sections: |
| 23 | + - Section: .dynamic |
| 24 | + - Type: PT_DYNAMIC |
| 25 | + VAddr: 0x1000 |
| 26 | + Sections: |
| 27 | + - Section: .dynamic |
| 28 | + |
| 29 | +# Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)). |
| 30 | +# RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize |
| 31 | +# RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE |
| 32 | +# RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE |
| 33 | + |
| 34 | +# BAD-ENTSIZE: DynamicSection [ (2 entries) |
| 35 | +# BAD-ENTSIZE-NEXT: Tag Type Name/Value |
| 36 | +# BAD-ENTSIZE-NEXT: 0x0000000000000015 DEBUG 0x0 |
| 37 | +# BAD-ENTSIZE-NEXT: 0x0000000000000000 NULL 0x0 |
| 38 | +# BAD-ENTSIZE-NEXT: ] |
| 39 | + |
| 40 | +--- !ELF |
| 41 | +FileHeader: |
| 42 | + Class: ELFCLASS64 |
| 43 | + Data: ELFDATA2LSB |
| 44 | + Type: ET_EXEC |
| 45 | + Machine: EM_X86_64 |
| 46 | +Sections: |
| 47 | + - Name: .dynamic |
| 48 | + Type: SHT_DYNAMIC |
| 49 | + Address: 0x1000 |
| 50 | + EntSize: 0x2 |
| 51 | + Entries: |
| 52 | + - Tag: DT_DEBUG |
| 53 | + Value: 0 |
| 54 | + - Tag: DT_NULL |
| 55 | + Value: 0 |
| 56 | +ProgramHeaders: |
| 57 | + - Type: PT_LOAD |
| 58 | + VAddr: 0x1000 |
| 59 | + Sections: |
| 60 | + - Section: .dynamic |
| 61 | + - Type: PT_DYNAMIC |
| 62 | + VAddr: 0x1000 |
| 63 | + Sections: |
| 64 | + - Section: .dynamic |
| 65 | + |
| 66 | +# Test handling of string references pointing past the end of the dynamic string table. In this case, |
| 67 | +# we have a DT_NEEDED tag pointing at offset 1 in a 1-byte string table. |
| 68 | +# RUN: yaml2obj %s --docnum=3 -o %t.bad-string |
| 69 | +# RUN: not llvm-readobj --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING |
| 70 | +# RUN: not llvm-readelf --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING |
| 71 | + |
| 72 | +# BAD-STRING: Error reading file: Invalid dynamic string table reference. |
| 73 | + |
| 74 | +--- !ELF |
| 75 | +FileHeader: |
| 76 | + Class: ELFCLASS64 |
| 77 | + Data: ELFDATA2LSB |
| 78 | + Type: ET_EXEC |
| 79 | + Machine: EM_X86_64 |
| 80 | +Sections: |
| 81 | + - Name: .dynstr |
| 82 | + Type: SHT_STRTAB |
| 83 | + Address: 0x1000 |
| 84 | + - Name: .dynamic |
| 85 | + Type: SHT_DYNAMIC |
| 86 | + Address: 0x1010 |
| 87 | + Entries: |
| 88 | + - Tag: DT_STRTAB |
| 89 | + Value: 0x1000 |
| 90 | + - Tag: DT_STRSZ |
| 91 | + Value: 1 |
| 92 | + - Tag: DT_NEEDED |
| 93 | + Value: 1 |
| 94 | + - Tag: DT_NULL |
| 95 | + Value: 0 |
| 96 | +ProgramHeaders: |
| 97 | + - Type: PT_LOAD |
| 98 | + VAddr: 0x1000 |
| 99 | + Sections: |
| 100 | + - Section: .dynstr |
| 101 | + - Section: .dynamic |
| 102 | + - Type: PT_DYNAMIC |
| 103 | + VAddr: 0x1010 |
| 104 | + Sections: |
| 105 | + - Section: .dynamic |
| 106 | + |
| 107 | +# Test handling of DT_STRTAB pointing outside the file's address space. |
| 108 | +# RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab |
| 109 | +# RUN: not llvm-readobj --dynamic-table %t.bad-strtab 2>&1 | FileCheck %s --check-prefix BAD-STRTAB |
| 110 | +# RUN: not llvm-readelf --dynamic-table %t.bad-strtab 2>&1 | FileCheck %s --check-prefix BAD-STRTAB |
| 111 | + |
| 112 | +# BAD-STRTAB: LLVM ERROR: Virtual address is not in any segment |
| 113 | + |
| 114 | +--- !ELF |
| 115 | +FileHeader: |
| 116 | + Class: ELFCLASS64 |
| 117 | + Data: ELFDATA2LSB |
| 118 | + Type: ET_EXEC |
| 119 | + Machine: EM_X86_64 |
| 120 | +Sections: |
| 121 | + - Name: .dynamic |
| 122 | + Type: SHT_DYNAMIC |
| 123 | + Address: 0x1000 |
| 124 | + Entries: |
| 125 | + - Tag: DT_STRTAB |
| 126 | + Value: 0x2000000 |
| 127 | + - Tag: DT_STRSZ |
| 128 | + Value: 10 |
| 129 | + - Tag: DT_NEEDED |
| 130 | + Value: 1 |
| 131 | + - Tag: DT_NULL |
| 132 | + Value: 0x0 |
| 133 | +ProgramHeaders: |
| 134 | + - Type: PT_LOAD |
| 135 | + VAddr: 0x1000 |
| 136 | + Sections: |
| 137 | + - Section: .dynamic |
| 138 | + - Type: PT_DYNAMIC |
| 139 | + VAddr: 0x1000 |
| 140 | + Sections: |
| 141 | + - Section: .dynamic |
| 142 | + |
| 143 | +# Test handling of other d_ptr tags pointing outside the file's address space. |
| 144 | +# RUN: yaml2obj %s --docnum=5 -o %t.bad-rela |
| 145 | +# RUN: not llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefix BAD-RELA |
| 146 | +# RUN: not llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefix BAD-RELA |
| 147 | + |
| 148 | +# BAD-RELA: LLVM ERROR: Virtual address is not in any segment |
| 149 | + |
| 150 | +--- !ELF |
| 151 | +FileHeader: |
| 152 | + Class: ELFCLASS64 |
| 153 | + Data: ELFDATA2LSB |
| 154 | + Type: ET_EXEC |
| 155 | + Machine: EM_X86_64 |
| 156 | +Sections: |
| 157 | + - Name: .dynamic |
| 158 | + Type: SHT_DYNAMIC |
| 159 | + Address: 0x1000 |
| 160 | + Entries: |
| 161 | + - Tag: DT_RELA |
| 162 | + Value: 0x1000000 |
| 163 | + - Tag: DT_NULL |
| 164 | + Value: 0x0 |
| 165 | +ProgramHeaders: |
| 166 | + - Type: PT_LOAD |
| 167 | + VAddr: 0x1000 |
| 168 | + Sections: |
| 169 | + - Section: .dynamic |
| 170 | + - Type: PT_DYNAMIC |
| 171 | + VAddr: 0x1000 |
| 172 | + Sections: |
| 173 | + - Section: .dynamic |
0 commit comments