From df84371bae98aa0724aa7926822da44cbcd3fbca Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Thu, 25 Apr 2019 10:37:18 -0700 Subject: Fix address comparison for binaries with LOAD vaddr > 0 Cherry-picked from Mesa commit 02e2009b929a (util/build-id: Fix address comparison for binaries with LOAD vaddr > 0) by Stephan Gerhold. --- build-id.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/build-id.c b/build-id.c index e686335..900f507 100644 --- a/build-id.c +++ b/build-id.c @@ -68,8 +68,21 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_) if (data->tag == BY_NAME && strcmp(info->dlpi_name, data->name) != 0) return 0; - if (data->tag == BY_SYMBOL && (void *)info->dlpi_addr != data->dli_fbase) - return 0; + if (data->tag == BY_SYMBOL) { + /* Calculate address where shared object is mapped into the process space. + * (Using the base address and the virtual address of the first LOAD segment) + */ + void *map_start = NULL; + for (unsigned i = 0; i < info->dlpi_phnum; i++) { + if (info->dlpi_phdr[i].p_type == PT_LOAD) { + map_start = (void *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr); + break; + } + } + + if (map_start != data->dli_fbase) + return 0; + } for (unsigned i = 0; i < info->dlpi_phnum; i++) { if (info->dlpi_phdr[i].p_type != PT_NOTE) -- cgit v1.2.3