Skip to content

Commit e9c6a33

Browse files
Meinersburgithub-actions[bot]
authored andcommitted
Automerge: Remember LLVM_ENABLE_LIBCXX setting in installed configuration (#139712)
Updated version of #134990 which was reverted because of the buildbot [openmp-offload-amdgpu-runtime-2](https://lab.llvm.org/buildbot/#/builders/10) failing. Its configuration has `LLVM_ENABLE_LIBCXX=ON` set although it does not even have libc++ installed. In addition to #134990, this PR adds a check whether C++ libraries are actually available. `#include <chrono>` was chosen because this is the library that [openmp-offload-amdgpu-runtime-2 failed with](llvm/llvm-project#134990 (comment)). Original summary: The buidbot [flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89) is currently failing with an ABI issue. The suspected reason is that LLVMSupport.a is built using libc++, but the unittests are using the default C++ standard library, libstdc++ in this case. This predefined `llvm_gtest` target uses the LLVMSupport from `find_package(LLVM)`, which finds the libc++-built LLVMSupport. To fix, store the `LLVM_ENABLE_LIBCXX` setting in the LLVMConfig.cmake such that everything that links to LLVM libraries use the same standard library. In this case discussed in llvm/llvm-zorg#387 it was the flang-rt unittests, but other runtimes with GTest unittests should have the same issue (e.g. offload), and any external project that uses `find_package(LLVM)`. This patch fixed the problem for me locally.
2 parents 8a03040 + b010b7e commit e9c6a33

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/cmake/modules/HandleLLVMStdlib.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# if the user has requested it.
33

44
include(DetermineGCCCompatible)
5+
include(CheckIncludeFiles)
56

67
if(NOT DEFINED LLVM_STDLIB_HANDLED)
78
set(LLVM_STDLIB_HANDLED ON)
@@ -19,7 +20,17 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
1920
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
2021
check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB)
2122
check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
22-
if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB)
23+
24+
# Check whether C++ include files are available
25+
# runtimes/CMakeLists.txt adds -nostdlib++ and -nostdinc++ to
26+
# CMAKE_REQUIRED_FLAGS, which are incompatible with -stdlib=libc++; use
27+
# a fresh CMAKE_REQUIRED_FLAGS environment.
28+
cmake_push_check_state(RESET)
29+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
30+
check_include_files("chrono" CXX_COMPILER_SUPPORTS_STDLIB_CHRONO LANGUAGE CXX)
31+
cmake_pop_check_state()
32+
33+
if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB AND CXX_COMPILER_SUPPORTS_STDLIB_CHRONO)
2334
append("-stdlib=libc++"
2435
CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
2536
CMAKE_MODULE_LINKER_FLAGS)

llvm/cmake/modules/LLVMConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ endif()
5555

5656
set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@)
5757

58+
set(LLVM_ENABLE_LIBCXX @LLVM_ENABLE_LIBCXX@)
59+
5860
set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
5961
if(LLVM_ENABLE_LIBEDIT)
6062
find_package(LibEdit)

0 commit comments

Comments
 (0)