Update LLVM to 6.0.1 and WebAssembly target refactoring (#1788)

* wasm updates: removed binaryen, simplified morecore and launcher.js
* Updated LLVM toolchain to 6.0.1
This commit is contained in:
Sergey Bogolepov
2018-08-14 21:08:45 +03:00
committed by GitHub
parent 061ea53853
commit 5a66f91da5
36 changed files with 1157 additions and 1108 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.konan.KonanExternalToolFailure import org.jetbrains.kotlin.konan.KonanExternalToolFailure
import org.jetbrains.kotlin.konan.exec.Command import org.jetbrains.kotlin.konan.exec.Command
import org.jetbrains.kotlin.konan.file.File import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.file.createTempFile
import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.target.*
typealias BitcodeFile = String typealias BitcodeFile = String
@@ -90,8 +89,8 @@ internal class LinkStage(val context: Context, val phaser: PhaseManager) {
val configurables = platform.configurables as WasmConfigurables val configurables = platform.configurables as WasmConfigurables
val combinedBc = temporary("combined", ".bc") val combinedBc = temporary("combined", ".bc")
// TODO: use -only-needed for the stdlib
hostLlvmTool("llvm-link", *bitcodeFiles.toTypedArray(), "-o", combinedBc) hostLlvmTool("llvm-link", *bitcodeFiles.toTypedArray(), "-o", combinedBc)
val optFlags = (configurables.optFlags + when { val optFlags = (configurables.optFlags + when {
optimize -> configurables.optOptFlags optimize -> configurables.optOptFlags
debug -> configurables.optDebugFlags debug -> configurables.optDebugFlags
@@ -99,24 +98,16 @@ internal class LinkStage(val context: Context, val phaser: PhaseManager) {
} + llvmProfilingFlags()).toTypedArray() } + llvmProfilingFlags()).toTypedArray()
val optimizedBc = temporary("optimized", ".bc") val optimizedBc = temporary("optimized", ".bc")
hostLlvmTool("opt", combinedBc, "-o", optimizedBc, *optFlags) hostLlvmTool("opt", combinedBc, "-o", optimizedBc, *optFlags)
val llcFlags = (configurables.llcFlags + when { val llcFlags = (configurables.llcFlags + when {
optimize -> configurables.llcOptFlags optimize -> configurables.llcOptFlags
debug -> configurables.llcDebugFlags debug -> configurables.llcDebugFlags
else -> configurables.llcNooptFlags else -> configurables.llcNooptFlags
} + llvmProfilingFlags()).toTypedArray() } + llvmProfilingFlags()).toTypedArray()
val combinedS = temporary("combined", ".s") val combinedO = temporary("combined", ".o")
targetTool("llc", optimizedBc, "-o", combinedS, *llcFlags) hostLlvmTool("llc", optimizedBc, "-o", combinedO, *llcFlags, "-filetype=obj")
val linkedWasm = temporary("linked", ".wasm")
val s2wasmFlags = configurables.s2wasmFlags.toTypedArray() hostLlvmTool("wasm-ld", combinedO, "-o", linkedWasm, *configurables.lldFlags.toTypedArray())
val combinedWast = temporary("combined", ".wast") return linkedWasm
targetTool("s2wasm", combinedS, "-o", combinedWast, *s2wasmFlags)
val combinedWasm = temporary("combined", ".wasm")
val combinedSmap = temporary("combined", ".smap")
targetTool("wasm-as", combinedWast, "-o", combinedWasm, "-g", "-s", combinedSmap)
return combinedWasm
} }
private fun llvmLinkAndLlc(bitcodeFiles: List<BitcodeFile>): String { private fun llvmLinkAndLlc(bitcodeFiles: List<BitcodeFile>): String {
+1
View File
@@ -32,6 +32,7 @@ linkerOpts.linux= -fPIC \
-lrt -ldl -lpthread -lz -lm -lrt -ldl -lpthread -lz -lm
linkerOpts.mingw = -lole32 -luuid -static-libgcc -static-libstdc++ \ linkerOpts.mingw = -lole32 -luuid -static-libgcc -static-libstdc++ \
-Wl,-Bstatic -lz \
-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic
# It looks like mingw port compiled without LLVM_ENABLE_DUMP # It looks like mingw port compiled without LLVM_ENABLE_DUMP
+1 -1
View File
@@ -98,7 +98,7 @@ goto :eof
rem libclang.dll is dynamically linked and thus requires correct PATH to be loaded. rem libclang.dll is dynamically linked and thus requires correct PATH to be loaded.
rem TODO: remove this hack. rem TODO: remove this hack.
if "%KONAN_DATA_DIR%"=="" (set KONAN_DATA_DIR=%USERPROFILE%\.konan) if "%KONAN_DATA_DIR%"=="" (set KONAN_DATA_DIR=%USERPROFILE%\.konan)
set "PATH=%KONAN_DATA_DIR%\dependencies\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64\bin;%PATH%" set "PATH=%KONAN_DATA_DIR%\dependencies\msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1\bin;%PATH%"
goto :eof goto :eof
:end :end
+34 -33
View File
@@ -31,10 +31,10 @@ downloadingAttemptIntervalMs = 3000
homeDependencyCache = .konan/cache homeDependencyCache = .konan/cache
llvmDebugOptFlags = -O1 llvmDebugOptFlags = -O1
llvmVersion = 5.0.0 llvmVersion = 6.0.1
# Mac OS X. # Mac OS X.
llvmHome.macos_x64 = clang-llvm-5.0.0-darwin-macos llvmHome.macos_x64 = clang-llvm-6.0.1-darwin-macos
targetToolchain.macos_x64 = target-toolchain-6-macos_x64 targetToolchain.macos_x64 = target-toolchain-6-macos_x64
arch.macos_x64 = x86_64 arch.macos_x64 = x86_64
@@ -54,7 +54,7 @@ osVersionMin.macos_x64 = 10.11
entrySelector.macos_x64 = -alias _Konan_main _main entrySelector.macos_x64 = -alias _Konan_main _main
dependencies.macos_x64 = \ dependencies.macos_x64 = \
libffi-3.2.1-2-darwin-macos \ libffi-3.2.1-2-darwin-macos \
clang-llvm-5.0.0-darwin-macos clang-llvm-6.0.1-darwin-macos
target-sysroot-6-macos_x64.default = \ target-sysroot-6-macos_x64.default = \
remote:internal remote:internal
@@ -66,7 +66,7 @@ target-toolchain-6-macos_x64.default = \
targetToolchain.macos_x64-ios_arm32 = target-toolchain-6-macos_x64 targetToolchain.macos_x64-ios_arm32 = target-toolchain-6-macos_x64
dependencies.macos_x64-ios_arm32 = \ dependencies.macos_x64-ios_arm32 = \
libffi-3.2.1-2-darwin-ios \ libffi-3.2.1-2-darwin-ios \
clang-llvm-5.0.0-darwin-macos clang-llvm-6.0.1-darwin-macos
target-sysroot-6-ios_arm32.default = \ target-sysroot-6-ios_arm32.default = \
remote:internal remote:internal
@@ -92,7 +92,7 @@ osVersionMin.ios_arm32 = 9.0
targetToolchain.macos_x64-ios_arm64 = target-toolchain-6-macos_x64 targetToolchain.macos_x64-ios_arm64 = target-toolchain-6-macos_x64
dependencies.macos_x64-ios_arm64 = \ dependencies.macos_x64-ios_arm64 = \
libffi-3.2.1-2-darwin-ios \ libffi-3.2.1-2-darwin-ios \
clang-llvm-5.0.0-darwin-macos clang-llvm-6.0.1-darwin-macos
target-sysroot-6-ios_arm64.default = \ target-sysroot-6-ios_arm64.default = \
remote:internal remote:internal
@@ -117,7 +117,7 @@ osVersionMin.ios_arm64 = 8.0
targetToolchain.macos_x64-ios_x64 = target-toolchain-6-macos_x64 targetToolchain.macos_x64-ios_x64 = target-toolchain-6-macos_x64
dependencies.macos_x64-ios_x64 = \ dependencies.macos_x64-ios_x64 = \
libffi-3.2.1-1-darwin-ios_sim \ libffi-3.2.1-1-darwin-ios_sim \
clang-llvm-5.0.0-darwin-macos clang-llvm-6.0.1-darwin-macos
target-sysroot-6-ios_x64.default = \ target-sysroot-6-ios_x64.default = \
remote:internal remote:internal
@@ -139,7 +139,7 @@ osVersionMinFlagClang.ios_x64 = -mios-simulator-version-min
osVersionMin.ios_x64 = 8.0 osVersionMin.ios_x64 = 8.0
# Linux x86-64. # Linux x86-64.
llvmHome.linux_x64 = clang-llvm-5.0.0-linux-x86-64 llvmHome.linux_x64 = clang-llvm-6.0.1-linux-x86-64
gccToolchain.linux_x64 = target-gcc-toolchain-3-linux-x86-64 gccToolchain.linux_x64 = target-gcc-toolchain-3-linux-x86-64
targetToolchain.linux_x64 = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu targetToolchain.linux_x64 = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu
@@ -164,14 +164,14 @@ entrySelector.linux_x64 = --defsym main=Konan_main
# targetSysRoot relative # targetSysRoot relative
abiSpecificLibraries.linux_x64 = ../lib64 lib64 usr/lib64 abiSpecificLibraries.linux_x64 = ../lib64 lib64 usr/lib64
dependencies.linux_x64 = \ dependencies.linux_x64 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-gcc-toolchain-3-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \
libffi-3.2.1-2-linux-x86-64 libffi-3.2.1-2-linux-x86-64
# Raspberry Pi # Raspberry Pi
targetToolchain.linux_x64-linux_arm32_hfp = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu targetToolchain.linux_x64-linux_arm32_hfp = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu
dependencies.linux_x64-linux_arm32_hfp = \ dependencies.linux_x64-linux_arm32_hfp = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-gcc-toolchain-3-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \
target-sysroot-1-raspberrypi \ target-sysroot-1-raspberrypi \
libffi-3.2.1-2-linux-x86-64 \ libffi-3.2.1-2-linux-x86-64 \
@@ -203,7 +203,7 @@ abiSpecificLibraries.linux_arm32_hfp = \
# MIPS # MIPS
targetToolchain.linux_x64-linux_mips32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu targetToolchain.linux_x64-linux_mips32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu
dependencies.linux_x64-linux_mips32 = \ dependencies.linux_x64-linux_mips32 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-gcc-toolchain-2-linux-mips \ target-gcc-toolchain-2-linux-mips \
target-gcc-toolchain-3-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \
target-sysroot-2-mips \ target-sysroot-2-mips \
@@ -232,7 +232,7 @@ abiSpecificLibraries.linux_mips32 =
# MIPSel # MIPSel
targetToolchain.linux_x64-linux_mipsel32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu targetToolchain.linux_x64-linux_mipsel32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu
dependencies.linux_x64-linux_mipsel32 = \ dependencies.linux_x64-linux_mipsel32 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-gcc-toolchain-2-linux-mips \ target-gcc-toolchain-2-linux-mips \
target-gcc-toolchain-3-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \
target-sysroot-2-mipsel \ target-sysroot-2-mipsel \
@@ -261,13 +261,13 @@ abiSpecificLibraries.linux_mipsel32 =
targetToolchain.macos_x64-android_arm32 = target-toolchain-21-osx-android_arm32 targetToolchain.macos_x64-android_arm32 = target-toolchain-21-osx-android_arm32
# TODO: split dependencies to host-dependent and host-independent parts. # TODO: split dependencies to host-dependent and host-independent parts.
dependencies.macos_x64-android_arm32 = \ dependencies.macos_x64-android_arm32 = \
clang-llvm-5.0.0-darwin-macos \ clang-llvm-6.0.1-darwin-macos \
target-sysroot-21-android_arm32 \ target-sysroot-21-android_arm32 \
target-toolchain-21-osx-android_arm32 \ target-toolchain-21-osx-android_arm32 \
libffi-3.2.1-2-android_arm32 libffi-3.2.1-2-android_arm32
targetToolchain.linux_x64-android_arm32 = target-toolchain-21-linux-android_arm32 targetToolchain.linux_x64-android_arm32 = target-toolchain-21-linux-android_arm32
dependencies.linux_x64-android_arm32 = \ dependencies.linux_x64-android_arm32 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-sysroot-21-android_arm32 \ target-sysroot-21-android_arm32 \
target-toolchain-21-linux-android_arm32 \ target-toolchain-21-linux-android_arm32 \
libffi-3.2.1-2-android_arm32 libffi-3.2.1-2-android_arm32
@@ -286,13 +286,13 @@ linkerKonanFlags.android_arm32 = -lm -latomic -lstdc++ -landroid
targetToolchain.macos_x64-android_arm64 = target-toolchain-21-osx-android_arm64 targetToolchain.macos_x64-android_arm64 = target-toolchain-21-osx-android_arm64
# TODO: split dependencies to host-dependent and host-independent parts. # TODO: split dependencies to host-dependent and host-independent parts.
dependencies.macos_x64-android_arm64 = \ dependencies.macos_x64-android_arm64 = \
clang-llvm-5.0.0-darwin-macos \ clang-llvm-6.0.1-darwin-macos \
target-sysroot-21-android_arm64 \ target-sysroot-21-android_arm64 \
target-toolchain-21-osx-android_arm64 \ target-toolchain-21-osx-android_arm64 \
libffi-3.2.1-2-android_arm64 libffi-3.2.1-2-android_arm64
targetToolchain.linux_x64-android_arm64 = target-toolchain-21-linux-android_arm64 targetToolchain.linux_x64-android_arm64 = target-toolchain-21-linux-android_arm64
dependencies.linux_x64-android_arm64 = \ dependencies.linux_x64-android_arm64 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-sysroot-21-android_arm64 \ target-sysroot-21-android_arm64 \
target-toolchain-21-linux-android_arm64 \ target-toolchain-21-linux-android_arm64 \
libffi-3.2.1-2-android_arm64 libffi-3.2.1-2-android_arm64
@@ -306,11 +306,11 @@ linkerKonanFlags.android_arm64 = -lm -latomic -lstdc++ -landroid
linkerNoDebugFlags.android_arm64 = -Wl,-S linkerNoDebugFlags.android_arm64 = -Wl,-S
# Windows x86-64, based on mingw-w64. # Windows x86-64, based on mingw-w64.
llvmHome.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 llvmHome.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1
targetToolchain.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 targetToolchain.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1
quadruple.mingw_x64 = x86_64-w64-mingw32 quadruple.mingw_x64 = x86_64-w64-mingw32
targetSysRoot.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 targetSysRoot.mingw_x64 = msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1
libffiDir.mingw_x64 = libffi-3.2.1-mingw-w64-x86-64 libffiDir.mingw_x64 = libffi-3.2.1-mingw-w64-x86-64
llvmLtoFlags.mingw_x64 = llvmLtoFlags.mingw_x64 =
llvmLtoOptFlags.mingw_x64 = -O3 -function-sections llvmLtoOptFlags.mingw_x64 = -O3 -function-sections
@@ -324,38 +324,39 @@ linkerKonanFlags.mingw_x64 =-static-libgcc -static-libstdc++ \
linkerOptimizationFlags.mingw_x64 = -Wl,--gc-sections linkerOptimizationFlags.mingw_x64 = -Wl,--gc-sections
entrySelector.mingw_x64 = -Wl,--defsym,main=Konan_main entrySelector.mingw_x64 = -Wl,--defsym,main=Konan_main
dependencies.mingw_x64 = \ dependencies.mingw_x64 = \
msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 \ msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1 \
libffi-3.2.1-mingw-w64-x86-64 libffi-3.2.1-mingw-w64-x86-64
# WebAssembly 32-bit. # WebAssembly 32-bit.
targetToolchain.macos_x64-wasm32 = target-toolchain-2-osx-wasm targetToolchain.macos_x64-wasm32 = target-toolchain-3-macos-wasm
dependencies.macos_x64-wasm32 = \ dependencies.macos_x64-wasm32 = \
clang-llvm-5.0.0-darwin-macos \ clang-llvm-6.0.1-darwin-macos \
target-sysroot-2-wasm \ target-sysroot-2-wasm \
target-toolchain-2-osx-wasm target-toolchain-3-macos-wasm
targetToolchain.linux_x64-wasm32 = target-toolchain-1-linux-wasm targetToolchain.linux_x64-wasm32 = target-toolchain-2-linux-wasm
dependencies.linux_x64-wasm32 = \ dependencies.linux_x64-wasm32 = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
target-sysroot-2-wasm \ target-sysroot-2-wasm \
target-toolchain-1-linux-wasm target-toolchain-2-linux-wasm
targetToolchain.mingw_x64-wasm32 = target-toolchain-1-mingw-wasm targetToolchain.mingw_x64-wasm32 = target-toolchain-2-mingw-wasm
dependencies.mingw_x64-wasm32 = \ dependencies.mingw_x64-wasm32 = \
msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 \ msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1 \
target-sysroot-2-wasm \ target-sysroot-2-wasm \
target-toolchain-1-mingw-wasm target-toolchain-2-mingw-wasm
quadruple.wasm32 = wasm32 quadruple.wasm32 = wasm32-unknown-unknown
llvmLtoFlags.wasm32 = llvmLtoFlags.wasm32 =
targetSysRoot.wasm32 = target-sysroot-2-wasm targetSysRoot.wasm32 = target-sysroot-2-wasm
optFlags.wasm32 = -internalize -globaldce optFlags.wasm32 = -internalize -globaldce -mtriple=wasm32-unknown-unknown-wasm
optNooptFlags.wasm32 = -O1 optNooptFlags.wasm32 = -O1
optOptFlags.wasm32 = -O3 optOptFlags.wasm32 = -O3
optDebugFlags.wasm32 = -O0 optDebugFlags.wasm32 = -O0
llcFlags.wasm32 = llcFlags.wasm32 = -mtriple=wasm32-unknown-unknown-wasm
llcNooptFlags.wasm32 = -O1 llcNooptFlags.wasm32 = -O1
llcOptFlags.wasm32 = -O3 llcOptFlags.wasm32 = -O3
llcDebugFlags.wasm32 = -O0 llcDebugFlags.wasm32 = -O0
# The stack size is in bytes. # TODO: make explicit list of external symbols
s2wasmFlags.wasm32 = --allocate-stack 1048576 --import-memory lld.wasm32 = --allow-undefined --no-entry --global-base=0 --no-threads
+3 -3
View File
@@ -25,18 +25,18 @@ boardSpecificClangFlags.zephyr_stm32f4_disco = -mabi=aapcs -mthumb -mcpu=cortex-
targetToolchain.linux_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-linux/arm-none-eabi targetToolchain.linux_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-linux/arm-none-eabi
dependencies.linux_x64-zephyr_stm32f4_disco = \ dependencies.linux_x64-zephyr_stm32f4_disco = \
clang-llvm-5.0.0-linux-x86-64 \ clang-llvm-6.0.1-linux-x86-64 \
gcc-arm-none-eabi-7-2017-q4-major-linux \ gcc-arm-none-eabi-7-2017-q4-major-linux \
target-sysroot-2-wasm target-sysroot-2-wasm
targetToolchain.macos_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-mac/arm-none-eabi targetToolchain.macos_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-mac/arm-none-eabi
dependencies.macos_x64-zephyr_stm32f4_disco = \ dependencies.macos_x64-zephyr_stm32f4_disco = \
gcc-arm-none-eabi-7-2017-q4-major-mac \ gcc-arm-none-eabi-7-2017-q4-major-mac \
clang-llvm-5.0.0-darwin-macos \ clang-llvm-6.0.1-darwin-macos \
target-sysroot-2-wasm target-sysroot-2-wasm
targetToolchain.mingw_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-win32/arm-none-eabi targetToolchain.mingw_x64-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-win32/arm-none-eabi
dependencies.mingw_x64-zephyr_stm32f4_disco = \ dependencies.mingw_x64-zephyr_stm32f4_disco = \
msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 \ msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1 \
gcc-arm-none-eabi-7-2017-q4-major-win32 \ gcc-arm-none-eabi-7-2017-q4-major-win32 \
target-sysroot-2-wasm target-sysroot-2-wasm
+3 -1
View File
@@ -39,7 +39,9 @@ model {
} }
} }
binaries.withType(StaticLibraryBinarySpec) { binary -> binaries.withType(StaticLibraryBinarySpec) { binary ->
cppCompiler.args "--std=c++11", "-g", "-fPIC", "-I${llvmDir}/include" if (!project.parent.convention.plugins.platformInfo.isWindows())
cppCompiler.args "-fPIC"
cppCompiler.args "--std=c++11", "-g", "-I${llvmDir}/include"
if (isEnabled) { if (isEnabled) {
cppCompiler.args '-DLIBCLANGEXT_ENABLE=1' cppCompiler.args '-DLIBCLANGEXT_ENABLE=1'
} }
+1
View File
@@ -28,6 +28,7 @@ targetList.each { targetName ->
if (!isWindows()) if (!isWindows())
compilerArgs '-fPIC' compilerArgs '-fPIC'
compilerArgs '-I' + project.file('../common/src/hash/headers') compilerArgs '-I' + project.file('../common/src/hash/headers')
compilerArgs '-I' + file('src/main/cpp')
if (rootProject.hasProperty("${targetName}LibffiDir")) if (rootProject.hasProperty("${targetName}LibffiDir"))
compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include") compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include")
linkerArgs project.file("../common/build/$targetName/hash.bc").path linkerArgs project.file("../common/build/$targetName/hash.bc").path
+70 -111
View File
@@ -14,38 +14,30 @@
* limitations under the License. * limitations under the License.
*/ */
var instance; let instance;
var heap; let heap;
var memory; let global_arguments;
var global_arguments;
var globalBase = 0; // TODO: Is there any way to obtain global_base from JavaScript?
var konanStackTop;
function isBrowser() { function isBrowser() {
if (typeof window === 'undefined') { return typeof window !== 'undefined';
return false;
} else {
return true;
};
} }
var runtime; let runtime;
if (isBrowser()) { if (isBrowser()) {
runtime = { runtime = {
print: console.log, print: console.log,
stdout: '', stdout: '',
write: function (message) { write: function (message) {
this.stdout += message; this.stdout += message;
var lastNewlineIndex = this.stdout.lastIndexOf('\n'); const lastNewlineIndex = this.stdout.lastIndexOf('\n');
if (lastNewlineIndex == -1) return; if (lastNewlineIndex == -1) return;
this.print(this.stdout.substring(0, lastNewlineIndex)); this.print(this.stdout.substring(0, lastNewlineIndex));
this.stdout = this.stdout.substring(lastNewlineIndex + 1) this.stdout = this.stdout.substring(lastNewlineIndex + 1)
}, },
flush: function () { flush: function () {
this.print(this.stdout); this.print(this.stdout);
}, },
exit: function(status) { exit: function (status) {
throw Error("Kotlin process called exit (" + status + ")"); throw Error("Kotlin process called exit (" + status + ")");
} }
}; };
@@ -53,7 +45,8 @@ if (isBrowser()) {
runtime = { runtime = {
write: write, write: write,
print: print, print: print,
flush: function() {}, flush: function () {
},
exit: quit exit: quit
}; };
} }
@@ -73,131 +66,110 @@ function utf8decode(s) {
} }
function fromString(string, pointer) { function fromString(string, pointer) {
for (i = 0; i < string.length; i++) { for (let i = 0; i < string.length; i++) {
heap[pointer + i] = string.charCodeAt(i); heap[pointer + i] = string.charCodeAt(i);
} }
heap[pointer + string.length] = 0; heap[pointer + string.length] = 0;
} }
function toString(pointer) { function toString(pointer) {
var string = ''; let string = '';
for (var i = pointer; heap[i] != 0; i++) { for (let i = pointer; heap[i] != 0; i++) {
string += String.fromCharCode(heap[i]); string += String.fromCharCode(heap[i]);
} }
return string; return string;
} }
function toUTF16String(pointer, size) { function toUTF16String(pointer, size) {
var string = ''; let string = '';
for (var i = pointer; i < pointer + size; i+=2) { for (let i = pointer; i < pointer + size; i += 2) {
string += String.fromCharCode(heap[i] + heap[i+1]*256); string += String.fromCharCode(heap[i] + heap[i + 1] * 256);
} }
return string; return string;
} }
function twoIntsToDouble(upper, lower) { function twoIntsToDouble(upper, lower) {
var buffer = new ArrayBuffer(8); const buffer = new ArrayBuffer(8);
var ints = new Int32Array(buffer); const ints = new Int32Array(buffer);
var doubles = new Float64Array(buffer); const doubles = new Float64Array(buffer);
ints[1] = upper; ints[1] = upper;
ints[0] = lower; ints[0] = lower;
return doubles[0]; return doubles[0];
} }
function doubleToTwoInts(value) { function doubleToTwoInts(value) {
var buffer = new ArrayBuffer(8); const buffer = new ArrayBuffer(8);
var ints = new Int32Array(buffer); const ints = new Int32Array(buffer);
var doubles = new Float64Array(buffer); const doubles = new Float64Array(buffer);
doubles[0] = value; doubles[0] = value;
var twoInts = {upper: ints[1], lower: ints[0]}; return {upper: ints[1], lower: ints[0]}
return twoInts
} }
function int32ToHeap(value, pointer) { function int32ToHeap(value, pointer) {
heap[pointer] = value & 0xff; heap[pointer] = value & 0xff;
heap[pointer+1] = (value & 0xff00) >>> 8; heap[pointer + 1] = (value & 0xff00) >>> 8;
heap[pointer+2] = (value & 0xff0000) >>> 16; heap[pointer + 2] = (value & 0xff0000) >>> 16;
heap[pointer+3] = (value & 0xff000000) >>> 24; heap[pointer + 3] = (value & 0xff000000) >>> 24;
} }
function doubleToReturnSlot(value) { function doubleToReturnSlot(value) {
var twoInts = doubleToTwoInts(value); const twoInts = doubleToTwoInts(value);
instance.exports.ReturnSlot_setDouble(twoInts.upper, twoInts.lower); instance.exports.ReturnSlot_setDouble(twoInts.upper, twoInts.lower);
} }
function stackTop() { let konan_dependencies = {
// Read the value module's `__stack_pointer` is initialized with.
// It is the very first static in .data section.
var addr = (globalBase == 0 ? 4 : globalBase);
var fourBytes = heap.buffer.slice(addr, addr+4);
return new Uint32Array(fourBytes)[0];
}
var konan_dependencies = {
env: { env: {
abort: function() { abort: function () {
throw new Error("abort()"); throw new Error("abort()");
}, },
// TODO: Account for file and size. // TODO: Account for file and size.
fgets: function(str, size, file) { fgets: function (str, size, file) {
// TODO: readline can't read lines without a newline. // TODO: readline can't read lines without a newline.
// Browsers cant read from console at all. // Browsers cant read from console at all.
fromString(utf8encode(readline() + '\n'), str); fromString(utf8encode(readline() + '\n'), str);
return str; return str;
}, },
Konan_heap_upper: function() { Konan_notify_memory_grow: function() {
return memory.buffer.byteLength; heap = new Uint8Array(instance.exports.memory.buffer);
}, },
Konan_heap_lower: function() { Konan_abort: function (pointer) {
return konanStackTop;
},
Konan_heap_grow: function(pages) {
// The buffer is allocated anew on calls to grow(),
// so renew the heap array.
var oldLength = memory.grow(pages);
heap = new Uint8Array(konan_dependencies.env.memory.buffer);
return oldLength;
},
Konan_abort: function(pointer) {
throw new Error("Konan_abort(" + utf8decode(toString(pointer)) + ")"); throw new Error("Konan_abort(" + utf8decode(toString(pointer)) + ")");
}, },
Konan_exit: function(status) { Konan_exit: function (status) {
runtime.exit(status); runtime.exit(status);
}, },
Konan_js_arg_size: function(index) { Konan_js_arg_size: function (index) {
if (index >= global_arguments.length) return -1; if (index >= global_arguments.length) return -1;
return global_arguments[index].length + 1; // + 1 for trailing zero. return global_arguments[index].length + 1; // + 1 for trailing zero.
}, },
Konan_js_fetch_arg: function(index, ptr) { Konan_js_fetch_arg: function (index, ptr) {
var arg = utf8encode(global_arguments[index]); let arg = utf8encode(global_arguments[index]);
fromString(arg, ptr); fromString(arg, ptr);
}, },
Konan_date_now: function(pointer) { Konan_date_now: function (pointer) {
var now = Date.now(); let now = Date.now();
var high = Math.floor(now / 0xffffffff); let high = Math.floor(now / 0xffffffff);
var low = Math.floor(now % 0xffffffff); let low = Math.floor(now % 0xffffffff);
int32ToHeap(low, pointer); int32ToHeap(low, pointer);
int32ToHeap(high, pointer+4); int32ToHeap(high, pointer + 4);
}, },
stdin: 0, // This is for fgets(,,stdin) to resolve. It is ignored.
// TODO: Account for fd and size. // TODO: Account for fd and size.
write: function(fd, str, size) { write: function (fd, str, size) {
if (fd != 1 && fd != 2) throw ("write(" + fd + ", ...)"); if (fd != 1 && fd != 2) throw ("write(" + fd + ", ...)");
// TODO: There is no writeErr() in d8. // TODO: There is no writeErr() in d8.
// Approximate it with write() to stdout for now. // Approximate it with write() to stdout for now.
runtime.write(utf8decode(toString(str))); runtime.write(utf8decode(toString(str)));
}, }
memory: new WebAssembly.Memory({ initial: 256, maximum: 16384 })
} }
}; };
function linkJavaScriptLibraries() { function linkJavaScriptLibraries() {
konan.libraries.forEach ( function (library) { konan.libraries.forEach(function (library) {
for (var property in library) { for (const property in library) {
konan_dependencies.env[property] = library[property]; konan_dependencies.env[property] = library[property];
}; }
}); });
}; }
function invokeModule(inst, args) { function invokeModule(inst, args) {
if (args.length < 1) print_usage(); if (args.length < 1) print_usage();
@@ -205,11 +177,9 @@ function invokeModule(inst, args) {
instance = inst; instance = inst;
memory = konan_dependencies.env.memory heap = new Uint8Array(instance.exports.memory.buffer);
heap = new Uint8Array(konan_dependencies.env.memory.buffer);
konanStackTop = stackTop();
var exit_status = 0; let exit_status = 0;
try { try {
exit_status = instance.exports.Konan_js_main(args.length, isBrowser() ? 0 : 1); exit_status = instance.exports.Konan_js_main(args.length, isBrowser() ? 0 : 1);
@@ -223,48 +193,37 @@ function invokeModule(inst, args) {
return exit_status; return exit_status;
} }
function setupModule(module) {
module.env = {};
module.env.memoryBase = 0;
module.env.tablebase = 0;
linkJavaScriptLibraries();
}
// Instantiate module in Browser in a sequence of promises. // Instantiate module in Browser in a sequence of promises.
function instantiateAndRun(arraybuffer, args) { function instantiateAndRun(arraybuffer, args) {
WebAssembly.compile(arraybuffer) WebAssembly.compile(arraybuffer)
.then(function(module) { .then(module => {
setupModule(module); linkJavaScriptLibraries();
return WebAssembly.instantiate(module, konan_dependencies); return WebAssembly.instantiate(module, konan_dependencies);
}).then(function(instance) { }).then(instance => invokeModule(instance, args));
return invokeModule(instance, args);
});
} }
// Instantiate module in d8 synchronously. // Instantiate module in d8 synchronously.
function instantiateAndRunSync(arraybuffer, args) { function instantiateAndRunSync(arraybuffer, args) {
var module = WebAssembly.Module(arraybuffer) const module = new WebAssembly.Module(arraybuffer);
setupModule(module); linkJavaScriptLibraries();
var instance = WebAssembly.Instance(module, konan_dependencies); const instance = new WebAssembly.Instance(module, konan_dependencies);
return invokeModule(instance, args) return invokeModule(instance, args)
} }
konan.moduleEntry = function (args) { konan.moduleEntry = function (args) {
if (isBrowser()) { if (isBrowser()) {
if (!document.currentScript.hasAttribute("wasm")) { if (!document.currentScript.hasAttribute("wasm")) {
throw new Error('Could not find the wasm attribute pointing to the WebAssembly binary.') ; throw new Error('Could not find the wasm attribute pointing to the WebAssembly binary.');
} }
var filename = document.currentScript.getAttribute("wasm"); const filename = document.currentScript.getAttribute("wasm");
fetch(filename).then( function(response) { fetch(filename)
return response.arrayBuffer(); .then(response => response.arrayBuffer())
}).then(function(arraybuffer) { .then(arraybuffer => instantiateAndRun(arraybuffer, [filename]));
instantiateAndRun(arraybuffer, [filename]);
});
} else { } else {
// Invoke from d8. // Invoke from d8.
var arrayBuffer = readbuffer(args[0]); const arrayBuffer = readbuffer(args[0]);
var exitStatus = instantiateAndRunSync(arrayBuffer, args); const exitStatus = instantiateAndRunSync(arrayBuffer, args);
quit(exitStatus); quit(exitStatus);
} }
} };
+1 -1
View File
@@ -17,7 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Memory.h" #include "Memory.h"
#include "Natives.h" #include "Natives.h"
+1 -1
View File
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "Assert.h" #include "KAssert.h"
#include "Memory.h" #include "Memory.h"
#include "Natives.h" #include "Natives.h"
#include "KString.h" #include "KString.h"
+1 -1
View File
@@ -33,7 +33,7 @@
#endif #endif
#endif // OMIT_BACKTRACE #endif // OMIT_BACKTRACE
#include "Assert.h" #include "KAssert.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "ExecFormat.h" #include "ExecFormat.h"
#include "Memory.h" #include "Memory.h"
+2 -2
View File
@@ -31,7 +31,7 @@
#include <vector> #include <vector>
#include "Assert.h" #include "KAssert.h"
namespace { namespace {
@@ -148,7 +148,7 @@ extern "C" bool AddressToSymbol(const void* address, char* resultBuffer, size_t
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
namespace { namespace {
@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "KAssert.h"
#include "Porting.h" #include "Porting.h"
void RuntimeAssertFailed(const char* location, const char* message) { void RuntimeAssertFailed(const char* location, const char* message) {
+1 -1
View File
@@ -18,7 +18,7 @@
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
#include "Memory.h" #include "Memory.h"
#include "Natives.h" #include "Natives.h"
#include "Porting.h" #include "Porting.h"
+1 -1
View File
@@ -15,7 +15,7 @@
*/ */
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
#include "City.h" #include "City.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Memory.h" #include "Memory.h"
+2 -2
View File
@@ -20,7 +20,7 @@
#include <cstddef> // for offsetof #include <cstddef> // for offsetof
#include "Alloc.h" #include "Alloc.h"
#include "Assert.h" #include "KAssert.h"
#include "Atomic.h" #include "Atomic.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Memory.h" #include "Memory.h"
@@ -912,7 +912,7 @@ void ObjectContainer::Init(const TypeInfo* typeInfo) {
// header->refCount_ is zero initialized by AllocContainer(). // header->refCount_ is zero initialized by AllocContainer().
SetHeader(GetPlace(), typeInfo); SetHeader(GetPlace(), typeInfo);
MEMORY_LOG("object at %p\n", GetPlace()) MEMORY_LOG("object at %p\n", GetPlace())
OBJECT_ALLOC_EVENT(memoryState, type_info->instanceSize_, GetPlace()) OBJECT_ALLOC_EVENT(memoryState, typeInfo->instanceSize_, GetPlace())
} }
} }
+1 -1
View File
@@ -17,7 +17,7 @@
#ifndef RUNTIME_MEMORY_H #ifndef RUNTIME_MEMORY_H
#define RUNTIME_MEMORY_H #define RUNTIME_MEMORY_H
#include "Assert.h" #include "KAssert.h"
#include "Common.h" #include "Common.h"
#include "TypeInfo.h" #include "TypeInfo.h"
+1 -1
View File
@@ -20,7 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Memory.h" #include "Memory.h"
#include "Natives.h" #include "Natives.h"
+1 -1
View File
@@ -218,7 +218,7 @@ Class Kotlin_objc_lookUpClass(const char* name) {
#else // KONAN_OBJC_INTEROP #else // KONAN_OBJC_INTEROP
#include "Assert.h" #include "KAssert.h"
extern "C" { extern "C" {
+45 -35
View File
@@ -78,7 +78,12 @@ int32_t consoleReadUtf8(void* utf8, uint32_t maxSizeBytes) {
#ifdef KONAN_ZEPHYR #ifdef KONAN_ZEPHYR
return 0; return 0;
#else #else
char* result = ::fgets(reinterpret_cast<char*>(utf8), maxSizeBytes - 1, stdin); #ifdef KONAN_WASM
FILE* file = nullptr;
#else
FILE* file = stdin;
#endif
char* result = ::fgets(reinterpret_cast<char*>(utf8), maxSizeBytes - 1, file);
if (result == nullptr) return -1; if (result == nullptr) return -1;
int32_t length = ::strlen(result); int32_t length = ::strlen(result);
// fgets reads until EOF or newline so we need to remove linefeeds. // fgets reads until EOF or newline so we need to remove linefeeds.
@@ -275,44 +280,49 @@ uint64_t getTimeMicros() {
#if KONAN_WASM #if KONAN_WASM
// This one is an interface to query module.env.memory.buffer.byteLength namespace {
extern "C" unsigned long Konan_heap_upper();
extern "C" unsigned long Konan_heap_lower();
extern "C" unsigned long Konan_heap_grow(unsigned long);
#define MFAIL ((void*) ~(size_t)0) constexpr uint32_t MFAIL = ~(uint32_t)0;
#define WASM_PAGESIZE_EXPONENT 16 constexpr uint32_t WASM_PAGESIZE_EXPONENT = 16;
#define WASM_PAGESIZE (1u << WASM_PAGESIZE_EXPONENT) constexpr uint32_t WASM_PAGESIZE = 1u << WASM_PAGESIZE_EXPONENT;
#define WASM_PAGEMASK ((WASM_PAGESIZE-(size_t)1)) constexpr uint32_t WASM_PAGEMASK = WASM_PAGESIZE-1;
#define PAGE_ALIGN(value) ((value + WASM_PAGEMASK) & ~(WASM_PAGEMASK))
#define IN_PAGES(value) (value >> WASM_PAGESIZE_EXPONENT)
void* moreCore(int size) { uint32_t pageAlign(int32_t value) {
static int initialized = 0; return (value + WASM_PAGEMASK) & ~ (WASM_PAGEMASK);
static void* sbrk_top = MFAIL; }
static void* upperHeapLimit = MFAIL;
if (!initialized) { uint32_t inBytes(uint32_t pageCount) {
sbrk_top = (void*)PAGE_ALIGN(Konan_heap_lower()); return pageCount << WASM_PAGESIZE_EXPONENT;
initialized = 1; }
uint32_t inPages(uint32_t value) {
return value >> WASM_PAGESIZE_EXPONENT;
}
extern "C" void Konan_notify_memory_grow();
uint32_t memorySize() {
return __builtin_wasm_current_memory();
}
int32_t growMemory(uint32_t delta) {
int32_t oldLength = __builtin_wasm_grow_memory(delta);
Konan_notify_memory_grow();
return oldLength;
}
}
void* moreCore(int32_t delta) {
uint32_t top = inBytes(memorySize());
if (delta > 0) {
if (growMemory(inPages(pageAlign(delta))) == 0) {
return (void *) MFAIL;
} }
} else if (delta < 0) {
if (size == 0) { return (void *) MFAIL;
return sbrk_top; }
} else if (size < 0) { return (void *) top;
return MFAIL;
}
size = PAGE_ALIGN(size);
void* old_sbrk_top = sbrk_top;
long excess = (char*)sbrk_top + size - (char*)Konan_heap_upper();
if (excess > 0) {
Konan_heap_grow(IN_PAGES(PAGE_ALIGN(excess)));
}
sbrk_top = (char*)sbrk_top + size;
return old_sbrk_top;
} }
// dlmalloc wants to know the page size. // dlmalloc wants to know the page size.
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "Assert.h" #include "KAssert.h"
#include "Porting.h" #include "Porting.h"
#include "Common.h" #include "Common.h"
+1 -1
View File
@@ -18,7 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "Assert.h" #include "KAssert.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "Memory.h" #include "Memory.h"
#include "Natives.h" #include "Natives.h"
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "Assert.h" #include "KAssert.h"
#include "TypeInfo.h" #include "TypeInfo.h"
// If one shall use binary search when looking up methods and fields. // If one shall use binary search when looking up methods and fields.
+1 -1
View File
@@ -15,7 +15,7 @@
*/ */
#include <cstdint> #include <cstdint>
#include "Assert.h" #include "KAssert.h"
class SimpleMutex { class SimpleMutex {
private: private:
+1 -1
View File
@@ -28,7 +28,7 @@
#endif #endif
#include "Alloc.h" #include "Alloc.h"
#include "Assert.h" #include "KAssert.h"
#include "Memory.h" #include "Memory.h"
#include "Runtime.h" #include "Runtime.h"
#include "Types.h" #include "Types.h"
+7
View File
@@ -1,6 +1,13 @@
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#ifdef KONAN_WASM
#include "Common.h"
#endif
#ifdef KONAN_WASM
RUNTIME_USED
#endif
double fmod(double x, double y) double fmod(double x, double y)
{ {
union {double f; uint64_t i;} ux = {x}, uy = {y}; union {double f; uint64_t i;} ux = {x}, uy = {y};
+7
View File
@@ -1,6 +1,13 @@
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#ifdef KONAN_WASM
#include "Common.h"
#endif
#ifdef KONAN_WASM
RUNTIME_USED
#endif
float fmodf(float x, float y) float fmodf(float x, float y)
{ {
union {float f; uint32_t i;} ux = {x}, uy = {y}; union {float f; uint32_t i;} ux = {x}, uy = {y};
+1 -1
View File
@@ -2,7 +2,7 @@
setlocal setlocal
set DIR=. set DIR=.
if "%KONAN_DATA_DIR%"=="" (set "KONAN_DATA_DIR=%userprofile%\.konan") if "%KONAN_DATA_DIR%"=="" (set "KONAN_DATA_DIR=%userprofile%\.konan")
set "PATH=..\..\dist\bin;..\..\bin;%KONAN_DATA_DIR%\dependencies\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64\bin;%PATH%" set "PATH=..\..\dist\bin;..\..\bin;%KONAN_DATA_DIR%\dependencies\msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1\bin;%PATH%"
if "%TARGET%" == "" set TARGET=mingw if "%TARGET%" == "" set TARGET=mingw
rem Requires default mingw64 install path yet. rem Requires default mingw64 install path yet.
set MINGW=\msys64\mingw64 set MINGW=\msys64\mingw64
+2 -2
View File
@@ -51,7 +51,7 @@ konanArtifacts {
} }
target 'mingw', { target 'mingw', {
linkerOpts "$resFile -L${System.getenv("MINGW64_DIR")?:"c:/msys64/mingw64"}/lib -lSDL2 -mwindows" linkerOpts "$resFile -L${System.getenv("MINGW64_DIR")?:"c:/msys64/mingw64"}/lib -Wl,-Bstatic -lstdc++ -static -lSDL2 -limm32 -lole32 -loleaut32 -lversion -lwinmm -mwindows"
dependsOn 'windowsResources' dependsOn 'windowsResources'
inputs.file resFile inputs.file resFile
} }
@@ -62,7 +62,7 @@ task windowsResources (type: Exec) {
def rcFile = file('Tetris.rc') def rcFile = file('Tetris.rc')
def path = System.getenv("PATH") def path = System.getenv("PATH")
def windresDir = "$konanUserDir/dependencies/msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64/bin" def windresDir = "$konanUserDir/dependencies/msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1/bin"
commandLine "$windresDir/windres", rcFile, '-O', 'coff', '-o', resFile commandLine "$windresDir/windres", rcFile, '-O', 'coff', '-o', resFile
environment 'PATH', "$windresDir;$path" environment 'PATH', "$windresDir;$path"
@@ -78,12 +78,22 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
"-I$absoluteTargetSysRoot/usr/include/c++/4.9.x", "-I$absoluteTargetSysRoot/usr/include/c++/4.9.x",
"-I$absoluteTargetSysRoot/usr/include/c++/4.9.x/aarch64-linux-android") "-I$absoluteTargetSysRoot/usr/include/c++/4.9.x/aarch64-linux-android")
// By default wasm target forces `hidden` visibility which causes
// linkage problems.
KonanTarget.WASM32 -> KonanTarget.WASM32 ->
listOf("-target", targetArg!!, "-fno-rtti", "-fno-exceptions", listOf("-target", targetArg!!,
"-D_LIBCPP_ABI_VERSION=2", "-D_LIBCPP_NO_EXCEPTIONS=1", "-fno-rtti",
"-nostdinc", "-Xclang", "-nobuiltininc", "-Xclang", "-nostdsysteminc", "-fno-exceptions",
"-Xclang", "-isystem$absoluteTargetSysRoot/include/libcxx", "-Xclang", "-isystem$absoluteTargetSysRoot/lib/libcxxabi/include", "-fvisibility=default",
"-Xclang", "-isystem$absoluteTargetSysRoot/include/compat", "-Xclang", "-isystem$absoluteTargetSysRoot/include/libc") "-D_LIBCPP_ABI_VERSION=2",
"-D_LIBCPP_NO_EXCEPTIONS=1",
"-nostdinc",
"-Xclang", "-nobuiltininc",
"-Xclang", "-nostdsysteminc",
"-Xclang", "-isystem$absoluteTargetSysRoot/include/libcxx",
"-Xclang", "-isystem$absoluteTargetSysRoot/lib/libcxxabi/include",
"-Xclang", "-isystem$absoluteTargetSysRoot/include/compat",
"-Xclang", "-isystem$absoluteTargetSysRoot/include/libc")
is KonanTarget.ZEPHYR -> is KonanTarget.ZEPHYR ->
listOf("-target", targetArg!!, listOf("-target", targetArg!!,
@@ -142,7 +152,7 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
KonanTarget.WASM32 -> KonanTarget.WASM32 ->
listOf("-DKONAN_WASM=1", "-DKONAN_NO_FFI=1", "-DKONAN_NO_THREADS=1", "-DKONAN_NO_EXCEPTIONS=1", listOf("-DKONAN_WASM=1", "-DKONAN_NO_FFI=1", "-DKONAN_NO_THREADS=1", "-DKONAN_NO_EXCEPTIONS=1",
"-DKONAN_INTERNAL_DLMALLOC=1", "-DKONAN_INTERNAL_SNPRINTF=1", "-DKONAN_INTERNAL_DLMALLOC=1", "-DKONAN_INTERNAL_SNPRINTF=1",
"-DKONAN_INTERNAL_NOW=1", "-DKONAN_NO_MEMMEM", "-DKONAN_NO_CTORS_SECTION") "-DKONAN_INTERNAL_NOW=1", "-DKONAN_NO_MEMMEM", "-DKONAN_NO_CTORS_SECTION=1")
is KonanTarget.ZEPHYR -> is KonanTarget.ZEPHYR ->
listOf( "-DKONAN_ZEPHYR=1", "-DKONAN_NO_FFI=1", "-DKONAN_NO_THREADS=1", "-DKONAN_NO_EXCEPTIONS=1", listOf( "-DKONAN_ZEPHYR=1", "-DKONAN_NO_FFI=1", "-DKONAN_NO_THREADS=1", "-DKONAN_NO_EXCEPTIONS=1",
@@ -76,7 +76,6 @@ interface RaspberryPiConfigurables : LinuxBasedConfigurables
interface AndroidConfigurables : NonAppleConfigurables interface AndroidConfigurables : NonAppleConfigurables
interface WasmConfigurables : NonAppleConfigurables { interface WasmConfigurables : NonAppleConfigurables {
val s2wasmFlags get() = targetList("s2wasmFlags")
val llcFlags get() = targetList("llcFlags") val llcFlags get() = targetList("llcFlags")
val llcNooptFlags get() = targetList("llcNooptFlags") val llcNooptFlags get() = targetList("llcNooptFlags")
@@ -87,6 +86,8 @@ interface WasmConfigurables : NonAppleConfigurables {
val optNooptFlags get() = targetList("optNooptFlags") val optNooptFlags get() = targetList("optNooptFlags")
val optOptFlags get() = targetList("optOptFlags") val optOptFlags get() = targetList("optOptFlags")
val optDebugFlags get() = targetList("optDebugFlags") val optDebugFlags get() = targetList("optDebugFlags")
val lldFlags get() = targetList("lld")
} }
interface ZephyrConfigurables : NonAppleConfigurables { interface ZephyrConfigurables : NonAppleConfigurables {
@@ -44,8 +44,6 @@ abstract class LinkerFlags(val configurables: Configurables)
else -> error("Don't know libLTO location for this platform.") else -> error("Don't know libLTO location for this platform.")
} }
val libLTO = "$libLTODir/${System.mapLibraryName("LTO")}"
val targetLibffi = configurables.libffiDir?.let { listOf("${configurables.absoluteLibffiDir}/lib/libffi.a") } val targetLibffi = configurables.libffiDir?.let { listOf("${configurables.absoluteLibffiDir}/lib/libffi.a") }
?: emptyList() ?: emptyList()
@@ -145,7 +143,6 @@ open class MacOSBasedLinker(targetProperties: AppleConfigurables)
val dynamic = kind == LinkerOutputKind.DYNAMIC_LIBRARY val dynamic = kind == LinkerOutputKind.DYNAMIC_LIBRARY
return listOf(Command(linker).apply { return listOf(Command(linker).apply {
+"-demangle" +"-demangle"
+listOf("-object_path_lto", "temporary.o", "-lto_library", libLTO)
+listOf("-dynamic", "-arch", arch) +listOf("-dynamic", "-arch", arch)
+osVersionMinFlags +osVersionMinFlags
+listOf("-syslibroot", absoluteTargetSysRoot, "-o", executable) +listOf("-syslibroot", absoluteTargetSysRoot, "-o", executable)
@@ -250,11 +247,6 @@ open class LinuxBasedLinker(targetProperties: LinuxBasedConfigurables)
if (!isMips) +"--hash-style=gnu" // MIPS doesn't support hash-style=gnu if (!isMips) +"--hash-style=gnu" // MIPS doesn't support hash-style=gnu
+specificLibs +specificLibs
+listOf("-L$absoluteTargetSysRoot/../lib", "-L$absoluteTargetSysRoot/lib", "-L$absoluteTargetSysRoot/usr/lib") +listOf("-L$absoluteTargetSysRoot/../lib", "-L$absoluteTargetSysRoot/lib", "-L$absoluteTargetSysRoot/usr/lib")
if (optimize) {
+"-plugin"
+"$llvmLib/LLVMgold.so"
+pluginOptimizationFlags
}
if (optimize) +linkerOptimizationFlags if (optimize) +linkerOptimizationFlags
if (!debug) +linkerNoDebugFlags if (!debug) +linkerNoDebugFlags
if (dynamic) +linkerDynamicFlags if (dynamic) +linkerDynamicFlags
@@ -113,7 +113,7 @@ internal class KonanInteropRunner(project: Project, additionalJvmArgs: List<Stri
if (HostManager.host == KonanTarget.MINGW_X64) { if (HostManager.host == KonanTarget.MINGW_X64) {
//TODO: Oh-ho-ho fix it in more convinient way. //TODO: Oh-ho-ho fix it in more convinient way.
environment.put("PATH", DependencyProcessor.defaultDependenciesRoot.absolutePath + environment.put("PATH", DependencyProcessor.defaultDependenciesRoot.absolutePath +
"\\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64" + "\\msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1" +
"\\bin;${environment.get("PATH")}") "\\bin;${environment.get("PATH")}")
} }
} }