[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 27 01:04:35 PST 2025
================
@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
return std::string(SysRootDir);
}
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../<TargetTriple> directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+ if (!getDriver().SysRoot.empty())
+ return getDriver().SysRoot;
+
+ 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());
----------------
petrhosek wrote:
I understand that this is copied as-is from `RISCVToolchain`, but it's quite confusing for this to be inside the method called `computeGCCSysroot` when it is not in fact a GCC sysroot, it's the sysroot installed alongside Clang.
https://github.com/llvm/llvm-project/pull/121829
More information about the cfe-commits
mailing list