[Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

This is the same change as https://reviews.llvm.org/D126289, but applied for OpenBSD & FreeBSD.

Differential Revision: https://reviews.llvm.org/D129654
This commit is contained in:
Egor Zhdan 2022-07-13 16:40:24 +01:00
parent ed261e7106
commit 1d0cc51051
10 changed files with 50 additions and 9 deletions

View File

@ -389,10 +389,10 @@ FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple,
// back to '/usr/lib' if it doesn't exist.
if ((Triple.getArch() == llvm::Triple::x86 || Triple.isMIPS32() ||
Triple.isPPC32()) &&
D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o"))
getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32");
D.getVFS().exists(concat(getDriver().SysRoot, "/usr/lib32/crt1.o")))
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib32"));
else
getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
}
ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const {
@ -411,14 +411,14 @@ unsigned FreeBSD::GetDefaultDwarfVersion() const {
void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/v1");
concat(getDriver().SysRoot, "/usr/include/c++/v1"));
}
void FreeBSD::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/c++/4.2", "", "",
DriverArgs, CC1Args);
addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/4.2"),
"", "", DriverArgs, CC1Args);
}
void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args,

View File

@ -284,7 +284,7 @@ SanitizerMask OpenBSD::getSupportedSanitizers() const {
OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
}
void OpenBSD::AddClangSystemIncludeArgs(
@ -317,13 +317,14 @@ void OpenBSD::AddClangSystemIncludeArgs(
return;
}
addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
addExternCSystemInclude(DriverArgs, CC1Args,
concat(D.SysRoot, "/usr/include"));
}
void OpenBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/v1");
concat(getDriver().SysRoot, "/usr/include/c++/v1"));
}
void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,

View File

@ -20,3 +20,23 @@
// CHECK-PG-FOURTEEN: "-lc++" "-lm"
// CHECK-PG-TEN: "-lc++_p" "-lm_p"
// CHECK-PG-NINE: "-lstdc++_p" "-lm_p"
// Test include paths with a sysroot.
// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
// RUN: --target=amd64-unknown-freebsd \
// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
// CHECK-LIBCXX-SYSROOT: "-cc1"
// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
// Test include paths when the sysroot path ends with `/`.
// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
// RUN: --target=amd64-unknown-freebsd \
// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"

View File

@ -19,3 +19,23 @@
// RUN: %clangxx %s -### -pg -o %t.o -target arm-unknown-openbsd 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-PG-CXX %s
// CHECK-PG-CXX: "-lc++_p" "-lc++abi_p" "-lpthread_p" "-lm_p"
// Test include paths with a sysroot.
// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
// RUN: --target=amd64-pc-openbsd \
// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
// CHECK-LIBCXX-SYSROOT: "-cc1"
// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
// Test include paths when the sysroot path ends with `/`.
// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
// RUN: --target=amd64-pc-openbsd \
// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"