Use --gc-sections during link
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
diff --git a/Makefile b/Makefile
index 9d02141..f4b74fe 100644
--- a/Makefile
+++ b/Makefile
@@ -150,8 +150,10 @@
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
diff --git a/bl1/bl1.ld.S b/bl1/bl1.ld.S
index 012ff58..81c5443 100644
--- a/bl1/bl1.ld.S
+++ b/bl1/bl1.ld.S
@@ -43,8 +43,8 @@
{
ro : {
__RO_START__ = .;
- *bl1_entrypoint.o(.text)
- *(.text)
+ *bl1_entrypoint.o(.text*)
+ *(.text*)
*(.rodata*)
*(.vectors)
__RO_END__ = .;
@@ -57,7 +57,7 @@
. = NEXT(16); /* Align LMA */
.data : ALIGN(16) { /* Align VMA */
__DATA_RAM_START__ = .;
- *(.data)
+ *(.data*)
__DATA_RAM_END__ = .;
} >RAM AT>ROM
@@ -73,7 +73,7 @@
*/
.bss : ALIGN(16) {
__BSS_START__ = .;
- *(.bss)
+ *(.bss*)
*(COMMON)
__BSS_END__ = .;
} >RAM
diff --git a/bl2/bl2.ld.S b/bl2/bl2.ld.S
index 09dec75..edb676a 100644
--- a/bl2/bl2.ld.S
+++ b/bl2/bl2.ld.S
@@ -47,8 +47,8 @@
ro . : {
__RO_START__ = .;
- *bl2_entrypoint.o(.text)
- *(.text)
+ *bl2_entrypoint.o(.text*)
+ *(.text*)
*(.rodata*)
*(.vectors)
__RO_END_UNALIGNED__ = .;
@@ -63,7 +63,7 @@
.data . : {
__DATA_START__ = .;
- *(.data)
+ *(.data*)
__DATA_END__ = .;
} >RAM
@@ -79,7 +79,7 @@
*/
.bss : ALIGN(16) {
__BSS_START__ = .;
- *(SORT_BY_ALIGNMENT(.bss))
+ *(SORT_BY_ALIGNMENT(.bss*))
*(COMMON)
__BSS_END__ = .;
} >RAM
diff --git a/bl31/bl31.ld.S b/bl31/bl31.ld.S
index 844f169..1b818f5 100644
--- a/bl31/bl31.ld.S
+++ b/bl31/bl31.ld.S
@@ -48,14 +48,14 @@
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 @@
.data . : {
__DATA_START__ = .;
- *(.data)
+ *(.data*)
__DATA_END__ = .;
} >RAM
@@ -87,7 +87,7 @@
*/
.bss : ALIGN(16) {
__BSS_START__ = .;
- *(.bss)
+ *(.bss*)
*(COMMON)
__BSS_END__ = .;
} >RAM
diff --git a/bl32/tsp/tsp.ld.S b/bl32/tsp/tsp.ld.S
index 74b03ad..53bce7d 100644
--- a/bl32/tsp/tsp.ld.S
+++ b/bl32/tsp/tsp.ld.S
@@ -48,8 +48,8 @@
ro . : {
__RO_START__ = .;
- *tsp_entrypoint.o(.text)
- *(.text)
+ *tsp_entrypoint.o(.text*)
+ *(.text*)
*(.rodata*)
*(.vectors)
__RO_END_UNALIGNED__ = .;
@@ -64,7 +64,7 @@
.data . : {
__DATA_START__ = .;
- *(.data)
+ *(.data*)
__DATA_END__ = .;
} >RAM
@@ -80,7 +80,7 @@
*/
.bss : ALIGN(16) {
__BSS_START__ = .;
- *(SORT_BY_ALIGNMENT(.bss))
+ *(SORT_BY_ALIGNMENT(.bss*))
*(COMMON)
__BSS_END__ = .;
} >RAM