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