Skip to content

Commit 3ff6c1c

Browse files
author
David Ungar
authored
Merge pull request swiftlang#28347 from davidungar/rdar-56946329-dynlink-filelist
[Driver] Use correct designator for filelist for dynamic link job
2 parents f240867 + cca40fc commit 3ff6c1c

File tree

5 files changed

+77
-48
lines changed

5 files changed

+77
-48
lines changed

include/swift/Driver/Util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ namespace driver {
4545
/// the Job this info is attached to.
4646
struct FilelistInfo {
4747
enum class WhichFiles : unsigned {
48-
Input,
49-
PrimaryInputs,
48+
InputJobs,
49+
SourceInputActions,
50+
InputJobsAndSourceInputActions,
5051
Output,
5152
/// Batch mode frontend invocations may have so many supplementary
5253
/// outputs that they don't comfortably fit as command-line arguments.

lib/Driver/Compilation.cpp

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,51 @@ static void writeCompilationRecord(StringRef path, StringRef argsHash,
13561356
}
13571357
}
13581358

1359+
static void writeInputJobsToFilelist(llvm::raw_fd_ostream &out, const Job *job,
1360+
const file_types::ID infoType) {
1361+
// FIXME: Duplicated from ToolChains.cpp.
1362+
for (const Job *input : job->getInputs()) {
1363+
const CommandOutput &outputInfo = input->getOutput();
1364+
if (outputInfo.getPrimaryOutputType() == infoType) {
1365+
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1366+
out << output << "\n";
1367+
} else {
1368+
auto output = outputInfo.getAnyOutputForType(infoType);
1369+
if (!output.empty())
1370+
out << output << "\n";
1371+
}
1372+
}
1373+
}
1374+
static void writeSourceInputActionsToFilelist(llvm::raw_fd_ostream &out,
1375+
const Job *job,
1376+
const ArgList &args) {
1377+
// Ensure that -index-file-path works in conjunction with
1378+
// -driver-use-filelists. It needs to be the only primary.
1379+
if (Arg *A = args.getLastArg(options::OPT_index_file_path))
1380+
out << A->getValue() << "\n";
1381+
else {
1382+
// The normal case for non-single-compile jobs.
1383+
for (const Action *A : job->getSource().getInputs()) {
1384+
// A could be a GeneratePCHJobAction
1385+
if (!isa<InputAction>(A))
1386+
continue;
1387+
const auto *IA = cast<InputAction>(A);
1388+
out << IA->getInputArg().getValue() << "\n";
1389+
}
1390+
}
1391+
}
1392+
static void writeOutputToFilelist(llvm::raw_fd_ostream &out, const Job *job,
1393+
const file_types::ID infoType) {
1394+
const CommandOutput &outputInfo = job->getOutput();
1395+
assert(outputInfo.getPrimaryOutputType() == infoType);
1396+
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1397+
out << output << "\n";
1398+
}
1399+
static void writeSupplementarOutputToFilelist(llvm::raw_fd_ostream &out,
1400+
const Job *job) {
1401+
job->getOutput().writeOutputFileMap(out);
1402+
}
1403+
13591404
static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
13601405
DiagnosticEngine &diags) {
13611406
bool ok = true;
@@ -1374,46 +1419,23 @@ static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
13741419
}
13751420

13761421
switch (filelistInfo.whichFiles) {
1377-
case FilelistInfo::WhichFiles::Input:
1378-
// FIXME: Duplicated from ToolChains.cpp.
1379-
for (const Job *input : job->getInputs()) {
1380-
const CommandOutput &outputInfo = input->getOutput();
1381-
if (outputInfo.getPrimaryOutputType() == filelistInfo.type) {
1382-
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1383-
out << output << "\n";
1384-
} else {
1385-
auto output = outputInfo.getAnyOutputForType(filelistInfo.type);
1386-
if (!output.empty())
1387-
out << output << "\n";
1388-
}
1389-
}
1422+
case FilelistInfo::WhichFiles::InputJobs:
1423+
writeInputJobsToFilelist(out, job, filelistInfo.type);
13901424
break;
1391-
case FilelistInfo::WhichFiles::PrimaryInputs:
1392-
// Ensure that -index-file-path works in conjunction with
1393-
// -driver-use-filelists. It needs to be the only primary.
1394-
if (Arg *A = args.getLastArg(options::OPT_index_file_path))
1395-
out << A->getValue() << "\n";
1396-
else {
1397-
// The normal case for non-single-compile jobs.
1398-
for (const Action *A : job->getSource().getInputs()) {
1399-
// A could be a GeneratePCHJobAction
1400-
if (!isa<InputAction>(A))
1401-
continue;
1402-
const auto *IA = cast<InputAction>(A);
1403-
out << IA->getInputArg().getValue() << "\n";
1404-
}
1405-
}
1425+
case FilelistInfo::WhichFiles::SourceInputActions:
1426+
writeSourceInputActionsToFilelist(out, job, args);
14061427
break;
1407-
case FilelistInfo::WhichFiles::Output: {
1408-
const CommandOutput &outputInfo = job->getOutput();
1409-
assert(outputInfo.getPrimaryOutputType() == filelistInfo.type);
1410-
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1411-
out << output << "\n";
1428+
case FilelistInfo::WhichFiles::InputJobsAndSourceInputActions:
1429+
writeInputJobsToFilelist(out, job, filelistInfo.type);
1430+
writeSourceInputActionsToFilelist(out, job, args);
14121431
break;
1413-
}
1414-
case FilelistInfo::WhichFiles::SupplementaryOutput:
1415-
job->getOutput().writeOutputFileMap(out);
1432+
case FilelistInfo::WhichFiles::Output: {
1433+
writeOutputToFilelist(out, job, filelistInfo.type);
14161434
break;
1435+
}
1436+
case FilelistInfo::WhichFiles::SupplementaryOutput:
1437+
writeSupplementarOutputToFilelist(out, job);
1438+
break;
14171439
}
14181440
}
14191441
return ok;

