From 1f4e643d422a33ffaabfcc7ba5be4449b8fcd985 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 27 Jul 2018 14:34:00 -0700 Subject: [PATCH] Move linker arguments to the end --- lib/Driver/DarwinToolChains.cpp | 6 ++++-- lib/Driver/UnixToolChains.cpp | 7 ++++--- test/Driver/linker.swift | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index cbb63ffed36..7c7830d9785 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -339,8 +339,6 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job, } } - context.Args.AddAllArgValues(Arguments, options::OPT_Xlinker); - context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group); for (const Arg *arg : context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { Arguments.push_back("-F"); @@ -477,6 +475,10 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job, Arguments.push_back("-no_objc_category_merging"); + // These custom arguments should be right before the object file at the end + context.Args.AddAllArgValues(Arguments, options::OPT_Xlinker); + context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group); + // This should be the last option, for convenience in checking output. Arguments.push_back("-o"); Arguments.push_back( diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 6c69f7804a0..51b9b8e1b40 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -210,9 +210,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, SmallString<128> StaticRuntimeLibPath; getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, /*Shared=*/false); - context.Args.AddAllArgs(Arguments, options::OPT_Xlinker); - context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group); - // Add the runtime library link path, which is platform-specific and found // relative to the compiler. if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) { @@ -325,6 +322,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, Arguments.push_back("-v"); } + // These custom arguments should be right before the object file at the end + context.Args.AddAllArgs(Arguments, options::OPT_Xlinker); + context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group); + // This should be the last option, for convenience in checking output. Arguments.push_back("-o"); Arguments.push_back( diff --git a/test/Driver/linker.swift b/test/Driver/linker.swift index 347ed9fa702..9885cd3862a 100644 --- a/test/Driver/linker.swift +++ b/test/Driver/linker.swift @@ -282,7 +282,6 @@ // LINUX_DYNLIB-x86_64: clang++{{"? }} // LINUX_DYNLIB-x86_64-DAG: -shared // LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold -// LINUX_DYNLIB-x86_64-DAG: -L bar // LINUX_DYNLIB-x86_64-NOT: -pie // LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]] // LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swiftrt.o @@ -290,21 +289,24 @@ // LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]] // LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]] // LINUX_DYNLIB-x86_64-DAG: -lswiftCore +// LINUX_DYNLIB-x86_64-DAG: -L bar // LINUX_DYNLIB-x86_64: -o dynlib.out // IOS-custom-rpath: swift // IOS-custom-rpath: -o [[OBJECTFILE:.*]] // IOS-custom-rpath: bin/ld{{"? }} -// IOS-custom-rpath: -rpath customrpath // IOS-custom-rpath: -rpath [[STDLIB_PATH:[^ ]+/lib/swift/iphonesimulator]] +// IOS-custom-rpath: -rpath customrpath +// IOS-custom-rpath: -o {{.*}} // LINUX-custom-rpath: swift // LINUX-custom-rpath: -o [[OBJECTFILE:.*]] // LINUX-custom-rpath: clang++{{"? }} +// LINUX-custom-rpath: -Xlinker -rpath -Xlinker {{[^ ]+/lib/swift/linux}} // LINUX-custom-rpath: -Xlinker -rpath -Xlinker customrpath -// LINUX-custom-rpath: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]] +// LINUX-custom-rpath: -o {{.*}} // DEBUG: bin/swift // DEBUG-NEXT: bin/swift