Problem
with the machine lib(goplus/lib#19) use the esp32 target will got follow,so we need reduce the binary size
2025-09-16T08:14:33.7708327Z ld.lld: error: section 'text' will not fit in region 'iram_seg': overflowed by 13157 bytes
According to the https://clang.llvm.org/docs/CommandGuide/clang.html, there are several optimization levels available:
- -O0 Means "no optimization": this level compiles the fastest and generates the most debuggable code.
- -O1 Somewhere between -O0 and -O2.
- -O2 Moderate level of optimization which enables most optimizations.
- -O3 Like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster).
- -Ofast Enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards. This is deprecated in Clang 19 and
a warning is emitted that -O3 in combination with -ffast-math should be used instead if the request for non-standard math behavior is intended. There is no timeline yet for removal; the
aim is to discourage use of -Ofast due to the surprising behavior of an optimization flag changing the observable behavior of correct code.
- -Os Like -O2 with extra optimizations to reduce code size.
- -Oz Like -Os (and thus -O2), but reduces code size further.
- -Og Similar to -O1, but with slightly reduced optimization and better variable visibility. The same optimizations are run as at -O1, but the -fextend-variable-liveness flag is also
set, which tries to prevent optimizations from reducing the liveness of user variables, improving their availability when debugging.
- -O Equivalent to -O1.
- -O4 and higher: Currently equivalent to -O3
Proposal
For embedded targets where code size is critical, we should use -Oz optimization level instead of the current settings to maximize size reduction while maintaining good performance.
Problem
with the machine lib(goplus/lib#19) use the esp32 target will got follow,so we need reduce the binary size
According to the https://clang.llvm.org/docs/CommandGuide/clang.html, there are several optimization levels available:
a warning is emitted that -O3 in combination with -ffast-math should be used instead if the request for non-standard math behavior is intended. There is no timeline yet for removal; the
aim is to discourage use of -Ofast due to the surprising behavior of an optimization flag changing the observable behavior of correct code.
set, which tries to prevent optimizations from reducing the liveness of user variables, improving their availability when debugging.
Proposal
For embedded targets where code size is critical, we should use -Oz optimization level instead of the current settings to maximize size reduction while maintaining good performance.