[clang] [compiler-rt] ohos: fix ohos.c test case error with LLVM_ENABLE_PER_TARGET_RUNTIME_… (PR #121484)

Peng Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 10:26:32 PST 2025


https://github.com/phuang updated https://github.com/llvm/llvm-project/pull/121484

>From 14d95fba0e0142be90d8c72dc8baed7cefc2268d Mon Sep 17 00:00:00 2001
From: Peng Huang <shawn.p.huang at gmail.com>
Date: Thu, 2 Jan 2025 10:21:00 -0500
Subject: [PATCH 1/3] ohos: fix ohos.c test case error with
 LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF

The problem is because libclang_rt.builtins-{arch}.a for all the
arches will be installed into the same folder with old compiler rt
layout (LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF) and OHOS driver will
get a wrong library in this case. To fix the problem, `-ohos`
suffix will be added to the ohos builtin libraries search path.

Note: OHOS driver doesn't support the old layout,
${arch}-linux-unknown-ohos targets have to be built with
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
---
 clang/lib/Driver/ToolChain.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 9f174fbda398b5..06ff0918245ea4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -745,7 +745,11 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args,
   std::string ArchAndEnv;
   if (AddArch) {
     StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
-    const char *Env = TT.isAndroid() ? "-android" : "";
+    const char *Env = "";
+    if (TT.isAndroid())
+      Env = "-android";
+    else if (TT.isOHOSFamily())
+      Env = "-ohos";
     ArchAndEnv = ("-" + Arch + Env).str();
   }
   return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str();

>From 43405a0523587e0f03417fe421dc9bae60d8e27c Mon Sep 17 00:00:00 2001
From: Peng Huang <shawn.p.huang at gmail.com>
Date: Thu, 2 Jan 2025 13:07:24 -0500
Subject: [PATCH 2/3] ohos: make cmake configure fail if
 LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF

---
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 379e2c25949cb4..f74232fb55f39c 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -510,6 +510,11 @@ function(get_compiler_rt_target arch variable)
 endfunction()
 
 function(get_compiler_rt_install_dir arch install_dir)
+  if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+    if (LLVM_TARGET_TRIPLE MATCHES "ohos")
+      message(FATAL_ERROR "ohos targets require LLVM_ENABLE_PER_TARGET_RUNTIME_DIR")
+    endif()
+  endif()
   if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
     get_compiler_rt_target(${arch} target)
     set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE)

>From b41e3c3b8930715d0e7960f3cbc768dba3621298 Mon Sep 17 00:00:00 2001
From: Peng Huang <shawn.p.huang at gmail.com>
Date: Thu, 2 Jan 2025 13:26:23 -0500
Subject: [PATCH 3/3] Update CompilerRTUtils.cmake

---
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index f74232fb55f39c..9189c010575569 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -512,7 +512,7 @@ endfunction()
 function(get_compiler_rt_install_dir arch install_dir)
   if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
     if (LLVM_TARGET_TRIPLE MATCHES "ohos")
-      message(FATAL_ERROR "ohos targets require LLVM_ENABLE_PER_TARGET_RUNTIME_DIR")
+      message(FATAL_ERROR "${LLVM_TARGET_TRIPLE} requires LLVM_ENABLE_PER_TARGET_RUNTIME_DIR")
     endif()
   endif()
   if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)



More information about the llvm-commits mailing list