Skip to content

Commit 2a0fcd8

Browse files
authored
Update ASan information regarding --without-pymalloc flag
As discussed with @encukou on the CPython Core sprint on EuroPython 2025. We initially thought that the `--without-pymalloc` flag is needed 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
1 parent bdfc99f commit 2a0fcd8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

development-tools/clang.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ Then, run ``./configure`` with the relevant flags:
103103
* ASan: ``--with-address-sanitizer --without-pymalloc``
104104
* UBsan: ``--with-undefined-behavior-sanitizer``
105105

106-
It is OK to specify both sanitizers.
106+
Disabling pymalloc for ASan helps uncover more bugs since it is more effective
107+
with the system allocator (pymalloc doesn't add padding in between the allocated
108+
objects and doesn't poison/annotate the memory it manages for ASan).
109+
110+
It is also OK to specify both sanitizers.
107111

108112
After that, run ``make`` and ``make test`` as usual.
109113
Note that ``make`` itself may fail with a sanitizer failure,

0 commit comments

Comments
 (0)