]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan information (GH-136790)
authorDisconnect3d <dominik.b.czarnota@gmail.com>
Sat, 19 Jul 2025 11:52:54 +0000 (13:52 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Jul 2025 11:52:54 +0000 (13:52 +0200)
commitd19bb4471331ca2cb87b86e4c904bc9a2bafb044
tree6470d76721bf1eea7c1d38e5ff20c607c16da423
parenteb8ac4c85773160a6104abafdea9159f26363a9b
Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan information (GH-136790)

* Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan information

This commit extends 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.

This code can be seen here:
https://github.com/python/cpython/blob/acefb978dcb5dd554e3c49a3015ee5c2ad6bfda1/Objects/obmalloc.c#L2096-L2110

While the annotation macro is defined here:
https://github.com/python/cpython/blob/acefb978dcb5dd554e3c49a3015ee5c2ad6bfda1/Include/pyport.h#L582-L598

And the corresponding attribute is documented in:
* for gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fsanitize_005faddress-function-attribute
* for clang: https://clang.llvm.org/docs/AttributeReference.html#no-sanitize-address-no-address-safety-analysis

* Update Doc/c-api/memory.rst

* Improve --with-address-sanitizer and pymalloc docs

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Doc/c-api/memory.rst
Doc/using/configure.rst