FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-91048: Prevent optimizing away the asyncio debug offsets structure on Windows by pablogsal · Pull Request #132963 · python/cpython · GitHub

/ cpython Public

gh-91048: Prevent optimizing away the asyncio debug offsets structure on Windows - #132963

Merged
pablogsal merged 3 commits into
python:mainfrom
pablogsal:gh-91048-win
Apr 25, 2025
Merged

gh-91048: Prevent optimizing away the asyncio debug offsets structure on Windows#132963
pablogsal merged 3 commits into
python:mainfrom
pablogsal:gh-91048-win

Conversation

pablogsal commented Apr 25, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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.

…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.

Copy link
Copy Markdown
Member

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?

pablogsal commented Apr 25, 2025
edited
Loading

Copy link
Copy Markdown
Member Author

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.

Comment thread Modules/_asynciomodule.c Outdated

Copy link
Copy Markdown
Member Author

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]

pablogsal disabled auto-merge April 25, 2025 17:08

Copy link
Copy Markdown
Member Author

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

Comment thread Modules/_asynciomodule.c Outdated
Comment thread Modules/_asynciomodule.c Outdated
Comment thread Modules/_asynciomodule.c Outdated
pablogsal enabled auto-merge (squash) April 25, 2025 17:18
pablogsal merged commit a5e628b into python:main Apr 25, 2025
pablogsal deleted the gh-91048-win branch April 25, 2025 17:43
Comment thread Modules/_asynciomodule.c

/* Pointer to the asyncio debug offset to avoid it to be optimized away
by the compiler */
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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah I still prefer to keep it

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL