EmbDev.net

Forum: ARM programming with GCC/GNU tools gnu/win-arm problem with sbrk and/or 'end' symbol


von Christian K. (chris-koerber)


Rate this post
useful
not useful
Hallo,

we are using GNUARM with the provided NewLib package for an Atmel ARM7
based board. So far we could last without malloc, but decided some days
ago that we would need dynamic memory in the future. And since then I'm
trying to make malloc run, without success, though.

malloc and _mallor_r both return 0. Allways.

sbrk and _sbrk_r both return -1. Allways.

I looked for sbrk at the newlib sources and found about 20 sbrk.c,
_sbrk.c,... etc. implementations. Even with those sorted out, which are
obviously related to other machines, there is no obvious candite for me.

To me, the most reasonable source of sbrk seems to be syscalls.c. Here,
sbrk refers to a linker defined symbol 'end' to determine the initinal
start of free momory after the data segments. And here could be the
problem. If I trace 'end', it points to the END of RAM, 0x00200000,
which is where, at least to my knowledge, the stack starts to grow.
Another symbol, '_end', is available, whose adress is actually the end
of the BSS segment.

Could this be related to the fact, that our linker script most certainly
comes from the WinARM package (AT91SAM7S256-ROM.ld, slightly modified by
M. Thomas)?
I'm uncertain, since the code looks right to me:

  .bss :
  {
    __bss_start = . ;
    _bss_start_ = . ;
    *(.bss)
    *(COMMON)
  }
  . = ALIGN(4);
  _bss_end_ = . ;
  _bss_end_ = . ;
  _end = .;
    . = ALIGN(4);
   .int_data :
   {
   *(.internal_ram_top)
   }> STACK

  PROVIDE (end = .);

I also grepped through the complete workspace (including startup code)
in order find any globally defined 'end' and/or assignments to 'end',
but couldn't find any.

Any suggestions about what I missed?

[Remark: I checked this thread
(http://en.mikrocontroller.net/topic/72860#new), which gave me a starter
(i.e. looking for a globally defined 'end'), but unfortunately was not
instructive enough to enable me to solve the problem on my own.]

regards,

Christian

von Christian K. (chris-koerber)


Rate this post
useful
not useful
I was wrong, the problem is definately related to the linker script.
It was just that I never had to look at a linker script before.

It seems that &end is identical to STACK which is the highest possible
adress.
Moving PROVIDE (end = .) before _bss_end_ = . made sbrk work.

Obviously this script works perfectly for nearly anybody, so I wonder
what is
wrong with my workspace?



>   .bss :
>   {
>     __bss_start = . ;
>     _bss_start_ = . ;
>     *(.bss)
>     *(COMMON)
>   }
>   . = ALIGN(4);
>   _bss_end_ = . ;
>   _bss_end_ = . ;
>   _end = .;
>     . = ALIGN(4);
>    .int_data :
>    {
>    *(.internal_ram_top)
>    }> STACK
>
>   PROVIDE (end = .);

best regards,

Christian

von Martin Thomas (Guest)


Rate this post
useful
not useful
The parts of the linker-script which you have copied into you message
looks like those which have been provided with some of my WinARM
examples. The postition of the "provide end" has been wrong as you have
already found out.

The examples have been updated. Please visit
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/index_at91.html
to download the updated versions.

Martin Thomas

von Christian K. (chris-koerber)


Rate this post
useful
not useful
Thanks a lot for the confirmation, Martin!

regards, Christian

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.