Lines Matching refs:lte

57 arch_elf_init(struct ltelf *lte, struct library *lib)
63 arch_elf_destroy(struct ltelf *lte)
70 os_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
80 arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
90 os_elf_add_func_entry(struct process *proc, struct ltelf *lte,
106 arch_elf_add_func_entry(struct process *proc, struct ltelf *lte,
126 elf_get_section_if(struct ltelf *lte, Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr,
131 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
135 scn = elf_getscn(lte->elf, i);
160 elf_get_section_covering(struct ltelf *lte, GElf_Addr addr,
163 return elf_get_section_if(lte, tgt_sec, tgt_shdr,
175 elf_get_section_type(struct ltelf *lte, GElf_Word type,
178 return elf_get_section_if(lte, tgt_sec, tgt_shdr,
183 struct ltelf *lte;
191 const char *name = elf_strptr(data->lte->elf,
192 data->lte->ehdr.e_shstrndx,
198 elf_get_section_named(struct ltelf *lte, const char *name,
202 .lte = lte,
205 return elf_get_section_if(lte, tgt_sec, tgt_shdr,
240 elf_each_symbol(struct ltelf *lte, unsigned start_after,
250 = each_symbol_in(lte->symtab, lte->strtab,
251 lte->symtab_count, index, cb, data);
260 = each_symbol_in(lte->dynsym, lte->dynstr, lte->dynsym_count,
360 ltelf_init(struct ltelf *lte, const char *filename)
362 memset(lte, 0, sizeof *lte);
363 lte->fd = open(filename, O_RDONLY);
364 if (lte->fd == -1) {
373 lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL);
375 lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL);
378 if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF) {
383 if (gelf_getehdr(lte->elf, &lte->ehdr) == NULL) {
389 if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN) {
397 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS
398 || lte->ehdr.e_machine != LT_ELF_MACHINE)
401 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS2
402 || lte->ehdr.e_machine != LT_ELF_MACHINE2)
405 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS3
406 || lte->ehdr.e_machine != LT_ELF_MACHINE3)
415 VECT_INIT(&lte->plt_relocs, GElf_Rela);
421 ltelf_destroy(struct ltelf *lte)
424 elf_end(lte->elf);
425 close(lte->fd);
426 VECT_DESTROY(&lte->plt_relocs, GElf_Rela, NULL, NULL);
430 read_symbol_table(struct ltelf *lte, const char *filename,
444 scn = elf_getscn(lte->elf, shdr->sh_link);
466 rel_to_rela(struct ltelf *lte, const GElf_Rel *rel, GElf_Rela *rela)
473 if (elf_get_section_covering(lte, rel->r_offset, &sec, &shdr) < 0
483 if (lte->ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
497 elf_read_relocs(struct ltelf *lte, Elf_Scn *scn, GElf_Shdr *shdr,
500 if (vect_reserve_additional(rela_vec, lte->ehdr.e_shnum) < 0)
523 || rel_to_rela(lte, &rel, &rela) < 0)
538 elf_load_dynamic_entry(struct ltelf *lte, int tag, GElf_Addr *valuep)
542 if (elf_get_section_type(lte, SHT_DYNAMIC, &scn, &shdr) < 0
570 ltelf_read_elf(struct ltelf *lte, const char *filename)
580 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
585 scn = elf_getscn(lte->elf, i);
592 name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
600 read_symbol_table(lte, filename,
601 scn, &shdr, name, &lte->symtab,
602 &lte->symtab_count, &lte->strtab);
605 read_symbol_table(lte, filename,
606 scn, &shdr, name, &lte->dynsym,
607 &lte->dynsym_count, &lte->dynstr);
613 lte->dyn_addr = shdr.sh_addr + lte->bias;
614 lte->dyn_sz = shdr.sh_size;
643 lte->plt_addr = shdr.sh_addr;
644 lte->plt_size = shdr.sh_size;
645 lte->plt_data = elf_loaddata(scn, &shdr);
646 if (lte->plt_data == NULL)
649 lte->plt_flags = shdr.sh_flags;
653 lte->opd_addr = (GElf_Addr *) (long) shdr.sh_addr;
654 lte->opd_size = shdr.sh_size;
655 lte->opd = elf_rawdata(scn, NULL);
661 if (lte->dynsym == NULL || lte->dynstr == NULL) {
667 if (!relplt_addr || !lte->plt_addr) {
672 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
676 scn = elf_getscn(lte->elf, i);
685 if (elf_read_relocs(lte, scn, &shdr,
686 &lte->plt_relocs) < 0) {
696 if (i == lte->ehdr.e_shnum) {
704 vect_size(&lte->plt_relocs));
707 lte->soname = lte->dynstr + soname_offset;
714 arch_get_sym_info(struct ltelf *lte, const char *filename,
717 return gelf_getsym(lte->dynsym,
723 default_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
737 GElf_Addr addr = arch_plt_sym_val(lte, ndx, rela);
746 (uintptr_t)(addr + lte->bias);
759 elf_add_plt_entry(struct process *proc, struct ltelf *lte,
764 = arch_elf_add_plt_entry(proc, lte, name, rela, idx, ret);
767 plts = os_elf_add_plt_entry(proc, lte, name, rela, idx, ret);
771 return default_elf_add_plt_entry(proc, lte, name,
812 struct ltelf *lte, struct library *lib)
815 const size_t count = vect_size(&lte->plt_relocs);
819 GElf_Rela *rela = VECT_ELEMENT(&lte->plt_relocs, GElf_Rela, i);
822 switch (arch_get_sym_info(lte, filename, i, rela, &sym)) {
835 char const *name = lte->dynstr + sym.st_name;
840 if (elf_add_plt_entry(proc, lte, name, rela, i, &libsym) < 0)
902 struct ltelf *lte, struct library *lib,
922 GElf_Word secflags[lte->ehdr.e_shnum];
924 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
925 Elf_Scn *scn = elf_getscn(lte->elf, i);
945 || sym.st_shndx >= lte->ehdr.e_shnum)
983 (uintptr_t)(sym.st_value + lte->bias);
992 } else if (arch_translate_address(lte, addr, &naddr) < 0) {
1008 = arch_elf_add_func_entry(proc, lte, &sym,
1011 plts = os_elf_add_func_entry(proc, lte, &sym,
1106 struct ltelf *lte, struct library *lib,
1110 if (symtabs && lte->symtab != NULL && lte->strtab != NULL
1111 && (status = populate_this_symtab(proc, filename, lte, lib,
1112 lte->symtab, lte->strtab,
1113 lte->symtab_count, NULL)) < 0)
1124 return populate_this_symtab(proc, filename, lte, lib,
1125 lte->dynsym, lte->dynstr,
1126 lte->dynsym_count, names);
1133 struct ltelf lte;
1134 if (ltelf_init(&lte, filename) < 0)
1140 * proc->abi = arch_get_abi(lte.ehdr);
1147 proc->e_machine = lte.ehdr.e_machine;
1148 proc->e_class = lte.ehdr.e_ident[EI_CLASS];
1153 if (main && lte.ehdr.e_type == ET_DYN) {
1159 ltelf_destroy(&lte);
1164 lte.entry_addr = (GElf_Addr)(uintptr_t)entry;
1165 lte.bias = (GElf_Addr)(uintptr_t)entry - lte.ehdr.e_entry;
1170 for (i = 0; gelf_getphdr (lte.elf, i, &phdr) != NULL; ++i) {
1172 lte.base_addr = phdr.p_vaddr + bias;
1177 lte.bias = bias;
1178 lte.entry_addr = lte.ehdr.e_entry + lte.bias;
1180 if (lte.base_addr == 0) {
1188 if (ltelf_read_elf(&lte, filename) < 0)
1191 if (arch_elf_init(&lte, lib) < 0) {
1211 if (lte.soname != NULL) {
1212 char *soname = strdup(lte.soname);
1227 arch_addr_t entry = (arch_addr_t)(uintptr_t)lte.entry_addr;
1228 if (arch_translate_address(&lte, entry, &entry) < 0)
1233 lib->base = (arch_addr_t)(uintptr_t)lte.base_addr;
1237 lib->dyn_addr = (arch_addr_t)(uintptr_t)lte.dyn_addr;
1252 && populate_plt(proc, filename, &lte, lib) < 0)
1258 && populate_symtab(proc, filename, &lte, lib,
1262 arch_elf_destroy(&lte);
1263 ltelf_destroy(&lte);