Skip to content

Commit 1402e4f

Browse files
gf712claude
andcommitted
testing: disable ASan use-after-return detection in the test binary
The garbage collector finds roots by conservatively scanning the machine stack. ASan's use-after-return fake stack relocates locals to heap memory the scan never sees, so the GC completeness tests fail under an ASan build even with a correct stack scrub. Bake detect_stack_use_after_return=0 into the test binary via __asan_default_options so ASan builds work out of the box; the rest of ASan's checks are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017NJ25FGK2EUWCLz2PaUwbT
1 parent 2d2b6d1 commit 1402e4f

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/testing/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55

66
#include <cxxopts.hpp>
77

8+
#if defined(__SANITIZE_ADDRESS__)
9+
#define PYTHON_ASAN_ENABLED
10+
#elif defined(__has_feature)
11+
#if __has_feature(address_sanitizer)
12+
#define PYTHON_ASAN_ENABLED
13+
#endif
14+
#endif
15+
16+
#ifdef PYTHON_ASAN_ENABLED
17+
// The garbage collector finds roots by conservatively scanning the machine
18+
// stack. ASan's use-after-return detection relocates locals to a heap-backed
19+
// fake stack that the scan never sees, so live GC pointers go unnoticed and
20+
// stale ones linger, breaking the collector's reachability tests.
21+
extern "C" const char *__asan_default_options() { return "detect_stack_use_after_return=0"; }
22+
#endif
23+
824
class PythonVMEnvironment : public ::testing::Environment
925
{
1026
char **m_argv;

0 commit comments

Comments
 (0)