
Peter Tyser ptyser@xes-inc.com wrote on 23/09/2009 14:17:51:
On Wed, 2009-09-23 at 13:51 +0200, Joakim Tjernlund wrote:
NULL is an absolute value and should not be relocated. After this correction code like: void weak_fun(void) __attribute__((weak)); printf("weak_fun:%p\n", weak_fun); will still print null after relocation.
Signed-off-by: Joakim Tjernlund Joakim.Tjernlund@transmode.se
I have only tested this on 83xx and on a somewhat older u-boot. The change is exactly the same on all PowerPC platforms though.
Hi Jocke, I made the same changes recently, but ran into an "issue" that prevented me from sending the change upstream. Some boards/arches have the bss at address 0 and later relocate it, unlike every other NULL pointer. If you don't fix up the bss address, the board will not function. If you run readelf on an 83xx u-boot image vs a 85xx u-boot image it should be more clear what's going on. I was doing my testing on the XPedite5370 fwiw.
Ouch, the horror continues :(
In any case, the change as is would break some other arches. Seems like the proper workaround would be to "fix" the 85xx (and other arches) link script to locate the bss similar to the 83xx boards.
Yes, something should be done. Does it work for you with a "fixed" linker script?
It might be nice to consolidate all the ppc relocate code into 1 function while we were at it.
Played around a little and this is what I got sofar, possibly WS damged and fixups untested:
From 5099be8f64a72080e89c325943b771932389c665 Mon Sep 17 00:00:00 2001
From: Joakim Tjernlund Joakim.Tjernlund@transmode.se Date: Tue, 22 Sep 2009 23:24:46 +0200 Subject: [PATCH] relocation: Use C-functions to do relocate the GOT & fixups.
--- cpu/mpc83xx/start.S | 29 ++++++++--------------------- lib_ppc/board.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/cpu/mpc83xx/start.S b/cpu/mpc83xx/start.S index 26e3106..868b070 100644 --- a/cpu/mpc83xx/start.S +++ b/cpu/mpc83xx/start.S @@ -950,35 +950,22 @@ in_ram: * Adjust got2 pointers, no need to check for 0, this code * already puts a few entries in the table. */ - li r0,__got2_entries@sectoff@l la r3,GOT(_GOT2_TABLE_) - lwz r11,GOT(_GOT2_TABLE_) - mtctr r0 - sub r11,r3,r11 - addi r3,r3,-4 -1: lwzu r0,4(r3) - add r0,r0,r11 - stw r0,0(r3) - bdnz 1b + li r4,__got2_entries@sectoff@l + lwz r5,GOT(_GOT2_TABLE_) + sub r5,r3,r5 + mr r30,r5 + bl __eabi_convert
#ifndef CONFIG_NAND_SPL /* * Now adjust the fixups and the pointers to the fixups * in case we need to move ourselves again. */ -2: li r0,__fixup_entries@sectoff@l lwz r3,GOT(_FIXUP_TABLE_) - cmpwi r0,0 - mtctr r0 - addi r3,r3,-4 - beq 4f -3: lwzu r4,4(r3) - lwzux r0,r4,r11 - add r0,r0,r11 - stw r10,0(r3) - stw r0,0(r4) - bdnz 3b -4: + li r4,__fixup_entries@sectoff@l + mr r5,r30 + bl __eabi_uconvert #endif
clear_bss: diff --git a/lib_ppc/board.c b/lib_ppc/board.c index 9e944fa..0afc7c3 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -148,6 +148,37 @@ static ulong mem_malloc_brk = 0; ************************************************************************ */
+/* Relocate the .got2 pointers. */ +void __eabi_convert(unsigned long *low, unsigned long len, + unsigned long addend) +{ + unsigned long val; + + for(--low; len; --len) { + val = *++low; + if (!val) + continue; + *low = val + addend; + } +} +/* Fixup any user initialized pointers (the compiler drops pointers to */ +/* each of the relocs that it does in the .fixup section). */ +void __eabi_uconvert(unsigned long *low, unsigned long len, + unsigned long addend) +{ + unsigned long val, *v2p, val2; + + for(--low; len; --len) { + val = *++low; + val += addend; + *low = val; + v2p = (unsigned long *)val; + val2 = *v2p; + val2 += addend; + *v2p = val2; + } +} + /* * The Malloc area is immediately below the monitor copy in DRAM */ -- 1.6.4.4