Skip to content

Commit 3ac5e12

Browse files
committed
[Linux] Reorder the -Xlinker and -l arguments
- Move the -Xlinker and -l options to just before swift_end.o - Add testcase to check linker option ordering.
1 parent 03b067b commit 3ac5e12

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
15341534
addPrimaryInputsOfType(Arguments, context.Inputs, types::TY_Object);
15351535
addInputsOfType(Arguments, context.InputActions, types::TY_Object);
15361536

1537-
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
1538-
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
15391537
for (const Arg *arg : context.Args.filtered(options::OPT_F,
15401538
options::OPT_Fsystem)) {
15411539
if (arg->getOption().matches(options::OPT_Fsystem))
@@ -1609,6 +1607,9 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
16091607
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
16101608
}
16111609

1610+
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
1611+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
1612+
16121613
// Just before the output option, allow GenericUnix toolchains to add
16131614
// additional inputs.
16141615
auto PostInputObjectPath = getPostInputObjectPath(ObjectLibPath);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Statically link a "hello world" program
2+
// REQUIRES: OS=linux-gnu
3+
// REQUIRES: static_stdlib
4+
print("hello world!")
5+
// RUN: %empty-directory(%t)
6+
// RUN: %target-swiftc_driver -v -static-stdlib -o %t/static-stdlib %s -Xlinker --no-allow-multiple-definition 2>&1| %FileCheck %s
7+
// CHECK: Swift version
8+
// CHECK: Target: x86_64-unknown-linux-gnu
9+
// CHECK: {{.*}}/swift -frontend -c -primary-file {{.*}}/linker-args-order-linux.swift -target x86_64-unknown-linux-gnu -disable-objc-interop
10+
// CHECK: {{.*}}/swift-autolink-extract{{.*}}
11+
// CHECK: {{.*}}swift_begin.o /{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.o @/{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.autolink {{.*}} @{{.*}}/static-stdlib-args.lnk {{.*}} -Xlinker --no-allow-multiple-definition {{.*}}/swift_end.o

0 commit comments

Comments
 (0)