]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Verify file vs. core build-id, when both available
authorJan Kratochvil <jan.kratochvil@redhat.com>
Thu, 21 Nov 2013 14:31:04 +0000 (15:31 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Thu, 21 Nov 2013 14:31:04 +0000 (15:31 +0100)
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index c0fbc831dcb2f9f8f36709ef2786f29c4c80e7ea..3c2ffc8149629807aacd786b4dd5cda38d2b7044 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): New
+       variable close_elf.  Call __libdwfl_find_elf_build_id and compare the
+       content, if possible.
+
 2013-11-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        link_map: Use proper bias, not l_addr.
index 97f4a1afc273377b9ca636d8423a6e7b3a0cf95a..55f6d38838b35c0dc5fdf4899d005d9fec490de9 100644 (file)
@@ -478,20 +478,40 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
        if ((module_end > module->start && module_start < module->end)
            || dyn_vaddr == module->l_ld)
          {
+           bool close_elf = false;
            if (! module->disk_file_has_build_id && build_id_len > 0)
              {
                /* Module found in segments with build-id is more reliable
                   than a module found via DT_DEBUG on disk without any
                   build-id.   */
                if (module->elf != NULL)
+                 close_elf = true;
+             }
+           if (module->elf != NULL
+               && module->disk_file_has_build_id && build_id_len > 0)
+             {
+               const void *elf_build_id;
+               GElf_Addr elf_build_id_elfaddr;
+               int elf_build_id_len;
+
+               if (__libdwfl_find_elf_build_id (NULL, module->elf,
+                                                &elf_build_id,
+                                                &elf_build_id_elfaddr,
+                                                &elf_build_id_len) > 0)
                  {
-                   elf_end (module->elf);
-                   close (module->fd);
-                   module->elf = NULL;
-                   module->fd = -1;
+                   if (build_id_len != (size_t) elf_build_id_len
+                       || memcmp (build_id, elf_build_id, build_id_len) != 0)
+                     close_elf = true;
                  }
              }
-           else if (module->elf != NULL)
+           if (close_elf)
+             {
+               elf_end (module->elf);
+               close (module->fd);
+               module->elf = NULL;
+               module->fd = -1;
+             }
+           if (module->elf != NULL)
              {
                /* Ignore this found module if it would conflict in address
                   space with any already existing module of DWFL.  */