diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2012-04-09 23:53:34 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2012-04-09 23:53:34 +0000 |
| commit | 9446d76e80aad5425d745e7404f10bf041b0ba8b (patch) | |
| tree | 37385132fb4bc38284ddf7985a1bf654b3490c52 | |
| parent | b5cedde66d334d0bdd8886ecb6f66a7df93937b7 (diff) | |
| download | bcm5719-llvm-9446d76e80aad5425d745e7404f10bf041b0ba8b.tar.gz bcm5719-llvm-9446d76e80aad5425d745e7404f10bf041b0ba8b.zip | |
Fix an annoying little bug I found while debugging another LTO issue. Gold
requires the -plugin to come before any -plugin-opt options, we were passing
them the other way around. With this one can run (for example):
clang -o foo foo.c -O4 -Wl,-plugin-opt=generate-api-file
llvm-svn: 154357
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 15 | ||||
| -rw-r--r-- | clang/test/Driver/gold-lto.c | 6 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 3a1778d136c..e5750924818 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -5259,6 +5259,15 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, 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. + 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)); + } + AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); if (D.CCCIsCXX && !Args.hasArg(options::OPT_nostdlib)) { @@ -5307,12 +5316,6 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); - 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)); - } - C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); } diff --git a/clang/test/Driver/gold-lto.c b/clang/test/Driver/gold-lto.c new file mode 100644 index 00000000000..646a59b1af9 --- /dev/null +++ b/clang/test/Driver/gold-lto.c @@ -0,0 +1,6 @@ +// RUN: touch %t.o +// RUN: %clang -target x86_64-pc-linux-gnu -### %t.o -O4 -Wl,-plugin-opt=foo 2> %t.log +// RUN: FileCheck %s < %t.log + +// CHECK: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK: "-plugin-arg=foo" |

