[K/N] Fix windows dynamic tests for LLD

Adjust compilation and linking flags to workaround absence of direct
DLL linkage in LLD.
This commit is contained in:
Sergey Bogolepov
2021-07-24 22:36:41 +07:00
committed by Space
parent c7c78e0e1a
commit 922fcc4049
2 changed files with 13 additions and 1 deletions

View File

@@ -327,6 +327,9 @@ Task dynamicTest(String name, Closure<KonanDynamicTest> 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)

View File

@@ -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,