Add "Optimize_for_size" build property
Projects with this property will be aggresively optimized for size. This
is useful for large binaries that are rarely executed and performance
insensitive (e.g. debugging tools, deprecated libraries).
This changeset reduces total system native binary size by 1.1%.
Test: presubmit
Bug: 342090838
Change-Id: I46a1db0c44e2e7d482b14eca1299f8ad48661d2d
diff --git a/cc/compiler.go b/cc/compiler.go
index 34d98c0..d13cd95 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -693,6 +693,10 @@
flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
}
+ if ctx.optimizeForSize() {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-Oz")
+ }
+
// Exclude directories from manual binder interface allowed list.
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {