forked from OSchip/llvm-project
282 lines
11 KiB
Plaintext
282 lines
11 KiB
Plaintext
## Test handling of a dynamic section size which is not a multiple of its entry size.
|
|
## Test the full output to demonstrate how we print the warnings.
|
|
|
|
# RUN: yaml2obj %s --docnum=1 -o %t.bad-size
|
|
# RUN: llvm-readobj --all %t.bad-size 2>&1 \
|
|
# RUN: | FileCheck %s -DFILE=%t.bad-size --implicit-check-not=warning --check-prefix WARN
|
|
# RUN: llvm-readelf --all %t.bad-size 2>&1 \
|
|
# RUN: | FileCheck %s -DFILE=%t.bad-size --implicit-check-not=warning --check-prefix WARN-GNU
|
|
|
|
# WARN: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x4){{$}}
|
|
# WARN: warning: '[[FILE]]': section with index 1 has invalid size (0x4){{$}}
|
|
# WARN: warning: '[[FILE]]': no valid dynamic table was found
|
|
# WARN-EMPTY:
|
|
# WARN: File:
|
|
# WARN: ProgramHeaders [
|
|
# WARN: Symbols [
|
|
# WARN: ]
|
|
|
|
# WARN-GNU: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x4){{$}}
|
|
# WARN-GNU: warning: '[[FILE]]': section with index 1 has invalid size (0x4){{$}}
|
|
# WARN-GNU: warning: '[[FILE]]': no valid dynamic table was found
|
|
# WARN-GNU-NEXT: ELF Header:
|
|
# WARN-GNU: Symbol table '.symtab' contains 1 entries:
|
|
# WARN-GNU: 0:
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x1000
|
|
Content: "01234567"
|
|
Symbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
|
|
## Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
|
|
# RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize
|
|
# RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-LLVM
|
|
# RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-GNU
|
|
|
|
# BAD-ENTSIZE-LLVM: DynamicSection [ (2 entries)
|
|
# BAD-ENTSIZE-LLVM-NEXT: Tag Type Name/Value
|
|
# BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000015 DEBUG 0x0
|
|
# BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000000 NULL 0x0
|
|
# BAD-ENTSIZE-LLVM-NEXT: ]
|
|
|
|
# BAD-ENTSIZE-GNU: Dynamic section at offset 0x{{.*}} contains 2 entries:
|
|
# BAD-ENTSIZE-GNU-NEXT: Tag Type Name/Value
|
|
# BAD-ENTSIZE-GNU-NEXT: 0x0000000000000015 (DEBUG) 0x0
|
|
# BAD-ENTSIZE-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x1000
|
|
EntSize: 0x2
|
|
Entries:
|
|
- Tag: DT_DEBUG
|
|
Value: 0
|
|
- Tag: DT_NULL
|
|
Value: 0
|
|
Symbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
|
|
## Test handling of string references pointing past the end of the dynamic string table.
|
|
# RUN: yaml2obj %s --docnum=3 -o %t.bad-string
|
|
# RUN: llvm-readobj --dynamic-table %t.bad-string 2>&1 | \
|
|
# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-LLVM -DFILE=%t.bad-string
|
|
# RUN: llvm-readelf --dynamic-table %t.bad-string 2>&1 | \
|
|
# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-GNU -DFILE=%t.bad-string
|
|
|
|
# BAD-STRING-LLVM: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM: LoadName: <?>
|
|
# BAD-STRING-LLVM: DynamicSection [ (10 entries)
|
|
# BAD-STRING-LLVM-NEXT: Tag Type Name/Value
|
|
# BAD-STRING-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
|
|
# BAD-STRING-LLVM-NEXT: 0x000000000000000A STRSZ 1 (bytes)
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
|
|
## Note: there is no "string table at offset 0xb0..." warning here, because it was printed earlier.
|
|
# BAD-STRING-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [<?>]
|
|
# BAD-STRING-LLVM-NEXT: 0x0000000000000000 NULL 0x0
|
|
# BAD-STRING-LLVM-NEXT: ]
|
|
|
|
# BAD-STRING-GNU: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: Dynamic section at offset 0xb1 contains 10 entries:
|
|
# BAD-STRING-GNU-NEXT: Tag Type Name/Value
|
|
# BAD-STRING-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
|
|
# BAD-STRING-GNU-NEXT: 0x000000000000000a (STRSZ) 1 (bytes)
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
|
|
## Note: there is no "string table at offset 0xb6..." warning here, because it was printed earlier.
|
|
# BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
|
|
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8, it goes past the end of the table (0xb1)
|
|
# BAD-STRING-GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [<?>]
|
|
# BAD-STRING-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynstr
|
|
Type: SHT_STRTAB
|
|
Address: 0x1000
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x1010
|
|
Entries:
|
|
- Tag: DT_STRTAB
|
|
Value: 0x1000
|
|
- Tag: DT_STRSZ
|
|
Value: 1
|
|
- Tag: DT_NEEDED
|
|
Value: 2
|
|
- Tag: DT_FILTER
|
|
Value: 3
|
|
- Tag: DT_AUXILIARY
|
|
Value: 4
|
|
- Tag: DT_USED
|
|
Value: 5
|
|
- Tag: DT_SONAME
|
|
Value: 6
|
|
- Tag: DT_RPATH
|
|
Value: 7
|
|
- Tag: DT_RUNPATH
|
|
Value: 8
|
|
- Tag: DT_NULL
|
|
Value: 0
|
|
Symbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynstr
|
|
- Section: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
VAddr: 0x1010
|
|
Sections:
|
|
- Section: .dynamic
|
|
|
|
## Test handling of DT_STRTAB pointing outside the file's address space.
|
|
# RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
|
|
|
|
# RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
|
|
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
|
|
# RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
|
|
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
|
|
# BAD-STRTAB-ERR: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
|
|
# BAD-STRTAB-ERR: warning: '[[FILE]]': string table was not found
|
|
|
|
# RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
|
|
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-LLVM
|
|
# RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
|
|
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-GNU
|
|
|
|
# BAD-STRTAB-LLVM: LoadName: <?>
|
|
# BAD-STRTAB-LLVM: 0x0000000000000001 NEEDED Shared library: [<?>]
|
|
# BAD-STRTAB-GNU: 0x0000000000000001 (NEEDED) Shared library: [<?>]
|
|
# BAD-STRTAB: NeededLibraries [
|
|
# BAD-STRTAB: <?>
|
|
# BAD-STRTAB: ]
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x1000
|
|
Entries:
|
|
- Tag: DT_STRTAB
|
|
Value: 0x2000000
|
|
- Tag: DT_STRSZ
|
|
Value: 10
|
|
- Tag: DT_NEEDED
|
|
Value: 1
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
Symbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
|
|
## Test handling of other d_ptr tags pointing outside the file's address space.
|
|
# RUN: yaml2obj %s --docnum=5 -o %t.bad-rela
|
|
# RUN: llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck -DFILE=%t.bad-rela %s --check-prefixes=CHECK,BAD-RELA
|
|
# RUN: llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck -DFILE=%t.bad-rela %s --check-prefixes=CHECK,BAD-RELA-GNU
|
|
|
|
# CHECK: warning: '[[FILE]]': Unable to parse DT_RELA: virtual address is not in any segment: 0x1000000
|
|
|
|
# BAD-RELA: DynamicSection [ (2 entries)
|
|
# BAD-RELA-NEXT: Tag Type Name/Value
|
|
# BAD-RELA-NEXT: 0x0000000000000007 RELA 0x1000000
|
|
# BAD-RELA-NEXT: 0x0000000000000000 NULL 0x0
|
|
# BAD-RELA-NEXT: ]
|
|
# BAD-RELA-GNU: Dynamic section at offset 0xb0 contains 2 entries:
|
|
# BAD-RELA-GNU-NEXT: Tag Type Name/Value
|
|
# BAD-RELA-GNU-NEXT: 0x0000000000000007 (RELA) 0x1000000
|
|
# BAD-RELA-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x1000
|
|
Entries:
|
|
- Tag: DT_RELA
|
|
Value: 0x1000000
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
Symbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
VAddr: 0x1000
|
|
Sections:
|
|
- Section: .dynamic
|