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 <[email protected]> --- 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, 40 insertions(+), 6 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..904bd8d 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 link-time 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 @@ -234,9 +250,9 @@ stack_setup: #ifndef CONFIG_SKIP_RELOCATE_UBOOT copy_loop: - ldmia r0!, {r9-r10} /* copy from source address [r0] */ - stmia r6!, {r9-r10} /* copy to target address [r1] */ - cmp r0, r2 /* until source end addreee [r2] */ + ldmia r0!, {r11-r12} /* copy from source address [r0] */ + stmia r6!, {r11-r12} /* copy to target address [r6] */ + cmp r0, r2 /* until source end address [r2] */ ble copy_loop #ifndef CONFIG_PRELOADER @@ -259,6 +275,15 @@ fixloop: cmp r2, r3 bne fixloop #endif + + /* + * Fix pic base register as well + */ + sub r9, r9, r1 + add r9, r9, r0 + sub r10, r10, r1 + add r10, r10, r0 + #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */ clear_bss: @@ -305,6 +330,9 @@ _nand_boot: .word nand_boot _board_init_r: .word board_init_r #endif +_got_base: + .word __got_base + #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ /* * the actual reset code 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 _______________________________________________ U-Boot mailing list [email protected] http://lists.denx.de/mailman/listinfo/u-boot

