summaryrefslogtreecommitdiff
path: root/clang/lib/Driver/ToolChains/Hurd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Driver/ToolChains/Hurd.cpp')
-rw-r--r--clang/lib/Driver/ToolChains/Hurd.cpp48
1 files changed, 33 insertions, 15 deletions
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 72166ca9f359..a700d7b9064c 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -61,21 +61,35 @@ static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
return Triple.isArch32Bit() ? "lib" : "lib64";
}
-Hurd::Hurd(const Driver &D, const llvm::Triple &Triple,
- const ArgList &Args)
+Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
+ GCCInstallation.init(Triple, Args);
+ Multilibs = GCCInstallation.getMultilibs();
+ SelectedMultilib = GCCInstallation.getMultilib();
std::string SysRoot = computeSysRoot();
+ ToolChain::path_list &PPaths = getProgramPaths();
+
+ Generic_GCC::PushPPaths(PPaths);
+
+ // The selection of paths to try here is designed to match the patterns which
+ // the GCC driver itself uses, as this is part of the GCC-compatible driver.
+ // This was determined by running GCC in a fake filesystem, creating all
+ // possible permutations of these directories, and seeing which ones it added
+ // to the link paths.
path_list &Paths = getFilePaths();
- const std::string OSLibDir = getOSLibDir(Triple, Args);
+ const std::string OSLibDir = std::string(getOSLibDir(Triple, Args));
const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
#ifdef ENABLE_LINKER_BUILD_ID
ExtraOpts.push_back("--build-id");
#endif
- // If we are currently running Clang inside of the requested system root, add
- // its parent library paths to those searched.
+ Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
+
+ // Similar to the logic for GCC above, if we currently running Clang inside
+ // of the requested system root, add its parent library paths to
+ // those searched.
// FIXME: It's not clear whether we should use the driver's installed
// directory ('Dir' below) or the ResourceDir.
if (StringRef(D.Dir).startswith(SysRoot)) {
@@ -89,8 +103,11 @@ Hurd::Hurd(const Driver &D, const llvm::Triple &Triple,
addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
- // If we are currently running Clang inside of the requested system root, add
- // its parent library path to those searched.
+ Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
+
+ // Similar to the logic for GCC above, if we are currently running Clang
+ // inside of the requested system root, add its parent library path to those
+ // searched.
// FIXME: It's not clear whether we should use the driver's installed
// directory ('Dir' below) or the ResourceDir.
if (StringRef(D.Dir).startswith(SysRoot))
@@ -108,13 +125,6 @@ Tool *Hurd::buildAssembler() const {
return new tools::gnutools::Assembler(*this);
}
-std::string Hurd::computeSysRoot() const {
- if (!getDriver().SysRoot.empty())
- return getDriver().SysRoot;
-
- return std::string();
-}
-
std::string Hurd::getDynamicLinker(const ArgList &Args) const {
if (getArch() == llvm::Triple::x86)
return "/lib/ld.so";
@@ -149,7 +159,7 @@ void Hurd::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
CIncludeDirs.split(Dirs, ":");
for (StringRef Dir : Dirs) {
StringRef Prefix =
- llvm::sys::path::is_absolute(Dir) ? StringRef(SysRoot) : "";
+ llvm::sys::path::is_absolute(Dir) ? "" : StringRef(SysRoot);
addExternCSystemInclude(DriverArgs, CC1Args, Prefix + Dir);
}
return;
@@ -157,6 +167,9 @@ void Hurd::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Lacking those, try to detect the correct set of system includes for the
// target triple.
+
+ AddMultilibIncludeArgs(DriverArgs, CC1Args);
+
if (getTriple().getArch() == llvm::Triple::x86) {
std::string Path = SysRoot + "/usr/include/i386-gnu";
if (D.getVFS().exists(Path))
@@ -170,3 +183,8 @@ void Hurd::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
}
+
+void Hurd::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
+ for (const auto &Opt : ExtraOpts)
+ CmdArgs.push_back(Opt.c_str());
+}