2011-07-07 08:48:09     Is there support for dynamic allocation on bare metal newlib libraries?

Document created by Aaronwu Employee on Oct 16, 2013
Version 1Show Document
  • View in full screen mode

2011-07-07 08:48:09     Is there support for dynamic allocation on bare metal newlib libraries?

Prasanth Rajagopal (INDIA)

Message: 102217   

 

Will "malloc();" work out of box for the bare metal toolchain?

 

The default script is:

 

.bss            :

  {

    *(.dynbss)

    *(.bss .bss.* .gnu.linkonce.b.*)

    *(COMMON)

    /* Align here to ensure that the .bss section occupies space up to

       _end.  Align after .bss to ensure correct alignment even if the

       .bss section disappears because there are no input sections.

       FIXME: Why do we need it? When there is no .bss section, we don't

       pad the .data section.  */

    . = ALIGN(. != 0 ? 32 / 8 : 1);

    __bss_end = .;

  } >MEM_L1_DATA_A

  . = ALIGN(32 / 8);

  . = ALIGN(32 / 8);

 

  __end = .; PROVIDE (_end = .);

  __stack_end = ORIGIN(MEM_L1_DATA_B) + LENGTH(MEM_L1_DATA_B);

 

I was reading some articles on newlib implementations of low level APIs called by malloc - just got me confused on how it works (in some cases they mentioned about __end as the base until the free space of stack..).  Ideally I would want it to work with two symbols in the script - such as for the stack management.

 

heap_start

 

heap_end

 

But I am not sure how the current implementation works..?

 

Thanks

QuoteReplyEditDelete

 

 

2011-07-07 11:50:04     Re: Is there support for dynamic allocation on bare metal newlib libraries?

Mike Frysinger (UNITED STATES)

Message: 102218   

 

i believe malloc() relies on just sbrk(), and sbrk() has to be provided by the end user.  you can see a simple implementation in the libgloss/bfin/syscalls.c file.  that probably would work on hardware too and not just the sim.

QuoteReplyEditDelete

 

 

2011-07-08 05:52:37     Re: Is there support for dynamic allocation on bare metal newlib libraries?

Prasanth Rajagopal (INDIA)

Message: 102257   

 

I just re-implemented the API based on that:

 

http://docs.blackfin.uclinux.org/doku.php?id=toolchain:bare_metal:newlib#malloc_on_newlib

 

Seems to work - but I would be happy if someone can validate the same.

QuoteReplyEditDelete

 

 

2011-07-08 14:03:06     Re: Is there support for dynamic allocation on bare metal newlib libraries?

Mike Frysinger (UNITED STATES)

Message: 102261   

 

why do you need to play with the errno variable ?

 

you dont need to cast the result of malloc()

 

i think the lds variables should be:

  extern char lds_hp_end[];

QuoteReplyEditDelete

 

 

2011-07-08 14:31:30     Re: Is there support for dynamic allocation on bare metal newlib libraries?

Prasanth Rajagopal (INDIA)

Message: 102262   

 

why do you need to play with the errno variable ?

 

>> That got carried from the embecosm. Application Note. I will remove that from the stubs.

 

you dont need to cast the result of malloc()

 

i think the lds variables should be:

  extern char lds_hp_end[];

 

>> Thanks, that was mistake.

Attachments

    Outcomes