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()
357 rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset); in elf_add_symbol()
362 entry = &sym->sec->symbol_list; in elf_add_symbol()
372 rb_erase(&sym->node, &sym->sec->symbol_tree); in elf_add_symbol()
377 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
428 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
429 if (!sym->sec) { in read_symbols()
435 sym->name = sym->sec->name; in read_symbols()
436 sym->sec->sym = sym; in read_symbols()
439 sym->sec = find_section_by_index(elf, 0); in read_symbols()
448 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
449 list_for_each_entry(sym, &sec->symbol_list, list) { in read_symbols()
493 if (sym->sec == pfunc->sec && in read_symbols()
512 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, in elf_add_reloc() argument
517 if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) in elf_add_reloc()
527 reloc->sec = sec->reloc; in elf_add_reloc()
533 list_add_tail(&reloc->list, &sec->reloc->reloc_list); in elf_add_reloc()
536 sec->reloc->changed = true; in elf_add_reloc()
548 struct section *sec; in elf_dirty_reloc_sym() local
550 list_for_each_entry(sec, &elf->sections, list) { in elf_dirty_reloc_sym()
553 if (sec->changed) in elf_dirty_reloc_sym()
556 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_dirty_reloc_sym()
558 sec->changed = true; in elf_dirty_reloc_sym()
576 Elf32_Word shndx = sym->sec ? sym->sec->idx : SHN_UNDEF; in elf_update_symbol()
637 shndx_data->d_buf = &sym->sec->idx; in elf_update_symbol()
692 elf_create_section_symbol(struct elf *elf, struct section *sec) in elf_create_section_symbol() argument
712 sym->name = sec->name; in elf_create_section_symbol()
713 sym->sec = sec; in elf_create_section_symbol()
760 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, in elf_add_reloc_to_insn() argument
781 return elf_add_reloc(elf, sec, offset, type, sym, addend); in elf_add_reloc_to_insn()
784 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rel_reloc() argument
786 if (!gelf_getrel(sec->data, i, &reloc->rel)) { in read_rel_reloc()
797 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rela_reloc() argument
799 if (!gelf_getrela(sec->data, i, &reloc->rela)) { in read_rela_reloc()
812 struct section *sec; in read_relocs() local
818 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
819 if ((sec->sh.sh_type != SHT_RELA) && in read_relocs()
820 (sec->sh.sh_type != SHT_REL)) in read_relocs()
823 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
824 if (!sec->base) { in read_relocs()
826 sec->name); in read_relocs()
830 sec->base->reloc = sec; in read_relocs()
833 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { in read_relocs()
840 switch (sec->sh.sh_type) { in read_relocs()
842 if (read_rel_reloc(sec, i, reloc, &symndx)) in read_relocs()
846 if (read_rela_reloc(sec, i, reloc, &symndx)) in read_relocs()
852 reloc->sec = sec; in read_relocs()
857 symndx, sec->name); in read_relocs()
861 list_add_tail(&reloc->list, &sec->reloc_list); in read_relocs()
981 struct section *sec, *shstrtab; in elf_create_section() local
985 sec = malloc(sizeof(*sec)); in elf_create_section()
986 if (!sec) { in elf_create_section()
990 memset(sec, 0, sizeof(*sec)); in elf_create_section()
992 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
993 INIT_LIST_HEAD(&sec->reloc_list); in elf_create_section()
1001 sec->name = strdup(name); in elf_create_section()
1002 if (!sec->name) { in elf_create_section()
1007 sec->idx = elf_ndxscn(s); in elf_create_section()
1008 sec->len = size; in elf_create_section()
1009 sec->changed = true; in elf_create_section()
1011 sec->data = elf_newdata(s); in elf_create_section()
1012 if (!sec->data) { in elf_create_section()
1017 sec->data->d_size = size; in elf_create_section()
1018 sec->data->d_align = 1; in elf_create_section()
1021 sec->data->d_buf = malloc(size); in elf_create_section()
1022 if (!sec->data->d_buf) { in elf_create_section()
1026 memset(sec->data->d_buf, 0, size); in elf_create_section()
1029 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
1034 sec->sh.sh_size = size; in elf_create_section()
1035 sec->sh.sh_entsize = entsize; in elf_create_section()
1036 sec->sh.sh_type = SHT_PROGBITS; in elf_create_section()
1037 sec->sh.sh_addralign = 1; in elf_create_section()
1038 sec->sh.sh_flags = SHF_ALLOC | sh_flags; in elf_create_section()
1048 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
1049 if (sec->sh.sh_name == -1) in elf_create_section()
1052 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
1053 elf_hash_add(elf->section_hash, &sec->hash, sec->idx); in elf_create_section()
1054 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
1058 return sec; in elf_create_section()
1064 struct section *sec; in elf_create_rel_reloc_section() local
1074 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
1076 if (!sec) in elf_create_rel_reloc_section()
1079 base->reloc = sec; in elf_create_rel_reloc_section()
1080 sec->base = base; in elf_create_rel_reloc_section()
1082 sec->sh.sh_type = SHT_REL; in elf_create_rel_reloc_section()
1083 sec->sh.sh_addralign = 8; in elf_create_rel_reloc_section()
1084 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
1085 sec->sh.sh_info = base->idx; in elf_create_rel_reloc_section()
1086 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rel_reloc_section()
1088 return sec; in elf_create_rel_reloc_section()
1094 struct section *sec; in elf_create_rela_reloc_section() local
1104 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
1106 if (!sec) in elf_create_rela_reloc_section()
1109 base->reloc = sec; in elf_create_rela_reloc_section()
1110 sec->base = base; in elf_create_rela_reloc_section()
1112 sec->sh.sh_type = SHT_RELA; in elf_create_rela_reloc_section()
1113 sec->sh.sh_addralign = 8; in elf_create_rela_reloc_section()
1114 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
1115 sec->sh.sh_info = base->idx; in elf_create_rela_reloc_section()
1116 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rela_reloc_section()
1118 return sec; in elf_create_rela_reloc_section()
1132 static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) in elf_rebuild_rel_reloc_section() argument
1146 sec->data->d_buf = relocs; in elf_rebuild_rel_reloc_section()
1147 sec->data->d_size = size; in elf_rebuild_rel_reloc_section()
1149 sec->sh.sh_size = size; in elf_rebuild_rel_reloc_section()
1152 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rel_reloc_section()
1161 static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) in elf_rebuild_rela_reloc_section() argument
1175 sec->data->d_buf = relocs; in elf_rebuild_rela_reloc_section()
1176 sec->data->d_size = size; in elf_rebuild_rela_reloc_section()
1178 sec->sh.sh_size = size; in elf_rebuild_rela_reloc_section()
1181 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rela_reloc_section()
1191 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
1197 list_for_each_entry(reloc, &sec->reloc_list, list) in elf_rebuild_reloc_section()
1200 switch (sec->sh.sh_type) { in elf_rebuild_reloc_section()
1201 case SHT_REL: return elf_rebuild_rel_reloc_section(sec, nr); in elf_rebuild_reloc_section()
1202 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec, nr); in elf_rebuild_reloc_section()
1207 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1211 Elf_Data *data = sec->data; in elf_write_insn()
1214 WARN("write to unexpected data for section: %s", sec->name); in elf_write_insn()
1228 struct section *sec = reloc->sec; in elf_write_reloc() local
1230 if (sec->sh.sh_type == SHT_REL) { in elf_write_reloc()
1234 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { in elf_write_reloc()
1243 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { in elf_write_reloc()
1256 struct section *sec; in elf_write() local
1260 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1261 if (sec->changed) { in elf_write()
1262 if (sec->base && in elf_write()
1263 elf_rebuild_reloc_section(elf, sec)) { in elf_write()
1268 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1273 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
1278 sec->changed = false; in elf_write()
1299 struct section *sec, *tmpsec; in elf_close() local
1309 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1310 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { in elf_close()
1315 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { in elf_close()
1320 list_del(&sec->list); in elf_close()
1321 free(sec); in elf_close()