Skip to content

Commit 1f4e643

Browse files
committed
Move linker arguments to the end
1 parent 577b18f commit 1f4e643

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
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.AddAllArgValues(Arguments, options::OPT_Xlinker);
480+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
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
@@ -210,9 +210,6 @@ 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-
216213
// Add the runtime library link path, which is platform-specific and found
217214
// relative to the compiler.
218215
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
@@ -325,6 +322,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
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_Xlinker);
327+
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,29 +282,31 @@
282282
// LINUX_DYNLIB-x86_64: clang++{{"? }}
283283
// LINUX_DYNLIB-x86_64-DAG: -shared
284284
// LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold
285-
// LINUX_DYNLIB-x86_64-DAG: -L bar
286285
// LINUX_DYNLIB-x86_64-NOT: -pie
287286
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
288287
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swiftrt.o
289288
// LINUX_DYNLIB-x86_64-DAG: [[OBJECTFILE]]
290289
// LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]]
291290
// LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]]
292291
// LINUX_DYNLIB-x86_64-DAG: -lswiftCore
292+
// LINUX_DYNLIB-x86_64-DAG: -L bar
293293
// LINUX_DYNLIB-x86_64: -o dynlib.out
294294

295295
// IOS-custom-rpath: swift
296296
// IOS-custom-rpath: -o [[OBJECTFILE:.*]]
297297

298298
// IOS-custom-rpath: bin/ld{{"? }}
299-
// IOS-custom-rpath: -rpath customrpath
300299
// IOS-custom-rpath: -rpath [[STDLIB_PATH:[^ ]+/lib/swift/iphonesimulator]]
300+
// IOS-custom-rpath: -rpath customrpath
301+
// IOS-custom-rpath: -o {{.*}}
301302

302303
// LINUX-custom-rpath: swift
303304
// LINUX-custom-rpath: -o [[OBJECTFILE:.*]]
304305

305306
// LINUX-custom-rpath: clang++{{"? }}
307+
// LINUX-custom-rpath: -Xlinker -rpath -Xlinker {{[^ ]+/lib/swift/linux}}
306308
// LINUX-custom-rpath: -Xlinker -rpath -Xlinker customrpath
307-
// LINUX-custom-rpath: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
309+
// LINUX-custom-rpath: -o {{.*}}
308310

309311
// DEBUG: bin/swift
310312
// DEBUG-NEXT: bin/swift

0 commit comments

Comments
 (0)