Disable default malloc with arm-none-eabi on cortex m3 (bare metal)

Viewed 985

I want to provide my own or better no malloc function. So I want to make sure it's not linked at all.

I already pass -nostdlib and --specs=nano.specs to the linker.

When providing my own malloc function I get:
../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-m\libc_nano.a(lib_a-malloc.o): In function `malloc': malloc.c:(.text.malloc+0x0): multiple definition of `malloc'

I'm looking for a way to skip linking of the lib_a-malloc.o

As a clarification: It's more about having no malloc at all than about providing my own implementation. Providing my own implementation was just to check if there already is one or for debugging purpose.

1 Answers

Using the same name as a standard function's name is almost always a bad idea.

Even you, after some time not working on that project, will not remember that this malloc() you are reading in your code is not the malloc() that we all know and loved. Let aside anyone else.

So, for maintainability and readability, I suggest you name your function differently, plain example: my_malloc().

PS: You might want to read GCC - How to stop malloc being linked?

Related