[U-Boot-Users] [PATCH] Fixed the _gp/_G_O_T_ confusion for good

$gp is loaded with _gp the GOT is updated starting from _G_O_T_+8 up to (but not including) __got_end __got_start is unused num_got_entries is unused and could be removed from ld scripts
To test: _gp =ALIGN(16)+4;
__got_start = .; . += 4; .got : { *(.got) } __got_end = .;
produces
0x00000000bfc1f564 _gp = (ALIGN (0x10) + 0x4) 0x00000000bfc1f560 __got_start = . 0x00000000bfc1f564 . = (. + 0x4)
.got 0x00000000bfc1f570 0x500 *(.got) .got 0x00000000bfc1f570 0x500 cpu/mips/start.o 0x00000000bfc1f570 _GLOBAL_OFFSET_TABLE_ 0x00000000bfc1fa70 __got_end = . 0x00000000bfc1fa70 . = .
The boards boots and the command line is working
Signed-off-by: Vlad Lungu vlad@comsys.ro --- cpu/mips/start.S | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/cpu/mips/start.S b/cpu/mips/start.S index e91e213..816c23a 100644 --- a/cpu/mips/start.S +++ b/cpu/mips/start.S @@ -234,11 +234,11 @@ reset: li t0, CONF_CM_UNCACHED mtc0 t0, CP0_CONFIG
- /* Initialize GOT pointer. + /* Initialize $gp. */ bal 1f nop - .word _GLOBAL_OFFSET_TABLE_ + .word _gp 1: move gp, ra lw t1, 0(ra) @@ -306,9 +306,9 @@ relocate_code: move t1, a2
/* - * Fix GOT pointer: + * Fix _gp: * - * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address + * New _gp = (old _gp - CFG_MONITOR_BASE) + Destination Address */ move t6, gp sub gp, CFG_MONITOR_BASE @@ -341,25 +341,28 @@ relocate_code: j t0 nop
+ .gpword _GLOBAL_OFFSET_TABLE_ .word uboot_end_data .word uboot_end - .word num_got_entries + .gpword __got_end
in_ram: /* Now we want to update GOT. */ - lw t3, -4(t0) /* t3 <-- num_got_entries */ + lw t3, -16(t0) /* t3 <-- _G_O_T_-_gp */ addi t4, gp, 8 /* Skipping first two entries. */ - li t2, 2 + add t4, t4, t3 /* Actual &(_G_O_T_[2]) */ + lw t3, -4(t0) /* t3 <-- __got_end-_gp */ + add t3,gp 1: lw t1, 0(t4) beqz t1, 2f add t1, t6 sw t1, 0(t4) 2: - addi t2, 1 - blt t2, t3, 1b - addi t4, 4 /* delay slot */ + addi t4, 4 + blt t4, t3, 1b + nop
/* Clear BSS. */

Sorry for late.
Vlad Lungu wrote:
$gp is loaded with _gp the GOT is updated starting from _G_O_T_+8 up to (but not including) __got_end __got_start is unused num_got_entries is unused and could be removed from ld scripts
I'll take this fix except for removing __got_start and num_got_entries. I know you want to make it work whether __got_start is out of alignment or not, but that is a little mess. We should fix num_got_entries part instead, and update GOT entries using _GLOBAL_OFFSET_TABLE_ and num_got_entries. This is easily understandable and straight forward :-)
I've submitted patches. Plase review.
thanks,
Shinya
participants (2)
-
Shinya Kuribayashi
-
Vlad Lungu