DCE on linked binaries, to avoid huge size due to static cache. (#3715) (#3717)

This commit is contained in:
Nikolay Igotti
2019-12-24 15:58:22 +03:00
committed by GitHub
parent a931b5453a
commit 17c5647ea4
2 changed files with 15 additions and 7 deletions
@@ -90,10 +90,15 @@ internal class Linker(val context: Context) {
val executable: String
if (context.config.produce != CompilerOutputKind.FRAMEWORK) {
if (context.config.produce == CompilerOutputKind.DYNAMIC_CACHE && target.family.isAppleFamily)
additionalLinkerArgs = listOf("-install_name", context.config.outputFiles.mainFile)
else
additionalLinkerArgs = emptyList()
additionalLinkerArgs = if (target.family.isAppleFamily) {
when (context.config.produce) {
CompilerOutputKind.DYNAMIC_CACHE ->
listOf("-install_name", context.config.outputFiles.mainFile)
else -> listOf("-dead_strip")
}
} else {
emptyList()
}
executable = context.config.outputFiles.mainFileMangled
} else {
val framework = File(context.config.outputFile)
@@ -105,7 +110,7 @@ internal class Linker(val context: Context) {
Family.OSX -> "Versions/A/$dylibName"
else -> error(target)
}
additionalLinkerArgs = listOf("-install_name", "@rpath/${framework.name}/$dylibRelativePath")
additionalLinkerArgs = listOf("-dead_strip", "-install_name", "@rpath/${framework.name}/$dylibRelativePath")
val dylibPath = framework.child(dylibRelativePath)
dylibPath.parentFile.mkdirs()
executable = dylibPath.absolutePath
@@ -588,8 +588,11 @@ private fun ObjCExportBlockCodeGenerator.emitBlockToKotlinFunctionConverters() {
val functionClassesByArity =
context.ir.symbols.functionIrClassFactory.builtFunctionNClasses.associateBy { it.arity }
val count = (functionClassesByArity.keys.max() ?: -1) + 1
var count = ((functionClassesByArity.keys.max() ?: -1) + 1)
// TODO: ugly hack to avoid huge unneeded adaptors linked into every binary, needs rework.
if (context.config.produce.isCache) {
count = count.coerceAtMost(33)
}
val converters = (0 until count).map { arity ->
val functionClass = functionClassesByArity[arity]
if (functionClass != null) {