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
29Sections:
30  - Name:      .deplibs
31    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
32    ShType:    [[TYPE=<none>]]
33    Libraries: [ foo, bar, foo ]
34
35## Show the output when there are no dependent library sections. Check that we are
36## locating dependent library sections by type. To do this we change the type to an arbitrary one.
37# RUN: yaml2obj --docnum=1 -DTYPE=SHT_PROGBITS %s -o %t3
38# RUN: llvm-readobj --dependent-libraries %t3 2>&1 | FileCheck %s --check-prefix=NONE
39# RUN: llvm-readelf --dependent-libraries %t3 2>&1 | FileCheck %s --allow-empty --implicit-check-not={{.}}
40
41# NONE:      DependentLibs [
42# NONE-NEXT: ]
43
44## Now, check how we dump a mix of valid, empty and invalid SHT_LLVM_DEPENDENT_LIBRARIES sections.
45
46# RUN: yaml2obj --docnum=2 %s -o %t2
47# RUN: llvm-readobj --dependent-libraries %t2 2>&1 | FileCheck %s --check-prefix=MIX-LLVM -DFILE=%t2
48# RUN: llvm-readelf --dependent-libraries %t2 2>&1 | FileCheck %s --check-prefix=MIX-GNU -DFILE=%t2
49
50# MIX-LLVM:      DependentLibs [
51# MIX-LLVM-NEXT:   warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 1 is broken: the content is not null-terminated
52# MIX-LLVM-NEXT:   abc
53# 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)
54# MIX-LLVM-NEXT:   bar
55# MIX-LLVM-NEXT:   xxx
56# MIX-LLVM-NEXT:   baz
57# MIX-LLVM-NEXT: ]
58
59# MIX-GNU:      warning: '[[FILE]]': SHT_LLVM_DEPENDENT_LIBRARIES section at index 1 is broken: the content is not null-terminated
60# MIX-GNU-NEXT: Dependent libraries section .deplibs.nonul at offset 0x40 contains 0 entries:
61# MIX-GNU-EMPTY:
62# MIX-GNU-NEXT: Dependent libraries section .deplibs.single at offset 0x43 contains 1 entries:
63# MIX-GNU-NEXT:   [     0]  abc
64# MIX-GNU-EMPTY:
65# MIX-GNU-NEXT: Dependent libraries section .deplibs.empty at offset 0x47 contains 0 entries:
66# MIX-GNU-EMPTY:
67# 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)
68# MIX-GNU-NEXT: Dependent libraries section .deplibs.broken.shoffset at offset 0xffff0000 contains 0 entries:
69# MIX-GNU-EMPTY:
70# MIX-GNU-NEXT: Dependent libraries section .deplibs.multiple at offset 0x4b contains 2 entries:
71# MIX-GNU-NEXT:   [     0]  bar
72# MIX-GNU-NEXT:   [     4]  xxx
73# MIX-GNU-EMPTY:
74# MIX-GNU-NEXT: warning: '[[FILE]]': unable to get the name of SHT_LLVM_DEPENDENT_LIBRARIES section with index 6: a section [index 6] has an invalid sh_name (0x10000) offset which goes past the end of the section name string table
75# MIX-GNU-NEXT: Dependent libraries section <?> at offset 0x53 contains 1 entries:
76# MIX-GNU-NEXT:   [     0]  baz
77
78--- !ELF
79FileHeader:
80  Class: ELFCLASS64
81  Data:  ELFDATA2LSB
82  Type:  ET_REL
83Sections:
84## Case 1: test we report a warning for a non-null-terminated section.
85  - Name:      .deplibs.nonul
86    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
87    Content:   "666f6f" ## 'f', 'o', 'o'
88## Case 2: test we can dump an entry from a valid section that has a single entry.
89  - Name:      .deplibs.single
90    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
91    Libraries: [ abc ]
92## Case 3: test we do not display warnings for an empty section.
93  - Name:      .deplibs.empty
94    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
95    Content:   ""
96## Case 4: test we report a warning when the section offset is invalid.
97  - Name:      .deplibs.broken.shoffset
98    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
99    Libraries: [ yyy ]
100    ShOffset:  0xffff0000
101## Case 5: test we can dump all entries from a valid section that has more than one entry.
102  - Name:      .deplibs.multiple
103    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
104    Libraries: [ bar, xxx ]
105## Case 6: test we report a warning in GNU mode if the section name can't be read.
106  - ShName:    0x10000
107    Type:      SHT_LLVM_DEPENDENT_LIBRARIES
108    Libraries: [ baz ]
109