r211866 - Driver: use GNU::Link for the Generic_GCC toolchain
Saleem Abdulrasool
compnerd at compnerd.org
Thu Jun 26 22:06:42 PDT 2014
Author: compnerd
Date: Fri Jun 27 00:06:41 2014
New Revision: 211866
URL: http://llvm.org/viewvc/llvm-project?rev=211866&view=rev
Log:
Driver: use GNU::Link for the Generic_GCC toolchain
This changes the behaviour of the driver for linking to match that of the
Generic_GCC::Assemble. The default link should use "ld" rather than "gcc" for
the linker as gcc does. This avoids the unnecessary round-tripping through gcc.
It also is much more reasonable behaviour from the user's perspective. This
should have been updated with SVN r195554 which changed the behaviour of
Generic_GCC::Assemble.
The gcc_forward test needs to be updated to mark the fact that -march is a flag
for GCC not ld. This was updated as a typo fix, but added a check for a flag
that is not a link flag.
The bindings test covers the change for testing, and thus no new test was added.
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/bindings.c
cfe/trunk/test/Driver/gcc_forward.c
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=211866&r1=211865&r2=211866&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Jun 27 00:06:41 2014
@@ -2102,7 +2102,7 @@ Tool *Generic_GCC::buildAssembler() cons
}
Tool *Generic_GCC::buildLinker() const {
- return new tools::gcc::Link(*this);
+ return new tools::gnutools::Link(*this);
}
void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=211866&r1=211865&r2=211866&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Jun 27 00:06:41 2014
@@ -7013,11 +7013,13 @@ void gnutools::Link::ConstructJob(Compil
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- const toolchains::Linux& ToolChain =
+ const toolchains::Linux& LinuxToolChain =
static_cast<const toolchains::Linux&>(getToolChain());
+ const auto &ToolChain = getToolChain();
const Driver &D = ToolChain.getDriver();
- const bool isAndroid =
- ToolChain.getTriple().getEnvironment() == llvm::Triple::Android;
+ const llvm::Triple &TT = ToolChain.getTriple();
+ const bool isAndroid = TT.getEnvironment() == llvm::Triple::Android;
+ const bool IsLinux = TT.isOSLinux();
const bool IsPIE =
!Args.hasArg(options::OPT_shared) &&
!Args.hasArg(options::OPT_static) &&
@@ -7049,8 +7051,9 @@ void gnutools::Link::ConstructJob(Compil
if (Args.hasArg(options::OPT_s))
CmdArgs.push_back("-s");
- for (const auto &Opt : ToolChain.ExtraOpts)
- CmdArgs.push_back(Opt.c_str());
+ if (IsLinux)
+ for (const auto &Opt : LinuxToolChain.ExtraOpts)
+ CmdArgs.push_back(Opt.c_str());
if (!Args.hasArg(options::OPT_static)) {
CmdArgs.push_back("--eh-frame-hdr");
@@ -7117,16 +7120,17 @@ void gnutools::Link::ConstructJob(Compil
}
}
- if (ToolChain.getArch() == llvm::Triple::arm ||
- ToolChain.getArch() == llvm::Triple::armeb ||
- ToolChain.getArch() == llvm::Triple::thumb ||
- ToolChain.getArch() == llvm::Triple::thumbeb ||
- (!Args.hasArg(options::OPT_static) &&
- !Args.hasArg(options::OPT_shared))) {
- CmdArgs.push_back("-dynamic-linker");
- CmdArgs.push_back(Args.MakeArgString(
- D.DyldPrefix + getLinuxDynamicLinker(Args, ToolChain)));
- }
+ if (IsLinux)
+ if (ToolChain.getArch() == llvm::Triple::arm ||
+ ToolChain.getArch() == llvm::Triple::armeb ||
+ ToolChain.getArch() == llvm::Triple::thumb ||
+ ToolChain.getArch() == llvm::Triple::thumbeb ||
+ (!Args.hasArg(options::OPT_static) &&
+ !Args.hasArg(options::OPT_shared))) {
+ CmdArgs.push_back("-dynamic-linker");
+ CmdArgs.push_back(Args.MakeArgString(
+ D.DyldPrefix + getLinuxDynamicLinker(Args, LinuxToolChain)));
+ }
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
@@ -7258,7 +7262,10 @@ void gnutools::Link::ConstructJob(Compil
}
}
- C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs));
+ const char *Exec =
+ IsLinux ? LinuxToolChain.Linker.c_str()
+ : Args.MakeArgString(ToolChain.GetProgramPath("ld"));
+ C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
Modified: cfe/trunk/test/Driver/bindings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/bindings.c?rev=211866&r1=211865&r2=211866&view=diff
==============================================================================
--- cfe/trunk/test/Driver/bindings.c (original)
+++ cfe/trunk/test/Driver/bindings.c Fri Jun 27 00:06:41 2014
@@ -2,7 +2,7 @@
// RUN: %clang -target i386-unknown-unknown -ccc-print-bindings -no-integrated-as %s 2>&1 | FileCheck %s --check-prefix=CHECK01
// CHECK01: "clang", inputs: ["{{.*}}bindings.c"], output: "{{.*}}.s"
// CHECK01: "GNU::Assemble", inputs: ["{{.*}}.s"], output: "{{.*}}.o"
-// CHECK01: "gcc::Link", inputs: ["{{.*}}.o"], output: "a.out"
+// CHECK01: "GNU::Link", inputs: ["{{.*}}.o"], output: "a.out"
// Clang control options
Modified: cfe/trunk/test/Driver/gcc_forward.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/gcc_forward.c?rev=211866&r1=211865&r2=211866&view=diff
==============================================================================
--- cfe/trunk/test/Driver/gcc_forward.c (original)
+++ cfe/trunk/test/Driver/gcc_forward.c Fri Jun 27 00:06:41 2014
@@ -17,14 +17,14 @@
// CHECK: as{{[^"]*}}"
// CHECK: "-o" "{{[^"]+}}.o"
//
-// gcc-ld
-// CHECK: gcc{{[^"]*}}"
+// gnu-ld
+// CHECK: ld{{[^"]*}}"
// CHECK-NOT: "-mlinker-version=10"
// CHECK-NOT: "-Xclang"
// CHECK-NOT: "foo-bar"
// CHECK-NOT: "-Wall"
// CHECK-NOT: "-Wdocumentation"
-// CHECK: -march
+// CHECK-NOT: "-march"
// CHECK-NOT: "-mlinker-version=10"
// CHECK-NOT: "-Xclang"
// CHECK-NOT: "foo-bar"
More information about the cfe-commits
mailing list