Skip to content

Commit

Permalink
pw_toolchain/arm_clang: Reduce binary size
Browse files Browse the repository at this point in the history
Update size optimization flags for Clang toolchain built artifacts.

Bug: b/254541584
Docs: N/A
Change-Id: Ic4ad573709f687fc4ba052608256247cf2293726
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/169576
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Prabhu Karthikeyan Rajasekaran <prabhukr@google.com>
  • Loading branch information
Prabhuk authored and CQ Bot Account committed Nov 27, 2023
1 parent 9d2d05a commit afac8b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
28 changes: 27 additions & 1 deletion pw_build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,34 @@ config("optimize_size") {
ldflags = cflags
}

config("enable_clang_mlinliner") {
cflags = [
# Enable ML inliner.
"-mllvm",
"-enable-ml-inliner=release",
]
}

config("enable_clang_gvn_sink_hoist") {
cflags = [
# Enable GVN sink/hoist.
"-mllvm",
"-enable-gvn-sink=1",
"-mllvm",
"-enable-gvn-hoist=1",
]
}

config("optimize_size_clang") {
cflags = [ "-Oz" ]
ldflags = cflags
ldflags = [
# Identical Code Folding optimization
"-Wl,--icf=all",

# LLD does not recognize `Oz` which is a compiler front-end flag.
"-Wl,-O2",
]
ldflags += cflags
}

# Standard compiler flags to reduce output binary size.
Expand All @@ -77,6 +102,7 @@ config("reduced_size") {
"-fno-exceptions",
"-ffunction-sections",
"-fdata-sections",
"-fomit-frame-pointer",
]
cflags_cc = [ "-fno-rtti" ]

Expand Down
7 changes: 5 additions & 2 deletions pw_toolchain/arm_clang/toolchains.gni
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ pw_toolchain_arm_clang = {
name = "arm_clang_cortex_m0plus_size_optimized"
forward_variables_from(_arm_clang_toolchain, "*")
defaults = {
default_configs = pigweed_default_configs + _cortex_m0plus +
[ "$dir_pw_build:optimize_size_clang" ]
default_configs = pigweed_default_configs + _cortex_m0plus + [
"$dir_pw_build:optimize_size_clang",
"$dir_pw_build:enable_clang_mlinliner",
"$dir_pw_build:enable_clang_gvn_sink_hoist",
]
}
}
cortex_m3_debug = {
Expand Down

0 comments on commit afac8b2

Please sign in to comment.