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

Author: Christian Koerber (chris-koerber)
Posted on:

Rate this post
0 useful
not useful

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_ = . ;
  . = ALIGN(4);
  _bss_end_ = . ;
  _bss_end_ = . ;
  _end = .;
    . = ALIGN(4);
   .int_data :
   }> 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.]



Author: Christian Koerber (chris-koerber)
Posted on:

Rate this post
0 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
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,


Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 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
to download the updated versions.

Martin Thomas

Author: Christian Koerber (chris-koerber)
Posted on:

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

regards, Christian


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.