[U-Boot] [Question] [ARM] global data array defined in board.c linkage problem : overlapping with relocation sections

Sun Eric ericsunplus at gmail.com
Tue Sep 11 09:06:49 CEST 2012


Hi all,

Recently I tried to bring up a new platform with the latest U-Boot code
(the git hash is e66443f). For recording some info before UART becomes
functional, I added a circular array in "arch/arm/lib/board.c", together
with some "printf" like function which simply write the debug string to the
array.

Things works fine until the code goes to "relocate_code()", the "copy_loop"
is finished but once the code goes to "fixloop", quite soon the code will
attempt to write to some invalid address, then the system will hang.

Further debugging shows that the root cause is that, the circular array I
added in board.c is linked to some address which in between
"__rel_dyn_start" and "__rel_dyn_end". Originally the area contains all
relocation section entries, which has the format " address_to_fix 0x17
address_to_fix 0x17 ....". Now for some reason the linker put the circular
array here, and write to this circular array will overwrite it with some
random data, thus later "address fix" algorithm will easily write to
invalid address.

On the other hand, this issue seems only happen to board.c. If I
experimentally add it to another file, say "net/bootp.c". The linkage
becomes correct, the array is linked to BSS section which is after
"__rel_dyn_end". I looked at the build log, and don't find a difference on
how "board.o" and "bootp.o" is linked to the final u-boot elf file. So I
can't understand why the final linkage result is different.

Can someone please help me out?

The array I added is as the following:
-----------------------------------------------------------
static uchar local_log_buf[LOCAL_BUF_SIZE] = {0};
static ushort local_log_buf_index = 0;

static void initlocalbuf(void) {...}
void writelocalbuf(char* fmt, ...) {...}
void dumplocalbuf(void) {...}
-----------------------------------------------------------

Regards,
Eric


More information about the U-Boot mailing list