diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go index 1db7e6d7..3d6766f5 100644 --- a/internal/rosa/llvm.go +++ b/internal/rosa/llvm.go @@ -10,6 +10,13 @@ import ( "hakurei.app/internal/pkg" ) +// llvmSource is the unpatched upstream LLVM monorepo. +var llvmSource = newFromGitHub( + "llvm/llvm-project", + "llvmorg-"+llvmVersion, + llvmChecksum, +) + // llvmAttr holds the attributes that will be applied to a new [pkg.Artifact] // containing a LLVM variant. type llvmAttr struct { @@ -116,27 +123,8 @@ func (t Toolchain) newLLVMVariant(variant string, attr *llvmAttr) pkg.Artifact { cmakeAppend = attr.append } - return t.NewPackage("llvm", llvmVersion, newFromGitHub( - "llvm/llvm-project", - "llvmorg-"+llvmVersion, - llvmChecksum, - ), &PackageAttr{ - Patches: slices.Concat(attr.patches, []KV{ - {"increase-stack-size-unconditional", `diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp -index 9da357a7ebb9..b2931510c1ae 100644 ---- a/llvm/lib/Support/Threading.cpp -+++ b/llvm/lib/Support/Threading.cpp -@@ -80,7 +80,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { - // keyword. - #include "llvm/Support/thread.h" - --#if defined(__APPLE__) -+#if defined(__APPLE__) || 1 - // Darwin's default stack size for threads except the main one is only 512KB, - // which is not enough for some/many normal LLVM compilations. This implements - // the same interface as std::thread but requests the same stack size as the -`}, - }), + return t.NewPackage("llvm", llvmVersion, llvmSource, &PackageAttr{ + Patches: slices.Concat(attr.patches, llvmPatches), NonStage0: attr.nonStage0, Env: slices.Concat([]string{ @@ -303,180 +291,6 @@ ln -s clang++ /work/system/bin/c++ ninja check-all `, - - patches: []KV{ - {"add-rosa-vendor", `diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h -index 9c83abeeb3b1..5acfe5836a23 100644 ---- a/llvm/include/llvm/TargetParser/Triple.h -+++ b/llvm/include/llvm/TargetParser/Triple.h -@@ -190,6 +190,7 @@ public: - - Apple, - PC, -+ Rosa, - SCEI, - Freescale, - IBM, -diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp -index a4f9dd42c0fe..cb5a12387034 100644 ---- a/llvm/lib/TargetParser/Triple.cpp -+++ b/llvm/lib/TargetParser/Triple.cpp -@@ -279,6 +279,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) { - case NVIDIA: return "nvidia"; - case OpenEmbedded: return "oe"; - case PC: return "pc"; -+ case Rosa: return "rosa"; - case SCEI: return "scei"; - case SUSE: return "suse"; - case Meta: -@@ -689,6 +690,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { - return StringSwitch(VendorName) - .Case("apple", Triple::Apple) - .Case("pc", Triple::PC) -+ .Case("rosa", Triple::Rosa) - .Case("scei", Triple::SCEI) - .Case("sie", Triple::SCEI) - .Case("fsl", Triple::Freescale) -`}, - - {"xfail-broken-tests", `diff --git a/clang/test/Modules/timestamps.c b/clang/test/Modules/timestamps.c -index 50fdce630255..4b4465a75617 100644 ---- a/clang/test/Modules/timestamps.c -+++ b/clang/test/Modules/timestamps.c -@@ -1,3 +1,5 @@ -+// XFAIL: target={{.*-rosa-linux-musl}} -+ - /// Verify timestamps that gets embedded in the module - #include - -`}, - - {"path-system-include", `diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp -index 8ac8d4eb9181..e46b04a898ca 100644 ---- a/clang/lib/Driver/ToolChains/Linux.cpp -+++ b/clang/lib/Driver/ToolChains/Linux.cpp -@@ -671,6 +671,12 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - addExternCSystemInclude( - DriverArgs, CC1Args, - concat(SysRoot, "/usr/include", MultiarchIncludeDir)); -+ if (!MultiarchIncludeDir.empty() && -+ D.getVFS().exists(concat(SysRoot, "/system/include", MultiarchIncludeDir))) -+ addExternCSystemInclude( -+ DriverArgs, CC1Args, -+ concat(SysRoot, "/system/include", MultiarchIncludeDir)); -+ - - if (getTriple().getOS() == llvm::Triple::RTEMS) - return; -@@ -681,6 +687,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); - - addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); -+ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/system/include")); - - if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) - addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); -`}, - - {"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 -@@ -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); -+ 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); - -@@ -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); -+ 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); -+ 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); -+ 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 +481,9 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { - return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; - } - if (Triple.isMusl()) { -+ if (Triple.getVendor() == llvm::Triple::Rosa) -+ return "/system/bin/linker"; -+ - std::string ArchName; - bool IsArm = false; - -diff --git a/clang/tools/clang-installapi/Options.cpp b/clang/tools/clang-installapi/Options.cpp -index 64324a3f8b01..15ce70b68217 100644 ---- a/clang/tools/clang-installapi/Options.cpp -+++ b/clang/tools/clang-installapi/Options.cpp -@@ -515,7 +515,7 @@ bool Options::processFrontendOptions(InputArgList &Args) { - FEOpts.FwkPaths = std::move(FrameworkPaths); - - // Add default framework/library paths. -- PathSeq DefaultLibraryPaths = {"/usr/lib", "/usr/local/lib"}; -+ PathSeq DefaultLibraryPaths = {"/usr/lib", "/system/lib", "/usr/local/lib"}; - PathSeq DefaultFrameworkPaths = {"/Library/Frameworks", - "/System/Library/Frameworks"}; - -`}, - }, }) return diff --git a/internal/rosa/llvm_patches_latest.go b/internal/rosa/llvm_patches_latest.go new file mode 100644 index 00000000..5e285cb0 --- /dev/null +++ b/internal/rosa/llvm_patches_latest.go @@ -0,0 +1,191 @@ +package rosa + +// llvmPatches are centralised patches against latest LLVM monorepo. +var llvmPatches = []KV{ + {"increase-stack-size-unconditional", `diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp +index 9da357a7ebb9..b2931510c1ae 100644 +--- a/llvm/lib/Support/Threading.cpp ++++ b/llvm/lib/Support/Threading.cpp +@@ -80,7 +80,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { + // keyword. + #include "llvm/Support/thread.h" + +-#if defined(__APPLE__) ++#if defined(__APPLE__) || 1 + // Darwin's default stack size for threads except the main one is only 512KB, + // which is not enough for some/many normal LLVM compilations. This implements + // the same interface as std::thread but requests the same stack size as the +`}, + + {"add-rosa-vendor", `diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h +index 9c83abeeb3b1..5acfe5836a23 100644 +--- a/llvm/include/llvm/TargetParser/Triple.h ++++ b/llvm/include/llvm/TargetParser/Triple.h +@@ -190,6 +190,7 @@ public: + + Apple, + PC, ++ Rosa, + SCEI, + Freescale, + IBM, +diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp +index a4f9dd42c0fe..cb5a12387034 100644 +--- a/llvm/lib/TargetParser/Triple.cpp ++++ b/llvm/lib/TargetParser/Triple.cpp +@@ -279,6 +279,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) { + case NVIDIA: return "nvidia"; + case OpenEmbedded: return "oe"; + case PC: return "pc"; ++ case Rosa: return "rosa"; + case SCEI: return "scei"; + case SUSE: return "suse"; + case Meta: +@@ -689,6 +690,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { + return StringSwitch(VendorName) + .Case("apple", Triple::Apple) + .Case("pc", Triple::PC) ++ .Case("rosa", Triple::Rosa) + .Case("scei", Triple::SCEI) + .Case("sie", Triple::SCEI) + .Case("fsl", Triple::Freescale) +`}, + + {"xfail-broken-tests", `diff --git a/clang/test/Modules/timestamps.c b/clang/test/Modules/timestamps.c +index 50fdce630255..4b4465a75617 100644 +--- a/clang/test/Modules/timestamps.c ++++ b/clang/test/Modules/timestamps.c +@@ -1,3 +1,5 @@ ++// XFAIL: target={{.*-rosa-linux-musl}} ++ + /// Verify timestamps that gets embedded in the module + #include + +`}, + + {"path-system-include", `diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp +index 8ac8d4eb9181..e46b04a898ca 100644 +--- a/clang/lib/Driver/ToolChains/Linux.cpp ++++ b/clang/lib/Driver/ToolChains/Linux.cpp +@@ -671,6 +671,12 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + addExternCSystemInclude( + DriverArgs, CC1Args, + concat(SysRoot, "/usr/include", MultiarchIncludeDir)); ++ if (!MultiarchIncludeDir.empty() && ++ D.getVFS().exists(concat(SysRoot, "/system/include", MultiarchIncludeDir))) ++ addExternCSystemInclude( ++ DriverArgs, CC1Args, ++ concat(SysRoot, "/system/include", MultiarchIncludeDir)); ++ + + if (getTriple().getOS() == llvm::Triple::RTEMS) + return; +@@ -681,6 +687,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); + + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); ++ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/system/include")); + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) + addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); +`}, + + {"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 +@@ -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); ++ 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); + +@@ -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); ++ 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); ++ 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); ++ 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 +481,9 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { + return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; + } + if (Triple.isMusl()) { ++ if (Triple.getVendor() == llvm::Triple::Rosa) ++ return "/system/bin/linker"; ++ + std::string ArchName; + bool IsArm = false; + +diff --git a/clang/tools/clang-installapi/Options.cpp b/clang/tools/clang-installapi/Options.cpp +index 64324a3f8b01..15ce70b68217 100644 +--- a/clang/tools/clang-installapi/Options.cpp ++++ b/clang/tools/clang-installapi/Options.cpp +@@ -515,7 +515,7 @@ bool Options::processFrontendOptions(InputArgList &Args) { + FEOpts.FwkPaths = std::move(FrameworkPaths); + + // Add default framework/library paths. +- PathSeq DefaultLibraryPaths = {"/usr/lib", "/usr/local/lib"}; ++ PathSeq DefaultLibraryPaths = {"/usr/lib", "/system/lib", "/usr/local/lib"}; + PathSeq DefaultFrameworkPaths = {"/Library/Frameworks", + "/System/Library/Frameworks"}; + +`}, +}