Base option for executable space-optimizations #14317
mitchgrout
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A common pattern within embedded firmware projects is to use
-ffunction-sections
and-fdata-sections
to hoist each symbol into its own dedicated linker section, then use-Wl,--gc-sections
to 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-sections
should 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-sections
and-fdata-sections
as a global compiler argument, if supported by the compiler, and-Wl,--gc-sections
as 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_sanitize
existing, 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