GCC - How to stop malloc being linked?

前端 未结 2 600
星月不相逢
星月不相逢 2021-01-16 10:09

I am struggling to get my code down to minimal bare bones size! I am using a STM32F0 with only 32k flash and need a good part of the flash for data storage. My code is alr

相关标签:
2条回答
  • 2021-01-16 10:29

    Solved... Some of my code included and called assert. The moment I removed assert calls my code size more than halved! I instead used the STM32 HALs assert_param macro that is a light weight assert that just redirects to a user defined function.

    It would be helpful if someone could explain to me how gcc decides to include library functions when assert is called? I see that assert.h declares an external function __assert_func. How does the linker know to reference it from a library rather than just say "undefined reference to __asert_func"?

    0 讨论(0)
  • 2021-01-16 10:40

    When you are wondering about what takes space, or why functions and libraries have been linked in, generate a map file with cross references - something like "-Wl,-Map=program.map,--cref". Look at the file with a text editor, and you can see why a function like malloc has been included.

    0 讨论(0)
提交回复
热议问题