Lines Matching refs:mod
59 open_elf (Dwfl_Module *mod, struct dwfl_file *file)
95 if (mod->e_type != ET_EXEC)
104 file->bias = ((mod->low_addr & -ph->p_align)
110 mod->e_type = ehdr->e_type;
113 if (mod->e_type == ET_EXEC && file->bias != 0)
114 mod->e_type = ET_DYN;
122 find_file (Dwfl_Module *mod)
124 if (mod->main.elf != NULL /* Already done. */
125 || mod->elferr != DWFL_E_NOERROR) /* Cached failure. */
128 mod->main.fd = (*mod->dwfl->callbacks->find_elf) (MODCB_ARGS (mod),
129 &mod->main.name,
130 &mod->main.elf);
131 mod->elferr = open_elf (mod, &mod->main);
133 if (mod->elferr == DWFL_E_NOERROR && !mod->main.valid)
137 free (mod->build_id_bits);
138 mod->build_id_bits = NULL;
139 mod->build_id_len = 0;
207 find_debuginfo (Dwfl_Module *mod)
209 if (mod->debug.elf != NULL)
213 const char *debuglink_file = find_debuglink (mod->main.elf, &debuglink_crc);
215 mod->debug.fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod),
216 mod->main.name,
219 &mod->debug.name);
220 return open_elf (mod, &mod->debug);
308 find_dynsym (Dwfl_Module *mod)
311 GElf_Ehdr *ehdr = gelf_getehdr (mod->main.elf, &ehdr_mem);
316 GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem);
324 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf,
340 size_t n = data->d_size / gelf_fsize (mod->main.elf,
380 find_offsets (mod->main.elf, ehdr, i_max, addrs, offs);
388 data = elf_getdata_rawchunk (mod->main.elf,
393 mod->syments = (entsz == 4
397 if (offs[i_gnu_hash] != 0 && mod->syments == 0)
409 data = elf_getdata_rawchunk (mod->main.elf, offs[i_gnu_hash],
417 + (gelf_getclass (mod->main.elf)
421 data = elf_getdata_rawchunk (mod->main.elf, buckets_at,
437 data = elf_getdata_rawchunk (mod->main.elf,
444 mod->syments = maxndx + 1;
453 if (offs[i_strtab] > offs[i_symtab] && mod->syments == 0)
454 mod->syments = ((offs[i_strtab] - offs[i_symtab])
455 / gelf_fsize (mod->main.elf,
458 if (mod->syments > 0)
460 mod->symdata = elf_getdata_rawchunk (mod->main.elf,
462 gelf_fsize (mod->main.elf,
464 mod->syments,
467 if (mod->symdata != NULL)
469 mod->symstrdata = elf_getdata_rawchunk (mod->main.elf,
473 if (mod->symstrdata == NULL)
474 mod->symdata = NULL;
476 if (mod->symdata == NULL)
477 mod->symerr = DWFL_E (LIBELF, elf_errno ());
480 mod->symfile = &mod->main;
481 mod->symerr = DWFL_E_NOERROR;
491 find_symtab (Dwfl_Module *mod)
493 if (mod->symdata != NULL /* Already done. */
494 || mod->symerr != DWFL_E_NOERROR) /* Cached previous failure. */
497 find_file (mod);
498 mod->symerr = mod->elferr;
499 if (mod->symerr != DWFL_E_NOERROR)
505 mod->symerr = load_symtab (&mod->main, &mod->symfile, &symscn,
506 &xndxscn, &mod->syments, &strshndx);
507 switch (mod->symerr)
517 mod->symerr = find_debuginfo (mod);
518 switch (mod->symerr)
524 mod->symerr = load_symtab (&mod->debug, &mod->symfile, &symscn,
525 &xndxscn, &mod->syments, &strshndx);
529 mod->symerr = DWFL_E_NO_SYMTAB;
533 switch (mod->symerr)
545 mod->symerr = DWFL_E_NOERROR;
550 find_dynsym (mod);
557 if (elf_strptr (mod->symfile->elf, strshndx, 0) == NULL)
560 mod->symerr = DWFL_E (LIBELF, elf_errno ());
566 mod->symstrdata = elf_getdata (elf_getscn (mod->symfile->elf, strshndx),
568 if (mod->symstrdata == NULL)
572 mod->symxndxdata = NULL;
575 mod->symxndxdata = elf_getdata (xndxscn, NULL);
576 if (mod->symxndxdata == NULL)
580 mod->symdata = elf_getdata (symscn, NULL);
581 if (mod->symdata == NULL)
589 __libdwfl_module_getebl (Dwfl_Module *mod)
591 if (mod->ebl == NULL)
593 find_file (mod);
594 if (mod->elferr != DWFL_E_NOERROR)
595 return mod->elferr;
597 mod->ebl = ebl_openbackend (mod->main.elf);
598 if (mod->ebl == NULL)
606 load_dw (Dwfl_Module *mod, struct dwfl_file *debugfile)
608 if (mod->e_type == ET_REL && !debugfile->relocated)
610 const Dwfl_Callbacks *const cb = mod->dwfl->callbacks;
616 Dwfl_Error error = __libdwfl_module_getebl (mod);
620 find_symtab (mod);
621 Dwfl_Error result = mod->symerr;
623 result = __libdwfl_relocate (mod, debugfile->elf, true);
628 if (mod->main.fd != -1 && elf_cntl (mod->main.elf, ELF_C_FDREAD) == 0)
630 close (mod->main.fd);
631 mod->main.fd = -1;
640 mod->dw = INTUSE(dwarf_begin_elf) (debugfile->elf, DWARF_C_READ, NULL);
641 if (mod->dw == NULL)
648 mod->lazycu = 1;
655 find_dw (Dwfl_Module *mod)
657 if (mod->dw != NULL /* Already done. */
658 || mod->dwerr != DWFL_E_NOERROR) /* Cached previous failure. */
661 find_file (mod);
662 mod->dwerr = mod->elferr;
663 if (mod->dwerr != DWFL_E_NOERROR)
667 mod->dwerr = load_dw (mod, &mod->main);
668 switch (mod->dwerr)
671 mod->debug.elf = mod->main.elf;
672 mod->debug.bias = mod->main.bias;
683 mod->dwerr = find_debuginfo (mod);
684 switch (mod->dwerr)
687 mod->dwerr = load_dw (mod, &mod->debug);
691 mod->dwerr = DWFL_E_NO_DWARF;
699 mod->dwerr = __libdwfl_canon_error (mod->dwerr);
704 dwfl_module_getelf (Dwfl_Module *mod, GElf_Addr *loadbase)
706 if (mod == NULL)
709 find_file (mod);
710 if (mod->elferr == DWFL_E_NOERROR)
712 if (mod->e_type == ET_REL && ! mod->main.relocated)
717 mod->main.relocated = true;
718 if (likely (__libdwfl_module_getebl (mod) == DWFL_E_NOERROR))
720 (void) __libdwfl_relocate (mod, mod->main.elf, false);
722 if (mod->debug.elf == mod->main.elf)
723 mod->debug.relocated = true;
724 else if (mod->debug.elf != NULL && ! mod->debug.relocated)
726 mod->debug.relocated = true;
727 (void) __libdwfl_relocate (mod, mod->debug.elf, false);
732 *loadbase = mod->main.bias;
733 return mod->main.elf;
736 __libdwfl_seterrno (mod->elferr);
743 dwfl_module_getdwarf (Dwfl_Module *mod, Dwarf_Addr *bias)
745 if (mod == NULL)
748 find_dw (mod);
749 if (mod->dwerr == DWFL_E_NOERROR)
753 if (mod->e_type == ET_REL
754 && mod->main.relocated && ! mod->debug.relocated)
756 mod->debug.relocated = true;
757 if (mod->debug.elf != mod->main.elf)
758 (void) __libdwfl_relocate (mod, mod->debug.elf, false);
761 *bias = mod->debug.bias;
762 return mod->dw;
765 __libdwfl_seterrno (mod->dwerr);
771 dwfl_module_getsymtab (Dwfl_Module *mod)
773 if (mod == NULL)
776 find_symtab (mod);
777 if (mod->symerr == DWFL_E_NOERROR)
778 return mod->syments;
780 __libdwfl_seterrno (mod->symerr);