void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
ArgStringList &CmdArgs, const InputInfo &Output,
const InputInfo &Input, bool IsThinLTO) {
- // 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.
- CmdArgs.push_back("-plugin");
+ const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
+ if (llvm::sys::path::filename(Linker) != "ld.lld" &&
+ llvm::sys::path::stem(Linker) != "ld.lld") {
+ // 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.
+ CmdArgs.push_back("-plugin");
#if defined(_WIN32)
- const char *Suffix = ".dll";
+ const char *Suffix = ".dll";
#elif defined(__APPLE__)
- const char *Suffix = ".dylib";
+ const char *Suffix = ".dylib";
#else
- const char *Suffix = ".so";
+ const char *Suffix = ".so";
#endif
- SmallString<1024> Plugin;
- llvm::sys::path::native(Twine(ToolChain.getDriver().Dir) +
- "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold" +
- Suffix,
- Plugin);
- CmdArgs.push_back(Args.MakeArgString(Plugin));
+ SmallString<1024> Plugin;
+ llvm::sys::path::native(Twine(ToolChain.getDriver().Dir) +
+ "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold" +
+ Suffix,
+ Plugin);
+ CmdArgs.push_back(Args.MakeArgString(Plugin));
+ }
// Try to pass driver level flags relevant to LTO code generation down to
// the plugin.
// RUN: -fuse-ld=gold -fno-lto -flto -### 2>&1 | FileCheck --check-prefix=LLVMGOLD %s
// LLVMGOLD: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+/// lld does not need LLVMgold.
+// RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
+// RUN: -fuse-ld=lld -flto -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
// RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
// RUN: -fuse-ld=gold -flto -fno-lto -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
// NO-LLVMGOLD-NOT: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
//
// LLVMGOLD: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
-// Check that subsequent -fno-lto takes precedence
+/// lld does not need LLVMgold.
+// RUN: %clangxx -nocudainc -nocudalib -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
+// RUN: -fuse-ld=lld -flto=full -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
// RUN: %clangxx -nocudainc -nocudalib -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
// RUN: -fuse-ld=gold -flto=full -fno-lto -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
//