https://github.com/legionus/kbd/pull/103 From 3392e2038dee97361d7438512653736d72a02109 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 4 Oct 2023 14:47:33 +0100 Subject: [PATCH] Use `AX_ADD_FORTIFY_SOURCE` to avoid redefining `_FORTIFY_SOURCE` Some distributions are now setting -D_FORTIFY_SOURCE=3 by default in their toolchains rather than _F_S=2. By forcing _F_S=2, this causes both a warning and a downgrade in the effective protection. Use the autoconf-archive macro for this purpose (AX_ADD_FORTIFY_SOURCE) to add the fortification at the highest supported level if the compiler doesn't already default to it. Bug: https://bugs.gentoo.org/892834 Signed-off-by: Sam James --- configure.ac | 5 +- m4/ax_add_fortify_source.m4 | 119 ++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 m4/ax_add_fortify_source.m4 diff --git a/configure.ac b/configure.ac index 66023ff8..7fdbe7d6 100644 --- a/configure.ac +++ b/configure.ac @@ -63,13 +63,14 @@ strspn strstr strtol strtoul setpgrp malloc realloc]) AC_SEARCH_LIBS([timer_create], [rt]) +AX_ADD_FORTIFY_SOURCE + # Optimization level CC_O_LEVEL="-O2" -FORTIFY_SOURCE="-D_FORTIFY_SOURCE=2" if test "$enable_code_coverage" = yes; then CC_O_LEVEL="-O0" - FORTIFY_SOURCE= + FORTIFY_SOURCE="-U_FORTIFY_SOURCE" fi case "$GCC,$ac_cv_prog_cc_g" in