Skip to content

Commit 634cf7e

Browse files
authored
Merge pull request #18266 from keith/ks/linker-order
Unify linker argument order across platforms
2 parents f6c77f5 + 14f0241 commit 634cf7e

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

lib/Driver/DarwinToolChains.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
339339
}
340340
}
341341

342-
context.Args.AddAllArgValues(Arguments, options::OPT_Xlinker);
343-
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
344342
for (const Arg *arg :
345343
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
346344
Arguments.push_back("-F");
@@ -477,6 +475,10 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
477475

478476
Arguments.push_back("-no_objc_category_merging");
479477

478+
// These custom arguments should be right before the object file at the end.
479+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
480+
context.Args.AddAllArgValues(Arguments, options::OPT_Xlinker);
481+
480482
// This should be the last option, for convenience in checking output.
481483
Arguments.push_back("-o");
482484
Arguments.push_back(

lib/Driver/UnixToolChains.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,15 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
317317
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
318318
}
319319

320-
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
321-
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
322-
323320
// Run clang++ in verbose mode if "-v" is set
324321
if (context.Args.hasArg(options::OPT_v)) {
325322
Arguments.push_back("-v");
326323
}
327324

325+
// These custom arguments should be right before the object file at the end.
326+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
327+
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
328+
328329
// This should be the last option, for convenience in checking output.
329330
Arguments.push_back("-o");
330331
Arguments.push_back(

test/Driver/linker.swift

Lines changed: 24 additions & 0 deletions
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 -L foo %s 2>&1 > %t.simple.txt
47+
// RUN: %FileCheck -check-prefix IOS-linker-order %s < %t.simple.txt
48+
49+
// RUN: %swiftc_driver -driver-print-jobs -target armv7-unknown-linux-gnueabihf -Xlinker -rpath -Xlinker customrpath -L foo %s 2>&1 > %t.linux.txt
50+
// RUN: %FileCheck -check-prefix LINUX-linker-order %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)
@@ -286,6 +292,24 @@
286292
// LINUX_DYNLIB-x86_64-DAG: -L bar
287293
// LINUX_DYNLIB-x86_64: -o dynlib.out
288294

295+
// IOS-linker-order: swift
296+
// IOS-linker-order: -o [[OBJECTFILE:.*]]
297+
298+
// IOS-linker-order: bin/ld{{"? }}
299+
// IOS-linker-order: -rpath [[STDLIB_PATH:[^ ]+/lib/swift/iphonesimulator]]
300+
// IOS-linker-order: -L foo
301+
// IOS-linker-order: -rpath customrpath
302+
// IOS-linker-order: -o {{.*}}
303+
304+
// LINUX-linker-order: swift
305+
// LINUX-linker-order: -o [[OBJECTFILE:.*]]
306+
307+
// LINUX-linker-order: clang++{{"? }}
308+
// LINUX-linker-order: -Xlinker -rpath -Xlinker {{[^ ]+/lib/swift/linux}}
309+
// LINUX-linker-order: -L foo
310+
// LINUX-linker-order: -Xlinker -rpath -Xlinker customrpath
311+
// LINUX-linker-order: -o {{.*}}
312+
289313
// DEBUG: bin/swift
290314
// DEBUG-NEXT: bin/swift
291315
// DEBUG-NEXT: bin/ld{{"? }}

0 commit comments

Comments
 (0)