From a50feea6efd5a7c30492d06d72e1699a1b91737e Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Tue, 17 May 2016 11:48:13 +0300 Subject: [PATCH] Support address sanity checking in clang/GCC Patch imported from upstream https://hg.python.org/cpython/rev/f6792f734fcc and enables Address Sanitizer support for Python. Change-Id: I1d8abfacb162b343f767f731424834004b65242c Signed-off-by: Slava Barinov --- Objects/obmalloc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 1434206..194fbfd 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -1,5 +1,23 @@ #include "Python.h" +#if defined(__has_feature) /* Clang */ + #if __has_feature(address_sanitizer) /* is ASAN enabled? */ + #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ + __attribute__ ((no_sanitize_address)) \ + __attribute__ ((noinline)) + #else + #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS + #endif +#else + #if defined(__SANITIZE_ADDRESS__) /* GCC, is ASAN enabled? */ + #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ + __attribute__ ((no_sanitize_address)) \ + __attribute__ ((noinline)) + #else + #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS + #endif +#endif + #ifdef WITH_PYMALLOC #ifdef HAVE_MMAP @@ -971,6 +989,7 @@ redirect: /* free */ #undef PyObject_Free +ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS void PyObject_Free(void *p) { @@ -1201,6 +1220,7 @@ redirect: */ #undef PyObject_Realloc +ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS void * PyObject_Realloc(void *p, size_t nbytes) { -- 2.34.1