From 4b68a05f3d29036a3bfe778255cffcd983349a13 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 27 Jun 2014 05:06:41 +0000 Subject: [PATCH] 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. llvm-svn: 211866 --- clang/lib/Driver/ToolChains.cpp | 2 +- clang/lib/Driver/Tools.cpp | 39 +++++++++++++++++++++++---------------- clang/test/Driver/bindings.c | 2 +- clang/test/Driver/gcc_forward.c | 6 +++--- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index d02c84d..c01f032 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -2102,7 +2102,7 @@ Tool *Generic_GCC::buildAssembler() const { } 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 { diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 28528ff..1402f78 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -7013,11 +7013,13 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::Linux& ToolChain = + const toolchains::Linux& LinuxToolChain = static_cast(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(Compilation &C, const JobAction &JA, 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(Compilation &C, const JobAction &JA, } } - 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(Compilation &C, const JobAction &JA, } } - 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, diff --git a/clang/test/Driver/bindings.c b/clang/test/Driver/bindings.c index dd8ad14..9653a57 100644 --- a/clang/test/Driver/bindings.c +++ b/clang/test/Driver/bindings.c @@ -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 diff --git a/clang/test/Driver/gcc_forward.c b/clang/test/Driver/gcc_forward.c index 3bc4131..a58cd9f 100644 --- a/clang/test/Driver/gcc_forward.c +++ b/clang/test/Driver/gcc_forward.c @@ -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" -- 2.7.4