Lines Matching full:sec

136 	struct section *sec;  in find_section_by_name()  local
138 elf_hash_for_each_possible(section_name, sec, name_hash, str_hash(name)) { in find_section_by_name()
139 if (!strcmp(sec->name, name)) in find_section_by_name()
140 return sec; in find_section_by_name()
149 struct section *sec; in find_section_by_index() local
151 elf_hash_for_each_possible(section, sec, hash, idx) { in find_section_by_index()
152 if (sec->idx == idx) in find_section_by_index()
153 return sec; in find_section_by_index()
171 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset) in find_symbol_by_offset() argument
173 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree; in find_symbol_by_offset()
184 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) in find_func_by_offset() argument
186 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree; in find_func_by_offset()
197 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset) in find_symbol_containing() argument
199 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree; in find_symbol_containing()
228 int find_symbol_hole_containing(const struct section *sec, unsigned long offset) in find_symbol_hole_containing() argument
240 n = rb_find(&hole, &sec->symbol_tree.rb_root, symbol_hole_by_offset); in find_symbol_hole_containing()
255 n = rb_first_cached(&sec->symbol_tree); in find_symbol_hole_containing()
265 struct symbol *find_func_containing(struct section *sec, unsigned long offset) in find_func_containing() argument
267 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree; in find_func_containing()
319 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec, in find_reloc_by_dest_range() argument
326 rsec = sec->rsec; in find_reloc_by_dest_range()
333 if (reloc->sec != rsec) in find_reloc_by_dest_range()
349 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset) in find_reloc_by_dest() argument
351 return find_reloc_by_dest_range(elf, sec, offset, 1); in find_reloc_by_dest()
354 static bool is_dwarf_section(struct section *sec) in is_dwarf_section() argument
356 return !strncmp(sec->name, ".debug_", 7); in is_dwarf_section()
362 struct section *sec; in read_sections() local
380 elf->section_data = calloc(sections_nr, sizeof(*sec)); in read_sections()
386 sec = &elf->section_data[i]; in read_sections()
388 INIT_LIST_HEAD(&sec->symbol_list); in read_sections()
396 sec->idx = elf_ndxscn(s); in read_sections()
398 if (!gelf_getshdr(s, &sec->sh)) { in read_sections()
403 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); in read_sections()
404 if (!sec->name) { in read_sections()
409 if (sec_size(sec) != 0 && !is_dwarf_section(sec)) { in read_sections()
410 sec->data = elf_getdata(s, NULL); in read_sections()
411 if (!sec->data) { in read_sections()
415 if (sec->data->d_off != 0 || in read_sections()
416 sec->data->d_size != sec_size(sec)) { in read_sections()
417 ERROR("unexpected data attributes for %s", sec->name); in read_sections()
422 list_add_tail(&sec->list, &elf->sections); in read_sections()
423 elf_hash_add(section, &sec->hash, sec->idx); in read_sections()
424 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in read_sections()
426 if (is_reloc_sec(sec)) in read_sections()
427 elf->num_relocs += sec_num_entries(sec); in read_sections()
493 __sym_for_each(iter, &sym->sec->symbol_tree, sym->offset, sym->offset) { in elf_add_symbol()
499 __sym_insert(sym, &sym->sec->symbol_tree); in elf_add_symbol()
504 entry = &sym->sec->symbol_list; in elf_add_symbol()
542 struct section *symtab, *symtab_shndx, *sec; in read_symbols() local
602 sym->sec = find_section_by_index(elf, shndx); in read_symbols()
603 if (!sym->sec) { in read_symbols()
608 sym->name = sym->sec->name; in read_symbols()
609 sym->sec->sym = sym; in read_symbols()
612 sym->sec = find_section_by_index(elf, 0); in read_symbols()
629 list_for_each_entry(sec, &elf->sections, list) { in read_symbols()
630 sec_for_each_sym(sec, sym) { in read_symbols()
672 if (sym->sec == pfunc->sec && in read_symbols()
685 struct section *symtab, *sec; in mark_group_syms() local
694 for_each_sec(elf, sec) { in mark_group_syms()
695 if (sec->sh.sh_type == SHT_GROUP && in mark_group_syms()
696 sec->sh.sh_link == symtab->idx) { in mark_group_syms()
697 sym = find_symbol_by_index(elf, sec->sh.sh_info); in mark_group_syms()
700 sec->name); in mark_group_syms()
704 sym->group_sec = sec; in mark_group_syms()
743 shndx = is_special_shndx ? sym->sym.st_shndx : sym->sec->idx; in elf_update_symbol()
862 struct section *sec, unsigned int bind, in elf_create_symbol() argument
888 if (sec) { in elf_create_symbol()
889 sym->sec = sec; in elf_create_symbol()
891 sym->sec = find_section_by_index(elf, 0); in elf_create_symbol()
892 if (!sym->sec) { in elf_create_symbol()
967 struct symbol *elf_create_section_symbol(struct elf *elf, struct section *sec) in elf_create_section_symbol() argument
971 sym = elf_create_symbol(elf, sec->name, sec, STB_LOCAL, STT_SECTION, 0, 0); in elf_create_section_symbol()
975 sec->sym = sym; in elf_create_section_symbol()
1000 reloc->sec = rsec; in elf_init_reloc()
1015 struct reloc *elf_init_reloc_text_sym(struct elf *elf, struct section *sec, in elf_init_reloc_text_sym() argument
1041 return elf_init_reloc(elf, sec->rsec, reloc_idx, offset, sym, addend, in elf_init_reloc_text_sym()
1045 struct reloc *elf_init_reloc_data_sym(struct elf *elf, struct section *sec, in elf_init_reloc_data_sym() argument
1051 if (is_text_sec(sec)) { in elf_init_reloc_data_sym()
1056 return elf_init_reloc(elf, sec->rsec, reloc_idx, offset, sym, addend, in elf_init_reloc_data_sym()
1097 reloc->sec = rsec; in read_relocs()
1316 sym->sec = null; in elf_create_file()
1346 void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_t size) in elf_add_data() argument
1351 if (!sec->sh.sh_addralign) { in elf_add_data()
1352 ERROR("'%s': invalid sh_addralign", sec->name); in elf_add_data()
1356 s = elf_getscn(elf->elf, sec->idx); in elf_add_data()
1362 sec->data = elf_newdata(s); in elf_add_data()
1363 if (!sec->data) { in elf_add_data()
1368 sec->data->d_buf = calloc(1, size); in elf_add_data()
1369 if (!sec->data->d_buf) { in elf_add_data()
1375 memcpy(sec->data->d_buf, data, size); in elf_add_data()
1377 sec->data->d_size = size; in elf_add_data()
1378 sec->data->d_align = sec->sh.sh_addralign; in elf_add_data()
1380 offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign); in elf_add_data()
1381 sec->sh.sh_size = offset + size; in elf_add_data()
1383 mark_sec_changed(elf, sec, true); in elf_add_data()
1385 return sec->data->d_buf; in elf_add_data()
1393 struct section *sec, *shstrtab; in elf_create_section() local
1401 sec = calloc(1, sizeof(*sec)); in elf_create_section()
1402 if (!sec) { in elf_create_section()
1407 INIT_LIST_HEAD(&sec->symbol_list); in elf_create_section()
1419 sec->idx = elf_ndxscn(s); in elf_create_section()
1422 sec->data = elf_newdata(s); in elf_create_section()
1423 if (!sec->data) { in elf_create_section()
1428 sec->data->d_size = size; in elf_create_section()
1429 sec->data->d_align = 1; in elf_create_section()
1431 sec->data->d_buf = calloc(1, size); in elf_create_section()
1432 if (!sec->data->d_buf) { in elf_create_section()
1438 if (!gelf_getshdr(s, &sec->sh)) { in elf_create_section()
1443 sec->sh.sh_size = size; in elf_create_section()
1444 sec->sh.sh_entsize = entsize; in elf_create_section()
1445 sec->sh.sh_type = type; in elf_create_section()
1446 sec->sh.sh_addralign = align; in elf_create_section()
1447 sec->sh.sh_flags = flags; in elf_create_section()
1450 sec->name = strdup(name); in elf_create_section()
1451 if (!sec->name) { in elf_create_section()
1465 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); in elf_create_section()
1466 if (sec->sh.sh_name == -1) in elf_create_section()
1469 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); in elf_create_section()
1473 list_add_tail(&sec->list, &elf->sections); in elf_create_section()
1474 elf_hash_add(section, &sec->hash, sec->idx); in elf_create_section()
1476 mark_sec_changed(elf, sec, true); in elf_create_section()
1478 return sec; in elf_create_section()
1589 struct section *elf_create_rela_section(struct elf *elf, struct section *sec, in elf_create_rela_section() argument
1595 rsec_name = malloc(strlen(sec->name) + strlen(".rela") + 1); in elf_create_rela_section()
1601 strcat(rsec_name, sec->name); in elf_create_rela_section()
1622 rsec->sh.sh_info = sec->idx; in elf_create_rela_section()
1624 sec->rsec = rsec; in elf_create_rela_section()
1625 rsec->base = sec; in elf_create_rela_section()
1630 struct reloc *elf_create_reloc(struct elf *elf, struct section *sec, in elf_create_reloc() argument
1635 struct section *rsec = sec->rsec; in elf_create_reloc()
1638 rsec = elf_create_rela_section(elf, sec, 0); in elf_create_reloc()
1643 if (find_reloc_by_dest(elf, sec, offset)) { in elf_create_reloc()
1644 ERROR_FUNC(sec, offset, "duplicate reloc"); in elf_create_reloc()
1661 struct section *sec; in elf_create_section_pair() local
1663 sec = elf_create_section(elf, name, nr * entsize, entsize, in elf_create_section_pair()
1665 if (!sec) in elf_create_section_pair()
1668 if (!elf_create_rela_section(elf, sec, nr_relocs)) in elf_create_section_pair()
1671 return sec; in elf_create_section_pair()
1674 int elf_write_insn(struct elf *elf, struct section *sec, in elf_write_insn() argument
1678 Elf_Data *data = sec->data; in elf_write_insn()
1681 ERROR("write to unexpected data for section: %s", sec->name); in elf_write_insn()
1687 mark_sec_changed(elf, sec, true); in elf_write_insn()
1701 static int elf_truncate_section(struct elf *elf, struct section *sec) in elf_truncate_section() argument
1703 u64 size = sec_size(sec); in elf_truncate_section()
1708 s = elf_getscn(elf->elf, sec->idx); in elf_truncate_section()
1747 struct section *sec; in elf_write() local
1751 list_for_each_entry(sec, &elf->sections, list) { in elf_write()
1752 if (sec->truncate && elf_truncate_section(elf, sec)) in elf_write()
1755 if (sec_changed(sec)) { in elf_write()
1756 s = elf_getscn(elf->elf, sec->idx); in elf_write()
1763 if (!gelf_update_shdr(s, &sec->sh)) { in elf_write()
1768 mark_sec_changed(elf, sec, false); in elf_write()