726498e
From: John (J5) Palmieri <johnp@redhat.com>
726498e
Date: Wed, 3 Oct 2007 19:21:57 +0000 (-0400)
726498e
Subject: Correctly implement -fPIC and -fPIE
726498e
X-Git-Url: http://gitweb.freedesktop.org/?p=dbus/dbus.git;a=commitdiff;h=8a92100bbed2ba5cb16a1ede36214fa7d2f43e43
726498e
726498e
Correctly implement -fPIC and -fPIE
726498e
726498e
* For security reasons we want possition independent code for libraries
726498e
  and possition independent executable for executables
726498e
* before we were just enabling -fPIC
726498e
* now we correctly enable -fPIC and -PIE for libdbus and the bus respectively
726498e
* propper LD_FLAGS are set for each also
726498e
---
726498e
726498e
--- a/bus/Makefile.am
726498e
+++ b/bus/Makefile.am
726498e
@@ -1,7 +1,7 @@
726498e
 
726498e
 configdir=$(sysconfdir)/dbus-1
726498e
 
726498e
-INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS)				\
726498e
+INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) @PIE_CFLAGS@		\
726498e
 	-DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\"	\
726498e
 	-DDAEMON_NAME=\"dbus-daemon\"  -DDBUS_COMPILATION
726498e
 
726498e
@@ -77,7 +77,7 @@ dbus_daemon_LDADD=					\
726498e
 	$(DBUS_BUS_LIBS)				\
726498e
 	$(top_builddir)/dbus/libdbus-convenience.la
726498e
 
726498e
-dbus_daemon_LDFLAGS=@R_DYNAMIC_LDFLAG@ @SECTION_LDFLAGS@
726498e
+dbus_daemon_LDFLAGS=@R_DYNAMIC_LDFLAG@ @SECTION_LDFLAGS@ @PIE_LDFLAGS@
726498e
 
726498e
 LAUNCH_HELPER_SOURCES=				\
726498e
 	$(XML_SOURCES)				\
726498e
--- a/configure.in
726498e
+++ b/configure.in
726498e
@@ -211,7 +211,17 @@ if test "x$GCC" = "xyes"; then
726498e
   case " $CFLAGS " in
726498e
   *[\ \	]-fPIC[\ \	]*) ;;
726498e
   *) if cc_supports_flag -fPIC; then
726498e
-        CFLAGS="$CFLAGS -fPIC"
726498e
+        PIC_CFLAGS="-fPIC"
726498e
+        PIC_LDFLAGS="-Wl,-z,relro"
726498e
+     fi
726498e
+     ;;
726498e
+  esac
726498e
+
726498e
+  case " $CFLAGS " in
726498e
+  *[\ \	]-fPIE[\ \	]*) ;;
726498e
+  *) if cc_supports_flag -fPIE; then
726498e
+        PIE_CFLAGS="-fPIE"
726498e
+        PIE_LDFLAGS="-pie -Wl,-z,relro"
726498e
      fi
726498e
      ;;
726498e
   esac
726498e
@@ -257,6 +267,11 @@ else
726498e
   fi
726498e
 fi
726498e
 
726498e
+AC_SUBST(PIC_CFLAGS)
726498e
+AC_SUBST(PIC_LDFLAGS)  
726498e
+AC_SUBST(PIE_CFLAGS)
726498e
+AC_SUBST(PIE_LDFLAGS)  
726498e
+
726498e
 # Check for -Wl,--gc-sections
726498e
 AC_MSG_CHECKING([for ld that supports "-Wl,--gc-sections"])
726498e
 AC_TRY_LINK([
726498e
--- a/dbus/Makefile.am
726498e
+++ b/dbus/Makefile.am
726498e
@@ -1,7 +1,7 @@
726498e
 
726498e
 configdir=$(sysconfdir)/dbus-1
726498e
 
726498e
-INCLUDES=-I$(top_builddir) -I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) -DDBUS_COMPILATION	\
726498e
+INCLUDES=-I$(top_builddir) -I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) @PIC_CFLAGS@ -DDBUS_COMPILATION	\
726498e
 	-DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\"		\
726498e
 	-DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\"			\
726498e
 	-DDBUS_SESSION_CONFIG_FILE=\""$(configdir)/session.conf"\"
726498e
@@ -173,7 +173,7 @@ noinst_LTLIBRARIES=libdbus-convenience.l
726498e
 libdbus_1_la_LIBADD= $(DBUS_CLIENT_LIBS)
726498e
 ## don't export symbols that start with "_" (we use this 
726498e
 ## convention for internal symbols)
726498e
-libdbus_1_la_LDFLAGS= -export-symbols-regex "^[^_].*" -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -no-undefined @R_DYNAMIC_LDFLAG@
726498e
+libdbus_1_la_LDFLAGS= -export-symbols-regex "^[^_].*" -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -no-undefined @R_DYNAMIC_LDFLAG@ @PIC_LDFLAGS@
726498e
 
726498e
 libdbus_convenience_la_LDFLAGS=@R_DYNAMIC_LDFLAG@
726498e