• Home
  • Raw
  • Download

Lines Matching refs:mod

77 open_elf (Dwfl_Module *mod, struct dwfl_file *file)  in open_elf()  argument
156 if (file == &mod->main) in open_elf()
158 mod->e_type = ehdr->e_type; in open_elf()
161 if (mod->e_type == ET_EXEC && file->vaddr != mod->low_addr) in open_elf()
162 mod->e_type = ET_DYN; in open_elf()
165 assert (mod->main.elf != NULL); in open_elf()
173 mod_verify_build_id (Dwfl_Module *mod) in mod_verify_build_id() argument
175 assert (mod->build_id_len > 0); in mod_verify_build_id()
177 switch (__builtin_expect (__libdwfl_find_build_id (mod, false, in mod_verify_build_id()
178 mod->main.elf), 2)) in mod_verify_build_id()
185 mod->elferr = INTUSE(dwfl_errno) (); in mod_verify_build_id()
190 mod->elferr = DWFL_E_WRONG_ID_ELF; in mod_verify_build_id()
198 elf_end (mod->main.elf); in mod_verify_build_id()
199 mod->main.elf = NULL; in mod_verify_build_id()
200 if (mod->main.fd >= 0) in mod_verify_build_id()
202 close (mod->main.fd); in mod_verify_build_id()
203 mod->main.fd = -1; in mod_verify_build_id()
211 __libdwfl_getelf (Dwfl_Module *mod) in __libdwfl_getelf() argument
213 if (mod->main.elf != NULL /* Already done. */ in __libdwfl_getelf()
214 || mod->elferr != DWFL_E_NOERROR) /* Cached failure. */ in __libdwfl_getelf()
217 mod->main.fd = (*mod->dwfl->callbacks->find_elf) (MODCB_ARGS (mod), in __libdwfl_getelf()
218 &mod->main.name, in __libdwfl_getelf()
219 &mod->main.elf); in __libdwfl_getelf()
220 const bool fallback = mod->main.elf == NULL && mod->main.fd < 0; in __libdwfl_getelf()
221 mod->elferr = open_elf (mod, &mod->main); in __libdwfl_getelf()
222 if (mod->elferr != DWFL_E_NOERROR) in __libdwfl_getelf()
225 if (!mod->main.valid) in __libdwfl_getelf()
229 free (mod->build_id_bits); in __libdwfl_getelf()
230 mod->build_id_bits = NULL; in __libdwfl_getelf()
231 mod->build_id_len = 0; in __libdwfl_getelf()
234 mod_verify_build_id (mod); in __libdwfl_getelf()
236 mod->main_bias = mod->e_type == ET_REL ? 0 : mod->low_addr - mod->main.vaddr; in __libdwfl_getelf()
274 find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file) in find_prelink_address_sync() argument
278 if (elf_getshdrstrndx (mod->main.elf, &shstrndx) < 0) in find_prelink_address_sync()
282 while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) in find_prelink_address_sync()
292 const char *secname = elf_strptr (mod->main.elf, shstrndx, in find_prelink_address_sync()
325 src.d_size = gelf_fsize (mod->main.elf, ELF_T_EHDR, 1, EV_CURRENT); in find_prelink_address_sync()
327 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
328 elf_getident (mod->main.elf, NULL)[EI_DATA]) in find_prelink_address_sync()
332 size_t shentsize = gelf_fsize (mod->main.elf, ELF_T_SHDR, 1, EV_CURRENT); in find_prelink_address_sync()
333 size_t phentsize = gelf_fsize (mod->main.elf, ELF_T_PHDR, 1, EV_CURRENT); in find_prelink_address_sync()
375 if (unlikely (elf_getphdrnum (mod->main.elf, &main_phnum))) in find_prelink_address_sync()
380 if (unlikely (gelf_getphdr (mod->main.elf, i, &phdr) == NULL)) in find_prelink_address_sync()
406 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
440 src.d_size = gelf_fsize (mod->main.elf, ELF_T_SHDR, shnum, EV_CURRENT); in find_prelink_address_sync()
451 if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src, in find_prelink_address_sync()
478 while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) in find_prelink_address_sync()
490 if (highest > mod->main.vaddr) in find_prelink_address_sync()
492 mod->main.address_sync = highest; in find_prelink_address_sync()
529 find_debuginfo (Dwfl_Module *mod) in find_debuginfo() argument
531 if (mod->debug.elf != NULL) in find_debuginfo()
536 debuglink_file = INTUSE(dwelf_elf_gnu_debuglink) (mod->main.elf, in find_debuginfo()
539 mod->debug.fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod), in find_debuginfo()
540 mod->main.name, in find_debuginfo()
543 &mod->debug.name); in find_debuginfo()
544 Dwfl_Error result = open_elf (mod, &mod->debug); in find_debuginfo()
545 if (result == DWFL_E_NOERROR && mod->debug.address_sync != 0) in find_debuginfo()
546 result = find_prelink_address_sync (mod, &mod->debug); in find_debuginfo()
555 find_debug_altlink (Dwfl_Module *mod, const char *filename) in find_debug_altlink() argument
557 assert (mod->dw != NULL); in find_debug_altlink()
561 ssize_t build_id_len = INTUSE(dwelf_dwarf_gnu_debugaltlink) (mod->dw, in find_debug_altlink()
569 mod->alt_fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod), in find_debug_altlink()
579 Dwfl_Error error = open_elf_file (&mod->alt_elf, &mod->alt_fd, in find_debug_altlink()
583 mod->alt = INTUSE(dwarf_begin_elf) (mod->alt_elf, in find_debug_altlink()
585 if (mod->alt == NULL) in find_debug_altlink()
587 elf_end (mod->alt_elf); in find_debug_altlink()
588 mod->alt_elf = NULL; in find_debug_altlink()
589 close (mod->alt_fd); in find_debug_altlink()
590 mod->alt_fd = -1; in find_debug_altlink()
593 dwarf_setalt (mod->dw, mod->alt); in find_debug_altlink()
704 Dwfl_Module *mod, size_t phnum, in translate_offs() argument
709 find_offsets (mod->main.elf, adjust, phnum, i_max, addrs, offs); in translate_offs()
717 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
722 mod->syments = (entsz == 4 in translate_offs()
726 if (offs[i_gnu_hash] != 0 && mod->syments == 0) in translate_offs()
738 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, offs[i_gnu_hash], in translate_offs()
746 + (gelf_getclass (mod->main.elf) in translate_offs()
757 data = elf_getdata_rawchunk (mod->main.elf, buckets_at, in translate_offs()
773 data = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
780 mod->syments = maxndx + 1; in translate_offs()
790 if (offs[i_strtab] > offs[i_symtab] && mod->syments == 0) in translate_offs()
791 mod->syments = ((offs[i_strtab] - offs[i_symtab]) in translate_offs()
792 / gelf_fsize (mod->main.elf, in translate_offs()
795 if (mod->syments > 0) in translate_offs()
797 mod->symdata = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
799 gelf_fsize (mod->main.elf, in translate_offs()
801 mod->syments, in translate_offs()
804 if (mod->symdata != NULL) in translate_offs()
806 mod->symstrdata = elf_getdata_rawchunk (mod->main.elf, in translate_offs()
810 if (mod->symstrdata == NULL) in translate_offs()
811 mod->symdata = NULL; in translate_offs()
813 if (mod->symdata == NULL) in translate_offs()
814 mod->symerr = DWFL_E (LIBELF, elf_errno ()); in translate_offs()
817 mod->symfile = &mod->main; in translate_offs()
818 mod->symerr = DWFL_E_NOERROR; in translate_offs()
825 find_dynsym (Dwfl_Module *mod) in find_dynsym() argument
828 GElf_Ehdr *ehdr = gelf_getehdr (mod->main.elf, &ehdr_mem); in find_dynsym()
831 if (unlikely (elf_getphdrnum (mod->main.elf, &phnum) != 0)) in find_dynsym()
837 GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem); in find_dynsym()
845 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, in find_dynsym()
853 size_t n = data->d_size / gelf_fsize (mod->main.elf, in find_dynsym()
894 translate_offs (0, mod, phnum, addrs, strsz, ehdr); in find_dynsym()
895 if (mod->symfile == NULL) in find_dynsym()
896 translate_offs (mod->main_bias, mod, phnum, addrs, strsz, ehdr); in find_dynsym()
907 find_aux_address_sync (Dwfl_Module *mod) in find_aux_address_sync() argument
911 mod->aux_sym.address_sync = mod->main.address_sync; in find_aux_address_sync()
916 if (unlikely (gelf_getehdr (mod->main.elf, &ehdr_main) == NULL) in find_aux_address_sync()
917 || unlikely (gelf_getehdr (mod->aux_sym.elf, &ehdr_aux) == NULL)) in find_aux_address_sync()
919 mod->aux_sym.address_sync += ehdr_aux.e_entry - ehdr_main.e_entry; in find_aux_address_sync()
923 if (mod->aux_sym.address_sync != 0) in find_aux_address_sync()
924 return find_prelink_address_sync (mod, &mod->aux_sym) == DWFL_E_NOERROR; in find_aux_address_sync()
934 find_aux_sym (Dwfl_Module *mod __attribute__ ((unused)), in find_aux_sym() argument
942 Elf *elf = mod->main.elf; in find_aux_sym()
984 mod->aux_sym.elf = elf_memory (buffer, size); in find_aux_sym()
985 if (mod->aux_sym.elf == NULL) in find_aux_sym()
989 mod->aux_sym.fd = -1; in find_aux_sym()
990 mod->aux_sym.elf->flags |= ELF_F_MALLOCED; in find_aux_sym()
991 if (open_elf (mod, &mod->aux_sym) != DWFL_E_NOERROR) in find_aux_sym()
993 if (! find_aux_address_sync (mod)) in find_aux_sym()
995 elf_end (mod->aux_sym.elf); in find_aux_sym()
996 mod->aux_sym.elf = NULL; in find_aux_sym()
1003 while ((scn = elf_nextscn (mod->aux_sym.elf, scn)) != NULL) in find_aux_sym()
1015 mod->aux_syments = shdr->sh_size / shdr->sh_entsize; in find_aux_sym()
1016 mod->aux_first_global = shdr->sh_info; in find_aux_sym()
1039 mod->aux_syments = 0; in find_aux_sym()
1040 elf_end (mod->aux_sym.elf); in find_aux_sym()
1041 mod->aux_sym.elf = NULL; in find_aux_sym()
1053 find_symtab (Dwfl_Module *mod) in find_symtab() argument
1055 if (mod->symdata != NULL || mod->aux_symdata != NULL /* Already done. */ in find_symtab()
1056 || mod->symerr != DWFL_E_NOERROR) /* Cached previous failure. */ in find_symtab()
1059 __libdwfl_getelf (mod); in find_symtab()
1060 mod->symerr = mod->elferr; in find_symtab()
1061 if (mod->symerr != DWFL_E_NOERROR) in find_symtab()
1068 mod->symerr = load_symtab (&mod->main, &mod->symfile, &symscn, in find_symtab()
1069 &xndxscn, &mod->syments, &mod->first_global, in find_symtab()
1071 switch (mod->symerr) in find_symtab()
1081 mod->symerr = find_debuginfo (mod); in find_symtab()
1082 switch (mod->symerr) in find_symtab()
1088 mod->symerr = load_symtab (&mod->debug, &mod->symfile, &symscn, in find_symtab()
1089 &xndxscn, &mod->syments, in find_symtab()
1090 &mod->first_global, &strshndx); in find_symtab()
1094 mod->symerr = DWFL_E_NO_SYMTAB; in find_symtab()
1098 switch (mod->symerr) in find_symtab()
1108 find_aux_sym (mod, &aux_symscn, &aux_xndxscn, &aux_strshndx); in find_symtab()
1113 mod->symerr = DWFL_E_NOERROR; in find_symtab()
1120 mod->symerr = DWFL_E_NOERROR; in find_symtab()
1125 find_dynsym (mod); in find_symtab()
1132 if (elf_strptr (mod->symfile->elf, strshndx, 0) == NULL) in find_symtab()
1135 mod->symdata = NULL; in find_symtab()
1136 mod->syments = 0; in find_symtab()
1137 mod->first_global = 0; in find_symtab()
1138 mod->symerr = DWFL_E (LIBELF, elf_errno ()); in find_symtab()
1148 Elf_Scn *symstrscn = elf_getscn (mod->symfile->elf, strshndx); in find_symtab()
1158 if (elf_getshdrstrndx (mod->symfile->elf, &shstrndx) < 0) in find_symtab()
1161 const char *sname = elf_strptr (mod->symfile->elf, shstrndx, shdr->sh_name); in find_symtab()
1174 mod->symstrdata = elf_getdata (symstrscn, NULL); in find_symtab()
1175 if (mod->symstrdata == NULL || mod->symstrdata->d_buf == NULL) in find_symtab()
1179 mod->symxndxdata = NULL; in find_symtab()
1190 mod->symxndxdata = elf_getdata (xndxscn, NULL); in find_symtab()
1191 if (mod->symxndxdata == NULL || mod->symxndxdata->d_buf == NULL) in find_symtab()
1203 mod->symdata = elf_getdata (symscn, NULL); in find_symtab()
1204 if (mod->symdata == NULL || mod->symdata->d_buf == NULL) in find_symtab()
1210 || mod->syments > mod->symdata->d_size / shdr->sh_entsize in find_symtab()
1211 || (size_t) mod->first_global > mod->syments) in find_symtab()
1219 if (elf_strptr (mod->aux_sym.elf, aux_strshndx, 0) == NULL) in find_symtab()
1222 mod->aux_syments = 0; in find_symtab()
1223 elf_end (mod->aux_sym.elf); in find_symtab()
1224 mod->aux_sym.elf = NULL; in find_symtab()
1227 find_dynsym (mod); in find_symtab()
1231 Elf_Scn *aux_strscn = elf_getscn (mod->aux_sym.elf, aux_strshndx); in find_symtab()
1240 if (elf_getshdrstrndx (mod->aux_sym.elf, &aux_shstrndx) < 0) in find_symtab()
1243 sname = elf_strptr (mod->aux_sym.elf, aux_shstrndx, in find_symtab()
1257 mod->aux_symstrdata = elf_getdata (aux_strscn, NULL); in find_symtab()
1258 if (mod->aux_symstrdata == NULL || mod->aux_symstrdata->d_buf == NULL) in find_symtab()
1262 mod->aux_symxndxdata = NULL; in find_symtab()
1273 mod->aux_symxndxdata = elf_getdata (aux_xndxscn, NULL); in find_symtab()
1274 if (mod->aux_symxndxdata == NULL in find_symtab()
1275 || mod->aux_symxndxdata->d_buf == NULL) in find_symtab()
1287 mod->aux_symdata = elf_getdata (aux_symscn, NULL); in find_symtab()
1288 if (mod->aux_symdata == NULL || mod->aux_symdata->d_buf == NULL) in find_symtab()
1293 if (mod->aux_syments > mod->aux_symdata->d_size / shdr->sh_entsize in find_symtab()
1294 || (size_t) mod->aux_first_global > mod->aux_syments) in find_symtab()
1303 __libdwfl_module_getebl (Dwfl_Module *mod) in __libdwfl_module_getebl() argument
1305 if (mod->ebl == NULL) in __libdwfl_module_getebl()
1307 __libdwfl_getelf (mod); in __libdwfl_module_getebl()
1308 if (mod->elferr != DWFL_E_NOERROR) in __libdwfl_module_getebl()
1309 return mod->elferr; in __libdwfl_module_getebl()
1311 mod->ebl = ebl_openbackend (mod->main.elf); in __libdwfl_module_getebl()
1312 if (mod->ebl == NULL) in __libdwfl_module_getebl()
1320 load_dw (Dwfl_Module *mod, struct dwfl_file *debugfile) in load_dw() argument
1322 if (mod->e_type == ET_REL && !debugfile->relocated) in load_dw()
1324 const Dwfl_Callbacks *const cb = mod->dwfl->callbacks; in load_dw()
1330 Dwfl_Error error = __libdwfl_module_getebl (mod); in load_dw()
1334 find_symtab (mod); in load_dw()
1335 Dwfl_Error result = mod->symerr; in load_dw()
1337 result = __libdwfl_relocate (mod, debugfile->elf, true); in load_dw()
1342 mod->dw = INTUSE(dwarf_begin_elf) (debugfile->elf, DWARF_C_READ, NULL); in load_dw()
1343 if (mod->dw == NULL) in load_dw()
1350 if (mod->e_type == ET_REL && !debugfile->relocated) in load_dw()
1353 if (mod->main.fd != -1 && elf_cntl (mod->main.elf, ELF_C_FDREAD) == 0) in load_dw()
1355 close (mod->main.fd); in load_dw()
1356 mod->main.fd = -1; in load_dw()
1368 if (mod->dw->debugdir == NULL && mod->elfdir != NULL in load_dw()
1369 && debugfile == &mod->main) in load_dw()
1370 mod->dw->debugdir = strdup (mod->elfdir); in load_dw()
1373 mod->lazycu = 1; in load_dw()
1380 find_dw (Dwfl_Module *mod) in find_dw() argument
1382 if (mod->dw != NULL /* Already done. */ in find_dw()
1383 || mod->dwerr != DWFL_E_NOERROR) /* Cached previous failure. */ in find_dw()
1386 __libdwfl_getelf (mod); in find_dw()
1387 mod->dwerr = mod->elferr; in find_dw()
1388 if (mod->dwerr != DWFL_E_NOERROR) in find_dw()
1392 mod->dwerr = load_dw (mod, &mod->main); in find_dw()
1393 switch (mod->dwerr) in find_dw()
1396 mod->debug.elf = mod->main.elf; in find_dw()
1397 mod->debug.address_sync = mod->main.address_sync; in find_dw()
1402 find_debug_altlink (mod, mod->main.name); in find_dw()
1413 mod->dwerr = find_debuginfo (mod); in find_dw()
1414 switch (mod->dwerr) in find_dw()
1417 mod->dwerr = load_dw (mod, &mod->debug); in find_dw()
1418 if (mod->dwerr == DWFL_E_NOERROR) in find_dw()
1423 find_debug_altlink (mod, mod->debug.name); in find_dw()
1430 mod->dwerr = DWFL_E_NO_DWARF; in find_dw()
1438 mod->dwerr = __libdwfl_canon_error (mod->dwerr); in find_dw()
1442 dwfl_module_getdwarf (Dwfl_Module *mod, Dwarf_Addr *bias) in dwfl_module_getdwarf() argument
1444 if (mod == NULL) in dwfl_module_getdwarf()
1447 find_dw (mod); in dwfl_module_getdwarf()
1448 if (mod->dwerr == DWFL_E_NOERROR) in dwfl_module_getdwarf()
1452 if (mod->e_type == ET_REL in dwfl_module_getdwarf()
1453 && mod->main.relocated && ! mod->debug.relocated) in dwfl_module_getdwarf()
1455 mod->debug.relocated = true; in dwfl_module_getdwarf()
1456 if (mod->debug.elf != mod->main.elf) in dwfl_module_getdwarf()
1457 (void) __libdwfl_relocate (mod, mod->debug.elf, false); in dwfl_module_getdwarf()
1460 *bias = dwfl_adjusted_dwarf_addr (mod, 0); in dwfl_module_getdwarf()
1461 return mod->dw; in dwfl_module_getdwarf()
1464 __libdwfl_seterrno (mod->dwerr); in dwfl_module_getdwarf()
1470 dwfl_module_getsymtab (Dwfl_Module *mod) in INTDEF()
1472 if (mod == NULL) in INTDEF()
1475 find_symtab (mod); in INTDEF()
1476 if (mod->symerr == DWFL_E_NOERROR) in INTDEF()
1478 return (mod->syments + mod->aux_syments in INTDEF()
1479 - (mod->syments > 0 && mod->aux_syments > 0 ? 1 : 0)); in INTDEF()
1481 __libdwfl_seterrno (mod->symerr); in INTDEF()
1487 dwfl_module_getsymtab_first_global (Dwfl_Module *mod) in INTDEF()
1489 if (mod == NULL) in INTDEF()
1492 find_symtab (mod); in INTDEF()
1493 if (mod->symerr == DWFL_E_NOERROR) in INTDEF()
1500 int skip_aux_zero = (mod->syments > 0 && mod->aux_syments > 0) ? 1 : 0; in INTDEF()
1501 return mod->first_global + mod->aux_first_global - skip_aux_zero; in INTDEF()
1504 __libdwfl_seterrno (mod->symerr); in INTDEF()