Disable inlining and loop unrolling in LTO without PGO profile
Such optimisations may significantly increase the binary size when
compiler heuristics are off. Disabling these helps cut down the
binary sizes with negligible decrease in performance, but allows us to
be more comfortable enabling LTO across various projects.
Test: m
Test: dex2oat, hwui, skia benchmark
Bug: 62839002
Change-Id: Id63e8dd295df2972f76ae4e29ee367080fff8429
diff --git a/cc/lto.go b/cc/lto.go
index 4757fc7..2ced124 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -87,6 +87,13 @@
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-emulated-tls")
}
flags.ArGoldPlugin = true
+
+ // If the module does not have a profile, be conservative and do not inline
+ // or unroll loops during LTO, in order to prevent significant size bloat.
+ if !ctx.isPgoCompile() {
+ flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-inline-threshold=0")
+ flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-unroll-threshold=0")
+ }
}
return flags
}