If PIE (position-independent executables) are supported, build valgrind's
stage2 as one.  This means that we're not hard-wiring stage2 in at 0xb0000000,
which means our memory layout is a bit more flexible, yay.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2833 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/stage1.c b/coregrind/stage1.c
index 0c4e030..9d66d20 100644
--- a/coregrind/stage1.c
+++ b/coregrind/stage1.c
@@ -259,16 +259,19 @@
    int *esp;
    char buf[strlen(valgrind_lib) + sizeof(stage2) + 16];
 
+#ifdef HAVE_PIE
+   info.exe_base = ROUNDDN(info.exe_end - 0x02000000, 0x10000000);
+   assert(info.exe_base >= PGROUNDUP(&_end));
+   info.map_base = info.exe_base + 0x01000000;
+#else
+
+   // If this system doesn't have PIE (position-independent executables),
+   // we have to choose a hardwired location for stage2.
    info.exe_base = PGROUNDUP(&_end);
+   info.map_base = KICKSTART_BASE + 0x01000000;
+#endif
    info.exe_end  = PGROUNDDN(init_sp);
 
-   /* XXX FIXME: how can stage1 know where stage2 wants things placed?
-      Options:
-      - we could look for a symbol
-      - it could have a special PHDR (v. ELF specific)
-      - something else?
-    */
-   info.map_base = KICKSTART_BASE + 0x01000000;
    info.argv = NULL;
 
    snprintf(buf, sizeof(buf), "%s/%s", valgrind_lib, stage2);