Use --gc-sections during link
authorAndrew Thoelke <andrew.thoelke@arm.com>
Tue, 18 Mar 2014 07:13:52 +0000 (07:13 +0000)
committerAndrew Thoelke <andrew.thoelke@arm.com>
Wed, 26 Mar 2014 21:54:37 +0000 (21:54 +0000)
All common functions are being built into all binary images,
whether or not they are actually used. This change enables the
use of -ffunction-sections, -fdata-sections and --gc-sections
in the compiler and linker to remove unused code and data from
the images.

Change-Id: Ia9f78c01054ac4fa15d145af38b88a0d6fb7d409

Makefile
bl1/bl1.ld.S
bl2/bl2.ld.S
bl31/bl31.ld.S
bl32/tsp/tsp.ld.S

index 9d02141aabf4d7f20b6e22471573a390eb1b20ee..f4b74fee91b17fdab5fa1b64ad5a18e20cb43aad 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -150,8 +150,10 @@ ASFLAGS                    +=      -nostdinc -ffreestanding -Wa,--fatal-warnings   \
 CFLAGS                 :=      -nostdinc -pedantic -ffreestanding -Wall        \
                                -Werror -mgeneral-regs-only -std=c99 -c -Os     \
                                -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
+CFLAGS                 +=      -ffunction-sections -fdata-sections
 
 LDFLAGS                        +=      --fatal-warnings -O1
+LDFLAGS                        +=      --gc-sections
 
 
 vpath %.ld.S bl1:bl2:bl31
index 012ff5823881152937008babd10220f4725ba0cd..81c544359d51056ddfc0ecd82efadbe7621bb163 100644 (file)
@@ -43,8 +43,8 @@ SECTIONS
 {
     ro : {
         __RO_START__ = .;
-        *bl1_entrypoint.o(.text)
-        *(.text)
+        *bl1_entrypoint.o(.text*)
+        *(.text*)
         *(.rodata*)
         *(.vectors)
         __RO_END__ = .;
@@ -57,7 +57,7 @@ SECTIONS
     . = NEXT(16);        /* Align LMA */
     .data : ALIGN(16) {  /* Align VMA */
         __DATA_RAM_START__ = .;
-        *(.data)
+        *(.data*)
         __DATA_RAM_END__ = .;
     } >RAM AT>ROM
 
@@ -73,7 +73,7 @@ SECTIONS
      */
     .bss : ALIGN(16) {
         __BSS_START__ = .;
-        *(.bss)
+        *(.bss*)
         *(COMMON)
         __BSS_END__ = .;
     } >RAM
index 09dec758f28ec805a10b62b16da5cedf97c88e70..edb676af21bc67a28488ad4faf5b16a2b7eb8527 100644 (file)
@@ -47,8 +47,8 @@ SECTIONS
 
     ro . : {
         __RO_START__ = .;
-        *bl2_entrypoint.o(.text)
-        *(.text)
+        *bl2_entrypoint.o(.text*)
+        *(.text*)
         *(.rodata*)
         *(.vectors)
         __RO_END_UNALIGNED__ = .;
@@ -63,7 +63,7 @@ SECTIONS
 
     .data . : {
         __DATA_START__ = .;
-        *(.data)
+        *(.data*)
         __DATA_END__ = .;
     } >RAM
 
@@ -79,7 +79,7 @@ SECTIONS
      */
     .bss : ALIGN(16) {
         __BSS_START__ = .;
-        *(SORT_BY_ALIGNMENT(.bss))
+        *(SORT_BY_ALIGNMENT(.bss*))
         *(COMMON)
         __BSS_END__ = .;
     } >RAM
index 844f1696747520967ff97b3e887efd8c3d2b6876..1b818f5ebf49fdee8be9a9cb58f79190d4ad1195 100644 (file)
@@ -48,14 +48,14 @@ SECTIONS
 
     ro . : {
         __RO_START__ = .;
-        *bl31_entrypoint.o(.text)
-        *(.text)
+        *bl31_entrypoint.o(.text*)
+        *(.text*)
         *(.rodata*)
 
-        /* Ensure 8-byte alignment for descriptors */
+        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
         . = ALIGN(8);
         __RT_SVC_DESCS_START__ = .;
-        *(rt_svc_descs)
+        KEEP(*(rt_svc_descs))
         __RT_SVC_DESCS_END__ = .;
 
         *(.vectors)
@@ -71,7 +71,7 @@ SECTIONS
 
     .data . : {
         __DATA_START__ = .;
-        *(.data)
+        *(.data*)
         __DATA_END__ = .;
     } >RAM
 
@@ -87,7 +87,7 @@ SECTIONS
      */
     .bss : ALIGN(16) {
         __BSS_START__ = .;
-        *(.bss)
+        *(.bss*)
         *(COMMON)
         __BSS_END__ = .;
     } >RAM
index 74b03ad5420035da70c393fc7fb69843f934f165..53bce7d5a04c19a279bd72b4d6f829235b0b39e5 100644 (file)
@@ -48,8 +48,8 @@ SECTIONS
 
     ro . : {
         __RO_START__ = .;
-        *tsp_entrypoint.o(.text)
-        *(.text)
+        *tsp_entrypoint.o(.text*)
+        *(.text*)
         *(.rodata*)
         *(.vectors)
         __RO_END_UNALIGNED__ = .;
@@ -64,7 +64,7 @@ SECTIONS
 
     .data . : {
         __DATA_START__ = .;
-        *(.data)
+        *(.data*)
         __DATA_END__ = .;
     } >RAM
 
@@ -80,7 +80,7 @@ SECTIONS
      */
     .bss : ALIGN(16) {
         __BSS_START__ = .;
-        *(SORT_BY_ALIGNMENT(.bss))
+        *(SORT_BY_ALIGNMENT(.bss*))
         *(COMMON)
         __BSS_END__ = .;
     } >RAM