Skip to content

Commit

Permalink
[build] Add -fstack-clash-protection to release builds
Browse files Browse the repository at this point in the history
CentOS Stream CI insists on this but it's generally a 'good thing'
  • Loading branch information
chrissie-c authored and fabbione committed May 18, 2021
1 parent 6d99a84 commit 29dbe46
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions configure.ac
Expand Up @@ -32,7 +32,6 @@ AX_CHECK_LINK_FLAG([-Wl,--enable-new-dtags],
[AC_MSG_ERROR(["Linker support for --enable-new-dtags is required"])])
AX_CHECK_LINK_FLAG([-Wl,--as-needed], [AM_LDFLAGS="$AM_LDFLAGS -Wl,--as-needed"])

AC_SUBST([AM_LDFLAGS])
saved_LDFLAGS="$LDFLAGS"
LDFLAGS="$AM_LDFLAGS $LDFLAGS"
LT_INIT
Expand Down Expand Up @@ -173,6 +172,23 @@ AC_ARG_ENABLE([libnozzle],

AM_CONDITIONAL([BUILD_LIBNOZZLE], [test x$enable_libnozzle = xyes])

## local helper functions
# this function checks if CC support options passed as
# args. Global CPPFLAGS are ignored during this test.
cc_supports_flag() {
saveCPPFLAGS="$CPPFLAGS"
CPPFLAGS="$@"
if echo $CC | grep -q clang; then
CPPFLAGS="-Werror $CPPFLAGS"
fi
AC_MSG_CHECKING([whether $CC supports "$@"])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[RC=0; AC_MSG_RESULT([yes])],
[RC=1; AC_MSG_RESULT([no])])
CPPFLAGS="$saveCPPFLAGS"
return $RC
}

# Checks for libraries.
AX_PTHREAD(,[AC_MSG_ERROR([POSIX threads support is required])])
saved_LIBS="$LIBS"
Expand Down Expand Up @@ -282,6 +298,10 @@ fi
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],[enable debug build])])

AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--disable-hardening],[disable hardening build flags])],,
[ enable_hardening="yes" ])

AC_ARG_WITH([sanitizers],
[AS_HELP_STRING([--with-sanitizers=...,...],
[enable SANitizer build, do *NOT* use for production. Only ASAN/UBSAN/TSAN are currently supported])],
Expand All @@ -297,6 +317,32 @@ AC_ARG_WITH([testdir],

AC_SUBST([TESTDIR])

# Check for availablility of hardening options

if echo $CC | grep -q gcc; then
ANNOPLUGIN="-fplugin=annobin"
fi

HARDENING_CFLAGS_ANNOCHECK="$ANNOPLUGIN -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fexceptions -D_GLIBCXX_ASSERTIONS -Wl,-z,now"
HARDENING_CFLAGS="-fstack-clash-protection -fcf-protection=full -mcet -mstackrealign"
EXTRA_HARDENING_CFLAGS=""
if test "x${enable_hardening}" = xyes; then
annocheck=yes
for j in $HARDENING_CFLAGS_ANNOCHECK; do
if cc_supports_flag $j; then
EXTRA_HARDENING_CFLAGS="$EXTRA_HARDENING_CFLAGS $j"
else
annocheck=no
fi
done
for j in $HARDENING_CFLAGS; do
if cc_supports_flag $j; then
EXTRA_HARDENING_CFLAGS="$EXTRA_HARDENING_CFLAGS $j"
fi
done
AM_LDFLAGS="$AM_LDFLAGS $EXTRA_HARDENING_CFLAGS"
fi

# debug build stuff
if test "x${enable_debug}" = xyes; then
AC_DEFINE_UNQUOTED([DEBUG], [1], [Compiling Debugging code])
Expand All @@ -307,9 +353,9 @@ fi

# gdb flags
if test "x${GCC}" = xyes; then
GDB_FLAGS="-ggdb3"
GDB_CFLAGS="-ggdb3"
else
GDB_FLAGS="-g"
GDB_CFLAGS="-g"
fi

# --- ASAN/UBSAN/TSAN (see man gcc) ---
Expand Down Expand Up @@ -348,8 +394,9 @@ DEFAULT_CFLAGS="-Werror -Wall -Wextra"
# generates too much noise for stub APIs
UNWANTED_CFLAGS="-Wno-unused-parameter"

AC_SUBST([AM_CFLAGS],["$SANITIZERS_CFLAGS $OPT_CFLAGS $GDB_FLAGS $DEFAULT_CFLAGS $UNWANTED_CFLAGS"])
AC_SUBST([AM_CFLAGS],["$SANITIZERS_CFLAGS $OPT_CFLAGS $GDB_CFLAGS $DEFAULT_CFLAGS $EXTRA_HARDENING_CFLAGS $UNWANTED_CFLAGS"])
LDFLAGS="$SANITIZERS_LDFLAGS $LDFLAGS"
AC_SUBST([AM_LDFLAGS])

AX_PROG_DATE
AS_IF([test "$ax_cv_prog_date_gnu_date:$ax_cv_prog_date_gnu_utc" = yes:yes],
Expand Down

0 comments on commit 29dbe46

Please sign in to comment.