11 static bool check_need_swap(
int file_endian)
22 return host_endian != file_endian;
25 #define NOTE_ALIGN(sz) (((sz) + 3) & ~3)
27 #define NT_GNU_BUILD_ID 3
29 static int read_build_id(
void *note_data,
size_t note_len,
void *
bf,
30 size_t size,
bool need_swap)
40 while (ptr < (note_data + note_len)) {
42 size_t namesz, descsz;
46 nhdr->n_namesz = bswap_32(nhdr->n_namesz);
47 nhdr->n_descsz = bswap_32(nhdr->n_descsz);
48 nhdr->n_type = bswap_32(nhdr->n_type);
58 nhdr->n_namesz ==
sizeof(
"GNU")) {
59 if (
memcmp(name,
"GNU",
sizeof(
"GNU")) == 0) {
60 size_t sz =
min(size, descsz);
62 memset(bf + sz, 0, size - sz);
73 char *debuglink __maybe_unused,
74 size_t size __maybe_unused)
86 bool need_swap =
false;
92 fp = fopen(filename,
"r");
96 if (fread(e_ident,
sizeof(e_ident), 1, fp) != 1)
103 need_swap = check_need_swap(e_ident[
EI_DATA]);
112 if (fread(&ehdr,
sizeof(ehdr), 1, fp) != 1)
127 if (fread(buf, buf_size, 1, fp) != 1)
130 for (i = 0, phdr = buf; i < ehdr.
e_phnum; i++, phdr++) {
143 tmp = realloc(buf, buf_size);
149 if (fread(buf, buf_size, 1, fp) != 1)
152 ret = read_build_id(buf, buf_size, bf, size, need_swap);
161 if (fread(&ehdr,
sizeof(ehdr), 1, fp) != 1)
176 if (fread(buf, buf_size, 1, fp) != 1)
179 for (i = 0, phdr = buf; i < ehdr.
e_phnum; i++, phdr++) {
192 tmp = realloc(buf, buf_size);
198 if (fread(buf, buf_size, 1, fp) != 1)
201 ret = read_build_id(buf, buf_size, bf, size, need_swap);
226 if (fstat(fd, &stbuf) < 0)
237 ret = read_build_id(buf, buf_size, build_id, size,
false);
253 ss->
name = strdup(name);
284 struct map *
map __maybe_unused,
292 struct symsrc *runtime_ss __maybe_unused,
294 int kmodule __maybe_unused)