本文介绍了即使未使用STM32 gcc(arm-none-eabi-gcc)链接printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚为什么某些printf库函数从libc_nano.a链接到我的代码中,即使我从不使用任何printf.它窃取了至少2K的宝贵闪存空间.我可以在链接器映射文件中看到_printf_i_vfprintf_r_vfiprintf_r等部分.

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.

我尝试了

  • Wl,-排除库选项
  • 链接描述文件中的EXCLUDE_FILE(..)

这些都不会使符号从地图文件中消失.

None of these make the symbols disappear from the map file..

我的gcc选项:

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

首先,为什么它们被链接?有什么方法可以排除它们?

First of all, why do they get linked?Is there any method to exclude them?

推荐答案

告诉链接器以生成交叉引用:-Wl,--cref

Tell the linker to generate a cross reference: -Wl,--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

您将找到内部使用printf的库函数.

There you'll find the library function that uses printf internally.

这篇关于即使未使用STM32 gcc(arm-none-eabi-gcc)链接printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 15:11