[K/N] Rework defines passing to runtime compilation
This commit is contained in:
+4
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.konan.library.KonanLibraryLayout
|
||||
import org.jetbrains.kotlin.konan.target.Architecture
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.needSmallBinary
|
||||
import org.jetbrains.kotlin.library.SerializedIrModule
|
||||
import org.jetbrains.kotlin.library.SerializedMetadata
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -318,10 +319,7 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
fun shouldUseDebugInfoFromNativeLibs() = shouldContainAnyDebugInfo() && config.useDebugInfoInNativeLibs
|
||||
|
||||
fun shouldOptimize() = config.optimizationsEnabled
|
||||
fun shouldInlineSafepoints() = when {
|
||||
config.target.family.isAppleFamily -> config.target.architecture != Architecture.ARM32 // disable for watchos_arm32 and similar
|
||||
else -> true
|
||||
}
|
||||
fun shouldInlineSafepoints() = !config.target.needSmallBinary()
|
||||
fun ghaEnabled() = ::globalHierarchyAnalysisResult.isInitialized
|
||||
fun useLazyFileInitializers() = config.propertyLazyInitialization
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ linkerDynamicFlags.macos_x64 = -dylib
|
||||
|
||||
osVersionMinFlagLd.macos_x64 = -macosx_version_min
|
||||
osVersionMin.macos_x64 = 10.13
|
||||
runtimeDefinitions.macos_x64 = KONAN_OSX=1 KONAN_MACOSX=1 KONAN_X64=1 KONAN_OBJC_INTEROP=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
dependencies.macos_x64 = \
|
||||
lldb-4-macos
|
||||
|
||||
@@ -170,7 +170,7 @@ linkerDynamicFlags.macos_arm64 = -dylib
|
||||
|
||||
osVersionMinFlagLd.macos_arm64 = -macosx_version_min
|
||||
osVersionMin.macos_arm64 = 11.0
|
||||
runtimeDefinitions.macos_arm64 = KONAN_OSX=1 KONAN_MACOSX=1 KONAN_ARM64=1 KONAN_OBJC_INTEROP=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
dependencies.macos_arm64 = \
|
||||
lldb-4-macos
|
||||
|
||||
@@ -207,14 +207,8 @@ linkerKonanFlags.ios_arm32 = -lSystem -lc++ -lobjc -framework Foundation -framew
|
||||
linkerOptimizationFlags.ios_arm32 = -dead_strip
|
||||
osVersionMinFlagLd.ios_arm32 = -iphoneos_version_min
|
||||
osVersionMin.ios_arm32 = 9.0
|
||||
# Regarding KONAN_NO_64BIT_ATOMIC:
|
||||
# While not 100% correct here, using atomic ops on iOS armv7 requires 8 byte alignment,
|
||||
# and general ABI requires 4-byte alignment on 64-bit long fields as mentioned in
|
||||
# https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html#//apple_ref/doc/uid/TP40009021-SW1
|
||||
# See https://github.com/ktorio/ktor/issues/941 for the context.
|
||||
runtimeDefinitions.ios_arm32 = KONAN_OBJC_INTEROP=1 KONAN_IOS KONAN_ARM32=1 \
|
||||
KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1 MACHSIZE=32 \
|
||||
KONAN_NO_64BIT_ATOMIC=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
|
||||
# Apple's 64-bit iOS.
|
||||
targetToolchain.macos_x64-ios_arm64 = target-toolchain-xcode_13_1
|
||||
@@ -241,8 +235,7 @@ linkerKonanFlags.ios_arm64 = -lSystem -lc++ -lobjc -framework Foundation -framew
|
||||
linkerOptimizationFlags.ios_arm64 = -dead_strip
|
||||
osVersionMinFlagLd.ios_arm64 = -iphoneos_version_min
|
||||
osVersionMin.ios_arm64 = 9.0
|
||||
runtimeDefinitions.ios_arm64 = KONAN_OBJC_INTEROP=1 KONAN_IOS=1 KONAN_ARM64=1 \
|
||||
KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1 MACHSIZE=64 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
additionalCacheFlags.ios_arm64 = -Xembed-bitcode-marker
|
||||
|
||||
# Apple's iOS simulator.
|
||||
@@ -267,7 +260,7 @@ stripFlags.ios_x64 = -S
|
||||
linkerDynamicFlags.ios_x64 = -dylib
|
||||
osVersionMinFlagLd.ios_x64 = -ios_simulator_version_min
|
||||
osVersionMin.ios_x64 = 9.0
|
||||
runtimeDefinitions.ios_x64 = KONAN_OBJC_INTEROP=1 KONAN_IOS=1 KONAN_X64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
# iOS simulator on Apple Silicon
|
||||
|
||||
@@ -292,7 +285,7 @@ stripFlags.ios_simulator_arm64 = -S
|
||||
linkerDynamicFlags.ios_simulator_arm64 = -dylib
|
||||
osVersionMinFlagLd.ios_simulator_arm64 = -ios_simulator_version_min
|
||||
osVersionMin.ios_simulator_arm64 = 9.0
|
||||
runtimeDefinitions.ios_simulator_arm64 = KONAN_OBJC_INTEROP=1 KONAN_IOS=1 KONAN_ARM64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
# Apple's tvOS simulator.
|
||||
targetToolchain.macos_x64-tvos_x64 = target-toolchain-xcode_13_1
|
||||
@@ -316,7 +309,7 @@ stripFlags.tvos_x64 = -S
|
||||
linkerDynamicFlags.tvos_x64 = -dylib
|
||||
osVersionMinFlagLd.tvos_x64 = -tvos_simulator_version_min
|
||||
osVersionMin.tvos_x64 = 9.0
|
||||
runtimeDefinitions.tvos_x64 = KONAN_OBJC_INTEROP=1 KONAN_TVOS=1 KONAN_X64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
# Apple's tvOS simulator.
|
||||
targetToolchain.macos_x64-tvos_simulator_arm64 = target-toolchain-xcode_13_1
|
||||
@@ -340,7 +333,7 @@ stripFlags.tvos_simulator_arm64 = -S
|
||||
linkerDynamicFlags.tvos_simulator_arm64 = -dylib
|
||||
osVersionMinFlagLd.tvos_simulator_arm64 = -tvos_simulator_version_min
|
||||
osVersionMin.tvos_simulator_arm64 = 9.0
|
||||
runtimeDefinitions.tvos_simulator_arm64 = KONAN_OBJC_INTEROP=1 KONAN_TVOS=1 KONAN_ARM64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
# Apple's 64-bit tvOS.
|
||||
targetToolchain.macos_x64-tvos_arm64 = target-toolchain-xcode_13_1
|
||||
@@ -364,8 +357,7 @@ linkerKonanFlags.tvos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -frame
|
||||
linkerOptimizationFlags.tvos_arm64 = -dead_strip
|
||||
osVersionMinFlagLd.tvos_arm64 = -tvos_version_min
|
||||
osVersionMin.tvos_arm64 = 9.0
|
||||
runtimeDefinitions.tvos_arm64 = KONAN_OBJC_INTEROP=1 KONAN_TVOS=1 KONAN_ARM64=1 \
|
||||
KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1 MACHSIZE=64 KONAN_HAS_FOUNDATION_FRAMEWORK=1 KONAN_HAS_UIKIT_FRAMEWORK=1
|
||||
|
||||
|
||||
# watchOS armv7k
|
||||
targetToolchain.macos_x64-watchos_arm32 = target-toolchain-xcode_13_1
|
||||
@@ -390,10 +382,7 @@ stripFlags.watchos_arm32 = -S
|
||||
linkerDynamicFlags.watchos_arm32 = -dylib
|
||||
osVersionMinFlagLd.watchos_arm32 = -watchos_version_min
|
||||
osVersionMin.watchos_arm32 = 5.0
|
||||
# Regarding KONAN_NO_64BIT_ATOMIC=1: see explanation for ios_arm32 above.
|
||||
runtimeDefinitions.watchos_arm32 = KONAN_OBJC_INTEROP=1 KONAN_WATCHOS KONAN_ARM32=1 \
|
||||
KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1 \
|
||||
MACHSIZE=32 KONAN_NO_64BIT_ATOMIC=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
|
||||
# watchOS arm64_32
|
||||
targetToolchain.macos_x64-watchos_arm64 = target-toolchain-xcode_13_1
|
||||
@@ -415,10 +404,7 @@ stripFlags.watchos_arm64 = -S
|
||||
linkerDynamicFlags.watchos_arm64 = -dylib
|
||||
osVersionMinFlagLd.watchos_arm64 = -watchos_version_min
|
||||
osVersionMin.watchos_arm64 = 5.0
|
||||
# Regarding KONAN_NO_64BIT_ATOMIC=1: see explanation for ios_arm32 above.
|
||||
runtimeDefinitions.watchos_arm64 = KONAN_OBJC_INTEROP=1 KONAN_WATCHOS KONAN_ARM32=1 \
|
||||
KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1 \
|
||||
MACHSIZE=32 KONAN_NO_64BIT_ATOMIC=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
|
||||
# Apple's watchOS i386 simulator.
|
||||
targetToolchain.macos_x64-watchos_x86 = target-toolchain-xcode_13_1
|
||||
@@ -443,7 +429,7 @@ stripFlags.watchos_x86 = -S
|
||||
linkerDynamicFlags.watchos_x86 = -dylib
|
||||
osVersionMinFlagLd.watchos_x86 = -watchos_simulator_version_min
|
||||
osVersionMin.watchos_x86 = 5.0
|
||||
runtimeDefinitions.watchos_x86 = KONAN_OBJC_INTEROP=1 KONAN_WATCHOS=1 KONAN_NO_64BIT_ATOMIC=1 KONAN_X86=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
|
||||
# watchOS x86_64 simulator.
|
||||
targetToolchain.macos_x64-watchos_x64 = target-toolchain-xcode_13_1
|
||||
@@ -467,7 +453,7 @@ stripFlags.watchos_x64 = -S
|
||||
linkerDynamicFlags.watchos_x64 = -dylib
|
||||
osVersionMinFlagLd.watchos_x64 = -watchos_simulator_version_min
|
||||
osVersionMin.watchos_x64 = 7.0
|
||||
runtimeDefinitions.watchos_x64 = KONAN_OBJC_INTEROP=1 KONAN_WATCHOS=1 KONAN_X64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
|
||||
# watchOS Apple Silicon simulator.
|
||||
targetToolchain.macos_x64-watchos_simulator_arm64 = target-toolchain-xcode_13_1
|
||||
@@ -491,7 +477,7 @@ stripFlags.watchos_simulator_arm64 = -S
|
||||
linkerDynamicFlags.watchos_simulator_arm64 = -dylib
|
||||
osVersionMinFlagLd.watchos_simulator_arm64 = -watchos_simulator_version_min
|
||||
osVersionMin.watchos_simulator_arm64 = 7.0
|
||||
runtimeDefinitions.watchos_simulator_arm64 = KONAN_OBJC_INTEROP=1 KONAN_WATCHOS=1 KONAN_ARM64=1 KONAN_HAS_FOUNDATION_FRAMEWORK=1
|
||||
|
||||
|
||||
|
||||
# Linux x86-64.
|
||||
@@ -551,8 +537,7 @@ dynamicLinker.linux_x64 = /lib64/ld-linux-x86-64.so.2
|
||||
abiSpecificLibraries.linux_x64 = lib usr/lib ../lib64 lib64 usr/lib64
|
||||
# targetSysRoot relative
|
||||
crtFilesLocation.linux_x64 = usr/lib
|
||||
runtimeDefinitions.linux_x64 = USE_GCC_UNWIND=1 KONAN_LINUX=1 KONAN_X64=1 \
|
||||
USE_ELF_SYMBOLS=1 ELFSIZE=64
|
||||
|
||||
|
||||
# Raspberry Pi
|
||||
gccToolchain.linux_arm32_hfp = $toolchainDependency.linux_arm32_hfp
|
||||
@@ -611,9 +596,7 @@ dynamicLinker.linux_arm32_hfp = /lib/ld-linux-armhf.so.3
|
||||
abiSpecificLibraries.linux_arm32_hfp = lib usr/lib
|
||||
# targetSysRoot relative
|
||||
crtFilesLocation.linux_arm32_hfp = usr/lib
|
||||
runtimeDefinitions.linux_arm32_hfp = USE_GCC_UNWIND=1 KONAN_LINUX=1 \
|
||||
KONAN_ARM32=1 USE_ELF_SYMBOLS=1 ELFSIZE=32 KONAN_NO_UNALIGNED_ACCESS=1 \
|
||||
KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# Linux arm64
|
||||
gccToolchain.linux_arm64 = $toolchainDependency.linux_arm64
|
||||
@@ -668,8 +651,7 @@ dynamicLinker.linux_arm64 = /lib/ld-linux-aarch64.so.1
|
||||
abiSpecificLibraries.linux_arm64 = lib usr/lib
|
||||
# targetSysRoot relative
|
||||
crtFilesLocation.linux_arm64 = usr/lib
|
||||
runtimeDefinitions.linux_arm64 = USE_GCC_UNWIND=1 KONAN_LINUX=1 KONAN_ARM64=1 \
|
||||
USE_ELF_SYMBOLS=1 ELFSIZE=64
|
||||
|
||||
|
||||
# MIPS
|
||||
gccToolchain.linux_mips32 = $toolchainDependency.linux_mips32
|
||||
@@ -721,10 +703,7 @@ dynamicLinker.linux_mips32 = /lib/ld.so.1
|
||||
abiSpecificLibraries.linux_mips32 = lib usr/lib
|
||||
# targetSysRoot relative
|
||||
crtFilesLocation.linux_mips32 = usr/lib
|
||||
# TODO: reconsider KONAN_NO_64BIT_ATOMIC, once target MIPS can do proper 64-bit load/store/CAS.
|
||||
runtimeDefinitions.linux_mips32 = USE_GCC_UNWIND=1 KONAN_LINUX=1 KONAN_MIPS32=1 \
|
||||
USE_ELF_SYMBOLS=1 ELFSIZE=32 KONAN_NO_64BIT_ATOMIC=1 KONAN_NO_UNALIGNED_ACCESS=1 \
|
||||
KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# MIPSel
|
||||
gccToolchain.linux_mipsel32 = $toolchainDependency.linux_mipsel32
|
||||
@@ -773,10 +752,7 @@ dynamicLinker.linux_mipsel32 = /lib/ld.so.1
|
||||
abiSpecificLibraries.linux_mipsel32 = lib usr/lib
|
||||
# targetSysRoot relative
|
||||
crtFilesLocation.linux_mipsel32 = usr/lib
|
||||
# TODO: reconsider KONAN_NO_64BIT_ATOMIC, once target MIPS can do proper 64-bit load/store/CAS.
|
||||
runtimeDefinitions.linux_mipsel32 = USE_GCC_UNWIND=1 KONAN_LINUX=1 \
|
||||
KONAN_MIPSEL32=1 USE_ELF_SYMBOLS=1 ELFSIZE=32 KONAN_NO_64BIT_ATOMIC=1 KONAN_NO_UNALIGNED_ACCESS=1 \
|
||||
KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# Android ARM32, based on NDK for android-21.
|
||||
targetToolchain.macos_x64-android_arm32 = target-toolchain-2-osx-android_ndk
|
||||
@@ -805,9 +781,7 @@ linkerNoDebugFlags.android_arm32 = -Wl,-S
|
||||
clangNooptFlags.android_arm32 = -O1
|
||||
targetSysRoot.android_arm32 = target-sysroot-1-android_ndk
|
||||
linkerKonanFlags.android_arm32 = -lm -lc++_static -lc++abi -landroid -llog -latomic
|
||||
runtimeDefinitions.android_arm32 = __ANDROID__ USE_GCC_UNWIND=1 USE_ELF_SYMBOLS=1 ELFSIZE=32 \
|
||||
KONAN_ANDROID=1 KONAN_ARM32=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_NO_64BIT_ATOMIC=1 \
|
||||
KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# Android ARM64, based on NDK.
|
||||
targetToolchain.macos_x64-android_arm64 = target-toolchain-2-osx-android_ndk
|
||||
@@ -835,8 +809,7 @@ clangNooptFlags.android_arm64 = -O1
|
||||
targetSysRoot.android_arm64 = target-sysroot-1-android_ndk
|
||||
linkerKonanFlags.android_arm64 = -lm -lc++_static -lc++abi -landroid -llog -latomic
|
||||
linkerNoDebugFlags.android_arm64 = -Wl,-S
|
||||
runtimeDefinitions.android_arm64 = __ANDROID__ USE_GCC_UNWIND=1 USE_ELF_SYMBOLS=1 \
|
||||
ELFSIZE=64 KONAN_ANDROID=1 KONAN_ARM64=1
|
||||
|
||||
|
||||
# Android X86, based on NDK.
|
||||
targetToolchain.macos_x64-android_x86 = target-toolchain-2-osx-android_ndk
|
||||
@@ -865,8 +838,7 @@ clangNooptFlags.android_x86 = -O1
|
||||
targetSysRoot.android_x86 = target-sysroot-1-android_ndk
|
||||
linkerKonanFlags.android_x86 = -lm -lc++_static -lc++abi -landroid -llog -latomic
|
||||
linkerNoDebugFlags.android_x86 = -Wl,-S
|
||||
runtimeDefinitions.android_x86 = __ANDROID__ USE_GCC_UNWIND=1 USE_ELF_SYMBOLS=1 \
|
||||
ELFSIZE=32 KONAN_ANDROID=1 KONAN_X86=1 KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# Android X64, based on NDK.
|
||||
targetToolchain.macos_x64-android_x64 = target-toolchain-2-osx-android_ndk
|
||||
@@ -894,8 +866,7 @@ clangNooptFlags.android_x64 = -O1
|
||||
targetSysRoot.android_x64 = target-sysroot-1-android_ndk
|
||||
linkerKonanFlags.android_x64 = -lm -lc++_static -lc++abi -landroid -llog -latomic
|
||||
linkerNoDebugFlags.android_x64 = -Wl,-S
|
||||
runtimeDefinitions.android_x64 = __ANDROID__ USE_GCC_UNWIND=1 USE_ELF_SYMBOLS=1 \
|
||||
ELFSIZE=64 KONAN_ANDROID=1 KONAN_X64=1
|
||||
|
||||
|
||||
# Windows x86-64, based on mingw-w64.
|
||||
llvmHome.mingw_x64 = $llvm.mingw_x64.dev
|
||||
@@ -945,8 +916,7 @@ linkerKonanFlags.mingw_x64 =-static-libgcc -static-libstdc++ \
|
||||
-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic
|
||||
linkerOptimizationFlags.mingw_x64 = -Wl,--gc-sections
|
||||
mimallocLinkerDependencies.mingw_x64 = -lbcrypt
|
||||
runtimeDefinitions.mingw_x64 = USE_GCC_UNWIND=1 USE_PE_COFF_SYMBOLS=1 KONAN_WINDOWS=1 \
|
||||
UNICODE KONAN_X64=1 KONAN_NO_MEMMEM=1
|
||||
|
||||
|
||||
# Windows i686, based on mingw-w64.
|
||||
targetToolchain.mingw_x64-mingw_x86 = $toolchainDependency.mingw_x86
|
||||
@@ -986,8 +956,7 @@ linkerKonanFlags.mingw_x86 = -static-libgcc -static-libstdc++ \
|
||||
-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic
|
||||
mimallocLinkerDependencies.mingw_x86 = -lbcrypt
|
||||
linkerOptimizationFlags.mingw_x86 = -Wl,--gc-sections
|
||||
runtimeDefinitions.mingw_x86 = USE_GCC_UNWIND=1 USE_PE_COFF_SYMBOLS=1 KONAN_WINDOWS=1 \
|
||||
UNICODE KONAN_X86=1 KONAN_NO_MEMMEM=1 KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
|
||||
# WebAssembly 32-bit.
|
||||
targetToolchain.macos_x64-wasm32 = target-toolchain-3-macos-wasm
|
||||
@@ -1019,10 +988,6 @@ clangOptFlags.wasm32 = -O3
|
||||
clangDebugFlags.wasm32 = -O0
|
||||
# TODO: make explicit list of external symbols
|
||||
lld.wasm32 = --allow-undefined --no-entry --global-base=0 --export-dynamic
|
||||
runtimeDefinitions.wasm32 = KONAN_WASM=1 KONAN_NO_FFI=1 KONAN_NO_THREADS=1 \
|
||||
KONAN_NO_EXCEPTIONS=1 KONAN_INTERNAL_DLMALLOC=1 KONAN_INTERNAL_SNPRINTF=1 \
|
||||
KONAN_INTERNAL_NOW=1 KONAN_NO_MEMMEM KONAN_NO_CTORS_SECTION=1 KONAN_NO_BACKTRACE=1 \
|
||||
KONAN_NO_EXTERNAL_CALLS_CHECKER=1 KONAN_FORBID_BUILTIN_MUL_OVERFLOW=1
|
||||
|
||||
# The version of Kotlin/Native compiler
|
||||
compilerVersion=@compilerVersion@
|
||||
|
||||
@@ -24,10 +24,6 @@ boardSpecificClangFlags.zephyr_stm32f4_disco = -mthumb
|
||||
targetCpu.zephyr_stm32f4_disco = cortex-m4
|
||||
targetAbi.zephyr_stm32f4_disco = aapcs
|
||||
clangFlags = -Os
|
||||
runtimeDefinitions.zephyr_stm32f4_disco = KONAN_ZEPHYR=1 KONAN_NO_FFI=1 \
|
||||
KONAN_NO_THREADS=1 KONAN_NO_EXCEPTIONS=1 KONAN_NO_MATH=1 \
|
||||
KONAN_INTERNAL_SNPRINTF=1 KONAN_INTERNAL_NOW=1 KONAN_NO_MEMMEM=1 \
|
||||
KONAN_NO_CTORS_SECTION=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_NO_BACKTRACE=1
|
||||
|
||||
targetToolchain.linux_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-linux/arm-none-eabi
|
||||
dependencies.linux_x64-zephyr_stm32f4_disco = \
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define RUNTIME_WEAK __attribute__((weak))
|
||||
#define RUNTIME_NODEBUG __attribute__((nodebug))
|
||||
|
||||
#if KONAN_ARM32 && (KONAN_IOS || KONAN_WATCHOS)
|
||||
#if KONAN_NEAD_SMALL_BINARY
|
||||
// On the one hand, ALWAYS_INLINE forces many performance-critical function to be, well,
|
||||
// inlined. Which is good for performance, of course.
|
||||
// On the other hand, 32-bit Mach-O object files can't be really big.
|
||||
@@ -52,9 +52,5 @@
|
||||
#define KONAN_TYPE_INFO_HAS_WRITABLE_PART 1
|
||||
#endif
|
||||
|
||||
// should be consistent with hasAddressDependencyInMemoryModel function
|
||||
#if defined(KONAN_X64) || defined(KONAN_X86) || defined(KONAN_ARM32) || defined(KONAN_ARM64)
|
||||
#define KONAN_TARGET_HAS_ADDRESS_DEPENDENCY 1
|
||||
#endif
|
||||
|
||||
#endif // RUNTIME_COMMON_H
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "PointerBits.h"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#if KONAN_ARM32 && (KONAN_IOS || KONAN_WATCHOS)
|
||||
#if KONAN_NEAD_SMALL_BINARY
|
||||
// Currently, codegen places a lot of unnecessary calls to MM functions.
|
||||
// By forcing NO_INLINE on these functions we keep binaries from growing too big.
|
||||
#define CODEGEN_INLINE_POLICY NO_INLINE
|
||||
|
||||
+37
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed -> in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.konan.target
|
||||
@@ -45,8 +34,41 @@ sealed class ClangArgs(
|
||||
// TODO: Should be dropped in favor of real MSVC target.
|
||||
private val argsForWindowsJni = forJni && target == KonanTarget.MINGW_X64
|
||||
|
||||
private val clangArgsSpecificForKonanSources
|
||||
get() = configurables.runtimeDefinitions.map { "-D$it" }
|
||||
private val clangArgsSpecificForKonanSources : List<String>
|
||||
get() {
|
||||
val konanOptions = listOfNotNull(
|
||||
target.architecture.name.takeIf { target != KonanTarget.WATCHOS_ARM64 },
|
||||
"ARM32".takeIf { target == KonanTarget.WATCHOS_ARM64 },
|
||||
target.family.name.takeIf { target.family != Family.MINGW },
|
||||
"WINDOWS".takeIf { target.family == Family.MINGW },
|
||||
"MACOSX".takeIf { target.family == Family.OSX },
|
||||
|
||||
"NO_THREADS".takeUnless { target.supportsThreads() },
|
||||
"NO_EXCEPTIONS".takeUnless { target.supportsExceptions() },
|
||||
"NO_MEMMEM".takeUnless { target.suportsMemMem() },
|
||||
"NO_64BIT_ATOMIC".takeUnless { target.supports64BitAtomics() },
|
||||
"NO_UNALIGNED_ACCESS".takeUnless { target.supportsUnalignedAccess() },
|
||||
"FORBID_BUILTIN_MUL_OVERFLOW".takeUnless { target.supports64BitMulOverflow() },
|
||||
|
||||
"OBJC_INTEROP".takeIf { target.supportsObjcInterop() },
|
||||
"HAS_FOUNDATION_FRAMEWORK".takeIf { target.hasFoundationFramework() },
|
||||
"HAS_UIKIT_FRAMEWORK".takeIf { target.hasUIKitFramework() },
|
||||
"REPORT_BACKTRACE_TO_IOS_CRASH_LOG".takeIf { target.supportsIosCrashLog() },
|
||||
"NEAD_SMALL_BINARY".takeIf { target.needSmallBinary() },
|
||||
"TARGET_HAS_ADDRESS_DEPENDENCY".takeIf { target.hasAddressDependencyInMemoryModel() },
|
||||
).map { "KONAN_$it=1" }
|
||||
val otherOptions = listOfNotNull(
|
||||
"USE_ELF_SYMBOLS=1".takeIf { target.binaryFormat() == BinaryFormat.ELF },
|
||||
"ELFSIZE=${target.pointerBits()}".takeIf { target.binaryFormat() == BinaryFormat.ELF },
|
||||
"MACHSIZE=${target.pointerBits()}".takeIf { target.binaryFormat() == BinaryFormat.MACH_O },
|
||||
"__ANDROID__".takeIf { target.family == Family.ANDROID },
|
||||
"USE_PE_COFF_SYMBOLS=1".takeIf { target.binaryFormat() == BinaryFormat.PE_COFF },
|
||||
"UNICODE".takeIf { target.family == Family.MINGW },
|
||||
"USE_GCC_UNWIND=1".takeIf { target.supportsGccUnwind() }
|
||||
)
|
||||
val customOptions = target.customArgsForKonanSources()
|
||||
return (konanOptions + otherOptions + customOptions).map { "-D$it" }
|
||||
}
|
||||
|
||||
private val binDir = when (HostManager.host) {
|
||||
KonanTarget.LINUX_X64 -> "$absoluteTargetToolchain/bin"
|
||||
|
||||
+115
-8
@@ -5,7 +5,33 @@
|
||||
|
||||
package org.jetbrains.kotlin.konan.target
|
||||
|
||||
// TODO: This all needs to go to konan.properties
|
||||
enum class BinaryFormat {
|
||||
ELF,
|
||||
PE_COFF,
|
||||
MACH_O
|
||||
}
|
||||
|
||||
fun KonanTarget.binaryFormat() = when (family) {
|
||||
Family.WATCHOS -> BinaryFormat.MACH_O
|
||||
Family.IOS -> BinaryFormat.MACH_O
|
||||
Family.TVOS -> BinaryFormat.MACH_O
|
||||
Family.OSX -> BinaryFormat.MACH_O
|
||||
Family.ANDROID -> BinaryFormat.ELF
|
||||
Family.LINUX -> BinaryFormat.ELF
|
||||
Family.MINGW -> BinaryFormat.PE_COFF
|
||||
Family.WASM, Family.ZEPHYR -> null
|
||||
}
|
||||
|
||||
fun KonanTarget.pointerBits() = when (architecture) {
|
||||
Architecture.X64 -> 64
|
||||
Architecture.X86 -> 32
|
||||
Architecture.ARM64 -> if (this == KonanTarget.WATCHOS_ARM64) 32 else 64
|
||||
Architecture.ARM32 -> 32
|
||||
Architecture.MIPS32 -> 32
|
||||
Architecture.MIPSEL32 -> 32
|
||||
Architecture.WASM32 -> 32
|
||||
}
|
||||
|
||||
|
||||
fun KonanTarget.supportsCodeCoverage(): Boolean =
|
||||
// TODO: Disabled for now, because we don't support
|
||||
@@ -46,13 +72,71 @@ fun KonanTarget.supportsCoreSymbolication(): Boolean =
|
||||
KonanTarget.WATCHOS_X86, KonanTarget.WATCHOS_X64, KonanTarget.WATCHOS_SIMULATOR_ARM64
|
||||
)
|
||||
|
||||
fun KonanTarget.supportsGccUnwind(): Boolean = family == Family.ANDROID || family == Family.LINUX || family == Family.MINGW
|
||||
|
||||
fun KonanTarget.supportsThreads(): Boolean =
|
||||
when(this) {
|
||||
is KonanTarget.WASM32 -> false
|
||||
is KonanTarget.ZEPHYR -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun KonanTarget.supportsThreads(): Boolean = when(this) {
|
||||
is KonanTarget.WASM32 -> false
|
||||
is KonanTarget.ZEPHYR -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun KonanTarget.supportsExceptions(): Boolean = when(this) {
|
||||
is KonanTarget.WASM32 -> false
|
||||
is KonanTarget.ZEPHYR -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun KonanTarget.suportsMemMem(): Boolean = when (this) {
|
||||
is KonanTarget.WASM32 -> false
|
||||
is KonanTarget.MINGW_X86 -> false
|
||||
is KonanTarget.MINGW_X64 -> false
|
||||
is KonanTarget.ZEPHYR -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun KonanTarget.supportsObjcInterop(): Boolean = family.isAppleFamily
|
||||
fun KonanTarget.hasFoundationFramework(): Boolean = family.isAppleFamily
|
||||
fun KonanTarget.hasUIKitFramework(): Boolean = family == Family.IOS || family == Family.TVOS
|
||||
fun KonanTarget.supports64BitMulOverflow(): Boolean = when (this) {
|
||||
is KonanTarget.MINGW_X86 -> false
|
||||
is KonanTarget.LINUX_ARM32_HFP -> false
|
||||
is KonanTarget.LINUX_MIPS32 -> false
|
||||
is KonanTarget.LINUX_MIPSEL32 -> false
|
||||
is KonanTarget.WASM32 -> false
|
||||
is KonanTarget.ZEPHYR -> false
|
||||
is KonanTarget.ANDROID_ARM32 -> false
|
||||
is KonanTarget.ANDROID_X86 -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun KonanTarget.supportsIosCrashLog(): Boolean = when (this) {
|
||||
KonanTarget.IOS_ARM32 -> true
|
||||
KonanTarget.IOS_ARM64 -> true
|
||||
KonanTarget.WATCHOS_ARM32 -> true
|
||||
KonanTarget.WATCHOS_ARM64 -> true
|
||||
KonanTarget.TVOS_ARM64 -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
/*
|
||||
* While not 100% correct here, using atomic ops on iOS armv7 requires 8 byte alignment,
|
||||
* and general ABI requires 4-byte alignment on 64-bit long fields as mentioned in
|
||||
* https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html#//apple_ref/doc/uid/TP40009021-SW1
|
||||
* See https://github.com/ktorio/ktor/issues/941 for the context.
|
||||
* TODO: reconsider once target MIPS can do proper 64-bit load/store/CAS.
|
||||
*/
|
||||
fun KonanTarget.supports64BitAtomics(): Boolean = when (architecture) {
|
||||
Architecture.ARM32, Architecture.WASM32, Architecture.MIPS32, Architecture.MIPSEL32 -> false
|
||||
Architecture.X86, Architecture.ARM64, Architecture.X64 -> true
|
||||
} && this != KonanTarget.WATCHOS_ARM64 && this != KonanTarget.WATCHOS_X86
|
||||
|
||||
fun KonanTarget.supportsUnalignedAccess(): Boolean = when (architecture) {
|
||||
Architecture.ARM32, Architecture.WASM32, Architecture.MIPS32, Architecture.MIPSEL32 -> false
|
||||
Architecture.X86, Architecture.ARM64, Architecture.X64 -> true
|
||||
} && this != KonanTarget.WATCHOS_ARM64
|
||||
|
||||
fun KonanTarget.needSmallBinary() = (architecture == Architecture.ARM32 && family.isAppleFamily) || this == KonanTarget.WATCHOS_ARM64
|
||||
|
||||
fun KonanTarget.supportedSanitizers(): List<SanitizerKind> =
|
||||
when(this) {
|
||||
@@ -65,9 +149,32 @@ fun KonanTarget.supportedSanitizers(): List<SanitizerKind> =
|
||||
else -> listOf()
|
||||
}
|
||||
|
||||
// should be consistent with KONAN_TARGET_HAS_ADDRESS_DEPENDENCY macro
|
||||
fun KonanTarget.hasAddressDependencyInMemoryModel(): Boolean =
|
||||
when (this.architecture) {
|
||||
Architecture.X86, Architecture.X64, Architecture.ARM32, Architecture.ARM64 -> true
|
||||
Architecture.MIPS32, Architecture.MIPSEL32, Architecture.WASM32 -> false
|
||||
}
|
||||
|
||||
|
||||
// TODO: this is bad function. It should be replaced by capabilities functions like above
|
||||
// but two affected targets are too strange, so we postpone it
|
||||
fun KonanTarget.customArgsForKonanSources() = when (this) {
|
||||
KonanTarget.WASM32 -> listOf(
|
||||
"KONAN_NO_FFI=1",
|
||||
"KONAN_INTERNAL_DLMALLOC=1",
|
||||
"KONAN_INTERNAL_SNPRINTF=1",
|
||||
"KONAN_INTERNAL_NOW=1",
|
||||
"KONAN_NO_CTORS_SECTION=1",
|
||||
"KONAN_NO_BACKTRACE=1",
|
||||
"KONAN_NO_EXTERNAL_CALLS_CHECKER=1",
|
||||
)
|
||||
is KonanTarget.ZEPHYR -> listOf(
|
||||
"KONAN_NO_FFI=1",
|
||||
"KONAN_NO_MATH=1",
|
||||
"KONAN_INTERNAL_SNPRINTF=1",
|
||||
"KONAN_INTERNAL_NOW=1",
|
||||
"KONAN_NO_CTORS_SECTION=1",
|
||||
"KONAN_NO_BACKTRACE=1"
|
||||
)
|
||||
else -> emptyList()
|
||||
}
|
||||
Reference in New Issue
Block a user