From 47ce6f5bd09472a46a576d3d223d0d6327d8401b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 2 Feb 2026 07:29:35 +0900 Subject: [PATCH] internal/rosa/llvm: conditionally add Rosa OS paths This change also moves rpath flags to a more appropriate method. Signed-off-by: Ophestra --- internal/rosa/llvm.go | 93 +++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go index 632a79f..67baea9 100644 --- a/internal/rosa/llvm.go +++ b/internal/rosa/llvm.go @@ -395,58 +395,81 @@ index cdbf21fb9026..dd052858700d 100644 addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); `}, - {"path-system-libraries", `diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp -index 8d3775de9be5..5200b2a4d37d 100644 ---- a/clang/lib/Driver/ToolChains/CommonArgs.cpp -+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp -@@ -463,6 +463,13 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, - if (!TC.isCrossCompiling()) - addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); - -+ if (TC.getTriple().getVendor() == llvm::Triple::Rosa) { -+ CmdArgs.push_back("-rpath"); -+ CmdArgs.push_back("/system/lib"); -+ CmdArgs.push_back("-rpath"); -+ CmdArgs.push_back(("/system/lib/" + TC.getTripleString()).c_str()); -+ } -+ - for (const auto &II : Inputs) { - // If the current tool chain refers to an OpenMP offloading host, we - // should ignore inputs that refer to OpenMP offloading devices - -diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp -index 8ac8d4eb9181..7d2d8541aca9 100644 + {"path-system-libraries", `diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp +index 8ac8d4eb9181..f4d1347ab64d 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp -@@ -324,6 +324,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) +@@ -282,6 +282,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + const bool IsHexagon = Arch == llvm::Triple::hexagon; + const bool IsRISCV = Triple.isRISCV(); + const bool IsCSKY = Triple.isCSKY(); ++ const bool IsRosa = Triple.getVendor() == llvm::Triple::Rosa; + + if (IsCSKY && !SelectedMultilibs.empty()) + SysRoot = SysRoot + SelectedMultilibs.back().osSuffix(); +@@ -318,12 +319,23 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + const std::string OSLibDir = std::string(getOSLibDir(Triple, Args)); + const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); + ++ if (IsRosa) { ++ ExtraOpts.push_back("-rpath"); ++ ExtraOpts.push_back("/system/lib"); ++ ExtraOpts.push_back("-rpath"); ++ ExtraOpts.push_back(concat("/system/lib", MultiarchTriple)); ++ } ++ + // mips32: Debian multilib, we use /libo32, while in other case, /lib is + // used. We need add both libo32 and /lib. + if (Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel) { Generic_GCC::AddMultilibPaths(D, SysRoot, "libo32", MultiarchTriple, Paths); - addPathIfExists(D, concat(SysRoot, "/libo32"), Paths); - addPathIfExists(D, concat(SysRoot, "/usr/libo32"), Paths); -+ addPathIfExists(D, concat(SysRoot, "/system/libo32"), Paths); +- addPathIfExists(D, concat(SysRoot, "/libo32"), Paths); +- addPathIfExists(D, concat(SysRoot, "/usr/libo32"), Paths); ++ if (!IsRosa) { ++ addPathIfExists(D, concat(SysRoot, "/libo32"), Paths); ++ addPathIfExists(D, concat(SysRoot, "/usr/libo32"), Paths); ++ } else { ++ addPathIfExists(D, concat(SysRoot, "/system/libo32"), Paths); ++ } } Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths); -@@ -343,16 +344,20 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) +@@ -341,18 +353,30 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + Paths); + } - addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths); - addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths); -+ addPathIfExists(D, concat(SysRoot, "/system/lib", MultiarchTriple), Paths); -+ addPathIfExists(D, concat(SysRoot, "/system", OSLibDir), Paths); +- addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths); +- addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths); ++ if (!IsRosa) { ++ addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths); ++ addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths); ++ } else { ++ addPathIfExists(D, concat(SysRoot, "/system/lib", MultiarchTriple), Paths); ++ addPathIfExists(D, concat(SysRoot, "/system", OSLibDir), Paths); ++ } if (IsRISCV) { StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); addPathIfExists(D, concat(SysRoot, "/", OSLibDir, ABIName), Paths); - addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir, ABIName), Paths); -+ addPathIfExists(D, concat(SysRoot, "/system", OSLibDir, ABIName), Paths); +- addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir, ABIName), Paths); ++ if (!IsRosa) ++ addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir, ABIName), Paths); ++ else ++ addPathIfExists(D, concat(SysRoot, "/system", OSLibDir, ABIName), Paths); } Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths); - addPathIfExists(D, concat(SysRoot, "/lib"), Paths); - addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths); -+ addPathIfExists(D, concat(SysRoot, "/system/lib"), Paths); +- addPathIfExists(D, concat(SysRoot, "/lib"), Paths); +- addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths); ++ if (!IsRosa) { ++ addPathIfExists(D, concat(SysRoot, "/lib"), Paths); ++ addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths); ++ } else { ++ addPathIfExists(D, concat(SysRoot, "/system/lib"), Paths); ++ } } ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const { -@@ -457,6 +462,9 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { +@@ -457,6 +481,9 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; } if (Triple.isMusl()) {