Lines Matching refs:sec
132 struct section *sec;
134 elf_hash_for_each_possible(elf->section_name_hash, sec, name_hash, str_hash(name))
135 if (!strcmp(sec->name, name))
136 return sec;
144 struct section *sec;
146 elf_hash_for_each_possible(elf->section_hash, sec, hash, idx)
147 if (sec->idx == idx)
148 return sec;
164 struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
168 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) {
178 struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
182 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) {
192 struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
196 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) {
206 struct symbol *find_func_containing(struct section *sec, unsigned long offset)
210 rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) {
231 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec,
237 if (!sec->reloc)
240 sec = sec->reloc;
244 sec_offset_hash(sec, o)) {
245 if (reloc->sec != sec)
260 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset)
262 return find_reloc_by_dest_range(elf, sec, offset, 1);
268 struct section *sec;
283 sec = malloc(sizeof(*sec));
284 if (!sec) {
288 memset(sec, 0, sizeof(*sec));
290 INIT_LIST_HEAD(&sec->symbol_list);
291 INIT_LIST_HEAD(&sec->reloc_list);
299 sec->idx = elf_ndxscn(s);
301 if (!gelf_getshdr(s, &sec->sh)) {
306 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name);
307 if (!sec->name) {
312 if (sec->sh.sh_size != 0) {
313 sec->data = elf_getdata(s, NULL);
314 if (!sec->data) {
318 if (sec->data->d_off != 0 ||
319 sec->data->d_size != sec->sh.sh_size) {
321 sec->name);
325 sec->len = sec->sh.sh_size;
327 list_add_tail(&sec->list, &elf->sections);
328 elf_hash_add(elf->section_hash, &sec->hash, sec->idx);
329 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name));
357 rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset);
362 entry = &sym->sec->symbol_list;
372 rb_erase(&sym->node, &sym->sec->symbol_tree);
377 struct section *symtab, *symtab_shndx, *sec;
428 sym->sec = find_section_by_index(elf, shndx);
429 if (!sym->sec) {
435 sym->name = sym->sec->name;
436 sym->sec->sym = sym;
439 sym->sec = find_section_by_index(elf, 0);
448 list_for_each_entry(sec, &elf->sections, list) {
449 list_for_each_entry(sym, &sec->symbol_list, list) {
493 if (sym->sec == pfunc->sec &&
512 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
517 if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA))
527 reloc->sec = sec->reloc;
533 list_add_tail(&reloc->list, &sec->reloc->reloc_list);
536 sec->reloc->changed = true;
548 struct section *sec;
550 list_for_each_entry(sec, &elf->sections, list) {
553 if (sec->changed)
556 list_for_each_entry(reloc, &sec->reloc_list, list) {
558 sec->changed = true;
576 Elf32_Word shndx = sym->sec ? sym->sec->idx : SHN_UNDEF;
637 shndx_data->d_buf = &sym->sec->idx;
692 elf_create_section_symbol(struct elf *elf, struct section *sec)
712 sym->name = sec->name;
713 sym->sec = sec;
760 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
781 return elf_add_reloc(elf, sec, offset, type, sym, addend);
784 static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx)
786 if (!gelf_getrel(sec->data, i, &reloc->rel)) {
797 static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx)
799 if (!gelf_getrela(sec->data, i, &reloc->rela)) {
812 struct section *sec;
818 list_for_each_entry(sec, &elf->sections, list) {
819 if ((sec->sh.sh_type != SHT_RELA) &&
820 (sec->sh.sh_type != SHT_REL))
823 sec->base = find_section_by_index(elf, sec->sh.sh_info);
824 if (!sec->base) {
826 sec->name);
830 sec->base->reloc = sec;
833 for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) {
840 switch (sec->sh.sh_type) {
842 if (read_rel_reloc(sec, i, reloc, &symndx))
846 if (read_rela_reloc(sec, i, reloc, &symndx))
852 reloc->sec = sec;
857 symndx, sec->name);
861 list_add_tail(&reloc->list, &sec->reloc_list);
981 struct section *sec, *shstrtab;
985 sec = malloc(sizeof(*sec));
986 if (!sec) {
990 memset(sec, 0, sizeof(*sec));
992 INIT_LIST_HEAD(&sec->symbol_list);
993 INIT_LIST_HEAD(&sec->reloc_list);
1001 sec->name = strdup(name);
1002 if (!sec->name) {
1007 sec->idx = elf_ndxscn(s);
1008 sec->len = size;
1009 sec->changed = true;
1011 sec->data = elf_newdata(s);
1012 if (!sec->data) {
1017 sec->data->d_size = size;
1018 sec->data->d_align = 1;
1021 sec->data->d_buf = malloc(size);
1022 if (!sec->data->d_buf) {
1026 memset(sec->data->d_buf, 0, size);
1029 if (!gelf_getshdr(s, &sec->sh)) {
1034 sec->sh.sh_size = size;
1035 sec->sh.sh_entsize = entsize;
1036 sec->sh.sh_type = SHT_PROGBITS;
1037 sec->sh.sh_addralign = 1;
1038 sec->sh.sh_flags = SHF_ALLOC | sh_flags;
1048 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name);
1049 if (sec->sh.sh_name == -1)
1052 list_add_tail(&sec->list, &elf->sections);
1053 elf_hash_add(elf->section_hash, &sec->hash, sec->idx);
1054 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name));
1058 return sec;
1064 struct section *sec;
1074 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rel), 0);
1076 if (!sec)
1079 base->reloc = sec;
1080 sec->base = base;
1082 sec->sh.sh_type = SHT_REL;
1083 sec->sh.sh_addralign = 8;
1084 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx;
1085 sec->sh.sh_info = base->idx;
1086 sec->sh.sh_flags = SHF_INFO_LINK;
1088 return sec;
1094 struct section *sec;
1104 sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
1106 if (!sec)
1109 base->reloc = sec;
1110 sec->base = base;
1112 sec->sh.sh_type = SHT_RELA;
1113 sec->sh.sh_addralign = 8;
1114 sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx;
1115 sec->sh.sh_info = base->idx;
1116 sec->sh.sh_flags = SHF_INFO_LINK;
1118 return sec;
1132 static int elf_rebuild_rel_reloc_section(struct section *sec, int nr)
1146 sec->data->d_buf = relocs;
1147 sec->data->d_size = size;
1149 sec->sh.sh_size = size;
1152 list_for_each_entry(reloc, &sec->reloc_list, list) {
1161 static int elf_rebuild_rela_reloc_section(struct section *sec, int nr)
1175 sec->data->d_buf = relocs;
1176 sec->data->d_size = size;
1178 sec->sh.sh_size = size;
1181 list_for_each_entry(reloc, &sec->reloc_list, list) {
1191 static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec)
1197 list_for_each_entry(reloc, &sec->reloc_list, list)
1200 switch (sec->sh.sh_type) {
1201 case SHT_REL: return elf_rebuild_rel_reloc_section(sec, nr);
1202 case SHT_RELA: return elf_rebuild_rela_reloc_section(sec, nr);
1207 int elf_write_insn(struct elf *elf, struct section *sec,
1211 Elf_Data *data = sec->data;
1214 WARN("write to unexpected data for section: %s", sec->name);
1228 struct section *sec = reloc->sec;
1230 if (sec->sh.sh_type == SHT_REL) {
1234 if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) {
1243 if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) {
1256 struct section *sec;
1260 list_for_each_entry(sec, &elf->sections, list) {
1261 if (sec->changed) {
1262 if (sec->base &&
1263 elf_rebuild_reloc_section(elf, sec)) {
1268 s = elf_getscn(elf->elf, sec->idx);
1273 if (!gelf_update_shdr(s, &sec->sh)) {
1278 sec->changed = false;
1299 struct section *sec, *tmpsec;
1309 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) {
1310 list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) {
1315 list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) {
1320 list_del(&sec->list);
1321 free(sec);