[K/N] Use LLD 12.0.1 for MinGW targets

Clang-produced and GCC-produced binaries might be ABI-incompatible on
MinGW. Explanation on GitHub: msys2/MINGW-packages/issues/6855#issuecomment-680859662.
TL;DR: GCC-generated sections are 16-byte-padded, while Clang ones are
not. It causes problems during merge of COMDAT sections.
I observed the problem during compilation of runtime tests, but it is
possible that the problem could affect main compilation pipeline as well.
https://reviews.llvm.org/D86659 (which landed in LLVM 12) fixes
the problem. So we have another motivation for switching to LLD besides
https://youtrack.jetbrains.com/issue/KT-47605.

The only known downside is unsupported defsym which causes slight binary
size increase. I think it is doable.
This commit is contained in:
Sergey Bogolepov
2021-07-23 17:29:36 +07:00
committed by Space
parent 6e093b0beb
commit c7c78e0e1a
6 changed files with 7 additions and 108 deletions
@@ -441,11 +441,6 @@ class MingwLinker(targetProperties: MingwConfigurables)
return if (dir != null) "$dir/lib/windows/libclang_rt.$libraryName-$targetSuffix.a" else null
}
/**
* Handle to command that runs LLD -### (i.e. without actual linkage) with arguments from [finalLinkCommands].
*/
var lldCompatibilityChecker: ((Command) -> Unit)? = null
override fun finalLinkCommands(objectFiles: List<ObjectFile>, executable: ExecutableFile,
libraries: List<String>, linkerArgs: List<String>,
optimize: Boolean, debug: Boolean,
@@ -482,29 +477,11 @@ class MingwLinker(targetProperties: MingwConfigurables)
+additionalArguments
}
if (HostManager.hostIsMingw) {
lldCompatibilityChecker?.let { checkLldCompatibiity ->
// -### flag allows to avoid actual linkage process.
val konanCxaDemangleSymbol = when (target) {
KonanTarget.MINGW_X64 -> "Konan_cxa_demangle"
KonanTarget.MINGW_X86 -> "_Konan_cxa_demangle"
else -> error("Unexpected target: $target")
}
val lldCommand = Command(linker).constructLinkerArguments(
// Add -fuse-ld to the end of the list to override previous appearances.
additionalArguments = listOf("-fuse-ld=$absoluteLldLocation", "-Wl,-###"),
// LLD doesn't support defsym.
skipDefaultArguments = listOf("-Wl,--defsym,__cxa_demangle=$konanCxaDemangleSymbol")
)
checkLldCompatibiity(lldCommand)
}
}
return listOf(when {
HostManager.hostIsMingw -> Command(linker)
else -> Command("wine64", "$linker.exe")
}.constructLinkerArguments(
additionalArguments = listOf("-fuse-ld=${absoluteTargetToolchain}/bin/ld.exe")
additionalArguments = listOf("-fuse-ld=$absoluteLldLocation")
))
}
}