Skip to content

Commit a9da37c

Browse files
committed
gh-109575: Don't export -fsanitize compiler options
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. Makefile.pre.in: PY_LDFLAGS_NOLTO now uses PY_LDFLAGS_NODIST, instead of LDFLAGS_NODIST, and add CONFIGURE_LDFLAGS_NOLTO after PY_LDFLAGS_NODIST.
1 parent 67d9363 commit a9da37c

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

Makefile.pre.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include
107107
PY_CPPFLAGS= $(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
108108
PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS)
109109
PY_LDFLAGS_NODIST=$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST)
110-
PY_LDFLAGS_NOLTO=$(PY_LDFLAGS) $(CONFIGURE_LDFLAGS_NOLTO) $(LDFLAGS_NODIST)
110+
PY_LDFLAGS_NOLTO=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST) $(CONFIGURE_LDFLAGS_NOLTO)
111111
NO_AS_NEEDED= @NO_AS_NEEDED@
112112
CCSHARED= @CCSHARED@
113113
# LINKFORSHARED are the flags passed to the $(CC) command that links
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
When Python is configured to use ASAN, MSAN or UBSAN sanitizer, with
2+
``./configure --with-address-sanitizer`` for example, compiler and linker
3+
flags for sanitizers are no longer exported to third party C extensions. Add
4+
flags to ``CFLAGS_NODIST`` and ``LDFLAGS_NODIST``, instead of ``BASECFLAGS``
5+
and ``LDFLAGS``. Patch by Victor Stinner.

configure

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+6-6
Original file line numberDiff line numberDiff line change
@@ -2997,8 +2997,8 @@ AC_ARG_WITH([address_sanitizer],
29972997
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
29982998
[
29992999
AC_MSG_RESULT([$withval])
3000-
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
3001-
LDFLAGS="-fsanitize=address $LDFLAGS"
3000+
CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=address -fno-omit-frame-pointer"
3001+
LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=address"
30023002
# ASan works by controlling memory allocation, our own malloc interferes.
30033003
with_pymalloc="no"
30043004
],
@@ -3014,8 +3014,8 @@ AC_ARG_WITH(
30143014
[
30153015
AC_MSG_RESULT([$withval])
30163016
AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
3017-
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
3018-
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
3017+
CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer"
3018+
LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=memory -fsanitize-memory-track-origins=2"
30193019
],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
30203020
# MSan works by controlling memory allocation, our own malloc interferes.
30213021
with_pymalloc="no"
@@ -3031,8 +3031,8 @@ AC_ARG_WITH(
30313031
)],
30323032
[
30333033
AC_MSG_RESULT([$withval])
3034-
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
3035-
LDFLAGS="-fsanitize=undefined $LDFLAGS"
3034+
CFLAGS_NODIST="$CFLAGS_NODIST -fsanitize=undefined"
3035+
LDFLAGS_NODIST="$LDFLAGS_NODIST -fsanitize=undefined"
30363036
with_ubsan="yes"
30373037
],
30383038
[

0 commit comments

Comments
 (0)