Discussion:
Freeing __malloc_av and impure_data
Aras Vaichas
2010-11-26 04:42:06 UTC
Permalink
Hi, I'm building a binary for a non-Linux embedded AVR32 application
and I'm getting close to my 16K of SRAM limit.

Looking at my elf file, I see that impure_data uses 1K of memory.

00000044 l O .data 00000400 impure_data

I understand that it is somehow used for rentrancy in newlib, but
AFAIK I don't need it.

Is there a way to reduce this, or remove it completely?

There is also a whole load of malloc related data as well:

00000444 g O .data 00000408 __malloc_av_

Can I free that up as well?

I use very little of newlib, and I've even replaced the stdio library
with my own to reduce the overall size and footprint. It would be
great if I could also remove or reduce these two symbols.

Aras
Corinna Vinschen
2010-11-26 10:40:28 UTC
Permalink
Post by Aras Vaichas
Hi, I'm building a binary for a non-Linux embedded AVR32 application
and I'm getting close to my 16K of SRAM limit.
Looking at my elf file, I see that impure_data uses 1K of memory.
00000044 l O .data 00000400 impure_data
I understand that it is somehow used for rentrancy in newlib, but
AFAIK I don't need it.
Is there a way to reduce this, or remove it completely?
You can't just remove it since it's used for more than just reentrency.
But you can shrink it for small targets. The --enable-newlib-reent-small
configure option will do that for you.
Post by Aras Vaichas
00000444 g O .data 00000408 __malloc_av_
Can I free that up as well?
I use very little of newlib, and I've even replaced the stdio library
with my own to reduce the overall size and footprint. It would be
great if I could also remove or reduce these two symbols.
You can get rid of it by overriding newlib's malloc with your own
malloc. Just define MALLOC_PROVIDED so the default malloc functionality
will not be built into newlib. Alternatively, make sure not to use
functions which potentially allocate space dynamically. printf is a
good candidate.


Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
Aras Vaichas
2010-11-26 11:00:04 UTC
Permalink
Post by Corinna Vinschen
Post by Aras Vaichas
Hi, I'm building a binary for a non-Linux embedded AVR32 application
and I'm getting close to my 16K of SRAM limit.
Looking at my elf file, I see that impure_data uses 1K of memory.
00000044 l     O .data   00000400 impure_data
I understand that it is somehow used for rentrancy in newlib, but
AFAIK I don't need it.
Is there a way to reduce this, or remove it completely?
You can't just remove it since it's used for more than just reentrency.
But you can shrink it for small targets.  The --enable-newlib-reent-small
configure option will do that for you.
Excellent. I ran the debugger today and saw that about 8 bytes in the
1K area were being used, but everything else remained at zero.
Is --enable-newlib-reent-small a newlib build configuration?
Sorry, excuse my ignorance but I've been using the newlib crosstools
supplied by Atmel for use with their AVR32Studio so I haven't yet
built newlib from scratch.
Post by Corinna Vinschen
Post by Aras Vaichas
00000444 g     O .data   00000408 __malloc_av_
Can I free that up as well?
You can get rid of it by overriding newlib's malloc with your own
malloc.  Just define MALLOC_PROVIDED so the default malloc functionality
will not be built into newlib.  Alternatively, make sure not to use
functions which potentially allocate space dynamically.  printf is a
good candidate.
Is MALLOC_PROVIDED intended for use in building newlib or for linking
against newlib?

Hmm, I'll have to take another look at which functions I use because
AFAIK I don't use anything which calls malloc.

Thanks!

Aras
Corinna Vinschen
2010-11-26 12:30:51 UTC
Permalink
Post by Aras Vaichas
Post by Corinna Vinschen
Post by Aras Vaichas
Hi, I'm building a binary for a non-Linux embedded AVR32 application
and I'm getting close to my 16K of SRAM limit.
Looking at my elf file, I see that impure_data uses 1K of memory.
00000044 l     O .data   00000400 impure_data
I understand that it is somehow used for rentrancy in newlib, but
AFAIK I don't need it.
Is there a way to reduce this, or remove it completely?
You can't just remove it since it's used for more than just reentrency.
But you can shrink it for small targets.  The --enable-newlib-reent-small
configure option will do that for you.
Excellent. I ran the debugger today and saw that about 8 bytes in the
1K area were being used, but everything else remained at zero.
Is --enable-newlib-reent-small a newlib build configuration?
Yes.
Post by Aras Vaichas
Post by Corinna Vinschen
You can get rid of it by overriding newlib's malloc with your own
malloc.  Just define MALLOC_PROVIDED so the default malloc functionality
will not be built into newlib.  Alternatively, make sure not to use
functions which potentially allocate space dynamically.  printf is a
good candidate.
Is MALLOC_PROVIDED intended for use in building newlib or for linking
against newlib?
It's for building newlib. It's usually set from within configure.host.


Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
Loading...