lib/Driver/DarwinToolChains.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,15 @@ toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
231231
if (context.shouldUseInputFileList()) {
232232
Arguments.push_back("-filelist");
233233
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
234-
II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object,
235-
FilelistInfo::WhichFiles::Input});
234+
II.FilelistInfos.push_back(
235+
{Arguments.back(), file_types::TY_Object,
236+
FilelistInfo::WhichFiles::InputJobsAndSourceInputActions});
236237
} else {
237238
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
238239
file_types::TY_Object);
240+
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
239241
}
240242

241-
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
242243

243244
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile)
244245
addInputsOfType(Arguments, context.Inputs, context.Args,
@@ -643,7 +644,7 @@ toolchains::Darwin::constructInvocation(const StaticLinkJobAction &job,
643644
Arguments.push_back("-filelist");
644645
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
645646
II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object,
646-
FilelistInfo::WhichFiles::Input});
647+
FilelistInfo::WhichFiles::InputJobs});
647648
} else {
648649
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
649650
file_types::TY_Object);

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ void ToolChain::JobContext::addFrontendInputAndOutputArguments(
579579
Arguments.push_back("-primary-filelist");
580580
Arguments.push_back(getTemporaryFilePath("primaryInputs", ""));
581581
FilelistInfos.push_back({Arguments.back(), file_types::TY_Swift,
582-
FilelistInfo::WhichFiles::PrimaryInputs});
582+
FilelistInfo::WhichFiles::SourceInputActions});
583583
}
584584
if (!UseFileList || !UsePrimaryFileList) {
585585
addFrontendCommandLineInputArguments(MayHavePrimaryInputs, UseFileList,
@@ -876,7 +876,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
876876
Arguments.push_back(context.getTemporaryFilePath("inputs", ""));
877877
II.FilelistInfos.push_back({Arguments.back(),
878878
file_types::TY_SwiftModuleFile,
879-
FilelistInfo::WhichFiles::Input});
879+
FilelistInfo::WhichFiles::InputJobs});
880880

881881
addInputsOfType(Arguments, context.InputActions,
882882
file_types::TY_SwiftModuleFile);

test/Driver/linker.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@
7070
// RUN: %FileCheck -check-prefix SIMPLE %s < %t.simple-macosx10.10.txt
7171

7272
// RUN: %empty-directory(%t)
73-
// RUN: touch %t/a.o
73+
// RUN: echo "int dummy;" >%t/a.cpp
74+
// RUN: cc -c %t/a.cpp -o %t/a.o
7475
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o -o linker 2>&1 | %FileCheck -check-prefix COMPILE_AND_LINK %s
75-
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o -driver-filelist-threshold=0 -o linker 2>&1 | %FileCheck -check-prefix FILELIST %s
76+
// RUN: %swiftc_driver -save-temps -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o -driver-filelist-threshold=0 -o linker 2>&1 | tee %t/forFilelistCapture | %FileCheck -check-prefix FILELIST %s
77+
78+
// Extract filelist name and check it out
79+
// RUN: tail -1 %t/forFilelistCapture | sed 's/.*-filelist //' | sed 's/ .*//' >%t/filelistName
80+
// RUN: %FileCheck -check-prefix FILELIST-CONTENTS %s < `cat %t/filelistName`
7681

7782
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME_DARWIN %s
7883
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME_LINUX %s
@@ -346,10 +351,10 @@
346351
// FILELIST-NOT: .o{{"? }}
347352
// FILELIST: -filelist {{"?[^-]}}
348353
// FILELIST-NOT: .o{{"? }}
349-
// FILELIST: /a.o{{"? }}
350-
// FILELIST-NOT: .o{{"? }}
351354
// FILELIST: -o linker
352355

356+
// FILELIST-CONTENTS: /linker-{{.*}}.o
357+
// FILELIST-CONTENTS: /a.o
353358

354359
// INFERRED_NAME_DARWIN: bin{{/|\\\\}}swift{{c?(\.EXE)?}}
355360
// INFERRED_NAME_DARWIN: -module-name LINKER

0 commit comments

Comments
 (0)