Skip to contentSkip to conversation

make automount daemon a PIE

PATCH New Jeff Moyer 1 participant 1 message Mar 24, 2004

Subsystems (2)
lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 make automount daemon a PIE

Hello,

Uli Drepper suggested making automount a position independent executable. Here is a patch which does so on systems with compilers that support it.

Ian, I didn't include generated files (ala configure and Makefile.conf) for obvious reasons.

Cheers,

Jeff

Makefile.conf.in +4 -0
diff --exclude configure --exclude Makefile.conf -urp autofs-4.1.1.orig/Makefile.conf.in autofs-4.1.1/Makefile.conf.in
@@ -7,6 +7,10 @@
 # build autofs.
 #
 
+# Do we build with -fpie?
+DAEMON_CFLAGS  = @DAEMON_CFLAGS@
+DAEMON_LDFLAGS = @DAEMON_LDFLAGS@
+
 # Special parameters for glibc (libc 6)
 LIBNSL    = @LIBNSL@
 LIBRESOLV = @LIBRESOLV@
configure.in +21 -0
diff --exclude configure --exclude Makefile.conf -urp autofs-4.1.1.orig/configure.in autofs-4.1.1/configure.in
@@ -126,6 +126,27 @@ AC_SUBST(LIBLDAP)
 LDFLAGS="${AF_tmp_ldflags}"
 
 #
+# Does gcc support building position independent executables?
+#
+AC_PROG_CC
+cat > pietest.c <<EOF
+int main(void) { return 0; }
+EOF
+CFLAGS=-fpie
+DAEMON_CFLAGS=
+DAEMON_LDFLAGS=
+AC_MSG_CHECKING([whether gcc accepts -fpie])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[int main(void) {return 0;}]])],
+		  [gcc_supports_pie=yes], [gcc_supports_pie=no])
+AC_MSG_RESULT([$gcc_supports_pie])
+if test $gcc_supports_pie = yes ; then
+	DAEMON_CFLAGS="-fpie"
+	DAEMON_LDFLAGS="-pie"
+fi
+AC_SUBST(DAEMON_CFLAGS)
+AC_SUBST(DAEMON_LDFLAGS)
+
+#
 # Location of init.d directory?
 #
 AF_INIT_D()
daemon/Makefile +2 -2
diff --exclude configure --exclude Makefile.conf -urp autofs-4.1.1.orig/daemon/Makefile autofs-4.1.1/daemon/Makefile
@@ -11,14 +11,14 @@ OBJS = automount.o spawn.o module.o moun
 
 version := $(shell cat ../.version)
 
-CFLAGS += -rdynamic -DAUTOFS_LIB_DIR=\"$(autofslibdir)\" -DVERSION_STRING=\"$(version)\" -I../include
+CFLAGS += -rdynamic $(DAEMON_CFLAGS) -DAUTOFS_LIB_DIR=\"$(autofslibdir)\" -DVERSION_STRING=\"$(version)\" -I../include
 LDFLAGS += -rdynamic
 LIBS = -ldl
 
 all: automount
 
 automount: $(OBJS) $(AUTOFS_LIB)
-	$(CC) $(LDFLAGS) -o automount $(OBJS) $(AUTOFS_LIB) $(LIBS)
+	$(CC) $(LDFLAGS) $(DAEMON_LDFLAGS) -o automount $(OBJS) $(AUTOFS_LIB) $(LIBS)
 	$(STRIP) automount
 
 clean: