List Info

Thread: _sbrk: undefined reference to `end' problem




_sbrk: undefined reference to `end' problem
country flaguser name
Italy
2008-05-27 07:00:57
Hi all,
  I'm using arm-elf-gcc, compiled with gcc-4.2, and
newlib-1.16 to build an application for a LPC2136 board. In
the linking phase I obtain the following error:

C:arm-elfarm-elfliblibc.a(lib_a-syscalls.o): In function
`_sbrk':
undefined reference to `end'

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?

Thanks
Roberto


Re: _sbrk: undefined reference to `end' problem
user name
2008-05-27 08:33:33
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



Re: _sbrk: undefined reference to `end' problem
country flaguser name
United States
2008-05-27 14:07:09
On Tue, 2008-05-27 at 14:33 +0100, Nick Clifton wrote:
> 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...

It is not clear (to me) why start of stack should be encoded
within the
ELF file.


Re: _sbrk: undefined reference to `end' problem
user name
2008-05-28 03:01:07
Hi Jonathan,

>> 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...
> 
> It is not clear (to me) why start of stack should be
encoded within the
> ELF file.

It isn't.  It is encoded within the linker script used to
link together 
the object files that make up the executable.  Since the
linker script 
knows the layout of memory on the target board/simulator, it
makes sense 
that the linker script should be responsible for the
placement of the 
start of the stack.

Cheers
   Nick



Re: _sbrk: undefined reference to `end' problem
country flaguser name
United States
2008-05-28 09:28:46
Interesting. We chose to do this with a weak symbol from a
platform-specific runtime library, in order to allow the
application to
override the selection. Same idea, and the linker script
could probably
export a weak symbol if desired.



On Wed, 2008-05-28 at 09:01 +0100, Nick Clifton wrote:
> Hi Jonathan,
> 
> >> 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...
> > 
> > It is not clear (to me) why start of stack should
be encoded within the
> > ELF file.
> 
> It isn't.  It is encoded within the linker script used
to link together 
> the object files that make up the executable.  Since
the linker script 
> knows the layout of memory on the target
board/simulator, it makes sense 
> that the linker script should be responsible for the
placement of the 
> start of the stack.
> 
> Cheers
>    Nick
> 


[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )