Lines Matching refs:mod
72 open_elf (Dwfl_Module *mod, struct dwfl_file *file) in open_elf() argument
151 if (file == &mod->main) in open_elf()
153 mod->e_type = ehdr->e_type; in open_elf()
156 if (mod->e_type == ET_EXEC && file->vaddr != mod->low_addr) in open_elf()
157 mod->e_type = ET_DYN; in open_elf()
160 assert (mod->main.elf != NULL); in open_elf()
168 mod_verify_build_id (Dwfl_Module *mod) in mod_verify_build_id() argument
170 assert (mod->build_id_len > 0); in mod_verify_build_id()
172 switch (__builtin_expect (__libdwfl_find_build_id (mod, false, in mod_verify_build_id()
173 mod->main.elf), 2)) in mod_verify_build_id()
180 mod->elferr = INTUSE(dwfl_errno) (); in mod_verify_build_id()
185 mod->elferr = DWFL_E_WRONG_ID_ELF; in mod_verify_build_id()
193 elf_end (mod->main.elf); in mod_verify_build_id()
194 mod->main.elf = NULL; in mod_verify_build_id()
195 if (mod->main.fd >= 0) in mod_verify_build_id()
197 close (mod->main.fd); in mod_verify_build_id()
198 mod->main.fd = -1; in mod_verify_build_id()
206 __libdwfl_getelf (Dwfl_Module *mod) in __libdwfl_getelf() argument
208 if (mod->main.elf != NULL /* Already done. */ in __libdwfl_getelf()
209 || mod->elferr != DWFL_E_NOERROR) /* Cached failure. */ in __libdwfl_getelf()
212 mod->main.fd = (*mod->dwfl->callbacks->find_elf) (MODCB_ARGS (mod), in __libdwfl_getelf()
213 &mod->main.name, in __libdwfl_getelf()
214 &mod->main.elf); in __libdwfl_getelf()
215 const bool fallback = mod->main.elf == NULL && mod->main.fd < 0; in __libdwfl_getelf()
216 mod->elferr = open_elf (mod, &mod->main); in __libdwfl_getelf()
217 if (mod->elferr != DWFL_E_NOERROR) in __libdwfl_getelf()
220 if (!mod->main.valid) in __libdwfl_getelf()
224 free (mod->build_id_bits); in __libdwfl_getelf()
225 mod->build_id_bits = NULL; in __libdwfl_getelf()
226 mod->build_id_len = 0; in __libdwfl_getelf()
229 mod_verify_build_id (mod); in __libdwfl_getelf()
231 mod->main_bias = mod->e_type == ET_REL ? 0 : mod->low_addr - mod->main.vaddr; in __libdwfl_getelf()
269 find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file) in find_prelink_address_sync() argument
273 if (elf_getshdrstrndx (mod->main.elf, &shstrndx) < 0) in find_prelink_address_sync()
277 while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) in find_prelink_address_sync()
287 const char *secname = elf_strptr (mod->main.elf, shstrndx, in find_prelink_address_sync()
320 src.d_size = gelf_fsize (mod->main.elf, ELF_T_EHDR, 1, EV_CURRENT); in find_prelink_address_sync()
322 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
323 elf_getident (mod->main.elf, NULL)[EI_DATA]) in find_prelink_address_sync()
327 size_t shentsize = gelf_fsize (mod->main.elf, ELF_T_SHDR, 1, EV_CURRENT); in find_prelink_address_sync()
328 size_t phentsize = gelf_fsize (mod->main.elf, ELF_T_PHDR, 1, EV_CURRENT); in find_prelink_address_sync()
368 if (unlikely (elf_getphdrnum (mod->main.elf, &main_phnum))) in find_prelink_address_sync()
373 if (unlikely (gelf_getphdr (mod->main.elf, i, &phdr) == NULL)) in find_prelink_address_sync()
399 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
433 src.d_size = gelf_fsize (mod->main.elf, ELF_T_SHDR, shnum - 1, EV_CURRENT); in find_prelink_address_sync()
444 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
471 while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) in find_prelink_address_sync()
483 if (highest > mod->main.vaddr) in find_prelink_address_sync()
485 mod->main.address_sync = highest; in find_prelink_address_sync()
522 find_debuginfo (Dwfl_Module *mod) in find_debuginfo() argument
524 if (mod->debug.elf != NULL) in find_debuginfo()
529 debuglink_file = INTUSE(dwelf_elf_gnu_debuglink) (mod->main.elf, in find_debuginfo()
532 mod->debug.fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod), in find_debuginfo()
533 mod->main.name, in find_debuginfo()
536 &mod->debug.name); in find_debuginfo()
537 Dwfl_Error result = open_elf (mod, &mod->debug); in find_debuginfo()
538 if (result == DWFL_E_NOERROR && mod->debug.address_sync != 0) in find_debuginfo()
539 result = find_prelink_address_sync (mod, &mod->debug); in find_debuginfo()
548 find_debug_altlink (Dwfl_Module *mod, const char *filename) in find_debug_altlink() argument
550 assert (mod->dw != NULL); in find_debug_altlink()
554 ssize_t build_id_len = INTUSE(dwelf_dwarf_gnu_debugaltlink) (mod->dw, in find_debug_altlink()
562 mod->alt_fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod), in find_debug_altlink()
572 Dwfl_Error error = open_elf_file (&mod->alt_elf, &mod->alt_fd, in find_debug_altlink()
576 mod->alt = INTUSE(dwarf_begin_elf) (mod->alt_elf, in find_debug_altlink()
578 if (mod->alt == NULL) in find_debug_altlink()
580 elf_end (mod->alt_elf); in find_debug_altlink()
581 mod->alt_elf = NULL; in find_debug_altlink()
582 close (mod->alt_fd); in find_debug_altlink()
583 mod->alt_fd = -1; in find_debug_altlink()
586 dwarf_setalt (mod->dw, mod->alt); in find_debug_altlink()
697 Dwfl_Module *mod, size_t phnum, in translate_offs() argument
702 find_offsets (mod->main.elf, adjust, phnum, i_max, addrs, offs); in translate_offs()
710 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
715 mod->syments = (entsz == 4 in translate_offs()
719 if (offs[i_gnu_hash] != 0 && mod->syments == 0) in translate_offs()
731 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, offs[i_gnu_hash], in translate_offs()
739 + (gelf_getclass (mod->main.elf) in translate_offs()
750 data = elf_getdata_rawchunk (mod->main.elf, buckets_at, in translate_offs()
766 data = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
773 mod->syments = maxndx + 1; in translate_offs()
783 if (offs[i_strtab] > offs[i_symtab] && mod->syments == 0) in translate_offs()
784 mod->syments = ((offs[i_strtab] - offs[i_symtab]) in translate_offs()
785 / gelf_fsize (mod->main.elf, in translate_offs()
788 if (mod->syments > 0) in translate_offs()
790 mod->symdata = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
792 gelf_fsize (mod->main.elf, in translate_offs()
794 mod->syments, in translate_offs()
797 if (mod->symdata != NULL) in translate_offs()
799 mod->symstrdata = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
803 if (mod->symstrdata == NULL) in translate_offs()
804 mod->symdata = NULL; in translate_offs()
806 if (mod->symdata == NULL) in translate_offs()
807 mod->symerr = DWFL_E (LIBELF, elf_errno ()); in translate_offs()
810 mod->symfile = &mod->main; in translate_offs()
811 mod->symerr = DWFL_E_NOERROR; in translate_offs()
818 find_dynsym (Dwfl_Module *mod) in find_dynsym() argument
821 GElf_Ehdr *ehdr = gelf_getehdr (mod->main.elf, &ehdr_mem); in find_dynsym()
824 if (unlikely (elf_getphdrnum (mod->main.elf, &phnum) != 0)) in find_dynsym()
830 GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem); in find_dynsym()
838 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, in find_dynsym()
846 size_t n = data->d_size / gelf_fsize (mod->main.elf, in find_dynsym()
887 translate_offs (0, mod, phnum, addrs, strsz, ehdr); in find_dynsym()
888 if (mod->symfile == NULL) in find_dynsym()
889 translate_offs (mod->main_bias, mod, phnum, addrs, strsz, ehdr); in find_dynsym()
900 find_aux_address_sync (Dwfl_Module *mod) in find_aux_address_sync() argument
904 mod->aux_sym.address_sync = mod->main.address_sync; in find_aux_address_sync()
909 if (unlikely (gelf_getehdr (mod->main.elf, &ehdr_main) == NULL) in find_aux_address_sync()
910 || unlikely (gelf_getehdr (mod->aux_sym.elf, &ehdr_aux) == NULL)) in find_aux_address_sync()
912 mod->aux_sym.address_sync += ehdr_aux.e_entry - ehdr_main.e_entry; in find_aux_address_sync()
916 if (mod->aux_sym.address_sync != 0) in find_aux_address_sync()
917 return find_prelink_address_sync (mod, &mod->aux_sym) == DWFL_E_NOERROR; in find_aux_address_sync()
927 find_aux_sym (Dwfl_Module *mod __attribute__ ((unused)), in find_aux_sym() argument
935 Elf *elf = mod->main.elf; in find_aux_sym()
977 mod->aux_sym.elf = elf_memory (buffer, size); in find_aux_sym()
978 if (mod->aux_sym.elf == NULL) in find_aux_sym()
982 mod->aux_sym.fd = -1; in find_aux_sym()
983 mod->aux_sym.elf->flags |= ELF_F_MALLOCED; in find_aux_sym()
984 if (open_elf (mod, &mod->aux_sym) != DWFL_E_NOERROR) in find_aux_sym()
986 if (! find_aux_address_sync (mod)) in find_aux_sym()
988 elf_end (mod->aux_sym.elf); in find_aux_sym()
989 mod->aux_sym.elf = NULL; in find_aux_sym()
996 while ((scn = elf_nextscn (mod->aux_sym.elf, scn)) != NULL) in find_aux_sym()
1006 mod->aux_syments = shdr->sh_size / shdr->sh_entsize; in find_aux_sym()
1007 mod->aux_first_global = shdr->sh_info; in find_aux_sym()
1030 mod->aux_syments = 0; in find_aux_sym()
1031 elf_end (mod->aux_sym.elf); in find_aux_sym()
1032 mod->aux_sym.elf = NULL; in find_aux_sym()
1044 find_symtab (Dwfl_Module *mod) in find_symtab() argument
1046 if (mod->symdata != NULL || mod->aux_symdata != NULL /* Already done. */ in find_symtab()
1047 || mod->symerr != DWFL_E_NOERROR) /* Cached previous failure. */ in find_symtab()
1050 __libdwfl_getelf (mod); in find_symtab()
1051 mod->symerr = mod->elferr; in find_symtab()
1052 if (mod->symerr != DWFL_E_NOERROR) in find_symtab()
1059 mod->symerr = load_symtab (&mod->main, &mod->symfile, &symscn, in find_symtab()
1060 &xndxscn, &mod->syments, &mod->first_global, in find_symtab()
1062 switch (mod->symerr) in find_symtab()
1072 mod->symerr = find_debuginfo (mod); in find_symtab()
1073 switch (mod->symerr) in find_symtab()
1079 mod->symerr = load_symtab (&mod->debug, &mod->symfile, &symscn, in find_symtab()
1080 &xndxscn, &mod->syments, in find_symtab()
1081 &mod->first_global, &strshndx); in find_symtab()
1085 mod->symerr = DWFL_E_NO_SYMTAB; in find_symtab()
1089 switch (mod->symerr) in find_symtab()
1099 find_aux_sym (mod, &aux_symscn, &aux_xndxscn, &aux_strshndx); in find_symtab()
1104 mod->symerr = DWFL_E_NOERROR; in find_symtab()
1111 mod->symerr = DWFL_E_NOERROR; in find_symtab()
1116 find_dynsym (mod); in find_symtab()
1123 if (elf_strptr (mod->symfile->elf, strshndx, 0) == NULL) in find_symtab()
1126 mod->symdata = NULL; in find_symtab()
1127 mod->syments = 0; in find_symtab()
1128 mod->first_global = 0; in find_symtab()
1129 mod->symerr = DWFL_E (LIBELF, elf_errno ()); in find_symtab()
1139 Elf_Scn *symstrscn = elf_getscn (mod->symfile->elf, strshndx); in find_symtab()
1149 if (elf_getshdrstrndx (mod->symfile->elf, &shstrndx) < 0) in find_symtab()
1152 const char *sname = elf_strptr (mod->symfile->elf, shstrndx, shdr->sh_name); in find_symtab()
1165 mod->symstrdata = elf_getdata (symstrscn, NULL); in find_symtab()
1166 if (mod->symstrdata == NULL || mod->symstrdata->d_buf == NULL) in find_symtab()
1170 mod->symxndxdata = NULL; in find_symtab()
1181 mod->symxndxdata = elf_getdata (xndxscn, NULL); in find_symtab()
1182 if (mod->symxndxdata == NULL || mod->symxndxdata->d_buf == NULL) in find_symtab()
1194 mod->symdata = elf_getdata (symscn, NULL); in find_symtab()
1195 if (mod->symdata == NULL || mod->symdata->d_buf == NULL) in find_symtab()
1201 || mod->syments > mod->symdata->d_size / shdr->sh_entsize in find_symtab()
1202 || (size_t) mod->first_global > mod->syments) in find_symtab()
1210 if (elf_strptr (mod->aux_sym.elf, aux_strshndx, 0) == NULL) in find_symtab()
1213 mod->aux_syments = 0; in find_symtab()
1214 elf_end (mod->aux_sym.elf); in find_symtab()
1215 mod->aux_sym.elf = NULL; in find_symtab()
1218 find_dynsym (mod); in find_symtab()
1222 Elf_Scn *aux_strscn = elf_getscn (mod->aux_sym.elf, aux_strshndx); in find_symtab()
1231 if (elf_getshdrstrndx (mod->aux_sym.elf, &aux_shstrndx) < 0) in find_symtab()
1234 sname = elf_strptr (mod->aux_sym.elf, aux_shstrndx, in find_symtab()
1248 mod->aux_symstrdata = elf_getdata (aux_strscn, NULL); in find_symtab()
1249 if (mod->aux_symstrdata == NULL || mod->aux_symstrdata->d_buf == NULL) in find_symtab()
1253 mod->aux_symxndxdata = NULL; in find_symtab()
1264 mod->aux_symxndxdata = elf_getdata (aux_xndxscn, NULL); in find_symtab()
1265 if (mod->aux_symxndxdata == NULL in find_symtab()
1266 || mod->aux_symxndxdata->d_buf == NULL) in find_symtab()
1278 mod->aux_symdata = elf_getdata (aux_symscn, NULL); in find_symtab()
1279 if (mod->aux_symdata == NULL || mod->aux_symdata->d_buf == NULL) in find_symtab()
1284 if (mod->aux_syments > mod->aux_symdata->d_size / shdr->sh_entsize in find_symtab()
1285 || (size_t) mod->aux_first_global > mod->aux_syments) in find_symtab()
1294 __libdwfl_module_getebl (Dwfl_Module *mod) in __libdwfl_module_getebl() argument
1296 if (mod->ebl == NULL) in __libdwfl_module_getebl()
1298 __libdwfl_getelf (mod); in __libdwfl_module_getebl()
1299 if (mod->elferr != DWFL_E_NOERROR) in __libdwfl_module_getebl()
1300 return mod->elferr; in __libdwfl_module_getebl()
1302 mod->ebl = ebl_openbackend (mod->main.elf); in __libdwfl_module_getebl()
1303 if (mod->ebl == NULL) in __libdwfl_module_getebl()
1311 load_dw (Dwfl_Module *mod, struct dwfl_file *debugfile) in load_dw() argument
1313 if (mod->e_type == ET_REL && !debugfile->relocated) in load_dw()
1315 const Dwfl_Callbacks *const cb = mod->dwfl->callbacks; in load_dw()
1321 Dwfl_Error error = __libdwfl_module_getebl (mod); in load_dw()
1325 find_symtab (mod); in load_dw()
1326 Dwfl_Error result = mod->symerr; in load_dw()
1328 result = __libdwfl_relocate (mod, debugfile->elf, true); in load_dw()
1333 if (mod->main.fd != -1 && elf_cntl (mod->main.elf, ELF_C_FDREAD) == 0) in load_dw()
1335 close (mod->main.fd); in load_dw()
1336 mod->main.fd = -1; in load_dw()
1345 mod->dw = INTUSE(dwarf_begin_elf) (debugfile->elf, DWARF_C_READ, NULL); in load_dw()
1346 if (mod->dw == NULL) in load_dw()
1353 mod->lazycu = 1; in load_dw()
1360 find_dw (Dwfl_Module *mod) in find_dw() argument
1362 if (mod->dw != NULL /* Already done. */ in find_dw()
1363 || mod->dwerr != DWFL_E_NOERROR) /* Cached previous failure. */ in find_dw()
1366 __libdwfl_getelf (mod); in find_dw()
1367 mod->dwerr = mod->elferr; in find_dw()
1368 if (mod->dwerr != DWFL_E_NOERROR) in find_dw()
1372 mod->dwerr = load_dw (mod, &mod->main); in find_dw()
1373 switch (mod->dwerr) in find_dw()
1376 mod->debug.elf = mod->main.elf; in find_dw()
1377 mod->debug.address_sync = mod->main.address_sync; in find_dw()
1382 find_debug_altlink (mod, mod->main.name); in find_dw()
1393 mod->dwerr = find_debuginfo (mod); in find_dw()
1394 switch (mod->dwerr) in find_dw()
1397 mod->dwerr = load_dw (mod, &mod->debug); in find_dw()
1398 if (mod->dwerr == DWFL_E_NOERROR) in find_dw()
1403 find_debug_altlink (mod, mod->debug.name); in find_dw()
1410 mod->dwerr = DWFL_E_NO_DWARF; in find_dw()
1418 mod->dwerr = __libdwfl_canon_error (mod->dwerr); in find_dw()
1422 dwfl_module_getdwarf (Dwfl_Module *mod, Dwarf_Addr *bias) in dwfl_module_getdwarf() argument
1424 if (mod == NULL) in dwfl_module_getdwarf()
1427 find_dw (mod); in dwfl_module_getdwarf()
1428 if (mod->dwerr == DWFL_E_NOERROR) in dwfl_module_getdwarf()
1432 if (mod->e_type == ET_REL in dwfl_module_getdwarf()
1433 && mod->main.relocated && ! mod->debug.relocated) in dwfl_module_getdwarf()
1435 mod->debug.relocated = true; in dwfl_module_getdwarf()
1436 if (mod->debug.elf != mod->main.elf) in dwfl_module_getdwarf()
1437 (void) __libdwfl_relocate (mod, mod->debug.elf, false); in dwfl_module_getdwarf()
1440 *bias = dwfl_adjusted_dwarf_addr (mod, 0); in dwfl_module_getdwarf()
1441 return mod->dw; in dwfl_module_getdwarf()
1444 __libdwfl_seterrno (mod->dwerr); in dwfl_module_getdwarf()
1450 dwfl_module_getsymtab (Dwfl_Module *mod) in INTDEF()
1452 if (mod == NULL) in INTDEF()
1455 find_symtab (mod); in INTDEF()
1456 if (mod->symerr == DWFL_E_NOERROR) in INTDEF()
1458 return (mod->syments + mod->aux_syments in INTDEF()
1459 - (mod->syments > 0 && mod->aux_syments > 0 ? 1 : 0)); in INTDEF()
1461 __libdwfl_seterrno (mod->symerr); in INTDEF()
1467 dwfl_module_getsymtab_first_global (Dwfl_Module *mod) in INTDEF()
1469 if (mod == NULL) in INTDEF()
1472 find_symtab (mod); in INTDEF()
1473 if (mod->symerr == DWFL_E_NOERROR) in INTDEF()
1480 int skip_aux_zero = (mod->syments > 0 && mod->aux_syments > 0) ? 1 : 0; in INTDEF()
1481 return mod->first_global + mod->aux_first_global - skip_aux_zero; in INTDEF()
1484 __libdwfl_seterrno (mod->symerr); in INTDEF()