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