[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
@@ -318,15 +318,6 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
configuration.report(ERROR, "-Xgc-aggressive is only supported for -memory-model experimental")
}
put(GARBAGE_COLLECTOR_AGRESSIVE, arguments.gcAggressive)
put(CHECK_LLD_COMPATIBILITY, when (val it = arguments.checkLldCompatibility) {
"enable" -> true
"disable" -> false
null -> true
else -> {
configuration.report(ERROR, "Unsupported '-Xcheck-compatibility-with-lld' value: $it. Possible values are 'enable'/'disable'")
true
}
})
put(RUNTIME_ASSERTS_MODE, when (arguments.runtimeAssertsMode) {
"ignore" -> RuntimeAssertsMode.IGNORE
"log" -> RuntimeAssertsMode.LOG
@@ -317,13 +317,6 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xir-property-lazy-initialization", description = "Initialize top level properties lazily per file")
var propertyLazyInitialization: Boolean = false
@Argument(
value = "-Xcheck-compatibility-with-lld",
valueDescription = "{disable|enable}",
description = "Check that linker flags are compatible with LLD."
)
var checkLldCompatibility: String? = null
@Argument(value="-Xruntime-asserts-mode", valueDescription = "<mode>", description = "Enable asserts in runtime. Possible values: 'ignore', 'log', 'panic'")
var runtimeAssertsMode: String? = "ignore"
@@ -146,7 +146,6 @@ internal class Linker(val context: Context) {
linkerInput.caches.dynamic +
libraryProvidedLinkerFlags + additionalLinkerArgs
checkLldCompatibility()
val finalOutputCommands = linker.finalLinkCommands(
objectFiles = linkerInput.objectFiles,
executable = executable,
@@ -178,23 +177,6 @@ internal class Linker(val context: Context) {
return executable
}
private fun checkLldCompatibility() {
if (linker is MingwLinker && config.getBoolean(KonanConfigKeys.CHECK_LLD_COMPATIBILITY)) {
linker.lldCompatibilityChecker = { command ->
command.logWith(context::log)
val result = command.getResult(withErrors = true)
if (result.exitCode != 0) {
val message = """
Kotlin/Native will switch from ld to LLD linker in future releases and this warning will become an error.
See https://youtrack.jetbrains.com/issue/KT-47605 for details.
${result.outputLines.joinToString("\n")}
""".lineSequence().map { it.trim() }.joinToString("\n")
context.reportCompilationWarning(message)
}
}
}
}
private fun shouldPerformPreLink(caches: CachesToLink, linkerOutputKind: LinkerOutputKind): Boolean {
// Pre-link is only useful when producing static library. Otherwise its just a waste of time.
val isStaticLibrary = linkerOutputKind == LinkerOutputKind.STATIC_LIBRARY &&
@@ -4441,48 +4441,6 @@ interopTest("interop_cppSkiaSignature") {
UtilsKt.dependsOnPlatformLibs(it)
}
/**
* Check that compiler properly reports linker options that aren't supported by LLD.
* @param withImportLibrary create an import library if true. Thus, LLD shoudn't complain.
* @param shouldShowWarning compiler should show warning from LLD if true.
* @param compilerFlags additional flags that will be passed to Kotlin/Native.
*/
void driverCheckLldCompatibilityTest(String taskName, boolean withImportLibrary, boolean shouldShowWarning, List<String> compilerFlags) {
tasks.register(taskName, KonanDriverTest) {
source = "interop/mingw_dll_linkage/main.kt"
flags = ["-linker-option", "-lrary", "-linker-option", "-L", "-linker-option", "$buildDir/$taskName"] +
compilerFlags
compilerMessages = true
goldValue = "lld doesn't support linking directly against"
outputChecker = { out ->
shouldShowWarning ? out.contains(goldValue) : !out.contains(goldValue)
}
doBeforeBuild {
mkdir("$buildDir/$taskName")
execClangForCompilerTests(project.target) {
args "$projectDir/interop/mingw_dll_linkage/library.c"
args '-shared', '-o', "$buildDir/$taskName/library.dll"
if (withImportLibrary) {
args "-Wl,--out-implib", "-Wl,$buildDir/$taskName/library.dll.a"
}
}
copy {
from("$buildDir/$taskName/library.dll")
into("$testOutputLocal/$name/$target/")
}
}
}
}
if (isWindowsTarget(project)) {
driverCheckLldCompatibilityTest("driver_lld_with_import_library", true, false, [])
driverCheckLldCompatibilityTest("driver_lld_without_import_library", false, true, [])
driverCheckLldCompatibilityTest("driver_lld_without_import_library_no_check", false, false, ["-Xcheck-compatibility-with-lld=disable"])
}
/*
TODO: This test isn't run automatically
task interop_echo_server(type: RunInteropKonanTest) {