symbol-minimal.c (b746a1a2860f4a918f32d10dc569115d282aaf2f) symbol-minimal.c (f766819cd5290d42efa55c505b9bed184fec17bf)
1#include "dso.h"
2#include "symbol.h"
3#include "symsrc.h"
4
5#include <errno.h>
6#include <unistd.h>
7#include <stdio.h>
8#include <fcntl.h>

--- 17 unchanged lines hidden (view full) ---

26
27 return host_endian != file_endian;
28}
29
30#define NOTE_ALIGN(sz) (((sz) + 3) & ~3)
31
32#define NT_GNU_BUILD_ID 3
33
1#include "dso.h"
2#include "symbol.h"
3#include "symsrc.h"
4
5#include <errno.h>
6#include <unistd.h>
7#include <stdio.h>
8#include <fcntl.h>

--- 17 unchanged lines hidden (view full) ---

26
27 return host_endian != file_endian;
28}
29
30#define NOTE_ALIGN(sz) (((sz) + 3) & ~3)
31
32#define NT_GNU_BUILD_ID 3
33
34static int read_build_id(void *note_data, size_t note_len, void *bf,
35 size_t size, bool need_swap)
34static int read_build_id(void *note_data, size_t note_len, struct build_id *bid,
35 bool need_swap)
36{
36{
37 size_t size = sizeof(bid->data);
37 struct {
38 u32 n_namesz;
39 u32 n_descsz;
40 u32 n_type;
41 } *nhdr;
42 void *ptr;
43
44 ptr = note_data;

--- 13 unchanged lines hidden (view full) ---

58
59 ptr += sizeof(*nhdr);
60 name = ptr;
61 ptr += namesz;
62 if (nhdr->n_type == NT_GNU_BUILD_ID &&
63 nhdr->n_namesz == sizeof("GNU")) {
64 if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
65 size_t sz = min(size, descsz);
38 struct {
39 u32 n_namesz;
40 u32 n_descsz;
41 u32 n_type;
42 } *nhdr;
43 void *ptr;
44
45 ptr = note_data;

--- 13 unchanged lines hidden (view full) ---

59
60 ptr += sizeof(*nhdr);
61 name = ptr;
62 ptr += namesz;
63 if (nhdr->n_type == NT_GNU_BUILD_ID &&
64 nhdr->n_namesz == sizeof("GNU")) {
65 if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
66 size_t sz = min(size, descsz);
66 memcpy(bf, ptr, sz);
67 memset(bf + sz, 0, size - sz);
67 memcpy(bid->data, ptr, sz);
68 memset(bid->data + sz, 0, size - sz);
69 bid->size = sz;
68 return 0;
69 }
70 }
71 ptr += descsz;
72 }
73
74 return -1;
75}
76
77int filename__read_debuglink(const char *filename __maybe_unused,
78 char *debuglink __maybe_unused,
79 size_t size __maybe_unused)
80{
81 return -1;
82}
83
84/*
85 * Just try PT_NOTE header otherwise fails
86 */
70 return 0;
71 }
72 }
73 ptr += descsz;
74 }
75
76 return -1;
77}
78
79int filename__read_debuglink(const char *filename __maybe_unused,
80 char *debuglink __maybe_unused,
81 size_t size __maybe_unused)
82{
83 return -1;
84}
85
86/*
87 * Just try PT_NOTE header otherwise fails
88 */
87int filename__read_build_id(const char *filename, void *bf, size_t size)
89int filename__read_build_id(const char *filename, struct build_id *bid)
88{
89 FILE *fp;
90 int ret = -1;
91 bool need_swap = false;
92 u8 e_ident[EI_NIDENT];
93 size_t buf_size;
94 void *buf;
95 int i;

--- 55 unchanged lines hidden (view full) ---

151 if (tmp == NULL)
152 goto out_free;
153
154 buf = tmp;
155 fseek(fp, offset, SEEK_SET);
156 if (fread(buf, buf_size, 1, fp) != 1)
157 goto out_free;
158
90{
91 FILE *fp;
92 int ret = -1;
93 bool need_swap = false;
94 u8 e_ident[EI_NIDENT];
95 size_t buf_size;
96 void *buf;
97 int i;

--- 55 unchanged lines hidden (view full) ---

153 if (tmp == NULL)
154 goto out_free;
155
156 buf = tmp;
157 fseek(fp, offset, SEEK_SET);
158 if (fread(buf, buf_size, 1, fp) != 1)
159 goto out_free;
160
159 ret = read_build_id(buf, buf_size, bf, size, need_swap);
161 ret = read_build_id(buf, buf_size, bid, need_swap);
160 if (ret == 0)
162 if (ret == 0)
161 ret = size;
163 ret = bid->size;
162 break;
163 }
164 } else {
165 Elf64_Ehdr ehdr;
166 Elf64_Phdr *phdr;
167
168 if (fread(&ehdr, sizeof(ehdr), 1, fp) != 1)
169 goto out;

--- 32 unchanged lines hidden (view full) ---

202 if (tmp == NULL)
203 goto out_free;
204
205 buf = tmp;
206 fseek(fp, offset, SEEK_SET);
207 if (fread(buf, buf_size, 1, fp) != 1)
208 goto out_free;
209
164 break;
165 }
166 } else {
167 Elf64_Ehdr ehdr;
168 Elf64_Phdr *phdr;
169
170 if (fread(&ehdr, sizeof(ehdr), 1, fp) != 1)
171 goto out;

--- 32 unchanged lines hidden (view full) ---

204 if (tmp == NULL)
205 goto out_free;
206
207 buf = tmp;
208 fseek(fp, offset, SEEK_SET);
209 if (fread(buf, buf_size, 1, fp) != 1)
210 goto out_free;
211
210 ret = read_build_id(buf, buf_size, bf, size, need_swap);
212 ret = read_build_id(buf, buf_size, bid, need_swap);
211 if (ret == 0)
213 if (ret == 0)
212 ret = size;
214 ret = bid->size;
213 break;
214 }
215 }
216out_free:
217 free(buf);
218out:
219 fclose(fp);
220 return ret;
221}
222
215 break;
216 }
217 }
218out_free:
219 free(buf);
220out:
221 fclose(fp);
222 return ret;
223}
224
223int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
225int sysfs__read_build_id(const char *filename, void *build_id, size_t size __maybe_unused)
224{
226{
227 struct build_id bid;
225 int fd;
226 int ret = -1;
227 struct stat stbuf;
228 size_t buf_size;
229 void *buf;
230
231 fd = open(filename, O_RDONLY);
232 if (fd < 0)

--- 5 unchanged lines hidden (view full) ---

238 buf_size = stbuf.st_size;
239 buf = malloc(buf_size);
240 if (buf == NULL)
241 goto out;
242
243 if (read(fd, buf, buf_size) != (ssize_t) buf_size)
244 goto out_free;
245
228 int fd;
229 int ret = -1;
230 struct stat stbuf;
231 size_t buf_size;
232 void *buf;
233
234 fd = open(filename, O_RDONLY);
235 if (fd < 0)

--- 5 unchanged lines hidden (view full) ---

241 buf_size = stbuf.st_size;
242 buf = malloc(buf_size);
243 if (buf == NULL)
244 goto out;
245
246 if (read(fd, buf, buf_size) != (ssize_t) buf_size)
247 goto out_free;
248
246 ret = read_build_id(buf, buf_size, build_id, size, false);
249 ret = read_build_id(buf, buf_size, &bid, false);
250 if (ret > 0)
251 memcpy(build_id, bid.data, bid.size);
247out_free:
248 free(buf);
249out:
250 close(fd);
251 return ret;
252}
253
254int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,

--- 79 unchanged lines hidden (view full) ---

334 return DSO__TYPE_32BIT;
335}
336
337int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,
338 struct symsrc *ss,
339 struct symsrc *runtime_ss __maybe_unused,
340 int kmodule __maybe_unused)
341{
252out_free:
253 free(buf);
254out:
255 close(fd);
256 return ret;
257}
258
259int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,

