Skip to contentSkip to conversation

master - configure: check compiler/linker support for RELRO and PIE options

PATCH Peter Rajnoha 1 participant 1 message Dec 4, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6c6bcc00e401262db3b906259674a3231a119603
Commit:        6c6bcc00e401262db3b906259674a3231a119603
Parent:        163666e513848e5d43d3e4f2f91b42d1a8f483a0
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Dec 4 09:58:58 2013 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Dec 4 13:30:08 2013 +0100

configure: check compiler/linker support for RELRO and PIE options

Also, add AC_TRY_LDFLAGS m4 macro to help with checking ld flags.

---
 WHATS_NEW    |    1 +
 acinclude.m4 |   21 +++++++++++++++
 configure    |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.in |    7 +++++
 4 files changed, 110 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
index 553edfd..9155ddf 100644
@@ -1,5 +1,6 @@
 Version 2.02.105 -
 =====================================
+  Automatically detect support for compiler/linker options to use RELRO and PIE.
   Add --splitsnapshot to lvconvert to separate out cow LV.
   Reinstate origin reload to complete lvconvert -s with active LVs. (2.02.98)
   Select only active volume groups if vgdisplay -A is used.
acinclude.m4 +21 -0
index bf9fe09..b9473db 100644
@@ -36,3 +36,24 @@ AC_DEFUN([AC_TRY_CCFLAG],
         ifelse([$4], [], [:], [$4])
     fi
 ])
+
+dnl AC_TRY_LDFLAGS([LDFLAGS], [VAR], [ACTION-IF-WORKS], [ACTION-IF-FAILS])
+dnl check if $CC supports given ld flags
+
+AC_DEFUN([AC_TRY_LDFLAGS],
+[
+    AC_REQUIRE([AC_PROG_CC])
+    ac_save_LDFLAGS=$LDFLAGS
+    LDFLAGS=$1
+	AC_CACHE_CHECK([whether $CC accepts $1 ld flags], [ac_cv_flag_$2],
+	[AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+			[AS_VAR_SET([ac_cv_flag_$2], [yes])],
+			[AS_VAR_SET([ac_cv_flag_$2], [no])])])
+    LDLAGS=$ac_save_LDFLAGS
+    $2=AS_VAR_GET([ac_cv_flag_$2])
+    if test "$2" = yes; then
+        ifelse([$3], [], [:], [$3])
+    else
+        ifelse([$4], [], [:], [$4])
+    fi
+])
configure +81 -0

93 lines not on this page · raw message

configure.in +7 -0
index e4d0014..851d3f7 100644
@@ -159,6 +159,13 @@ AC_ARG_ENABLE(static_link,
 AC_MSG_RESULT($STATIC_LINK)
 
 ################################################################################
+dnl -- Check if compiler/linker supports PIE and RELRO
+AC_TRY_CCFLAG([-pie], [HAVE_PIE], [], [])
+AC_SUBST(HAVE_PIE)
+AC_TRY_LDFLAGS([-Wl,-z,relro,-z,now], [HAVE_FULL_RELRO], [], [])
+AC_SUBST(HAVE_FULL_RELRO)
+
+################################################################################
 dnl -- Prefix is /usr by default, the exec_prefix default is setup later
 AC_PREFIX_DEFAULT(/usr)