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

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