Blame SOURCES/0003-buildsys-Build-vdagentd-as-pie-relro-when-possible.patch

46eaa5
From 3b4db5a5064909641ad80e0c1678a62f94afb9aa Mon Sep 17 00:00:00 2001
46eaa5
From: Hans de Goede <hdegoede@redhat.com>
46eaa5
Date: Wed, 3 Jul 2013 11:16:20 +0200
46eaa5
Subject: [PATCH] buildsys: Build vdagentd as pie + relro when possible
46eaa5
46eaa5
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
46eaa5
(cherry picked from commit 71b8e75c6f1bc6c482d28cf29b82643d6b38cf34)
46eaa5
---
46eaa5
 Makefile.am  |  6 ++++--
46eaa5
 configure.ac | 32 ++++++++++++++++++++++++++++++++
46eaa5
 2 files changed, 36 insertions(+), 2 deletions(-)
46eaa5
46eaa5
diff --git a/Makefile.am b/Makefile.am
46eaa5
index ea9bc05..5515ca0 100644
46eaa5
--- a/Makefile.am
46eaa5
+++ b/Makefile.am
46eaa5
@@ -8,8 +8,10 @@ src_spice_vdagent_CFLAGS = $(X_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS)
46eaa5
 src_spice_vdagent_LDADD = $(X_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS)
46eaa5
 src_spice_vdagent_SOURCES = src/vdagent.c src/vdagent-x11.c src/vdagent-x11-randr.c src/vdagent-file-xfers.c src/udscs.c
46eaa5
 
46eaa5
-src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(LIBSYSTEMD_LOGIN_CFLAGS) $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS)
46eaa5
-src_spice_vdagentd_LDADD = $(DBUS_LIBS) $(LIBSYSTEMD_LOGIN_LIBS) $(PCIACCESS_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS)
46eaa5
+src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(LIBSYSTEMD_LOGIN_CFLAGS) \
46eaa5
+  $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS) $(PIE_CFLAGS)
46eaa5
+src_spice_vdagentd_LDADD = $(DBUS_LIBS) $(LIBSYSTEMD_LOGIN_LIBS) \
46eaa5
+  $(PCIACCESS_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) $(PIE_LDFLAGS)
46eaa5
 src_spice_vdagentd_SOURCES = src/vdagentd.c \
46eaa5
                              src/vdagentd-uinput.c \
46eaa5
                              src/vdagentd-xorg-conf.c \
46eaa5
diff --git a/configure.ac b/configure.ac
46eaa5
index 91a24ff..a1ce6c0 100644
46eaa5
--- a/configure.ac
46eaa5
+++ b/configure.ac
46eaa5
@@ -141,6 +141,37 @@ if test "$ac_test_CFLAGS" != set; then
46eaa5
   done
46eaa5
 fi
46eaa5
 
46eaa5
+AC_ARG_ENABLE([pie],
46eaa5
+  AS_HELP_STRING([--enable-pie=@<:@auto/yes/no@:>@],
46eaa5
+                 [Enable position-independent-executable support (for spice-vdagentd)@<:@default=auto@:>@]),
46eaa5
+  [],
46eaa5
+  [enable_pie="auto"])
46eaa5
+
46eaa5
+if test "x$enable_pie" != "xno"; then
46eaa5
+  save_CFLAGS="$CFLAGS"
46eaa5
+  save_LDFLAGS="$LDFLAGS"
46eaa5
+  CFLAGS="$CFLAGS -fPIE"
46eaa5
+  LDFLAGS="$LDFLAGS -pie -Wl,-z,relro -Wl,-z,now"
46eaa5
+  AC_MSG_CHECKING([for PIE support])
46eaa5
+  AC_LINK_IFELSE([AC_LANG_SOURCE([int main () { return 0; }])],
46eaa5
+                 [have_pie=yes],
46eaa5
+                 [have_pie=no])
46eaa5
+  AC_MSG_RESULT([$have_pie])
46eaa5
+  if test "x$have_pie" = "xno" && test "x$enable_pie" = "xyes"; then
46eaa5
+    AC_MSG_ERROR([pie support explicitly requested, but your toolchain does not support it])
46eaa5
+  fi
46eaa5
+  if test "x$have_pie" = "xyes"; then
46eaa5
+    PIE_CFLAGS="-fPIE"
46eaa5
+    PIE_LDFLAGS="-pie -Wl,-z,relro -Wl,-z,now"
46eaa5
+    AC_SUBST(PIE_CFLAGS)
46eaa5
+    AC_SUBST(PIE_LDFLAGS)
46eaa5
+  fi
46eaa5
+  CFLAGS="$save_CFLAGS"
46eaa5
+  LDFLAGS="$save_LDFLAGS"
46eaa5
+else
46eaa5
+  have_pie=no
46eaa5
+fi
46eaa5
+
46eaa5
 AC_CONFIG_FILES([
46eaa5
 Makefile
46eaa5
 data/spice-vdagent.1
46eaa5
@@ -160,6 +191,7 @@ AC_MSG_NOTICE([
46eaa5
         session-info:             ${with_session_info}
46eaa5
         pciaccess:                ${enable_pciaccess}
46eaa5
         static uinput:            ${enable_static_uinput}
46eaa5
+        vdagentd pie + relro:     ${have_pie}
46eaa5
 
46eaa5
         install RH initscript:    ${init_redhat}
46eaa5
         install systemd service:  ${init_systemd}