[Toybox] [PATCH] Implement readelf(1).

enh enh at google.com
Tue Jan 7 17:59:40 PST 2020


Basic readelf(1) implementation, with output close enough to the binutils
version to be usable with scripts that expect the binutils version. This
started as an implementation of nm(1) until I realized that I almost always
want readelf instead, and that you actually have to do much of the work
needed for readelf just to implement nm. Arguably nm (being part of POSIX)
belongs in toybox while readelf doesn't. An argument could also be made that
neither really belongs in toybox, belonging in a separate set of development
tools (such as binutils or the LLVM binutils).

Doesn't support most of the architecture-specific stuff, most notably
relocations, but is aware of things like ARM exidx sections and the common
register state notes in core dumps for the "big four" architectures: arm,
arm64, x86, and x86-64.

Doesn't support symbol versions (but probably should).

Doesn't support section groups or the -t "section details" (which is a long
form of -S "section headers" that I've never seen used in practice and which
isn't part of -a). Doesn't support dumping unwind info or the hash table
bucket histograms.

Reuses the table of ELF architectures from file(1).

Not fuzzed, but successfully parses all the ELF files in my Ubuntu 18.04
system's lib directories. Attempts to exit with an error when presented with
an invalid ELF file rather than struggle on as binutils seems to.
---
 lib/lib.c              |  26 ++
 lib/lib.h              |   1 +
 tests/readelf.test     | 202 ++++++++++++++
 toys/pending/readelf.c | 589 +++++++++++++++++++++++++++++++++++++++++
 toys/posix/file.c      |  22 +-
 5 files changed, 820 insertions(+), 20 deletions(-)
 create mode 100755 tests/readelf.test
 create mode 100644 toys/pending/readelf.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Implement-readelf-1.patch
Type: text/x-patch
Size: 36968 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20200107/df801b5e/attachment-0002.bin>


More information about the Toybox mailing list