Skip to content

Commit 577b18f

Browse files
committed
Unify linker argument order across platforms
Previously extra linker arguments had different behavior on darwin vs other unix platforms. On darwin the arguments passed with -Xlinker would be passed to the linker before the default arguments, where as with the default unix toolchain they would be passed afterwards. There isn't really a great option for which order these should be in. If you want to have a custom rpath that takes precedence over the default rpaths, you want them to be passed before, but if you want to negate a default argument you want them to come after. This change unifies the behavior so at least you always get the same behavior across platforms.
1 parent 0abb019 commit 577b18f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/Driver/UnixToolChains.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
210210
SmallString<128> StaticRuntimeLibPath;
211211
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, /*Shared=*/false);
212212

213+
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
214+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
215+
213216
// Add the runtime library link path, which is platform-specific and found
214217
// relative to the compiler.
215218
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
@@ -317,9 +320,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
317320
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
318321
}
319322

320-
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
321-
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
322-
323323
// Run clang++ in verbose mode if "-v" is set
324324
if (context.Args.hasArg(options::OPT_v)) {
325325
Arguments.push_back("-v");

test/Driver/linker.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
// RUN: %FileCheck %s < %t.complex.txt
4444
// RUN: %FileCheck -check-prefix COMPLEX %s < %t.complex.txt
4545

46+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios7.1 -Xlinker -rpath -Xlinker customrpath %s 2>&1 > %t.simple.txt
47+
// RUN: %FileCheck -check-prefix IOS-custom-rpath %s < %t.simple.txt
48+
49+
// RUN: %swiftc_driver -driver-print-jobs -target armv7-unknown-linux-gnueabihf -Xlinker -rpath -Xlinker customrpath %s 2>&1 > %t.linux.txt
50+
// RUN: %FileCheck -check-prefix LINUX-custom-rpath %s < %t.linux.txt
51+
4652
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -g %s | %FileCheck -check-prefix DEBUG %s
4753

4854
// RUN: %empty-directory(%t)
@@ -276,16 +282,30 @@
276282
// LINUX_DYNLIB-x86_64: clang++{{"? }}
277283
// LINUX_DYNLIB-x86_64-DAG: -shared
278284
// LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold
285+
// LINUX_DYNLIB-x86_64-DAG: -L bar
279286
// LINUX_DYNLIB-x86_64-NOT: -pie
280287
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
281288
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swiftrt.o
282289
// LINUX_DYNLIB-x86_64-DAG: [[OBJECTFILE]]
283290
// LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]]
284291
// LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]]
285292
// LINUX_DYNLIB-x86_64-DAG: -lswiftCore
286-
// LINUX_DYNLIB-x86_64-DAG: -L bar
287293
// LINUX_DYNLIB-x86_64: -o dynlib.out
288294

295+
// IOS-custom-rpath: swift
296+
// IOS-custom-rpath: -o [[OBJECTFILE:.*]]
297+
298+
// IOS-custom-rpath: bin/ld{{"? }}
299+
// IOS-custom-rpath: -rpath customrpath
300+
// IOS-custom-rpath: -rpath [[STDLIB_PATH:[^ ]+/lib/swift/iphonesimulator]]
301+
302+
// LINUX-custom-rpath: swift
303+
// LINUX-custom-rpath: -o [[OBJECTFILE:.*]]
304+
305+
// LINUX-custom-rpath: clang++{{"? }}
306+
// LINUX-custom-rpath: -Xlinker -rpath -Xlinker customrpath
307+
// LINUX-custom-rpath: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
308+
289309
// DEBUG: bin/swift
290310
// DEBUG-NEXT: bin/swift
291311
// DEBUG-NEXT: bin/ld{{"? }}

0 commit comments

Comments
 (0)