mirror of
https://git.proxmox.com/git/llvm-toolchain
synced 2025-10-18 18:37:45 +00:00
Add support for loading wasi-libc from /usr
The WebAssembly target seems to have been designed to be always passed a --sysroot, likely because of being tested to work only with the WASI-SDK. This results into passing bare, non-existing paths in include paths, such as: -internal-isystem /include/wasm32-wasi -internal-isystem /include (and similar for /lib/). In Debian, the wasi-libc package ships its files in /usr/include/wasm32-wasi, /usr/lib/wasm32-wasi etc. Add support in the target for including paths from /usr as well. To avoid changing the code in more intrusive ways (to do e.g. what the Linux target does) add a bit of an indirection where the "sysroot" defaults to "/usr" instead of the empty string. This should probably be adjusted a bit if it were to be upstreamed. Closes: #1020746
This commit is contained in:
parent
a94a2fe7c3
commit
335200bf69
1
debian/patches/series
vendored
1
debian/patches/series
vendored
@ -139,6 +139,7 @@ compilerrt-builtins-arch-fix-armhf.diff
|
||||
compilerrt-build-scudo-standalone-option.diff
|
||||
wasm-ld-path.diff
|
||||
wasm-compiler-rt-default.diff
|
||||
wasm-sysroot-usr.diff
|
||||
issue-54242.diff
|
||||
revert-update-doc.diff
|
||||
unwind-force-pthread-dl.diff
|
||||
|
62
debian/patches/wasm-sysroot-usr.diff
vendored
Normal file
62
debian/patches/wasm-sysroot-usr.diff
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
|
||||
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
|
||||
@@ -174,7 +174,7 @@ WebAssembly::WebAssembly(const Driver &D
|
||||
|
||||
getProgramPaths().push_back(getDriver().getInstalledDir());
|
||||
|
||||
- auto SysRoot = getDriver().SysRoot;
|
||||
+ std::string SysRoot = computeSysRoot();
|
||||
if (getTriple().getOS() == llvm::Triple::UnknownOS) {
|
||||
// Theoretically an "unknown" OS should mean no standard libraries, however
|
||||
// it could also mean that a custom set of libraries is in use, so just add
|
||||
@@ -402,6 +402,7 @@ void WebAssembly::AddClangSystemIncludeA
|
||||
return;
|
||||
|
||||
const Driver &D = getDriver();
|
||||
+ std::string SysRoot = computeSysRoot();
|
||||
|
||||
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
|
||||
SmallString<128> P(D.ResourceDir);
|
||||
@@ -427,10 +428,10 @@ void WebAssembly::AddClangSystemIncludeA
|
||||
|
||||
if (getTriple().getOS() != llvm::Triple::UnknownOS) {
|
||||
const std::string MultiarchTriple =
|
||||
- getMultiarchTriple(D, getTriple(), D.SysRoot);
|
||||
- addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
|
||||
+ getMultiarchTriple(D, getTriple(), SysRoot);
|
||||
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include/" + MultiarchTriple);
|
||||
}
|
||||
- addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
|
||||
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
|
||||
}
|
||||
|
||||
void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
||||
@@ -478,6 +479,17 @@ Tool *WebAssembly::buildLinker() const {
|
||||
return new tools::wasm::Linker(*this);
|
||||
}
|
||||
|
||||
+std::string WebAssembly::computeSysRoot() const {
|
||||
+ if (!getDriver().SysRoot.empty())
|
||||
+ return getDriver().SysRoot;
|
||||
+
|
||||
+ std::string Path = "/usr";
|
||||
+ if (getVFS().exists(Path))
|
||||
+ return Path;
|
||||
+
|
||||
+ return std::string();
|
||||
+}
|
||||
+
|
||||
void WebAssembly::addLibCxxIncludePaths(
|
||||
const llvm::opt::ArgList &DriverArgs,
|
||||
llvm::opt::ArgStringList &CC1Args) const {
|
||||
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
|
||||
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
|
||||
@@ -89,6 +89,8 @@ private:
|
||||
llvm::opt::ArgStringList &CC1Args) const;
|
||||
void addLibStdCXXIncludePaths(const llvm::opt::ArgList &DriverArgs,
|
||||
llvm::opt::ArgStringList &CC1Args) const;
|
||||
+
|
||||
+ std::string computeSysRoot() const override;
|
||||
};
|
||||
|
||||
} // end namespace toolchains
|
Loading…
Reference in New Issue
Block a user