Lines Matching full:sec
132 struct section *sec; in find_section_by_name() local
134 elf_hash_for_each_possible(elf->section_name_hash, sec, name_hash, str_hash(name)) in find_section_by_name()
135 if (!strcmp(sec->name, name)) in find_section_by_name()
136 return sec; in find_section_by_name()
144 struct section *sec; in find_section_by_index() local
146 elf_hash_for_each_possible(elf->section_hash, sec, hash, idx) in find_section_by_index()
147 if (sec->idx == idx) in find_section_by_index()
148 return sec; in find_section_by_index()
164 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset) in find_symbol_by_offset() argument
168 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) { in find_symbol_by_offset()
178 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) in find_func_by_offset() argument
182 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) { in find_func_by_offset()
192 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset) in find_symbol_containing() argument
196 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) { in find_symbol_containing()
206 struct symbol *find_func_containing(struct section *sec, unsigned long offset) in find_func_containing() argument
210 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) { in find_func_containing()
231 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec, in find_reloc_by_dest_range() argument
237 if (!sec->reloc) in find_reloc_by_dest_range()
240 sec = sec->reloc; in find_reloc_by_dest_range()
244 sec_offset_hash(sec, o)) { in find_reloc_by_dest_range()
245 if (reloc->sec != sec) in find_reloc_by_dest_range()
260 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset) in find_reloc_by_dest() argument
262 return find_reloc_by_dest_range(elf, sec, offset, 1); in find_reloc_by_dest()
268 struct section *sec; in read_sections() local
283 sec = malloc(sizeof(*sec)); in read_sections()
284 if (!sec) { in read_sections()
288 memset(sec, 0, sizeof(*sec)); in read_sections()
290 INIT_LIST_HEAD(&sec->symbol_list); in read_sections()
291 INIT_LIST_HEAD(&sec->reloc_list); in read_sections()
299 sec->idx = elf_ndxscn(s); in read_sections()
301 if (!gelf_getshdr(s, &sec->sh)) { in read_sections()
306 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
307 if (!sec->name) { in read_sections()
312 if (sec->sh.sh_size != 0) { in read_sections()
313 sec->data = elf_getdata(s, NULL); in read_sections()
314 if (!sec->data) { in read_sections()
318 if (sec->data->d_off != 0 || in read_sections()
319 sec->data->d_size != sec->sh.sh_size) { in read_sections()
321 sec->name); in read_sections()
325 sec->len = sec->sh.sh_size; in read_sections()
327 list_add_tail(&sec->list, &elf->sections); in read_sections()
328 elf_hash_add(elf->section_hash, &sec->hash, sec->idx); in read_sections()
329 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); in read_sections()
355 rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset); in elf_add_symbol()
360 entry = &sym->sec->symbol_list; in elf_add_symbol()
370 rb_erase(&sym->node, &sym->sec->symbol_tree); in elf_add_symbol()
375 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
427 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
428 if (!sym->sec) { in read_symbols()
434 sym->name = sym->sec->name; in read_symbols()
435 sym->sec->sym = sym; in read_symbols()
438 sym->sec = find_section_by_index(elf, 0); in read_symbols()
447 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
448 list_for_each_entry(sym, &sec->symbol_list, list) { in read_symbols()
492 if (sym->sec == pfunc->sec && in read_symbols()
511 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, in elf_add_reloc() argument
516 if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) in elf_add_reloc()
526 reloc->sec = sec->reloc; in elf_add_reloc()
532 list_add_tail(&reloc->list, &sec->reloc->reloc_list); in elf_add_reloc()
535 sec->reloc->changed = true; in elf_add_reloc()
540 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, in elf_add_reloc_to_insn() argument
573 return elf_add_reloc(elf, sec, offset, type, sym, addend); in elf_add_reloc_to_insn()
576 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rel_reloc() argument
578 if (!gelf_getrel(sec->data, i, &reloc->rel)) { in read_rel_reloc()
589 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rela_reloc() argument
591 if (!gelf_getrela(sec->data, i, &reloc->rela)) { in read_rela_reloc()
604 struct section *sec; in read_relocs() local
610 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
611 if ((sec->sh.sh_type != SHT_RELA) && in read_relocs()
612 (sec->sh.sh_type != SHT_REL)) in read_relocs()
615 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
616 if (!sec->base) { in read_relocs()
618 sec->name); in read_relocs()
622 sec->base->reloc = sec; in read_relocs()
625 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { in read_relocs()
632 switch (sec->sh.sh_type) { in read_relocs()
634 if (read_rel_reloc(sec, i, reloc, &symndx)) in read_relocs()
638 if (read_rela_reloc(sec, i, reloc, &symndx)) in read_relocs()
644 reloc->sec = sec; in read_relocs()
649 symndx, sec->name); in read_relocs()
653 list_add_tail(&reloc->list, &sec->reloc_list); in read_relocs()
773 struct section *sec, *shstrtab; in elf_create_section() local
777 sec = malloc(sizeof(*sec)); in elf_create_section()
778 if (!sec) { in elf_create_section()
782 memset(sec, 0, sizeof(*sec)); in elf_create_section()
784 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
785 INIT_LIST_HEAD(&sec->reloc_list); in elf_create_section()
793 sec->name = strdup(name); in elf_create_section()
794 if (!sec->name) { in elf_create_section()
799 sec->idx = elf_ndxscn(s); in elf_create_section()
800 sec->len = size; in elf_create_section()
801 sec->changed = true; in elf_create_section()
803 sec->data = elf_newdata(s); in elf_create_section()
804 if (!sec->data) { in elf_create_section()
809 sec->data->d_size = size; in elf_create_section()
810 sec->data->d_align = 1; in elf_create_section()
813 sec->data->d_buf = malloc(size); in elf_create_section()
814 if (!sec->data->d_buf) { in elf_create_section()
818 memset(sec->data->d_buf, 0, size); in elf_create_section()
821 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
826 sec->sh.sh_size = size; in elf_create_section()
827 sec->sh.sh_entsize = entsize; in elf_create_section()
828 sec->sh.sh_type = SHT_PROGBITS; in elf_create_section()
829 sec->sh.sh_addralign = 1; in elf_create_section()
830 sec->sh.sh_flags = SHF_ALLOC | sh_flags; in elf_create_section()
840 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
841 if (sec->sh.sh_name == -1) in elf_create_section()
844 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
845 elf_hash_add(elf->section_hash, &sec->hash, sec->idx); in elf_create_section()
846 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
850 return sec; in elf_create_section()
856 struct section *sec; in elf_create_rel_reloc_section() local
866 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
868 if (!sec) in elf_create_rel_reloc_section()
871 base->reloc = sec; in elf_create_rel_reloc_section()
872 sec->base = base; in elf_create_rel_reloc_section()
874 sec->sh.sh_type = SHT_REL; in elf_create_rel_reloc_section()
875 sec->sh.sh_addralign = 8; in elf_create_rel_reloc_section()
876 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
877 sec->sh.sh_info = base->idx; in elf_create_rel_reloc_section()
878 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rel_reloc_section()
880 return sec; in elf_create_rel_reloc_section()
886 struct section *sec; in elf_create_rela_reloc_section() local
896 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
898 if (!sec) in elf_create_rela_reloc_section()
901 base->reloc = sec; in elf_create_rela_reloc_section()
902 sec->base = base; in elf_create_rela_reloc_section()
904 sec->sh.sh_type = SHT_RELA; in elf_create_rela_reloc_section()
905 sec->sh.sh_addralign = 8; in elf_create_rela_reloc_section()
906 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
907 sec->sh.sh_info = base->idx; in elf_create_rela_reloc_section()
908 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rela_reloc_section()
910 return sec; in elf_create_rela_reloc_section()
924 static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) in elf_rebuild_rel_reloc_section() argument
938 sec->data->d_buf = relocs; in elf_rebuild_rel_reloc_section()
939 sec->data->d_size = size; in elf_rebuild_rel_reloc_section()
941 sec->sh.sh_size = size; in elf_rebuild_rel_reloc_section()
944 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rel_reloc_section()
953 static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) in elf_rebuild_rela_reloc_section() argument
967 sec->data->d_buf = relocs; in elf_rebuild_rela_reloc_section()
968 sec->data->d_size = size; in elf_rebuild_rela_reloc_section()
970 sec->sh.sh_size = size; in elf_rebuild_rela_reloc_section()
973 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rela_reloc_section()
983 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
989 list_for_each_entry(reloc, &sec->reloc_list, list) in elf_rebuild_reloc_section()
992 switch (sec->sh.sh_type) { in elf_rebuild_reloc_section()
993 case SHT_REL: return elf_rebuild_rel_reloc_section(sec, nr); in elf_rebuild_reloc_section()
994 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec, nr); in elf_rebuild_reloc_section()
999 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1003 Elf_Data *data = sec->data; in elf_write_insn()
1006 WARN("write to unexpected data for section: %s", sec->name); in elf_write_insn()
1020 struct section *sec = reloc->sec; in elf_write_reloc() local
1022 if (sec->sh.sh_type == SHT_REL) { in elf_write_reloc()
1026 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { in elf_write_reloc()
1035 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { in elf_write_reloc()
1048 struct section *sec; in elf_write() local
1052 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1053 if (sec->changed) { in elf_write()
1054 if (sec->base && in elf_write()
1055 elf_rebuild_reloc_section(elf, sec)) { in elf_write()
1060 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1065 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
1070 sec->changed = false; in elf_write()
1091 struct section *sec, *tmpsec; in elf_close() local
1101 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1102 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { in elf_close()
1107 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { in elf_close()
1112 list_del(&sec->list); in elf_close()
1113 free(sec); in elf_close()