-
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
<chrono>: Including header pulls in a dynamic initializer, incompatible with /kernel #1926
Comments
Would it be possible to mitigate this issue by modifying // CLASS id
class _CRTIMP2_PURE_IMPORT id { // identifier stamp, unique for each distinct kind of facet
public:
constexpr __CLR_OR_THIS_CALL id() noexcept = default;
__CLR_OR_THIS_CALL id(size_t _Val) : _Id(_Val) {}
id(const id&) = delete;
id& operator=(const id&) = delete;
__CLR_OR_THIS_CALL operator size_t() { // get stamp, with lazy allocation
if (_Id == 0) { // still zero, allocate stamp
_BEGIN_LOCK(_LOCK_LOCALE)
if (_Id == 0) {
_Id = static_cast<size_t>(++_Id_cnt);
}
_END_LOCK()
}
return _Id;
}
private:
size_t _Id{}; // the identifier stamp
__PURE_APPDOMAIN_GLOBAL static int _Id_cnt;
}; i.e., removing the default argument value 0 from |
I believe that would break ABI because this is separately compiled (as obscurely indicated by the |
What if instead of the entire class being |
That might work, but I would be very hesitant to attempt such a change - the locale IDs are basically the most fragile, most poorly understood part of the entire STL, and it's very easy to damage things in a subtle way (as I did back in the VS 2010 era). We've never removed |
Just out of curiosity, what happened in the circa VS 2010 incident? |
As I vaguely recall (it was a decade ago and I was new so I barely understood anything), I tried to make the machinery header-only, which damaged the order in which the IDs were assigned. I was able to successfully make other machinery header-only (including |
I used to think this was fixed by #2496 but I was probably wrong then. I think my new PR can fix this, see the analyzation in the PR. |
Describe the bug
With Visual Studio 16.10 (Preview 3), just including
<chrono>
now pulls in a dynamic initializer forstd::numpunct<char>::id
andstd::numpunct<wchar_t>::id
, which was previously not the case in 16.9. Presumably this is the result of #1821 or #1870.Since we use
<chrono>
as part of kernel mode driver projects, this now results in a linker warning:Since the kernel mode build environment does not have startup code that calls these initializers, this is problematic. For these specific initializers the warning is benign in the sense formatting-related chrono functionality cannot be consumed anyway. However, suppressing the warning globally (in our project) is also undesirable because it would allow developers to sneak in their own initializers which are never invoked.
It's clear to us that
<chrono>
isn't officially supported for consumption in the kernel mode build environment and isn't really a part of the freestanding subset. However, since this is a regression, it seems appropriate to bring it to your attention for consideration.Command-line test case
while with 16.9:
with no warning.
Expected behavior
Ideally just including
<chrono>
without consuming any of the new formatting related functionality won't pull in any redundant dynamic initializers.STL version
Additional context
The repro command lines above do not use
/kernel
or the kernel mode build environment, but simulate the same situation by not linking with the usual user mode startup code.The text was updated successfully, but these errors were encountered: