gnu/win-arm problem with sbrk and/or 'end' symbol

OP #1171590
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
OP #1171591
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

Reply

A question of your own? This thread is over 20 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.