Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-readobj] --needed-libs: support --elf-output-style=JSON #75028

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Dec 11, 2023

Close #74529

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 11, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Fangrui Song (MaskRay)

Changes

Close #74529


Full diff: https://github.com/llvm/llvm-project/pull/75028.diff

2 Files Affected:

  • (modified) llvm/test/tools/llvm-readobj/ELF/needed-libs.test (+13)
  • (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+1-1)
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>

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MaskRay MaskRay merged commit 54b4a0d into llvm:main Dec 11, 2023
5 checks passed
@MaskRay MaskRay deleted the readobj-needed branch December 11, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LLVM-Tools] [LLVM-ReadElf] Errorneous JSON Output when using --needed-libs
3 participants