Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver] Some improvements for path handling on NetBSD #66863

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions clang/lib/Driver/ToolChains/NetBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
// what all logic is needed to emulate the '=' prefix here.
switch (Triple.getArch()) {
case llvm::Triple::x86:
getFilePaths().push_back("=/usr/lib/i386");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/i386"));
break;
case llvm::Triple::arm:
case llvm::Triple::armeb:
Expand All @@ -369,35 +369,35 @@ NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
switch (Triple.getEnvironment()) {
case llvm::Triple::EABI:
case llvm::Triple::GNUEABI:
getFilePaths().push_back("=/usr/lib/eabi");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/eabi"));
break;
case llvm::Triple::EABIHF:
case llvm::Triple::GNUEABIHF:
getFilePaths().push_back("=/usr/lib/eabihf");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/eabihf"));
break;
default:
getFilePaths().push_back("=/usr/lib/oabi");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/oabi"));
break;
}
break;
case llvm::Triple::mips64:
case llvm::Triple::mips64el:
if (tools::mips::hasMipsAbiArg(Args, "o32"))
getFilePaths().push_back("=/usr/lib/o32");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/o32"));
else if (tools::mips::hasMipsAbiArg(Args, "64"))
getFilePaths().push_back("=/usr/lib/64");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/64"));
break;
case llvm::Triple::ppc:
getFilePaths().push_back("=/usr/lib/powerpc");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/powerpc"));
break;
case llvm::Triple::sparc:
getFilePaths().push_back("=/usr/lib/sparc");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/sparc"));
break;
default:
break;
}

getFilePaths().push_back("=/usr/lib");
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
}
}

Expand Down Expand Up @@ -467,11 +467,11 @@ void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const std::string Candidates[] = {
// directory relative to build tree
getDriver().Dir + "/../include/c++/v1",
concat(getDriver().Dir, "/../include/c++/v1"),
// system install with full upstream path
getDriver().SysRoot + "/usr/include/c++/v1",
concat(getDriver().SysRoot, "/usr/include/c++/v1"),
// system install from src
getDriver().SysRoot + "/usr/include/c++",
concat(getDriver().SysRoot, "/usr/include/c++"),
};

for (const auto &IncludePath : Candidates) {
Expand All @@ -486,7 +486,7 @@ void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,

void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/g++", "", "",
addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/g++"), "", "",
DriverArgs, CC1Args);
}

Expand Down
Empty file.
11 changes: 11 additions & 0 deletions clang/test/Driver/netbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,14 @@
// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include"
// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "{{.*}}/usr/include"

// Test NetBSD with libstdc++ when the sysroot path ends with `/`.
// RUN: %clangxx -### %s 2>&1 \
// RUN: --target=x86_64-unknown-netbsd \
// RUN: -stdlib=libstdc++ \
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree/ \
// RUN: --gcc-toolchain="" \
// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/g++"