Skip to content
Snippets Groups Projects
Commit 429fe822 authored by Petr Hosek's avatar Petr Hosek
Browse files

[Driver] Update Fuchsia driver path handling

Several improvements to the Fuchsia driver:

* Search for C++ library headers and libraries in directories that
are part of the toolchain distribution rather than sysroot.

* Use LLVM support utlities to construct paths to make sure the driver
is also usable on Windows for cross-compiling.

* Change the driver to inherit directly from ToolChain rather than
Generic_GCC since we don't need any of the GCC related multilib logic.

Differential Revision: https://reviews.llvm.org/D32613

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307830 91177308-0d34-0410-b5e6-96231b3b80d8
parent 9a439088
No related branches found
No related tags found
No related merge requests found
...@@ -131,16 +131,44 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, ...@@ -131,16 +131,44 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
/// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly. /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
static std::string computeTriple(llvm::Triple Triple) {
SmallString<64> T;
T += Triple.getArchName();
T += "-";
T += Triple.getOSName();
return T.str();
}
static std::string getTargetDir(const Driver &D,
llvm::Triple Triple) {
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
llvm::sys::path::append(P, "lib", computeTriple(Triple));
return P.str();
}
Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple, Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args) const ArgList &Args)
: Generic_ELF(D, Triple, Args) { : ToolChain(D, Triple, Args) {
getProgramPaths().push_back(getDriver().getInstalledDir());
getFilePaths().push_back(D.SysRoot + "/lib"); if (getDriver().getInstalledDir() != D.Dir)
getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia"); getProgramPaths().push_back(D.Dir);
SmallString<128> P(getTargetDir(D, getTriple()));
llvm::sys::path::append(P, "lib");
getFilePaths().push_back(P.str());
if (!D.SysRoot.empty()) {
SmallString<128> P(D.SysRoot);
llvm::sys::path::append(P, "lib");
getFilePaths().push_back(P.str());
}
} }
Tool *Fuchsia::buildAssembler() const { std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
return new tools::gnutools::Assembler(*this); types::ID InputType) const {
llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
Triple.setTriple(computeTriple(Triple));
return Triple.getTriple();
} }
Tool *Fuchsia::buildLinker() const { Tool *Fuchsia::buildLinker() const {
...@@ -208,19 +236,44 @@ void Fuchsia::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ...@@ -208,19 +236,44 @@ void Fuchsia::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
return; return;
} }
addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include"); if (!D.SysRoot.empty()) {
SmallString<128> P(D.SysRoot);
llvm::sys::path::append(P, "include");
addExternCSystemInclude(DriverArgs, CC1Args, P.str());
}
} }
std::string Fuchsia::findLibCxxIncludePath() const { void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
return getDriver().SysRoot + "/include/c++/v1"; ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
DriverArgs.hasArg(options::OPT_nostdincxx))
return;
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx: {
SmallString<128> P(getTargetDir(getDriver(), getTriple()));
llvm::sys::path::append(P, "include", "c++", "v1");
addSystemInclude(DriverArgs, CC1Args, P.str());
break;
}
default:
llvm_unreachable("invalid stdlib name");
}
} }
void Fuchsia::AddCXXStdlibLibArgs(const ArgList &Args, void Fuchsia::AddCXXStdlibLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const { ArgStringList &CmdArgs) const {
(void) GetCXXStdlibType(Args); switch (GetCXXStdlibType(Args)) {
CmdArgs.push_back("-lc++"); case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++abi"); CmdArgs.push_back("-lc++");
CmdArgs.push_back("-lunwind"); CmdArgs.push_back("-lc++abi");
CmdArgs.push_back("-lunwind");
break;
case ToolChain::CST_Libstdcxx:
llvm_unreachable("invalid stdlib name");
}
} }
SanitizerMask Fuchsia::getSupportedSanitizers() const { SanitizerMask Fuchsia::getSupportedSanitizers() const {
......
...@@ -35,18 +35,29 @@ public: ...@@ -35,18 +35,29 @@ public:
namespace toolchains { namespace toolchains {
class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF { class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
public: public:
Fuchsia(const Driver &D, const llvm::Triple &Triple, Fuchsia(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args); const llvm::opt::ArgList &Args);
bool isPIEDefault() const override { return true; }
bool HasNativeLLVMSupport() const override { return true; } bool HasNativeLLVMSupport() const override { return true; }
bool IsIntegratedAssemblerDefault() const override { return true; } bool IsIntegratedAssemblerDefault() const override { return true; }
RuntimeLibType GetDefaultRuntimeLibType() const override {
return ToolChain::RLT_CompilerRT;
}
CXXStdlibType GetDefaultCXXStdlibType() const override {
return ToolChain::CST_Libcxx;
}
bool isPICDefault() const override { return false; }
bool isPIEDefault() const override { return true; }
bool isPICDefaultForced() const override { return false; }
llvm::DebuggerKind getDefaultDebuggerTuning() const override { llvm::DebuggerKind getDefaultDebuggerTuning() const override {
return llvm::DebuggerKind::GDB; return llvm::DebuggerKind::GDB;
} }
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
types::ID InputType) const override;
SanitizerMask getSupportedSanitizers() const override; SanitizerMask getSupportedSanitizers() const override;
RuntimeLibType RuntimeLibType
...@@ -60,7 +71,9 @@ public: ...@@ -60,7 +71,9 @@ public:
void void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override; llvm::opt::ArgStringList &CC1Args) const override;
std::string findLibCxxIncludePath() const override; void
AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override; llvm::opt::ArgStringList &CmdArgs) const override;
...@@ -69,7 +82,6 @@ public: ...@@ -69,7 +82,6 @@ public:
} }
protected: protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override; Tool *buildLinker() const override;
}; };
......
// RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \ // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s // RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
// CHECK: {{.*}}clang{{.*}}" "-cc1" // CHECK: {{.*}}clang{{.*}}" "-cc1"
// CHECK: "-triple" "x86_64-fuchsia"
// CHECK: "-fuse-init-array" // CHECK: "-fuse-init-array"
// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK: "-internal-isystem" "[[SYSROOT]]{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1" // CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1"
// CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include" // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include"
// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu" // CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
// CHECK: "--sysroot=[[SYSROOT]]" // CHECK: "--sysroot=[[SYSROOT]]"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment