[llvm] 54b4a0d - [llvm-readobj] --needed-libs: support --elf-output-style=JSON (#75028)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 08:59:23 PST 2023
Author: Fangrui Song
Date: 2023-12-11T08:59:19-08:00
New Revision: 54b4a0d688dd6463b81678273b125ff24dc25cff
URL: https://github.com/llvm/llvm-project/commit/54b4a0d688dd6463b81678273b125ff24dc25cff
DIFF: https://github.com/llvm/llvm-project/commit/54b4a0d688dd6463b81678273b125ff24dc25cff.diff
LOG: [llvm-readobj] --needed-libs: support --elf-output-style=JSON (#75028)
Close #74529
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/needed-libs.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/needed-libs.test b/llvm/test/tools/llvm-readobj/ELF/needed-libs.test
index d37ab6238e137..d2d0bdad26ed0 100644
--- a/llvm/test/tools/llvm-readobj/ELF/needed-libs.test
+++ b/llvm/test/tools/llvm-readobj/ELF/needed-libs.test
@@ -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.
@@ -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
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 85d5ab68b495c..a9a31ae6c4740 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -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>
More information about the llvm-commits
mailing list