Lines Matching refs:elf

78 static int elf_getphdrnum(Elf *elf, size_t *dst)  in elf_getphdrnum()  argument
83 ehdr = gelf_getehdr(elf, &gehdr); in elf_getphdrnum()
94 static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused) in elf_getshdrstrndx()
191 static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) in elf_addr_to_index() argument
197 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_addr_to_index()
210 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, in elf_section_by_name() argument
217 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) in elf_section_by_name()
220 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_section_by_name()
224 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); in elf_section_by_name()
236 static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr) in elf_read_program_header() argument
241 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_program_header()
245 if (gelf_getphdr(elf, i, phdr) == NULL) in elf_read_program_header()
328 Elf *elf; in dso__synthesize_plt_symbols() local
334 elf = ss->elf; in dso__synthesize_plt_symbols()
344 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
347 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
358 if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL) in dso__synthesize_plt_symbols()
373 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); in dso__synthesize_plt_symbols()
488 static int elf_read_build_id(Elf *elf, void *bf, size_t size) in elf_read_build_id() argument
501 ek = elf_kind(elf); in elf_read_build_id()
505 if (gelf_getehdr(elf, &ehdr) == NULL) { 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()
527 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
602 Elf *elf; in read_build_id() local
611 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in read_build_id()
612 if (elf == NULL) { in read_build_id()
617 err = elf_read_build_id(elf, bid->data, size); in read_build_id()
621 elf_end(elf); in read_build_id()
755 Elf *elf; in filename__read_debuglink() local
766 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__read_debuglink()
767 if (elf == NULL) { in filename__read_debuglink()
772 ek = elf_kind(elf); in filename__read_debuglink()
776 if (gelf_getehdr(elf, &ehdr) == NULL) { in filename__read_debuglink()
781 sec = elf_section_by_name(elf, &ehdr, &shdr, in filename__read_debuglink()
796 elf_end(elf); in filename__read_debuglink()
845 elf_end(ss->elf); in symsrc__destroy()
864 Elf *elf; in symsrc__init() local
881 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in symsrc__init()
882 if (elf == NULL) { in symsrc__init()
888 if (gelf_getehdr(elf, &ehdr) == NULL) { in symsrc__init()
905 size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE); in symsrc__init()
919 ss->is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in symsrc__init()
921 ss->symtab = elf_section_by_name(elf, &ehdr, &ss->symshdr, ".symtab", in symsrc__init()
927 ss->dynsym = elf_section_by_name(elf, &ehdr, &ss->dynshdr, ".dynsym", in symsrc__init()
933 ss->opdsec = elf_section_by_name(elf, &ehdr, &ss->opdshdr, ".opd", in symsrc__init()
949 ss->elf = elf; in symsrc__init()
957 elf_end(elf); in symsrc__init()
1122 Elf *elf; in dso__load_sym_internal() local
1129 elf = syms_ss->elf; in dso__load_sym_internal()
1139 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, in dso__load_sym_internal()
1150 sec = elf_getscn(elf, shdr.sh_link); in dso__load_sym_internal()
1158 sec_strndx = elf_getscn(runtime_ss->elf, runtime_ss->ehdr.e_shstrndx); in dso__load_sym_internal()
1166 sec_strndx = elf_getscn(elf, ehdr.e_shstrndx); in dso__load_sym_internal()
1235 sym.st_shndx = elf_addr_to_index(runtime_ss->elf, in dso__load_sym_internal()
1252 sec = elf_getscn(syms_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1278 sec = elf_getscn(runtime_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1306 if (elf_read_program_header(runtime_ss->elf, in dso__load_sym_internal()
1413 static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data) in elf_read_maps() argument
1420 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_maps()
1424 if (gelf_getphdr(elf, i, &phdr) == NULL) in elf_read_maps()
1449 Elf *elf; in file__read_maps() local
1451 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in file__read_maps()
1452 if (elf == NULL) in file__read_maps()
1456 *is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in file__read_maps()
1458 err = elf_read_maps(elf, exe, mapfn, data); in file__read_maps()
1460 elf_end(elf); in file__read_maps()
1469 Elf *elf; in dso__type_fd() local
1471 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in dso__type_fd()
1472 if (elf == NULL) in dso__type_fd()
1475 ek = elf_kind(elf); in dso__type_fd()
1479 if (gelf_getclass(elf) == ELFCLASS64) { in dso__type_fd()
1484 if (gelf_getehdr(elf, &ehdr) == NULL) in dso__type_fd()
1492 elf_end(elf); in dso__type_fd()
1541 Elf *elf; member
1553 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL); in kcore__open()
1554 if (!kcore->elf) in kcore__open()
1557 kcore->elfclass = gelf_getclass(kcore->elf); in kcore__open()
1561 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr); in kcore__open()
1568 elf_end(kcore->elf); in kcore__open()
1586 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL); in kcore__init()
1587 if (!kcore->elf) in kcore__init()
1590 if (!gelf_newehdr(kcore->elf, elfclass)) in kcore__init()
1598 elf_end(kcore->elf); in kcore__init()
1607 elf_end(kcore->elf); in kcore__close()
1638 if (!gelf_update_ehdr(to->elf, ehdr)) in kcore__copy_hdr()
1641 if (!gelf_newphdr(to->elf, count)) in kcore__copy_hdr()
1661 if (!gelf_update_phdr(kcore->elf, idx, &phdr)) in kcore__add_phdr()
1669 return elf_update(kcore->elf, ELF_C_WRITE); in kcore__write()
1881 static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf) in kcore_copy__read_maps() argument
1883 if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0) in kcore_copy__read_maps()
1948 Elf *elf) in kcore_copy__calc_maps() argument
1986 if (kcore_copy__read_maps(kci, elf)) in kcore_copy__calc_maps()
2136 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf)) in kcore_copy()
2145 offset = gelf_fsize(extract.elf, ELF_T_EHDR, 1, EV_CURRENT) + in kcore_copy()
2146 gelf_fsize(extract.elf, ELF_T_PHDR, kci.phnum, EV_CURRENT); in kcore_copy()
2278 static int populate_sdt_note(Elf **elf, const char *data, size_t len, in populate_sdt_note() argument
2294 .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT), in populate_sdt_note()
2315 if (gelf_xlatetom(*elf, &dst, &src, in populate_sdt_note()
2316 elf_getident(*elf, NULL)[EI_DATA]) == NULL) { in populate_sdt_note()
2358 if (gelf_getclass(*elf) == ELFCLASS32) { in populate_sdt_note()
2366 if (!gelf_getehdr(*elf, &ehdr)) { in populate_sdt_note()
2379 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL)) in populate_sdt_note()
2383 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL)) in populate_sdt_note()
2410 static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes) in construct_sdt_notes_list() argument
2421 if (gelf_getehdr(elf, &ehdr) == NULL) { in construct_sdt_notes_list()
2425 if (elf_getshdrstrndx(elf, &shstrndx) != 0) { in construct_sdt_notes_list()
2431 scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL); in construct_sdt_notes_list()
2454 ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off), in construct_sdt_notes_list()
2477 Elf *elf; in get_sdt_note_list() local
2484 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in get_sdt_note_list()
2485 if (!elf) { in get_sdt_note_list()
2489 ret = construct_sdt_notes_list(elf, head); in get_sdt_note_list()
2490 elf_end(elf); in get_sdt_note_list()