--- 79 unchanged lines hidden (view full) ---

339 return DSO__TYPE_32BIT;
340}
341
342int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,
343 struct symsrc *ss,
344 struct symsrc *runtime_ss __maybe_unused,
345 int kmodule __maybe_unused)
346{
342 unsigned char build_id[BUILD_ID_SIZE];
347 struct build_id bid;
343 int ret;
344
345 ret = fd__is_64_bit(ss->fd);
346 if (ret >= 0)
347 dso->is_64_bit = ret;
348
348 int ret;
349
350 ret = fd__is_64_bit(ss->fd);
351 if (ret >= 0)
352 dso->is_64_bit = ret;
353
349 if (filename__read_build_id(ss->name, build_id, BUILD_ID_SIZE) > 0) {
350 dso__set_build_id(dso, build_id);
351 }
354 if (filename__read_build_id(ss->name, &bid) > 0)
355 dso__set_build_id(dso, bid.data);
352 return 0;
353}
354
355int file__read_maps(int fd __maybe_unused, bool exe __maybe_unused,
356 mapfn_t mapfn __maybe_unused, void *data __maybe_unused,
357 bool *is_64_bit __maybe_unused)
358{
359 return -1;

--- 27 unchanged lines hidden ---
356 return 0;
357}
358
359int file__read_maps(int fd __maybe_unused, bool exe __maybe_unused,
360 mapfn_t mapfn __maybe_unused, void *data __maybe_unused,
361 bool *is_64_bit __maybe_unused)
362{
363 return -1;

--- 27 unchanged lines hidden ---