]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
fixup for DRAFT e38ce78: cache Elf * in open_elf
authorSerhei Makarov <serhei@serhei.io>
Mon, 3 Feb 2025 21:45:20 +0000 (16:45 -0500)
committerSerhei Makarov <serhei@serhei.io>
Mon, 3 Feb 2025 21:45:28 +0000 (16:45 -0500)
Caching behaviour is improving. The commented assert still catches
some cases where a redundant Elf * is being created.

* dwfl_module_getdwarf.c (open_elf): Cache file->elf in Dwfl_Process_Tracker.

libdwfl/dwfl_module_getdwarf.c
libdwfl/dwfl_process_tracker_find_elf.c

index 6f98c02b4f3fe675ec1ef4b3f677a542751a7b2a..6aa87fdfda309cdcb580a5e0f6f9c08d2c693aa0 100644 (file)
@@ -79,6 +79,18 @@ open_elf (Dwfl_Module *mod, struct dwfl_file *file)
   if (error != DWFL_E_NOERROR)
     return error;
 
+  /* Cache file->elf in Dwfl_Process_Tracker if available: */
+  if (mod->dwfl->tracker != NULL && file->name != NULL)
+    {
+      dwfltracker_elftab_ent *ent = __libdwfl_process_tracker_elftab_find (mod->dwfl->tracker, file->name, false/* should_resize */);
+      if (ent != NULL)
+       {
+         /* assert(ent->elf == NULL || ent->elf == file->elf); */ /* TODO(PRERELEASE): Guard against redundant/leaked Elf *. */
+         assert(ent->fd == file->fd); /* TODO(PRERELEASE): Guard against redundant open. */
+         ent->elf = file->elf;
+       }
+    }
+
   GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (file->elf, &ehdr_mem);
   if (ehdr == NULL)
     {
index d1871071f59cd1a5f7688d60b32cfa939d0308a5..20c48beacb570e1713afba7bb1f434186c30e100 100644 (file)
@@ -82,7 +82,6 @@ dwfl_process_tracker_find_elf (Dwfl_Module *mod,
   /* XXX fd < 0 implies elf_from_remote_memory, uses base, not cacheable */
   if (tracker != NULL && ent != NULL && fd >= 0 && *file_name != NULL)
     {
-      /* TODO(WIP): *elfp may be NULL here, need to be populated later. */
       ent->elf = *elfp;
       ent->fd = fd;
       rc = fstat(fd, &sb);