summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2014-02-22 20:54:37 +0100
committerJan Kratochvil <jan.kratochvil@redhat.com>2014-02-22 21:16:26 +0100
commit45c85fe5df4559b1e8bb8f5bbf9093160dcec449 (patch)
tree122644d7a4162b92c28d092424fede67a990439e
parent43c9c2d0d8422cb584e3c97df5edde5d7be53173 (diff)
downloadelfutils-45c85fe5df4559b1e8bb8f5bbf9093160dcec449.tar.gz
Extend __libdw_open_file and elf_begin as *_at_offset.
./ 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>
-rw-r--r--NEWS2
-rw-r--r--libdwfl/libdwflP.h10
-rw-r--r--libdwfl/open.c14
-rw-r--r--libelf/elf_begin.c20
-rw-r--r--libelf/libelf.h6
-rw-r--r--libelf/libelf.map5
6 files changed, 49 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index b774ec4e..b0653f1d 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 710e6992..9d7157d6 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 40aac388..352f7343 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 a592fbf7..5bd14eb6 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 5a2b3af8..bd5157b2 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 de6d912a..0b563968 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;