summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2019-04-25 10:37:18 -0700
committerMatt Turner <mattst88@gmail.com>2019-04-25 10:52:20 -0700
commitdf84371bae98aa0724aa7926822da44cbcd3fbca (patch)
tree5eae3627524c58cf848226df17f196b888cba323
parent8f13b4246acddd0cde1d34f81f4329dc22649d7d (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.c17
1 files 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)