Lines Matching refs:sec

113 	struct section *sec;  in find_section_by_name()  local
115 elf_hash_for_each_possible(section_name, sec, name_hash, str_hash(name)) { in find_section_by_name()
116 if (!strcmp(sec->name, name)) in find_section_by_name()
117 return sec; in find_section_by_name()
126 struct section *sec; in find_section_by_index() local
128 elf_hash_for_each_possible(section, sec, hash, idx) { in find_section_by_index()
129 if (sec->idx == idx) in find_section_by_index()
130 return sec; in find_section_by_index()
148 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset) in find_symbol_by_offset() argument
152 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_symbol_by_offset()
162 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) in find_func_by_offset() argument
166 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_func_by_offset()
176 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset) in find_symbol_containing() argument
180 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_symbol_containing()
193 int find_symbol_hole_containing(const struct section *sec, unsigned long offset) in find_symbol_hole_containing() argument
205 n = rb_find(&hole, &sec->symbol_tree, symbol_hole_by_offset); in find_symbol_hole_containing()
225 struct symbol *find_func_containing(struct section *sec, unsigned long offset) in find_func_containing() argument
229 rb_for_each(node, &offset, &sec->symbol_tree, symbol_by_offset) { in find_func_containing()
251 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec, in find_reloc_by_dest_range() argument
257 if (!sec->reloc) in find_reloc_by_dest_range()
260 sec = sec->reloc; in find_reloc_by_dest_range()
264 sec_offset_hash(sec, o)) { in find_reloc_by_dest_range()
265 if (reloc->sec != sec) in find_reloc_by_dest_range()
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()
288 struct section *sec; in read_sections() local
307 sec = malloc(sizeof(*sec)); in read_sections()
308 if (!sec) { in read_sections()
312 memset(sec, 0, sizeof(*sec)); in read_sections()
314 INIT_LIST_HEAD(&sec->symbol_list); in read_sections()
315 INIT_LIST_HEAD(&sec->reloc_list); in read_sections()
323 sec->idx = elf_ndxscn(s); in read_sections()
325 if (!gelf_getshdr(s, &sec->sh)) { in read_sections()
330 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
331 if (!sec->name) { in read_sections()
336 if (sec->sh.sh_size != 0) { in read_sections()
337 sec->data = elf_getdata(s, NULL); in read_sections()
338 if (!sec->data) { in read_sections()
342 if (sec->data->d_off != 0 || in read_sections()
343 sec->data->d_size != sec->sh.sh_size) { in read_sections()
345 sec->name); in read_sections()
350 if (sec->sh.sh_flags & SHF_EXECINSTR) 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()
354 elf_hash_add(section, &sec->hash, sec->idx); in read_sections()
355 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in read_sections()
389 rb_add(&sym->node, &sym->sec->symbol_tree, symbol_to_offset); in elf_add_symbol()
394 entry = &sym->sec->symbol_list; in elf_add_symbol()
404 rb_erase(&sym->node, &sym->sec->symbol_tree); in elf_add_symbol()
409 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
466 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
467 if (!sym->sec) { in read_symbols()
473 sym->name = sym->sec->name; in read_symbols()
474 sym->sec->sym = sym; in read_symbols()
477 sym->sec = find_section_by_index(elf, 0); in read_symbols()
488 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
489 list_for_each_entry(sym, &sec->symbol_list, list) { in read_symbols()
533 if (sym->sec == pfunc->sec && in read_symbols()
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()
567 reloc->sec = sec->reloc; in elf_add_reloc()
573 list_add_tail(&reloc->list, &sec->reloc->reloc_list); in elf_add_reloc()
576 sec->reloc->sh.sh_size += sec->reloc->sh.sh_entsize; in elf_add_reloc()
577 sec->reloc->changed = true; in elf_add_reloc()
589 struct section *sec; in elf_dirty_reloc_sym() local
591 list_for_each_entry(sec, &elf->sections, list) { in elf_dirty_reloc_sym()
594 if (sec->changed) in elf_dirty_reloc_sym()
597 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_dirty_reloc_sym()
599 sec->changed = true; in elf_dirty_reloc_sym()
617 Elf32_Word shndx = sym->sec ? sym->sec->idx : SHN_UNDEF; in elf_update_symbol()
678 shndx_data->d_buf = &sym->sec->idx; in elf_update_symbol()
733 elf_create_section_symbol(struct elf *elf, struct section *sec) in elf_create_section_symbol() argument
753 sym->name = sec->name; in elf_create_section_symbol()
754 sym->sec = sec; 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
822 return elf_add_reloc(elf, sec, offset, type, sym, addend); in elf_add_reloc_to_insn()
825 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rel_reloc() argument
827 if (!gelf_getrel(sec->data, i, &reloc->rel)) { in read_rel_reloc()
838 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rela_reloc() argument
840 if (!gelf_getrela(sec->data, i, &reloc->rela)) { in read_rela_reloc()
853 struct section *sec; in read_relocs() local
862 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
863 if ((sec->sh.sh_type != SHT_RELA) && in read_relocs()
864 (sec->sh.sh_type != SHT_REL)) in read_relocs()
867 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
868 if (!sec->base) { in read_relocs()
870 sec->name); in read_relocs()
874 sec->base->reloc = sec; in read_relocs()
877 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { in read_relocs()
884 switch (sec->sh.sh_type) { in read_relocs()
886 if (read_rel_reloc(sec, i, reloc, &symndx)) in read_relocs()
890 if (read_rela_reloc(sec, i, reloc, &symndx)) in read_relocs()
896 reloc->sec = sec; in read_relocs()
901 symndx, sec->name); in read_relocs()
905 list_add_tail(&reloc->list, &sec->reloc_list); in read_relocs()
1019 struct section *sec, *shstrtab; in elf_create_section() local
1023 sec = malloc(sizeof(*sec)); in elf_create_section()
1024 if (!sec) { in elf_create_section()
1028 memset(sec, 0, sizeof(*sec)); in elf_create_section()
1030 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
1031 INIT_LIST_HEAD(&sec->reloc_list); in elf_create_section()
1039 sec->name = strdup(name); in elf_create_section()
1040 if (!sec->name) { in elf_create_section()
1045 sec->idx = elf_ndxscn(s); in elf_create_section()
1046 sec->changed = true; in elf_create_section()
1048 sec->data = elf_newdata(s); in elf_create_section()
1049 if (!sec->data) { in elf_create_section()
1054 sec->data->d_size = size; in elf_create_section()
1055 sec->data->d_align = 1; in elf_create_section()
1058 sec->data->d_buf = malloc(size); in elf_create_section()
1059 if (!sec->data->d_buf) { in elf_create_section()
1063 memset(sec->data->d_buf, 0, size); in elf_create_section()
1066 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
1071 sec->sh.sh_size = size; in elf_create_section()
1072 sec->sh.sh_entsize = entsize; in elf_create_section()
1073 sec->sh.sh_type = SHT_PROGBITS; in elf_create_section()
1074 sec->sh.sh_addralign = 1; in elf_create_section()
1075 sec->sh.sh_flags = SHF_ALLOC | sh_flags; in elf_create_section()
1085 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
1086 if (sec->sh.sh_name == -1) in elf_create_section()
1089 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
1090 elf_hash_add(section, &sec->hash, sec->idx); in elf_create_section()
1091 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
1095 return sec; in elf_create_section()
1101 struct section *sec; in elf_create_rel_reloc_section() local
1111 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
1113 if (!sec) in elf_create_rel_reloc_section()
1116 base->reloc = sec; in elf_create_rel_reloc_section()
1117 sec->base = base; in elf_create_rel_reloc_section()
1119 sec->sh.sh_type = SHT_REL; in elf_create_rel_reloc_section()
1120 sec->sh.sh_addralign = 8; in elf_create_rel_reloc_section()
1121 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
1122 sec->sh.sh_info = base->idx; in elf_create_rel_reloc_section()
1123 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rel_reloc_section()
1125 return sec; in elf_create_rel_reloc_section()
1131 struct section *sec; in elf_create_rela_reloc_section() local
1141 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
1143 if (!sec) in elf_create_rela_reloc_section()
1146 base->reloc = sec; in elf_create_rela_reloc_section()
1147 sec->base = base; in elf_create_rela_reloc_section()
1149 sec->sh.sh_type = SHT_RELA; in elf_create_rela_reloc_section()
1150 sec->sh.sh_addralign = 8; in elf_create_rela_reloc_section()
1151 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
1152 sec->sh.sh_info = base->idx; in elf_create_rela_reloc_section()
1153 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rela_reloc_section()
1155 return sec; in elf_create_rela_reloc_section()
1169 static int elf_rebuild_rel_reloc_section(struct section *sec) in elf_rebuild_rel_reloc_section() argument
1176 buf = malloc(sec->sh.sh_size); in elf_rebuild_rel_reloc_section()
1182 sec->data->d_buf = buf; in elf_rebuild_rel_reloc_section()
1183 sec->data->d_size = sec->sh.sh_size; in elf_rebuild_rel_reloc_section()
1184 sec->data->d_type = ELF_T_REL; in elf_rebuild_rel_reloc_section()
1187 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rel_reloc_section()
1190 if (!gelf_update_rel(sec->data, idx, &reloc->rel)) { in elf_rebuild_rel_reloc_section()
1200 static int elf_rebuild_rela_reloc_section(struct section *sec) in elf_rebuild_rela_reloc_section() argument
1207 buf = malloc(sec->sh.sh_size); in elf_rebuild_rela_reloc_section()
1213 sec->data->d_buf = buf; in elf_rebuild_rela_reloc_section()
1214 sec->data->d_size = sec->sh.sh_size; in elf_rebuild_rela_reloc_section()
1215 sec->data->d_type = ELF_T_RELA; in elf_rebuild_rela_reloc_section()
1218 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rela_reloc_section()
1222 if (!gelf_update_rela(sec->data, idx, &reloc->rela)) { in elf_rebuild_rela_reloc_section()
1232 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
1234 switch (sec->sh.sh_type) { in elf_rebuild_reloc_section()
1235 case SHT_REL: return elf_rebuild_rel_reloc_section(sec); in elf_rebuild_reloc_section()
1236 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec); in elf_rebuild_reloc_section()
1241 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1245 Elf_Data *data = sec->data; in elf_write_insn()
1248 WARN("write to unexpected data for section: %s", sec->name); in elf_write_insn()
1262 struct section *sec = reloc->sec; in elf_write_reloc() local
1264 if (sec->sh.sh_type == SHT_REL) { in elf_write_reloc()
1268 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { in elf_write_reloc()
1277 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { in elf_write_reloc()
1290 struct section *sec; in elf_write() local
1297 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1298 if (sec->changed) { in elf_write()
1299 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1304 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
1309 if (sec->base && in elf_write()
1310 elf_rebuild_reloc_section(elf, sec)) { in elf_write()
1315 sec->changed = false; in elf_write()
1336 struct section *sec, *tmpsec; in elf_close() local
1346 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1347 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { in elf_close()
1352 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { in elf_close()
1357 list_del(&sec->list); in elf_close()
1358 free(sec); in elf_close()