Lines Matching refs:elf
24 struct section *find_section_by_name(struct elf *elf, const char *name) in find_section_by_name() argument
28 list_for_each_entry(sec, &elf->sections, list) in find_section_by_name()
35 static struct section *find_section_by_index(struct elf *elf, in find_section_by_index() argument
40 list_for_each_entry(sec, &elf->sections, list) in find_section_by_index()
47 static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx) in find_symbol_by_index() argument
52 list_for_each_entry(sec, &elf->sections, list) in find_symbol_by_index()
72 struct symbol *find_symbol_by_name(struct elf *elf, const char *name) in find_symbol_by_name() argument
77 list_for_each_entry(sec, &elf->sections, list) in find_symbol_by_name()
131 static int read_sections(struct elf *elf) in read_sections() argument
138 if (elf_getshdrnum(elf->elf, §ions_nr)) { in read_sections()
143 if (elf_getshdrstrndx(elf->elf, &shstrndx)) { in read_sections()
161 list_add_tail(&sec->list, &elf->sections); in read_sections()
163 s = elf_getscn(elf->elf, i); in read_sections()
176 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
199 if (elf_nextscn(elf->elf, s)) { in read_sections()
207 static int read_symbols(struct elf *elf) in read_symbols() argument
215 symtab = find_section_by_name(elf, ".symtab"); in read_symbols()
239 sym->name = elf_strptr(elf->elf, symtab->sh.sh_link, in read_symbols()
251 sym->sec = find_section_by_index(elf, in read_symbols()
263 sym->sec = find_section_by_index(elf, 0); in read_symbols()
296 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
316 pfunc = find_symbol_by_name(elf, pname); in read_symbols()
350 static int read_relas(struct elf *elf) in read_relas() argument
357 list_for_each_entry(sec, &elf->sections, list) { in read_relas()
361 sec->base = find_section_by_name(elf, sec->name + 5); in read_relas()
387 rela->sym = find_symbol_by_index(elf, symndx); in read_relas()
404 struct elf *elf_read(const char *name, int flags) in elf_read()
406 struct elf *elf; in elf_read() local
411 elf = malloc(sizeof(*elf)); in elf_read()
412 if (!elf) { in elf_read()
416 memset(elf, 0, sizeof(*elf)); in elf_read()
418 INIT_LIST_HEAD(&elf->sections); in elf_read()
420 elf->fd = open(name, flags); in elf_read()
421 if (elf->fd == -1) { in elf_read()
434 elf->elf = elf_begin(elf->fd, cmd, NULL); in elf_read()
435 if (!elf->elf) { in elf_read()
440 if (!gelf_getehdr(elf->elf, &elf->ehdr)) { in elf_read()
445 if (read_sections(elf)) in elf_read()
448 if (read_symbols(elf)) in elf_read()
451 if (read_relas(elf)) in elf_read()
454 return elf; in elf_read()
457 elf_close(elf); in elf_read()
461 struct section *elf_create_section(struct elf *elf, const char *name, in elf_create_section() argument
481 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
483 s = elf_newscn(elf->elf); in elf_create_section()
530 shstrtab = find_section_by_name(elf, ".shstrtab"); in elf_create_section()
532 shstrtab = find_section_by_name(elf, ".strtab"); in elf_create_section()
538 s = elf_getscn(elf->elf, shstrtab->idx); in elf_create_section()
562 struct section *elf_create_rela_section(struct elf *elf, struct section *base) in elf_create_rela_section() argument
575 sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); in elf_create_rela_section()
585 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_section()
625 int elf_write(struct elf *elf) in elf_write() argument
631 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
633 s = elf_getscn(elf->elf, sec->idx); in elf_write()
646 elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY); in elf_write()
649 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { in elf_write()
657 void elf_close(struct elf *elf) in elf_close() argument
663 if (elf->elf) in elf_close()
664 elf_end(elf->elf); in elf_close()
666 if (elf->fd > 0) in elf_close()
667 close(elf->fd); in elf_close()
669 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
684 free(elf); in elf_close()