https://github.com/zeroomega created 
https://github.com/llvm/llvm-project/pull/210496

…468)

This reverts commit 42eb7db188f23625872b6f1d722979a3100d170e. This reland 
3fbb037d03e7ff1ef1cd9156363e895af7caaf98 (#209922).

Under CMake 4+, calling add_library(... SHARED IMPORTED) on a target platform 
that lacks dynamic linking support triggers a fatal error. This becomes an 
issue when building LLVM and runtimes for baremetal targets like 
armv6m-none-eabi. This patch adds the option "LLVM_OMIT_EXPORTS_FROM_CONFIG" in 
LLVM. When used in sub builds like LLVM runtimes, it makes CMake to skip 
including the LLVM and Clang exports. This mitigates the CMake 4 errors on 
baremetal runtimes.

#[209922](https://github.com/llvm/llvm-project/pull/209922) originally apply 
this flag on all runtimes build and causing issues on runtimes like 
intel-sycl-gpu, amdgpu-offload-ubuntu-22-cmake-build-only.

This PR only set this flag when the target platform lacks shared library support

>From 6f10fe287ea9650066d262f38495ae1079e1f91c Mon Sep 17 00:00:00 2001
From: Haowei Wu <[email protected]>
Date: Fri, 17 Jul 2026 17:26:19 -0700
Subject: [PATCH] Reapply "Skipping host target exports during
 cross-compilation" (#210468)

This reverts commit 42eb7db188f23625872b6f1d722979a3100d170e.
This reland 3fbb037d03e7ff1ef1cd9156363e895af7caaf98 (#209922).

Under CMake 4+, calling add_library(... SHARED IMPORTED) on a
target platform that lacks dynamic linking support triggers a fatal
error. This becomes an issue when building LLVM and runtimes for
baremetal targets like armv6m-none-eabi. This patch
adds the option "LLVM_OMIT_EXPORTS_FROM_CONFIG" in LLVM.
When used in sub builds like LLVM runtimes, it makes CMake to skip
including the LLVM and Clang exports. This mitigates the CMake 4
errors on baremetal runtimes.
---
 clang/cmake/modules/ClangConfig.cmake.in        |  9 +++++++--
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 10 ++++++++++
 llvm/cmake/modules/LLVMConfig.cmake.in          |  2 +-
 runtimes/CMakeLists.txt                         | 10 ++++++++++
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 68f723d050117..3550c393d492d 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -12,8 +12,13 @@ set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_INCLUDE_DIRS@")
 set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
 set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@")
 
-# Provide all our library targets to users.
-@CLANG_CONFIG_INCLUDE_EXPORTS@
+# Provide all our library targets to users. Skip when
+# LLVM_OMIT_EXPORTS_FROM_CONFIG flag is set. Runtimes build do not need these.
+# These exports may contain shared libraries and they are causing cmake errors
+# when the target platform is baremetal, which lack shared library support.
+if(NOT LLVM_OMIT_EXPORTS_FROM_CONFIG)
+  @CLANG_CONFIG_INCLUDE_EXPORTS@
+endif()
 
 # By creating clang-tablegen-targets here, subprojects that depend on Clang's
 # tablegen-generated headers can always depend on this target whether building
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake 
b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index c2bf2e54b9fd4..63e52327e3ccc 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -313,6 +313,16 @@ macro(load_llvm_config)
       "You are not using the monorepo layout. This configuration is 
DEPRECATED.")
   endif()
 
+  # Exports from LLVM and Clang may contain shared libraries. When targeting
+  # baremetal platforms that lacks shared library support, importing such
+  # exports unrestrictedly will trigger cmake errors. Set
+  # LLVM_OMIT_EXPORTS_FROM_CONFIG flag to skip importing these exports
+  # when the target platform does not support shared library.
+  get_property(HAS_SHARED_SUPPORT GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+  message(NOTICE "HAS_SHARED_SUPPORT is ${HAS_SHARED_SUPPORT}")
+  if (NOT HAS_SHARED_SUPPORT)
+    set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
+  endif()
   find_package(LLVM HINTS "${LLVM_CMAKE_DIR}")
   if (NOT LLVM_FOUND)
      message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in 
b/llvm/cmake/modules/LLVMConfig.cmake.in
index 300c25e7c6101..6f5fcc6a926f9 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -152,7 +152,7 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)
 set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
 set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")
 
-if(NOT TARGET LLVMSupport)
+if(NOT TARGET LLVMSupport AND NOT LLVM_OMIT_EXPORTS_FROM_CONFIG)
   @LLVM_CONFIG_INCLUDE_EXPORTS@
   @llvm_config_include_buildtree_only_exports@
 endif()
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 67ed49a7dcabb..4d90a30d1f2f3 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -76,6 +76,16 @@ if(LLVM_BINARY_DIR)
   list(APPEND llvm_search_paths 
"${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
   list(APPEND clang_search_paths 
"${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang")
 endif()
+
+# Exports from LLVM and Clang may contain shared libraries. When targeting
+# baremetal platforms that lacks shared library support, importing such
+# exports unrestrictedly will trigger cmake errors. Set
+# LLVM_OMIT_EXPORTS_FROM_CONFIG flag to skip importing these exports.
+get_property(HAS_SHARED_SUPPORT GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+message(NOTICE "HAS_SHARED_SUPPORT is ${HAS_SHARED_SUPPORT}")
+if (NOT HAS_SHARED_SUPPORT)
+  set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
+endif()
 find_package(LLVM PATHS ${llvm_search_paths} NO_DEFAULT_PATH 
NO_CMAKE_FIND_ROOT_PATH)
 find_package(Clang PATHS ${clang_search_paths} NO_DEFAULT_PATH 
NO_CMAKE_FIND_ROOT_PATH)
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to