[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:29:15 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());
+ }
+
+ if (!llvm::sys::fs::exists(SysRootDir))
----------------
petrhosek wrote:
I believe the underlying issue is that BareMetal and RISCVToolchain original authors made different choices when it comes to the default sysroot location:
* BareMetal uses the `bin/../lib/clang-runtimes/<TargetTriple>` directory.
* RISCVToolchain uses the `bin/../<TargetTriple>` directory.
Unless we deprecate one (or both) of these and force everyone to switch to a common one, I don't think we can avoid the directory check.
I'd be in favor of unifying on a single location sooner rather than later even if it's going to require a migration for some users. This would be probably best discussed in an RFC though.
https://github.com/llvm/llvm-project/pull/121829
More information about the cfe-commits
mailing list