llvm-toolchain/debian/patches/wasm/wasm-sysroot-usr.diff
Faidon Liambotis 14ef8ad6b5 Update wasm-sysroot-usr.diff to fix #1029010
Update the wasm-sysroot-usr.diff patch to restore functionality that was
accidentally dropped when the patch was forward-ported from 14 to 15.
This resolves an issue in which clang++ builds would fail if
libc++-15-dev was installed alongside libc++-15-dev-wasm32.

This issue was rightfully caught in the autopkgtests, and has prevented
the package from migrating to testing, something that should hopefully
be resolved now.

Closes: #1029010, #1032317
2023-03-09 19:53:49 +02:00

98 lines
3.8 KiB
Diff

--- 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,18 @@ void WebAssembly::AddClangSystemIncludeA
+ // add the multiarch path on e.g. wasm32-wasi
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 + "/local/include/" + MultiarchTriple);
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/local/include");
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include/" + MultiarchTriple);
}
- addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+
+ // also add the non-multiarch path, only on a known OS (as above), or when
+ // a sysroot is given, for backwards compatibility with the original driver
+ if (getTriple().getOS() != llvm::Triple::UnknownOS ||
+ !getDriver().SysRoot.empty())
+ 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 {
@@ -499,7 +519,9 @@ void WebAssembly::addLibCxxIncludePaths(
}
// Second add the generic one.
- addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
+ // don't include the host architecture's headers in the search path
+ if (!getDriver().SysRoot.empty())
+ addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
}
void WebAssembly::addLibStdCXXIncludePaths(
@@ -546,8 +568,11 @@ void WebAssembly::addLibStdCXXIncludePat
addSystemInclude(DriverArgs, CC1Args, TargetDir);
}
- // Second add the generic one.
- addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
- // Third the backward one.
- addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version + "/backward");
+ // don't include the host architecture's headers in the search path
+ if (!getDriver().SysRoot.empty()) {
+ // Second add the generic one.
+ addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
+ // Third the backward one.
+ addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version + "/backward");
+ }
}
--- 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