From: Jan Kratochvil Date: Sat, 22 Feb 2014 19:54:37 +0000 (+0100) Subject: Extend __libdw_open_file and elf_begin as *_at_offset. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45c85fe5df4559b1e8bb8f5bbf9093160dcec449;p=thirdparty%2Felfutils.git Extend __libdw_open_file and elf_begin as *_at_offset. ./ 2014-02-22 Jan Kratochvil Extend __libdw_open_file and elf_begin as *_at_offset. * NEWS (libelf): New, with elf_begin_at_offset. libdwfl/ 2014-02-22 Jan Kratochvil Extend __libdw_open_file and elf_begin as *_at_offset. * libdwflP.h (__libdw_open_file_at_offset): New declaration. * open.c (__libdw_open_file): Rename to ... (__libdw_open_file_at_offset): ... here and add parameters start_offset and maximum_size. (__libdw_open_file): New wrapper of it. libelf/ 2014-02-22 Jan Kratochvil Extend __libdw_open_file and elf_begin as *_at_offset. * elf_begin.c (elf_begin): Rename to ... (elf_begin_at_offset): ... here and add parameters start_offset and maximum_size. (elf_begin): New wrapper of it. * libelf.h (elf_begin_at_offset): New declaration. * libelf.map (ELFUTILS_1.7): New, with elf_begin_at_offset. Signed-off-by: Jan Kratochvil --- diff --git a/NEWS b/NEWS index b774ec4e3..b0653f1d8 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ Version 0.159 stack: New option -d, --debugname to lookup DWARF debuginfo name for frame. New option -i, --inlines to show inlined frames using DWARF debuginfo. +libelf: New function elf_begin_at_offset. + Version 0.158 libdwfl: dwfl_core_file_report has new parameter executable. diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h index 710e69923..9d7157d64 100644 --- a/libdwfl/libdwflP.h +++ b/libdwfl/libdwflP.h @@ -563,6 +563,16 @@ extern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) internal_function; +/* Call __libdw_open_file but the ELF file starts in *FDP at START_OFFSET and + has length MAXIMUM_SIZE. __libdw_open_file defaults to 0 and ~((size_t) 0) + respectively. */ +extern Dwfl_Error __libdw_open_file_at_offset (int *fdp, Elf **elfp, + off_t start_offset, + size_t maximum_size, + bool close_on_fail, + bool archive_ok) + internal_function; + /* Fetch PT_DYNAMIC P_VADDR from ELF and store it to *VADDRP. Return success. *VADDRP is not modified if the function fails. */ extern bool __libdwfl_dynamic_vaddr_get (Elf *elf, GElf_Addr *vaddrp) diff --git a/libdwfl/open.c b/libdwfl/open.c index 40aac3880..352f73431 100644 --- a/libdwfl/open.c +++ b/libdwfl/open.c @@ -119,11 +119,14 @@ what_kind (int fd, Elf **elfp, Elf_Kind *kind, bool *close_fd) } Dwfl_Error internal_function -__libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) +__libdw_open_file_at_offset (int *fdp, Elf **elfp, off_t start_offset, + size_t maximum_size, bool close_on_fail, + bool archive_ok) { bool close_fd = false; - Elf *elf = elf_begin (*fdp, ELF_C_READ_MMAP_PRIVATE, NULL); + Elf *elf = elf_begin_at_offset (*fdp, ELF_C_READ_MMAP_PRIVATE, NULL, + start_offset, maximum_size); Elf_Kind kind; Dwfl_Error error = what_kind (*fdp, &elf, &kind, &close_fd); @@ -180,3 +183,10 @@ __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) *elfp = elf; return error; } + +Dwfl_Error internal_function +__libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) +{ + return __libdw_open_file_at_offset (fdp, elfp, 0, ~((size_t) 0), + close_on_fail, archive_ok); +} diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index a592fbf77..5bd14eb63 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -1013,10 +1013,8 @@ write_file (int fd, Elf_Cmd cmd) /* Return a descriptor for the file belonging to FILDES. */ Elf * -elf_begin (fildes, cmd, ref) - int fildes; - Elf_Cmd cmd; - Elf *ref; +elf_begin_at_offset (int fildes, Elf_Cmd cmd, Elf *ref, off_t start_offset, + size_t maximum_size) { Elf *retval; @@ -1073,7 +1071,7 @@ elf_begin (fildes, cmd, ref) retval = lock_dup_elf (); else /* Create descriptor for existing file. */ - retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL); + retval = read_file (fildes, start_offset, maximum_size, cmd, NULL); break; case ELF_C_RDWR: @@ -1095,7 +1093,7 @@ elf_begin (fildes, cmd, ref) } else /* Create descriptor for existing file. */ - retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL); + retval = read_file (fildes, start_offset, maximum_size, cmd, NULL); break; case ELF_C_WRITE: @@ -1116,4 +1114,14 @@ elf_begin (fildes, cmd, ref) return retval; } +INTDEF(elf_begin_at_offset) + +Elf * +elf_begin (fildes, cmd, ref) + int fildes; + Elf_Cmd cmd; + Elf *ref; +{ + return elf_begin_at_offset (fildes, cmd, ref, 0, ~((size_t) 0)); +} INTDEF(elf_begin) diff --git a/libelf/libelf.h b/libelf/libelf.h index 5a2b3af85..bd5157b22 100644 --- a/libelf/libelf.h +++ b/libelf/libelf.h @@ -164,6 +164,12 @@ extern "C" { /* Return descriptor for ELF file to work according to CMD. */ extern Elf *elf_begin (int __fildes, Elf_Cmd __cmd, Elf *__ref); +/* Call elf_begin but the ELF file starts in FILDES at START_OFFSET and + has length MAXIMUM_SIZE. elf_begin defaults to 0 and ~((size_t) 0) + respectively. */ +extern Elf *elf_begin_at_offset (int fildes, Elf_Cmd __cmd, Elf *__ref, + off_t start_offset, size_t maximum_size); + /* Create a clone of an existing ELF descriptor. */ extern Elf *elf_clone (Elf *__elf, Elf_Cmd __cmd); diff --git a/libelf/libelf.map b/libelf/libelf.map index de6d912a1..0b563968b 100644 --- a/libelf/libelf.map +++ b/libelf/libelf.map @@ -138,3 +138,8 @@ ELFUTILS_1.6 { global: elf_getphdrnum; } ELFUTILS_1.5; + +ELFUTILS_1.7 { + global: + elf_begin_at_offset; +} ELFUTILS_1.6;