Skip to content
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

constexpr mutex constructor #3824

Merged
merged 7 commits into from
Jul 20, 2023
Merged

Conversation

cpplearner
Copy link
Contributor

@cpplearner cpplearner commented Jun 23, 2023

Fixes #2285.

Because this might cause problem in complicated (and formally forbidden) scenarios (see discussion in #3770), I chose to make this opt-in via the _USE_CONSTEXPR_MUTEX_CONSTRUCTOR macro. If _USE_CONSTEXPR_MUTEX_CONSTRUCTOR is not defined, mutex will call _Mtx_init_in_situ as before.

For the same reason, I changed stl_critical_section_win7 and stl_condition_variable_win7 back to polymorphic classes, even though their vptrs are no longer accessed. (If _USE_CONSTEXPR_MUTEX_CONSTRUCTOR is defined, no stl_critical_section_win7 object will be created.)

@cpplearner cpplearner requested a review from a team as a code owner June 23, 2023 10:00
@cpplearner cpplearner marked this pull request as draft June 23, 2023 10:27
@cpplearner cpplearner marked this pull request as ready for review June 23, 2023 11:01
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jun 23, 2023
@StephanTLavavej StephanTLavavej self-assigned this Jun 23, 2023
stl/inc/mutex Outdated Show resolved Hide resolved
stl/inc/xthreads.h Outdated Show resolved Hide resolved
stl/src/primitives.hpp Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks, this looks great! I pushed extremely minor changes.

Having thought about this extensively during the previous PR, I think that this change is correct and safe, and it's a good simplification too.

@StephanTLavavej StephanTLavavej self-assigned this Jul 13, 2023
@StephanTLavavej

This comment was marked as outdated.

@StephanTLavavej StephanTLavavej removed their assignment Jul 13, 2023
@StephanTLavavej
Copy link
Member

Unfortunately, I need to pull this from the merge batch. It's causing the internal build to consistently fail with:

D:\msvc\src\vctools\asan\mt\llvm-symbolizer.nativeproj(79,5): error MSB3073:
The command ""D:\msvc\src\ExternalAPIs\cmake\bin\ninja.exe" "bin/llvm-symbolizer.exe"   " exited with code 1.

I don't know what's causing this yet.

@StephanTLavavej
Copy link
Member

I've had to push an additional commit to avoid a /clr compiler error:

.\test.cpp(479): error C2127: 'obj2': illegal initialization of 'constinit' entity with a non-constant expression

/clr just hates constant initialization so there's nothing we can do about this except skip the test coverage.

@StephanTLavavej StephanTLavavej merged commit 8d18fec into microsoft:main Jul 20, 2023
@StephanTLavavej
Copy link
Member

Thanks for fixing this unfixable bug!!! 😻 😻 😻

@cpplearner cpplearner deleted the constexpr-mutex branch July 21, 2023 07:05
strega-nil added a commit to strega-nil/llvm-project that referenced this pull request Aug 18, 2023
It turns out that the STL requires you to place the DLLs into the
directory of the executable; else, msvcp140.dll will be taken from
C:\Windows\System32 (which is unsupported).

This was discovered because of the recent constexpr mutex change;
see [microsoft/STL#3824][]. Especially the fuzzer unit tests fail
completely with the mutex changes.

[microsoft/STL#3824]: microsoft/STL#3824

Differential Revision: https://reviews.llvm.org/D158221
CaseyCarter added a commit to CaseyCarter/STL that referenced this pull request Aug 30, 2023
This reverts commit 8d18fec.

Conflicts:
* stl/inc/xthreads.h
* stl/src/cond.cpp
* stl/src/mutex.cpp
* stl/src/primitives.hpp
tianleiwu pushed a commit to microsoft/onnxruntime that referenced this pull request Jun 12, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
baijumeswani added a commit to microsoft/onnxruntime that referenced this pull request Jun 20, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
yf711 pushed a commit to microsoft/onnxruntime that referenced this pull request Jun 21, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
narknon added a commit to UE4SS-RE/RE-UE4SS that referenced this pull request Jun 22, 2024
microsoft/STL#3824
microsoft/STL#4000
microsoft/STL#4339

Add escape hatch due to STL change resulting in issues with binary compatibility.

https://github.com/microsoft/STL/wiki/Changelog
"Fixed bugs:

    Fixed mutex's constructor to be constexpr. #3824 #4000 #4339
        Note: Programs that aren't following the documented restrictions on binary compatibility may encounter null dereferences in mutex machinery. You must follow this rule:

            When you mix binaries built by different supported versions of the toolset, the Redistributable version must be at least as new as the latest toolset used by any app component.

        You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch."
narknon added a commit to UE4SS-RE/RE-UE4SS that referenced this pull request Jun 27, 2024
STL updates Mutex Fix

microsoft/STL#3824
microsoft/STL#4000
microsoft/STL#4339

Add escape hatch due to STL change resulting in issues with binary compatibility.

https://github.com/microsoft/STL/wiki/Changelog
"Fixed bugs:

    Fixed mutex's constructor to be constexpr. #3824 #4000 #4339
        Note: Programs that aren't following the documented restrictions on binary compatibility may encounter null dereferences in mutex machinery. You must follow this rule:

            When you mix binaries built by different supported versions of the toolset, the Redistributable version must be at least as new as the latest toolset used by any app component.

        You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch."**Description**
barcharcraz pushed a commit to barcharcraz/llvm-project that referenced this pull request Nov 1, 2024
See [MSVC-PR-490940][] and [LLVM-D158221][].

It turns out that the STL requires you to place the DLLs into the
directory of the executable; else, `msvcp140.dll` will be taken from
`C:\Windows\System32` (which is unsupported).

This was discovered because of the recent constexpr mutex change;
see [microsoft/STL#3824][]. Especially the fuzzer unit tests fail
completely with the mutex changes.

[MSVC-PR-490940]: https://dev.azure.com/devdiv/DevDiv/_git/msvc/pullrequest/490940
[LLVM-D158221]: https://reviews.llvm.org/D158221
[microsoft/STL#3824]: microsoft/STL#3824
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects redist Results in changes to separately compiled bits bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<mutex> : std::mutex::mutex is not constexpr
5 participants