From ab4b955f172cc14870a3f91f995d07e36cea533a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Thu, 19 Dec 2013 21:11:04 +0100 Subject: [PATCH] cc2538: Sort link input sections by alignment to optimize size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normally, the linker does not sort files and sections matched by wildcards, so they are placed in the order in which they are seen during link. If numerous objects with different alignments are mixed, or if objects with unusually large alignments are present, this very likely leads to a lot of space being wasted because of accumulated alignment gaps. This commit forces input sections to be sorted by alignment (unless this is overridden by the linker script), which decreases the number and the size of alignment gaps, thus saving space. For a typical Contiki project, this change saves nearly 1 kiB, mainly in .bss. Note that this behavior is only enabled if the SMALL make variable is set to 1, because this makes more sense for a size optimization. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/Makefile.cc2538 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc2538/Makefile.cc2538 b/cpu/cc2538/Makefile.cc2538 index 103e177fc..537036034 100644 --- a/cpu/cc2538/Makefile.cc2538 +++ b/cpu/cc2538/Makefile.cc2538 @@ -21,7 +21,7 @@ OBJCOPY_FLAGS += -O binary --gap-fill 0xff ### Are we building with code size optimisations? ifeq ($(SMALL),1) CFLAGS += -ffunction-sections -fdata-sections - LDFLAGS += -Wl,--gc-sections + LDFLAGS += -Wl,--gc-sections,--sort-section=alignment endif ### If the user-specified a Node ID, pass a define