Lines Matching full:seg
39 static void insert_to_inseg_list(struct segment *seg, struct section *sec);
56 struct segment *seg; in add_to_inseg_list() local
74 STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) { in add_to_inseg_list()
75 if (s->off < seg->off || (s->vma < seg->vaddr && !s->pseudo)) in add_to_inseg_list()
77 if (s->off + s->sz > seg->off + seg->fsz && in add_to_inseg_list()
80 if (s->vma + s->sz > seg->vaddr + seg->msz) in add_to_inseg_list()
82 if (seg->type == PT_TLS && ((s->flags & SHF_TLS) == 0)) in add_to_inseg_list()
85 insert_to_inseg_list(seg, s); in add_to_inseg_list()
86 if (seg->type == PT_LOAD) in add_to_inseg_list()
87 s->seg = seg; in add_to_inseg_list()
88 else if (seg->type == PT_TLS) in add_to_inseg_list()
89 s->seg_tls = seg; in add_to_inseg_list()
91 s->vma = seg->vaddr + (s->off - seg->off); in add_to_inseg_list()
92 if (seg->paddr > 0) in add_to_inseg_list()
93 s->lma = seg->paddr + (s->off - seg->off); in add_to_inseg_list()
106 struct segment *seg; in adjust_addr() local
125 if (ecp->change_addr != 0 && s->seg != NULL && in adjust_addr()
126 s->seg->paddr > 0) in adjust_addr()
157 if (s->seg == NULL) { in adjust_addr()
183 if (vma < s->vma - s->seg->vaddr) in adjust_addr()
187 start = vma - (s->vma - s->seg->vaddr); in adjust_addr()
188 if (s == s->seg->v_sec[s->seg->nsec - 1]) in adjust_addr()
189 end = start + s->seg->msz; in adjust_addr()
191 end = s->seg->vaddr + s->seg->msz; in adjust_addr()
194 if (s == s->seg->v_sec[0]) in adjust_addr()
197 start = s->seg->vaddr; in adjust_addr()
198 end = vma + (s->seg->vaddr + s->seg->msz - s->vma); in adjust_addr()
210 STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) { in adjust_addr()
211 if (seg == s->seg || seg->type != PT_LOAD) in adjust_addr()
213 if (start > seg->vaddr + seg->msz) in adjust_addr()
215 if (end < seg->vaddr) in adjust_addr()
219 s->name, (uintmax_t) seg->vaddr, in adjust_addr()
220 (uintmax_t) (seg->vaddr + seg->msz)); in adjust_addr()
235 for (i = 0; i < s->seg->nsec; i++) { in adjust_addr()
236 s0 = s->seg->v_sec[i]; in adjust_addr()
245 for (i = i + 1; i < s->seg->nsec; i++) { in adjust_addr()
246 s0 = s->seg->v_sec[i]; in adjust_addr()
262 for (i = 0; i < s->seg->nsec; i++) in adjust_addr()
263 if (s->seg->v_sec[i] == s) in adjust_addr()
265 if (i >= s->seg->nsec) in adjust_addr()
269 for (; i < s->seg->nsec; i++) { in adjust_addr()
270 s0 = s->seg->v_sec[i]; in adjust_addr()
276 if (s != s->seg->v_sec[0]) { in adjust_addr()
297 STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) { in adjust_addr()
298 if (seg->type != PT_LOAD) in adjust_addr()
300 for (i = seg->nsec - 1; i >= 0; i--) in adjust_addr()
301 if (seg->v_sec[i]->type != SHT_NOBITS) in adjust_addr()
306 s = seg->v_sec[i]; in adjust_addr()
308 s0 = seg->v_sec[i]; in adjust_addr()
341 if (!s->loadable || s->seg == NULL || s->seg->paddr == 0) in adjust_addr()
382 for (i = 0; i < s->seg->nsec; i++) { in adjust_addr()
383 s0 = s->seg->v_sec[i]; in adjust_addr()
399 for (i = 0; i < s->seg->nsec; i++) in adjust_addr()
400 if (s->seg->v_sec[i] == s) in adjust_addr()
402 if (i >= s->seg->nsec) in adjust_addr()
406 for (; i < s->seg->nsec; i++) { in adjust_addr()
407 s0 = s->seg->v_sec[i]; in adjust_addr()
442 insert_to_inseg_list(struct segment *seg, struct section *sec) in insert_to_inseg_list() argument
447 seg->nsec++; in insert_to_inseg_list()
448 seg->v_sec = realloc(seg->v_sec, seg->nsec * sizeof(*seg->v_sec)); in insert_to_inseg_list()
449 if (seg->v_sec == NULL) in insert_to_inseg_list()
456 for (i = seg->nsec - 1; i > 0; i--) { in insert_to_inseg_list()
457 s = seg->v_sec[i - 1]; in insert_to_inseg_list()
459 seg->v_sec[i] = sec; in insert_to_inseg_list()
462 seg->v_sec[i] = s; in insert_to_inseg_list()
465 seg->v_sec[0] = sec; in insert_to_inseg_list()
471 struct segment *seg; in setup_phdr() local
493 if ((seg = calloc(1, sizeof(*seg))) == NULL) in setup_phdr()
495 seg->vaddr = iphdr.p_vaddr; in setup_phdr()
496 seg->paddr = iphdr.p_paddr; in setup_phdr()
497 seg->off = iphdr.p_offset; in setup_phdr()
498 seg->fsz = iphdr.p_filesz; in setup_phdr()
499 seg->msz = iphdr.p_memsz; in setup_phdr()
500 seg->type = iphdr.p_type; in setup_phdr()
501 STAILQ_INSERT_TAIL(&ecp->v_seg, seg, seg_list); in setup_phdr()
508 struct segment *seg; in copy_phdr() local
513 STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) { in copy_phdr()
514 if (seg->type == PT_PHDR) { in copy_phdr()
518 seg->vaddr = s->vma + in copy_phdr()
521 seg->paddr = s->lma + in copy_phdr()
526 seg->fsz = seg->msz = gelf_fsize(ecp->eout, ELF_T_PHDR, in copy_phdr()
531 if (seg->nsec > 0) { in copy_phdr()
532 s = seg->v_sec[0]; in copy_phdr()
533 seg->vaddr = s->vma; in copy_phdr()
534 seg->paddr = s->lma; in copy_phdr()
537 seg->fsz = seg->msz = 0; in copy_phdr()
538 for (i = 0; i < seg->nsec; i++) { in copy_phdr()
539 s = seg->v_sec[i]; in copy_phdr()
540 seg->msz = s->vma + s->sz - seg->vaddr; in copy_phdr()
542 seg->fsz = s->off + s->sz - seg->off; in copy_phdr()
568 STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) { in copy_phdr()
579 ophdr.p_vaddr = seg->vaddr; in copy_phdr()
580 ophdr.p_paddr = seg->paddr; in copy_phdr()
583 ophdr.p_offset = seg->off; in copy_phdr()
584 ophdr.p_filesz = seg->fsz; in copy_phdr()
585 ophdr.p_memsz = seg->msz; in copy_phdr()