aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-04-30 15:00:14 +0900
committerKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-04-30 15:53:44 +0900
commit75e62709f161d4f5f2bc1202bb7e4e906b4aaa91 (patch)
treefd1a0a141dd8c64031d807a3898ee2f60f8efcaf
parentb56b582a049d194a14064b36212f81645deeec22 (diff)
downloadportable-75e62709f161d4f5f2bc1202bb7e4e906b4aaa91.tar.gz
portable-75e62709f161d4f5f2bc1202bb7e4e906b4aaa91.tar.bz2
portable-75e62709f161d4f5f2bc1202bb7e4e906b4aaa91.zip
Do not override user CFLAGS/LDFLAGS in hardening flag detection
`CHECK_CFLAG` / `CHECK_LDFLAG` overwrote `CFLAGS`/`LDFLAGS` with only the flag under test, so feature detection ran with a different target than the real build. For example `CFLAGS=-march=i586 ./configure` accepted `-fcf-protection=full` (detected under the toolchain's i686 default) but then failed to compile because GCC 15 rejects `-fcf-protection` on i586. Prepend `$USER_CFLAGS` / `$USER_LDFLAGS` (saved before `AC_PROG_CC`) to the detection command so the probe matches the real build. Fixes #1268
-rw-r--r--configure.ac1
-rw-r--r--m4/check-hardening-options.m44
2 files changed, 3 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index eb2b9ce..c0ad033 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
26 26
27# This must be saved before AC_PROG_CC 27# This must be saved before AC_PROG_CC
28USER_CFLAGS="$CFLAGS" 28USER_CFLAGS="$CFLAGS"
29USER_LDFLAGS="$LDFLAGS"
29 30
30AC_PROG_CC([cc gcc]) 31AC_PROG_CC([cc gcc])
31AM_PROG_CC_C_O 32AM_PROG_CC_C_O
diff --git a/m4/check-hardening-options.m4 b/m4/check-hardening-options.m4
index 2cb3083..401b7e4 100644
--- a/m4/check-hardening-options.m4
+++ b/m4/check-hardening-options.m4
@@ -3,7 +3,7 @@ AC_DEFUN([CHECK_CFLAG], [
3 AC_LANG_ASSERT(C) 3 AC_LANG_ASSERT(C)
4 AC_MSG_CHECKING([if $saved_CC supports "$1"]) 4 AC_MSG_CHECKING([if $saved_CC supports "$1"])
5 old_cflags="$CFLAGS" 5 old_cflags="$CFLAGS"
6 CFLAGS="$1 -Wall -Werror" 6 CFLAGS="$USER_CFLAGS $1 -Wall -Werror"
7 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[printf("Hello")]])], 7 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[printf("Hello")]])],
8 [AC_MSG_RESULT([yes]) 8 [AC_MSG_RESULT([yes])
9 CFLAGS=$old_cflags 9 CFLAGS=$old_cflags
@@ -17,7 +17,7 @@ AC_DEFUN([CHECK_LDFLAG], [
17 AC_LANG_ASSERT(C) 17 AC_LANG_ASSERT(C)
18 AC_MSG_CHECKING([if $saved_LD supports "$1"]) 18 AC_MSG_CHECKING([if $saved_LD supports "$1"])
19 old_ldflags="$LDFLAGS" 19 old_ldflags="$LDFLAGS"
20 LDFLAGS="$1 -Wall -Werror" 20 LDFLAGS="$USER_LDFLAGS $1 -Wall -Werror"
21 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[printf("Hello")]])], 21 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[printf("Hello")]])],
22 [AC_MSG_RESULT([yes]) 22 [AC_MSG_RESULT([yes])
23 LDFLAGS=$old_ldflags 23 LDFLAGS=$old_ldflags