@@ -69,6 +69,10 @@
*/
START_GOT
GOT_ENTRY(_GOT2_TABLE_)
+#if defined(__pic__) && __pic__ == 1
+ GOT_ENTRY(_GOT_TABLE_)
+ GOT_ENTRY(_GLOBAL_OFFSET_TABLE_)
+#endif
GOT_ENTRY(__bss_start)
GOT_ENTRY(_end)
@@ -296,7 +300,11 @@ in_flash:
/*------------------------------------------------------*/
GET_GOT /* initialize GOT access */
-
+#if defined(__pic__) && __pic__ == 1
+ /* Needed for upcoming -msingle-pic-base */
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r30
+#endif
/* r3: IMMR */
lis r3, CONFIG_SYS_IMMR@h
/* run low-level CPU init code (in Flash)*/
@@ -950,7 +958,26 @@ in_ram:
add r0,r0,r11
stw r0,0(r3)
2: bdnz 1b
-
+#if defined(__pic__) && __pic__ == 1
+ /*
+ * Relocation of *.got(-fpic)
+ */
+ lwz r4,GOT(_GLOBAL_OFFSET_TABLE_)
+ addi r4,r4,-4 /* don't write over blrl in GOT */
+ lwz r3,GOT(_GOT_TABLE_)
+ subf. r4,r3,r4 /* r4 - r3 */
+ ble 3f
+ srwi r4,r4,2 /* r4/4 */
+ mtctr r4
+ addi r3,r3,-4
+1: lwzu r0,4(r3)
+ cmpwi r0,0
+ beq- 2f
+ add r0,r0,r11
+ stw r0,0(r3)
+2: bdnz 1b
+3:
+#endif
#ifndef CONFIG_NAND_SPL
/*
* Now adjust the fixups and the pointers to the fixups
@@ -67,6 +67,7 @@ SECTIONS
PROVIDE (erotext = .);
.reloc :
{
+ _GOT_TABLE_ = .;
*(.got)
_GOT2_TABLE_ = .;
*(.got2)
@@ -38,6 +38,8 @@ SECTIONS
.data : {
*(.data*)
*(.sdata*)
+ _GOT_TABLE_ = .;
+ *(.got)
_GOT2_TABLE_ = .;
*(.got2)
__got2_entries = (. - _GOT2_TABLE_) >> 2;
@@ -38,6 +38,8 @@ SECTIONS
.data : {
*(.data*)
*(.sdata*)
+ _GOT_TABLE_ = .;
+ *(.got)
_GOT2_TABLE_ = .;
*(.got2)
__got2_entries = (. - _GOT2_TABLE_) >> 2;
This add relocation of .got entries produced by -fpic. -fpic produces 2-3% smaller code and is faster. Unfortunately gcc promotes -fpic to -fPIC when -mrelocatable is used so one need a very small patch to gcc too(sent upstream). -fpic puts its GOT entries in .got section(s) and linker defines the symbol _GLOBAL_OFFSET_TABLE_ to point to the middle of this table. The entry at _GLOBAL_OFFSET_TABLE_-4 contains a blrl insn which is used to find the table's real address by branching to _GLOBAL_OFFSET_TABLE_-4. Here are some size examples for my board: size with -fPIC text data bss dec hex filename 224687 14400 24228 263315 40493 u-boot size with -mbss-plt -fPIC text data bss dec hex filename 222687 14400 24228 261315 3fcc3 u-boot size with -mbss-plt -fpic text data bss dec hex filename 225179 6580 24228 255987 3e7f3 u-boot size with -mbss-plt -fpic -msingle-pic-base text data bss dec hex filename 222091 6580 24228 252899 3dbe3 u-boot Note: -msingle-pic-base is not supported upstarem yet. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> --- v2: Better commit msg Fix linker script for two NAND boards. Only compile the new -fpic code if compiled with -fpic to reduce size. arch/powerpc/cpu/mpc83xx/start.S | 31 +++++++++++++++++++++- arch/powerpc/cpu/mpc83xx/u-boot.lds | 1 + nand_spl/board/freescale/mpc8313erdb/u-boot.lds | 2 + nand_spl/board/freescale/mpc8315erdb/u-boot.lds | 2 + 4 files changed, 34 insertions(+), 2 deletions(-)