X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fbuild_id.c;h=536c74360ea83962503f7e02f1d4ba45b856cffc;hb=a8b1715b8ab974518f9713b82955f049a2c1c7ec;hp=898a15f2b316702a219a1c1959fdb278200bdbcb;hpb=70d25cae8b9769d155eb8cabf4095f2b36d9265f;p=mesa.git diff --git a/src/util/build_id.c b/src/util/build_id.c index 898a15f2b31..536c74360ea 100644 --- a/src/util/build_id.c +++ b/src/util/build_id.c @@ -22,6 +22,7 @@ */ #ifdef HAVE_DL_ITERATE_PHDR +#include #include #include #include @@ -46,7 +47,9 @@ struct build_id_note { }; struct callback_data { - const char *filename; + /* Base address of shared object, taken from Dl_info::dli_fbase */ + const void *dli_fbase; + struct build_id_note *note; }; @@ -55,14 +58,7 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_) { struct callback_data *data = data_; - /* The first object visited by callback is the main program. - * Android's libc returns a NULL pointer for the first executable. - */ - if (info->dlpi_name == NULL) - return 0; - - char *ptr = strstr(info->dlpi_name, data->filename); - if (ptr == NULL || ptr[strlen(data->filename)] != '\0') + if ((void *)info->dlpi_addr != data->dli_fbase) return 0; for (unsigned i = 0; i < info->dlpi_phnum; i++) { @@ -94,10 +90,18 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_) } const struct build_id_note * -build_id_find_nhdr(const char *filename) +build_id_find_nhdr_for_addr(const void *addr) { + Dl_info info; + + if (!dladdr(addr, &info)) + return NULL; + + if (!info.dli_fbase) + return NULL; + struct callback_data data = { - .filename = filename, + .dli_fbase = info.dli_fbase, .note = NULL, };