From 922fcc4049c116920a4b43b5d4af829b8eaa911f Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Sat, 24 Jul 2021 22:36:41 +0700 Subject: [PATCH] [K/N] Fix windows dynamic tests for LLD Adjust compilation and linking flags to workaround absence of direct DLL linkage in LLD. --- kotlin-native/backend.native/tests/build.gradle | 3 +++ .../kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 9dc38d77f1e..9b76416ca44 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -327,6 +327,9 @@ Task dynamicTest(String name, Closure configureClosure) { baseDir "$testOutputLocal/$name" extraOpts task.flags extraOpts project.globalTestArgs + if (targetName == "mingw_x64" || targetName == "mingw_x86") { + extraOpts "-linker-option", "-Wl,--out-implib,$testOutputLocal/$name/$targetName/${name}.dll.a" + } } } def buildTask = UtilsKt.findKonanBuildTask(project, name, target) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt index cc1871299bb..f22aab1d65a 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt @@ -17,6 +17,8 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.process.ExecSpec import org.jetbrains.kotlin.konan.exec.Command import org.jetbrains.kotlin.konan.target.HostManager +import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.konan.target.Family import org.jetbrains.kotlin.konan.target.LinkerOutputKind import java.io.ByteArrayOutputStream import java.io.File @@ -505,11 +507,18 @@ open class KonanDynamicTest : KonanStandaloneTest() { execResult.assertNormalExitValue() val linker = project.platformManager.platform(project.testTarget).linker + val linkerArgs = when (project.testTarget.family) { + // rpath is meaningless on Windows (and isn't supported by LLD). + // --allow-multiple-definition is needed because finalLinkCommands statically links a lot of MinGW-specific libraries, + // that are already included in DLL produced by Kotlin/Native. + Family.MINGW -> listOf("-L", artifactsDir, "-Wl,--allow-multiple-definition") + else -> listOf("-L", artifactsDir, "-rpath", artifactsDir) + } val commands = linker.finalLinkCommands( objectFiles = listOf("${this@KonanDynamicTest.executable}.o"), executable = executable, libraries = listOf("-l$name"), - linkerArgs = listOf("-L", artifactsDir, "-rpath", artifactsDir), + linkerArgs = linkerArgs, optimize = isOpt, debug = isDebug, kind = LinkerOutputKind.EXECUTABLE,