[U-Boot] [PATCH 2/2] [NEXT] arm926ejs: reduce code size with -msingle-pic-base

Albert Aribaud albert.aribaud at free.fr
Wed Sep 22 15:57:52 CEST 2010


Add -msingle-pic-base to the relocation flags, and compute the pic base
in start.S twice and for all -- once before relocation to run board_init_f,
and once after relocation to run board_init_r and the rest of u-boot.
This further reduces code size by 2.5% compared to -fPIE alone.

Signed-off-by: Albert Aribaud <albert.aribaud at free.fr>
---
 arch/arm/cpu/arm926ejs/config.mk  |    5 ++++
 arch/arm/cpu/arm926ejs/start.S    |   40 ++++++++++++++++++++++++++++++++++--
 arch/arm/cpu/arm926ejs/u-boot.lds |    1 +
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/config.mk b/arch/arm/cpu/arm926ejs/config.mk
index f8ef90f..aa84706 100644
--- a/arch/arm/cpu/arm926ejs/config.mk
+++ b/arch/arm/cpu/arm926ejs/config.mk
@@ -23,6 +23,11 @@
 
 PLATFORM_RELFLAGS += -fno-common -ffixed-r8 -msoft-float
 
+ifndef CONFIG_SYS_ARM_WITHOUT_RELOC
+# needed for optimal relocation
+PLATFORM_RELFLAGS += -msingle-pic-base
+endif
+
 PLATFORM_CPPFLAGS += -march=armv5te
 # =========================================================================
 #
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 16ee972..739fa06 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,9 +198,23 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
+	/*
+	 * Set stack pointer in internal RAM
+	 */
 	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+
+	/*
+	 * Set pic base register to the current GOT position. At the
+	 * moment this is also our run-time position.
+	 * Set both r10 and r9 because either could be used as pic base
+	 * depending on whether stack checking is off or on.
+	 */
+	ldr	r10, _got_base
+	mov	r9, r10
+
+	/*
+	 * Call board_init_f, passing it 0 for bootflag
+	 */
 	ldr	r0,=0x00000000
 	bl	board_init_f
 
@@ -220,7 +234,9 @@ relocate_code:
 	mov	r6, r2	/* save addr of destination */
 	mov	r7, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
+	/*
+	 * Set up the stack
+	 */
 stack_setup:
 	mov	sp, r4
 
@@ -282,6 +298,18 @@ clbss_l:str	r2, [r0]		/* clear loop...		    */
 	bl red_LED_on
 #endif
 
+	/*
+	 * Set pic base register to the current GOT position. Since we are
+	 * now running from RAM, we need to offset it from its link-time to
+	 *  its run-time position.
+	 */
+	ldr	r9, relocate_got_base_r
+	sub	r9, pc, r9
+	ldr	r10, _got_base
+relocate_got_base_r:
+	add	r10, r9, r10
+	mov	r9, r10
+
 /*
  * We are done. Do not return, instead branch to second part of board
  * initialization, now running from RAM.
@@ -303,6 +331,12 @@ _nand_boot: .word nand_boot
 	mov	pc, lr
 
 _board_init_r: .word board_init_r
+
+_got_base:
+	.word __got_base
+_relocate_got_base_r:
+	.word relocate_got_base_r
+
 #endif
 
 #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
diff --git a/arch/arm/cpu/arm926ejs/u-boot.lds b/arch/arm/cpu/arm926ejs/u-boot.lds
index 02eb8ca..b6e21f2 100644
--- a/arch/arm/cpu/arm926ejs/u-boot.lds
+++ b/arch/arm/cpu/arm926ejs/u-boot.lds
@@ -53,6 +53,7 @@ SECTIONS
 
 	__got_start = .;
 	. = ALIGN(4);
+	__got_base = .;
 	.got : { *(.got) }
 
 	__got_end = .;
-- 
1.7.0.4



More information about the U-Boot mailing list