https://github.com/python/cpython/commit/cce38eefd4b8f4e90eaa40ebfda64cb5ffde679f
commit: cce38eefd4b8f4e90eaa40ebfda64cb5ffde679f
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2025-07-20T10:55:06+02:00
summary:

[3.14] Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan 
information (GH-136790) (GH-136798)

Extend the documentation for disabling pymalloc with the `--without-pymalloc` 
flag regarding why it is worth to use it when enabling AddressSanitizer for 
Python build (which is done, e.g., in CPython's CI builds).

I have tested the CPython latest main build with both ASan and pymalloc enabled 
and it seems to work just fine. I did run the `python -m test` suite which 
didn't uncover any ASan crashes (though, it detected some memory leaks, which I 
believe are irrelevant here).

I have discussed ASan and this flag with @encukou on the CPython Core sprint on 
EuroPython 2025. We initially thought that the `--without-pymalloc` flag is 
needed for ASan builds due to the fact pymalloc must hit the begining of page 
when determining if the memory to be freed comes from pymalloc or was allocated 
by the system malloc. In other words, we thought, that ASan would crash CPython 
during free of big objects (allocated by system malloc). It may be that this 
was the case in the past, but it is not the case anymore as the 
`address_in_range` function used by pymalloc is annotated to be skipped from 
the ASan instrumentation.


(cherry picked from commit d19bb4471331ca2cb87b86e4c904bc9a2bafb044)

Co-authored-by: Disconnect3d <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>

files:
M Doc/c-api/memory.rst
M Doc/using/configure.rst

diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst
index 61fa49f8681cce..df1bb0ce370919 100644
--- a/Doc/c-api/memory.rst
+++ b/Doc/c-api/memory.rst
@@ -672,6 +672,10 @@ This allocator is disabled if Python is configured with the
 :option:`--without-pymalloc` option. It can also be disabled at runtime using
 the :envvar:`PYTHONMALLOC` environment variable (ex: ``PYTHONMALLOC=malloc``).
 
+Typically, it makes sense to disable the pymalloc allocator when building
+Python with AddressSanitizer (:option:`--with-address-sanitizer`) which helps
+uncover low level bugs within the C code.
+
 Customize pymalloc Arena Allocator
 ----------------------------------
 
diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index e5fe3c72b1b26e..2cda9587975ddc 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -802,6 +802,9 @@ Debug options
 .. option:: --with-address-sanitizer
 
    Enable AddressSanitizer memory error detector, ``asan`` (default is no).
+   To improve ASan detection capabilities you may also want to combine this
+   with :option:`--without-pymalloc` to disable the specialized small-object
+   allocator whose allocations are not tracked by ASan.
 
    .. versionadded:: 3.6
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to