Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
pablogsal committed Apr 25, 2025
commit 4e99743f01f27f8c456cfaa8d736d8684cb01a0b
10 changes: 10 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Comment thread
pablogsal marked this conversation as resolved.
Outdated
void *debug_offsets;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we'd even do not need the __attribute__((used)) any longer in the GENERATE_DEBUG_SECTION macros.
But it doesn't hurt either - so let's keep it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I still prefer to keep it

#endif
Comment thread
pablogsal marked this conversation as resolved.
Outdated

} asyncio_state;

static inline asyncio_state *
Expand Down Expand Up @@ -4320,6 +4326,10 @@ module_init(asyncio_state *state)
goto fail;
}

#ifdef MS_WINDOWS
Comment thread
pablogsal marked this conversation as resolved.
Outdated
state->debug_offsets = &_AsyncioDebug;
#endif

Comment thread
pablogsal marked this conversation as resolved.
Outdated
Py_DECREF(module);
return 0;

Expand Down