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()
346 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
400 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
401 if (!sym->sec) { in read_symbols()
407 sym->name = sym->sec->name; in read_symbols()
408 sym->sec->sym = sym; in read_symbols()
411 sym->sec = find_section_by_index(elf, 0); in read_symbols()
416 rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset); in read_symbols()
421 entry = &sym->sec->symbol_list; in read_symbols()
431 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
432 list_for_each_entry(sym, &sec->symbol_list, list) { in read_symbols()
476 if (sym->sec == pfunc->sec && in read_symbols()
493 struct section *sec = reloc->sec; in elf_add_reloc() local
495 list_add_tail(&reloc->list, &sec->reloc_list); in elf_add_reloc()
499 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rel_reloc() argument
501 if (!gelf_getrel(sec->data, i, &reloc->rel)) { in read_rel_reloc()
512 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) in read_rela_reloc() argument
514 if (!gelf_getrela(sec->data, i, &reloc->rela)) { in read_rela_reloc()
527 struct section *sec; in read_relocs() local
533 list_for_each_entry(sec, &elf->sections, list) { in read_relocs()
534 if ((sec->sh.sh_type != SHT_RELA) && in read_relocs()
535 (sec->sh.sh_type != SHT_REL)) in read_relocs()
538 sec->base = find_section_by_index(elf, sec->sh.sh_info); in read_relocs()
539 if (!sec->base) { in read_relocs()
541 sec->name); in read_relocs()
545 sec->base->reloc = sec; in read_relocs()
548 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { in read_relocs()
555 switch (sec->sh.sh_type) { in read_relocs()
557 if (read_rel_reloc(sec, i, reloc, &symndx)) in read_relocs()
561 if (read_rela_reloc(sec, i, reloc, &symndx)) in read_relocs()
567 reloc->sec = sec; in read_relocs()
572 symndx, sec->name); in read_relocs()
657 struct section *sec, *shstrtab; in elf_create_section() local
662 sec = malloc(sizeof(*sec)); in elf_create_section()
663 if (!sec) { in elf_create_section()
667 memset(sec, 0, sizeof(*sec)); in elf_create_section()
669 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
670 INIT_LIST_HEAD(&sec->reloc_list); in elf_create_section()
678 sec->name = strdup(name); in elf_create_section()
679 if (!sec->name) { in elf_create_section()
684 sec->idx = elf_ndxscn(s); in elf_create_section()
685 sec->len = size; in elf_create_section()
686 sec->changed = true; in elf_create_section()
688 sec->data = elf_newdata(s); in elf_create_section()
689 if (!sec->data) { in elf_create_section()
694 sec->data->d_size = size; in elf_create_section()
695 sec->data->d_align = 1; in elf_create_section()
698 sec->data->d_buf = malloc(size); in elf_create_section()
699 if (!sec->data->d_buf) { in elf_create_section()
703 memset(sec->data->d_buf, 0, size); in elf_create_section()
706 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
711 sec->sh.sh_size = size; in elf_create_section()
712 sec->sh.sh_entsize = entsize; in elf_create_section()
713 sec->sh.sh_type = SHT_PROGBITS; in elf_create_section()
714 sec->sh.sh_addralign = 1; in elf_create_section()
715 sec->sh.sh_flags = SHF_ALLOC | sh_flags; in elf_create_section()
739 data->d_buf = sec->name; in elf_create_section()
743 sec->sh.sh_name = shstrtab->len; in elf_create_section()
748 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
749 elf_hash_add(elf->section_hash, &sec->hash, sec->idx); in elf_create_section()
750 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
754 return sec; in elf_create_section()
760 struct section *sec; in elf_create_rel_reloc_section() local
770 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0); in elf_create_rel_reloc_section()
772 if (!sec) in elf_create_rel_reloc_section()
775 base->reloc = sec; in elf_create_rel_reloc_section()
776 sec->base = base; in elf_create_rel_reloc_section()
778 sec->sh.sh_type = SHT_REL; in elf_create_rel_reloc_section()
779 sec->sh.sh_addralign = 8; in elf_create_rel_reloc_section()
780 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rel_reloc_section()
781 sec->sh.sh_info = base->idx; in elf_create_rel_reloc_section()
782 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rel_reloc_section()
784 return sec; in elf_create_rel_reloc_section()
790 struct section *sec; in elf_create_rela_reloc_section() local
800 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); in elf_create_rela_reloc_section()
802 if (!sec) in elf_create_rela_reloc_section()
805 base->reloc = sec; in elf_create_rela_reloc_section()
806 sec->base = base; in elf_create_rela_reloc_section()
808 sec->sh.sh_type = SHT_RELA; in elf_create_rela_reloc_section()
809 sec->sh.sh_addralign = 8; in elf_create_rela_reloc_section()
810 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; in elf_create_rela_reloc_section()
811 sec->sh.sh_info = base->idx; in elf_create_rela_reloc_section()
812 sec->sh.sh_flags = SHF_INFO_LINK; in elf_create_rela_reloc_section()
814 return sec; in elf_create_rela_reloc_section()
828 static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) in elf_rebuild_rel_reloc_section() argument
842 sec->data->d_buf = relocs; in elf_rebuild_rel_reloc_section()
843 sec->data->d_size = size; in elf_rebuild_rel_reloc_section()
845 sec->sh.sh_size = size; in elf_rebuild_rel_reloc_section()
848 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rel_reloc_section()
857 static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) in elf_rebuild_rela_reloc_section() argument
871 sec->data->d_buf = relocs; in elf_rebuild_rela_reloc_section()
872 sec->data->d_size = size; in elf_rebuild_rela_reloc_section()
874 sec->sh.sh_size = size; in elf_rebuild_rela_reloc_section()
877 list_for_each_entry(reloc, &sec->reloc_list, list) { in elf_rebuild_rela_reloc_section()
887 int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) in elf_rebuild_reloc_section() argument
892 sec->changed = true; in elf_rebuild_reloc_section()
896 list_for_each_entry(reloc, &sec->reloc_list, list) in elf_rebuild_reloc_section()
899 switch (sec->sh.sh_type) { in elf_rebuild_reloc_section()
900 case SHT_REL: return elf_rebuild_rel_reloc_section(sec, nr); in elf_rebuild_reloc_section()
901 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec, nr); in elf_rebuild_reloc_section()
906 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
910 Elf_Data *data = sec->data; in elf_write_insn()
913 WARN("write to unexpected data for section: %s", sec->name); in elf_write_insn()
927 struct section *sec = reloc->sec; in elf_write_reloc() local
929 if (sec->sh.sh_type == SHT_REL) { in elf_write_reloc()
933 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { in elf_write_reloc()
942 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { in elf_write_reloc()
955 struct section *sec; in elf_write() local
959 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
960 if (sec->changed) { in elf_write()
961 s = elf_getscn(elf->elf, sec->idx); in elf_write()
966 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
971 sec->changed = false; in elf_write()
991 struct section *sec, *tmpsec; in elf_close() local
1001 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { in elf_close()
1002 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { in elf_close()
1007 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { in elf_close()
1012 list_del(&sec->list); in elf_close()
1013 free(sec); in elf_close()