STM32 gcc (arm-none-eabi-gcc) links printf even though it is not used

徘徊边缘 提交于 2019-12-22 06:50:00

问题


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

  • Wl,--exclude-libs option
  • EXCLUDE_FILE(..) in linker script

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?


回答1:


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.



来源:https://stackoverflow.com/questions/39858015/stm32-gcc-arm-none-eabi-gcc-links-printf-even-though-it-is-not-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!