From ecbe3120cddb1b9597a19a68c4265e4f2c530444 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 21 Oct 2018 23:41:32 +0200 Subject: 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 --- src/ChangeLog | 7 +++++-- src/readelf.c | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') 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 + + * readelf.c (process_elf_file): Use dwelf_elf_begin to open pure_elf. + 2018-10-26 Mark Wielaard * 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 +2018-10-13 Mark Wielaard * readelf.c (print_debug_macro_section): Use elf_getdata. Print decoded flag string. -2018-09-13 Mark Wielaard 2018-10-19 Mark Wielaard 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; -- cgit v1.2.3