From ca567ac35c124fc4432560e0b256f3e37a7c710b Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Fri, 22 Sep 2017 01:24:07 +0700 Subject: [PATCH] Added support for mipsel --- .../kotlin/native/interop/gen/jvm/main.kt | 1 + .../kotlin/backend/konan/LinkStage.kt | 5 ++-- backend.native/konan.properties | 24 +++++++++++++++++++ backend.native/tests/build.gradle | 7 +++++- .../org/jetbrains/kotlin/KonanTest.groovy | 7 +++++- .../kotlin/konan/target/ClangArgs.kt | 7 ++++++ .../kotlin/konan/target/KonanTarget.kt | 9 ++++--- 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index 423a7d0494a..e91897c3c08 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -91,6 +91,7 @@ private val knownTargets = mapOf( "ios_sim" to "ios_sim", "raspberrypi" to "raspberrypi", "mips" to "mips", + "mipsel" to "mipsel", "android_arm32" to "android_arm32", "android_arm64" to "android_arm64", "mingw" to "mingw", diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt index 23165b1756c..7709adeb34b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt @@ -155,7 +155,7 @@ internal open class LinuxBasedPlatform(val distribution: Distribution) "${targetSysRoot}/usr/lib64/crt1.o", "${targetSysRoot}/usr/lib64/crti.o", "${libGcc}/crtbegin.o", "-L${llvmLib}", "-L${libGcc}")) - if (distribution.target != KonanTarget.MIPS) add("--hash-style=gnu") // MIPS doesn't support hash-style=gnu + if (distribution.target != KonanTarget.MIPS && distribution.target != KonanTarget.MIPSEL) add("--hash-style=gnu") // MIPS doesn't support hash-style=gnu addAll(specificLibs) addAll(listOf("-L${targetSysRoot}/../lib", "-L${targetSysRoot}/lib", "-L${targetSysRoot}/usr/lib")) if (optimize) addAll(listOf("-plugin", "$llvmLib/LLVMgold.so") + pluginOptimizationFlags) @@ -218,7 +218,8 @@ internal class LinkStage(val context: Context) { private val distribution = context.config.distribution private val platform = when (target) { - KonanTarget.LINUX, KonanTarget.RASPBERRYPI, KonanTarget.MIPS -> + KonanTarget.LINUX, KonanTarget.RASPBERRYPI, + KonanTarget.MIPS, KonanTarget.MIPSEL -> LinuxBasedPlatform(distribution) KonanTarget.MACBOOK, KonanTarget.IPHONE, KonanTarget.IPHONE_SIM -> MacOSBasedPlatform(distribution) diff --git a/backend.native/konan.properties b/backend.native/konan.properties index 1d648f4dfcf..fc4abcfb881 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -172,6 +172,30 @@ dynamicLinker.mips = /lib/ld.so.1 # targetSysRoot relative abiSpecificLibraries.mips = +# MIPSel +targetToolchain.linux-mipsel = target-gcc-toolchain-1-linux-mips-x86-64/x86_64-unknown-linux-gnu +dependencies.linux-mipsel = \ + clang-llvm-3.9.0-linux-x86-64 \ + target-gcc-toolchain-1-linux-mips-x86-64 \ + target-sysroot-mipsel \ + libffi-3.2.1-2-linux-x86-64 \ + libffi-3.2.1-linux-mipsel +quadruple.mipsel = mipsel-unknown-linux-gnu +entrySelector.mipsel = --defsym main=Konan_main +linkerOptimizationFlags.mipsel = --gc-sections +targetSysRoot.mipsel = target-sysroot-mipsel +# We could reuse host toolchain here. +libffiDir.mipsel = libffi-3.2.1-linux-mipsel +linkerKonanFlags.mipsel = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread +# targetSysroot-relative. +libGcc.mipsel = lib/gcc/mipsel-unknown-linux-gnu/4.9.4 +llvmLtoFlags.mipsel = +llvmLtoOptFlags.mipsel = -O3 -function-sections +llvmLtoNooptFlags.mipsel = -O1 +dynamicLinker.mipsel = /lib/ld.so.1 +# targetSysRoot relative +abiSpecificLibraries.mipsel = + # Android ARM32, based on NDK for android-21. targetToolchain.osx-android_arm32 = target-toolchain-21-osx-android_arm32 # TODO: split dependencies to host-dependent and host-independent parts. diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 830d8b23428..d2f2c5a9919 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2084,7 +2084,9 @@ kotlinNativeInterop { } task interop0(type: RunInteropKonanTest) { - disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + disabled = (project.testTarget == 'wasm32') || // No interop for wasm yet. + (project.testTarget == 'mips') || // st_uid of '/' is not equal to 0 when using qemu + (project.testTarget == 'mipsel') // st_uid of '/' is not equal to 0 when using qemu goldValue = "0\n0\n" source = "interop/basics/0.kt" interop = 'sysstat' @@ -2112,6 +2114,7 @@ task interop3(type: RunInteropKonanTest) { // test back on. disabled = (project.testTarget == 'raspberrypi') || (project.testTarget == 'mips') || + (project.testTarget == 'mipsel') || (project.testTarget == 'wasm32') // No interop for wasm yet. goldValue = "8 9 12 13 14 \n" source = "interop/basics/3.kt" @@ -2127,12 +2130,14 @@ task interop4(type: RunInteropKonanTest) { task interop_bitfields(type: RunInteropKonanTest) { disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + expectedFail = (project.testTarget == 'mips') // fails because of big-endiannes source = "interop/basics/bf.kt" interop = 'bitfields' } task interop_funptr(type: RunInteropKonanTest) { disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + expectedFail = (project.testTarget == 'mips') // fails because of big-endiannes goldValue = "42\n17\n1\n0\n" source = "interop/basics/funptr.kt" interop = 'cfunptr' diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 44e318e433b..c776920ab5b 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -277,13 +277,18 @@ fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation = ob } List executionCommandLine(String exe) { + def properties = project.rootProject.konanProperties if (target == KonanTarget.WASM32) { - def properties = project.rootProject.konanProperties def targetToolchain = TargetPropertiesKt.hostTargetString(properties, "targetToolchain", target) def absoluteTargetToolchain = "$dependenciesDir/$targetToolchain" def d8 = "$absoluteTargetToolchain/bin/d8" def launcherJs = "${exe}.js" return [d8, '--expose-wasm', launcherJs, '--', exe] + } else if (target == KonanTarget.MIPS || target == KonanTarget.MIPSEL) { + def targetSysroot = TargetPropertiesKt.targetString(properties, "targetSysRoot", target) + def absoluteTargetSysroot = "$dependenciesDir/$targetSysroot" + def qemu = "$absoluteTargetSysroot/bin/qemu-mips" + return [qemu, "-L", absoluteTargetSysroot, exe] } else { return [exe] } diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt index 0fe974a953d..6af8b7a4bf6 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt @@ -45,6 +45,13 @@ class ClangTarget(val target: KonanTarget, konanProperties: KonanProperties) { "-I$sysRoot/usr/include/c++/4.9.4", "-I$sysRoot/usr/include/c++/4.9.4/mips-unknown-linux-gnu") + KonanTarget.MIPSEL -> + listOf("-target", targetArg!!, + "-DUSE_GCC_UNWIND=1", "-DUSE_ELF_SYMBOLS=1", "-DELFSIZE=32", + "--sysroot=$sysRoot", + "-I$sysRoot/usr/include/c++/4.9.4", + "-I$sysRoot/usr/include/c++/4.9.4/mipsel-unknown-linux-gnu") + KonanTarget.MINGW -> listOf("-target", targetArg!!, "--sysroot=$sysRoot", "-DUSE_GCC_UNWIND=1", "-DUSE_PE_COFF_SYMBOLS=1", "-DKONAN_WINDOWS=1") diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt index 8dbe89acf5c..75897620f74 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt @@ -34,6 +34,7 @@ enum class KonanTarget(val targetSuffix: String, val programSuffix: String, var MACBOOK("osx", "kexe"), RASPBERRYPI("raspberrypi", "kexe"), MIPS("mips", "kexe"), + MIPSEL("mipsel", "kexe"), WASM32("wasm32", "wasm"); val userName get() = name.toLowerCase() @@ -46,6 +47,7 @@ enum class KonanTarget(val targetSuffix: String, val programSuffix: String, var RASPBERRYPI -> Platform.LINUX LINUX -> Platform.LINUX MIPS -> Platform.LINUX + MIPSEL -> Platform.LINUX MINGW -> Platform.WINDOWS WASM32 -> Platform.WASM } @@ -163,10 +165,11 @@ class TargetManager(val userRequest: String? = null) { when (host) { KonanTarget.LINUX -> { KonanTarget.LINUX.enabled = true - KonanTarget.RASPBERRYPI.enabled = true + KonanTarget.RASPBERRYPI.enabled = false KonanTarget.MIPS.enabled = true - KonanTarget.ANDROID_ARM32.enabled = true - KonanTarget.ANDROID_ARM64.enabled = true + KonanTarget.MIPSEL.enabled = true + KonanTarget.ANDROID_ARM32.enabled = false + KonanTarget.ANDROID_ARM64.enabled = false } KonanTarget.MINGW -> { KonanTarget.MINGW.enabled = true