diff --git a/Makefile.pre.in b/Makefile.pre.in index 7b03dd233e62318..20169b0d627dcad 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -107,7 +107,7 @@ PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include PY_CPPFLAGS= $(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS) PY_LDFLAGS_NODIST=$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST) -PY_LDFLAGS_NOLTO=$(PY_LDFLAGS) $(CONFIGURE_LDFLAGS_NOLTO) $(LDFLAGS_NODIST) +PY_LDFLAGS_NOLTO=$(PY_LDFLAGS) $(CONFIGURE_LDFLAGS_NOLTO) $(PY_LDFLAGS_NODIST) NO_AS_NEEDED= @NO_AS_NEEDED@ CCSHARED= @CCSHARED@ # LINKFORSHARED are the flags passed to the $(CC) command that links diff --git a/Misc/NEWS.d/next/Build/2023-09-19-16-32-56.gh-issue-109575.41o1jt.rst b/Misc/NEWS.d/next/Build/2023-09-19-16-32-56.gh-issue-109575.41o1jt.rst new file mode 100644 index 000000000000000..783060acc99c0c3 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-09-19-16-32-56.gh-issue-109575.41o1jt.rst @@ -0,0 +1,5 @@ +When Python is configured to use ASAN, MSAN or UBSAN sanitizer, with +``./configure --with-address-sanitizer`` for example, compiler and linker +flags for sanitizers are no longer exported to third party C extensions. Add +flags to ``CFLAGS_NODIST`` and ``LDFLAGS_NODIST``, instead of ``BASECFLAGS`` +and ``LDFLAGS``. Patch by Victor Stinner. diff --git a/configure b/configure index 17b9e7f532a827a..6aa0e377d5e92a1 100755 --- a/configure +++ b/configure @@ -12357,8 +12357,8 @@ then : withval=$with_address_sanitizer; { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5 printf "%s\n" "$withval" >&6; } -BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=address $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=address -fno-omit-frame-pointer" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=address" # ASan works by controlling memory allocation, our own malloc interferes. with_pymalloc="no" @@ -12411,8 +12411,8 @@ printf "%s\n" "$ax_cv_check_cflags___fsanitize_memory" >&6; } if test "x$ax_cv_check_cflags___fsanitize_memory" = xyes then : -BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2" else $as_nop as_fn_error $? "The selected compiler doesn't support memory sanitizer" "$LINENO" 5 @@ -12436,8 +12436,8 @@ then : withval=$with_undefined_behavior_sanitizer; { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5 printf "%s\n" "$withval" >&6; } -BASECFLAGS="-fsanitize=undefined $BASECFLAGS" -LDFLAGS="-fsanitize=undefined $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=undefined" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=undefined" with_ubsan="yes" else $as_nop diff --git a/configure.ac b/configure.ac index 34958a1cdf15286..10b352441da041f 100644 --- a/configure.ac +++ b/configure.ac @@ -2997,8 +2997,8 @@ AC_ARG_WITH([address_sanitizer], [enable AddressSanitizer memory error detector, 'asan' (default is no)]), [ AC_MSG_RESULT([$withval]) -BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=address $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=address -fno-omit-frame-pointer" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=address" # ASan works by controlling memory allocation, our own malloc interferes. with_pymalloc="no" ], @@ -3014,8 +3014,8 @@ AC_ARG_WITH( [ AC_MSG_RESULT([$withval]) AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[ -BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2" ],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])]) # MSan works by controlling memory allocation, our own malloc interferes. with_pymalloc="no" @@ -3031,8 +3031,8 @@ AC_ARG_WITH( )], [ AC_MSG_RESULT([$withval]) -BASECFLAGS="-fsanitize=undefined $BASECFLAGS" -LDFLAGS="-fsanitize=undefined $LDFLAGS" +CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=undefined" +LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=undefined" with_ubsan="yes" ], [