diff --git a/Interop/Indexer/build.gradle b/Interop/Indexer/build.gradle index 5f700d9f4a9..91f41dea278 100644 --- a/Interop/Indexer/build.gradle +++ b/Interop/Indexer/build.gradle @@ -22,6 +22,7 @@ apply plugin: 'kotlin' apply plugin: org.jetbrains.kotlin.NativeInteropPlugin apply plugin: 'c' +apply plugin: 'cpp' final Project libclangextProject = project(":libclangext") final String libclangextTask = libclangextProject.path + ":build" @@ -44,7 +45,7 @@ List ldflags = ["$llvmDir/$libclang", "-L$libclangextDir.absolutePath", if (libclangextIsEnabled) { assert(isMac()) - ldflags.addAll(['-Wl,--no-demangle', '-Wl,-search_paths_first', '-Wl,-headerpad_max_install_names']) + ldflags.addAll(['-Wl,--no-demangle', '-Wl,-search_paths_first', '-Wl,-headerpad_max_install_names', '-Wl,-U,_futimens']) List llvmLibs = [ "clangAST", "clangASTMatchers", "clangAnalysis", "clangBasic", "clangDriver", "clangEdit", @@ -54,7 +55,7 @@ if (libclangextIsEnabled) { "clangToolingCore", "clangTooling", "clangFormat", "LLVMTarget", "LLVMMC", "LLVMLinker", "LLVMTransformUtils", "LLVMBitWriter", "LLVMBitReader", "LLVMAnalysis", "LLVMProfileData", "LLVMCore", - "LLVMSupport" + "LLVMSupport", "LLVMBinaryFormat", "LLVMDemangle" ].collect { "$llvmDir/lib/lib${it}.a".toString() } ldflags.addAll(llvmLibs) @@ -67,6 +68,7 @@ model { clangstubs(NativeLibrarySpec) { sources { c.source.srcDir 'prebuilt/nativeInteropStubs/c' + cpp.source.srcDir 'prebuilt/nativeInteropStubs/cpp' } binaries.all { diff --git a/Interop/Indexer/prebuilt/nativeInteropStubs/cpp/disable-abi-checks.cpp b/Interop/Indexer/prebuilt/nativeInteropStubs/cpp/disable-abi-checks.cpp new file mode 100644 index 00000000000..89e4142b16d --- /dev/null +++ b/Interop/Indexer/prebuilt/nativeInteropStubs/cpp/disable-abi-checks.cpp @@ -0,0 +1,9 @@ +#ifdef __linux__ +namespace llvm { +/** + * http://lists.llvm.org/pipermail/llvm-dev/2017-January/109621.html + * We can't rebuild llvm, but we can define symbol missed in llvm build. + */ +int DisableABIBreakingChecks = 1; +} +#endif diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 4ffaab92768..c8c5a130433 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -99,13 +99,17 @@ kotlinNativeInterop { llvm { dependsOn ":llvmDebugInfoC:debugInfoStaticLibrary" defFile 'llvm.def' - compilerOpts "-fPIC", "-I$llvmDir/include", "-I${project(':llvmDebugInfoC').projectDir}/src/main/include" + if (!project.parent.convention.plugins.platformInfo.isWindows()) + compilerOpts "-fPIC" + compilerOpts "-I$llvmDir/include", "-I${project(':llvmDebugInfoC').projectDir}/src/main/include" linkerOpts "-L$llvmDir/lib", "-L${project(':llvmDebugInfoC').buildDir}/libs/debugInfo/static" } hash { // TODO: copy-pasted from ':common:compileHash' - compilerOpts '-fPIC' - linkerOpts '-fPIC' + if (!project.parent.convention.plugins.platformInfo.isWindows()) { + compilerOpts '-fPIC' + linkerOpts '-fPIC' + } linker 'clang++' linkOutputs ":common:${hostName}Hash" diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt index e0f802781e0..cb82228fd2c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt @@ -290,8 +290,8 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, private fun callRaw(llvmFunction: LLVMValueRef, args: List, lazyLandingpad: () -> LLVMBasicBlockRef?): LLVMValueRef { val rargs = args.toCValues() - if (LLVMIsAFunction(llvmFunction) != null /* the function declaration */ && - (LLVMGetFunctionAttr(llvmFunction) and LLVMNoUnwindAttribute) != 0) { + if (LLVMIsAFunction(llvmFunction) != null /* the function declaration */ && + isFunctionNoUnwind(llvmFunction)) { return LLVMBuildCall(builder, llvmFunction, rargs, args.size, "")!! } else { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt index fb3e605ebb4..21f94d890e5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt @@ -280,11 +280,25 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) { val functionType = getFunctionType(externalFunction) val function = LLVMAddFunction(llvmModule, name, functionType)!! - val attributes = LLVMGetFunctionAttr(externalFunction) - LLVMAddFunctionAttr(function, attributes) + + copyFunctionAttributes(externalFunction, function) + return function } + private fun copyFunctionAttributes(source: LLVMValueRef, destination: LLVMValueRef) { + // TODO: consider parameter attributes + val attributeIndex = LLVMAttributeFunctionIndex + val count = LLVMGetAttributeCountAtIndex(source, attributeIndex) + memScoped { + val attributes = allocArray(count) + LLVMGetAttributesAtIndex(source, attributeIndex, attributes) + (0 until count).forEach { + LLVMAddAttributeAtIndex(destination, attributeIndex, attributes[it]) + } + } + } + private fun importMemset() : LLVMValueRef { val parameterTypes = cValuesOf(int8TypePtr, int8Type, int32Type, int32Type, int1Type) val functionType = LLVMFunctionType(LLVMVoidType(), parameterTypes, 5, 0) @@ -306,7 +320,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) { private fun externalNounwindFunction(name: String, type: LLVMTypeRef, origin: LlvmSymbolOrigin): LLVMValueRef { val function = externalFunction(name, type, origin) - LLVMAddFunctionAttr(function, LLVMNoUnwindAttribute) + setFunctionNoUnwind(function) return function } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt index 6eba59b409d..44ed646cb20 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt @@ -281,6 +281,28 @@ fun parseBitcodeFile(path: String): LLVMModuleRef = memScoped { } } +private val nounwindAttrKindId: Int + get() = getAttributeKindId("nounwind") + +fun isFunctionNoUnwind(function: LLVMValueRef): Boolean { + + val attribute = LLVMGetEnumAttributeAtIndex(function, LLVMAttributeFunctionIndex, nounwindAttrKindId) + return attribute != null +} + +private fun getAttributeKindId(attributeName: String): Int { + val nounwindAttrKindId = LLVMGetEnumAttributeKindForName(attributeName, attributeName.length.signExtend()) + if (nounwindAttrKindId == 0) { + throw Error("Unable to find '$attributeName' attribute kind id") + } + return nounwindAttrKindId +} + +fun setFunctionNoUnwind(function: LLVMValueRef) { + val attribute = LLVMCreateEnumAttribute(LLVMGetTypeContext(function.type), nounwindAttrKindId, 0)!! + LLVMAddAttributeAtIndex(function, LLVMAttributeFunctionIndex, attribute) +} + internal fun String.mdString() = LLVMMDString(this, this.length)!! internal fun node(vararg it:LLVMValueRef) = LLVMMDNode(it.toList().toCValues(), it.size) diff --git a/backend.native/konan.properties b/backend.native/konan.properties index 9a1edc8169f..c19a3dbc24d 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -28,9 +28,9 @@ homeDependencyCache = .konan/cache llvmDebugOptFlags = -O0 # Mac OS X. -llvmVersion.osx = 3.9.0 -llvmHome.osx = clang-llvm-3.9.0-darwin-macos -targetToolchain.osx = clang-llvm-3.9.0-darwin-macos +llvmVersion.osx = 5.0.0 +llvmHome.osx = clang-llvm-5.0.0-darwin-macos +targetToolchain.osx = clang-llvm-5.0.0-darwin-macos arch.osx = x86_64 targetSysRoot.osx = target-sysroot-1-darwin-macos @@ -49,13 +49,13 @@ osVersionMin.osx = 10.11 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 + clang-llvm-5.0.0-darwin-macos # Apple iOS. -targetToolchain.osx-ios = clang-llvm-3.9.0-darwin-macos +targetToolchain.osx-ios = clang-llvm-5.0.0-darwin-macos dependencies.osx-ios = target-sysroot-1-darwin-macos \ libffi-3.2.1-2-darwin-ios \ - clang-llvm-3.9.0-darwin-macos \ + clang-llvm-5.0.0-darwin-macos \ target-sysroot-2-darwin-ios arch.ios = arm64 @@ -73,10 +73,10 @@ osVersionMinFlagClang.ios = -miphoneos-version-min osVersionMin.ios = 8.0 # Apple iOS simulator. -targetToolchain.osx-ios_sim = clang-llvm-3.9.0-darwin-macos +targetToolchain.osx-ios_sim = clang-llvm-5.0.0-darwin-macos dependencies.osx-ios_sim = target-sysroot-1-darwin-macos \ libffi-3.2.1-2-darwin-ios_sim \ - clang-llvm-3.9.0-darwin-macos \ + clang-llvm-5.0.0-darwin-macos \ target-sysroot-1-darwin-ios_sim arch.ios_sim = x86_64 @@ -94,8 +94,8 @@ osVersionMinFlagClang.ios_sim = -mios-simulator-version-min osVersionMin.ios_sim = 8.0 # Linux x86-64. -llvmVersion.linux = 3.9.0 -llvmHome.linux = clang-llvm-3.9.0-linux-x86-64 +llvmVersion.linux = 5.0.0 +llvmHome.linux = clang-llvm-5.0.0-linux-x86-64 gccToolchain.linux = target-gcc-toolchain-3-linux-x86-64 targetToolchain.linux = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu @@ -119,14 +119,14 @@ entrySelector.linux = --defsym main=Konan_main # targetSysRoot relative abiSpecificLibraries.linux = ../lib64 lib64 usr/lib64 dependencies.linux = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \ libffi-3.2.1-2-linux-x86-64 # Raspberry Pi targetToolchain.linux-raspberrypi = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu dependencies.linux-raspberrypi = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-gcc-toolchain-3-linux-x86-64 \ target-sysroot-1-raspberrypi \ libffi-3.2.1-2-linux-x86-64 \ @@ -155,7 +155,7 @@ abiSpecificLibraries.raspberrypi = \ # MIPS targetToolchain.linux-linux_mips32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu dependencies.linux-linux_mips32 = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-gcc-toolchain-2-linux-mips \ target-sysroot-2-mips \ libffi-3.2.1-2-linux-x86-64 \ @@ -179,7 +179,7 @@ abiSpecificLibraries.linux_mips32 = # MIPSel targetToolchain.linux-linux_mipsel32 = target-gcc-toolchain-2-linux-mips/x86_64-unknown-linux-gnu dependencies.linux-linux_mipsel32 = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-gcc-toolchain-2-linux-mips \ target-sysroot-2-mipsel \ libffi-3.2.1-2-linux-x86-64 \ @@ -204,13 +204,13 @@ abiSpecificLibraries.linux_mipsel32 = targetToolchain.osx-android_arm32 = target-toolchain-21-osx-android_arm32 # TODO: split dependencies to host-dependent and host-independent parts. dependencies.osx-android_arm32 = \ - clang-llvm-3.9.0-darwin-macos \ + clang-llvm-5.0.0-darwin-macos \ target-sysroot-21-android_arm32 \ target-toolchain-21-osx-android_arm32 \ libffi-3.2.1-2-android_arm32 targetToolchain.linux-android_arm32 = target-toolchain-21-linux-android_arm32 dependencies.linux-android_arm32 = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-sysroot-21-android_arm32 \ target-toolchain-21-linux-android_arm32 \ libffi-3.2.1-2-android_arm32 @@ -229,13 +229,13 @@ linkerKonanFlags.android_arm32 = -lm -latomic -lstdc++ -landroid targetToolchain.osx-android_arm64 = target-toolchain-21-osx-android_arm64 # TODO: split dependencies to host-dependent and host-independent parts. dependencies.osx-android_arm64 = \ - clang-llvm-3.9.0-darwin-macos \ + clang-llvm-5.0.0-darwin-macos \ target-sysroot-21-android_arm64 \ target-toolchain-21-osx-android_arm64 \ libffi-3.2.1-2-android_arm64 targetToolchain.linux-android_arm64 = target-toolchain-21-linux-android_arm64 dependencies.linux-android_arm64 = \ - clang-llvm-3.9.0-linux-x86-64 \ + clang-llvm-5.0.0-linux-x86-64 \ target-sysroot-21-android_arm64 \ target-toolchain-21-linux-android_arm64 \ libffi-3.2.1-2-android_arm64 @@ -249,34 +249,33 @@ linkerKonanFlags.android_arm64 = -lm -latomic -lstdc++ -landroid linkerDebugFlags.android_arm64 = -Wl,-S # Windows x86-64, based on mingw-w64. -llvmVersion.mingw = 3.9.1 -llvmHome.mingw = msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64 -targetToolchain.mingw = msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64 +llvmVersion.mingw = 5.0.0 +llvmHome.mingw = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 +targetToolchain.mingw = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 quadruple.mingw = x86_64-w64-mingw32 -targetSysRoot.mingw = msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64 +targetSysRoot.mingw = msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 libffiDir.mingw = libffi-3.2.1-mingw-w64-x86-64 llvmLtoFlags.mingw = llvmLtoOptFlags.mingw = -O3 -function-sections llvmLtoNooptFlags.mingw = -O1 linkerDebugFlags.mingw = -Wl,-S -linkerKonanFlags.mingw = -static-libgcc -static-libstdc++ \ - -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic +linkerKonanFlags.mingw =-static-libgcc -static-libstdc++ -Xclang -flto-visibility-public-std -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic linkerOptimizationFlags.mingw = -Wl,--gc-sections entrySelector.mingw = -Wl,--defsym,main=Konan_main dependencies.mingw = \ - msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64 \ + msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 \ libffi-3.2.1-mingw-w64-x86-64 # WebAssembly 32-bit. -targetToolchain.osx-wasm32 = target-toolchain-1-osx-wasm +targetToolchain.osx-wasm32 = target-toolchain-2-osx-wasm dependencies.osx-wasm32 = \ - clang-llvm-3.9.0-darwin-macos \ - target-sysroot-1-wasm \ - target-toolchain-1-osx-wasm + clang-llvm-5.0.0-darwin-macos \ + target-sysroot-2-wasm \ + target-toolchain-2-osx-wasm quadruple.wasm32 = wasm32 llvmLtoFlags.wasm32 = -targetSysRoot.wasm32 = target-sysroot-1-wasm +targetSysRoot.wasm32 = target-sysroot-2-wasm # The stack size is in bytes. s2wasmFlags.wasm32 = --allocate-stack 1048576 --import-memory diff --git a/backend.native/llvm.def b/backend.native/llvm.def index 9bc217cebd1..df03a81846a 100644 --- a/backend.native/llvm.def +++ b/backend.native/llvm.def @@ -3,7 +3,7 @@ headers = llvm-c/Core.h llvm-c/Target.h llvm-c/Analysis.h llvm-c/BitWriter.h \ headerFilter = llvm-c/* DebugInfoC.h -compilerOpts = -std=c99 -fPIC \ +compilerOpts = -std=c99 \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers \ -pedantic -Wno-long-long -Wcovered-switch-default -Wdelete-non-virtual-dtor \ -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS @@ -11,28 +11,36 @@ compilerOpts = -std=c99 -fPIC \ linker = clang++ -linkerOpts = -fPIC -fvisibility-inlines-hidden \ +linkerOpts = -fvisibility-inlines-hidden \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \ -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \ -std=c++11 \ -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ -ldebugInfo -lLLVMTarget -lLLVMMC -lLLVMLinker -lLLVMTransformUtils -lLLVMBitWriter \ - -lLLVMBitReader -lLLVMAnalysis -lLLVMProfileData -lLLVMCore -lLLVMSupport + -lLLVMBitReader -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC \ + -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle # ./llvm-config --libs analysis bitreader bitwriter core linker target -linkerOpts.osx = \ +linkerOpts.osx = -fPIC \ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \ - -lpthread -lz -lm -lcurses + -lpthread -lz -lm -lcurses -Wl,-U,_futimens -Wl,-U,_LLVMDumpType -linkerOpts.linux=\ +linkerOpts.linux= -fPIC \ -Wl,-z,noexecstack \ -lrt -ldl -lpthread -lz -lm linkerOpts.mingw = -lole32 -luuid -static-libgcc -static-libstdc++ \ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic +# It looks like mingw port compiled without LLVM_ENABLE_DUMP +#Note: ld on mingw process -Wl,-U,_LLVMDumpType use different from other platform +# way, using this option cause linkage error: +# ld: -r and -shared may not be used together +excludedFunctions.mingw = LLVMDumpType + + excludedFunctions = LLVMInitializeAllAsmParsers LLVMInitializeAllAsmPrinters LLVMInitializeAllDisassemblers \ LLVMInitializeAllTargetInfos LLVMInitializeAllTargetMCs LLVMInitializeAllTargets LLVMInitializeNativeTarget \ LLVMInitializeNativeAsmParser LLVMInitializeNativeAsmPrinter LLVMInitializeNativeDisassembler diff --git a/llvmDebugInfoC/build.gradle b/llvmDebugInfoC/build.gradle index e62964653b7..169ab45f366 100644 --- a/llvmDebugInfoC/build.gradle +++ b/llvmDebugInfoC/build.gradle @@ -21,8 +21,11 @@ model { components { debugInfo(NativeLibrarySpec) { sources.cpp.source.srcDirs "src/main/cpp" + binaries.withType(StaticLibraryBinarySpec) { binary -> - cppCompiler.args "--std=c++11", "-g", "-fPIC", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" + if (!project.parent.convention.plugins.platformInfo.isWindows()) + cppCompiler.args "-fPIC" + cppCompiler.args "--std=c++11", "-g", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport" } binaries.withType(SharedLibraryBinarySpec) { binary -> diff --git a/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp b/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp index b8fa84b9d4c..2273ea93650 100644 --- a/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp +++ b/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp @@ -29,7 +29,7 @@ */ namespace llvm { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, DIBuilderRef) +//DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, DIBuilderRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DICompileUnit, DICompileUnitRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIFile, DIFileRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBasicType, DIBasicTypeRef) @@ -45,7 +45,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DILocalVariable, DILocalVariableRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIExpression, DIExpressionRef) // from Module.cpp -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef) +//DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef) } /** @@ -68,7 +68,8 @@ DICompileUnitRef DICreateCompilationUnit(DIBuilderRef builder, unsigned int lang const char *file, const char* dir, const char * producer, int isOptimized, const char * flags, unsigned int rv) { - return llvm::wrap(llvm::unwrap(builder)->createCompileUnit(lang, file, dir, producer, isOptimized, flags, rv)); + llvm::DIBuilder *D = llvm::unwrap(builder); + return llvm::wrap(llvm::unwrap(builder)->createCompileUnit(lang, D->createFile(file, dir), producer, isOptimized, flags, rv)); } DIFileRef DICreateFile(DIBuilderRef builder, const char *filename, const char *directory) { @@ -76,7 +77,7 @@ DIFileRef DICreateFile(DIBuilderRef builder, const char *filename, const char *d } DIBasicTypeRef DICreateBasicType(DIBuilderRef builder, const char* name, uint64_t sizeInBits, uint64_t alignment, unsigned encoding) { - return llvm::wrap(llvm::unwrap(builder)->createBasicType(name, sizeInBits, alignment, encoding)); + return llvm::wrap(llvm::unwrap(builder)->createBasicType(name, sizeInBits, encoding)); } DIModuleRef DICreateModule(DIBuilderRef builder, DIScopeOpaqueRef scope, @@ -111,7 +112,7 @@ DICompositeTypeRef DICreateStructType(DIBuilderRef refBuilder, DICompositeTypeRef refPlace) { auto builder = llvm::unwrap(refBuilder); if ((flags & DI_FORWARD_DECLARAION) != 0) { - return llvm::wrap(builder->createStructType(llvm::unwrap(scope), name, NULL, 0, 0, 0, flags, NULL, NULL)); + return llvm::wrap(builder->createStructType(llvm::unwrap(scope), name, NULL, 0, 0, 0, (llvm::DINode::DIFlags)flags, NULL, NULL)); } std::vector typeElements; for(int i = 0; i < elementsCount; ++i) { @@ -121,7 +122,7 @@ DICompositeTypeRef DICreateStructType(DIBuilderRef refBuilder, auto composite = builder->createStructType(llvm::unwrap(scope), name, llvm::unwrap(file), lineNumber, - sizeInBits, alignInBits, flags, + sizeInBits, alignInBits, (llvm::DINode::DIFlags)flags, llvm::unwrap(derivedFrom), elementsArray); builder->replaceTemporary(llvm::TempDIType(llvm::unwrap(refPlace)), composite); @@ -158,7 +159,7 @@ DIDerivedTypeRef DICreateMemberType(DIBuilderRef refBuilder, sizeInBits, alignInBits, offsetInBits, - flags, + (llvm::DINode::DIFlags)flags, llvm::unwrap(type))); } @@ -270,8 +271,5 @@ int DISubprogramDescribesFunction(DISubprogramRef sp, LLVMValueRef fn) { return llvm::unwrap(sp)->describes(llvm::cast(llvm::unwrap(fn))); } -void DIScopeDump(DIScopeOpaqueRef scope) { - llvm::unwrap(scope)->dump(); -} } /* extern "C" */ diff --git a/llvmDebugInfoC/src/main/include/DebugInfoC.h b/llvmDebugInfoC/src/main/include/DebugInfoC.h index bd9086417f9..45248e205dc 100644 --- a/llvmDebugInfoC/src/main/include/DebugInfoC.h +++ b/llvmDebugInfoC/src/main/include/DebugInfoC.h @@ -20,7 +20,9 @@ # ifdef __cplusplus extern "C" { # endif -typedef struct DIBuilder *DIBuilderRef; + +typedef struct LLVMOpaqueDIBuilder *DIBuilderRef; +//typedef struct DIBuilder *DIBuilderRef; typedef struct DICompileUnit *DICompileUnitRef; typedef struct DIFile *DIFileRef; typedef struct DIBasicType *DIBasicTypeRef; @@ -103,7 +105,7 @@ const char* LLVMBuilderGetCurrentBbName(LLVMBuilderRef builder); const char *DIGetSubprogramLinkName(DISubprogramRef sp); LLVMValueRef LLVMBuilderGetCurrentFunction(LLVMBuilderRef builder); int DISubprogramDescribesFunction(DISubprogramRef sp, LLVMValueRef fn); -void DIScopeDump(DIScopeOpaqueRef scope); +//void DIScopeDump(DIScopeOpaqueRef scope); # ifdef __cplusplus } # endif diff --git a/runtime/build.gradle b/runtime/build.gradle index 7c913f66c25..228368e9b93 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -25,6 +25,8 @@ targetList.each { targetName -> dependsOn ":common:${targetName}Hash" dependsOn "${targetName}Launcher" target targetName + if (!isWindows()) + compilerArgs '-fPIC' compilerArgs '-I' + project.file('../common/src/hash/headers') if (rootProject.hasProperty("${targetName}LibffiDir")) compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include") diff --git a/runtime/src/main/cpp/Porting.cpp b/runtime/src/main/cpp/Porting.cpp index 797764e6df7..e6359ea948e 100644 --- a/runtime/src/main/cpp/Porting.cpp +++ b/runtime/src/main/cpp/Porting.cpp @@ -308,7 +308,7 @@ extern "C" { void _ZNKSt3__221__basic_string_commonILb1EE20__throw_length_errorEv(void) { Konan_abort("TODO: throw_length_error not implemented."); } - int _ZNSt3__212__next_primeEm(unsigned long n) { + int _ZNSt3__212__next_primeEj(unsigned long n) { static unsigned long primes[] = { 11UL, 101UL, diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt index 5efd60f5352..81e2a3b5592 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt @@ -54,7 +54,7 @@ class ClangTarget(val target: KonanTarget, konanProperties: KonanProperties) { KonanTarget.MINGW -> listOf("-target", targetArg!!, "--sysroot=$sysRoot", - "-DUSE_GCC_UNWIND=1", "-DUSE_PE_COFF_SYMBOLS=1", "-DKONAN_WINDOWS=1") + "-DUSE_GCC_UNWIND=1", "-DUSE_PE_COFF_SYMBOLS=1", "-DKONAN_WINDOWS=1", "-Xclang", "-flto-visibility-public-std") KonanTarget.MACBOOK -> listOf("--sysroot=$sysRoot", "-mmacosx-version-min=10.11", "-DKONAN_OSX=1", diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanToolRunner.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanToolRunner.kt index 4920c81cff6..34e0e1d6b5d 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanToolRunner.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanToolRunner.kt @@ -82,9 +82,10 @@ internal class KonanInteropRunner(project: Project) { init { if (project.host == "mingw") { + //TODO: Oh-ho-ho fix it in more convinient way. environment.put("PATH", DependencyProcessor.defaultDependenciesRoot.absolutePath + - "\\msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64" + - "\\bin;${System.getenv("PATH")}") + "\\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64" + + "\\bin;${environment.get("PATH")}") } } }