GCC [for ARM] 强制无浮点 [英] GCC [for ARM] force no floating point

查看:21
本文介绍了GCC [for ARM] 强制无浮点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建我的嵌入式 C 代码的构建,专门检查浮点运算不是偶然引入的.我已经尝试将 +nofp 添加到我的 [cortex-m3] 处理器架构中,但 GCC for ARM 不喜欢那样(可能是因为 cortex-m3 没有一个浮点单元).我试过指定 -mfpu=none 但这不是允许的选项.我试过将 -lm 离开链接器命令行,但链接器似乎太聪明了,不能被它愚弄,并且正在编译带有 double 的代码并解析 pow() 无论如何.

I would like to create a build of my embedded C code which specifically checks that floating point operations aren't introduced into it by accident. I've tried adding +nofp to my [cortex-m3] processor architecture but GCC for ARM doesn't like that (probably because the cortex-m3 doesn't have a floating point unit). I've tried specifying -mfpu=none but that isn't a permitted option. I've tried leaving -lm off the linker command-line but the linker seems too clever to be fooled by that and is compiling code with double in it and resolving pow() anyway.

这篇文章:https://gcc.2011 年的 gnu.org/legacy-ml/gcc-help/2011-07/msg00093.html 暗示 GCC 没有这样的选择,因为没有人对它感兴趣,这让我感到惊讶,因为它看起来像是至少从嵌入式的角度来看,想要避免意外的 C 库膨胀是很常见的事情.

This post: https://gcc.gnu.org/legacy-ml/gcc-help/2011-07/msg00093.html from 2011 hints that GCC has no such option, since no-one is interested in it, which surprises me as it seems like a common thing to want, at least from an embedded standpoint, to avoid accidental C-library bloat.

有没有人知道一种使用 GCC/newlib 执行此操作的方法,而无需我通过它选择的 C 库文件手动破解内容?

Does anyone know of a way to do this with GCC/newlib without me having to go through and manually hack stuff out of the C library file it chooses?

推荐答案

这不仅仅是图书馆的问题.您的目标将使用 soft-fp,并且编译器将提供浮点代码来实现算术运算符,而不管库如何.

It is not just a library issue. Your target will use soft-fp, and the compiler will supply floating point code to implement arithmetic operators regardless of the library.

我通常应用的解决方案是扫描映射文件以查找编译器提供的浮点例程的实例.如果您的代码是fp clean"不会有这样的引用.数学库和任何其他执行浮点算术运算的代码都将使用这些运算符实现,因此您只需查找这些运算符调用即可,而可以忽略 Newlib 数学库函数.

The solution I generally apply is to scan the map file for instances of the compiler supplied floating-point routines. If your code is "fp clean" there will be no such references. The math library and any other code that perform floating-point arithmetic operations will use these operator implementations, so you only need look for these operator calls and can ignore the Newlib math library functions.

内部 soft-fp 例程列于 https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html.手动检查地图文件中的 fp 符号可能是可行的,但您可以自己编写脚本或工具来扫描地图文件中的这些名称以检查您的.映射文件的交叉引用部分将列出使用这些符号的所有模块,以便您可以使用它来识别使用浮点代码的位置.

The internal soft-fp routines are listed at https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html. It is probably feasible to manually check the mapfile for fp symbols but you might write yourself a script or tool to scan the map file for these names to check your. The cross-reference section of the map file will list all modules these symbols are used in so you can use that to identify where the floating point code is used.

Newlib stdio 函数默认支持浮点.如果您的格式化 I/O 仅限于 printf(),您可以使用 iprintf() 代替,或者您可以使用未定义的 FLOATING_POINT 重建 Newlib 以删除除了 scanf() 之外的所有浮点支持(不知道为什么).然后您可以再次使用地图文件技术来查找禁止"的文件.格式化的 I/O 函数(尽管这些函数在任何情况下也可能使用浮点运算符函数,因此您已经间接地发现了它们).

The Newlib stdio functions support floating-point by default. If your formatted I/O is limited to printf() you can use iprintf() instead or you can rebuild Newlib with FLOATING_POINT undefined to remove floating point support from all but scanf() (no idea why). You can then use the map file technique again to find "banned" formatted I/O functions (although these are likely to also use the floating point operator functions in any case, so you will already have spotted them indirectly).

另一种方法是使用替代的 stdio 库来覆盖 Newlib 版本.有任意数量的微小的 printf"您可以使用的可用实现.如果您将此类库链接为目标代码或在链接命令中将其库列在 Newlib 之前,它将覆盖 Newlib 版本.

An alternative is to use an alternative stdio library to override the Newlib versions. There are any number of "tiny printf" implementations available you could use. If you link such a library as object code or list its library ahead of Newlib in the link command, it will override the Newlib versions.

这篇关于GCC [for ARM] 强制无浮点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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