static void _copy_optarg(struct ld *ld, char **dst, char *src) { if (*dst != NULL) free(*dst); if ((*dst = strdup(src)) == NULL) ld_fatal_std(ld, "strdup"); }
struct ld_wildcard * ld_wildcard_alloc(struct ld *ld) { struct ld_wildcard *lw; if ((lw = calloc(1, sizeof(*lw))) == NULL) ld_fatal_std(ld, "calloc"); return (lw); }
void ld_dynamic_load_dso_dynamic(struct ld *ld, struct ld_input *li, Elf *e, Elf_Scn *scn, size_t strndx) { GElf_Shdr shdr; GElf_Dyn dyn; Elf_Data *d; int elferr, i, len; const char *name; if (strndx == SHN_UNDEF) return; if (gelf_getshdr(scn, &shdr) != &shdr) { ld_warn(ld, "%s: gelf_getshdr failed: %s", li->li_name, elf_errmsg(-1)); return; } (void) elf_errno(); if ((d = elf_getdata(scn, NULL)) == NULL) { elferr = elf_errno(); if (elferr != 0) ld_warn(ld, "%s: elf_getdata failed: %s", li->li_name, elf_errmsg(elferr)); return; } len = d->d_size / shdr.sh_entsize; for (i = 0; i < len; i++) { if (gelf_getdyn(d, i, &dyn) != &dyn) { ld_warn(ld, "%s: gelf_getdyn failed: %s", li->li_name, elf_errmsg(-1)); continue; } switch (dyn.d_tag) { case DT_SONAME: name = elf_strptr(e, strndx, dyn.d_un.d_ptr); if (name != NULL && (li->li_soname = strdup(name)) == NULL) ld_fatal_std(ld, "strdup"); break; case DT_NEEDED: name = elf_strptr(e, strndx, dyn.d_un.d_ptr); if (name != NULL) ld_path_search_dso_needed(ld, li->li_file, name); break; default: break; } } }
void i386_register(struct ld *ld) { struct ld_arch *i386_arch; if ((i386_arch = calloc(1, sizeof(*i386_arch))) == NULL) ld_fatal_std(ld, "calloc"); snprintf(i386_arch->name, sizeof(i386_arch->name), "%s", "i386"); i386_arch->script = i386_script; i386_arch->get_max_page_size = _get_max_page_size; i386_arch->get_common_page_size = _get_common_page_size; i386_arch->scan_reloc = _scan_reloc; i386_arch->process_reloc = _process_reloc; i386_arch->is_absolute_reloc = _is_absolute_reloc; i386_arch->is_relative_reloc = _is_relative_reloc; i386_arch->reloc_is_64bit = 0; i386_arch->reloc_is_rela = 0; i386_arch->reloc_entsize = sizeof(Elf32_Rel); HASH_ADD_STR(ld->ld_arch_list, name, i386_arch); }