[clang] 381df16 - Clang Driver: Use Apple ld64's new @response-file support.

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 29 15:27:21 PDT 2020


Author: James Y Knight
Date: 2020-06-29T18:26:53-04:00
New Revision: 381df1653c927efa9dac86c24a9db2b98f270de0

URL: https://github.com/llvm/llvm-project/commit/381df1653c927efa9dac86c24a9db2b98f270de0
DIFF: https://github.com/llvm/llvm-project/commit/381df1653c927efa9dac86c24a9db2b98f270de0.diff

LOG: 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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 7495e08fe6e6..0d3727b4ab8d 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -201,6 +201,9 @@ class ToolChain {
 
   // 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 47bf036d24d8..81b5576096e4 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 04c5bfa69a5a..5f13aa9a3087 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; }


        


More information about the cfe-commits mailing list