util: hashtable: make hashing prototypes match
[mesa.git] / src / util / build_id.c
index 2993a80cfe6abede915b610ae98a668a14c72b3e..536c74360ea83962503f7e02f1d4ba45b856cffc 100644 (file)
  */
 
 #ifdef HAVE_DL_ITERATE_PHDR
+#include <dlfcn.h>
 #include <link.h>
 #include <stddef.h>
 #include <string.h>
 
 #include "build_id.h"
 
+#ifndef NT_GNU_BUILD_ID
+#define NT_GNU_BUILD_ID 3
+#endif
+
+#ifndef ElfW
+#define ElfW(type) Elf_##type
+#endif
+
 #define ALIGN(val, align)      (((val) + (align) - 1) & ~((align) - 1))
 
 struct build_id_note {
@@ -38,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;
 };
 
@@ -47,8 +58,7 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_)
 {
    struct callback_data *data = data_;
 
-   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++) {
@@ -80,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,
    };
 
@@ -99,11 +117,10 @@ build_id_length(const struct build_id_note *note)
    return note->nhdr.n_descsz;
 }
 
-void
-build_id_read(const struct build_id_note *note,
-              unsigned char *build_id, size_t n)
+const uint8_t *
+build_id_data(const struct build_id_note *note)
 {
-   memcpy(build_id, note->build_id, n);
+   return note->build_id;
 }
 
 #endif