Removed hacks
Just moving `-internalized` to the `opt` resolves the issue
This commit is contained in:
committed by
Sergey Bogolepov
parent
8b351078e6
commit
bb5dcc9111
-10
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -84,13 +84,14 @@ internal class LinkStage(val context: Context) {
|
||||
runTool(command)
|
||||
}
|
||||
|
||||
// TODO: pass different options llvm toolchain
|
||||
private fun bitcodeToWasm(bitcodeFiles: List<BitcodeFile>): 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")
|
||||
|
||||
+1
-3
@@ -657,9 +657,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
||||
|
||||
val descriptor = declaration.descriptor
|
||||
|
||||
// Preserve symbol from deletion if needed
|
||||
if (descriptor.usedAnnotation
|
||||
|| (context.shouldPreserveRuntimeSymbols() && descriptor.isExportedForCppRuntime())) {
|
||||
if (descriptor.usedAnnotation) {
|
||||
context.llvm.usedFunctions += codegen.llvmFunction(descriptor)
|
||||
}
|
||||
|
||||
|
||||
-5
@@ -89,11 +89,6 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
val nameValue = annot.allValueArguments.values.single() as StringValue
|
||||
// TODO: use LLVMAddAlias?
|
||||
val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType), isExported = true)
|
||||
|
||||
if (context.shouldPreserveRuntimeSymbols()) {
|
||||
context.llvm.usedGlobals += global
|
||||
}
|
||||
|
||||
LLVMSetInitializer(global, typeInfoGlobal)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user