Skip to content

[LLVM-Tools] [LLVM-ReadElf] Errorneous JSON Output when using --needed-libs #74529

Closed
@carstencodes

Description

@carstencodes

Description

I am using LLVM-readelf to find out the needed libraries of a shared object. The data shall be formatted as json and passed to a JSON processing library, where it is parsed and processed.

How To Reproduce

$  llvm-readelf-15 --needed-libs --pretty-print --elf-output-style=JSON /usr/lib/libgdiplus.so | jq
...

Expected Behavior

Output like

[
  {
    "/usr/lib/libgdiplus.so": {
      "FileSummary": {
        "File": "/usr/lib/libgdiplus.so",
        "Format": "elf64-x86-64",
        "Arch": "x86_64",
        "AddressSize": "64bit",
        "LoadName": "libgdiplus.so.0"
      },
      "NeededLibraries": [
         "libX11.so.6",
         "libc.so.6",
         "libcairo.so.2",
         "libexif.so.12",
         "libfontconfig.so.1",
         "libfreetype.so.6",
         "libgif.so.7",
         "libglib-2.0.so.0",
         "libjpeg.so.8",
         "libm.so.6",
         "libpng16.so.16",
         "libpthread.so.0",
         "libtiff.so.5"
      ]
    }
  }
]

Actual Behavior

parse error: Invalid numeric literal at line 12, column 0

Output without JQ

[
  {
    "/usr/lib/libgdiplus.so": {
      "FileSummary": {
        "File": "/usr/lib/libgdiplus.so",
        "Format": "elf64-x86-64",
        "Arch": "x86_64",
        "AddressSize": "64bit",
        "LoadName": "libgdiplus.so.0"
      },
      "NeededLibraries": [libX11.so.6
libc.so.6
libcairo.so.2
libexif.so.12
libfontconfig.so.1
libfreetype.so.6
libgif.so.7
libglib-2.0.so.0
libjpeg.so.8
libm.so.6
libpng16.so.16
libpthread.so.0
libtiff.so.5
]
    }
  }
]

Versions

Tried with LLVM

  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

Possible Issue Location

I think the faulting location is in ELFDumper.cpp:2566:

Instead of using

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

it should be something like

 W.printList(Libs);

But I actually don't know the interna about ArrayRef and StringRef and have no Idea whether this would work.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions