Skip to content

Commit e31ad38

Browse files
committed
Undo Linux linker order changes
Turns out the order of the linker flags matters on Linux; see swiftlang#9958. I don’t know if the change I previously made would break something, but it’s not worth risking it.
1 parent 6dbe717 commit e31ad38

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/Driver/UnixToolChains.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
194194
getRuntimeLibraryPaths(RuntimeLibPaths, context.Args, context.OI.SDKPath,
195195
/*Shared=*/!(staticExecutable || staticStdlib));
196196

197-
// Add the runtime library link paths.
198-
for (auto path : RuntimeLibPaths) {
199-
Arguments.push_back("-L");
200-
Arguments.push_back(context.Args.MakeArgString(path));
201-
}
202-
203197
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
204198
// FIXME: We probably shouldn't be adding an rpath here unless we know
205199
// ahead of time the standard library won't be copied.
@@ -246,9 +240,15 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
246240
Twine("@") + OutputInfo.getPrimaryOutputFilename()));
247241
}
248242

249-
// Link the standard library.
243+
// Add the runtime library link paths.
244+
for (auto path : RuntimeLibPaths) {
245+
Arguments.push_back("-L");
246+
Arguments.push_back(context.Args.MakeArgString(path));
247+
}
250248

251-
// If we need to use an .lnk file, linkFilePath will contain it.
249+
// Link the standard library. In two paths, we do this using a .lnk file;
250+
// if we're going that route, we'll set `linkFilePath` to the path to that
251+
// file.
252252
SmallString<128> linkFilePath;
253253
getResourceDirPath(linkFilePath, context.Args, /*Shared=*/false);
254254

test/Driver/linker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@
291291
// LINUX_DYNLIB-x86_64-DAG: -shared
292292
// LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold
293293
// LINUX_DYNLIB-x86_64-NOT: -pie
294-
// LINUX_DYNLIB-x86_64-DAG: -L [[STDLIB_PATH:[^ ]+(/|\\\\)lib(/|\\\\)swift(/|\\\\)linux]]
295-
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
294+
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+(/|\\\\)lib(/|\\\\)swift(/|\\\\)linux]]
296295
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]{{/|\\\\}}x86_64{{/|\\\\}}swiftrt.o
297296
// LINUX_DYNLIB-x86_64-DAG: [[OBJECTFILE]]
298297
// LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]]
298+
// LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]]
299299
// LINUX_DYNLIB-x86_64-DAG: -lswiftCore
300300
// LINUX_DYNLIB-x86_64-DAG: -L bar
301301
// LINUX_DYNLIB-x86_64: -o dynlib.out

0 commit comments

Comments
 (0)