Use -ffunction-sections and -fdata-sections This results in a greater size reduction as it can eliminate all unnecessary function and data symbols. On Linux it reduce the binary size from 2624088 to 2016216 bytes. Change-Id: Ie15ca7b87a4f8430ef5a0d443a2c0cec0badd915 Reviewed-on: https://gn-review.googlesource.com/2201 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 fe16882..3e1630a 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -258,7 +258,16 @@ if options.debug: cflags.extend(['-O0', '-g']) else: - cflags.extend(['-O3', '-DNDEBUG']) + cflags.append('-DNDEBUG') + cflags.append('-O3') + ldflags.append('-O3') + # Use -fdata-sections and -ffunction-sections to place each function + # or data item into its own section so --gc-sections can eliminate any + # unused functions and data items. + cflags.extend(['-fdata-sections', '-ffunction-sections']) + ldflags.extend(['-fdata-sections', '-ffunction-sections']) + ldflags.append('-Wl,-dead_strip' if is_mac else '-Wl,--gc-sections') + # Omit all symbol information from the output file. ldflags.append('-Wl,-S' if is_mac else '-Wl,-strip-all') cflags.extend([