diff options
author | Mark Wielaard <mark@klomp.org> | 2018-10-21 23:41:32 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2018-11-09 18:11:48 +0100 |
commit | ecbe3120cddb1b9597a19a68c4265e4f2c530444 (patch) | |
tree | 40f6549cda3aa5bff3df983f15ac88d0da597b72 /src | |
parent | 4b0342b85b5b1a3d3636e06e3b5320954828dfb1 (diff) | |
download | elfutils-ecbe3120cddb1b9597a19a68c4265e4f2c530444.tar.gz |
libdwelf: New function dwelf_elf_begin.
This introduces a new function dwelf_elf_begin which creates a (read-only)
ELF handle from a possibly compressed file handle or a file that start
with a linux kernel header. This can be used in eu-readelf to (re)open a
(pure) ELF.
eu-readelf uses libdwfl to relocate addresses in the original file in
case it is ET_REL. But to show the "raw" data it might need to (re)open
the file. Which could fail if the file was compressed. And produced an
obscure error message: "cannot create EBL handle".
This rewrites __libdw_open_file a little so that the given file handle
will never be closed (whether on success or failure) and introduces a
new internal function __libdw_open_elf that dwelf_elf_begin wraps.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/readelf.c | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 79e6872a..f1a35798 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2018-10-20 Mark Wielaard <mark@klomp.org> + + * readelf.c (process_elf_file): Use dwelf_elf_begin to open pure_elf. + 2018-10-26 Mark Wielaard <mark@klomp.org> * strip.c (OPT_RELOC_DEBUG_ONLY): New define. @@ -93,11 +97,10 @@ * findtextrel.c (process_file): Check that sh_entsize is not zero. -2018-09-13 Mark Wielaard <mark@klomp.org> +2018-10-13 Mark Wielaard <mark@klomp.org> * readelf.c (print_debug_macro_section): Use elf_getdata. Print decoded flag string. -2018-09-13 Mark Wielaard <mark@klomp.org> 2018-10-19 Mark Wielaard <mark@klomp.org> diff --git a/src/readelf.c b/src/readelf.c index ccd07eb7..c6c3fb32 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -905,7 +905,6 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) if (ehdr == NULL) { - elf_error: error (0, 0, gettext ("cannot read ELF header: %s"), elf_errmsg (-1)); return; } @@ -948,7 +947,7 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) { /* Read the file afresh. */ off_t aroff = elf_getaroff (elf); - pure_elf = elf_begin (fd, ELF_C_READ_MMAP, NULL); + pure_elf = dwelf_elf_begin (fd); if (aroff > 0) { /* Archive member. */ @@ -958,7 +957,10 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) pure_elf = armem; } if (pure_elf == NULL) - goto elf_error; + { + error (0, 0, gettext ("cannot read ELF: %s"), elf_errmsg (-1)); + return; + } pure_ebl = ebl_openbackend (pure_elf); if (pure_ebl == NULL) goto ebl_error; |