Forum: ARM programming with GCC/GNU tools Problem with malloc (WinARM, GCC 4.0.2)

Author: Vyachwslav Krutov (doomer)
Posted on:

Rate this post
0 useful
not useful
I can't build the program with memory allocation functions thats work

I definded _sbrk() and _sbrk_functions, but malloc returns zero-pointer,
or getting stick in after second call of _sbrk_r().

CPU - LPC2214
i tried to compile syscalls.c in pure arm mode and in thumb-interwork,
but result is same

----------------syscalls.c cut------------------------------------

 extern char _end;

 caddr_t _sbrk(int incr)
     static unsigned char *heap_end =0;
     unsigned char *prev_heap_end=0;

     if( heap_end == 0 ) heap_end = (caddr_t)&_end;

     prev_heap_end = heap_end;
     heap_end += incr;
     return(caddr_t) prev_heap_end;

void *_sbrk_r(struct _reent* reent, ptrdiff_t incr)
  return _sbrk(incr);
Whats version of libc should i use ?

..\arm-elf\lib\interwork\libc.a           // the program get stack in
                                          // second _sbrk_r call

..\arm-elf\lib\thumb\interwork\libc.a     // malloc always return zero


Does anybody has a working code for memory functions ?

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 useful
not useful
Vyachwslav Krutov wrote:

> [...]
> Does anybody has a working code for memory functions ?

There is working code for sbrk in the newlib-lpc, source comes with
WinARM  in utils/newlib_lpc_src/. In other examples sbrk is implemented
in the file syscalls.c (basicly code from newlib-lpc or the
newlib-default-code or from Keil-Examples - it my differ a little bit).
Also check if end is provided correctly in the linker-script.

Martin Thomas


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.