From 4e99743f01f27f8c456cfaa8d736d8684cb01a0b Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Fri, 25 Apr 2025 16:53:37 +0100 Subject: [PATCH 1/3] gh-91048: Prevent optimizing away the asyncio debug offsets structure on Windows To avoid having the debug sections being optimised away by the compiler we use __attribute__((used)) on gcc and clang but in Windows this is not supported by the Microsoft compiler and there is no equivalent flag. Unfortunately Windows offers almost no alternative other than exporting the symbol in the dynamic table or using it somehow. --- Modules/_asynciomodule.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 27e6e67e3c9386..0a780b8c584f47 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -185,6 +185,12 @@ typedef struct { /* Counter for autogenerated Task names */ uint64_t task_name_counter; +#ifdef MS_WINDOWS + /* Pointer to the asyncio debug offset to avoid it to be optimized away + by the compiler in Windows (other platforms don't need this) */ + void *debug_offsets; +#endif + } asyncio_state; static inline asyncio_state * @@ -4320,6 +4326,10 @@ module_init(asyncio_state *state) goto fail; } +#ifdef MS_WINDOWS + state->debug_offsets = &_AsyncioDebug; +#endif + Py_DECREF(module); return 0; From 6f6bde5a025048a0ed25d89cd538a418dce93c1e Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 25 Apr 2025 18:17:57 +0100 Subject: [PATCH 2/3] Apply suggestions from code review --- Modules/_asynciomodule.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 0a780b8c584f47..0d4a4ab138b31d 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -185,11 +185,9 @@ typedef struct { /* Counter for autogenerated Task names */ uint64_t task_name_counter; -#ifdef MS_WINDOWS /* Pointer to the asyncio debug offset to avoid it to be optimized away by the compiler in Windows (other platforms don't need this) */ void *debug_offsets; -#endif } asyncio_state; @@ -4326,9 +4324,7 @@ module_init(asyncio_state *state) goto fail; } -#ifdef MS_WINDOWS state->debug_offsets = &_AsyncioDebug; -#endif Py_DECREF(module); return 0; From d3272239a53c5de312c17220d9fe000d3353ab0c Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 25 Apr 2025 18:18:18 +0100 Subject: [PATCH 3/3] Update Modules/_asynciomodule.c --- Modules/_asynciomodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 0d4a4ab138b31d..5f9181395c4828 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -186,7 +186,7 @@ typedef struct { uint64_t task_name_counter; /* Pointer to the asyncio debug offset to avoid it to be optimized away - by the compiler in Windows (other platforms don't need this) */ + by the compiler */ void *debug_offsets; } asyncio_state;