Skip to content

Commit 381df16

Browse files
committed
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
1 parent bdcd200 commit 381df16

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ class ToolChain {
201201

202202
// Accessors
203203

204+
/// Temporary for Darwin::Linker
205+
const llvm::opt::ArgList &getArgs_DO_NOT_USE() const { return Args; }
206+
204207
const Driver &getDriver() const { return D; }
205208
llvm::vfs::FileSystem &getVFS() const;
206209
const llvm::Triple &getTriple() const { return Triple; }

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,22 @@ Tool *MachO::getTool(Action::ActionClass AC) const {
929929
}
930930
}
931931

932-
Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); }
932+
Tool *MachO::buildLinker() const {
933+
// Determine whether to use an @responsefile or the old -filelist mechanism.
934+
bool UseAtFile = false;
935+
unsigned Version[5] = {0, 0, 0, 0, 0};
936+
if (Arg *A =
937+
getArgs_DO_NOT_USE().getLastArg(options::OPT_mlinker_version_EQ)) {
938+
// We don't need to diagnose a parse error here, it'll be caught in
939+
// ConstructJob.
940+
if (Driver::GetReleaseVersion(A->getValue(), Version)) {
941+
if (Version[0] >= 607)
942+
UseAtFile = true;
943+
}
944+
}
945+
946+
return new tools::darwin::Linker(*this, UseAtFile);
947+
}
933948

934949
Tool *MachO::buildAssembler() const {
935950
return new tools::darwin::Assembler(*this);

clang/lib/Driver/ToolChains/Darwin.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class LLVM_LIBRARY_VISIBILITY Linker : public MachOTool {
6969
const InputInfoList &Inputs) const;
7070

7171
public:
72-
Linker(const ToolChain &TC)
73-
: MachOTool("darwin::Linker", "linker", TC, RF_FileList,
74-
llvm::sys::WEM_UTF8, "-filelist") {}
72+
Linker(const ToolChain &TC, bool UseAtFile)
73+
: MachOTool("darwin::Linker", "linker", TC,
74+
UseAtFile ? RF_Full : RF_FileList, llvm::sys::WEM_UTF8,
75+
UseAtFile ? "@" : "-filelist") {}
7576

7677
bool hasIntegratedCPP() const override { return false; }
7778
bool isLinkJob() const override { return true; }

0 commit comments

Comments
 (0)