r255848 - [WebAssembly] Initial linking support.
Dan Gohman via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 16 15:30:42 PST 2015
Author: djg
Date: Wed Dec 16 17:30:41 2015
New Revision: 255848
URL: http://llvm.org/viewvc/llvm-project?rev=255848&view=rev
Log:
[WebAssembly] Initial linking support.
This begins minimal support for invoking 'ld' from clang for WebAssembly
targets.
Differential Revision: http://reviews.llvm.org/D15586
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Driver/Tools.h
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=255848&r1=255847&r2=255848&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Dec 16 17:30:41 2015
@@ -4418,6 +4418,13 @@ Tool *MyriadToolChain::buildLinker() con
return new tools::Myriad::Linker(*this);
}
+WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args)
+ : ToolChain(D, Triple, Args) {
+ // Use LLD by default.
+ DefaultLinker = "lld";
+}
+
bool WebAssembly::IsMathErrnoDefault() const { return false; }
bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
@@ -4440,6 +4447,8 @@ bool WebAssembly::hasBlocksRuntime() con
// TODO: Support profiling.
bool WebAssembly::SupportsProfiling() const { return false; }
+bool WebAssembly::HasNativeLLVMSupport() const { return true; }
+
void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
@@ -4447,6 +4456,10 @@ void WebAssembly::addClangTargetOptions(
CC1Args.push_back("-fuse-init-array");
}
+Tool *WebAssembly::buildLinker() const {
+ return new tools::wasm::Linker(*this);
+}
+
PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
if (Args.hasArg(options::OPT_static))
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=255848&r1=255847&r2=255848&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Wed Dec 16 17:30:41 2015
@@ -1088,8 +1088,7 @@ private:
class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain {
public:
WebAssembly(const Driver &D, const llvm::Triple &Triple,
- const llvm::opt::ArgList &Args)
- : ToolChain(D, Triple, Args) {}
+ const llvm::opt::ArgList &Args);
private:
bool IsMathErrnoDefault() const override;
@@ -1102,8 +1101,11 @@ private:
bool hasBlocksRuntime() const override;
bool SupportsObjCGC() const override;
bool SupportsProfiling() const override;
+ bool HasNativeLLVMSupport() const override;
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
+
+ Tool *buildLinker() const override;
};
class LLVM_LIBRARY_VISIBILITY PS4CPU : public Generic_ELF {
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=255848&r1=255847&r2=255848&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Dec 16 17:30:41 2015
@@ -6439,6 +6439,34 @@ void amdgpu::Linker::ConstructJob(Compil
}
// AMDGPU tools end.
+wasm::Linker::Linker(const ToolChain &TC)
+ : GnuTool("wasm::Linker", "lld", TC) {}
+
+bool wasm::Linker::isLinkJob() const {
+ return true;
+}
+
+bool wasm::Linker::hasIntegratedCPP() const {
+ return false;
+}
+
+void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInfoList &Inputs,
+ const ArgList &Args,
+ const char *LinkingOutput) const {
+ const char *Linker = Args.MakeArgString(getToolChain().GetLinkerPath());
+ ArgStringList CmdArgs;
+ CmdArgs.push_back("-flavor");
+ CmdArgs.push_back("ld");
+ CmdArgs.push_back("-target");
+ CmdArgs.push_back(Args.MakeArgString(getToolChain().getTripleString()));
+ AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
+ CmdArgs.push_back("-o");
+ CmdArgs.push_back(Output.getFilename());
+ C.addCommand(llvm::make_unique<Command>(JA, *this, Linker, CmdArgs, Inputs));
+}
+
const std::string arm::getARMArch(StringRef Arch, const llvm::Triple &Triple) {
std::string MArch;
if (!Arch.empty())
Modified: cfe/trunk/lib/Driver/Tools.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=255848&r1=255847&r2=255848&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Wed Dec 16 17:30:41 2015
@@ -245,6 +245,21 @@ public:
} // end namespace amdgpu
+namespace wasm {
+
+class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
+public:
+ explicit Linker(const ToolChain &TC);
+ bool isLinkJob() const override;
+ bool hasIntegratedCPP() const override;
+ void ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output, const InputInfoList &Inputs,
+ const llvm::opt::ArgList &TCArgs,
+ const char *LinkingOutput) const override;
+};
+
+} // end namespace wasm
+
namespace arm {
std::string getARMTargetCPU(StringRef CPU, StringRef Arch,
const llvm::Triple &Triple);
More information about the cfe-commits
mailing list