From d7a7e1cdb93ed38d54ba016b18f781e5d3b81f48 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 4 Nov 2025 12:45:50 +1030 Subject: [PATCH 1/2] Makefile: improve print-binary-sizes to be more meaningful. Users care about memory more than disk, and they care about programs they run more than our test programs and tools. Signed-off-by: Rusty Russell --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 32e95d48327b..715e926d281f 100644 --- a/Makefile +++ b/Makefile @@ -1107,6 +1107,7 @@ ccan-rune-coding.o: $(CCANDIR)/ccan/rune/coding.c @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) print-binary-sizes: $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) - @find $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) -printf '%p\t%s\n' - @echo 'Total program size: '`find $(ALL_PROGRAMS) -printf '%s\n' | awk '{TOTAL+= $$1} END {print TOTAL}'` - @echo 'Total tests size: '`find $(ALL_TEST_PROGRAMS) -printf '%s\n' | awk '{TOTAL+= $$1} END {print TOTAL}'` + @echo User programs: + @size -t $(PKGLIBEXEC_PROGRAMS) $(filter-out tools/reckless,$(BIN_PROGRAMS)) $(PLUGINS) + @echo All programs: + @size -t $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) | tail -n1 From 38635c06b625c7276963659099bd27370b4766f4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 4 Nov 2025 12:58:15 +1030 Subject: [PATCH 2/2] Build: add function sections. This allows further reduction in binary sizes. Size of all user before: text data bss dec hex filename 64277932 904968 317576 65500476 3e7753c (TOTALS) After: 52443036 729560 271720 53444316 32f7edc (TOTALS) Some are dramatic, such as lightning-cli not pulling in libbacktrace: 174454 2880 296 177630 2b5de cli/lightning-cli 56633 2608 232 59473 e851 cli/lightning-cli But most things get a 25% trim: 3972339 363568 21760 4357667 427e23 lightningd/lightningd 3300337 247768 21664 3569769 367869 lightningd/lightningd Changelog-Changed: Build: most binaries are now about 20% smaller. Signed-off-by: Rusty Russell --- Makefile | 4 ++-- configure | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 715e926d281f..5c93e6145457 100644 --- a/Makefile +++ b/Makefile @@ -290,9 +290,9 @@ ifeq ($(STATIC),1) # For MacOS, Jacob Rapoport changed this to: # -L/usr/local/lib -lsqlite3 -lz -Wl,-lm -lpthread -ldl $(COVFLAGS) # But that doesn't static link. -LDLIBS = -L$(CPATH) -Wl,-dn $(SQLITE3_LDLIBS) -Wl,-dy -lm -lpthread -ldl $(COVFLAGS) +LDLIBS = -L$(CPATH) -Wl,-dn $(SQLITE3_LDLIBS) -Wl,-dy -lm -lpthread -ldl $(COVFLAGS) -Wl,--gc-sections else -LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS) +LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS) -Wl,--gc-sections endif # If we have the postgres client library we need to link against it as well diff --git a/configure b/configure index f69dc1573a3b..243017b472db 100755 --- a/configure +++ b/configure @@ -46,8 +46,9 @@ usage_with_default() # Given DEBUGBUILD, what COPTFLAGS do we default to. default_coptflags() { + printf "%s" "-ffunction-sections" if [ "$1" = 0 ]; then - echo "-Og" + echo " -Og" fi }