16 u8 *
check = (u8 *)&data;
20 host_endian = ELFDATA2LSB;
22 host_endian = ELFDATA2MSB;
24 return host_endian != file_endian;
27 #define NOTE_ALIGN(sz) (((sz) + 3) & ~3) 29 #define NT_GNU_BUILD_ID 3 32 size_t size,
bool need_swap)
42 while (ptr < (note_data + note_len)) {
44 size_t namesz, descsz;
48 nhdr->n_namesz = bswap_32(nhdr->n_namesz);
49 nhdr->n_descsz = bswap_32(nhdr->n_descsz);
50 nhdr->n_type = bswap_32(nhdr->n_type);
60 nhdr->n_namesz ==
sizeof(
"GNU")) {
61 if (memcmp(name,
"GNU",
sizeof(
"GNU")) == 0) {
62 size_t sz =
min(size, descsz);
64 memset(bf + sz, 0, size - sz);
75 char *debuglink __maybe_unused,
76 size_t size __maybe_unused)
88 bool need_swap =
false;
89 u8 e_ident[EI_NIDENT];
94 fp = fopen(filename,
"r");
98 if (fread(e_ident,
sizeof(e_ident), 1, fp) != 1)
101 if (memcmp(e_ident, ELFMAG, SELFMAG) ||
102 e_ident[EI_VERSION] != EV_CURRENT)
108 fseek(fp, 0, SEEK_SET);
110 if (e_ident[EI_CLASS] == ELFCLASS32) {
114 if (fread(&ehdr,
sizeof(ehdr), 1, fp) != 1)
118 ehdr.e_phoff = bswap_32(ehdr.e_phoff);
119 ehdr.e_phentsize = bswap_16(ehdr.e_phentsize);
120 ehdr.e_phnum = bswap_16(ehdr.e_phnum);
123 buf_size = ehdr.e_phentsize * ehdr.e_phnum;
128 fseek(fp, ehdr.e_phoff, SEEK_SET);
129 if (fread(buf, buf_size, 1, fp) != 1)
132 for (i = 0, phdr = buf; i < ehdr.e_phnum; i++, phdr++) {
137 phdr->p_type = bswap_32(phdr->p_type);
138 phdr->p_offset = bswap_32(phdr->p_offset);
139 phdr->p_filesz = bswap_32(phdr->p_filesz);
142 if (phdr->p_type != PT_NOTE)
145 buf_size = phdr->p_filesz;
146 offset = phdr->p_offset;
147 tmp = realloc(buf, buf_size);
152 fseek(fp, offset, SEEK_SET);
153 if (fread(buf, buf_size, 1, fp) != 1)
165 if (fread(&ehdr,
sizeof(ehdr), 1, fp) != 1)
169 ehdr.e_phoff = bswap_64(ehdr.e_phoff);
170 ehdr.e_phentsize = bswap_16(ehdr.e_phentsize);
171 ehdr.e_phnum = bswap_16(ehdr.e_phnum);
174 buf_size = ehdr.e_phentsize * ehdr.e_phnum;
179 fseek(fp, ehdr.e_phoff, SEEK_SET);
180 if (fread(buf, buf_size, 1, fp) != 1)
183 for (i = 0, phdr = buf; i < ehdr.e_phnum; i++, phdr++) {
188 phdr->p_type = bswap_32(phdr->p_type);
189 phdr->p_offset = bswap_64(phdr->p_offset);
190 phdr->p_filesz = bswap_64(phdr->p_filesz);
193 if (phdr->p_type != PT_NOTE)
196 buf_size = phdr->p_filesz;
197 offset = phdr->p_offset;
198 tmp = realloc(buf, buf_size);
203 fseek(fp, offset, SEEK_SET);
204 if (fread(buf, buf_size, 1, fp) != 1)
228 fd = open(filename, O_RDONLY);
232 if (fstat(fd, &stbuf) < 0)
235 buf_size = stbuf.st_size;
240 if (read(fd, buf, buf_size) != (ssize_t) buf_size)
254 int fd = open(name, O_RDONLY);
258 ss->
name = strdup(name);
291 struct symsrc *ss __maybe_unused)
298 u8 e_ident[EI_NIDENT];
300 if (lseek(fd, 0, SEEK_SET))
303 if (
readn(fd, e_ident,
sizeof(e_ident)) !=
sizeof(e_ident))
306 if (memcmp(e_ident, ELFMAG, SELFMAG) ||
307 e_ident[EI_VERSION] != EV_CURRENT)
310 return e_ident[EI_CLASS] == ELFCLASS64;
325 if (
readn(fd, &ehdr,
sizeof(ehdr)) !=
sizeof(ehdr))
328 if (ehdr.e_machine == EM_X86_64)
336 struct symsrc *runtime_ss __maybe_unused,
337 int kmodule __maybe_unused)
353 mapfn_t mapfn __maybe_unused,
void *
data __maybe_unused,
354 bool *is_64_bit __maybe_unused)
369 const char *to_dir __maybe_unused)
379 int kmodule __maybe_unused,
380 const char *elf_name __maybe_unused)
int(* mapfn_t)(u64 start, u64 len, u64 pgoff, void *data)
static int fd__is_64_bit(int fd)
ssize_t readn(int fd, void *buf, size_t n)
int filename__read_build_id(const char *filename, void *bf, size_t size)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
enum dso_load_errno load_errno
void symbol__elf_init(void)
void symsrc__destroy(struct symsrc *ss)
static int read_build_id(void *note_data, size_t note_len, void *bf, size_t size, bool need_swap)
static bool check_need_swap(int file_endian)
enum dso_binary_type type
int kcore_extract__create(struct kcore_extract *kce __maybe_unused)
int dso__load_sym(struct dso *dso, struct map *map __maybe_unused, struct symsrc *ss, struct symsrc *runtime_ss __maybe_unused, int kmodule __maybe_unused)
int dso__synthesize_plt_symbols(struct dso *dso __maybe_unused, struct symsrc *ss __maybe_unused)
int file__read_maps(int fd __maybe_unused, bool exe __maybe_unused, mapfn_t mapfn __maybe_unused, void *data __maybe_unused, bool *is_64_bit __maybe_unused)
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, enum dso_binary_type type)
char * dso__demangle_sym(struct dso *dso __maybe_unused, int kmodule __maybe_unused, const char *elf_name __maybe_unused)
int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
int filename__read_debuglink(const char *filename __maybe_unused, char *debuglink __maybe_unused, size_t size __maybe_unused)
bool symsrc__has_symtab(struct symsrc *ss __maybe_unused)
enum dso_type dso__type_fd(int fd)
void dso__set_build_id(struct dso *dso, void *build_id)
void kcore_extract__delete(struct kcore_extract *kce __maybe_unused)
static int check(union perf_mem_data_src data_src, const char *string)
bool symsrc__possibly_runtime(struct symsrc *ss __maybe_unused)
int kcore_copy(const char *from_dir __maybe_unused, const char *to_dir __maybe_unused)