diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2014-06-27 05:06:41 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2014-06-27 05:06:41 +0000 |
commit | 3f48d22b9ea26f03a28b54cb3c4bcd920b3496a7 (patch) | |
tree | cee1e3678641e57abc0495d9b0cd8c7ec1f878d0 | |
parent | f85d10e6c52e1ff79200ecdc9247814281949546 (diff) | |
download | clang-3f48d22b9ea26f03a28b54cb3c4bcd920b3496a7.tar.gz clang-3f48d22b9ea26f03a28b54cb3c4bcd920b3496a7.tar.bz2 clang-3f48d22b9ea26f03a28b54cb3c4bcd920b3496a7.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211866 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Driver/ToolChains.cpp | 2 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 39 | ||||
-rw-r--r-- | test/Driver/bindings.c | 2 | ||||
-rw-r--r-- | test/Driver/gcc_forward.c | 6 |
4 files changed, 28 insertions, 21 deletions
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index d02c84d315..c01f0326a0 100644 --- a/lib/Driver/ToolChains.cpp +++ b/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/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 28528ffbd0..1402f78f08 100644 --- a/lib/Driver/Tools.cpp +++ b/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<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(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/test/Driver/bindings.c b/test/Driver/bindings.c index dd8ad14f67..9653a5794e 100644 --- a/test/Driver/bindings.c +++ b/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/test/Driver/gcc_forward.c b/test/Driver/gcc_forward.c index 3bc413193f..a58cd9f501 100644 --- a/test/Driver/gcc_forward.c +++ b/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" |