Lines Matching full:sec
88 struct section *sec; in find_section_by_name() local
90 elf_hash_for_each_possible(section_name, sec, name_hash, str_hash(name)) { in find_section_by_name()
91 if (!strcmp(sec->name, name)) in find_section_by_name()
92 return sec; in find_section_by_name()
101 struct section *sec; in find_section_by_index() local
103 elf_hash_for_each_possible(section, sec, hash, idx) { in find_section_by_index()
104 if (sec->idx == idx) in find_section_by_index()
105 return sec; in find_section_by_index()
123 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset) in find_symbol_by_offset() argument
127 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_symbol_by_offset()
137 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) in find_func_by_offset() argument
141 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_func_by_offset()
151 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset) in find_symbol_containing() argument
155 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_symbol_containing()
165 struct symbol *find_func_containing(struct section *sec, unsigned long offset) in find_func_containing() argument
169 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_func_containing()
191 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec, in find_reloc_by_dest_range() argument
197 if (!sec->reloc) in find_reloc_by_dest_range()
200 sec = sec->reloc; in find_reloc_by_dest_range()
204 sec_offset_hash(sec, o)) { in find_reloc_by_dest_range()
205 if (reloc->sec != sec) in find_reloc_by_dest_range()
220 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset) in find_reloc_by_dest() argument
222 return find_reloc_by_dest_range(elf, sec, offset, 1); in find_reloc_by_dest()
228 struct section *sec; in read_sections() local
247 sec = malloc(sizeof(*sec)); in read_sections()
248 if (!sec) { in read_sections()
252 memset(sec, 0, sizeof(*sec)); in read_sections()
254 INIT_LIST_HEAD(&sec->symbol_list); in read_sections()
255 INIT_LIST_HEAD(&sec->reloc_list); in read_sections()
263 sec->idx = elf_ndxscn(s); in read_sections()
265 if (!gelf_getshdr(s, &sec->sh)) { in read_sections()
270 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
271 if (!sec->name) { in read_sections()
276 if (sec->sh.sh_size != 0) { in read_sections()
277 sec->data = elf_getdata(s, NULL); in read_sections()
278 if (!sec->data) { in read_sections()
282 if (sec->data->d_off != 0 || in read_sections()
283 sec->data->d_size != sec->sh.sh_size) { in read_sections()
285 sec->name); in read_sections()
290 if (sec->sh.sh_flags & SHF_EXECINSTR) in read_sections()
291 elf->text_size += sec->sh.sh_size; in read_sections()
293 list_add_tail(&sec->list, &elf->sections); in read_sections()
294 elf_hash_add(section, &sec->hash, sec->idx); in read_sections()
295 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in read_sections()
323 rb_add(&sym->node, &sym->sec->symbol_tree, symbol_to_offset); in elf_add_symbol()
328 entry = &sym->sec->symbol_list; in elf_add_symbol()
338 rb_erase(&sym->node, &sym->sec->symbol_tree); in elf_add_symbol()
343 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
401 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
402 if (!sym->sec) { in read_symbols()
408 sym->name = sym->sec->name; in read_symbols()
409 sym->sec->sym = sym; in read_symbols()
412 sym->sec = find_section_by_index(elf, 0); in read_symbols()
423 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
424 list_for_each_entry(sym, &sec->symbol_list, list) { in read_symbols()
468 if (sym->sec == pfunc->sec && in read_symbols()
487 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, in elf_add_reloc() argument
492 if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) in elf_add_reloc()
502 reloc->sec = sec->reloc; in elf_add_reloc()
508 list_add_tail(&reloc->list, &sec->reloc->reloc_list); in elf_add_reloc()
511 sec->reloc->sh.sh_size += sec->reloc->sh.sh_entsize; in elf_add_reloc()
512 sec->reloc->changed = true; in elf_add_reloc()
517 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, in elf_add_reloc_to_insn() argument
550 return elf_add_reloc(elf, sec, offset, type, sym, addend); in elf_add_reloc_to_insn()
553 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rel_reloc() argument
555 if (!gelf_getrel(sec->data, i, &reloc->rel)) { in read_rel_reloc()
566 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rela_reloc() argument
568 if (!gelf_getrela(sec->data, i, &reloc->rela)) { in read_rela_reloc()
581 struct section *sec; in read_relocs() local
590 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
591 if ((sec->sh.sh_type != SHT_RELA) && in read_relocs()
592 (sec->sh.sh_type != SHT_REL)) in read_relocs()
595 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
596 if (!sec->base) { in read_relocs()
598 sec->name); in read_relocs()
602 sec->base->reloc = sec; in read_relocs()
605 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { in read_relocs()
612 switch (sec->sh.sh_type) { in read_relocs()
614 if (read_rel_reloc(sec, i, reloc, &symndx)) in read_relocs()
618 if (read_rela_reloc(sec, i, reloc, &symndx)) in read_relocs()
624 reloc->sec = sec; in read_relocs()
629 symndx, sec->name); in read_relocs()
633 list_add_tail(&reloc->list, &sec->reloc_list); in read_relocs()
821 sym->sec = find_section_by_index(elf, 0); in elf_create_undef_symbol()
831 struct section *sec, *shstrtab; in elf_create_section() local
835 sec = malloc(sizeof(*sec)); in elf_create_section()
836 if (!sec) { in elf_create_section()
840 memset(sec, 0, sizeof(*sec)); in elf_create_section()
842 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
843 INIT_LIST_HEAD(&sec->reloc_list); in elf_create_section()
851 sec->name = strdup(name); in elf_create_section()
852 if (!sec->name) { in elf_create_section()
857 sec->idx = elf_ndxscn(s); in elf_create_section()
858 sec->changed = true; in elf_create_section()
860 sec->data = elf_newdata(s); in elf_create_section()
861 if (!sec->data) { in elf_create_section()
866 sec->data->d_size = size; in elf_create_section()
867 sec->data->d_align = 1; in elf_create_section()
870 sec->data->d_buf = malloc(size); in elf_create_section()
871 if (!sec->data->d_buf) { in elf_create_section()
875 memset(sec->data->d_buf, 0, size); in elf_create_section()
878 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
883 sec->sh.sh_size = size; in elf_create_section()
884 sec->sh.sh_entsize = entsize; in elf_create_section()
885 sec->sh.sh_type = SHT_PROGBITS; in elf_create_section()
886 sec->sh.sh_addralign = 1; in elf_create_section()
887 sec->sh.sh_flags = SHF_ALLOC | sh_flags; in elf_create_section()
897 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
898 if (sec->sh.sh_name == -1) in elf_create_section()
901 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
902 elf_hash_add(section, &sec->hash, sec->idx); in elf_create_section()
903 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
907 return sec; in elf_create_section()
913 struct section *sec; in elf_create_rel_reloc_section() local
923 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
925 if (!sec) in elf_create_rel_reloc_section()
928 base->reloc = sec; in elf_create_rel_reloc_section()
929 sec->base = base; in elf_create_rel_reloc_section()
931 sec->sh.sh_type = SHT_REL; in elf_create_rel_reloc_section()
932 sec->sh.sh_addralign = 8; in elf_create_rel_reloc_section()
933 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
934 sec->sh.sh_info = base->idx; in elf_create_rel_reloc_section()
935 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rel_reloc_section()
937 return sec; in elf_create_rel_reloc_section()
943 struct section *sec; in elf_create_rela_reloc_section() local
953 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
955 if (!sec) in elf_create_rela_reloc_section()
958 base->reloc = sec; in elf_create_rela_reloc_section()
959 sec->base = base; in elf_create_rela_reloc_section()
961 sec->sh.sh_type = SHT_RELA; in elf_create_rela_reloc_section()
962 sec->sh.sh_addralign = 8; in elf_create_rela_reloc_section()
963 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
964 sec->sh.sh_info = base->idx; in elf_create_rela_reloc_section()
965 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rela_reloc_section()
967 return sec; in elf_create_rela_reloc_section()
981 static int elf_rebuild_rel_reloc_section(struct section *sec) in elf_rebuild_rel_reloc_section() argument
988 buf = malloc(sec->sh.sh_size); in elf_rebuild_rel_reloc_section()
994 sec->data->d_buf = buf; in elf_rebuild_rel_reloc_section()
995 sec->data->d_size = sec->sh.sh_size; in elf_rebuild_rel_reloc_section()
996 sec->data->d_type = ELF_T_REL; in elf_rebuild_rel_reloc_section()
999 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rel_reloc_section()
1002 if (!gelf_update_rel(sec->data, idx, &reloc->rel)) { in elf_rebuild_rel_reloc_section()
1012 static int elf_rebuild_rela_reloc_section(struct section *sec) in elf_rebuild_rela_reloc_section() argument
1019 buf = malloc(sec->sh.sh_size); in elf_rebuild_rela_reloc_section()
1025 sec->data->d_buf = buf; in elf_rebuild_rela_reloc_section()
1026 sec->data->d_size = sec->sh.sh_size; in elf_rebuild_rela_reloc_section()
1027 sec->data->d_type = ELF_T_RELA; in elf_rebuild_rela_reloc_section()
1030 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rela_reloc_section()
1034 if (!gelf_update_rela(sec->data, idx, &reloc->rela)) { in elf_rebuild_rela_reloc_section()
1044 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
1046 switch (sec->sh.sh_type) { in elf_rebuild_reloc_section()
1047 case SHT_REL: return elf_rebuild_rel_reloc_section(sec); in elf_rebuild_reloc_section()
1048 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec); in elf_rebuild_reloc_section()
1053 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1057 Elf_Data *data = sec->data; in elf_write_insn()
1060 WARN("write to unexpected data for section: %s", sec->name); in elf_write_insn()
1074 struct section *sec = reloc->sec; in elf_write_reloc() local
1076 if (sec->sh.sh_type == SHT_REL) { in elf_write_reloc()
1080 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { in elf_write_reloc()
1089 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { in elf_write_reloc()
1102 struct section *sec; in elf_write() local
1106 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1107 if (sec->changed) { in elf_write()
1108 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1113 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
1118 if (sec->base && in elf_write()
1119 elf_rebuild_reloc_section(elf, sec)) { in elf_write()
1124 sec->changed = false; in elf_write()
1145 struct section *sec, *tmpsec; in elf_close() local
1155 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1156 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { in elf_close()
1161 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { in elf_close()
1166 list_del(&sec->list); in elf_close()
1167 free(sec); in elf_close()