[clang] [compiler-rt] ohos: make configure fail if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF (PR #121575)
Peng Huang via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 3 06:52:13 PST 2025
https://github.com/phuang created https://github.com/llvm/llvm-project/pull/121575
OHOS driver doesn't support old runtime libraries layout, so make cmake configure report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF.
[Driver][OHOS] Fix lld link issue
The link error is becasue clang rt libraries are installed in lib/${arch}-linux-unknown-ohos/ folder, however OHOS driver searches libraries in lib/${arch}-linux-ohos/ folder. Fix the problem by searching libraries in both lib/${arch}-linux-ohos/ and lib/${arch}-linux-unknown-ohos/
Also make cmake report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is not used for building OHOS runtime, since OHOS driver doesn't support the old layout
>From 9e9a457fc1f57f1fb233e48a694336c2985f7414 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] ohos: make configure fail if
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF
OHOS driver doesn't support old runtime libraries layout, so make
cmake configure report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
is OFF.
[Driver][OHOS] Fix lld link issue
The link error is becasue clang rt libraries are installed in
lib/${arch}-linux-unknown-ohos/ folder, however OHOS driver
searches libraries in lib/${arch}-linux-ohos/ folder. Fix the
problem by searching libraries in both lib/${arch}-linux-ohos/ and
lib/${arch}-linux-unknown-ohos/
Also make cmake report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
is not used for building OHOS runtime, since OHOS driver doesn't
support the old layout
---
clang/lib/Driver/ToolChains/OHOS.cpp | 64 +++++++++----------
.../cmake/Modules/CompilerRTUtils.cmake | 5 ++
2 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2f..a4137ba0416a7a 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -19,8 +19,8 @@
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/VirtualFileSystem.h"
using namespace clang::driver;
using namespace clang::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
return false;
}
-static bool findOHOSMultilibs(const Driver &D,
- const ToolChain &TC,
- const llvm::Triple &TargetTriple,
- StringRef Path, const ArgList &Args,
- DetectedMultilibs &Result) {
+static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
+ const llvm::Triple &TargetTriple, StringRef Path,
+ const ArgList &Args, DetectedMultilibs &Result) {
Multilib::flags_list Flags;
bool IsA7 = false;
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Paths);
}
-ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
- const ArgList &Args) const {
+ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
StringRef Value = A->getValue();
if (Value != "compiler-rt")
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
return ToolChain::RLT_CompilerRT;
}
-ToolChain::CXXStdlibType
-OHOS::GetCXXStdlibType(const ArgList &Args) const {
+ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
StringRef Value = A->getValue();
if (Value != "libc++")
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
- << A->getAsString(Args);
+ << A->getAsString(Args);
}
return ToolChain::CST_Libcxx;
}
void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
- ArgStringList &CC1Args) const {
+ ArgStringList &CC1Args) const {
const Driver &D = getDriver();
const llvm::Triple &Triple = getTriple();
std::string SysRoot = computeSysRoot();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
}
void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
- ArgStringList &CmdArgs) const {
+ ArgStringList &CmdArgs) const {
switch (GetCXXStdlibType(Args)) {
case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++");
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
// First try the triple passed to driver as --target=<triple>.
P.assign(D.ResourceDir);
- llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix());
+ llvm::sys::path::append(P, "lib", D.getTargetTriple(),
+ SelectedMultilib.gccSuffix());
Paths.push_back(P.c_str());
// Second try the normalized triple.
@@ -340,26 +337,26 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const {
std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
FileType Type) const {
+ std::string CRTBasename =
+ buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+
+ // Search libraries in ${arch}-linux-ohos directory first.
SmallString<128> Path(getDriver().ResourceDir);
llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
- SelectedMultilib.gccSuffix());
- const char *Prefix =
- Type == ToolChain::FT_Object ? "" : "lib";
- const char *Suffix;
- switch (Type) {
- case ToolChain::FT_Object:
- Suffix = ".o";
- break;
- case ToolChain::FT_Static:
- Suffix = ".a";
- break;
- case ToolChain::FT_Shared:
- Suffix = ".so";
- break;
+ SelectedMultilib.gccSuffix(), CRTBasename);
+
+ if (getVFS().exists(Path))
+ return std::string(Path);
+
+ // Search libraries in ${arch}-unknown-linux-ohos directory.
+ for (const auto &LibPath : getLibraryPaths()) {
+ SmallString<128> P(LibPath);
+ llvm::sys::path::append(P, CRTBasename);
+ if (getVFS().exists(P))
+ return std::string(P);
}
- llvm::sys::path::append(
- Path, Prefix + Twine("clang_rt.") + Component + Suffix);
- return static_cast<std::string>(Path.str());
+
+ return std::string(Path);
}
void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
@@ -396,7 +393,7 @@ SanitizerMask OHOS::getSupportedSanitizers() const {
// TODO: Make a base class for Linux and OHOS and move this there.
void OHOS::addProfileRTLibs(const llvm::opt::ArgList &Args,
- llvm::opt::ArgStringList &CmdArgs) const {
+ llvm::opt::ArgStringList &CmdArgs) const {
// Add linker option -u__llvm_profile_runtime to cause runtime
// initialization module to be linked in.
if (needsProfileRT(Args))
@@ -413,7 +410,8 @@ ToolChain::path_list OHOS::getArchSpecificLibPaths() const {
return Paths;
}
-ToolChain::UnwindLibType OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
+ToolChain::UnwindLibType
+OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
if (Args.getLastArg(options::OPT_unwindlib_EQ))
return Generic_ELF::GetUnwindLibType(Args);
return GetDefaultUnwindLibType();
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 379e2c25949cb4..9189c010575569 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 "${LLVM_TARGET_TRIPLE} requires 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)
More information about the llvm-commits
mailing list