|
From: Jeremy F. <je...@go...> - 2004-09-08 20:05:13
|
CVS commit by fitzhardinge:
When loading a -fpie executable, put it where info.exebase wants it, since
it doesn't have a useful address in its phdrs.
M +17 -6 ume.c 1.25
--- valgrind/coregrind/ume.c #1.24:1.25
@@ -406,8 +406,9 @@ static int load_ELF(char *hdr, int len,
struct elfinfo *e;
struct elfinfo *interp = NULL;
- ESZ(Addr) minaddr = ~0;
- ESZ(Addr) maxaddr = 0;
- ESZ(Addr) interp_addr = 0;
- ESZ(Word) interp_size = 0;
+ ESZ(Addr) exeoff = 0; /* offset between link address and load address */
+ ESZ(Addr) minaddr = ~0; /* lowest mapped address */
+ ESZ(Addr) maxaddr = 0; /* highest mapped address */
+ ESZ(Addr) interp_addr = 0; /* interpreter (ld.so) address */
+ ESZ(Word) interp_size = 0; /* interpreter size */
int i;
void *entry;
@@ -487,4 +488,14 @@ static int load_ELF(char *hdr, int len,
}
+ if (e->e.e_type == ET_DYN) {
+ /* PIE executable */
+ exeoff = info->exe_base - minaddr;
+ }
+
+ minaddr += exeoff;
+ maxaddr += exeoff;
+ info->phdr += exeoff;
+ info->entry += exeoff;
+
if (info->exe_base != info->exe_end) {
if (minaddr >= maxaddr ||
@@ -499,5 +510,5 @@ static int load_ELF(char *hdr, int len,
}
- info->brkbase = mapelf(e, 0); /* map the executable */
+ info->brkbase = mapelf(e, exeoff); /* map the executable */
if (info->brkbase == 0)
@@ -530,5 +541,5 @@ static int load_ELF(char *hdr, int len,
info->interp_base = (ESZ(Addr))base;
} else
- entry = (void *)e->e.e_entry;
+ entry = (void *)e->e.e_entry + exeoff;
info->exe_base = minaddr;
|