-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid <atomic>
in filesystem.cpp
#3011
Avoid <atomic>
in filesystem.cpp
#3011
Conversation
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.
🙏 Thanks for the quick fix and help!
Oddly enough, looks like a sporadic ASAN failure as well :(
Updated #2908 and re-ran. Also, congratulations on finally running this monster aground! |
I'm speculatively mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
It seems that |
Ah, sorry about this; it's really unfortunate that we don't have a core atomic header (real |
Background
@zacklj89 found this while updating the STL in Windows. (Thanks Zack, for investigating this for over a week - it wasn't easy! 😸)
#2302 (merged for VS 2022 17.4 Preview 2) made
filesystem.cpp
(which is injected into the STL's import lib) include<atomic>
to cache a function pointer. Unfortunately,<atomic>
is a non-core header, and it's the first non-core header included byfilesystem.cpp
:STL/stl/inc/atomic
Line 9 in 2263d93
This drags in
_Init_locks
, which is separately compiled and has an implicitly defined assignment operator:STL/stl/inc/yvals.h
Lines 456 to 475 in 2263d93
In a certain project, this was leading to linker errors, as the STL's DLL exports
_Init_locks::operator=
and the linker was seeing a duplicate definition in the injectedfilesystem.obj
.GitHub vs. MSVC difference
Curiously, I'm unable to observe this assignment operator in the import lib produced by microsoft/STL
main
, but I can see it in the MSVC-internal build. I'm not sure this is due to a very recent compiler change, or some difference in the CMake vs. MSBuild build systems. In any event, dragging in this non-core header is risky, and we should avoid it due to the potential for similar linker errors when 17.4 ships.microsoft/STL
main
MSVC-internal
prod/fe
Fix
I believe the proper fix is to simply avoid
<atomic>
entirely. Users should be very rarely callingtemp_directory_path()
, so the performance impact of always callingGetProcAddress()
should be minimal. Zack has confirmed that this change fixes the affected project in Windows.Because #2302 was merged for 17.4 Preview 2, if we remove the
<atomic>
dependency for 17.4 Preview 3, it will never have shipped to users for production.Size impact
This shrinks the import lib:
main
msvcprt.lib
msvcprtd.lib