Lines 579-584
static char *scanelf_file_textrels(elfobj *elf, char *found_textrels, char *foun
Link Here
|
579 |
Elf ## B ## _Rela *rela; \ |
579 |
Elf ## B ## _Rela *rela; \ |
580 |
Elf ## B ## _Dyn *dyn, *drel, *drelsz, *drelent, *dpltrel; \ |
580 |
Elf ## B ## _Dyn *dyn, *drel, *drelsz, *drelent, *dpltrel; \ |
581 |
uint32_t pltrel; \ |
581 |
uint32_t pltrel; \ |
|
|
582 |
Elf ## B ## _Addr load_address = 0; \ |
583 |
Elf ## B ## _Addr file_offset; \ |
582 |
\ |
584 |
\ |
583 |
/* Walk all the dynamic tags to find relocation info */ \ |
585 |
/* Walk all the dynamic tags to find relocation info */ \ |
584 |
drel = drelsz = drelent = dpltrel = NULL; \ |
586 |
drel = drelsz = drelent = dpltrel = NULL; \ |
Lines 605-631
static char *scanelf_file_textrels(elfobj *elf, char *found_textrels, char *foun
Link Here
|
605 |
warnf("ELF is missing relocation information"); \ |
607 |
warnf("ELF is missing relocation information"); \ |
606 |
break; \ |
608 |
break; \ |
607 |
} \ |
609 |
} \ |
|
|
610 |
phdr = PHDR ## B(elf->phdr); \ |
611 |
/* Lookup load base: byte 0 is mapped at load_address */ \ |
612 |
for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ |
613 |
/* Only care about loadable segments. */ \ |
614 |
if (EGET(phdr[i].p_type) != PT_LOAD) \ |
615 |
continue; \ |
616 |
/* We search for the first program header to map into memory */ \ |
617 |
if (EGET(phdr[i].p_offset) != 0) \ |
618 |
continue; \ |
619 |
load_address = EGET(phdr[i].p_vaddr); \ |
620 |
} \ |
608 |
switch (EGET(dpltrel->d_un.d_val)) { \ |
621 |
switch (EGET(dpltrel->d_un.d_val)) { \ |
609 |
case DT_REL: \ |
622 |
case DT_REL: \ |
610 |
if (!VALID_RANGE(elf, EGET(drel->d_un.d_val), sizeof (drel->d_un.d_val))) { \ |
623 |
file_offset = EGET(drel->d_un.d_val) - load_address; \ |
|
|
624 |
if (!VALID_RANGE(elf, file_offset, sizeof (drel->d_un.d_val))) { \ |
611 |
rel = NULL; \ |
625 |
rel = NULL; \ |
612 |
rela = NULL; \ |
626 |
rela = NULL; \ |
613 |
warn("%s: DT_REL is out of file range", elf->filename); \ |
627 |
warn("%s: DT_REL is out of file range", elf->filename); \ |
614 |
break; \ |
628 |
break; \ |
615 |
} \ |
629 |
} \ |
616 |
rel = REL##B(elf->vdata + EGET(drel->d_un.d_val)); \ |
630 |
rel = REL##B(elf->vdata + file_offset); \ |
617 |
rela = NULL; \ |
631 |
rela = NULL; \ |
618 |
pltrel = DT_REL; \ |
632 |
pltrel = DT_REL; \ |
619 |
break; \ |
633 |
break; \ |
620 |
case DT_RELA: \ |
634 |
case DT_RELA: \ |
621 |
if (!VALID_RANGE(elf, EGET(drel->d_un.d_val), sizeof (drel->d_un.d_val))) { \ |
635 |
file_offset = EGET(drel->d_un.d_val) - load_address; \ |
|
|
636 |
if (!VALID_RANGE(elf, file_offset, sizeof (drel->d_un.d_val))) { \ |
622 |
rel = NULL; \ |
637 |
rel = NULL; \ |
623 |
rela = NULL; \ |
638 |
rela = NULL; \ |
624 |
warn("%s: DT_RELA is out of file range", elf->filename); \ |
639 |
warn("%s: DT_RELA is out of file range", elf->filename); \ |
625 |
break; \ |
640 |
break; \ |
626 |
} \ |
641 |
} \ |
627 |
rel = NULL; \ |
642 |
rel = NULL; \ |
628 |
rela = RELA##B(elf->vdata + EGET(drel->d_un.d_val)); \ |
643 |
rela = RELA##B(elf->vdata + file_offset); \ |
629 |
pltrel = DT_RELA; \ |
644 |
pltrel = DT_RELA; \ |
630 |
break; \ |
645 |
break; \ |
631 |
default: \ |
646 |
default: \ |
Lines 639-645
static char *scanelf_file_textrels(elfobj *elf, char *found_textrels, char *foun
Link Here
|
639 |
rmax = EGET(drelsz->d_un.d_val) / EGET(drelent->d_un.d_val); \ |
654 |
rmax = EGET(drelsz->d_un.d_val) / EGET(drelent->d_un.d_val); \ |
640 |
\ |
655 |
\ |
641 |
/* search the program segments for relocations */ \ |
656 |
/* search the program segments for relocations */ \ |
642 |
phdr = PHDR ## B(elf->phdr); \ |
|
|
643 |
for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ |
657 |
for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ |
644 |
Elf ## B ## _Addr vaddr = EGET(phdr[i].p_vaddr); \ |
658 |
Elf ## B ## _Addr vaddr = EGET(phdr[i].p_vaddr); \ |
645 |
uint ## B ## _t memsz = EGET(phdr[i].p_memsz); \ |
659 |
uint ## B ## _t memsz = EGET(phdr[i].p_memsz); \ |
646 |
- |
|
|