cgcclinkerarm

How to ensure malloc is not linked in the project? ARM GCC


ARM GCC 12 version - how to ensure that malloc and free functions don't get linked and that build fails if called?

Looking for similar to delete in C++, that is used to make sure function is not included (like hidden copy/move constructors, for instance).


Solution

  • functions don't get linked by the linker and throw a compilation error if called?

    Contraverting requirements. If the compiler throws an error then nothing will be linked as it will stop the build process.

    Add to the linker script:

    PROVIDE(malloc = 0);
    ASSERT(!malloc, "MALLOC PRESENT - ALERT!!!");
    

    same for other symbols you want to be warned about (actually linking will terminate)