STM32 gcc (arm-none-eabi-gcc) 链接 printf 即使它没有被使用 [英] STM32 gcc (arm-none-eabi-gcc) links printf even though it is not used

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

问题描述

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

我试过了

  • Wl,--exclude-libs 选项
  • 链接描述文件中的EXCLUDE_FILE(..)

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

我的 gcc 选项:

CFLAGS = -Og -Wall -g3 -Wdouble-promotion -mcpu=cortex-m0 -mthumb -fmessage-length=0 -ffunction-sections -mfloat-abi=soft -DUSE_HAL_DRIVERLFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -Wl,--gc-sections

<块引用>

arm-none-eabi-gcc.exe(ARM 嵌入式处理器的 GNU 工具)5.2.120151202(发布)【ARM/embedded-5-branch修订231848】 版权所有(C) 2015 Free Software Foundation, Inc. 这是免费软件;见复制条件的来源.没有保修;甚至不为特定用途的适销性或适用性.

首先,为什么它们会被关联起来?有没有办法排除它们?

解决方案

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

<块引用>

--cref

输出交叉引用表.如果正在生成链接器映射文件,则会将交叉引用表打印到映射文件中.否则,它会打印在标准输出上.的格式表故意简单,以便它可以很容易地被一个如有必要,脚本.符号被打印出来,按名称排序.为了每个符号,给出一个文件名列表.如果定义了符号,列出的第一个文件是定义的位置.其余文件包含对符号的引用.

查找以其中一个打印符号开头的行及其下方的行.

grep -A5 _printf *.map

您会在那里找到内部使用 printf 的库函数.

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?

解决方案

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