Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ba64f4

Browse files
committed
Close #18596: Support address sanity checking in clang/GCC
This patch appropriately marks known false alarms in the small object allocator when address sanity checking is enabled (patch contributed by Dhiru Kholia).
1 parent 4cc2afa commit 6ba64f4

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ Jim Kerr
650650
Magnus Kessler
651651
Lawrence Kesteloot
652652
Vivek Khera
653+
Dhiru Kholia
653654
Mads Kiilerich
654655
Jason Killen
655656
Jan Kim

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ Documentation
9494
- Issue #17003: Unified the size argument names in the io module with common
9595
practice.
9696

97+
Build
98+
-----
99+
100+
- Issue #18596: Support the use of address sanity checking in recent versions
101+
of clang and GCC by appropriately marking known false alarms in the small
102+
object allocator. Patch contributed by Dhiru Kholia.
103+
97104
Tools/Demos
98105
-----------
99106

Objects/obmalloc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ static void _PyObject_DebugDumpAddress(const void *p);
1212
static void _PyMem_DebugCheckAddress(char api_id, const void *p);
1313
#endif
1414

15+
#if defined(__has_feature) /* Clang */
16+
#if __has_feature(address_sanitizer) /* is ASAN enabled? */
17+
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
18+
__attribute__((no_address_safety_analysis)) \
19+
__attribute__ ((noinline))
20+
#else
21+
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
22+
#endif
23+
#else
24+
#if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */
25+
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
26+
__attribute__((no_address_safety_analysis)) \
27+
__attribute__ ((noinline))
28+
#else
29+
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
30+
#endif
31+
#endif
32+
1533
#ifdef WITH_PYMALLOC
1634

1735
#ifdef MS_WINDOWS
@@ -1300,6 +1318,7 @@ _PyObject_Malloc(void *ctx, size_t nbytes)
13001318

13011319
/* free */
13021320

1321+
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
13031322
static void
13041323
_PyObject_Free(void *ctx, void *p)
13051324
{
@@ -1528,6 +1547,7 @@ _PyObject_Free(void *ctx, void *p)
15281547
* return a non-NULL result.
15291548
*/
15301549

1550+
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
15311551
static void *
15321552
_PyObject_Realloc(void *ctx, void *p, size_t nbytes)
15331553
{

0 commit comments

Comments
 (0)