Own malloc implementation

Asked by Martin Velek

Hello,

I am using the gcc version 4.8.3 20140228 with Newlib. For some reasons I would like to ommit the Newlib's malloc implementation and use mine. Currently, it is not possible to redefine the malloc,free,calloc,etc symbols because some functions from newlib call _malloc_r directly. I am unable to redefine the _malloc_r because it is not a weak symbol.

To solve it, I am using "scratch my left ear with right hand" solution by adding linker parameters
--wrap=_free_r
--wrap=_malloc_r
--wrap=_calloc_r
--wrap=_realloc_r

in my application

and syscall.c (in library) contains definition of __wrap_.... functions.

Is there any fancy solution to this? E.g. make _malloc_r weak, etc. The goal is to make it transparent to the application (no linker flags).

Thank You for any hints.

Martin

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

I think if you reimplement all _r functions and put then in an obj, linker
should get your symbol instead of the ones in newlib, no matter weak or not
2014-4-5 下午7:11于 "Martin Velek" <email address hidden>写道:

> New question #246548 on GCC ARM Embedded:
> https://answers.launchpad.net/gcc-arm-embedded/+question/246548
>
> Hello,
>
> I am using the gcc version 4.8.3 20140228 with Newlib. For some reasons I
> would like to ommit the Newlib's malloc implementation and use mine.
> Currently, it is not possible to redefine the malloc,free,calloc,etc
> symbols because some functions from newlib call _malloc_r directly. I am
> unable to redefine the _malloc_r because it is not a weak symbol.
>
> To solve it, I am using "scratch my left ear with right hand" solution by
> adding linker parameters
> --wrap=_free_r
> --wrap=_malloc_r
> --wrap=_calloc_r
> --wrap=_realloc_r
>
> in my application
>
> and syscall.c (in library) contains definition of __wrap_.... functions.
>
> Is there any fancy solution to this? E.g. make _malloc_r weak, etc. The
> goal is to make it transparent to the application (no linker flags).
>
> Thank You for any hints.
>
> Martin
>
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Revision history for this message
Martin Velek (martin-velek) said :
#2

There is another solution for experienced users, to recompile the Newlib with -DMALLOC_PROVIDED.

Can you help with this problem?

Provide an answer of your own, or ask Martin Velek for more information if necessary.

To post a message you must log in.