On Wed, Feb 04, 2015 at 01:12:16PM -0500, Wietse Venema wrote: > Very lighty-tested patch follows. No INSTALL documentation until > this has been tested. > > Usage: $ make makefiles pie=yes ...
Works on NETBSD6, with: pie=yes shared=yes dynamicmaps=yes pie=yes shared=no dynamicmaps=no I also tested with a variant patch which uses "-fPIE" rather than "-fPIC" to compile the object files when shared=no, because these all end up in executables, rather than shared libraries. Rumour has it that's the "more correct" thing to do in that case. This also worked on NETBSD6. Slightly modified patch below (note the " $CCARGS " to also match leading or trailing -fPI[CE]) -- Viktor. diff --git a/makedefs b/makedefs index f7be08c..618634d 100644 --- a/makedefs +++ b/makedefs @@ -105,6 +105,13 @@ # "dynamicmaps=yes" implicitly enables Postfix shared libraries. # # This feature was introduced with Postfix 3.0. +# .IP \fBpie=yes\fR +# .IP \fBpie=no\fR +# +# Enable (disable) Postfix builds with position-independent +# executables, on platforms where this is supported. +# +# This feature was introduced with Postfix 3.1. # .IP \fIinstallation_parameter\fB=\fIvalue\fR... # Override the compiled-in default value of the specified # installation parameter(s). The following parameters are @@ -142,6 +149,7 @@ echo "# CCARGS=$CCARGS" echo "# AUXLIBS=$AUXLIBS" env | grep '^AUXLIBS_' | sed 's/^/# /' echo "# dynamicmaps=$dynamicmaps" +echo "# pie=$pie" # Defaults for most sane systems @@ -1082,6 +1090,24 @@ yes) SHLIB_SYSLIBS=`${AWK} ' '` esac +# Choose between PIE and non-PIE builds. + +case "$pie" in + yes) + case $shared in + yes) CCARGS_PIE="-fPIC" ;; + *) CCARGS_PIE="-fPIE" ;; + esac + case " $CCARGS " in + *" $CCARGS_PIE "*) CCARGS_PIE= ;; + *) ;; + esac + SYSLIBS_PIE="-pie";; +""|no) ;; + *) error "Specify \"pie=yes\" or \"pie=no\"";; +esac + + # Finally... sed 's/ */ /g' <<EOF @@ -1090,8 +1116,8 @@ SYSTYPE = $SYSTYPE _AR = $_AR ARFL = $ARFL _RANLIB = $_RANLIB -SYSLIBS = $AUXLIBS $SYSLIBS $PLUGIN_AUXLIBS -CC = $CC $CCARGS \$(WARN) +SYSLIBS = $SYSLIBS_PIE $AUXLIBS $SYSLIBS $PLUGIN_AUXLIBS +CC = $CC $CCARGS_PIE $CCARGS \$(WARN) OPT = $OPT DEBUG = $DEBUG AWK = $AWK