Skip to content

Commit

Permalink
pythongh-109575: Don't export -fsanitize compiler options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner committed Sep 19, 2023
1 parent 67d9363 commit 5d039d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand All @@ -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"
Expand All @@ -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"
],
[
Expand Down

0 comments on commit 5d039d7

Please sign in to comment.