Standard Library Modules: Fix spurious _Init_locks dllexport#3233
Standard Library Modules: Fix spurious _Init_locks dllexport#3233StephanTLavavej merged 2 commits intomicrosoft:mainfrom
_Init_locks dllexport#3233Conversation
Thanks for mentioning this and saving me the trouble of asking =)
Should we have a validation step in our build that looks for |
😸
I wouldn't object to that, but (at least for me) I think it'd take more time to learn how to implement than it would be worth. With this PR, (The core-header-only approach may be feasible in the long term, which I'd want to explore if we keep adding import lib objects at a steady rate.) |
All true. I really don't want a repeat of the fiasco getting the LKG update out, but it would be quite hard to do so unintentionally now. (This statement of agreement should not be construed as waiving my right to say "I told you so".) |
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
I observed a curious message "Creating library meow.lib and object meow.exp" when consuming
import std;with VS 2022 17.5 Preview 1. This doesn't repro when using the 17.5p1 compiler to consumeimport std;from microsoft/STLmain; it repros only with the shipped machinery. I haven't figured out what the difference is yet, but I did find the root cause of the message.The problem is that when we inject
stacktrace.cppinto the import lib, it drags inyvals.hand the headache-inducing_Init_locks. In #3019, we guarded_Init_lockswith_CRTBLDso it wouldn't affect users ofstl/inc, but the problem here is thatstacktrace.cppis part of the STL's build, so_Init_locksis being emitted.I have two fixes for this (either alone would be sufficient but I want to be extra sure here). First,
stacktrace.cppdirectly includesyvals.hbut barely needs it. We can replace its use of_STL_VERIFYwith direct calls tostd::abort(), since these should only fail due to STL-internal logic errors (or something catastrophic happening at runtime).Second, let's take the additional effort to fully remove
_Init_locksfromstl/incand move it into anstl/srcsource-header that is then included by only the files that need_Init_locks- never those injected into the import lib.(I experimented with a third strategy, enforcing all import lib files to be core-only via the recently-added
_ENFORCE_ONLY_CORE_HEADERS. This is currently not possible, even after fixingstacktrace.cpp, due tonothrow.cppincluding<new>(which would be fairly easy to disconnect) andlocale0_implib.cppeventually including<xfacet>which would be harder and scarier to rework. For the time being, I have abandoned that approach.)Note: Unlike user-visible headers, our source-headers can be very lightweight, i.e. they don't need push-pop defenses and all that. We're currently inconsistent about how to give them idempotency guards, but I went with the lightweight
#pragma once.Here is the full repro that shows how I tracked this down to
stacktrace.cpp:This will require MSVC-internal changes to add the new source-header.