diff options
author | Matt Turner <mattst88@gmail.com> | 2019-04-25 10:37:18 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2019-04-25 10:52:20 -0700 |
commit | df84371bae98aa0724aa7926822da44cbcd3fbca (patch) | |
tree | 5eae3627524c58cf848226df17f196b888cba323 | |
parent | 8f13b4246acddd0cde1d34f81f4329dc22649d7d (diff) |
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.
-rw-r--r-- | build-id.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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) |