Skip to content

Commit cce38ee

Browse files
miss-islingtondisconnect3dencukou
authored
[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 d19bb44) Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 197f3ec commit cce38ee

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Doc/c-api/memory.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ This allocator is disabled if Python is configured with the
672672
:option:`--without-pymalloc` option. It can also be disabled at runtime using
673673
the :envvar:`PYTHONMALLOC` environment variable (ex: ``PYTHONMALLOC=malloc``).
674674
675+
Typically, it makes sense to disable the pymalloc allocator when building
676+
Python with AddressSanitizer (:option:`--with-address-sanitizer`) which helps
677+
uncover low level bugs within the C code.
678+
675679
Customize pymalloc Arena Allocator
676680
----------------------------------
677681

Doc/using/configure.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ Debug options
802802
.. option:: --with-address-sanitizer
803803

804804
Enable AddressSanitizer memory error detector, ``asan`` (default is no).
805+
To improve ASan detection capabilities you may also want to combine this
806+
with :option:`--without-pymalloc` to disable the specialized small-object
807+
allocator whose allocations are not tracked by ASan.
805808

806809
.. versionadded:: 3.6
807810

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy