make automount daemon a PIE
Subsystems (2)
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
@@ -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
@@ -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
@@ -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: