diff --git a/common/environment/configure/gccspecs/hardened-mips-cc1 b/common/environment/configure/gccspecs/hardened-mips-cc1 new file mode 100644 index 00000000000..41e40b98022 --- /dev/null +++ b/common/environment/configure/gccspecs/hardened-mips-cc1 @@ -0,0 +1,8 @@ +*cpp_options: ++ %{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE -mshared}}}}} + +*cc1_options: ++ %{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE -mshared}}}}} + +*asm_options: ++ %{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-mshared}}}}} diff --git a/common/environment/configure/hardening.sh b/common/environment/configure/hardening.sh index a519efce585..890471de2bb 100644 --- a/common/environment/configure/hardening.sh +++ b/common/environment/configure/hardening.sh @@ -1,27 +1,26 @@ # Enable SSP and FORITFY_SOURCE=2 by default. -CFLAGS=" -fstack-protector-strong -D_FORTIFY_SOURCE=2 $CFLAGS" -CXXFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 $CXXFLAGS" +_CFLAGS=" -fstack-protector-strong -D_FORTIFY_SOURCE=2 ${CFLAGS}" +_CXXFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 ${CXXFLAGS}" # Enable as-needed and relro by default. -LDFLAGS="-Wl,--as-needed -Wl,-z,relro $LDFLAGS" +_LDFLAGS="-Wl,--as-needed ${LDFLAGS}" case "$XBPS_TARGET_MACHINE" in i686-musl) # SSP currently broken (see https://github.com/voidlinux/void-packages/issues/2902) - CFLAGS+=" -fno-stack-protector" - CXXFLAGS+=" -fno-stack-protector" + _CFLAGS+=" -fno-stack-protector" + _CXXFLAGS+=" -fno-stack-protector" ;; esac if [ -z "$nopie" ]; then - case "$XBPS_TARGET_MACHINE" in - mips*) - # XXX for some reason the gcc specs does not apply correctly - CFLAGS+=" -fPIE" - CXXFLAGS+=" -fPIE" - ;; - esac _GCCSPECSDIR=${XBPS_COMMONDIR}/environment/configure/gccspecs - CFLAGS="-specs=${_GCCSPECSDIR}/hardened-cc1 $CFLAGS" - CXXFLAGS="-specs=${_GCCSPECSDIR}/hardened-cc1 $CXXFLAGS" + case "$XBPS_TARGET_MACHINE" in + mips*) _GCCSPECSFILE=${_GCCSPECSDIR}/hardened-mips-cc1;; + *) _GCCSPECSFILE=${_GCCSPECSDIR}/hardened-cc1;; + esac + CFLAGS="-specs=${_GCCSPECSFILE} ${_CFLAGS}" + CXXFLAGS="-specs=${_GCCSPECSFILE} ${_CXXFLAGS}" # We pass -z relro -z now here too, because libtool drops -specs... - LDFLAGS="-specs=${_GCCSPECSDIR}/hardened-ld -Wl,-z,relro -Wl,-z,now $LDFLAGS" + LDFLAGS="-specs=${_GCCSPECSDIR}/hardened-ld -Wl,-z,relro -Wl,-z,now ${_LDFLAGS}" fi + +unset _CFLAGS _CXXFLAGS _LDFLAGS