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

Peng Huang via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 2 07:34:26 PST 2025


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

…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, compiler-rt for ${arch}-linux-unknown-ohos targets have to be built with
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON

>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] 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();



More information about the cfe-commits mailing list