Correctly implement -fPIC and -fPIE
authorJohn (J5) Palmieri <johnp@redhat.com>
Wed, 3 Oct 2007 19:21:57 +0000 (15:21 -0400)
committerJohn (J5) Palmieri <johnp@redhat.com>
Wed, 3 Oct 2007 19:21:57 +0000 (15:21 -0400)
* For security reasons we want possition independent code for libraries
  and possition independent executable for executables
* before we were just enabling -fPIC
* now we correctly enable -fPIC and -PIE for libdbus and the bus respectively
* propper LD_FLAGS are set for each also

bus/Makefile.am
configure.in
dbus/Makefile.am

index d521fa7..4648a31 100644 (file)
@@ -1,7 +1,7 @@
 
 configdir=$(sysconfdir)/dbus-1
 
-INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS)                            \
+INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) @PIE_CFLAGS@               \
        -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\"        \
        -DDAEMON_NAME=\"dbus-daemon\"  -DDBUS_COMPILATION
 
@@ -77,7 +77,7 @@ dbus_daemon_LDADD=                                    \
        $(DBUS_BUS_LIBS)                                \
        $(top_builddir)/dbus/libdbus-convenience.la
 
-dbus_daemon_LDFLAGS=@R_DYNAMIC_LDFLAG@ @SECTION_LDFLAGS@
+dbus_daemon_LDFLAGS=@R_DYNAMIC_LDFLAG@ @SECTION_LDFLAGS@ @PIE_LDFLAGS@
 
 LAUNCH_HELPER_SOURCES=                         \
        $(XML_SOURCES)                          \
index 3dcd8bc..ee0d40b 100644 (file)
@@ -211,7 +211,17 @@ if test "x$GCC" = "xyes"; then
   case " $CFLAGS " in
   *[\ \        ]-fPIC[\ \      ]*) ;;
   *) if cc_supports_flag -fPIC; then
-        CFLAGS="$CFLAGS -fPIC"
+        PIC_CFLAGS="-fPIC"
+        PIC_LDFLAGS="-Wl,-z,relro"
+     fi
+     ;;
+  esac
+
+  case " $CFLAGS " in
+  *[\ \        ]-fPIE[\ \      ]*) ;;
+  *) if cc_supports_flag -fPIE; then
+        PIE_CFLAGS="-fPIE"
+        PIE_LDFLAGS="-pie -Wl,-z,relro"
      fi
      ;;
   esac
@@ -257,6 +267,11 @@ else
   fi
 fi
 
+AC_SUBST(PIC_CFLAGS)
+AC_SUBST(PIC_LDFLAGS)  
+AC_SUBST(PIE_CFLAGS)
+AC_SUBST(PIE_LDFLAGS)  
+
 # Check for -Wl,--gc-sections
 AC_MSG_CHECKING([for ld that supports "-Wl,--gc-sections"])
 AC_TRY_LINK([
index 81f90b9..e966a43 100644 (file)
@@ -1,7 +1,7 @@
 
 configdir=$(sysconfdir)/dbus-1
 
-INCLUDES=-I$(top_builddir) -I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) -DDBUS_COMPILATION    \
+INCLUDES=-I$(top_builddir) -I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) @PIC_CFLAGS@ -DDBUS_COMPILATION       \
        -DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\"             \
        -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\"                        \
        -DDBUS_SESSION_CONFIG_FILE=\""$(configdir)/session.conf"\"
@@ -173,7 +173,7 @@ noinst_LTLIBRARIES=libdbus-convenience.la
 libdbus_1_la_LIBADD= $(DBUS_CLIENT_LIBS)
 ## don't export symbols that start with "_" (we use this 
 ## convention for internal symbols)
-libdbus_1_la_LDFLAGS= -export-symbols-regex "^[^_].*" -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -no-undefined @R_DYNAMIC_LDFLAG@
+libdbus_1_la_LDFLAGS= -export-symbols-regex "^[^_].*" -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -no-undefined @R_DYNAMIC_LDFLAG@ @PIC_LDFLAGS@
 
 libdbus_convenience_la_LDFLAGS=@R_DYNAMIC_LDFLAG@