Skip to content

Commit 03b067b

Browse files
committed
[Linux] Reorder arguments for autolink files from swift-autolink-extract
- Reordering the auto link files when linking in static libraries and object files is required because the ordering of arguments is important, and the dependant libraries need to come after the objects/libs that require them. This is not a problem for libswiftCore.a but can be an issue with libs that sit on top of it, e.g. libFoundation.a - Dont add an -rpath to the Swift dynamic libraries if using -static-stdlib
1 parent b08023a commit 03b067b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
15181518

15191519
// Add the runtime library link path, which is platform-specific and found
15201520
// relative to the compiler.
1521-
if (!staticExecutable && shouldProvideRPathToLinker()) {
1521+
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
15221522
// FIXME: We probably shouldn't be adding an rpath here unless we know
15231523
// ahead of time the standard library won't be copied.
15241524
Arguments.push_back("-Xlinker");
@@ -1550,6 +1550,14 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
15501550
Arguments.push_back(context.Args.MakeArgString(context.OI.SDKPath));
15511551
}
15521552

1553+
// Add any autolinking scripts to the arguments
1554+
for (const Job *Cmd : context.Inputs) {
1555+
auto &OutputInfo = Cmd->getOutput();
1556+
if (OutputInfo.getPrimaryOutputType() == types::TY_AutolinkFile)
1557+
Arguments.push_back(context.Args.MakeArgString(
1558+
Twine("@") + OutputInfo.getPrimaryOutputFilename()));
1559+
}
1560+
15531561
// Link the standard library.
15541562
Arguments.push_back("-L");
15551563

@@ -1601,15 +1609,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
16011609
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
16021610
}
16031611

1604-
1605-
// Add any autolinking scripts to the arguments
1606-
for (const Job *Cmd : context.Inputs) {
1607-
auto &OutputInfo = Cmd->getOutput();
1608-
if (OutputInfo.getPrimaryOutputType() == types::TY_AutolinkFile)
1609-
Arguments.push_back(context.Args.MakeArgString(
1610-
Twine("@") + OutputInfo.getPrimaryOutputFilename()));
1611-
}
1612-
16131612
// Just before the output option, allow GenericUnix toolchains to add
16141613
// additional inputs.
16151614
auto PostInputObjectPath = getPostInputObjectPath(ObjectLibPath);

0 commit comments

Comments
 (0)