Lines Matching refs:elf
34 struct section *find_section_by_name(struct elf *elf, const char *name) in find_section_by_name() argument
38 list_for_each_entry(sec, &elf->sections, list) in find_section_by_name()
45 static struct section *find_section_by_index(struct elf *elf, in find_section_by_index() argument
50 list_for_each_entry(sec, &elf->sections, list) in find_section_by_index()
57 static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx) in find_symbol_by_index() argument
62 list_for_each_entry(sec, &elf->sections, list) in find_symbol_by_index()
82 struct symbol *find_symbol_by_name(struct elf *elf, const char *name) in find_symbol_by_name() argument
87 list_for_each_entry(sec, &elf->sections, list) in find_symbol_by_name()
141 static int read_sections(struct elf *elf) in read_sections() argument
148 if (elf_getshdrnum(elf->elf, §ions_nr)) { in read_sections()
153 if (elf_getshdrstrndx(elf->elf, &shstrndx)) { in read_sections()
171 list_add_tail(&sec->list, &elf->sections); in read_sections()
173 s = elf_getscn(elf->elf, i); in read_sections()
186 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
209 if (elf_nextscn(elf->elf, s)) { in read_sections()
217 static int read_symbols(struct elf *elf) in read_symbols() argument
225 symtab = find_section_by_name(elf, ".symtab"); in read_symbols()
248 sym->name = elf_strptr(elf->elf, symtab->sh.sh_link, in read_symbols()
260 sym->sec = find_section_by_index(elf, in read_symbols()
272 sym->sec = find_section_by_index(elf, 0); in read_symbols()
299 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
309 pfunc = find_symbol_by_name(elf, sym->name); in read_symbols()
344 static int read_relas(struct elf *elf) in read_relas() argument
351 list_for_each_entry(sec, &elf->sections, list) { in read_relas()
355 sec->base = find_section_by_name(elf, sec->name + 5); in read_relas()
381 rela->sym = find_symbol_by_index(elf, symndx); in read_relas()
397 struct elf *elf_open(const char *name, int flags) in elf_open()
399 struct elf *elf; in elf_open() local
404 elf = malloc(sizeof(*elf)); in elf_open()
405 if (!elf) { in elf_open()
409 memset(elf, 0, sizeof(*elf)); in elf_open()
411 INIT_LIST_HEAD(&elf->sections); in elf_open()
413 elf->fd = open(name, flags); in elf_open()
414 if (elf->fd == -1) { in elf_open()
427 elf->elf = elf_begin(elf->fd, cmd, NULL); in elf_open()
428 if (!elf->elf) { in elf_open()
433 if (!gelf_getehdr(elf->elf, &elf->ehdr)) { in elf_open()
438 if (read_sections(elf)) in elf_open()
441 if (read_symbols(elf)) in elf_open()
444 if (read_relas(elf)) in elf_open()
447 return elf; in elf_open()
450 elf_close(elf); in elf_open()
454 struct section *elf_create_section(struct elf *elf, const char *name, in elf_create_section() argument
474 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
476 s = elf_newscn(elf->elf); in elf_create_section()
523 shstrtab = find_section_by_name(elf, ".shstrtab"); in elf_create_section()
525 shstrtab = find_section_by_name(elf, ".strtab"); in elf_create_section()
531 s = elf_getscn(elf->elf, shstrtab->idx); in elf_create_section()
555 struct section *elf_create_rela_section(struct elf *elf, struct section *base) in elf_create_rela_section() argument
568 sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); in elf_create_rela_section()
578 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_section()
618 int elf_write(struct elf *elf) in elf_write() argument
624 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
626 s = elf_getscn(elf->elf, sec->idx); in elf_write()
639 elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY); in elf_write()
642 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { in elf_write()
650 void elf_close(struct elf *elf) in elf_close() argument
656 if (elf->elf) in elf_close()
657 elf_end(elf->elf); in elf_close()
659 if (elf->fd > 0) in elf_close()
660 close(elf->fd); in elf_close()
662 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
677 free(elf); in elf_close()