From 381df1653c927efa9dac86c24a9db2b98f270de0 Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Mon, 29 Jun 2020 18:26:53 -0400 Subject: [PATCH] Clang Driver: Use Apple ld64's new @response-file support. In XCode 12, ld64 got support for @files, in addition to the old -filelist mechanism. Response files allow passing all command-line arguments to the linker via a file, rather than just filenames, and is therefore preferred. Because of the way response-file support is currently implemented as part of the Tool class in Clang, this change requires an ugly backdoor function to access Args. A follow-up commit fixes this, but I've ordered this change first, for easier backportability. I've added no tests here, because unfortunately, there don't appear to be _any_ response-file emission automated tests, and I don't see an obvious way to add them. I've tested that this change works as expected locally. Differential Revision: https://reviews.llvm.org/D82777 --- clang/include/clang/Driver/ToolChain.h | 3 +++ clang/lib/Driver/ToolChains/Darwin.cpp | 17 ++++++++++++++++- clang/lib/Driver/ToolChains/Darwin.h | 7 ++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 7495e08..0d3727b 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -201,6 +201,9 @@ public: // Accessors + /// Temporary for Darwin::Linker + const llvm::opt::ArgList &getArgs_DO_NOT_USE() const { return Args; } + const Driver &getDriver() const { return D; } llvm::vfs::FileSystem &getVFS() const; const llvm::Triple &getTriple() const { return Triple; } diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 47bf036..81b5576 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -929,7 +929,22 @@ Tool *MachO::getTool(Action::ActionClass AC) const { } } -Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } +Tool *MachO::buildLinker() const { + // Determine whether to use an @responsefile or the old -filelist mechanism. + bool UseAtFile = false; + unsigned Version[5] = {0, 0, 0, 0, 0}; + if (Arg *A = + getArgs_DO_NOT_USE().getLastArg(options::OPT_mlinker_version_EQ)) { + // We don't need to diagnose a parse error here, it'll be caught in + // ConstructJob. + if (Driver::GetReleaseVersion(A->getValue(), Version)) { + if (Version[0] >= 607) + UseAtFile = true; + } + } + + return new tools::darwin::Linker(*this, UseAtFile); +} Tool *MachO::buildAssembler() const { return new tools::darwin::Assembler(*this); diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h index 04c5bfa..5f13aa9a 100644 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -69,9 +69,10 @@ class LLVM_LIBRARY_VISIBILITY Linker : public MachOTool { const InputInfoList &Inputs) const; public: - Linker(const ToolChain &TC) - : MachOTool("darwin::Linker", "linker", TC, RF_FileList, - llvm::sys::WEM_UTF8, "-filelist") {} + Linker(const ToolChain &TC, bool UseAtFile) + : MachOTool("darwin::Linker", "linker", TC, + UseAtFile ? RF_Full : RF_FileList, llvm::sys::WEM_UTF8, + UseAtFile ? "@" : "-filelist") {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } -- 2.7.4