Base option for executable space-optimizations #14317
mitchgrout
started this conversation in
Ideas
Replies: 1 comment
-
|
FYI Rust enables function sections, data sections and gc sections by default for all targets that support it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
A common pattern within embedded firmware projects is to use
-ffunction-sectionsand-fdata-sectionsto hoist each symbol into its own dedicated linker section, then use-Wl,--gc-sectionsto inform the linker to discard any section without a reference[1]. This allows for the use of a particularly large, feature-rich library, without having to pay the space cost of keeping every function. Obviously, this only works if each library is compiled from source, as an already-compiled library cannot be stripped (AFAIK).The annoying part of this is, the
-Wl,--gc-sectionsshould only be applied to finalexecutable()objects. If applied to alibrary(), it's prone to strip out otherwise necessary symbols. Writing it in meson currently, you end up with the two arguments being quite far apart, e.g.I'd also argue that this config isn't really a project-specific thing; it's rather ubiquitous. As such, making it into a dedicated option feels like the meson way. This option would:
-ffunction-sectionsand-fdata-sectionsas a global compiler argument, if supported by the compiler, and-Wl,--gc-sectionsas a per-target argument, if the target is anexecutable()I'm not aware if this optimization exists for other languages like Rust, but with
b_sanitizeexisting, a C/C++ specific option does not seem totally unreasonable.[1] https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags#-ffunction-sections--fdata-sections----gc-sections
Beta Was this translation helpful? Give feedback.
All reactions