title: GCC - How to stop malloc being linked?
body: <p>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 already at approx 20k flash size!  Some of this is due to use of the STM32 HAL functions which I can account for and optimise later if needed.</p>
  
  <p>However, my biggest consumer of flash is all the implicitly included library routines.  I can not seem to remove these functions.  They are not called anywhere in my code or any HAL code.  Functions such as _malloc_r (1.3k Bytes), and __vfiprintf_r (3kB) and many others are using a large part of my flash.  I think these are all the libc functions.  I do not use these and would like them gone!</p>
  
  <p>Does anybody know how to remove these?</p>
  
  <p>I have tried different optimisation levels and linker options but no luck so far. I have tried -nostdlib and --specs=nosys.specs with no change.  If I remove my file with definitions for functions such as _exit I get a linker error suggesting that the library is still included and needs these.  Also linker map confirms presence of a lot of unwanted functions!</p>
  
  <p>Any suggestions?</p>