Make LTO an option in gen.py Previously, LTO was enabled unconditionally for all release builds but this was causing issues and got reverted in https://gn-review.googlesource.com/2120, but LTO still makes sense for release builds where we control the compiler, so we make it an option which can be enabled as needed. Change-Id: I4650210a326aeeb00a44d853b8b2da0c90ef17a5 Reviewed-on: https://gn-review.googlesource.com/2200 Reviewed-by: Brett Wilson <brettw@chromium.org> Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/build/gen.py b/build/gen.py index 9dda914..fe16882 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -31,6 +31,8 @@ parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) parser.add_option('-d', '--debug', action='store_true', help='Do a debug build. Defaults to release build.') + parser.add_option('--use-lto', action='store_true', + help='Enable the use of LTO') parser.add_option('--no-sysroot', action='store_true', help='(Linux only) Do not build with the Debian sysroot.') parser.add_option('--no-last-commit-position', action='store_true', @@ -291,6 +293,10 @@ cflags.append(min_mac_version_flag) ldflags.append(min_mac_version_flag) + if options.use_lto: + cflags.extend(['-flto', '-fwhole-program-vtables']) + ldflags.extend(['-flto', '-fwhole-program-vtables']) + elif is_win: if not options.debug: cflags.extend(['/Ox', '/DNDEBUG', '/GL'])