Lines Matching full:elf
68 static int elf_getphdrnum(Elf *elf, size_t *dst) in elf_getphdrnum() argument
73 ehdr = gelf_getehdr(elf, &gehdr); in elf_getphdrnum()
84 static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused) in elf_getshdrstrndx()
181 static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) in elf_addr_to_index() argument
187 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_addr_to_index()
200 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, in elf_section_by_name() argument
206 /* ELF is corrupted/truncated, avoid calling elf_strptr. */ in elf_section_by_name()
207 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) in elf_section_by_name()
210 while ((sec = elf_nextscn(elf, sec)) != NULL) { in elf_section_by_name()
214 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); in elf_section_by_name()
229 Elf *elf; in filename__has_section() local
238 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__has_section()
239 if (elf == NULL) in filename__has_section()
242 if (gelf_getehdr(elf, &ehdr) == NULL) in filename__has_section()
245 found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL); in filename__has_section()
248 elf_end(elf); in filename__has_section()
254 static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr) in elf_read_program_header() argument
259 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_program_header()
263 if (gelf_getphdr(elf, i, phdr) == NULL) in elf_read_program_header()
403 static bool get_ifunc_name(Elf *elf, struct dso *dso, GElf_Ehdr *ehdr, in get_ifunc_name() argument
413 if (elf_read_program_header(elf, addr, &phdr)) in get_ifunc_name()
539 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
546 scn = elf_section_by_name(elf, ehdr, &rela_dyn_shdr, ".rela.dyn", NULL); in get_rela_dyn_info()
553 scn = elf_getscn(elf, rela_dyn_shdr.sh_link); in get_rela_dyn_info()
558 di->dynstr_data = elf_getdata(elf_getscn(elf, shdr.sh_link), NULL); in get_rela_dyn_info()
633 static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf, in dso__synthesize_plt_got_symbols() argument
644 scn = elf_section_by_name(elf, ehdr, &shdr, ".plt.got", NULL); in dso__synthesize_plt_got_symbols()
649 get_rela_dyn_info(elf, ehdr, &di, scn); in dso__synthesize_plt_got_symbols()
684 Elf *elf; in dso__synthesize_plt_symbols() local
689 elf = ss->elf; in dso__synthesize_plt_symbols()
692 if (!elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL)) in dso__synthesize_plt_symbols()
715 dso__synthesize_plt_got_symbols(dso, elf, &ehdr, sympltname, sizeof(sympltname))) in dso__synthesize_plt_symbols()
720 elf_section_by_name(elf, &ehdr, &plt_sec_shdr, ".plt.sec", NULL)) { in dso__synthesize_plt_symbols()
733 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
736 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, in dso__synthesize_plt_symbols()
778 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); in dso__synthesize_plt_symbols()
823 else if (!get_ifunc_name(elf, dso, &ehdr, &ri, sympltname, sizeof(sympltname))) in dso__synthesize_plt_symbols()
857 static int elf_read_build_id(Elf *elf, void *bf, size_t size) in elf_read_build_id() argument
870 ek = elf_kind(elf); in elf_read_build_id()
874 if (gelf_getehdr(elf, &ehdr) == NULL) { in elf_read_build_id()
875 pr_err("%s: cannot get elf header.\n", __func__); in elf_read_build_id()
886 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
891 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
896 sec = elf_section_by_name(elf, &ehdr, &shdr, in elf_read_build_id()
971 Elf *elf; in read_build_id() local
980 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in read_build_id()
981 if (elf == NULL) { in read_build_id()
982 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in read_build_id()
986 err = elf_read_build_id(elf, bid->data, size); in read_build_id()
990 elf_end(elf); in read_build_id()
1124 Elf *elf; in filename__read_debuglink() local
1135 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in filename__read_debuglink()
1136 if (elf == NULL) { in filename__read_debuglink()
1137 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); in filename__read_debuglink()
1141 ek = elf_kind(elf); in filename__read_debuglink()
1145 if (gelf_getehdr(elf, &ehdr) == NULL) { in filename__read_debuglink()
1146 pr_err("%s: cannot get elf header.\n", __func__); in filename__read_debuglink()
1150 sec = elf_section_by_name(elf, &ehdr, &shdr, in filename__read_debuglink()
1165 elf_end(elf); in filename__read_debuglink()
1214 elf_end(ss->elf); in symsrc__destroy()
1221 * Usually vmlinux is an ELF file with type ET_EXEC for most in elf__needs_adjust_symbols()
1233 Elf *elf; in symsrc__init() local
1250 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in symsrc__init()
1251 if (elf == NULL) { in symsrc__init()
1252 pr_debug("%s: cannot read %s ELF file.\n", __func__, name); in symsrc__init()
1257 if (gelf_getehdr(elf, &ehdr) == NULL) { in symsrc__init()
1259 pr_debug("%s: cannot get elf header.\n", __func__); in symsrc__init()
1274 size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE); in symsrc__init()
1288 ss->is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in symsrc__init()
1291 ss->symtab = elf_section_by_name(elf, &ehdr, &ss->symshdr, ".symtab", in symsrc__init()
1297 ss->dynsym = elf_section_by_name(elf, &ehdr, &ss->dynshdr, ".dynsym", in symsrc__init()
1303 ss->opdsec = elf_section_by_name(elf, &ehdr, &ss->opdshdr, ".opd", in symsrc__init()
1319 ss->elf = elf; in symsrc__init()
1327 elf_end(elf); in symsrc__init()
1344 static u64 max_text_section(Elf *elf, GElf_Ehdr *ehdr) in max_text_section() argument
1355 /* ELF is corrupted/truncated, avoid calling elf_strptr. */ in max_text_section()
1356 if (!elf_rawdata(elf_getscn(elf, ehdr->e_shstrndx), NULL)) in max_text_section()
1359 while ((sec = elf_nextscn(elf, sec)) != NULL) { in max_text_section()
1369 sec_name = elf_strptr(elf, ehdr->e_shstrndx, shdr.sh_name); in max_text_section()
1556 Elf *elf; in dso__load_sym_internal() local
1564 elf = syms_ss->elf; in dso__load_sym_internal()
1574 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, in dso__load_sym_internal()
1587 sec = elf_getscn(elf, shdr.sh_link); in dso__load_sym_internal()
1595 sec_strndx = elf_getscn(runtime_ss->elf, runtime_ss->ehdr.e_shstrndx); in dso__load_sym_internal()
1603 sec_strndx = elf_getscn(elf, ehdr.e_shstrndx); in dso__load_sym_internal()
1649 max_text_sh_offset = max_text_section(runtime_ss->elf, &runtime_ss->ehdr); in dso__load_sym_internal()
1663 /* Reject ARM ELF "mapping symbols": these aren't unique and in dso__load_sym_internal()
1676 sym.st_shndx = elf_addr_to_index(runtime_ss->elf, in dso__load_sym_internal()
1693 sec = elf_getscn(syms_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1719 sec = elf_getscn(runtime_ss->elf, sym.st_shndx); in dso__load_sym_internal()
1752 if (elf_read_program_header(runtime_ss->elf, in dso__load_sym_internal()
1765 * is not necessary for normal C ELF file, we in dso__load_sym_internal()
1861 static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data) in elf_read_maps() argument
1868 if (elf_getphdrnum(elf, &phdrnum)) in elf_read_maps()
1872 if (gelf_getphdr(elf, i, &phdr) == NULL) in elf_read_maps()
1897 Elf *elf; in file__read_maps() local
1899 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in file__read_maps()
1900 if (elf == NULL) in file__read_maps()
1904 *is_64_bit = (gelf_getclass(elf) == ELFCLASS64); in file__read_maps()
1906 err = elf_read_maps(elf, exe, mapfn, data); in file__read_maps()
1908 elf_end(elf); in file__read_maps()
1917 Elf *elf; in dso__type_fd() local
1919 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in dso__type_fd()
1920 if (elf == NULL) in dso__type_fd()
1923 ek = elf_kind(elf); in dso__type_fd()
1927 if (gelf_getclass(elf) == ELFCLASS64) { in dso__type_fd()
1932 if (gelf_getehdr(elf, &ehdr) == NULL) in dso__type_fd()
1940 elf_end(elf); in dso__type_fd()
1989 Elf *elf; member
2001 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL); in kcore__open()
2002 if (!kcore->elf) in kcore__open()
2005 kcore->elfclass = gelf_getclass(kcore->elf); in kcore__open()
2009 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr); in kcore__open()
2016 elf_end(kcore->elf); in kcore__open()
2034 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL); in kcore__init()
2035 if (!kcore->elf) in kcore__init()
2038 if (!gelf_newehdr(kcore->elf, elfclass)) in kcore__init()
2046 elf_end(kcore->elf); in kcore__init()
2055 elf_end(kcore->elf); in kcore__close()
2086 if (!gelf_update_ehdr(to->elf, ehdr)) in kcore__copy_hdr()
2089 if (!gelf_newphdr(to->elf, count)) in kcore__copy_hdr()
2109 if (!gelf_update_phdr(kcore->elf, idx, &phdr)) in kcore__add_phdr()
2117 return elf_update(kcore->elf, ELF_C_WRITE); in kcore__write()
2329 static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf) in kcore_copy__read_maps() argument
2331 if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0) in kcore_copy__read_maps()
2396 Elf *elf) in kcore_copy__calc_maps() argument
2434 if (kcore_copy__read_maps(kci, elf)) in kcore_copy__calc_maps()
2584 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf)) in kcore_copy()
2593 offset = gelf_fsize(extract.elf, ELF_T_EHDR, 1, EV_CURRENT) + in kcore_copy()
2594 gelf_fsize(extract.elf, ELF_T_PHDR, kci.phnum, EV_CURRENT); in kcore_copy()
2717 * @elf: elf of the opened file
2723 * Responsible for parsing the @data in section .note.stapsdt in @elf and
2726 static int populate_sdt_note(Elf **elf, const char *data, size_t len, in populate_sdt_note() argument
2742 .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT), in populate_sdt_note()
2763 if (gelf_xlatetom(*elf, &dst, &src, in populate_sdt_note()
2764 elf_getident(*elf, NULL)[EI_DATA]) == NULL) { in populate_sdt_note()
2806 if (gelf_getclass(*elf) == ELFCLASS32) { in populate_sdt_note()
2814 if (!gelf_getehdr(*elf, &ehdr)) { in populate_sdt_note()
2815 pr_debug("%s : cannot get elf header.\n", __func__); in populate_sdt_note()
2827 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL)) in populate_sdt_note()
2831 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL)) in populate_sdt_note()
2851 * @elf : elf to look into
2854 * Scans the sections in 'elf' for the section
2858 static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes) in construct_sdt_notes_list() argument
2869 if (gelf_getehdr(elf, &ehdr) == NULL) { in construct_sdt_notes_list()
2873 if (elf_getshdrstrndx(elf, &shstrndx) != 0) { in construct_sdt_notes_list()
2879 scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL); in construct_sdt_notes_list()
2902 ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off), in construct_sdt_notes_list()
2921 * the ELF and then calls construct_sdt_notes_list.
2925 Elf *elf; in get_sdt_note_list() local
2932 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); in get_sdt_note_list()
2933 if (!elf) { in get_sdt_note_list()
2937 ret = construct_sdt_notes_list(elf, head); in get_sdt_note_list()
2938 elf_end(elf); in get_sdt_note_list()