Lines Matching full:elf

54 static int elf_getphdrnum(Elf *elf, size_t *dst)
59 ehdr = gelf_getehdr(elf, &gehdr);
70 static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused)
167 static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
173 while ((sec = elf_nextscn(elf, sec)) != NULL) {
186 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
192 /* ELF is corrupted/truncated, avoid calling elf_strptr. */
193 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL))
196 while ((sec = elf_nextscn(elf, sec)) != NULL) {
200 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
215 Elf *elf;
224 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
225 if (elf == NULL)
228 if (gelf_getehdr(elf, &ehdr) == NULL)
231 found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL);
234 elf_end(elf);
240 static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr)
245 if (elf_getphdrnum(elf, &phdrnum))
249 if (gelf_getphdr(elf, i, phdr) == NULL)
335 static bool get_ifunc_name(Elf *elf, struct dso *dso, GElf_Ehdr *ehdr,
345 if (elf_read_program_header(elf, addr, &phdr))
470 static void get_rela_dyn_info(Elf *elf, GElf_Ehdr *ehdr, struct rela_dyn_info *di, Elf_Scn *scn)
477 scn = elf_section_by_name(elf, ehdr, &rela_dyn_shdr, ".rela.dyn", NULL);
484 scn = elf_getscn(elf, rela_dyn_shdr.sh_link);
489 di->dynstr_data = elf_getdata(elf_getscn(elf, shdr.sh_link), NULL);
564 static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf,
575 scn = elf_section_by_name(elf, ehdr, &shdr, ".plt.got", NULL);
580 get_rela_dyn_info(elf, ehdr, &di, scn);
615 Elf *elf;
620 elf = ss->elf;
623 if (!elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL))
646 dso__synthesize_plt_got_symbols(dso, elf, &ehdr, sympltname, sizeof(sympltname)))
651 elf_section_by_name(elf, &ehdr, &plt_sec_shdr, ".plt.sec", NULL)) {
664 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
667 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
709 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link);
754 else if (!get_ifunc_name(elf, dso, &ehdr, &ri, sympltname, sizeof(sympltname)))
783 static int elf_read_build_id(Elf *elf, void *bf, size_t size)
796 ek = elf_kind(elf);
800 if (gelf_getehdr(elf, &ehdr) == NULL) {
801 pr_err("%s: cannot get elf header.\n", __func__);
812 sec = elf_section_by_name(elf, &ehdr, &shdr,
817 sec = elf_section_by_name(elf, &ehdr, &shdr,
822 sec = elf_section_by_name(elf, &ehdr, &shdr,
880 Elf *elf;
893 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
894 if (elf == NULL) {
895 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename);
899 err = elf_read_build_id(elf, bid->data, size);
903 elf_end(elf);
1014 Elf *elf;
1029 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
1030 if (elf == NULL) {
1031 pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename);
1035 ek = elf_kind(elf);
1039 if (gelf_getehdr(elf, &ehdr) == NULL) {
1040 pr_err("%s: cannot get elf header.\n", __func__);
1044 sec = elf_section_by_name(elf, &ehdr, &shdr,
1066 elf_end(elf);
1086 elf_end(ss->elf);
1093 * Usually vmlinux is an ELF file with type ET_EXEC for most
1101 static Elf *read_gnu_debugdata(struct dso *dso, Elf *elf, const char *name, int *fd_ret)
1103 Elf *elf_embedded;
1110 char temp_filename[] = "/tmp/perf.gnu_debugdata.elf.XXXXXX";
1113 if (gelf_getehdr(elf, &ehdr) == NULL) {
1114 pr_debug("%s: cannot read %s ELF file.\n", __func__, name);
1119 scn = elf_section_by_name(elf, &ehdr, &shdr, ".gnu_debugdata", &shndx);
1126 pr_debug("%s: .gnu_debugdata of ELF file %s has no data.\n", __func__, name);
1180 Elf *elf;
1197 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
1198 if (elf == NULL) {
1199 pr_debug("%s: cannot read %s ELF file.\n", __func__, name);
1206 Elf *embedded = read_gnu_debugdata(dso, elf, name, &new_fd);
1211 elf_end(elf);
1214 elf = embedded;
1217 if (gelf_getehdr(elf, &ehdr) == NULL) {
1219 pr_debug("%s: cannot get elf header.\n", __func__);
1234 size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE);
1248 ss->is_64_bit = (gelf_getclass(elf) == ELFCLASS64);
1251 ss->symtab = elf_section_by_name(elf, &ehdr, &ss->symshdr, ".symtab",
1257 ss->dynsym = elf_section_by_name(elf, &ehdr, &ss->dynshdr, ".dynsym",
1263 ss->opdsec = elf_section_by_name(elf, &ehdr, &ss->opdshdr, ".opd",
1279 ss->elf = elf;
1287 elf_end(elf);
1304 static u64 max_text_section(Elf *elf, GElf_Ehdr *ehdr)
1315 /* ELF is corrupted/truncated, avoid calling elf_strptr. */
1316 if (!elf_rawdata(elf_getscn(elf, ehdr->e_shstrndx), NULL))
1319 while ((sec = elf_nextscn(elf, sec)) != NULL) {
1329 sec_name = elf_strptr(elf, ehdr->e_shstrndx, shdr.sh_name);
1534 Elf *elf;
1542 elf = syms_ss->elf;
1552 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr,
1565 sec = elf_getscn(elf, shdr.sh_link);
1573 sec_strndx = elf_getscn(runtime_ss->elf, runtime_ss->ehdr.e_shstrndx);
1581 sec_strndx = elf_getscn(elf, ehdr.e_shstrndx);
1627 max_text_sh_offset = max_text_section(runtime_ss->elf, &runtime_ss->ehdr);
1642 * Reject ARM ELF "mapping symbols": these aren't unique and
1652 /* Reject RISCV ELF "mapping symbols" */
1666 sym.st_shndx = elf_addr_to_index(runtime_ss->elf,
1683 sec = elf_getscn(syms_ss->elf, sym.st_shndx);
1714 sec = elf_getscn(runtime_ss->elf, sym.st_shndx);
1747 if (elf_read_program_header(runtime_ss->elf,
1760 * is not necessary for normal C ELF file, we
1869 static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data)
1876 if (elf_getphdrnum(elf, &phdrnum))
1880 if (gelf_getphdr(elf, i, &phdr) == NULL)
1905 Elf *elf;
1907 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
1908 if (elf == NULL)
1912 *is_64_bit = (gelf_getclass(elf) == ELFCLASS64);
1914 err = elf_read_maps(elf, exe, mapfn, data);
1916 elf_end(elf);
1925 Elf *elf;
1927 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
1928 if (elf == NULL)
1931 ek = elf_kind(elf);
1935 if (gelf_getclass(elf) == ELFCLASS64) {
1940 if (gelf_getehdr(elf, &ehdr) == NULL)
1948 elf_end(elf);
1997 Elf *elf;
2009 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL);
2010 if (!kcore->elf)
2013 kcore->elfclass = gelf_getclass(kcore->elf);
2017 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr);
2024 elf_end(kcore->elf);
2042 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL);
2043 if (!kcore->elf)
2046 if (!gelf_newehdr(kcore->elf, elfclass))
2054 elf_end(kcore->elf);
2063 elf_end(kcore->elf);
2094 if (!gelf_update_ehdr(to->elf, ehdr))
2097 if (!gelf_newphdr(to->elf, count))
2117 if (!gelf_update_phdr(kcore->elf, idx, &phdr))
2125 return elf_update(kcore->elf, ELF_C_WRITE);
2341 static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf)
2343 if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0)
2408 Elf *elf)
2446 if (kcore_copy__read_maps(kci, elf))
2596 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf))
2605 offset = gelf_fsize(extract.elf, ELF_T_EHDR, 1, EV_CURRENT) +
2606 gelf_fsize(extract.elf, ELF_T_PHDR, kci.phnum, EV_CURRENT);
2729 * @elf: elf of the opened file
2735 * Responsible for parsing the @data in section .note.stapsdt in @elf and
2738 static int populate_sdt_note(Elf **elf, const char *data, size_t len,
2754 .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT),
2775 if (gelf_xlatetom(*elf, &dst, &src,
2776 elf_getident(*elf, NULL)[EI_DATA]) == NULL) {
2818 if (gelf_getclass(*elf) == ELFCLASS32) {
2826 if (!gelf_getehdr(*elf, &ehdr)) {
2827 pr_debug("%s : cannot get elf header.\n", __func__);
2839 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL))
2843 if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL))
2863 * @elf : elf to look into
2866 * Scans the sections in 'elf' for the section
2870 static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes)
2881 if (gelf_getehdr(elf, &ehdr) == NULL) {
2885 if (elf_getshdrstrndx(elf, &shstrndx) != 0) {
2891 scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL);
2914 ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off),
2933 * the ELF and then calls construct_sdt_notes_list.
2937 Elf *elf;
2944 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
2945 if (!elf) {
2949 ret = construct_sdt_notes_list(elf, head);
2950 elf_end(elf);