Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7.0][Driver] Work around lld 13+ issue with --gc-sections for ELF by adding -z nostart-stop-gc (#60544) #60740

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
#else
Arguments.push_back(context.Args.MakeArgString("-fuse-ld=" + Linker));
#endif
// Starting with lld 13, Swift stopped working with the lld --gc-sections
// implementation for ELF, unless -z nostart-stop-gc is also passed to lld:
//
// https://reviews.llvm.org/D96914
if (Linker == "lld" || (Linker.length() > 5 &&
Linker.substr(Linker.length() - 6) == "ld.lld")) {
Arguments.push_back("-Xlinker");
Arguments.push_back("-z");
Arguments.push_back("-Xlinker");
Arguments.push_back("nostart-stop-gc");
}
}

// Configure the toolchain.
Expand Down
2 changes: 2 additions & 0 deletions test/Driver/link-time-opt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// CHECK-SIMPLE-THIN-linux-gnu: clang
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -flto=thin
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -fuse-ld=lld
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -Xlinker -z -Xlinker nostart-stop-gc
// CHECK-SIMPLE-THIN-linux-gnu-DAG: [[BITCODEFILE]]
// CHECK-SIMPLE-THIN-linux-gnu-NOT: swift-autolink-extract

Expand All @@ -37,6 +38,7 @@
// CHECK-SIMPLE-FULL-linux-gnu: clang
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -flto=full
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -fuse-ld=lld
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -Xlinker -z -Xlinker nostart-stop-gc
// CHECK-SIMPLE-FULL-linux-gnu-DAG: [[BITCODEFILE]]
// CHECK-SIMPLE-FULL-linux-gnu-NOT: swift-autolink-extract

Expand Down