From bb5dcc9111c9d47564603660bb1b869597b8786d Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Fri, 2 Feb 2018 17:45:49 +0300 Subject: [PATCH] Removed hacks Just moving `-internalized` to the `opt` resolves the issue --- .../src/org/jetbrains/kotlin/backend/konan/Context.kt | 10 ---------- .../org/jetbrains/kotlin/backend/konan/LinkStage.kt | 9 +++++---- .../jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt | 4 +--- .../kotlin/backend/konan/llvm/RTTIGenerator.kt | 5 ----- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt index c6594ae5722..498e6d094e5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt @@ -385,15 +385,5 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) { val isDynamicLibrary: Boolean by lazy { config.configuration.get(KonanConfigKeys.PRODUCE) == CompilerOutputKind.DYNAMIC } - - // For wasm32 target we use `llvm-link -internalize` which is kinda broken. - // llvm-link links modules one by one and can't see usages - // of symbol in subsequent modules. So it will mangle such symbol if - // -internalize flag (which is needed for DCE) is provided - // That's the case for the stdlib and runtime modules - // The solution is to add such symbols to llvm.used array to preserve them from - // mangling. - fun shouldPreserveRuntimeSymbols(): Boolean = - config.targetManager.target == KonanTarget.WASM32 } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt index 74dbabec595..9280911b7c8 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt @@ -84,13 +84,14 @@ internal class LinkStage(val context: Context) { runTool(command) } + // TODO: pass different options llvm toolchain private fun bitcodeToWasm(bitcodeFiles: List): String { val combinedBc = temporary("combined", ".bc") - hostLlvmTool("llvm-link", bitcodeFiles + listOf("-o", combinedBc, "-internalize")) - val optimizedBc = temporary("optimized", ".bc") - hostLlvmTool("opt", listOf(combinedBc, "-o", optimizedBc, "-O2")) + hostLlvmTool("llvm-link", bitcodeFiles + listOf("-o", combinedBc)) + val internalizedBc = temporary("internalized", ".bc") + hostLlvmTool("opt", listOf(combinedBc, "-o", internalizedBc, "-internalize", "-O2")) val combinedS = temporary("combined", ".s") - targetTool("llc", optimizedBc, "-o", combinedS) + targetTool("llc", internalizedBc, "-o", combinedS) val s2wasmFlags = (platform.configurables as WasmConfigurables).s2wasmFlags.toTypedArray() val combinedWast = temporary( "combined", ".wast") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 3bb027165a7..274b1b40a91 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -657,9 +657,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map