*/
#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 {
};
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;
};
{
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++) {
}
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,
};
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