[PATCH] D82777: Clang Driver: Use Apple ld64's new @response-file support.

James Y Knight via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 29 09:10:17 PDT 2020


jyknight created this revision.
jyknight added reviewers: steven_wu, arphaman.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
jyknight added a child revision: D82782: Clang Driver: refactor support for writing response files to be specified at Command creation, rather than as part of the Tool..

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82777

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h


Index: clang/lib/Driver/ToolChains/Darwin.h
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -69,9 +69,10 @@
                    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; }
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -929,7 +929,22 @@
   }
 }
 
-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);
Index: clang/include/clang/Driver/ToolChain.h
===================================================================
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -201,6 +201,9 @@
 
   // 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; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82777.274145.patch
Type: text/x-patch
Size: 2237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200629/1babdc30/attachment-0001.bin>


More information about the cfe-commits mailing list