[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
Garvit Gupta via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 24 12:05:58 PDT 2025
================
@@ -110,20 +110,76 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
return std::string(SysRootDir);
}
+std::string BareMetal::computeSysRoot() const {
+ if (!SysRoot.empty())
+ return SysRoot;
+
+ std::string SysRoot = getDriver().SysRoot;
+ if (!SysRoot.empty())
+ return SysRoot;
+
+ // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+ // alongside clang. If valid, form the sysroot. Otherwise, check
+ // lib/clang-runtimes above the driver.
+ SmallString<128> SysRootDir;
+ if (GCCInstallation.isValid()) {
+ StringRef LibDir = GCCInstallation.getParentLibPath();
+ StringRef TripleStr = GCCInstallation.getTriple().str();
+ llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+ } else {
+ // Use the triple as provided to the driver. Unlike the parsed triple
+ // this has not been normalized to always contain every field.
+ llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+ getDriver().getTargetTriple());
+ }
+
+ if (llvm::sys::fs::exists(SysRootDir))
+ return std::string(SysRootDir);
+ SysRoot = computeBaseSysRoot(getDriver(), /*IncludeTriple*/ true);
+
+ return SysRoot;
----------------
quic-garvgupt wrote:
Thanks for pointing this out!. I have fixed it in the next patchset
https://github.com/llvm/llvm-project/pull/121829
More information about the cfe-commits
mailing list