Lines Matching refs:elf

31 #define __elf_table(name)	(elf->name##_hash)
32 #define __elf_bits(name) (elf->name##_bits)
111 struct section *find_section_by_name(const struct elf *elf, const char *name) in find_section_by_name() argument
123 static struct section *find_section_by_index(struct elf *elf, in find_section_by_index() argument
136 static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx) in find_symbol_by_index() argument
239 struct symbol *find_symbol_by_name(const struct elf *elf, const char *name) in find_symbol_by_name() argument
251 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec, in find_reloc_by_dest_range() argument
280 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset) in find_reloc_by_dest() argument
282 return find_reloc_by_dest_range(elf, sec, offset, 1); in find_reloc_by_dest()
285 static int read_sections(struct elf *elf) in read_sections() argument
292 if (elf_getshdrnum(elf->elf, &sections_nr)) { in read_sections()
297 if (elf_getshdrstrndx(elf->elf, &shstrndx)) { in read_sections()
317 s = elf_getscn(elf->elf, i); in read_sections()
330 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
351 elf->text_size += sec->sh.sh_size; in read_sections()
353 list_add_tail(&sec->list, &elf->sections); in read_sections()
360 printf("section_bits: %d\n", elf->section_bits); in read_sections()
364 if (elf_nextscn(elf->elf, s)) { in read_sections()
372 static void elf_add_symbol(struct elf *elf, struct symbol *sym) in elf_add_symbol() argument
384 elf->num_files++; in elf_add_symbol()
407 static int read_symbols(struct elf *elf) in read_symbols() argument
416 symtab = find_section_by_name(elf, ".symtab"); in read_symbols()
418 symtab_shndx = find_section_by_name(elf, ".symtab_shndx"); in read_symbols()
453 sym->name = elf_strptr(elf->elf, symtab->sh.sh_link, in read_symbols()
466 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
477 sym->sec = find_section_by_index(elf, 0); in read_symbols()
479 elf_add_symbol(elf, sym); in read_symbols()
484 printf("symbol_bits: %d\n", elf->symbol_bits); in read_symbols()
488 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
514 pfunc = find_symbol_by_name(elf, pname); in read_symbols()
548 static struct section *elf_create_reloc_section(struct elf *elf,
552 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, in elf_add_reloc() argument
557 if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) in elf_add_reloc()
587 static void elf_dirty_reloc_sym(struct elf *elf, struct symbol *sym) in elf_dirty_reloc_sym() argument
591 list_for_each_entry(sec, &elf->sections, list) { in elf_dirty_reloc_sym()
614 static int elf_update_symbol(struct elf *elf, struct section *symtab, in elf_update_symbol() argument
628 s = elf_getscn(elf->elf, symtab->idx); in elf_update_symbol()
635 t = elf_getscn(elf->elf, symtab_shndx->idx); in elf_update_symbol()
733 elf_create_section_symbol(struct elf *elf, struct section *sec) in elf_create_section_symbol() argument
739 symtab = find_section_by_name(elf, ".symtab"); in elf_create_section_symbol()
741 symtab_shndx = find_section_by_name(elf, ".symtab_shndx"); in elf_create_section_symbol()
768 old = find_symbol_by_index(elf, first_non_local); in elf_create_section_symbol()
775 elf_dirty_reloc_sym(elf, old); in elf_create_section_symbol()
777 if (elf_update_symbol(elf, symtab, symtab_shndx, old)) { in elf_create_section_symbol()
786 if (elf_update_symbol(elf, symtab, symtab_shndx, sym)) { in elf_create_section_symbol()
796 elf_add_symbol(elf, sym); in elf_create_section_symbol()
801 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, in elf_add_reloc_to_insn() argument
815 sym = elf_create_section_symbol(elf, insn_sec); in elf_add_reloc_to_insn()
822 return elf_add_reloc(elf, sec, offset, type, sym, addend); in elf_add_reloc_to_insn()
851 static int read_relocs(struct elf *elf) in read_relocs() argument
859 if (!elf_alloc_hash(reloc, elf->text_size / 16)) in read_relocs()
862 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
867 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
898 reloc->sym = find_symbol_by_index(elf, symndx); in read_relocs()
917 printf("reloc_bits: %d\n", elf->reloc_bits); in read_relocs()
923 struct elf *elf_open_read(const char *name, int flags) in elf_open_read()
925 struct elf *elf; in elf_open_read() local
930 elf = malloc(sizeof(*elf)); in elf_open_read()
931 if (!elf) { in elf_open_read()
935 memset(elf, 0, offsetof(struct elf, sections)); in elf_open_read()
937 INIT_LIST_HEAD(&elf->sections); in elf_open_read()
939 elf->fd = open(name, flags); in elf_open_read()
940 if (elf->fd == -1) { in elf_open_read()
953 elf->elf = elf_begin(elf->fd, cmd, NULL); in elf_open_read()
954 if (!elf->elf) { in elf_open_read()
959 if (!gelf_getehdr(elf->elf, &elf->ehdr)) { in elf_open_read()
964 if (read_sections(elf)) in elf_open_read()
967 if (read_symbols(elf)) in elf_open_read()
970 if (read_relocs(elf)) in elf_open_read()
973 return elf; in elf_open_read()
976 elf_close(elf); in elf_open_read()
980 static int elf_add_string(struct elf *elf, struct section *strtab, char *str) in elf_add_string() argument
987 strtab = find_section_by_name(elf, ".strtab"); in elf_add_string()
993 s = elf_getscn(elf->elf, strtab->idx); in elf_add_string()
1016 struct section *elf_create_section(struct elf *elf, const char *name, in elf_create_section() argument
1033 s = elf_newscn(elf->elf); in elf_create_section()
1078 shstrtab = find_section_by_name(elf, ".shstrtab"); in elf_create_section()
1080 shstrtab = find_section_by_name(elf, ".strtab"); in elf_create_section()
1085 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
1089 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
1093 elf->changed = true; in elf_create_section()
1098 static struct section *elf_create_rel_reloc_section(struct elf *elf, struct section *base) in elf_create_rel_reloc_section() argument
1111 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
1121 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
1128 static struct section *elf_create_rela_reloc_section(struct elf *elf, struct section *base) in elf_create_rela_reloc_section() argument
1141 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
1151 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
1158 static struct section *elf_create_reloc_section(struct elf *elf, in elf_create_reloc_section() argument
1163 case SHT_REL: return elf_create_rel_reloc_section(elf, base); in elf_create_reloc_section()
1164 case SHT_RELA: return elf_create_rela_reloc_section(elf, base); in elf_create_reloc_section()
1232 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
1241 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1255 elf->changed = true; in elf_write_insn()
1260 int elf_write_reloc(struct elf *elf, struct reloc *reloc) in elf_write_reloc() argument
1283 elf->changed = true; in elf_write_reloc()
1288 int elf_write(struct elf *elf) in elf_write() argument
1297 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1299 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1310 elf_rebuild_reloc_section(elf, sec)) { in elf_write()
1316 elf->changed = true; in elf_write()
1321 elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY); in elf_write()
1324 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { in elf_write()
1329 elf->changed = false; in elf_write()
1334 void elf_close(struct elf *elf) in elf_close() argument
1340 if (elf->elf) in elf_close()
1341 elf_end(elf->elf); in elf_close()
1343 if (elf->fd > 0) in elf_close()
1344 close(elf->fd); in elf_close()
1346 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1361 free(elf); in elf_close()