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

bumping cmake_minimum_required causes compiler-rt test link failures on Windows #62719

Closed
zmodem opened this issue May 15, 2023 · 8 comments
Closed
Labels
cmake Build system in general and CMake in particular compiler-rt

Comments

@zmodem
Copy link
Collaborator

zmodem commented May 15, 2023

Surprisingly, it seems the cmake_minimum_required bump from 3.13.4 to 3.20.0 in @mordante's ffb807a is causing some behavior change that makes compiler-rt tests fail to link on Windows.

From the top of https://lab.llvm.org/buildbot/#/builders/127/builds/48120/steps/8/logs/stdio

[58/136] Generating Fuzzer-x86_64-Test.exe
FAILED: projects/compiler-rt/lib/fuzzer/tests/Fuzzer-x86_64-Test.exe C:/b/slave/sanitizer-windows/build/stage1/projects/compiler-rt/lib/fuzzer/tests/Fuzzer-x86_64-Test.exe 
cmd.exe /C "cd /D C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\lib\fuzzer\tests && C:\b\slave\sanitizer-windows\build\stage1\.\bin\clang++.exe FuzzerTestObjects.FuzzerUnittest.cpp.x86_64.o FuzzerTestObjects.gtest-all.cc.x86_64.o C:/b/slave/sanitizer-windows/build/stage1/projects/compiler-rt/lib/fuzzer/tests/RTFuzzerTest.x86_64.lib -o C:/b/slave/sanitizer-windows/build/stage1/projects/compiler-rt/lib/fuzzer/tests/./Fuzzer-x86_64-Test.exe --driver-mode=g++ -Wl,-defaultlib:libcmt,-defaultlib:oldnames"
RTFuzzerTest.x86_64.lib(FuzzerIOWindows.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in FuzzerTestObjects.FuzzerUnittest.cpp.x86_64.o

I can also reproduce this locally. My CMake version is 3.20.21032501-MSVC_2

> cmake -GNinja -DLLVM_ENABLE_PROJECTS="llvm;clang;compiler-rt" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=X86 ..\llvm && ninja check-fuzzer
[...]
[2985/2987] Generating Fuzzer-x86_64-Test.exe
FAILED: projects/compiler-rt/lib/fuzzer/tests/Fuzzer-x86_64-Test.exe
cmd.exe /C "cd /D C:\src\llvm-project\build.nana\projects\compiler-rt\lib\fuzzer\tests && C:\src\llvm-project\build.nana\.\bin\clang++.exe FuzzerTestObjects.FuzzerUnittest.cpp.x86_64.o FuzzerTestObjects.gtest-all.cc.x86_64.o C:/src/llvm-project/build.nana/projects/compiler-rt/lib/fuzzer/tests/RTFuzzerTest.x86_64.lib -o C:/src/llvm-project/build.nana/projects/compiler-rt/lib/fuzzer/tests/./Fuzzer-x86_64-Test.exe --driver-mode=g++ -Wl,-defaultlib:libcmt,-defaultlib:oldnames"
RTFuzzerTest.x86_64.lib(FuzzerIOWindows.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in FuzzerTestObjects.FuzzerUnittest.cpp.x86_64.o

I thought LLVM builds defauled to /MT (and compiler-rt's cmake files does some flag massaging for it here: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.3/compiler-rt/CMakeLists.txt#L398), but for some reason ffb807a changes that?

If I add -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded, it builds. Maybe that should be added as a default somewhere?

@zmodem zmodem added cmake Build system in general and CMake in particular compiler-rt labels May 15, 2023
@mordante
Copy link
Member

Starting with CMake 3.15 it offers CMAKE_MSVC_RUNTIME_LIBRARY so probably that should be used instead of the current work-around.

Maybe a quick fix would be to disable the CMP0091 which probably works with the current work-around.

@rnk
Copy link
Collaborator

rnk commented May 15, 2023

I'm not familiar with this new option, but you can check out ChooseMSVCRT.cmake for some past history of how we've tried to handle CRT selection. However, compiler-rt is compiled very differently, so it may not be relevant anymore.

@zmodem
Copy link
Collaborator Author

zmodem commented May 16, 2023

Sent out https://reviews.llvm.org/D150688 to set the CMP0091 policy.

We hit another issue in Chromium where building the toolchain with rpmalloc failed (https://bugs.chromium.org/p/chromium/issues/detail?id=1445671). I've verified that this patch fixes that too.

@zmodem
Copy link
Collaborator Author

zmodem commented May 17, 2023

The compiler-rt label applies since it's compiler-rt's tests that fail to link.

Also, it seems there are still breakages (https://bugs.chromium.org/p/chromium/issues/detail?id=1445671#c7). I'll try to get a repro for that.

@zmodem zmodem reopened this May 17, 2023
@zmodem
Copy link
Collaborator Author

zmodem commented May 17, 2023

Also, it seems there are still breakages (https://bugs.chromium.org/p/chromium/issues/detail?id=1445671#c7). I'll try to get a repro for that.

cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_ENABLE_RUNTIMES=compiler-rt -DLLVM_TARGETS_TO_BUILD=X86 -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF -DLLVM_USE_CRT_RELEASE=MT -DCOMPILER_RT_BUILD_CRT=ON -DCOMPILER_RT_BUILD_LIBFUZZER=OFF -DCOMPILER_RT_BUILD_MEMPROF=OFF -DCOMPILER_RT_BUILD_ORC=OFF -DCOMPILER_RT_BUILD_PROFILE=ON -DCOMPILER_RT_BUILD_SANITIZERS=OFF -DCOMPILER_RT_BUILD_XRAY=OFF -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON ..\llvm && ninja check-all
[...]
-- Testing: 69999 tests, 60 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: Profile-x86_64 :: gcov-__gcov_flush-terminate.c (67132 of 69999)
******************** TEST 'Profile-x86_64 :: gcov-__gcov_flush-terminate.c' FAILED ********************
Script:
--
: 'RUN: at line 3';   mkdir -p C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp.dir && cd C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp.dir
: 'RUN: at line 4';      C:/src/llvm-project/build.blabla/./bin/clang.exe       -Wl,-incremental:no --coverage C:\src\llvm-project\compiler-rt\test\profile\gcov-__gcov_flush-terminate.c -o C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp
: 'RUN: at line 5';   test -f gcov-__gcov_flush-terminate.gcno
: 'RUN: at line 7';   rm -f gcov-__gcov_flush-terminate.gcda && not KillTheDoctor  C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp
: 'RUN: at line 8';   llvm-cov gcov -t gcov-__gcov_flush-terminate.gcda | FileCheck C:\src\llvm-project\compiler-rt\test\profile\gcov-__gcov_flush-terminate.c
--
Exit Code: 1120

Command Output (stdout):
--
$ ":" "RUN: at line 3"
$ "mkdir" "-p" "C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp.dir"
$ "cd" "C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp.dir"
$ ":" "RUN: at line 4"
$ "C:/src/llvm-project/build.blabla/./bin/clang.exe" "-Wl,-incremental:no" "--coverage" "C:\src\llvm-project\compiler-rt\test\profile\gcov-__gcov_flush-terminate.c" "-o" "C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp"
# command output:
LINK : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4217: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_start_file'
LINK : warning LNK4217: symbol '_get_osfhandle' defined in 'libucrt.lib(osfinfo.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_start_file'
LINK : warning LNK4286: symbol '_get_osfhandle' defined in 'libucrt.lib(osfinfo.obj)' is imported by 'clang_rt.profile-x86_64.lib(WindowsMMap.c.obj)'
LINK : warning LNK4217: symbol '__acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_start_file'
LINK : warning LNK4217: symbol '_errno' defined in 'libucrt.lib(errno.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_start_file'
LINK : warning LNK4217: symbol '__stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'fprintf'
LINK : warning LNK4217: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_emit_arcs'
LINK : warning LNK4217: symbol 'fflush' defined in 'libucrt.lib(fflush.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_end_file'
LINK : warning LNK4217: symbol 'fclose' defined in 'libucrt.lib(fclose.obj)' is imported by 'clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj)' in function 'llvm_gcda_end_file'
LINK : warning LNK4217: symbol '_fileno' defined in 'libucrt.lib(fileno.obj)' is imported by 'clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj)' in function 'lprofLockFileHandle'
LINK : warning LNK4217: symbol '_open_osfhandle' defined in 'libucrt.lib(osfinfo.obj)' is imported by 'clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj)' in function 'lprofOpenFileEx'
LINK : warning LNK4217: symbol 'atoi' defined in 'libucrt.lib(atox.obj)' is imported by 'clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj)' in function 'lprofGetPathPrefix'
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_strdup referenced in function llvm_gcda_start_file
oldnames.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp_strdup
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_open referenced in function llvm_gcda_start_file
oldnames.lib(open.obi) : error LNK2001: unresolved external symbol __imp_open
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_fdopen referenced in function llvm_gcda_start_file
oldnames.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp_fdopen
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_fseek referenced in function llvm_gcda_start_file
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_ftell referenced in function llvm_gcda_start_file
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_realloc referenced in function llvm_gcda_start_file
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_strerror referenced in function llvm_gcda_start_file
clang_rt.profile-x86_64.lib(GCDAProfiling.c.obj) : error LNK2019: unresolved external symbol __imp_fwrite referenced in function llvm_gcda_end_file
clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj) : error LNK2019: unresolved external symbol __imp__mkdir referenced in function __llvm_profile_recursive_mkdir
clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj) : error LNK2019: unresolved external symbol __imp__fdopen referenced in function lprofOpenFileEx
oldnames.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp__fdopen
clang_rt.profile-x86_64.lib(InstrProfilingUtil.c.obj) : error LNK2019: unresolved external symbol __imp_getenv referenced in function lprofGetPathPrefix
oldnames.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp__strdup
oldnames.lib(open.obi) : error LNK2001: unresolved external symbol __imp__open
C:\src\llvm-project\build.blabla\runtimes\runtimes-bins\compiler-rt\test\profile\Profile-x86_64\Output\gcov-__gcov_flush-terminate.c.tmp : fatal error LNK1120: 13 unresolved externals

# command stderr:
clang: error: linker command failed with exit code 1120 (use -v to see invocation)

error: command failed with exit status: 0x460

--
[...]
Failed Tests (47):
  Profile-x86_64 :: Windows/coverage-linkage.cpp
  Profile-x86_64 :: Windows/instrprof-multiprocess.test
  Profile-x86_64 :: coverage-inline.cpp
  Profile-x86_64 :: coverage_comments.cpp
  Profile-x86_64 :: coverage_emptylines.cpp
  Profile-x86_64 :: gcc-flag-compatibility.test
  Profile-x86_64 :: gcov-__gcov_flush-terminate.c
  Profile-x86_64 :: gcov-basic.c
  Profile-x86_64 :: gcov-complex-line.c
  Profile-x86_64 :: gcov-dump-and-remove.c
  Profile-x86_64 :: infinite_loop.c
  Profile-x86_64 :: instrprof-basic.c
  Profile-x86_64 :: instrprof-block-coverage.c
  Profile-x86_64 :: instrprof-bufferio.c
  Profile-x86_64 :: instrprof-dump.c
  Profile-x86_64 :: instrprof-entry-coverage.c
  Profile-x86_64 :: instrprof-error.c
  Profile-x86_64 :: instrprof-gcov-exceptions.test
  Profile-x86_64 :: instrprof-gcov-multiple-bbs-single-line.test
  Profile-x86_64 :: instrprof-gcov-one-line-function.test
  Profile-x86_64 :: instrprof-gcov-switch.test
  Profile-x86_64 :: instrprof-gcov-two-objects.test
  Profile-x86_64 :: instrprof-get-filename.c
  Profile-x86_64 :: instrprof-groups.c
  Profile-x86_64 :: instrprof-override-filename-then-reset-default.c
  Profile-x86_64 :: instrprof-override-filename-with-env.c
  Profile-x86_64 :: instrprof-override-filename.c
  Profile-x86_64 :: instrprof-path.c
  Profile-x86_64 :: instrprof-reset-counters.c
  Profile-x86_64 :: instrprof-set-file-object-merging.c
  Profile-x86_64 :: instrprof-set-file-object.c
  Profile-x86_64 :: instrprof-set-filename-then-reset-default.c
  Profile-x86_64 :: instrprof-set-filename.c
  Profile-x86_64 :: instrprof-timestamp.c
  Profile-x86_64 :: instrprof-tmpdir.c
  Profile-x86_64 :: instrprof-value-prof-2.c
  Profile-x86_64 :: instrprof-value-prof-evict.test
  Profile-x86_64 :: instrprof-value-prof-reset.c
  Profile-x86_64 :: instrprof-value-prof.c
  Profile-x86_64 :: instrprof-value-prof.test
  Profile-x86_64 :: instrprof-version-mismatch.c
  Profile-x86_64 :: instrprof-write-file-atexit-explicitly.c
  Profile-x86_64 :: instrprof-write-file-only.c
  Profile-x86_64 :: instrprof-write-file.c
  Profile-x86_64 :: runtime_infinite.c

@zmodem
Copy link
Collaborator Author

zmodem commented May 17, 2023

I tried

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 8485fe9232d0..9c68e84fd072 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -13,6 +13,8 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE
 endif()

 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)

 # Add path for custom compiler-rt modules.
 list(INSERT CMAKE_MODULE_PATH 0
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index be68d6df34c2..e1b2e08ffe09 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -4,6 +4,8 @@ project(Runtimes C CXX ASM)

 # Add path for custom and the LLVM build's modules to the CMake module path.
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)
 list(INSERT CMAKE_MODULE_PATH 0
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"

but that didn't help.

Also the below didn't help:

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 8485fe9232d0..979efc5dfb09 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -398,9 +398,9 @@ if(MSVC)
       CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
       CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
       CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
-      string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
-      string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
-      string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
+      string(REGEX REPLACE "[/-]M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
+      string(REGEX REPLACE "[/-]MD" "/MT" ${flag_var} "${${flag_var}}")
+      string(REGEX REPLACE "[/-]D_DEBUG" "" ${flag_var} "${${flag_var}}")
     endforeach()
   endif()
   append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)

@glandium
Copy link
Contributor

@zmodem CMakePolicy.cmake needs to be included before project(). You need to move the set() and include() right below the cmake_minimum_required.

@zmodem
Copy link
Collaborator Author

zmodem commented May 18, 2023

Thanks @glandium, that seems to work. With the patch below on top of 7d47dac, I was able to build successfully.

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 8485fe9232d0..6489aa17c229 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -5,6 +5,10 @@

 cmake_minimum_required(VERSION 3.20.0)

+set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)
+
 # Check if compiler-rt is built as a standalone project.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
   project(CompilerRT C CXX ASM)
@@ -12,8 +16,6 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE
   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 endif()

-set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
-
 # Add path for custom compiler-rt modules.
 list(INSERT CMAKE_MODULE_PATH 0
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index be68d6df34c2..599529852688 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -1,9 +1,13 @@
 # This file handles building LLVM runtime sub-projects.
 cmake_minimum_required(VERSION 3.20.0)
-project(Runtimes C CXX ASM)

 # Add path for custom and the LLVM build's modules to the CMake module path.
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)
+
+project(Runtimes C CXX ASM)
+
 list(INSERT CMAKE_MODULE_PATH 0
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"

mstorsjo added a commit that referenced this issue Jul 17, 2023
…ehaviour

With the new behaviour, the /MD or similar options aren't added to
e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake.
They can be changed by the cmake variable
CMAKE_MSVC_RUNTIME_LIBRARY or with the target property
MSVC_RUNTIME_LIBRARY.

LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE,
which affects which CRT is used for release mode builds. Deprecate
these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly
instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY
based on the existing LLVM_USE_CRT_ flags). This only handles the
simple cases, it doesn't handle multi-config generators with
different LLVM_USE_CRT_* variables for different configs though,
but that's probably fine - we should move over to the new upstream
CMake mechanism anyway, and push users towards that.

Change code in compiler-rt, that previously tried to override the
CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of
meddling in the old variables.

This resolves the policy issue in
#63286, and should
handle the issues that were observed originally when the
minimum CMake version was bumped, in
#62719 and
#62739.

Differential Revision: https://reviews.llvm.org/D155233
gnoliyil pushed a commit to gnoliyil/fuchsia that referenced this issue Jan 27, 2024
…ersion to 3.20.0.

This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6.

Adds the patch by @hans from
llvm/llvm-project#62719
This patch fixes the Windows build.

d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 reverted the reviews

D144509 [CMake] Bumps minimum version to 3.20.0.

This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

D150532 [OpenMP] Compile assembly files as ASM, not C

Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.

Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.

Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.

D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump

The build uses other mechanism to select the runtime.

Fixes #62719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D151344

GitOrigin-RevId: 53ecfc3277a34dd2809dd76d4c07854de7ba8928
Original-Revision: 528483e0e18ef69085956fa350ca1e0305d5ab75
Roller-URL: https://ci.chromium.org/b/8779938680740208097
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: Icbc27c7586140da89afed38f641ae850a89a34da
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/862996
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Aug 26, 2024
This reverts commit d763c6e.

Adds the patch by @hans from
llvm/llvm-project#62719
This patch fixes the Windows build.

d763c6e reverted the reviews

D144509 [CMake] Bumps minimum version to 3.20.0.

This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

D150532 [OpenMP] Compile assembly files as ASM, not C

Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.

Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.

Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.

D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump

The build uses other mechanism to select the runtime.

Fixes #62719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D151344
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Sep 6, 2024
…ehaviour

With the new behaviour, the /MD or similar options aren't added to
e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake.
They can be changed by the cmake variable
CMAKE_MSVC_RUNTIME_LIBRARY or with the target property
MSVC_RUNTIME_LIBRARY.

LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE,
which affects which CRT is used for release mode builds. Deprecate
these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly
instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY
based on the existing LLVM_USE_CRT_ flags). This only handles the
simple cases, it doesn't handle multi-config generators with
different LLVM_USE_CRT_* variables for different configs though,
but that's probably fine - we should move over to the new upstream
CMake mechanism anyway, and push users towards that.

Change code in compiler-rt, that previously tried to override the
CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of
meddling in the old variables.

This resolves the policy issue in
llvm/llvm-project#63286, and should
handle the issues that were observed originally when the
minimum CMake version was bumped, in
llvm/llvm-project#62719 and
llvm/llvm-project#62739.

Differential Revision: https://reviews.llvm.org/D155233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular compiler-rt
Projects
None yet
Development

No branches or pull requests

5 participants