Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,

// Add the runtime library link path, which is platform-specific and found
// relative to the compiler.
if (!staticExecutable && shouldProvideRPathToLinker()) {
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
// FIXME: We probably shouldn't be adding an rpath here unless we know
// ahead of time the standard library won't be copied.
Arguments.push_back("-Xlinker");
Expand All @@ -1534,8 +1534,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
addPrimaryInputsOfType(Arguments, context.Inputs, types::TY_Object);
addInputsOfType(Arguments, context.InputActions, types::TY_Object);

context.Args.AddAllArgs(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)) {
if (arg->getOption().matches(options::OPT_Fsystem))
Expand All @@ -1550,6 +1548,14 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
Arguments.push_back(context.Args.MakeArgString(context.OI.SDKPath));
}

// Add any autolinking scripts to the arguments
for (const Job *Cmd : context.Inputs) {
auto &OutputInfo = Cmd->getOutput();
if (OutputInfo.getPrimaryOutputType() == types::TY_AutolinkFile)
Arguments.push_back(context.Args.MakeArgString(
Twine("@") + OutputInfo.getPrimaryOutputFilename()));
}

// Link the standard library.
Arguments.push_back("-L");

Expand Down Expand Up @@ -1601,14 +1607,8 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
}


// Add any autolinking scripts to the arguments
for (const Job *Cmd : context.Inputs) {
auto &OutputInfo = Cmd->getOutput();
if (OutputInfo.getPrimaryOutputType() == types::TY_AutolinkFile)
Arguments.push_back(context.Args.MakeArgString(
Twine("@") + OutputInfo.getPrimaryOutputFilename()));
}
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);

// Just before the output option, allow GenericUnix toolchains to add
// additional inputs.
Expand Down
11 changes: 11 additions & 0 deletions test/Driver/linker-args-order-linux.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Statically link a "hello world" program
// REQUIRES: OS=linux-gnu
// REQUIRES: static_stdlib
print("hello world!")
// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -v -static-stdlib -o %t/static-stdlib %s -Xlinker --no-allow-multiple-definition 2>&1| %FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to actually run the linker here. Instead, you can use -### (or -driver-print-jobs) to show what would be run. That way we can run the test on other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to update the test? The argument reordering change is only for Linux (actually GenericUnix) so I don't think it will make any difference on other platforms.

Copy link
Contributor

@jrose-apple jrose-apple Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. GenericUnix is still used in other places, and it's useful to be able to run the test even on Darwin. (Also, not actually compiling and linking would run faster.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple Ive added the -driver-print-jobs and removed the linux requirement. It tested ok on Linux and macOS. If the commit looks ok could you rerun the tests please.

// CHECK: Swift version
// CHECK: Target: x86_64-unknown-linux-gnu
// CHECK: {{.*}}/swift -frontend -c -primary-file {{.*}}/linker-args-order-linux.swift -target x86_64-unknown-linux-gnu -disable-objc-interop
// CHECK: {{.*}}/swift-autolink-extract{{.*}}
// 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
22 changes: 20 additions & 2 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -2454,14 +2454,21 @@ for host in "${ALL_HOSTS[@]}"; do
else
dispatch_build_variant_arg="debug"
fi

if [ $(true_false "${BUILD_SWIFT_STATIC_STDLIB}") == "TRUE" ]; then
libdispatch_enable_static="--enable-static=yes"
else
libdispatch_enable_static=""
fi

call mkdir -p "${LIBDISPATCH_BUILD_DIR}"
with_pushd "${LIBDISPATCH_SOURCE_DIR}" \
call autoreconf -fvi
with_pushd "${LIBDISPATCH_BUILD_DIR}" \
call env CC="${LLVM_BIN}/clang" CXX="${LLVM_BIN}/clang++" SWIFTC="${SWIFTC_BIN}" \
"${LIBDISPATCH_SOURCE_DIR}"/configure --with-swift-toolchain="${SWIFT_BUILD_PATH}" \
--with-build-variant=$dispatch_build_variant_arg \
--prefix="$(get_host_install_destdir ${host})$(get_host_install_prefix ${host})"
--prefix="$(get_host_install_destdir ${host})$(get_host_install_prefix ${host})" ${libdispatch_enable_static}
else
echo "Skipping reconfiguration of libdispatch"
fi
Expand Down Expand Up @@ -3050,10 +3057,16 @@ for host in "${ALL_HOSTS[@]}"; do
echo "--- Installing ${product} ---"
XCTEST_BUILD_DIR=$(build_directory ${host} xctest)
XCTEST_INSTALL_PREFIX="${host_install_destdir}${host_install_prefix}/lib/swift/${LIB_TARGET}"
if [ $(true_false "${BUILD_SWIFT_STATIC_STDLIB}") == "TRUE" ]; then
XCTEST_STATIC_INSTALL_PREFIX="${host_install_destdir}${host_install_prefix}/lib/swift_static/${LIB_TARGET}"
xctest_static_install="--static-library-install-path=${XCTEST_STATIC_INSTALL_PREFIX}"
else
xctest_static_install=""
fi
# Note that installing directly to /usr/lib/swift usually
# requires root permissions.
call "${XCTEST_SOURCE_DIR}"/build_script.py install \
--library-install-path="${XCTEST_INSTALL_PREFIX}" \
--library-install-path="${XCTEST_INSTALL_PREFIX}" ${xctest_static_install} \
--module-install-path="${XCTEST_INSTALL_PREFIX}"/"${SWIFT_HOST_VARIANT_ARCH}" \
"${XCTEST_BUILD_DIR}"

Expand Down Expand Up @@ -3093,6 +3106,11 @@ for host in "${ALL_HOSTS[@]}"; do
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
with_pushd "${LIBDISPATCH_BUILD_DIR}" \
call make install
DISPATCH_LIBDIR="${host_install_destdir}${host_install_prefix}/lib/swift/${SWIFT_HOST_VARIANT}"
DISPATCH_LIBDIR_STATIC="${host_install_destdir}${host_install_prefix}/lib/swift_static/${SWIFT_HOST_VARIANT}"
if [ -f "$DISPATCH_LIBDIR/libdispatch.a" ]; then
mv "$DISPATCH_LIBDIR/libdispatch.a" "$DISPATCH_LIBDIR_STATIC"
fi

# As libdispatch installation is self-contained, we break early here.
continue
Expand Down