GeezerVison is showing github.com — gh-91048: Prevent optimizing away the asyncio debug offsets structure on Windows by pablogsal · Pull Request #132963 · python/cpython
Conversation
pablogsal
commented
Apr 25, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ucture 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.
|
Sorry can't test this out right now, but does dllexport not prevent it from being optimized away? Or are there other reasons we can't use it?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
pablogsal
commented
Apr 25, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry can't test this out right now, but does dllexport not prevent it from being optimized away?
Check the commit message: we don't want to export the symbol in the dynamic table. This is basically the less intrusive option Windows offers.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Just for completeness, we also get an error if we try to add __declspec(dllexport) to the macro:
C:\Users\pablogsal\GitHub\cpython\Python\pylifecycle.c(113,1): error C2370: '_PyRuntime': redefinition; different storage class [C:\Users\pablogsal\GitHub\cpython\PCbuild\_freeze_module.vcxproj]
we could have it as an option only for shared modules but then we need to deal with this other error:
C:\Users\pablogsal\GitHub\cpython\PCbuild\win32\_freeze_module.exe : fatal error LNK1120: 1 unresolved externals [C:\Users\pablogsal\GitHub\cpython\PCbuild\_freeze_module.vcxproj]
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I also tried doing this but doesn't work:
#if defined(MS_WINDOWS)
#define _GENERATE_DEBUG_SECTION_WINDOWS(name) \
_Pragma("optimize(\"g\", off)") \
_Pragma(Py_STRINGIFY(section(Py_STRINGIFY(name), read, write))) \
__declspec(allocate(Py_STRINGIFY(name))) \
_Pragma("optimize(\"g\", on)")
#else
#define _GENERATE_DEBUG_SECTION_WINDOWS(name)
#endif
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
/* Pointer to the asyncio debug offset to avoid it to be optimized away
|
|
|
by the compiler */
|
|
|
void *debug_offsets;
|
There was a problem hiding this comment.
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?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
chris-eibl reacted with thumbs up emoji
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|