[clang] [clang]: baremetal `multilib.yaml` discovery (PR #227965)
Mythreya Kuricheti via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 23:01:37 PDT 2026
https://github.com/MythreyaK created https://github.com/llvm/llvm-project/pull/227965
Clang does not auto-detect `multilib.yaml` in the triple dirs correctly because baremetal targets use `SYSROOT` as a fallback dir, unlike the linux `multilib.yaml` discovery, which correctly searches the triple-specific dirs first (`FallbackDir` dir is unset).
`findMultilibsYAML` treats `FallbackDir` and `getStdlibPath()` as mutually-exclusive settings. Because baremetal uses a fallback path `SYSROOT/multilib.yaml`, `getStdlibPath()` is never searched (`SYSROOT/usr/lib/<triple>/multilib.yaml`).
With this change to shared `Toolchain.cpp`, baremetal targets look for a `multilib.yaml` in the triple-specific dirs first, before attempting to locate it in SYSROOT. Attempt triple-specific dirs first if present, `FallbackDir` otherwise.
Follow-up to llvm/llvm-project#183453
>From 4a448aa18c39b5654b5f6ffd079fbd1a7c54e5d5 Mon Sep 17 00:00:00 2001
From: Mythreya Kuricheti <git at mythreya.dev>
Date: Thu, 1 Oct 2026 05:43:57 +0000
Subject: [PATCH] [clang]: baremetal `multilib.yaml` discovery
Clang does not auto-detect `multilib.yaml` in the triple dirs
correctly because baremetal targets use `SYSROOT` as a fallback
dir, unlike the linux `multilib.yaml` discovery, which correctly
searches the triple-specific dirs first (`FallbackDir` dir is
unset).
`findMultilibsYAML` treats `FallbackDir` and `getStdlibPath()`
as mutually-exclusive settings. Because baremetal uses a fallback
path `SYSROOT/multilib.yaml`, `getStdlibPath()` is never searched
(`SYSROOT/usr/lib/<triple>/multilib.yaml`).
With this change to shared `Toolchain.cpp`, baremetal targets
look for a `multilib.yaml` in the triple-specific dirs first,
before attempting to locate it in SYSROOT. Attempt triple-specific
dirs first if present, `FallbackDir` otherwise.
---
clang/lib/Driver/ToolChain.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 4b194b5b70534..838dbadb482af 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -202,10 +202,10 @@ ToolChain::findMultilibsYAML(const llvm::opt::ArgList &Args, const Driver &D,
}
SmallString<128> MultilibPath;
- if (!FallbackDir.empty())
- MultilibPath = FallbackDir;
- else if (std::optional<std::string> StdlibDir = getStdlibPath())
+ if (std::optional<std::string> StdlibDir = getStdlibPath())
MultilibPath = *StdlibDir;
+ else if (!FallbackDir.empty())
+ MultilibPath = FallbackDir;
else
return std::nullopt;
llvm::sys::path::append(MultilibPath, "multilib.yaml");
More information about the cfe-commits
mailing list