diff options
author | Fangrui Song <maskray@google.com> | 2020-02-07 14:17:36 -0800 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-02-07 22:53:14 -0800 |
commit | 8aa3f507c38a2ccd8ed7cb33d02a6f645cdbc03a (patch) | |
tree | ddede7537664214b32f026706c0f62cbf07ecc4c | |
parent | 70e0935256fc173fbc57c7333727ab222af476eb (diff) | |
download | llvm-8aa3f507c38a2ccd8ed7cb33d02a6f645cdbc03a.zip llvm-8aa3f507c38a2ccd8ed7cb33d02a6f645cdbc03a.tar.gz llvm-8aa3f507c38a2ccd8ed7cb33d02a6f645cdbc03a.tar.bz2 |
[Driver] Don't pass -plugin LLVMgold.so when the linker is ld.lld
This is does not cover the case when ld is lld (e.g. /usr/bin/ld on
modern FreeBSD systems).
-rw-r--r-- | clang/lib/Driver/ToolChains/CommonArgs.cpp | 30 | ||||
-rw-r--r-- | clang/test/Driver/lto.c | 3 | ||||
-rw-r--r-- | clang/test/Driver/lto.cu | 4 |
3 files changed, 23 insertions, 14 deletions
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 122872f..0b2f8ce 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -356,25 +356,29 @@ bool tools::isUseSeparateSections(const llvm::Triple &Triple) { 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. diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c index becaa9e..34e6076 100644 --- a/clang/test/Driver/lto.c +++ b/clang/test/Driver/lto.c @@ -41,6 +41,9 @@ // 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}}" diff --git a/clang/test/Driver/lto.cu b/clang/test/Driver/lto.cu index d3d71f3..131ed83 100644 --- a/clang/test/Driver/lto.cu +++ b/clang/test/Driver/lto.cu @@ -55,7 +55,9 @@ // // 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 // |