_sbrk: undefined reference to `end' problem

Nick Clifton nickc@redhat.com
Wed May 28 14:00:00 GMT 2008


Hi Roberto,

> In my .ld file there isn't an `end' declaration. But if I put the following code at the end of .ld file, the compilation terminate correctly, but the application does not function correctly:
> 
> PROVIDE (end = .);
> 
> I don't know the `end' address to insert in the declaration. Can anybody help me?

As you guessed the "end" symbol is a special one that need to be 
provided by the linker script.  But what you didn't know is that the 
symbol needs to be placed at the lowest allocatable memory address not 
occupied by the program or its data.  (Try running "ld --verose" to see 
how this is done with the linker's built-in default script).  The 
_sbrk() function in libgloss/arm/syscalls.c uses this "end" symbol as 
the starting point for memory allocation.

Note: putting the "PROVIDE (end = .);" at the end of your linker script 
is incorrect because presumably you have also provided the location of 
the start of the stack, which is at the top of allocatable memory. 
"end" needs to be that the bottom of allocatable memory.

Cheers
   Nick




More information about the Newlib mailing list