From: Serhei Makarov Date: Mon, 3 Feb 2025 21:45:20 +0000 (-0500) Subject: fixup for DRAFT e38ce78: cache Elf * in open_elf X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4c0992f6dda5ed9e62190a808a2cd4d651a9220;p=thirdparty%2Felfutils.git fixup for DRAFT e38ce78: cache Elf * in open_elf 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. --- diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index 6f98c02b..6aa87fdf 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -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) { diff --git a/libdwfl/dwfl_process_tracker_find_elf.c b/libdwfl/dwfl_process_tracker_find_elf.c index d1871071..20c48bea 100644 --- a/libdwfl/dwfl_process_tracker_find_elf.c +++ b/libdwfl/dwfl_process_tracker_find_elf.c @@ -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);