Skip to content

Commit

Permalink
[llvm-readobj] --needed-libs: support --elf-output-style=JSON (llvm#7…
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Dec 11, 2023
1 parent 05b68d5 commit 54b4a0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/needed-libs.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
# RUN: llvm-readelf --needed-libs %t1 2>&1 \
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
# RUN: llvm-readobj --elf-output-style=JSON --needed-libs --pretty-print %t1 2>&1 \
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --match-full-lines --strict-whitespace --check-prefix=JSON

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

# JSON: "FileSummary": {
# 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)
# 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)
# JSON-EMPTY:
# JSON-NEXT: "<?>",
# JSON-NEXT: "<?>",
# JSON-NEXT: "aaa",
# JSON-NEXT: "bbb",
# JSON-NEXT: "ccc"
# JSON-NEXT: ]

--- !ELF
FileHeader:
Class: ELFCLASS64
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2581,7 +2581,7 @@ template <class ELFT> void ELFDumper<ELFT>::printNeededLibraries() {
llvm::sort(Libs);

for (StringRef L : Libs)
W.startLine() << L << "\n";
W.printString(L);
}

template <class ELFT>
Expand Down

0 comments on commit 54b4a0d

Please sign in to comment.