Skip to content

Commit 54b4a0d

Browse files
authored
[llvm-readobj] --needed-libs: support --elf-output-style=JSON (#75028)
Close #74529
1 parent 05b68d5 commit 54b4a0d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/test/tools/llvm-readobj/ELF/needed-libs.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
66
# RUN: llvm-readelf --needed-libs %t1 2>&1 \
77
# 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
810

911
## Check that library names are sorted when printed.
1012
## Document that we also sort error entries.
@@ -19,6 +21,17 @@
1921
# NEEDED-LIBS-NEXT:{{^}} ccc{{$}}
2022
# NEEDED-LIBS-NEXT:{{^}}]{{$}}
2123

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+
2235
--- !ELF
2336
FileHeader:
2437
Class: ELFCLASS64

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ template <class ELFT> void ELFDumper<ELFT>::printNeededLibraries() {
25812581
llvm::sort(Libs);
25822582

25832583
for (StringRef L : Libs)
2584-
W.startLine() << L << "\n";
2584+
W.printString(L);
25852585
}
25862586

25872587
template <class ELFT>

0 commit comments

Comments
 (0)