-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[runtimes] remove workaround for old CMake when setting --unwindlib=none
#93429
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
base: main
Are you sure you want to change the base?
Conversation
Hm, this seems to affect some feature detection (and constraints) later on, though I don't see why/how removing the specification of llvm-project/libunwind/src/CMakeLists.txt Lines 99 to 106 in 1c046ca
|
I think something else is going on. The CMake configuration as a whole is failing, the logs show:
This shouldn't be affected by this patch, but somehow it is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW this LGTM if we can make it work -- this is a great cleanup, thanks for noticing.
The interesting thing is that everything past that check is failing, which somehow looks like it's corrupting some (CMake's?) state somehow:
|
@llvm/pr-subscribers-libunwind @llvm/pr-subscribers-clang Author: None (h-vetinari) ChangesNoticed a left-over for old CMake, irrelevant now that the baseline version moved to 3.20. Full diff: https://github.com/llvm/llvm-project/pull/93429.diff 6 Files Affected:
diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt
index 290bf2a42536d..018605c2fd4f2 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -107,7 +107,7 @@ endif()
if(CLANG_ORDER_FILE AND
(LLVM_LINKER_IS_APPLE OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
- include(LLVMCheckLinkerFlag)
+ include(CheckLinkerFlag)
if (LLVM_LINKER_IS_APPLE OR (LLVM_LINKER_IS_LLD AND APPLE))
set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
@@ -118,7 +118,7 @@ if(CLANG_ORDER_FILE AND
endif()
# This is a test to ensure the actual order file works with the linker.
- llvm_check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
+ check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
# Passing an empty order file disables some linker layout optimizations.
# To work around this and enable workflows for re-linking when the order file
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 03f4e1f190fd9..cac5470435d91 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -327,8 +327,8 @@ function(add_link_opts target_name)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
# Support for ld -z discard-unused=sections was only added in
# Solaris 11.4. GNU ld ignores it, but warns every time.
- include(LLVMCheckLinkerFlag)
- llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
+ include(CheckLinkerFlag)
+ check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-z,discard-unused=sections")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 99d848ba3d853..4ec9dc3a3b571 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1061,8 +1061,8 @@ if (LLVM_USE_SPLIT_DWARF AND
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-gsplit-dwarf>)
- include(LLVMCheckLinkerFlag)
- llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
+ include(CheckLinkerFlag)
+ check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index"
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
@@ -1084,7 +1084,7 @@ endif()
# lld doesn't print colored diagnostics when invoked from Ninja
if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja")
include(LLVMCheckLinkerFlag)
- llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
+ check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
diff --git a/llvm/cmake/modules/HandleLLVMStdlib.cmake b/llvm/cmake/modules/HandleLLVMStdlib.cmake
index 7afc10cff74ff..a7e138aa0789b 100644
--- a/llvm/cmake/modules/HandleLLVMStdlib.cmake
+++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake
@@ -13,12 +13,12 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
endfunction()
include(CheckCXXCompilerFlag)
- include(LLVMCheckLinkerFlag)
+ include(CheckLinkerFlag)
set(LLVM_LIBCXX_USED 0)
if(LLVM_ENABLE_LIBCXX)
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB)
- llvm_check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
+ check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB)
append("-stdlib=libc++"
CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
@@ -36,7 +36,7 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
check_cxx_compiler_flag("-static-libstdc++"
CXX_COMPILER_SUPPORTS_STATIC_STDLIB)
- llvm_check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB)
+ check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB)
if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND
CXX_LINKER_SUPPORTS_STATIC_STDLIB)
append("-static-libstdc++"
diff --git a/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake b/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake
deleted file mode 100644
index e09bbc66f2d26..0000000000000
--- a/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake
+++ /dev/null
@@ -1,28 +0,0 @@
-include(CheckLinkerFlag OPTIONAL)
-
-if (COMMAND check_linker_flag)
- macro(llvm_check_linker_flag)
- check_linker_flag(${ARGN})
- endmacro()
-else()
- # Until the minimum CMAKE version is 3.18
-
- include(CheckCXXCompilerFlag)
-
- # cmake builtin compatible, except we assume lang is C or CXX
- function(llvm_check_linker_flag lang flag out_var)
- cmake_policy(PUSH)
- cmake_policy(SET CMP0056 NEW)
- set(_CMAKE_EXE_LINKER_FLAGS_SAVE ${CMAKE_EXE_LINKER_FLAGS})
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
- if("${lang}" STREQUAL "C")
- check_c_compiler_flag("" ${out_var})
- elseif("${lang}" STREQUAL "CXX")
- check_cxx_compiler_flag("" ${out_var})
- else()
- message(FATAL_ERROR "\"${lang}\" is not C or CXX")
- endif()
- set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE})
- cmake_policy(POP)
- endfunction()
-endif()
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 24f4851169591..15f9334776e05 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -116,27 +116,7 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C
# brittle. We should ideally move this to runtimes/CMakeLists.txt.
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
- set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none")
- # TODO: When we can require CMake 3.14, we should use
- # CMAKE_REQUIRED_LINK_OPTIONS here. Until then, we need a workaround:
- # When using CMAKE_REQUIRED_FLAGS, this option gets added both to
- # compilation and linking commands. That causes warnings in the
- # compilation commands during cmake tests. This is normally benign, but
- # when testing whether -Werror works, that test fails (due to the
- # preexisting warning).
- #
- # Therefore, before we can use CMAKE_REQUIRED_LINK_OPTIONS, check if we
- # can use --start-no-unused-arguments to silence the warnings about
- # --unwindlib=none during compilation.
- #
- # We must first add --unwindlib=none to CMAKE_REQUIRED_FLAGS above, to
- # allow this subsequent test to succeed, then rewrite CMAKE_REQUIRED_FLAGS
- # below.
- check_c_compiler_flag("--start-no-unused-arguments" C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
- if (C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
- set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS} --start-no-unused-arguments --unwindlib=none --end-no-unused-arguments")
- endif()
+ set(CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS} --unwindlib=none")
endif()
# Disable use of the installed C++ standard library when building runtimes.
|
Found some more CMake cruft... Unfortunately, it doesn't improve the situation with libunwind, but at least that means I should be able to break this out into a separate PR. |
I think the riddle may be explained by @mstorsjo's excellent commit message from 4169b52 (which I just found):
... which is indeed what libunwind specifies: llvm-project/libunwind/CMakeLists.txt Line 224 in 6859685
|
I actually tested doing this cleanup back around when I wrote this - sorry I never got around to amending the comment here explaining what has to be done. The case with libunwind is a bit non-obvious. I rebased my test change from 2022, see mstorsjo@runtimes-link-options-unwindlib-none. Can you try this out and see if it fixes the issue you're seeing? |
…ng of the --unwindlib=none option This avoids passing the option unnecessarily to compilation commands (where it causes warnings). This fails in practice with libunwind, where setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY breaks it, as the option from CMAKE_REQUIRED_LINK_OPTIONS ends up passed to the "ar" tool too.
Haha, just when I realized the key to the whole thing - luckily my comment won the race condition at least. ;-) Thanks a lot for the fix, I've pulled it into the PR (also rebased on main while I'm at it) - and CI didn't fail as previously, so this looks great! Thank you! |
Ok, good! Btw, it might be good to add a reference to https://gitlab.kitware.com/cmake/cmake/-/issues/23454 in the new commit message too (or perhaps even in a comment in libunwind/CMakeLists.txt?), to clarify that this is indeed not a bug but expected behaviour. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The CI failures are flakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think some of the libunwind failures on BuildKite are legitimate. See https://buildkite.com/llvm-project/libcxx-ci/builds/35920.
Yeah, it looks like the picolib-noexceptions build is still trying to actually build the exceptions, and then fails to find the symbols when linking. I've tried looking for anything that would switch arm/pico or the I do not think I'll be able to fix this without some help, or at least pointers. |
I looked into it and I don't quite understand. We should definitely be building with
There should not be references to these functions since we're building without exceptions. Pinging the bot owner @mplatings |
Linaro will look into this. Reproducing the build is quite easy if you do want to look yourselves in the meantime:
You'll need a recent |
I may be missing something, but it looks like the armv7m-picolibc-no-exceptions issue is still related to https://gitlab.kitware.com/cmake/cmake/-/issues/23454 I notice that once the This is probably due to the fact that for Armv7M-picolibc, |
w.r.t. interference between CMAKE_REQUIRED_LINK_OPTIONS and static libraries
…lags_if_supported
…lags_if_supported
So I've been trying to follow down the rabbit hole of the failing flag checks, and it seems the combination of I'm not claiming that adding the |
That's probably not possible... The point is that when bootstrapping a new sysroot from scratch (i.e. building the initial libunwind etc), in a configuration where libunwind is linked in automatically, every test that tries to do linking will fail (as it implicitly tries to link in libunwind, which does not exist yet). Therefore, we need to add Also, in general, setting So that cmake issue seems to be really, really unfortunate here. :-( I wonder if the cure is worse than the disease here - and if it would be better to just keep what we have now - and simplify it only if cmake adds something like |
Yup, that's a distinct possibility IMO...
It would probably make sense to report back on the CMake issue how big the fallout from this is? Perhaps the CMake devs would reconsider, or at least take it as an indicator for the necessity of |
Broken out from #93429 Somewhat closing the loop opened by 7017e6c. Co-authored-by: Ryan Prichard <[email protected]>
instead, teach existing llvm_check_compiler_linker_flag to do it
I'm trying another approach here (now that #96171 showed we cannot get rid of There's not so many callers in the code base that this looks infeasible per se, but people might want to design the API differently (e.g. have a dedicated helper function for the case under consideration here). I'm also expecting this to break in various ways until I've figured out the right invocations everywhere. There's also several implementations of |
Noticed a left-over for old CMake, irrelevant now that the baseline version moved to 3.20.