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

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