Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp	(revision 161071)
+++ lib/Driver/ToolChains.cpp	(working copy)
@@ -1582,6 +1582,10 @@
     getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
 }
 
+bool FreeBSD::HasNativeLLVMSupport() const {
+  return true;
+}
+
 Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA,
                           const ActionList &Inputs) const {
   Action::ActionClass Key;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 161071)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -198,6 +198,12 @@
   CmdArgs.push_back(Args.MakeArgString(ProfileRT));
 }
 
+/// \brief Add the necessary arguments to use the LLVMgold plugin
+static void addGoldPlugin(ArgStringList &CmdArgs, const ArgList &Args, StringRef LinkerDir) {
+  CmdArgs.push_back("-plugin");
+  CmdArgs.push_back(Args.MakeArgString(LinkerDir + "/../lib/LLVMgold.so"));
+}
+
 void Clang::AddPreprocessingOptions(Compilation &C,
                                     const Driver &D,
                                     const ArgList &Args,
@@ -5082,6 +5088,14 @@
   for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
        i != e; ++i)
     CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
+
+  // Tell the linker to load the plugin. This has to come before AddLinkerInputs
+  // as gold requires -plugin to come before any -plugin-opt that -Wl might
+  // forward.
+  const bool UseGold = D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin);
+  if (UseGold)
+    addGoldPlugin(CmdArgs, Args, getToolChain().getDriver().Dir);
+
   Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
   Args.AddAllArgs(CmdArgs, options::OPT_e);
   Args.AddAllArgs(CmdArgs, options::OPT_s);
@@ -5159,8 +5173,9 @@
 
   addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
+  const char *Linker = UseGold? "ld.gold":"ld";
   const char *Exec =
-    Args.MakeArgString(getToolChain().GetProgramPath("ld"));
+    Args.MakeArgString(getToolChain().GetProgramPath(Linker));
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 }
 
@@ -5574,11 +5589,8 @@
   // Tell the linker to load the plugin. This has to come before AddLinkerInputs
   // as gold requires -plugin to come before any -plugin-opt that -Wl might
   // forward.
-  if (D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin)) {
-    CmdArgs.push_back("-plugin");
-    std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so";
-    CmdArgs.push_back(Args.MakeArgString(Plugin));
-  }
+  if (D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin))
+    addGoldPlugin(CmdArgs, Args, ToolChain.getDriver().Dir);
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
 
Index: lib/Driver/ToolChains.h
===================================================================
--- lib/Driver/ToolChains.h	(revision 161071)
+++ lib/Driver/ToolChains.h	(working copy)
@@ -449,6 +449,7 @@
 public:
   FreeBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args);
 
+  virtual bool HasNativeLLVMSupport() const;
   virtual bool IsMathErrnoDefault() const { return false; }
   virtual bool IsObjCNonFragileABIDefault() const { return true; }
 
Index: test/Driver/freebsd.c
===================================================================
--- test/Driver/freebsd.c	(revision 161071)
+++ test/Driver/freebsd.c	(working copy)
@@ -43,4 +43,12 @@
 // CHECK-LDFLAGS8: --enable-new-dtags
 // CHECK-LDFLAGS9: --hash-style=both
 // CHECK-LDFLAGS9: --enable-new-dtags
-
+//
+// Check for ld.gold and the plugin
+// RUN: %clang -no-canonical-prefixes %s -### -flto -o %t.o 2>&1 \
+// RUN:     -ccc-install-dir %S/Inputs/fake_install_tree/bin \
+// RUN:     -target i386-unknown-freebsd \
+// RUN:     --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-GOLD %s
+// CHECK-GOLD: "{{.*}}ld.gold{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-GOLD: "-plugin" "{{.*}}/Inputs/fake_install_tree/bin/../lib/LLVMgold.so"
