Lines Matching full:elf

54 static int elf_getphdrnum(Elf *elf, size_t *dst)  in elf_getphdrnum()  argument
59 ehdr = gelf_getehdr(elf, &gehdr); in elf_getphdrnum()
70 static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused) in elf_getshdrstrndx()
167 static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) in elf_addr_to_index() argument
173 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_addr_to_index()
186 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, in elf_section_by_name() argument
192 /* ELF is corrupted/truncated, avoid calling elf_strptr. */ in elf_section_by_name()
193 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) in elf_section_by_name()
196 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_section_by_name()
200 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); in elf_section_by_name()
215 Elf *elf; in filename__has_section() local
224 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__has_section()
225 if (elf == NULL) in filename__has_section()
228 if (gelf_getehdr(elf, &ehdr) == NULL) in filename__has_section()
231 found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL); in filename__has_section()
234 elf_end(elf); in filename__has_section()
240 static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr) in elf_read_program_header() argument
245 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_program_header()
249 if (gelf_getphdr(elf, i, phdr) == NULL) in elf_read_program_header()
335 static bool get_ifunc_name(Elf *elf, struct dso *dso, GElf_Ehdr *ehdr, in get_ifunc_name() argument
345 if (elf_read_program_header(elf, addr, &phdr)) in get_ifunc_name()
471 static void get_rela_dyn_info(Elf *elf, GElf_Ehdr *ehdr, struct rela_dyn_info *di, Elf_Scn *scn) in get_rela_dyn_info() argument
478 scn = elf_section_by_name(elf, ehdr, &rela_dyn_shdr, ".rela.dyn", NULL); in get_rela_dyn_info()
485 scn = elf_getscn(elf, rela_dyn_shdr.sh_link); in get_rela_dyn_info()
490 di->dynstr_data = elf_getdata(elf_getscn(elf, shdr.sh_link), NULL); in get_rela_dyn_info()
565 static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf, in dso__synthesize_plt_got_symbols() argument
576 scn = elf_section_by_name(elf, ehdr, &shdr, ".plt.got", NULL); in dso__synthesize_plt_got_symbols()
581 get_rela_dyn_info(elf, ehdr, &di, scn); in dso__synthesize_plt_got_symbols()
616 Elf *elf; in dso__synthesize_plt_symbols() local
621 elf = ss->elf; in dso__synthesize_plt_symbols()
624 if (!elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL)) in dso__synthesize_plt_symbols()
647 dso__synthesize_plt_got_symbols(dso, elf, &ehdr, sympltname, sizeof(sympltname))) in dso__synthesize_plt_symbols()
652 elf_section_by_name(elf, &ehdr, &plt_sec_shdr, ".plt.sec", NULL)) { in dso__synthesize_plt_symbols()
665 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
668 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
710 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); in dso__synthesize_plt_symbols()
755 else if (!get_ifunc_name(elf, dso, &ehdr, &ri, sympltname, sizeof(sympltname))) in dso__synthesize_plt_symbols()
784 static int elf_read_build_id(Elf *elf, void *bf, size_t size) in elf_read_build_id() argument
797 ek = elf_kind(elf); in elf_read_build_id()
801 if (gelf_getehdr(elf, &ehdr) == NULL) { in elf_read_build_id()
802 pr_err("%s: cannot get elf header.\n", __func__); in elf_read_build_id()
813 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
818 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
823 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
867 Elf *elf; in read_build_id() local
880 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in read_build_id()
881 if (elf == NULL) { in read_build_id()
882 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in read_build_id()
886 err = elf_read_build_id(elf, bid->data, size); in read_build_id()
890 elf_end(elf); in read_build_id()
985 Elf *elf; in filename__read_debuglink() local
1000 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__read_debuglink()
1001 if (elf == NULL) { in filename__read_debuglink()
1002 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in filename__read_debuglink()
1006 ek = elf_kind(elf); in filename__read_debuglink()
1010 if (gelf_getehdr(elf, &ehdr) == NULL) { in filename__read_debuglink()
1011 pr_err("%s: cannot get elf header.\n", __func__); in filename__read_debuglink()
1015 sec = elf_section_by_name(elf, &ehdr, &shdr, in filename__read_debuglink()
1030 elf_end(elf); in filename__read_debuglink()
1050 elf_end(ss->elf); in symsrc__destroy()
1057 * Usually vmlinux is an ELF file with type ET_EXEC for most in elf__needs_adjust_symbols()
1065 static Elf *read_gnu_debugdata(struct dso *dso, Elf *elf, const char *name, int *fd_ret) in read_gnu_debugdata() argument
1067 Elf *elf_embedded; in read_gnu_debugdata()
1074 char temp_filename[] = "/tmp/perf.gnu_debugdata.elf.XXXXXX"; in read_gnu_debugdata()
1077 if (gelf_getehdr(elf, &ehdr) == NULL) { in read_gnu_debugdata()
1078 pr_debug("%s: cannot read %s ELF file.\n", __func__, name); in read_gnu_debugdata()
1083 scn = elf_section_by_name(elf, &ehdr, &shdr, ".gnu_debugdata", &shndx); in read_gnu_debugdata()
1090 pr_debug("%s: .gnu_debugdata of ELF file %s has no data.\n", __func__, name); in read_gnu_debugdata()
1144 Elf *elf; in symsrc__init() local
1161 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in symsrc__init()
1162 if (elf == NULL) { in symsrc__init()
1163 pr_debug("%s: cannot read %s ELF file.\n", __func__, name); in symsrc__init()
1170 Elf *embedded = read_gnu_debugdata(dso, elf, name, &new_fd); in symsrc__init()
1175 elf_end(elf); in symsrc__init()
1178 elf = embedded; in symsrc__init()
1181 if (gelf_getehdr(elf, &ehdr) == NULL) { in symsrc__init()
1183 pr_debug("%s: cannot get elf header.\n", __func__); in symsrc__init()
1198 size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE); in symsrc__init()
1212 ss->is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in symsrc__init()
1215 ss->symtab = elf_section_by_name(elf, &ehdr, &ss->symshdr, ".symtab", in symsrc__init()
1221 ss->dynsym = elf_section_by_name(elf, &ehdr, &ss->dynshdr, ".dynsym", in symsrc__init()
1227 ss->opdsec = elf_section_by_name(elf, &ehdr, &ss->opdshdr, ".opd", in symsrc__init()
1243 ss->elf = elf; in symsrc__init()
1251 elf_end(elf); in symsrc__init()
1268 static u64 max_text_section(Elf *elf, GElf_Ehdr *ehdr) in max_text_section() argument
1279 /* ELF is corrupted/truncated, avoid calling elf_strptr. */ in max_text_section()
1280 if (!elf_rawdata(elf_getscn(elf, ehdr->e_shstrndx), NULL)) in max_text_section()
1283 while ((sec = elf_nextscn(elf, sec)) != NULL) { in max_text_section()
1293 sec_name = elf_strptr(elf, ehdr->e_shstrndx, shdr.sh_name); in max_text_section()
1480 Elf *elf; in dso__load_sym_internal() local
1488 elf = syms_ss->elf; in dso__load_sym_internal()
1498 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, in dso__load_sym_internal()
1511 sec = elf_getscn(elf, shdr.sh_link); in dso__load_sym_internal()
1519 sec_strndx = elf_getscn(runtime_ss->elf, runtime_ss->ehdr.e_shstrndx); in dso__load_sym_internal()
1527 sec_strndx = elf_getscn(elf, ehdr.e_shstrndx); in dso__load_sym_internal()
1573 max_text_sh_offset = max_text_section(runtime_ss->elf, &runtime_ss->ehdr); in dso__load_sym_internal()
1587 /* Reject ARM ELF "mapping symbols": these aren't unique and in dso__load_sym_internal()
1596 /* Reject RISCV ELF "mapping symbols" */ in dso__load_sym_internal()
1606 sym.st_shndx = elf_addr_to_index(runtime_ss->elf, in dso__load_sym_internal()
1623 sec = elf_getscn(syms_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1649 sec = elf_getscn(runtime_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1682 if (elf_read_program_header(runtime_ss->elf, in dso__load_sym_internal()
1695 * is not necessary for normal C ELF file, we in dso__load_sym_internal()
1804 static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data) in elf_read_maps() argument
1811 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_maps()
1815 if (gelf_getphdr(elf, i, &phdr) == NULL) in elf_read_maps()
1840 Elf *elf; in file__read_maps() local
1842 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in file__read_maps()
1843 if (elf == NULL) in file__read_maps()
1847 *is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in file__read_maps()
1849 err = elf_read_maps(elf, exe, mapfn, data); in file__read_maps()
1851 elf_end(elf); in file__read_maps()
1860 Elf *elf; in dso__type_fd() local
1862 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in dso__type_fd()
1863 if (elf == NULL) in dso__type_fd()
1866 ek = elf_kind(elf); in dso__type_fd()
1870 if (gelf_getclass(elf) == ELFCLASS64) { in dso__type_fd()
1875 if (gelf_getehdr(elf, &ehdr) == NULL) in dso__type_fd()
1883 elf_end(elf); in dso__type_fd()
1932 Elf *elf; member
1944 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL); in kcore__open()
1945 if (!kcore->elf) in kcore__open()
1948 kcore->elfclass = gelf_getclass(kcore->elf); in kcore__open()
1952 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr); in kcore__open()
1959 elf_end(kcore->elf); in kcore__open()
1977 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL); in kcore__init()
1978 if (!kcore->elf) in kcore__init()
1981 if (!gelf_newehdr(kcore->elf, elfclass)) in kcore__init()
1989 elf_end(kcore->elf); in kcore__init()
1998 elf_end(kcore->elf); in kcore__close()
2029 if (!gelf_update_ehdr(to->elf, ehdr)) in kcore__copy_hdr()
2032 if (!gelf_newphdr(to->elf, count)) in kcore__copy_hdr()
2052 if (!gelf_update_phdr(kcore->elf, idx, &phdr)) in kcore__add_phdr()
2060 return elf_update(kcore->elf, ELF_C_WRITE); in kcore__write()
2272 static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf) in kcore_copy__read_maps() argument
2274 if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0) in kcore_copy__read_maps()
2339 Elf *elf) in kcore_copy__calc_maps() argument
2377 if (kcore_copy__read_maps(kci, elf)) in kcore_copy__calc_maps()
2527 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf)) in kcore_copy()
2536 offset = gelf_fsize(extract.elf, ELF_T_EHDR, 1, EV_CURRENT) + in kcore_copy()
2537 gelf_fsize(extract.elf, ELF_T_PHDR, kci.phnum, EV_CURRENT); in kcore_copy()
2660 * @elf: elf of the opened file
2666 * Responsible for parsing the @data in section .note.stapsdt in @elf and
2669 static int populate_sdt_note(Elf **elf, const char *data, size_t len, in populate_sdt_note() argument
2685 .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT), in populate_sdt_note()
2706 if (gelf_xlatetom(*elf, &dst, &src, in populate_sdt_note()
2707 elf_getident(*elf, NULL)[EI_DATA]) == NULL) { in populate_sdt_note()
2749 if (gelf_getclass(*elf) == ELFCLASS32) { in populate_sdt_note()
2757 if (!gelf_getehdr(*elf, &ehdr)) { in populate_sdt_note()
2758 pr_debug("%s : cannot get elf header.\n", __func__); in populate_sdt_note()
2770 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL)) in populate_sdt_note()
2774 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL)) in populate_sdt_note()
2794 * @elf : elf to look into
2797 * Scans the sections in 'elf' for the section
2801 static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes) in construct_sdt_notes_list() argument
2812 if (gelf_getehdr(elf, &ehdr) == NULL) { in construct_sdt_notes_list()
2816 if (elf_getshdrstrndx(elf, &shstrndx) != 0) { in construct_sdt_notes_list()
2822 scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL); in construct_sdt_notes_list()
2845 ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off), in construct_sdt_notes_list()
2864 * the ELF and then calls construct_sdt_notes_list.
2868 Elf *elf; in get_sdt_note_list() local
2875 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in get_sdt_note_list()
2876 if (!elf) { in get_sdt_note_list()
2880 ret = construct_sdt_notes_list(elf, head); in get_sdt_note_list()
2881 elf_end(elf); in get_sdt_note_list()