[libc-commits] [libc] [llvm] [LLVM] Fix and adjust runtime multilibs builds (PR #188303)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed Mar 25 08:48:01 PDT 2026
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/188303
>From 4373cc0fceb751057846cc1f51d0f8ea9441d134 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 24 Mar 2026 13:14:58 -0500
Subject: [PATCH] [LLVM] Fix and adjust runtime multilibs builds
Summary:
This PR primarily changes using `LLVM_RUNTIMES_TARGET` to
`LLVM_DEFAULT_TARGET_TRIPLE`. The reason is that the default target
triple is the true cross-compiling architecture we are using, while the
runtimes_target can contain multilib strings like `+debug` or similar.
Additionally add the proper path handling to the OpenMP / Offload
libraries.
---
flang-rt/CMakeLists.txt | 4 ++--
flang-rt/README.md | 9 ++++-----
flang-rt/cmake/modules/AddFlangRT.cmake | 4 ++--
flang-rt/lib/runtime/CMakeLists.txt | 2 +-
libc/cmake/modules/LLVMLibCArchitectures.cmake | 11 ++++++-----
llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
runtimes/CMakeLists.txt | 2 +-
7 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index 6817279c9547f..23e217cdaf9b7 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -141,7 +141,7 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
# TODO: Support tests for the GPU target.
set(FLANG_RT_INCLUDE_TESTS_default ${LLVM_INCLUDE_TESTS})
-if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
set(FLANG_RT_INCLUDE_TESTS_default OFF)
endif()
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${FLANG_RT_INCLUDE_TESTS_default}")
@@ -263,7 +263,7 @@ find_package(Threads)
# FIXME: The NVPTX target will erroneously report it has backtrace support. This
# is caused by using "-c -flto" in the required flags to suppress CUDA
# tools from being required for the CMake flag checks to succeed.
-if (NOT "${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+if (NOT "${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
find_package(Backtrace)
endif()
set(HAVE_BACKTRACE ${Backtrace_FOUND})
diff --git a/flang-rt/README.md b/flang-rt/README.md
index a7dde887b31ef..68bc9c9f60574 100644
--- a/flang-rt/README.md
+++ b/flang-rt/README.md
@@ -112,11 +112,10 @@ The `CMAKE_Fortran_COMPILER_WORKS` parameter must be set because otherwise CMake
will test whether the Fortran compiler can compile and link programs which will
obviously fail without a runtime library available yet.
-Building Flang-RT for cross-compilation triple, the target triple can
-be selected using `LLVM_DEFAULT_TARGET_TRIPLE` AND `LLVM_RUNTIMES_TARGET`.
-Of course, Flang-RT can be built multiple times with different build
-configurations, but have to be located manually when using with the Flang
-driver using the `-L` option.
+Building Flang-RT for cross-compilation triple, the target triple can be
+selected using `LLVM_DEFAULT_TARGET_TRIPLE`. Of course, Flang-RT can be built
+multiple times with different build configurations, but have to be located
+manually when using with the Flang driver using the `-L` option.
After configuration, build, test, and install the runtime via
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index 7c416ea77b88c..4590aab5cb415 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -269,11 +269,11 @@ function (add_flangrt_library name)
endif ()
# Add target specific options if necessary.
- if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
+ if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden>
)
- elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+ elseif ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index a524aeba666db..b824727c72e47 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -183,7 +183,7 @@ else ()
set(f128_sources "")
endif ()
-if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
set(sources ${gpu_sources})
elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
set(sources ${supported_sources})
diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index bb96c07b1e7a7..b24ea353df484 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -98,21 +98,22 @@ string(SUBSTRING ${libc_compiler_target_info} 8 -1 libc_compiler_triple)
# One should not set LLVM_RUNTIMES_TARGET and LIBC_TARGET_TRIPLE
if(LLVM_RUNTIMES_TARGET AND LIBC_TARGET_TRIPLE)
message(FATAL_ERROR
- "libc build: Specify only LLVM_RUNTIMES_TARGET if you are doing a "
+ "libc build: Specify only LLVM_DEFAULT_TARGET_TRIPLE if you are doing a "
"runtimes/bootstrap build. If you are doing a standalone build, "
"specify only LIBC_TARGET_TRIPLE.")
endif()
set(explicit_target_triple)
if(LLVM_RUNTIMES_TARGET)
- set(explicit_target_triple ${LLVM_RUNTIMES_TARGET})
+ # LLVM_RUNTIMES_TARGET may contain multilib flags, use the clean triple.
+ set(explicit_target_triple ${LLVM_DEFAULT_TARGET_TRIPLE})
elseif(LIBC_TARGET_TRIPLE)
set(explicit_target_triple ${LIBC_TARGET_TRIPLE})
endif()
# The libc's target architecture and OS are set to match the compiler's default
# target triple above. However, one can explicitly set LIBC_TARGET_TRIPLE or
-# LLVM_RUNTIMES_TARGET (for runtimes/bootstrap build). If one of them is set,
+# LLVM_DEFAULT_TARGET_TRIPLE (for runtimes/bootstrap build). If one of them is set,
# then we will use that target triple to deduce libc's target OS and
# architecture.
if(explicit_target_triple)
@@ -124,7 +125,7 @@ if(explicit_target_triple)
set(LIBC_TARGET_ARCHITECTURE ${libc_arch})
set(LIBC_TARGET_OS ${libc_sys})
# If the compiler target triple is not the same as the triple specified by
- # LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
+ # LIBC_TARGET_TRIPLE or LLVM_DEFAULT_TARGET_TRIPLE, we will add a --target option
# if the compiler is clang. If the compiler is GCC we just error out as there
# is no equivalent of an option like --target.
if(NOT libc_compiler_triple STREQUAL explicit_target_triple)
@@ -216,7 +217,7 @@ else()
endif()
# If the compiler target triple is not the same as the triple specified by
-# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
+# LIBC_TARGET_TRIPLE or LLVM_DEFAULT_TARGET_TRIPLE, we will add a --target option
# if the compiler is clang. If the compiler is GCC we just error out as there
# is no equivalent of an option like --target.
if(explicit_target_triple AND
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 21fec1d064ff8..f645de1277687 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1159,7 +1159,7 @@ if (UNIX AND
endif()
# lld doesn't print colored diagnostics when invoked from Ninja
-if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT "${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx64")
+if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT "${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx64")
include(CheckLinkerFlag)
check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index c12e2406b5d0c..b067fe97be271 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -191,7 +191,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
endif()
# The NVPTX target needs to override linking to pass compiler flag checks.
-if("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
endif()
More information about the libc-commits
mailing list