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

Fix MSVC_RUNTIME_LIBRARY inconsistencies #374

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

leha-bot
Copy link
Contributor

Use CMake defaults as sane default, as LLVM also uses it by default.

  1. The policy was ambiguous as CMake sets it to NEW since CMake 3.15 (as we have CMake 3.16);
  2. The /MD flag just override the target's property MSVC_RUNTIME_LIBRARY, so all configuration types used the /MD flag (instead of CMAKE_MSVC_RUNTIME_LIBRARY);
  3. The manual override for CMAKE_MSVC_RUNTIME_LIBRARY was removed as a potential ODR-violation against LLVM's used MSVC runtime and a real runtime mismatch (which follows to LNK2038 error with text like "Detected mismatch for "RuntimeLibrary": value "MDd_DynamicDebug" doesn't match value "MD_StaticDebug").

@leha-bot
Copy link
Contributor Author

leha-bot commented Jan 17, 2025

That was pretty tough to detect, I found it accidentally, as I need to build a Debug LLVM, which uses the MDd_DynamicDebug (/MDd) by default, unlike the other profiles, which use the MD_DynamicRelease (that /MD flag)

In my localised MSVC the error(s) looks like:

обнаружено несоответствие для "_ITERATOR_DEBUG_LEVEL": значение "2" не соответствует значению "0" в main.obj
обнаружено несоответствие для "RuntimeLibrary": значение "MDd_DynamicDebug" не соответствует значению "MD_DynamicRelease" в main.obj

The first one detects the MSVC STL ABI differences related to their debug iterators (they could handle some typical errors as runtime errors), the second is our root cause. The old MSVCs actually could link the libraries with distinct runtimes, but final executable would definitely crash on any ABI boundary

Use CMake defaults as sane default, as LLVM also uses it by default.
1. The policy was ambiguous as CMake sets it to NEW since CMake 3.15 (as
   we have CMake 3.16);
2. The `/MD` flag just override the target's property
   MSVC_RUNTIME_LIBRARY, so all configuration types used the /MD flag
   (instead of CMAKE_MSVC_RUNTIME_LIBRARY);
3. The manual override for CMAKE_MSVC_RUNTIME_LIBRARY was removed as a
   potential ODR-violation against LLVM's used MSVC runtime and a real
   runtime mismatch (which follows to LNK2038 error with text like
   "Detected mismatch for "RuntimeLibrary": value "MDd_DynamicDebug"
   doesn't match value "MD_StaticDebug").
@leha-bot leha-bot force-pushed the fix/msvc-inconsistent-runtimes branch from 2d3a8ee to 57f7280 Compare January 17, 2025 08:43
@bkryza bkryza merged commit 9b157e8 into bkryza:master Jan 17, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants