I can't seem to figure out why some printf
library functions get linked into my code from libc_nano.a even though I never use any printf
. It steals at least 2K of valuable flash memory space. I can see the sections _printf_i
, _vfprintf_r
, _vfiprintf_r
, etc. in my linker map file.
I tried
None of these make the symbols disappear from the map file..
My gcc options:
CFLAGS = -Og -Wall -g3 -Wdouble-promotion -mcpu=cortex-m0 -mthumb -fmessage-length=0 -ffunction-sections -mfloat-abi=soft -DUSE_HAL_DRIVER
LFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -Wl,--gc-sections
arm-none-eabi-gcc.exe (GNU Tools for ARM Embedded Processors) 5.2.1 20151202 (re lease) [ARM/embedded-5-branch revision 231848] Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
First of all, why do they get linked? Is there any method to exclude them?
Tell the linker to generate a cross reference: -Wl,--cref
--cref
Output a cross reference table. If a linker map file is being generated, the cross reference table is printed to the map file. Otherwise, it is printed on the standard output. The format of the table is intentionally simple, so that it may be easily processed by a script if necessary. The symbols are printed out, sorted by name. For each symbol, a list of file names is given. If the symbol is defined, the first file listed is the location of the definition. The remaining files contain references to the symbol.
Look for a line starting with one of the print symbols, and the lines below it.
grep -A5 _printf *.map
There you'll find the library function that uses printf internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With