Lines Matching refs:sec
134 struct section *sec;
136 elf_hash_for_each_possible(section_name, sec, name_hash, str_hash(name)) {
137 if (!strcmp(sec->name, name))
138 return sec;
147 struct section *sec;
149 elf_hash_for_each_possible(section, sec, hash, idx) {
150 if (sec->idx == idx)
151 return sec;
169 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
171 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
182 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
184 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
195 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
197 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
211 int find_symbol_hole_containing(const struct section *sec, unsigned long offset)
223 n = rb_find(&hole, &sec->symbol_tree.rb_root, symbol_hole_by_offset);
243 struct symbol *find_func_containing(struct section *sec, unsigned long offset)
245 struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
268 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec,
275 rsec = sec->rsec;
282 if (reloc->sec != rsec)
298 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset)
300 return find_reloc_by_dest_range(elf, sec, offset, 1);
303 static bool is_dwarf_section(struct section *sec)
305 return !strncmp(sec->name, ".debug_", 7);
311 struct section *sec;
329 elf->section_data = calloc(sections_nr, sizeof(*sec));
335 sec = &elf->section_data[i];
337 INIT_LIST_HEAD(&sec->symbol_list);
345 sec->idx = elf_ndxscn(s);
347 if (!gelf_getshdr(s, &sec->sh)) {
352 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name);
353 if (!sec->name) {
358 if (sec->sh.sh_size != 0 && !is_dwarf_section(sec)) {
359 sec->data = elf_getdata(s, NULL);
360 if (!sec->data) {
364 if (sec->data->d_off != 0 ||
365 sec->data->d_size != sec->sh.sh_size) {
367 sec->name);
372 list_add_tail(&sec->list, &elf->sections);
373 elf_hash_add(section, &sec->hash, sec->idx);
374 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));
376 if (is_reloc_sec(sec))
377 elf->num_relocs += sec_num_entries(sec);
412 __sym_for_each(iter, &sym->sec->symbol_tree, sym->offset, sym->offset) {
417 __sym_insert(sym, &sym->sec->symbol_tree);
422 entry = &sym->sec->symbol_list;
432 __sym_remove(sym, &sym->sec->symbol_tree);
437 struct section *symtab, *symtab_shndx, *sec;
494 sym->sec = find_section_by_index(elf, shndx);
495 if (!sym->sec) {
501 sym->name = sym->sec->name;
502 sym->sec->sym = sym;
505 sym->sec = find_section_by_index(elf, 0);
516 list_for_each_entry(sec, &elf->sections, list) {
517 sec_for_each_sym(sec, sym) {
561 if (sym->sec == pfunc->sec &&
600 Elf32_Word shndx = sym->sec ? sym->sec->idx : SHN_UNDEF;
794 elf_create_section_symbol(struct elf *elf, struct section *sec)
803 sym->name = sec->name;
804 sym->sec = sec;
836 sym->sec = orig->sec;
871 reloc->sec = rsec;
886 struct reloc *elf_init_reloc_text_sym(struct elf *elf, struct section *sec,
915 return elf_init_reloc(elf, sec->rsec, reloc_idx, offset, sym, addend,
919 struct reloc *elf_init_reloc_data_sym(struct elf *elf, struct section *sec,
925 if (sym->sec && (sec->sh.sh_flags & SHF_EXECINSTR)) {
931 return elf_init_reloc(elf, sec->rsec, reloc_idx, offset, sym, addend,
969 reloc->sec = rsec;
1093 struct section *sec, *shstrtab;
1097 sec = malloc(sizeof(*sec));
1098 if (!sec) {
1102 memset(sec, 0, sizeof(*sec));
1104 INIT_LIST_HEAD(&sec->symbol_list);
1112 sec->name = strdup(name);
1113 if (!sec->name) {
1118 sec->idx = elf_ndxscn(s);
1120 sec->data = elf_newdata(s);
1121 if (!sec->data) {
1126 sec->data->d_size = size;
1127 sec->data->d_align = 1;
1130 sec->data->d_buf = malloc(size);
1131 if (!sec->data->d_buf) {
1135 memset(sec->data->d_buf, 0, size);
1138 if (!gelf_getshdr(s, &sec->sh)) {
1143 sec->sh.sh_size = size;
1144 sec->sh.sh_entsize = entsize;
1145 sec->sh.sh_type = SHT_PROGBITS;
1146 sec->sh.sh_addralign = 1;
1147 sec->sh.sh_flags = SHF_ALLOC;
1157 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name);
1158 if (sec->sh.sh_name == -1)
1161 list_add_tail(&sec->list, &elf->sections);
1162 elf_hash_add(section, &sec->hash, sec->idx);
1163 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));
1165 mark_sec_changed(elf, sec, true);
1167 return sec;
1171 struct section *sec,
1177 rsec_name = malloc(strlen(sec->name) + strlen(".rela") + 1);
1183 strcat(rsec_name, sec->name);
1194 rsec->sh.sh_info = sec->idx;
1203 sec->rsec = rsec;
1204 rsec->base = sec;
1213 struct section *sec;
1215 sec = elf_create_section(elf, name, entsize, nr);
1216 if (!sec)
1219 if (!elf_create_rela_section(elf, sec, reloc_nr))
1222 return sec;
1225 int elf_write_insn(struct elf *elf, struct section *sec,
1229 Elf_Data *data = sec->data;
1232 WARN("write to unexpected data for section: %s", sec->name);
1238 mark_sec_changed(elf, sec, true);
1252 static int elf_truncate_section(struct elf *elf, struct section *sec)
1254 u64 size = sec->sh.sh_size;
1259 s = elf_getscn(elf->elf, sec->idx);
1299 struct section *sec;
1306 list_for_each_entry(sec, &elf->sections, list) {
1307 if (sec->truncate)
1308 elf_truncate_section(elf, sec);
1310 if (sec_changed(sec)) {
1311 s = elf_getscn(elf->elf, sec->idx);
1318 if (!gelf_update_shdr(s, &sec->sh)) {
1323 mark_sec_changed(elf, sec, false);