1## Check that we can use the --dependent-libraries option
2## to dump SHT_LLVM_DEPENDENT_LIBRARIES sections.
3
4## Check how we dump a file that has a single valid SHT_LLVM_DEPENDENT_LIBRARIES
5## section with multiple entries.
6
7# RUN: yaml2obj --docnum=1 %s -o %t1
8# RUN: llvm-readobj --dependent-libraries %t1 | \
9# RUN:   FileCheck %s --check-prefix=LLVM --strict-whitespace --match-full-lines
10# RUN: llvm-readelf --dependent-libraries %t1 | \
11# RUN:   FileCheck %s --check-prefix=GNU --strict-whitespace --match-full-lines --implicit-check-not="Dependent libraries"
12
13#      LLVM:DependentLibs [
14# LLVM-NEXT:  foo
15# LLVM-NEXT:  bar
16# LLVM-NEXT:  foo
17# LLVM-NEXT:]
18
19#      GNU:Dependent libraries section .deplibs at offset 0x40 contains 3 entries:
20# GNU-NEXT:  [     0]  foo
21# GNU-NEXT:  [     4]  bar
22# GNU-NEXT:  [     8]  foo
23
24--- !ELF
25FileHeader:
26  Class:   ELFCLASS64
27  Data:    ELFDATA2LSB
28  Type:    ET_REL
29  Machine: EM_X86_64
30Sections:
31  - Name:      .deplibs
32    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
33    Libraries: [ foo, bar, foo ]
34
35## Now, check how we dump a mix of valid, empty and invalid SHT_LLVM_DEPENDENT_LIBRARIES sections.
36
37# RUN: yaml2obj --docnum=2 %s -o %t2
38# RUN: llvm-readobj --dependent-libraries %t2 2>&1 | FileCheck %s --check-prefix=MIX-LLVM -DFILE=%t2
39# RUN: llvm-readelf --dependent-libraries %t2 2>&1 | FileCheck %s --check-prefix=MIX-GNU -DFILE=%t2
40
41# MIX-LLVM:      DependentLibs [
42# MIX-LLVM-NEXT:   warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 1 is broken: the content is not null-terminated
43# MIX-LLVM-NEXT:   abc
44# MIX-LLVM-NEXT:   warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 4 is broken: section [index 4] has a sh_offset (0xffff0000) + sh_size (0x4) that is greater than the file size (0x308)
45# MIX-LLVM-NEXT:   bar
46# MIX-LLVM-NEXT:   xxx
47# MIX-LLVM-NEXT:   baz
48# MIX-LLVM-NEXT: ]
49
50# MIX-GNU:      warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 1 is broken: the content is not null-terminated
51# MIX-GNU-NEXT: Dependent libraries section .deplibs.nonul at offset 0x40 contains 0 entries:
52# MIX-GNU-EMPTY:
53# MIX-GNU-NEXT: Dependent libraries section .deplibs.single at offset 0x43 contains 1 entries:
54# MIX-GNU-NEXT:   [     0]  abc
55# MIX-GNU-EMPTY:
56# MIX-GNU-NEXT: Dependent libraries section .deplibs.empty at offset 0x47 contains 0 entries:
57# MIX-GNU-EMPTY:
58# MIX-GNU-NEXT: warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 4 is broken: section [index 4] has a sh_offset (0xffff0000) + sh_size (0x4) that is greater than the file size (0x308)
59# MIX-GNU-NEXT: Dependent libraries section .deplibs.broken.shoffset at offset 0xffff0000 contains 0 entries:
60# MIX-GNU-EMPTY:
61# MIX-GNU-NEXT: Dependent libraries section .deplibs.multiple at offset 0x4b contains 2 entries:
62# MIX-GNU-NEXT:   [     0]  bar
63# MIX-GNU-NEXT:   [     4]  xxx
64# MIX-GNU-EMPTY:
65# MIX-GNU-NEXT: warning: '[[FILE]]': cannot get section name of SHT_LLVM_DEPENDENT_LIBRARIES section: a section [index 6] has an invalid sh_name (0x10000) offset which goes past the end of the section name string table
66# MIX-GNU-NEXT: Dependent libraries section <?> at offset 0x53 contains 1 entries:
67# MIX-GNU-NEXT:   [     0]  baz
68
69--- !ELF
70FileHeader:
71  Class:   ELFCLASS64
72  Data:    ELFDATA2LSB
73  Type:    ET_REL
74  Machine: EM_X86_64
75Sections:
76## Case 1: test we report a warning for a non-null-terminated section.
77  - Name:      .deplibs.nonul
78    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
79    Content:   "666f6f" ## 'f', 'o', 'o'
80## Case 2: test we can dump an entry from a valid section that has a single entry.
81  - Name:      .deplibs.single
82    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
83    Libraries: [ abc ]
84## Case 3: test we do not display warnings for an empty section.
85  - Name:      .deplibs.empty
86    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
87    Content:   ""
88## Case 4: test we report a warning when the section offset is invalid.
89  - Name:      .deplibs.broken.shoffset
90    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
91    Libraries: [ yyy ]
92    ShOffset:  0xffff0000
93## Case 5: test we can dump all entries from a valid section that has more than one entry.
94  - Name:      .deplibs.multiple
95    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
96    Libraries: [ bar, xxx ]
97## Case 6: test we report a warning in GNU mode if the section name can't be read.
98  - ShName:    0x10000
99    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
100    Libraries: [ baz ]
101
102## Show the output when there are no dependent library sections.
103# RUN: yaml2obj --docnum=3 %s -o %t3
104# RUN: llvm-readobj --dependent-libraries %t3 2>&1 | FileCheck %s --check-prefix=NONE
105# RUN: llvm-readelf --dependent-libraries %t3 2>&1 | FileCheck %s --allow-empty --implicit-check-not={{.}}
106
107# NONE:      DependentLibs [
108# NONE-NEXT: ]
109
110--- !ELF
111FileHeader:
112  Class:   ELFCLASS64
113  Data:    ELFDATA2LSB
114  Type:    ET_REL
115  Machine: EM_X86_64
116