Lines Matching full:elf
77 static int elf_getphdrnum(Elf *elf, size_t *dst) in elf_getphdrnum() argument
82 ehdr = gelf_getehdr(elf, &gehdr); in elf_getphdrnum()
93 static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused) in elf_getshdrstrndx()
190 static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) in elf_addr_to_index() argument
196 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_addr_to_index()
209 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, in elf_section_by_name() argument
215 /* Elf is corrupted/truncated, avoid calling elf_strptr. */ in elf_section_by_name()
216 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) in elf_section_by_name()
219 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_section_by_name()
223 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); in elf_section_by_name()
235 static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr) in elf_read_program_header() argument
240 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_program_header()
244 if (gelf_getphdr(elf, i, phdr) == NULL) in elf_read_program_header()
323 Elf *elf; in dso__synthesize_plt_symbols() local
329 elf = ss->elf; in dso__synthesize_plt_symbols()
339 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
342 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
353 if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL) in dso__synthesize_plt_symbols()
368 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); in dso__synthesize_plt_symbols()
483 static int elf_read_build_id(Elf *elf, void *bf, size_t size) in elf_read_build_id() argument
496 ek = elf_kind(elf); in elf_read_build_id()
500 if (gelf_getehdr(elf, &ehdr) == NULL) { in elf_read_build_id()
501 pr_err("%s: cannot get elf header.\n", __func__); in elf_read_build_id()
512 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
517 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
522 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
597 Elf *elf; in filename__read_build_id() local
606 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__read_build_id()
607 if (elf == NULL) { in filename__read_build_id()
608 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in filename__read_build_id()
612 err = elf_read_build_id(elf, bid->data, size); in filename__read_build_id()
616 elf_end(elf); in filename__read_build_id()
717 Elf *elf; in filename__read_debuglink() local
728 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__read_debuglink()
729 if (elf == NULL) { in filename__read_debuglink()
730 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in filename__read_debuglink()
734 ek = elf_kind(elf); in filename__read_debuglink()
738 if (gelf_getehdr(elf, &ehdr) == NULL) { in filename__read_debuglink()
739 pr_err("%s: cannot get elf header.\n", __func__); in filename__read_debuglink()
743 sec = elf_section_by_name(elf, &ehdr, &shdr, in filename__read_debuglink()
758 elf_end(elf); in filename__read_debuglink()
807 elf_end(ss->elf); in symsrc__destroy()
814 * Usually vmlinux is an ELF file with type ET_EXEC for most in elf__needs_adjust_symbols()
826 Elf *elf; in symsrc__init() local
843 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in symsrc__init()
844 if (elf == NULL) { in symsrc__init()
845 pr_debug("%s: cannot read %s ELF file.\n", __func__, name); in symsrc__init()
850 if (gelf_getehdr(elf, &ehdr) == NULL) { in symsrc__init()
852 pr_debug("%s: cannot get elf header.\n", __func__); in symsrc__init()
867 size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE); in symsrc__init()
881 ss->is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in symsrc__init()
883 ss->symtab = elf_section_by_name(elf, &ehdr, &ss->symshdr, ".symtab", in symsrc__init()
889 ss->dynsym = elf_section_by_name(elf, &ehdr, &ss->dynshdr, ".dynsym", in symsrc__init()
895 ss->opdsec = elf_section_by_name(elf, &ehdr, &ss->opdshdr, ".opd", in symsrc__init()
911 ss->elf = elf; in symsrc__init()
919 elf_end(elf); in symsrc__init()
1083 Elf *elf; in dso__load_sym() local
1114 elf = syms_ss->elf; in dso__load_sym()
1119 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, in dso__load_sym()
1130 sec = elf_getscn(elf, shdr.sh_link); in dso__load_sym()
1138 sec_strndx = elf_getscn(runtime_ss->elf, runtime_ss->ehdr.e_shstrndx); in dso__load_sym()
1194 /* Reject ARM ELF "mapping symbols": these aren't unique and in dso__load_sym()
1207 sym.st_shndx = elf_addr_to_index(runtime_ss->elf, in dso__load_sym()
1224 sec = elf_getscn(runtime_ss->elf, sym.st_shndx); in dso__load_sym()
1250 if (elf_read_program_header(runtime_ss->elf, in dso__load_sym()
1263 * is not necessary for normal C ELF file, we in dso__load_sym()
1313 static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data) in elf_read_maps() argument
1320 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_maps()
1324 if (gelf_getphdr(elf, i, &phdr) == NULL) in elf_read_maps()
1349 Elf *elf; in file__read_maps() local
1351 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in file__read_maps()
1352 if (elf == NULL) in file__read_maps()
1356 *is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in file__read_maps()
1358 err = elf_read_maps(elf, exe, mapfn, data); in file__read_maps()
1360 elf_end(elf); in file__read_maps()
1369 Elf *elf; in dso__type_fd() local
1371 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in dso__type_fd()
1372 if (elf == NULL) in dso__type_fd()
1375 ek = elf_kind(elf); in dso__type_fd()
1379 if (gelf_getclass(elf) == ELFCLASS64) { in dso__type_fd()
1384 if (gelf_getehdr(elf, &ehdr) == NULL) in dso__type_fd()
1392 elf_end(elf); in dso__type_fd()
1441 Elf *elf; member
1453 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL); in kcore__open()
1454 if (!kcore->elf) in kcore__open()
1457 kcore->elfclass = gelf_getclass(kcore->elf); in kcore__open()
1461 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr); in kcore__open()
1468 elf_end(kcore->elf); in kcore__open()
1486 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL); in kcore__init()
1487 if (!kcore->elf) in kcore__init()
1490 if (!gelf_newehdr(kcore->elf, elfclass)) in kcore__init()
1498 elf_end(kcore->elf); in kcore__init()
1507 elf_end(kcore->elf); in kcore__close()
1538 if (!gelf_update_ehdr(to->elf, ehdr)) in kcore__copy_hdr()
1541 if (!gelf_newphdr(to->elf, count)) in kcore__copy_hdr()
1561 if (!gelf_update_phdr(kcore->elf, idx, &phdr)) in kcore__add_phdr()
1569 return elf_update(kcore->elf, ELF_C_WRITE); in kcore__write()
1781 static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf) in kcore_copy__read_maps() argument
1783 if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0) in kcore_copy__read_maps()
1848 Elf *elf) in kcore_copy__calc_maps() argument
1886 if (kcore_copy__read_maps(kci, elf)) in kcore_copy__calc_maps()
2036 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf)) in kcore_copy()
2045 offset = gelf_fsize(extract.elf, ELF_T_EHDR, 1, EV_CURRENT) + in kcore_copy()
2046 gelf_fsize(extract.elf, ELF_T_PHDR, kci.phnum, EV_CURRENT); in kcore_copy()
2169 * @elf: elf of the opened file
2175 * Responsible for parsing the @data in section .note.stapsdt in @elf and
2178 static int populate_sdt_note(Elf **elf, const char *data, size_t len, in populate_sdt_note() argument
2194 .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT), in populate_sdt_note()
2215 if (gelf_xlatetom(*elf, &dst, &src, in populate_sdt_note()
2216 elf_getident(*elf, NULL)[EI_DATA]) == NULL) { in populate_sdt_note()
2258 if (gelf_getclass(*elf) == ELFCLASS32) { in populate_sdt_note()
2266 if (!gelf_getehdr(*elf, &ehdr)) { in populate_sdt_note()
2267 pr_debug("%s : cannot get elf header.\n", __func__); in populate_sdt_note()
2279 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL)) in populate_sdt_note()
2283 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL)) in populate_sdt_note()
2303 * @elf : elf to look into
2306 * Scans the sections in 'elf' for the section
2310 static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes) in construct_sdt_notes_list() argument
2321 if (gelf_getehdr(elf, &ehdr) == NULL) { in construct_sdt_notes_list()
2325 if (elf_getshdrstrndx(elf, &shstrndx) != 0) { in construct_sdt_notes_list()
2331 scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL); in construct_sdt_notes_list()
2354 ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off), in construct_sdt_notes_list()
2373 * the ELF and then calls construct_sdt_notes_list.
2377 Elf *elf; in get_sdt_note_list() local
2384 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in get_sdt_note_list()
2385 if (!elf) { in get_sdt_note_list()
2389 ret = construct_sdt_notes_list(elf, head); in get_sdt_note_list()
2390 elf_end(elf); in get_sdt_note_list()