1## In this test we check the --needed-libs option.
2
3# RUN: yaml2obj %s --docnum=1 -o %t1
4# RUN: llvm-readobj --needed-libs %t1 2>&1 \
5# RUN:   | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
6# RUN: llvm-readelf --needed-libs %t1 2>&1 \
7# RUN:   | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
8
9## Check that library names are sorted when printed.
10## Document that we also sort error entries.
11
12#      NEEDED-LIBS:{{^}}NeededLibraries [{{$}}
13# NEEDED-LIBS-NEXT:  warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x9999a11: it goes past the end of the table (0x85){{$}}
14# NEEDED-LIBS-NEXT:  warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x1111189: it goes past the end of the table (0x85){{$}}
15# NEEDED-LIBS-NEXT:{{^}}  <?>{{$}}
16# NEEDED-LIBS-NEXT:{{^}}  <?>{{$}}
17# NEEDED-LIBS-NEXT:{{^}}  aaa{{$}}
18# NEEDED-LIBS-NEXT:{{^}}  bbb{{$}}
19# NEEDED-LIBS-NEXT:{{^}}  ccc{{$}}
20# NEEDED-LIBS-NEXT:{{^}}]{{$}}
21
22--- !ELF
23FileHeader:
24  Class: ELFCLASS64
25  Data:  ELFDATA2LSB
26  Type:  ET_EXEC
27Sections:
28  - Name:  .dynstr
29    Type:  SHT_STRTAB
30    Flags: [ SHF_ALLOC ]
31    Content: '00616161006262620063636300' ## 0,a,a,a,0,b,b,b,0,c,c,c,0
32  - Name:    .dynamic
33    Type:    SHT_DYNAMIC
34    Entries:
35      - Tag:   DT_STRTAB
36        Value: 0x0000000000000000
37      - Tag:   DT_NEEDED
38        Value: 0x9999999
39      - Tag:   DT_NEEDED
40        Value: 9
41      - Tag:   DT_NEEDED
42        Value: 1
43      - Tag:   DT_NEEDED
44        Value: 5
45      - Tag:   DT_NEEDED
46        Value: 0x1111111
47      - Tag:   DT_STRSZ
48        Value: [[SIZE=0xD]]
49      - Tag:   DT_NULL
50        Value: 0x0
51ProgramHeaders:
52  - Type: PT_LOAD
53    VAddr: 0x0
54    Sections:
55      - Section: .dynstr
56      - Section: .dynamic
57
58## Check what we print when the dynamic string table is empty.
59# RUN: yaml2obj %s --docnum=2 -o %t2
60# RUN: llvm-readobj --needed-libs %t2 2>&1 | \
61# RUN:   FileCheck %s -DFILE=%t2 --implicit-check-not=warning: --check-prefixes=EMPTY-DYNSTR,EMPTY-DYNSTR-LLVM
62# RUN: llvm-readelf --needed-libs %t2 2>&1 | \
63# RUN:   FileCheck %s -DFILE=%t2 --implicit-check-not=warning: --check-prefix=EMPTY-DYNSTR
64
65# EMPTY-DYNSTR:      NeededLibraries [
66# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x79: it goes past the end of the table (0x78)
67# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x7a: it goes past the end of the table (0x78)
68# EMPTY-DYNSTR-NEXT:   <?>
69# EMPTY-DYNSTR-NEXT:   <?>
70# EMPTY-DYNSTR-NEXT: ]
71
72--- !ELF
73FileHeader:
74  Class: ELFCLASS64
75  Data:  ELFDATA2LSB
76  Type:  ET_EXEC
77Sections:
78  - Name:  .dynstr
79    Type:  SHT_STRTAB
80    Flags: [ SHF_ALLOC ]
81    Size:  0
82  - Name:    .dynamic
83    Type:    SHT_DYNAMIC
84    Address: 0x1000
85    Entries:
86      - Tag:   DT_STRTAB
87        Value: 0x0000000000000000
88      - Tag:   DT_NEEDED
89        Value: 1
90      - Tag:   DT_NEEDED
91        Value: 2
92      - Tag:   DT_STRSZ
93        Value: 0x0
94      - Tag:   DT_NULL
95        Value: 0x0
96ProgramHeaders:
97  - Type: PT_LOAD
98    VAddr: 0x0
99    Sections:
100      - Section: .dynstr
101      - Section: .dynamic
102