Skip to content

Commit 34afd6a

Browse files
committed
Revert "Linux: Don't default to ld.gold linker"
This reverts commit e125411. It's too much of a breaking change for a point release.
1 parent df70a35 commit 34afd6a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

driver/linker-gcc.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,22 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
587587
void ArgsBuilder::addLinker() {
588588
llvm::StringRef linker = opts::linker;
589589

590-
// Default to ld.bfd for Android (placing .tdata and .tbss sections adjacent
591-
// to each other as required by druntime's rt.sections_android, contrary to
592-
// gold and lld as of Android NDK r21d).
593-
if (global.params.targetTriple->getEnvironment() == llvm::Triple::Android &&
590+
// We have a default linker preference for Linux targets. It can be disabled
591+
// via `-linker=` (explicitly empty).
592+
if (global.params.targetTriple->isOSLinux() &&
594593
opts::linker.getNumOccurrences() == 0) {
595-
linker = "bfd";
594+
// Default to ld.bfd for Android (placing .tdata and .tbss sections adjacent
595+
// to each other as required by druntime's rt.sections_android, contrary to
596+
// gold and lld as of Android NDK r21d).
597+
if (global.params.targetTriple->getEnvironment() == llvm::Triple::Android) {
598+
linker = "bfd";
599+
}
600+
// Otherwise default to ld.gold for Linux due to ld.bfd issues with ThinLTO
601+
// (see #2278) and older bfd versions stripping llvm.used symbols (e.g.,
602+
// ModuleInfo refs) with --gc-sections (see #2870).
603+
else {
604+
linker = "gold";
605+
}
596606
}
597607

598608
if (!linker.empty())

0 commit comments

Comments
 (0)