Slightly refactored cross compilation infrastructure.
This commit is contained in:
committed by
alexander-gorshenev
parent
8b148fd35c
commit
7d111c4d31
+13
-31
@@ -178,12 +178,13 @@ private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties,
|
|||||||
|
|
||||||
private fun Properties.defaultCompilerOpts(target: String, dependencies: String): List<String> {
|
private fun Properties.defaultCompilerOpts(target: String, dependencies: String): List<String> {
|
||||||
|
|
||||||
val hostSysRootDir = this.getOsSpecific("sysRoot", target)!!
|
val arch = this.getOsSpecific("arch", target)!!
|
||||||
|
val hostSysRootDir = this.getOsSpecific("sysRoot")!!
|
||||||
val hostSysRoot = "$dependencies/$hostSysRootDir"
|
val hostSysRoot = "$dependencies/$hostSysRootDir"
|
||||||
val targetSysRootDir = this.getOsSpecific("targetSysRoot", target) ?: hostSysRootDir
|
val targetSysRootDir = this.getOsSpecific("targetSysRoot", target) ?: hostSysRootDir
|
||||||
val targetSysRoot = "$dependencies/$targetSysRootDir"
|
val targetSysRoot = "$dependencies/$targetSysRootDir"
|
||||||
val sysRoot = targetSysRoot
|
val sysRoot = targetSysRoot
|
||||||
val llvmHomeDir = this.getOsSpecific("llvmHome", target)!!
|
val llvmHomeDir = this.getOsSpecific("llvmHome")!!
|
||||||
val llvmHome = "$dependencies/$llvmHomeDir"
|
val llvmHome = "$dependencies/$llvmHomeDir"
|
||||||
val llvmVersion = this.getProperty("llvmVersion")!!
|
val llvmVersion = this.getProperty("llvmVersion")!!
|
||||||
|
|
||||||
@@ -197,44 +198,25 @@ private fun Properties.defaultCompilerOpts(target: String, dependencies: String)
|
|||||||
// We workaround the problem with -isystem flag below.
|
// We workaround the problem with -isystem flag below.
|
||||||
val isystem = "$llvmHome/lib/clang/$llvmVersion/include"
|
val isystem = "$llvmHome/lib/clang/$llvmVersion/include"
|
||||||
|
|
||||||
when (target) {
|
when (detectHost()) {
|
||||||
"osx" ->
|
"osx" -> {
|
||||||
|
val osVersionMinFlag = this.getOsSpecific("osVersionMinFlagClang", target)!!
|
||||||
|
val osVersionMinValue = this.getOsSpecific("osVersionMin", target)!!
|
||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
|
"-arch", arch,
|
||||||
"-isystem", isystem,
|
"-isystem", isystem,
|
||||||
"-B$hostSysRoot/usr/bin",
|
"-B$hostSysRoot/usr/bin",
|
||||||
"--sysroot=$sysRoot",
|
"--sysroot=$sysRoot",
|
||||||
"-mmacosx-version-min=10.11")
|
"$osVersionMinFlag=$osVersionMinValue")
|
||||||
"osx-ios" ->
|
}
|
||||||
return listOf(
|
|
||||||
"-arch", "arm64",
|
|
||||||
"-isystem", isystem,
|
|
||||||
"-B$hostSysRoot/usr/bin",
|
|
||||||
"--sysroot=$sysRoot",
|
|
||||||
"-miphoneos-version-min=5.0.0")
|
|
||||||
"osx-ios-sim" ->
|
|
||||||
return listOf(
|
|
||||||
"-arch", "x86_64",
|
|
||||||
"-isystem", isystem,
|
|
||||||
"-B$hostSysRoot/usr/bin",
|
|
||||||
"--sysroot=$sysRoot",
|
|
||||||
"-mios-simulator-version-min=5.0.0")
|
|
||||||
"linux" -> {
|
"linux" -> {
|
||||||
val gccToolChainDir = this.getOsSpecific("gccToolChain", target)!!
|
val gccToolChainDir = this.getOsSpecific("gccToolChain", target)!!
|
||||||
val gccToolChain= "$dependencies/$gccToolChainDir"
|
val gccToolChain= "$dependencies/$gccToolChainDir"
|
||||||
|
val quadruple = this.getOsSpecific("quadruple", target)!!
|
||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
"-isystem", isystem,
|
"-target", quadruple,
|
||||||
"--gcc-toolchain=$gccToolChain",
|
|
||||||
"-L$llvmHome/lib",
|
|
||||||
"-B$hostSysRoot/../bin",
|
|
||||||
"--sysroot=$sysRoot")
|
|
||||||
}
|
|
||||||
"linux-raspberrypi" -> {
|
|
||||||
val gccToolChainDir = this.getOsSpecific("gccToolChain", target)!!
|
|
||||||
val gccToolChain= "$dependencies/$gccToolChainDir"
|
|
||||||
|
|
||||||
return listOf(
|
|
||||||
"-target", "armv7-unknown-linux-gnueabihf",
|
|
||||||
"-isystem", isystem,
|
"-isystem", isystem,
|
||||||
"--gcc-toolchain=$gccToolChain",
|
"--gcc-toolchain=$gccToolChain",
|
||||||
"-L$llvmHome/lib",
|
"-L$llvmHome/lib",
|
||||||
|
|||||||
+5
-3
@@ -26,6 +26,8 @@ class Distribution(val config: CompilerConfiguration) {
|
|||||||
if (!targetManager.crossCompile) "host"
|
if (!targetManager.crossCompile) "host"
|
||||||
else targetManager.current.name.toLowerCase()
|
else targetManager.current.name.toLowerCase()
|
||||||
val suffix = targetManager.currentSuffix()
|
val suffix = targetManager.currentSuffix()
|
||||||
|
val hostSuffix = TargetManager.host.suffix
|
||||||
|
init { if (!targetManager.crossCompile) assert(suffix == hostSuffix) }
|
||||||
|
|
||||||
private fun findKonanHome(): String {
|
private fun findKonanHome(): String {
|
||||||
val value = System.getProperty("konan.home", "dist")
|
val value = System.getProperty("konan.home", "dist")
|
||||||
@@ -49,10 +51,10 @@ class Distribution(val config: CompilerConfiguration) {
|
|||||||
val runtime = config.get(KonanConfigKeys.RUNTIME_FILE)
|
val runtime = config.get(KonanConfigKeys.RUNTIME_FILE)
|
||||||
?: "$lib/runtime.bc"
|
?: "$lib/runtime.bc"
|
||||||
|
|
||||||
val llvmHome = "$dependenciesDir/${properties.propertyString("llvmHome.$suffix")}"
|
val llvmHome = "$dependenciesDir/${properties.propertyString("llvmHome.$hostSuffix")}"
|
||||||
val sysRoot = "$dependenciesDir/${properties.propertyString("sysRoot.$suffix")}"
|
val sysRoot = "$dependenciesDir/${properties.propertyString("sysRoot.$hostSuffix")}"
|
||||||
val libGcc = "$dependenciesDir/${properties.propertyString("libGcc.$suffix")}"
|
|
||||||
|
|
||||||
|
val libGcc = "$dependenciesDir/${properties.propertyString("libGcc.$suffix")}"
|
||||||
val targetSysRoot = if (properties.hasProperty("targetSysRoot.$suffix")) {
|
val targetSysRoot = if (properties.hasProperty("targetSysRoot.$suffix")) {
|
||||||
"$dependenciesDir/${properties.propertyString("targetSysRoot.$suffix")}"
|
"$dependenciesDir/${properties.propertyString("targetSysRoot.$suffix")}"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+11
-6
@@ -23,21 +23,26 @@ public class KonanProperties(val propertyFile: String) {
|
|||||||
|
|
||||||
val properties = Properties()
|
val properties = Properties()
|
||||||
|
|
||||||
|
fun String.suffix(suf: String?): String =
|
||||||
|
if (suf == null) this
|
||||||
|
else "${this}.${suf}"
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val file = File(propertyFile)
|
val file = File(propertyFile)
|
||||||
file.bufferedReader()?.use { reader ->
|
file.bufferedReader().use { reader ->
|
||||||
properties.load(reader)
|
properties.load(reader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun propertyString(key: String): String? = properties.getProperty(key)
|
fun propertyString(key: String, suffix: String? = null): String?
|
||||||
fun propertyString(key: String, default: String) : String = properties.getProperty(key, default)
|
= properties.getProperty(key.suffix(suffix))
|
||||||
|
|
||||||
fun propertyList(key: String): List<String> {
|
fun propertyList(key: String, suffix: String? = null): List<String> {
|
||||||
val value = properties.getProperty(key)
|
val value = properties.getProperty(key.suffix(suffix))
|
||||||
return value?.split(' ') ?: listOf<String>()
|
return value?.split(' ') ?: listOf<String>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasProperty(key: String): Boolean = properties.getProperty(key) != null
|
fun hasProperty(key: String, suffix: String? = null): Boolean
|
||||||
|
= properties.getProperty(key.suffix(suffix)) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-25
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.backend.konan
|
|||||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
|
||||||
enum class KonanTarget(var enabled: Boolean = false) {
|
enum class KonanTarget(val suffix: String, var enabled: Boolean = false) {
|
||||||
IPHONE,
|
IPHONE("ios"),
|
||||||
IPHONE_SIM,
|
IPHONE_SIM("ios-sim"),
|
||||||
LINUX,
|
LINUX("linux"),
|
||||||
MACBOOK,
|
MACBOOK("osx"),
|
||||||
RASPBERRYPI
|
RASPBERRYPI("raspberrypi")
|
||||||
}
|
}
|
||||||
|
|
||||||
class TargetManager(val config: CompilerConfiguration) {
|
class TargetManager(val config: CompilerConfiguration) {
|
||||||
@@ -42,6 +42,8 @@ class TargetManager(val config: CompilerConfiguration) {
|
|||||||
KonanTarget.IPHONE.enabled = true
|
KonanTarget.IPHONE.enabled = true
|
||||||
KonanTarget.IPHONE_SIM.enabled = true
|
KonanTarget.IPHONE_SIM.enabled = true
|
||||||
}
|
}
|
||||||
|
else ->
|
||||||
|
error("Unknown host platform: $host")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!current.enabled) {
|
if (!current.enabled) {
|
||||||
@@ -53,7 +55,7 @@ class TargetManager(val config: CompilerConfiguration) {
|
|||||||
if (targets[name] == null) {
|
if (targets[name] == null) {
|
||||||
error("Unknown target: $name. Use -list_targets to see the list of available targets")
|
error("Unknown target: $name. Use -list_targets to see the list of available targets")
|
||||||
}
|
}
|
||||||
return name!!
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
fun list() {
|
fun list() {
|
||||||
@@ -75,24 +77,8 @@ class TargetManager(val config: CompilerConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun currentSuffix(): String {
|
fun currentSuffix(): String {
|
||||||
if (host == KonanTarget.MACBOOK) {
|
return host.suffix +
|
||||||
when (current) {
|
if (host != current) "-${current.suffix}" else ""
|
||||||
KonanTarget.MACBOOK -> return("osx")
|
|
||||||
KonanTarget.IPHONE -> return("osx-ios")
|
|
||||||
KonanTarget.IPHONE_SIM -> return("osx-ios-sim")
|
|
||||||
else -> error("Impossible combination of $host and $current")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (host == KonanTarget.LINUX) {
|
|
||||||
when (current) {
|
|
||||||
KonanTarget.LINUX -> return("linux")
|
|
||||||
KonanTarget.RASPBERRYPI -> return("linux-raspberrypi")
|
|
||||||
KonanTarget.IPHONE -> return("linux-ios")
|
|
||||||
KonanTarget.IPHONE_SIM -> return("linux-ios-sim")
|
|
||||||
else -> error("Impossible combination of $host and $current")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error("Unknown host target $host)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+58
-109
@@ -29,39 +29,53 @@ typealias ExecutableFile = String
|
|||||||
internal abstract class PlatformFlags(val distribution: Distribution) {
|
internal abstract class PlatformFlags(val distribution: Distribution) {
|
||||||
val properties = distribution.properties
|
val properties = distribution.properties
|
||||||
|
|
||||||
abstract val llvmLtoNooptFlags: List<String>
|
val hostSuffix = TargetManager.host.suffix
|
||||||
abstract val llvmLtoOptFlags: List<String>
|
val targetSuffix = distribution.suffix
|
||||||
abstract val llvmLtoFlags: List<String>
|
val arch = propertyTargetString("arch")
|
||||||
abstract val llvmLlcFlags: List<String>
|
|
||||||
|
open val llvmLtoNooptFlags
|
||||||
|
= propertyHostList("llvmLtoNooptFlags")
|
||||||
|
open val llvmLtoOptFlags
|
||||||
|
= propertyHostList("llvmLtoOptFlags")
|
||||||
|
open val llvmLtoFlags
|
||||||
|
= propertyHostList("llvmLtoFlags")
|
||||||
|
open val entrySelector
|
||||||
|
= propertyHostList("entrySelector")
|
||||||
|
open val linkerOptimizationFlags
|
||||||
|
= propertyHostList("linkerOptimizationFlags")
|
||||||
|
open val linkerKonanFlags
|
||||||
|
= propertyHostList("linkerKonanFlags")
|
||||||
|
|
||||||
abstract val linker: String
|
abstract val linker: String
|
||||||
abstract val linkerKonanFlags: List<String>
|
|
||||||
abstract val linkerOptimizationFlags: List<String>
|
|
||||||
|
|
||||||
abstract fun linkCommand(objectFiles: List<ObjectFile>,
|
abstract fun linkCommand(objectFiles: List<ObjectFile>,
|
||||||
executable: ExecutableFile, optimize: Boolean): List<String>
|
executable: ExecutableFile, optimize: Boolean): List<String>
|
||||||
|
|
||||||
|
protected fun propertyHostString(name: String)
|
||||||
|
= properties.propertyString(name, hostSuffix)!!
|
||||||
|
protected fun propertyHostList(name: String)
|
||||||
|
= properties.propertyList(name, hostSuffix)
|
||||||
|
protected fun propertyTargetString(name: String)
|
||||||
|
= properties.propertyString(name, targetSuffix)!!
|
||||||
|
protected fun propertyTargetList(name: String)
|
||||||
|
= properties.propertyList(name, targetSuffix)
|
||||||
|
protected fun propertyCommonString(name: String)
|
||||||
|
= properties.propertyString(name, null)!!
|
||||||
|
protected fun propertyCommonList(name: String)
|
||||||
|
= properties.propertyList(name, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal open class MacOSBasedPlatform(distribution: Distribution)
|
||||||
internal open class MacOSPlatform(distribution: Distribution)
|
|
||||||
: PlatformFlags(distribution) {
|
: PlatformFlags(distribution) {
|
||||||
|
|
||||||
override val llvmLtoNooptFlags = properties.propertyList("llvmLtoNooptFlags.osx")
|
|
||||||
override val llvmLtoOptFlags = properties.propertyList("llvmLtoOptFlags.osx")
|
|
||||||
override val llvmLtoFlags = properties.propertyList("llvmLtoFlags.osx")
|
|
||||||
override val llvmLlcFlags = properties.propertyList("llvmLlcFlags.osx")
|
|
||||||
|
|
||||||
override val linkerOptimizationFlags =
|
|
||||||
properties.propertyList("linkerOptimizationFlags.osx")
|
|
||||||
override val linkerKonanFlags = properties.propertyList("linkerKonanFlags.osx")
|
|
||||||
override val linker = "${distribution.sysRoot}/usr/bin/ld"
|
override val linker = "${distribution.sysRoot}/usr/bin/ld"
|
||||||
private val dsymutil = "${distribution.llvmBin}/llvm-dsymutil"
|
|
||||||
|
|
||||||
open val arch = properties.propertyString("arch.osx")!!
|
open val osVersionMin = listOf(
|
||||||
open val osVersionMin = properties.propertyList("osVersionMin.osx")
|
propertyTargetString("osVersionMinFlagLd"),
|
||||||
|
propertyTargetString("osVersionMin")+".0")
|
||||||
|
|
||||||
open val sysRoot = distribution.sysRoot
|
open val sysRoot = distribution.sysRoot
|
||||||
open val targetSysRoot = sysRoot
|
open val targetSysRoot = distribution.targetSysRoot
|
||||||
|
|
||||||
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
|
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
|
||||||
|
|
||||||
@@ -76,66 +90,39 @@ internal open class MacOSPlatform(distribution: Distribution)
|
|||||||
linkerKonanFlags +
|
linkerKonanFlags +
|
||||||
listOf("-lSystem")
|
listOf("-lSystem")
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun dsymutilCommand(executable: ExecutableFile): List<String> {
|
|
||||||
return listOf(dsymutil, executable)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun dsymutilDryRunVerboseCommand(executable: ExecutableFile): List<String> {
|
|
||||||
return listOf(dsymutil, "-dump-debug-map" ,executable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class IPhoneOSfromMacOSPlatform(distribution: Distribution)
|
internal open class LinuxBasedPlatform(distribution: Distribution)
|
||||||
: MacOSPlatform(distribution) {
|
|
||||||
|
|
||||||
override val arch = properties.propertyString("arch.osx-ios")!!
|
|
||||||
override val osVersionMin = properties.propertyList("osVersionMin.osx-ios")
|
|
||||||
override val llvmLlcFlags = properties.propertyList("llvmLlcFlags.osx-ios")
|
|
||||||
override val targetSysRoot = "${distribution.dependenciesDir}/${properties.propertyString("targetSysRoot.osx-ios")!!}"
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class IPhoneSimulatorFromMacOSPlatform(distribution: Distribution)
|
|
||||||
: MacOSPlatform(distribution) {
|
|
||||||
|
|
||||||
override val arch = properties.propertyString("arch.osx-ios-sim")!!
|
|
||||||
override val osVersionMin = properties.propertyList("osVersionMin.osx-ios-sim")
|
|
||||||
override val llvmLlcFlags = properties.propertyList("llvmLlcFlags.osx-ios-sim")
|
|
||||||
override val targetSysRoot = "${distribution.dependenciesDir}/${properties.propertyString("targetSysRoot.osx-ios-sim")!!}"
|
|
||||||
}
|
|
||||||
|
|
||||||
internal open class LinuxPlatform(distribution: Distribution)
|
|
||||||
: PlatformFlags(distribution) {
|
: PlatformFlags(distribution) {
|
||||||
|
|
||||||
open val sysRoot = distribution.sysRoot
|
open val sysRoot = distribution.sysRoot
|
||||||
|
open val targetSysRoot = distribution.targetSysRoot
|
||||||
|
|
||||||
val llvmLib = distribution.llvmLib
|
val llvmLib = distribution.llvmLib
|
||||||
val libGcc = distribution.libGcc
|
val libGcc = distribution.libGcc
|
||||||
|
|
||||||
override val llvmLtoNooptFlags = properties.propertyList("llvmLtoNooptFlags.linux")
|
|
||||||
override val llvmLtoOptFlags = properties.propertyList("llvmLtoOptFlags.linux")
|
|
||||||
override val llvmLtoFlags = properties.propertyList("llvmLtoFlags.linux")
|
|
||||||
override val llvmLlcFlags = properties.propertyList("llvmLlcFlags.linux")
|
|
||||||
|
|
||||||
override val linkerOptimizationFlags =
|
|
||||||
properties.propertyList("linkerOptimizationFlags.linux")
|
|
||||||
override val linkerKonanFlags = properties.propertyList("linkerKonanFlags.linux")
|
|
||||||
override val linker = "${distribution.sysRoot}/../bin/ld.gold"
|
override val linker = "${distribution.sysRoot}/../bin/ld.gold"
|
||||||
|
|
||||||
val pluginOptimizationFlags =
|
open val pluginOptimizationFlags =
|
||||||
properties.propertyList("pluginOptimizationFlags.linux")
|
propertyHostList("pluginOptimizationFlags")
|
||||||
|
open val dynamicLinker =
|
||||||
|
propertyTargetString("dynamicLinker")
|
||||||
|
|
||||||
|
open val specificLibs
|
||||||
|
= propertyTargetList("abiSpecificLibraries").map{it -> "-L${targetSysRoot}/$it"}
|
||||||
|
|
||||||
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
|
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
|
||||||
// TODO: Can we extract more to the konan.properties?
|
// TODO: Can we extract more to the konan.properties?
|
||||||
return mutableListOf<String>("$linker",
|
return mutableListOf<String>("$linker",
|
||||||
"--sysroot=${sysRoot}",
|
"--sysroot=${targetSysRoot}",
|
||||||
"-export-dynamic", "-z", "relro", "--hash-style=gnu",
|
"-export-dynamic", "-z", "relro", "--hash-style=gnu",
|
||||||
"--build-id", "--eh-frame-hdr", "-m", "elf_x86_64",
|
"--build-id", "--eh-frame-hdr", // "-m", "elf_x86_64",
|
||||||
"-dynamic-linker", "/lib64/ld-linux-x86-64.so.2",
|
"-dynamic-linker", dynamicLinker,
|
||||||
"-o", executable,
|
"-o", executable,
|
||||||
"${sysRoot}/usr/lib64/crt1.o", "${sysRoot}/usr/lib64/crti.o", "${libGcc}/crtbegin.o",
|
"${targetSysRoot}/usr/lib64/crt1.o", "${targetSysRoot}/usr/lib64/crti.o", "${libGcc}/crtbegin.o",
|
||||||
"-L${llvmLib}", "-L${libGcc}", "-L${sysRoot}/../lib64", "-L${sysRoot}/lib64",
|
"-L${llvmLib}", "-L${libGcc}") +
|
||||||
"-L${sysRoot}/usr/lib64", "-L${sysRoot}/../lib", "-L${sysRoot}/lib", "-L${sysRoot}/usr/lib") +
|
specificLibs +
|
||||||
|
listOf("-L${targetSysRoot}/../lib", "-L${targetSysRoot}/lib", "-L${targetSysRoot}/usr/lib") +
|
||||||
if (optimize) listOf("-plugin", "$llvmLib/LLVMgold.so") + pluginOptimizationFlags else {listOf<String>()} +
|
if (optimize) listOf("-plugin", "$llvmLib/LLVMgold.so") + pluginOptimizationFlags else {listOf<String>()} +
|
||||||
objectFiles +
|
objectFiles +
|
||||||
if (optimize) linkerOptimizationFlags else {listOf<String>()} +
|
if (optimize) linkerOptimizationFlags else {listOf<String>()} +
|
||||||
@@ -143,31 +130,7 @@ internal open class LinuxPlatform(distribution: Distribution)
|
|||||||
listOf("-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed",
|
listOf("-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed",
|
||||||
"-lc", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed",
|
"-lc", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed",
|
||||||
"${libGcc}/crtend.o",
|
"${libGcc}/crtend.o",
|
||||||
"${sysRoot}/usr/lib64/crtn.o")
|
"${targetSysRoot}/usr/lib64/crtn.o")
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class RaspberryPiPlatform(distribution: Distribution)
|
|
||||||
: LinuxPlatform(distribution) {
|
|
||||||
|
|
||||||
override val sysRoot = "${distribution.dependenciesDir}/${properties.propertyString("targetSysRoot.linux-raspberrypi")!!}"
|
|
||||||
|
|
||||||
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
|
|
||||||
// TODO: Can we extract more to the konan.properties?
|
|
||||||
return mutableListOf<String>("$linker",
|
|
||||||
"--sysroot=${sysRoot}",
|
|
||||||
"-export-dynamic", "-z", "relro", "--hash-style=gnu",
|
|
||||||
"--build-id", "--eh-frame-hdr",
|
|
||||||
"-dynamic-linker", "/lib/ld-linux-armhf.so.3",
|
|
||||||
"-o", executable,
|
|
||||||
"${sysRoot}/usr/lib/crt1.o", "${sysRoot}/usr/lib/crti.o", "${libGcc}/crtbegin.o",
|
|
||||||
"-L${llvmLib}", "-L${libGcc}", "-L${sysRoot}/../lib/arm-linux-gnueabihf", "-L${sysRoot}/lib/arm-linux-gnueabihf",
|
|
||||||
"-L${sysRoot}/usr/lib/arm-linux-gnueabihf", "-L${sysRoot}/../lib", "-L${sysRoot}/lib", "-L${sysRoot}/usr/lib") +
|
|
||||||
if (optimize) listOf("-plugin", "$llvmLib/LLVMgold.so") + pluginOptimizationFlags else {listOf<String>()} +
|
|
||||||
objectFiles +
|
|
||||||
if (optimize) linkerOptimizationFlags else {listOf<String>()} +
|
|
||||||
linkerKonanFlags +
|
|
||||||
listOf("-lgcc", "-lgcc_s", "-lc", "${libGcc}/crtend.o", "${sysRoot}/usr/lib/crtn.o")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,21 +144,12 @@ internal class LinkStage(val context: Context) {
|
|||||||
private val properties = distribution.properties
|
private val properties = distribution.properties
|
||||||
|
|
||||||
val platform = when (TargetManager.host) {
|
val platform = when (TargetManager.host) {
|
||||||
KonanTarget.LINUX -> when (targetManager.current) {
|
KonanTarget.LINUX ->
|
||||||
KonanTarget.LINUX -> LinuxPlatform(distribution)
|
LinuxBasedPlatform(distribution)
|
||||||
KonanTarget.RASPBERRYPI -> RaspberryPiPlatform(distribution)
|
KonanTarget.MACBOOK ->
|
||||||
else -> TODO("Target not implemented yet.")
|
MacOSBasedPlatform(distribution)
|
||||||
}
|
else ->
|
||||||
KonanTarget.MACBOOK -> when (targetManager.current) {
|
error("Unexpected host platform")
|
||||||
KonanTarget.IPHONE_SIM
|
|
||||||
-> IPhoneSimulatorFromMacOSPlatform(distribution)
|
|
||||||
KonanTarget.IPHONE
|
|
||||||
-> IPhoneOSfromMacOSPlatform(distribution)
|
|
||||||
KonanTarget.MACBOOK
|
|
||||||
-> MacOSPlatform(distribution)
|
|
||||||
else -> TODO("Target not implemented yet.")
|
|
||||||
}
|
|
||||||
else -> TODO("Target not implemented yet")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val suffix = targetManager.currentSuffix()
|
val suffix = targetManager.currentSuffix()
|
||||||
@@ -258,7 +212,7 @@ internal class LinkStage(val context: Context) {
|
|||||||
// And just do the same on Linux.
|
// And just do the same on Linux.
|
||||||
val entryPointSelector: List<String>
|
val entryPointSelector: List<String>
|
||||||
get() = if (nomain) listOf()
|
get() = if (nomain) listOf()
|
||||||
else properties.propertyList("entrySelector.$suffix")
|
else platform.entrySelector
|
||||||
|
|
||||||
fun link(objectFiles: List<ObjectFile>): ExecutableFile {
|
fun link(objectFiles: List<ObjectFile>): ExecutableFile {
|
||||||
val executable = config.get(KonanConfigKeys.EXECUTABLE_FILE)!!
|
val executable = config.get(KonanConfigKeys.EXECUTABLE_FILE)!!
|
||||||
@@ -268,11 +222,6 @@ internal class LinkStage(val context: Context) {
|
|||||||
entryPointSelector
|
entryPointSelector
|
||||||
|
|
||||||
runTool(*linkCommand.toTypedArray())
|
runTool(*linkCommand.toTypedArray())
|
||||||
if (platform is MacOSPlatform && context.shouldContainDebugInfo()) {
|
|
||||||
if (context.phase?.verbose ?: false)
|
|
||||||
runTool(*platform.dsymutilDryRunVerboseCommand(executable).toTypedArray())
|
|
||||||
runTool(*platform.dsymutilCommand(executable).toTypedArray())
|
|
||||||
}
|
|
||||||
|
|
||||||
return executable
|
return executable
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,24 +27,23 @@ llvmHome.osx = clang-llvm-3.9.0-darwin-macos
|
|||||||
llvmLtoFlags.osx = -exported-symbol=_Konan_main
|
llvmLtoFlags.osx = -exported-symbol=_Konan_main
|
||||||
llvmLtoOptFlags.osx = -O3 -function-sections
|
llvmLtoOptFlags.osx = -O3 -function-sections
|
||||||
llvmLtoNooptFlags.osx = -O1
|
llvmLtoNooptFlags.osx = -O1
|
||||||
llvmLlcFlags.osx = -mtriple=x86_64-apple-macosx10.11.0 --disable-fp-elim
|
|
||||||
linkerKonanFlags.osx = -lc++
|
linkerKonanFlags.osx = -lc++
|
||||||
linkerOptimizationFlags.osx = -dead_strip
|
linkerOptimizationFlags.osx = -dead_strip
|
||||||
osVersionMin.osx = -macosx_version_min 10.11.0
|
osVersionMinFlagLd.osx = -macosx_version_min
|
||||||
|
osVersionMinFlagClang.osx = -mmacosx-version-min
|
||||||
|
osVersionMin.osx = 10.11
|
||||||
entrySelector.osx = -alias _Konan_main _main
|
entrySelector.osx = -alias _Konan_main _main
|
||||||
dependencies.osx = target-sysroot-1-darwin-macos libffi-3.2.1-2-darwin-macos clang-llvm-3.9.0-darwin-macos
|
dependencies.osx = target-sysroot-1-darwin-macos \
|
||||||
|
libffi-3.2.1-2-darwin-macos \
|
||||||
|
clang-llvm-3.9.0-darwin-macos
|
||||||
|
|
||||||
# iphone
|
# iphone
|
||||||
arch.osx-ios = arm64
|
arch.osx-ios = arm64
|
||||||
sysRoot.osx-ios = target-sysroot-1-darwin-macos
|
|
||||||
targetSysRoot.osx-ios = target-sysroot-2-darwin-ios
|
targetSysRoot.osx-ios = target-sysroot-2-darwin-ios
|
||||||
libffiDir.osx-ios = libffi-3.2.1-2-darwin-ios
|
libffiDir.osx-ios = libffi-3.2.1-2-darwin-ios
|
||||||
llvmHome.osx-ios = clang-llvm-3.9.0-darwin-macos
|
osVersionMinFlagLd.osx-ios = -iphoneos_version_min
|
||||||
llvmLlcFlags.osx-ios = -mtriple=arm64-apple-ios8.0.0 --disable-fp-elim
|
osVersionMinFlagClang.osx-ios = -miphoneos-version-min
|
||||||
linkerKonanFlags.osx-ios = -lc++
|
osVersionMin.osx-ios = 8.0
|
||||||
linkerOptimizationFlags.osx-ios = -dead_strip
|
|
||||||
osVersionMin.osx-ios = -iphoneos_version_min 8.0.0
|
|
||||||
entrySelector.osx-ios = -alias _Konan_main _main
|
|
||||||
dependencies.osx-ios = target-sysroot-1-darwin-macos \
|
dependencies.osx-ios = target-sysroot-1-darwin-macos \
|
||||||
libffi-3.2.1-2-darwin-ios \
|
libffi-3.2.1-2-darwin-ios \
|
||||||
clang-llvm-3.9.0-darwin-macos \
|
clang-llvm-3.9.0-darwin-macos \
|
||||||
@@ -52,21 +51,19 @@ dependencies.osx-ios = target-sysroot-1-darwin-macos \
|
|||||||
|
|
||||||
# iphone_sim
|
# iphone_sim
|
||||||
arch.osx-ios-sim = x86_64
|
arch.osx-ios-sim = x86_64
|
||||||
sysRoot.osx-ios-sim = target-sysroot-1-darwin-macos
|
|
||||||
targetSysRoot.osx-ios-sim = target-sysroot-1-darwin-ios-sim
|
targetSysRoot.osx-ios-sim = target-sysroot-1-darwin-ios-sim
|
||||||
libffiDir.osx-ios-sim = libffi-3.2.1-2-darwin-ios-sim
|
libffiDir.osx-ios-sim = libffi-3.2.1-2-darwin-ios-sim
|
||||||
llvmHome.osx-ios-sim = clang-llvm-3.9.0-darwin-macos
|
osVersionMinFlagLd.osx-ios-sim = -ios_simulator_version_min
|
||||||
llvmLlcFlags.osx-ios-sim = -mtriple=x86_64-apple-ios5.0.0 --disable-fp-elim
|
osVersionMinFlagClang.osx-ios-sim = -mios-simulator-version-min
|
||||||
linkerKonanFlags.osx-ios-sim = -lc++
|
osVersionMin.osx-ios-sim = 8.0
|
||||||
linkerOptimizationFlags.osx-ios-sim = -dead_strip
|
|
||||||
osVersionMin.osx-ios-sim = -ios_simulator_version_min 5.0.0
|
|
||||||
entrySelector.osx-ios-sim = -alias _Konan_main _main
|
|
||||||
dependencies.osx-ios-sim = target-sysroot-1-darwin-macos \
|
dependencies.osx-ios-sim = target-sysroot-1-darwin-macos \
|
||||||
libffi-3.2.1-2-darwin-ios-sim \
|
libffi-3.2.1-2-darwin-ios-sim \
|
||||||
clang-llvm-3.9.0-darwin-macos \
|
clang-llvm-3.9.0-darwin-macos \
|
||||||
target-sysroot-1-darwin-ios-sim
|
target-sysroot-1-darwin-ios-sim
|
||||||
|
|
||||||
# linux
|
# linux
|
||||||
|
arch.linux = x86_64
|
||||||
|
quadruple.linux = x86_64-unknown-linux-gnu
|
||||||
sysRoot.linux = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/sysroot
|
sysRoot.linux = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/sysroot
|
||||||
libffiDir.linux = libffi-3.2.1-2-linux-x86-64
|
libffiDir.linux = libffi-3.2.1-2-linux-x86-64
|
||||||
llvmHome.linux = clang-llvm-3.9.0-linux-x86-64
|
llvmHome.linux = clang-llvm-3.9.0-linux-x86-64
|
||||||
@@ -79,22 +76,31 @@ llvmLlcFlags.linux = -march=x86-64
|
|||||||
linkerKonanFlags.linux = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread
|
linkerKonanFlags.linux = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread
|
||||||
linkerOptimizationFlags.linux = --gc-sections
|
linkerOptimizationFlags.linux = --gc-sections
|
||||||
pluginOptimizationFlags.linux = -plugin-opt=mcpu=x86-64 -plugin-opt=O3
|
pluginOptimizationFlags.linux = -plugin-opt=mcpu=x86-64 -plugin-opt=O3
|
||||||
|
dynamicLinker.linux = /lib64/ld-linux-x86-64.so.2
|
||||||
entrySelector.linux = --defsym main=Konan_main
|
entrySelector.linux = --defsym main=Konan_main
|
||||||
dependencies.linux = clang-llvm-3.9.0-linux-x86-64 target-gcc-toolchain-3-linux-x86-64 libffi-3.2.1-2-linux-x86-64
|
# targetSysRoot relative
|
||||||
|
abiSpecificLibraries = ../lib64 lib64 usr/lib64
|
||||||
|
dependencies.linux = \
|
||||||
|
clang-llvm-3.9.0-linux-x86-64 \
|
||||||
|
target-gcc-toolchain-3-linux-x86-64 \
|
||||||
|
libffi-3.2.1-2-linux-x86-64
|
||||||
|
|
||||||
# Raspberry Pi
|
# Raspberry Pi
|
||||||
arch.linux-raspberrypi = armv7
|
arch.linux-raspberrypi = armv7
|
||||||
sysRoot.linux-raspberrypi = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/sysroot
|
quadruple.linux-raspberrypi = armv7-unknown-linux-gnueabihf
|
||||||
targetSysRoot.linux-raspberrypi = target-sysroot-1-raspberrypi
|
targetSysRoot.linux-raspberrypi = target-sysroot-1-raspberrypi
|
||||||
libffiDir.linux-raspberrypi = libffi-3.2.1-2-raspberrypi
|
libffiDir.linux-raspberrypi = libffi-3.2.1-2-raspberrypi
|
||||||
llvmHome.linux-raspberrypi = clang-llvm-3.9.0-linux-x86-64
|
|
||||||
libGcc.linux-raspberrypi = target-sysroot-1-raspberrypi/lib/gcc/arm-linux-gnueabihf/4.8.3/
|
libGcc.linux-raspberrypi = target-sysroot-1-raspberrypi/lib/gcc/arm-linux-gnueabihf/4.8.3/
|
||||||
gccToolChain.linux-raspberrypi = target-gcc-toolchain-3-linux-x86-64
|
gccToolChain.linux-raspberrypi = target-gcc-toolchain-3-linux-x86-64
|
||||||
llvmLlcFlags.linux-raspberrypi = -mtriple=armv7-unknown-linux-gnueabihf --disable-fp-elim -float-abi=hard
|
dynamicLinker.linux-raspberrypi = /lib/ld-linux-armhf.so.3
|
||||||
linkerKonanFlags.linux-raspberrypi = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lc -lpthread -fuse-ld=gold
|
# targetSysRoot relative
|
||||||
entrySelector.linux-raspberrypi = --defsym main=Konan_main
|
abiSpecificLibraries = \
|
||||||
dependencies.linux-raspberrypi = clang-llvm-3.9.0-linux-x86-64 \
|
../lib/arm-linux-gnueabihf \
|
||||||
target-gcc-toolchain-3-linux-x86-64 \
|
lib/arm-linux-gnueabihf \
|
||||||
target-sysroot-1-raspberrypi \
|
usr/lib/arm-linux-gnueabihf
|
||||||
libffi-3.2.1-2-linux-x86-64 \
|
dependencies.linux-raspberrypi = \
|
||||||
libffi-3.2.1-2-raspberrypi
|
clang-llvm-3.9.0-linux-x86-64 \
|
||||||
|
target-gcc-toolchain-3-linux-x86-64 \
|
||||||
|
target-sysroot-1-raspberrypi \
|
||||||
|
libffi-3.2.1-2-linux-x86-64 \
|
||||||
|
libffi-3.2.1-2-raspberrypi
|
||||||
|
|||||||
Reference in New Issue
Block a user