Add support for -fstack-protector in native builds

-fstack-protector only needs a small amount of runtime
support to work on native builds. It increases code size
by ~1.5% on ARM/MIPS; -fstack-protector-strong adds 3-4%.
This is disabled by default and must be enabled by passing
'--with-stack-protector' to configure.

Change-Id: If952e711d3673c9b469895f08c7bff70b3d95df6
This commit is contained in:
Aidan MacDonald 2026-04-21 14:33:58 +01:00 committed by Solomon Peachy
parent 9ac6edf750
commit d815053360
5 changed files with 68 additions and 0 deletions

17
tools/configure vendored
View file

@ -1531,6 +1531,9 @@ help() {
--with-address-sanitizer
Enables the AddressSanitizer feature. Forces SDL threads.
--with-ubsan Enables the UB Sanitizer feature. Forces SDL threads.
--with-stack-protector[=MODE]
Enable -fstack-protector-MODE option. With no MODE,
enables the normal -fstack-protector option.
--32-bit Force a 32-bit simulator (use with --sdl-threads for duke3d)
--prefix Target installation directory
--compiler-prefix Override compiler prefix (inherently dangerous)
@ -1557,6 +1560,7 @@ ARG_THREAD_SUPPORT=
ARG_32BIT=
ARG_ADDR_SAN=
ARG_UBSAN=
ARG_STACK_PROTECTOR=
ARG_PLUGINS=
err=
for arg in "$@"; do
@ -1583,6 +1587,8 @@ for arg in "$@"; do
ARG_THREAD_SUPPORT=0;;
--with-address-sanitizer) ARG_ADDR_SAN=1;;
--with-ubsan) ARG_UBSAN=1;;
--with-stack-protector=*) ARG_STACK_PROTECTOR=`echo "$arg" | cut -d = -f 2`;;
--with-stack-protector) ARG_STACK_PROTECTOR=default;;
--prefix=*) ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;;
--compiler-prefix=*) ARG_COMPILER_PREFIX=`echo "$arg" | cut -d = -f 2`;;
--help) help;;
@ -4694,6 +4700,17 @@ if [ "$ARG_RBDIR" != "" ]; then
echo "Using alternate rockbox dir: ${rbdir}"
fi
if [ "$ARG_STACK_PROTECTOR" != "" ]; then
echo "Stack protector mode: $ARG_STACK_PROTECTOR"
extradefines="$extradefines -DUSE_STACK_PROTECTOR"
if [ "$ARG_STACK_PROTECTOR" = "default" ]; then
GCCOPTS="$GCCOPTS -fstack-protector"
else
GCCOPTS="$GCCOPTS -fstack-protector-${ARG_STACK_PROTECTOR}"
fi
fi
cat > autoconf.h.new <<EOF
/* This header was made by configure */
#ifndef __BUILD_AUTOCONF_H