]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Extend __libdw_open_file and elf_begin as *_at_offset.
authorJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 22 Feb 2014 19:54:37 +0000 (20:54 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 22 Feb 2014 20:16:26 +0000 (21:16 +0100)
./
2014-02-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

Extend __libdw_open_file and elf_begin as *_at_offset.
* NEWS (libelf): New, with elf_begin_at_offset.

libdwfl/
2014-02-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

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  <jan.kratochvil@redhat.com>

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 <jan.kratochvil@redhat.com>
NEWS
libdwfl/libdwflP.h
libdwfl/open.c
libelf/elf_begin.c
libelf/libelf.h
libelf/libelf.map

diff --git a/NEWS b/NEWS
index b774ec4e3078cf3f753db4290e8f24b6a8c20381..b0653f1d89a486322ee091bd88b185a0440665fa 100644 (file)
--- 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.
index 710e69923c94e6e382edceaabd488cf0ac3a7640..9d7157d6483a56a9068c12638a327afc52dbced0 100644 (file)
@@ -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)
index 40aac38801ef5fc2c5a29a0179fed0fcb3fcc8d3..352f73431a509c24c7058b61d6d8f7dff99164dc 100644 (file)
@@ -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);
+}
index a592fbf770756399189937475f963cfba915b2f0..5bd14eb632e0db4a134b5ab5e6f10e1d6d4b90af 100644 (file)
@@ -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)
index 5a2b3af856e0c65e7afe9c5cc23b12058827cac3..bd5157b227ee9c32afffca50566e660e3a21425b 100644 (file)
@@ -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);
 
index de6d912a1aa1187e47196e8bf203728c5459a6ef..0b563968b593c50c72b83cdb2898d38ba5a19ebf 100644 (file)
@@ -138,3 +138,8 @@ ELFUTILS_1.6 {
   global:
     elf_getphdrnum;
 } ELFUTILS_1.5;
+
+ELFUTILS_1.7 {
+  global:
+    elf_begin_at_offset;
+} ELFUTILS_1.6;