]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
+dwfl_report_elf_baseaddr
authorJan Kratochvil <jan.kratochvil@redhat.com>
Mon, 12 Nov 2012 14:41:10 +0000 (15:41 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Mon, 12 Nov 2012 14:41:10 +0000 (15:41 +0100)
libdwfl/dwfl_report_elf.c
libdwfl/libdwfl.h
libdwfl/libdwflP.h
libdwfl/offline.c

index d7061704cbc57f780712a251ec14df1323ccad1e..08ad37c8bfc707e5a901a67c237b2b93a4f1a4fb 100644 (file)
@@ -41,7 +41,8 @@
 Dwfl_Module *
 internal_function
 __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
-                     int fd, Elf *elf, GElf_Addr base, bool sanity)
+                     int fd, Elf *elf, GElf_Addr base, bool base_is_bias,
+                     bool sanity)
 {
   GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
   if (ehdr == NULL)
@@ -181,11 +182,19 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
            {
              vaddr = ph->p_vaddr & -ph->p_align;
              address_sync = ph->p_vaddr + ph->p_memsz;
-             start = base + vaddr;
              break;
            }
        }
-      bias = base;
+      if (base_is_bias)
+       {
+         start = base + vaddr;
+         bias = base;
+       }
+      else
+       {
+         start = base;
+         bias = base - vaddr;
+       }
 
       for (size_t i = phnum; i-- > 0;)
        {
@@ -195,7 +204,7 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
          if (ph->p_type == PT_LOAD
              && ph->p_vaddr + ph->p_memsz > 0)
            {
-             end = base + (ph->p_vaddr + ph->p_memsz);
+             end = bias + (ph->p_vaddr + ph->p_memsz);
              break;
            }
        }
@@ -246,8 +255,9 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
 }
 
 Dwfl_Module *
-dwfl_report_elf (Dwfl *dwfl, const char *name,
-                const char *file_name, int fd, GElf_Addr base)
+internal_function
+__libdwfl_report_elf_open (Dwfl *dwfl, const char *name, const char *file_name,
+                          int fd, GElf_Addr base, bool base_is_bias)
 {
   bool closefd = false;
   if (fd < 0)
@@ -270,7 +280,7 @@ dwfl_report_elf (Dwfl *dwfl, const char *name,
     }
 
   Dwfl_Module *mod = __libdwfl_report_elf (dwfl, name, file_name,
-                                          fd, elf, base, true);
+                                          fd, elf, base, base_is_bias, true);
   if (mod == NULL)
     {
       elf_end (elf);
@@ -280,4 +290,19 @@ dwfl_report_elf (Dwfl *dwfl, const char *name,
 
   return mod;
 }
+
+Dwfl_Module *
+dwfl_report_elf (Dwfl *dwfl, const char *name,
+                const char *file_name, int fd, GElf_Addr base)
+{
+  return __libdwfl_report_elf_open (dwfl, name, file_name, fd, base, true);
+}
 INTDEF (dwfl_report_elf)
+
+Dwfl_Module *
+dwfl_report_elf_baseaddr (Dwfl *dwfl, const char *name,
+                         const char *file_name, int fd, GElf_Addr base)
+{
+  return __libdwfl_report_elf_open (dwfl, name, file_name, fd, base, false);
+}
+INTDEF (dwfl_report_elf_baseaddr)
index 8498c0cdb28e260585d5d1454e5fa6947c9d52d4..a2ab8246dadec92026e16705107172016c928266 100644 (file)
@@ -146,6 +146,13 @@ extern Dwfl_Module *dwfl_report_elf (Dwfl *dwfl, const char *name,
                                     const char *file_name, int fd,
                                     GElf_Addr base);
 
+/* See dwfl_report_elf except that BASE is the page-aligned absolute VMA
+   address where the ELF file should start.  Any possible file prelinking of
+   the disk file is compensated.  */
+extern Dwfl_Module *dwfl_report_elf_baseaddr (Dwfl *dwfl, const char *name,
+                                             const char *file_name, int fd,
+                                             GElf_Addr base);
+
 /* Similar, but report the module for offline use.  All ET_EXEC files
    being reported must be reported before any relocatable objects.
    If this is used, dwfl_report_module and dwfl_report_elf may not be
index ca8be2f2a557374afd0c142a4d3903c6d439d8bc..e5e638c98fdc76a7713b71deb62b42df3d349f55 100644 (file)
@@ -353,7 +353,8 @@ extern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden;
    Consumes ELF on success, not on failure.  */
 extern Dwfl_Module *__libdwfl_report_elf (Dwfl *dwfl, const char *name,
                                          const char *file_name, int fd,
-                                         Elf *elf, GElf_Addr base, bool sanity)
+                                         Elf *elf, GElf_Addr base,
+                                         bool base_is_bias, bool sanity)
   internal_function;
 
 /* Meat of dwfl_report_offline.  */
index 26a6bd664dd55b1b284018c044ca1dc72f452933..28d2782e8a879a2ef6e18973738aacb3427b25e2 100644 (file)
@@ -127,7 +127,8 @@ process_elf (Dwfl *dwfl, const char *name, const char *file_name, int fd,
             Elf *elf)
 {
   Dwfl_Module *mod = __libdwfl_report_elf (dwfl, name, file_name, fd, elf,
-                                          dwfl->offline_next_address, false);
+                                          dwfl->offline_next_address, true,
+                                          false);
   if (mod != NULL)
     {
       /* If this is an ET_EXEC file with fixed addresses, the address range