From: Yu Watanabe Date: Sat, 4 Jul 2026 16:32:27 +0000 (+0900) Subject: meson: add -ffunction-sections and -fdata-sections to compiler flags X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6aa24f1c8af3e4e4f7bf4f6f621693efb00f98a5;p=thirdparty%2Fsystemd.git meson: add -ffunction-sections and -fdata-sections to compiler flags Enable compiler section splitting for functions and data to allow the linker's `--gc-sections` optimization to accurately drop unused code. Note that in highly optimized production builds with Link-Time Optimization (LTO) enabled (such as `-Db_lto=true`), the compiler already performs intensive dead-code elimination, resulting in negligible binary size changes from this change. However, explicit section splitting provides clear benefits in other areas: 1. Significant size reduction for `.standalone` executables and libraries in non-LTO environments. 2. Crucially, it provides the necessary infrastructure for the linker to garbage-collect unused `dlopen` metadata notes implemented in subsequent commits, ensuring precise dependency tracking regardless of the LTO state. Below is a binary size comparison (unstripped) across different build types: - `build-debug`: `-Dbuildtype=debug` - `build-plain`: `-Dbuildtype=plain` (without LTO) - `build-plain-lto`: `-Dbuildtype=plain -Db_lto=true` Before: ``` -rwxr-xr-x 1 watanabe watanabe 6143952 Jul 10 03:10 build-debug/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 830224 Jul 10 03:10 build-debug/systemd-repart -rwxr-xr-x 1 watanabe watanabe 9107880 Jul 10 03:10 build-debug/systemd-repart.standalone -rwxr-xr-x 1 watanabe watanabe 3581856 Jul 10 03:11 build-plain-lto/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 515536 Jul 10 03:11 build-plain-lto/systemd-repart -rwxr-xr-x 1 watanabe watanabe 5017000 Jul 10 03:11 build-plain-lto/systemd-repart.standalone -rwxr-xr-x 1 watanabe watanabe 3352616 Jul 10 03:11 build-plain/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 515232 Jul 10 03:11 build-plain/systemd-repart -rwxr-xr-x 1 watanabe watanabe 5103176 Jul 10 03:11 build-plain/systemd-repart.standalone ``` After: ``` -rwxr-xr-x 1 watanabe watanabe 5424064 Jul 10 03:04 build-debug/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 850880 Jul 10 03:04 build-debug/systemd-repart -rwxr-xr-x 1 watanabe watanabe 7138496 Jul 10 03:04 build-debug/systemd-repart.standalone -rwxr-xr-x 1 watanabe watanabe 3581856 Jul 10 03:06 build-plain-lto/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 515536 Jul 10 03:06 build-plain-lto/systemd-repart -rwxr-xr-x 1 watanabe watanabe 5017000 Jul 10 03:06 build-plain-lto/systemd-repart.standalone -rwxr-xr-x 1 watanabe watanabe 2321048 Jul 10 03:06 build-plain/libsystemd.so.0.44.0 -rwxr-xr-x 1 watanabe watanabe 514056 Jul 10 03:06 build-plain/systemd-repart -rwxr-xr-x 1 watanabe watanabe 2716264 Jul 10 03:06 build-plain/systemd-repart.standalone ``` --- diff --git a/meson.build b/meson.build index f9c84767dee..b9de4656b70 100644 --- a/meson.build +++ b/meson.build @@ -431,7 +431,9 @@ possible_common_cc_flags = [ '-Wno-string-plus-int', # clang '-fdiagnostics-show-option', + '-fdata-sections', '-fexcess-precision=standard', + '-ffunction-sections', '-fno-common', '-fstack-protector', '-fstack-protector-strong',