Reference:
https://youtu.be/7QNtiH5wTAs?si=c8I_prA9k9Hasfdr
Problem
- Devices with limited storage
- Devices with limited bandwith
- Env impact
Parts of an executable
- Header
- Text
- Data (init. vs uninit)
- Read-only data
- symbol table
- Relocation info
- (ref https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking)
- Import table / Procedure linkage table
- Export table
- Exception handling info
- Debugging info
Consider
- cross platform?
- linking/symbol resolution handling
- PIC
- Endianness
- Architecture / extensibility
Tools
Coding part
- Object init.
- Member ordering
padding http://www.catb.org/esr/structure-packing/
alignment https://vsdmars.blogspot.com/2022/03/c-memory-allignment-wrap-up.html - Special member functions
- virtual functions
- templates
- passing functions around
- constexpr functions
Object init.
0(.zerofill) vs. other thing else; decrease size
Member ordering
Usually won't reduce the binary size due to compiler is able to optimize.
Special member functions
- inline default special functions
- inline empty special functions
- following the rule of zero(RoZ)
- with either virtual or non-virtual destructor
Follow the Rule-Of-Zero
templates
- minimal template code section; same as marco
- Exact/promote to the upper level, which the code is not generated
for every new type instance.
Compiler options
- -Os
- -flto
- -fdata-sections / -ffunction-sections -Wl, --gc-sections
- -Wl, --icf=all or -Wl, --icf==safe
- -Wl, -s and -Wl, --strip-all
- -Wl, --as-needed
- -mllvm -inline-threshold=<n>
- -fstack-protector
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fstack-protector - -finline-limit=n
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-limit - Identical Code Folding (ICF)
https://research.google/pubs/safe-icf-pointer-safe-and-unwinding-aware-identical-code-folding-in-gold
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.