1## Check we are able to dump library soname properly.
2
3## Test a valid object case first. We set 'FileSize' to 0x48, because this is a no-op,
4## i.e. this value would be set if we had no 'FileSize' at all.
5# RUN: yaml2obj -DDTSTRTABVAL=0x0 -DPHDRFILESIZE="0x48" %s -o %t.o
6# RUN: llvm-readobj %t.o | FileCheck %s --check-prefix LLVM
7# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix GNU
8
9# LLVM:      Format: elf64-x86-64
10# LLVM-NEXT: Arch: x86_64
11# LLVM-NEXT: AddressSize: 64bit
12# LLVM-NEXT: LoadName: test.so
13
14# GNU:       Dynamic section at offset 0x80 contains 4 entries:
15# GNU-NEXT:   Tag                Type     Name/Value
16# GNU-NEXT:   0x0000000000000005 (STRTAB) 0x0
17# GNU-NEXT:   0x000000000000000a (STRSZ)  8 (bytes)
18# GNU-NEXT:   0x000000000000000e (SONAME) Library soname: [test.so]
19# GNU-NEXT:   0x0000000000000000 (NULL)   0x0
20
21!ELF
22FileHeader:
23  Class:   ELFCLASS64
24  Data:    ELFDATA2LSB
25  Type:    ET_EXEC
26  Machine: EM_X86_64
27Sections:
28  - Name:  .dynstr
29    Type:  SHT_STRTAB
30    Flags: [ SHF_ALLOC ]
31    Content: '746573742e736f00' ## "test.so"
32  - Name:  .dynamic
33    Type:  SHT_DYNAMIC
34    Flags: [ SHF_ALLOC ]
35    Link:  .dynstr
36    Entries:
37      - Tag:   DT_STRTAB
38        Value: [[DTSTRTABVAL]]
39      - Tag:   DT_STRSZ
40        Value: 0x0000000000000008
41      - Tag:   DT_SONAME
42        Value: 0x0000000000000000
43      - Tag:   DT_NULL
44        Value: 0x0000000000000000
45ProgramHeaders:
46  - Type:     PT_LOAD
47    Flags:    [ PF_R ]
48    VAddr:    0x0000
49    FileSize: [[PHDRFILESIZE]]
50    FirstSec: .dynstr
51    LastSec:  .dynamic
52
53## Check we do not crash when an object contains a DT_STRTAB entry whose address
54## is past the end of the object.
55## Note that we have to set p_filesz for PT_LOAD larger than DT_STRTAB value
56## to trigger this particular warning.
57
58# RUN: yaml2obj -DDTSTRTABVAL=0xFFFE -DPHDRFILESIZE=0xFFFF %s -o %t.err.1.o
59# RUN: llvm-readobj %t.err.1.o 2>&1 | FileCheck %s -DFILE=%t.err.1.o --check-prefixes=BROKEN-OFFSET,BROKEN-OFFSET-LLVM
60# RUN: llvm-readelf --dynamic-table %t.err.1.o 2>&1 | FileCheck %s -DFILE=%t.err.1.o --check-prefixes=BROKEN-OFFSET,BROKEN-OFFSET-GNU
61
62# BROKEN-OFFSET:      warning: '[[FILE]]': unable to parse DT_STRTAB: can't map virtual address 0xfffe to the segment with index 1: the segment ends at 0x10077, which is greater than the file size (0x228)
63# BROKEN-OFFSET:      warning: '[[FILE]]': string table was not found
64# BROKEN-OFFSET-LLVM: LoadName: <?>
65# BROKEN-OFFSET-GNU:  0x000000000000000e (SONAME) Library soname: [<?>]
66