Skip to content

Commit

Permalink
[Driver] Work around lld 13+ issue with --gc-sections for ELF by addi…
Browse files Browse the repository at this point in the history
…ng -z nostart-stop-gc (swiftlang#60544)

Fixes swiftlang#60406 

Ran the linux x86_64 compiler validation suite on this pull with `-use-ld=lld -Xlinker --gc-sections`, then without stripping as in the linked issue, and only saw the 20 unrelated failures just like @drodriguez had.
  • Loading branch information
finagolfin committed Aug 19, 2022
1 parent 3a9211a commit e5e13aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit e5e13aa

Please sign in to comment.