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/Makefile.am b/coregrind/Makefile.am
index a1a4a17..3c21458 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -77,11 +77,22 @@
 	vg_toolint.c \
 	vg_translate.c \
 	vg_transtab.c
+## Test repeated in both arms of the if-then-else because older versions of
+## automake don't seem to like having += within an if-then-else.
+if USE_PIE
+stage2_CFLAGS = $(AM_CFLAGS) -fpie
+stage2_DEPENDENCIES = $(srcdir)/valgrind.vs
+stage2_LDFLAGS = -Wl,--export-dynamic -g \
+	-Wl,-version-script $(srcdir)/valgrind.vs \
+	-pie
+else
+stage2_CFLAGS = $(AM_CFLAGS)
 stage2_DEPENDENCIES = $(srcdir)/valgrind.vs ${VG_ARCH}/stage2.lds
-stage2_LDFLAGS=-Wl,--export-dynamic -g \
-	-Wl,-defsym,kickstart_base=@KICKSTART_BASE@ \
-	-Wl,-T,${VG_ARCH}/stage2.lds \
-	-Wl,-version-script $(srcdir)/valgrind.vs 
+stage2_LDFLAGS = -Wl,--export-dynamic -g \
+	-Wl,-version-script $(srcdir)/valgrind.vs \
+	-Wl,-defsym,kickstart_base=@KICKSTART_BASE@ -Wl,-T,${VG_ARCH}/stage2.lds
+endif
+
 stage2_LDADD= \
 	demangle/cp-demangle.o \
 	demangle/cplus-dem.o \