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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2026-01-27 12:37:11 +10:30
parent 01c1264c5b
commit 744432dd63

View File

@@ -313,6 +313,10 @@ else
LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS)
endif
ifeq ($(HAVE_FUNCTION_SECTIONS),1)
LDLIBS += -Wl,--gc-sections
endif
# If we have the postgres client library we need to link against it as well
ifeq ($(HAVE_POSTGRES),1)
LDLIBS += $(POSTGRES_LDLIBS)