Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,16 @@ Debug options

.. versionadded:: 3.6

.. option:: --with-hwaddress-sanitizer

Enable HWAddressSanitizer memory error detector, ``hwasan`` (default is no).
Note that on x86-64 this uses `page aliasing
<https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#supported-architectures>`_,
which only tags heap allocations and is unsafe for programs that ``fork()``,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think implicitly this means "Do not use on x86-64", right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much, you could try using it if you're careful (as such it's an option).

including much of the test suite.

.. versionadded:: 3.16

.. option:: --with-memory-sanitizer

Enable MemorySanitizer allocation error detector, ``msan`` (default is no).
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,11 @@ Build changes

(Contributed by Stan Ulbrych in :gh:`139314`.)

* Add the :option:`--with-hwaddress-sanitizer` :program:`configure` option to
build with `HWAddressSanitizer <https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html>`_.

(Contributed by Stan Ulbrych, Florian Mayer and AnnaAr321 in :gh:`156049`.)


C API changes
=============
Expand Down
9 changes: 9 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ extern "C" {
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
# endif
# endif
# if __has_feature(hwaddress_sanitizer)
# if !defined(_Py_ADDRESS_SANITIZER)
# define _Py_ADDRESS_SANITIZER
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("hwaddress")))
# endif
# endif
# if __has_feature(thread_sanitizer)
# if !defined(_Py_THREAD_SANITIZER)
# define _Py_THREAD_SANITIZER
Expand All @@ -572,6 +578,9 @@ extern "C" {
# if defined(__SANITIZE_ADDRESS__)
# define _Py_ADDRESS_SANITIZER
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
# elif defined(__SANITIZE_HWADDRESS__)
# define _Py_ADDRESS_SANITIZER
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("hwaddress")))
# endif
# if defined(__SANITIZE_THREAD__)
# define _Py_THREAD_SANITIZER
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ def check_sanitizer(*, address=False, memory=False, ub=False, thread=False,
)
address_sanitizer = (
'-fsanitize=address' in cflags or
'--with-address-sanitizer' in config_args
'-fsanitize=hwaddress' in cflags or
'--with-address-sanitizer' in config_args or
'--with-hwaddress-sanitizer' in config_args
)
ub_sanitizer = (
'-fsanitize=undefined' in cflags or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :option:`--with-hwaddress-sanitizer` to build with `HWAddressSanitizer
<https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html>`_.
79 changes: 79 additions & 0 deletions configure

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

24 changes: 24 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3533,6 +3533,30 @@ with_pymalloc="no"
],
[AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for --with-hwaddress-sanitizer])
AC_ARG_WITH(
[hwaddress_sanitizer],
[AS_HELP_STRING(
[--with-hwaddress-sanitizer],
[enable HWAddressSanitizer memory error detector, 'hwasan' (default is no)]
)],
[
AC_MSG_RESULT([$withval])
hwasan_flags="-fsanitize=hwaddress"
# x86-64 lacks address tagging, so HWASan needs the page aliasing mode there.
# See https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#supported-architectures
AS_CASE([$host_cpu],
[x86_64|amd64], [hwasan_flags="$hwasan_flags -fsanitize-hwaddress-experimental-aliasing"]
)
AX_CHECK_COMPILE_FLAG([$hwasan_flags],[
BASECFLAGS="$hwasan_flags -fno-omit-frame-pointer $BASECFLAGS"
LDFLAGS="$hwasan_flags $LDFLAGS"
],[AC_MSG_ERROR([The selected compiler doesn't support hardware address sanitizer])])
# HWASan works by controlling memory allocation, our own malloc interferes.
with_pymalloc="no"
],
[AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for --with-memory-sanitizer])
AC_ARG_WITH(
[memory_sanitizer],
Expand Down
Loading