X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futil%2Fbuild_id.c;h=8b4f8f30afb560fb26479c5c2bb4cbff8ba686ff;hb=d415748955034b659c8b577adc727b1fd39948b8;hp=6280b4a54e363fe95aa79051d0dd6fe439cce401;hpb=5c98d3825ccbed9054a1bb2de607116b2b31d48b;p=mesa.git diff --git a/src/util/build_id.c b/src/util/build_id.c index 6280b4a54e3..8b4f8f30afb 100644 --- a/src/util/build_id.c +++ b/src/util/build_id.c @@ -22,11 +22,13 @@ */ #ifdef HAVE_DL_ITERATE_PHDR +#include #include #include #include #include "build_id.h" +#include "macros.h" #ifndef NT_GNU_BUILD_ID #define NT_GNU_BUILD_ID 3 @@ -36,8 +38,6 @@ #define ElfW(type) Elf_##type #endif -#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1)) - struct build_id_note { ElfW(Nhdr) nhdr; @@ -57,7 +57,18 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_) { struct callback_data *data = data_; - if ((void *)info->dlpi_addr != data->dli_fbase) + /* 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++) { @@ -78,8 +89,8 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_) } size_t offset = sizeof(ElfW(Nhdr)) + - ALIGN(note->nhdr.n_namesz, 4) + - ALIGN(note->nhdr.n_descsz, 4); + ALIGN_POT(note->nhdr.n_namesz, 4) + + ALIGN_POT(note->nhdr.n_descsz, 4); note = (struct build_id_note *)((char *)note + offset); len -= offset; }