Browse Source

[build] Test for GNU-style PIE support in toolchain and enable

2008-08-13 Paul P Komkoff Jr <i@stingr.net>

	* configure.ac: add a configure flag and autoconf macro, which will
	  determine if your toolchain supports PIE.
	* */Makefile.am: add corresponding CFLAGS and LDFLAGS into
	  appropriate places.

Signed-off-by: Paul Jakma <paul@quagga.net>
Paul P Komkoff Jr 11 years ago
parent
commit
46bc0e432e

+ 3 - 0
bgpd/Makefile.am

@@ -4,6 +4,9 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
 DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 INSTALL_SDATA=@INSTALL@ -m 600
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_LIBRARIES = libbgp.a
 sbin_PROGRAMS = bgpd
 

+ 27 - 1
configure.ac

@@ -60,9 +60,10 @@ fi
 dnl --------------------
 dnl Check CC and friends
 dnl --------------------
+AC_LANG([C])
 AC_PROG_CC
 AC_PROG_CPP
-
+AM_PROG_CC_C_O
 AC_PROG_EGREP
 
 dnl autoconf 2.59 appears not to support AC_PROG_SED
@@ -1395,6 +1396,31 @@ dnl ----------
 CONFDATE=`date '+%Y%m%d'`
 AC_SUBST(CONFDATE)
 
+dnl Conditionally enable PIE support for GNU toolchains.
+enable_pie=yes
+
+AC_ARG_ENABLE(pie, AS_HELP_STRING([--disable-pie], [Do not build tools as a Position Independent Executables]))
+if test "$enable_pie" = "yes"; then
+  AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [
+    save_CFLAGS=$CFLAGS
+    save_LDFLAGS=$LDFLAGS
+    CFLAGS="$CFLAGS -fPIE"
+    LDFLAGS="$LDFLAGS -pie"
+    AC_LINK_IFELSE([AC_LANG_SOURCE([[static int foo[30000]; int main () { return 0; }]])],
+      [ap_cv_cc_pie=yes], [ap_cv_cc_pie=no]
+    )
+    CFLAGS=$save_CFLAGS
+    LDFLAGS=$save_LDFLAGS
+  ])
+  if test "$ap_cv_cc_pie" = "yes"; then
+    PICFLAGS="-fPIE"
+    PILDFLAGS="-pie"
+  fi
+fi
+
+AC_SUBST(PICFLAGS)
+AC_SUBST(PILDFLAGS)
+
 dnl ------------------------------
 dnl set paths for state directory
 dnl ------------------------------

+ 3 - 0
guile/Makefile.am

@@ -3,6 +3,9 @@
 INCLUDES = @GUILE_CFLAGS@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
 DEFS = @DEFS@ -I. -I$(srcdir)
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 bin_PROGRAMS = zebra-guile
 zebra_guile_SOURCES = zebra-guile.c zebra-support.c guile-bgp.c
 noinst_HEADERS = zebra-guile.h

+ 4 - 0
isisd/Makefile.am

@@ -5,6 +5,10 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib \
 DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 INSTALL_SDATA=@INSTALL@ -m 600
 LIBS = @LIBS@ 
+
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_LIBRARIES = libisis.a
 sbin_PROGRAMS = isisd 
 SUBDIRS = topology

+ 3 - 0
ospf6d/Makefile.am

@@ -4,6 +4,9 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
 DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 INSTALL_SDATA=@INSTALL@ -m 600
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_LIBRARIES = libospf6.a
 sbin_PROGRAMS = ospf6d
 

+ 2 - 0
ospfclient/Makefile.am

@@ -21,4 +21,6 @@ ospfclient_SOURCES = \
 ospfclient_LDADD = libospfapiclient.la \
 	../ospfd/libospf.la ../lib/libzebra.la @LIBCAP@
 
+ospfclient_CFLAGS = $(AM_CFLAGS) $(PICFLAGS)
+ospfclient_LDFLAGS = $(AM_LDFLAGS) $(PILDFLAGS)
 

+ 3 - 0
ripd/Makefile.am

@@ -4,6 +4,9 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
 DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 INSTALL_SDATA=@INSTALL@ -m 600
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_LIBRARIES = librip.a
 sbin_PROGRAMS = ripd
 

+ 3 - 0
ripngd/Makefile.am

@@ -4,6 +4,9 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
 DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 INSTALL_SDATA=@INSTALL@ -m 600
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_LIBRARIES = libripng.a
 sbin_PROGRAMS = ripngd
 

+ 3 - 0
tests/Makefile.am

@@ -1,6 +1,9 @@
 INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
 DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\"
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 noinst_PROGRAMS = testsig testbuffer testmemory heavy heavywq heavythread \
 		aspathtest testprivs teststream testbgpcap ecommtest \
 		testbgpmpattr

+ 3 - 0
vtysh/Makefile.am

@@ -5,6 +5,9 @@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 
 LIBS = @LIBS@ @CURSES@ @LIBPAM@
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 bin_PROGRAMS = vtysh
 
 vtysh_SOURCES = vtysh_main.c vtysh.c vtysh_user.c vtysh_config.c

+ 3 - 0
watchquagga/Makefile.am

@@ -3,6 +3,9 @@
 INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib
 DEFS = @DEFS@ -DSTATEDIR=\"$(localstatedir)/\"
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 sbin_PROGRAMS = watchquagga
 
 watchquagga_SOURCES = watchquagga.c

+ 3 - 0
zebra/Makefile.am

@@ -19,6 +19,9 @@ ioctl_method = @IOCTL_METHOD@
 otherobj = $(ioctl_method) $(ipforward) $(if_method) $(if_proc) \
 	$(rt_method) $(rtread_method) $(kernel_method) $(other_method)
 
+AM_CFLAGS = $(PICFLAGS)
+AM_LDFLAGS = $(PILDFLAGS)
+
 sbin_PROGRAMS = zebra
 
 noinst_PROGRAMS = testzebra