独立的GCC和内置功能 [英] Freestanding GCC and builtin functions

查看:111
本文介绍了独立的GCC和内置功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC文档位于 http://gcc.gnu.org/ onlinedocs / gcc / C-Dialect-Options.html 表示(独立于 -freestanding )独立环境意味着 -fno-builtin 。我可能误解了独立环境究竟是什么或它是如何工作的,但在我看来,由于内建函数通常会发出内联代码而不是调用库函数,因此这对于标准库可能会丢失的独立环境功能,甚至完全没有。



那么,为什么我们不想在独立环境中使用biltin?

>解决方案

在独立模式下,编译器不能依赖语义考虑。

GCC中的大多数内置工作都是静默的 - 例如,编译器会发现您使用 strcpy(),并且托管模式,可能会猜测,当您使用 strcpy()时,您打算正好复制一个字符串。然后它可以用一个扩展等价的内建函数替换 strcpy ,这对于给定目标复制一个字符串更好。



在独立模式下,使用 strcpy()函数表示ANYTHING。这个想法并不是标准的图书馆缺乏联系。独立模式的思想是,除了float.h,iso646.h,limits.h,stdarg.h,stdbool.h,stddef.h,stdint.h(C99标准4.6)外,即使在定义级别上也没有标准库。 。您可以在独立模式下决定使用 strcpy 来格式化您的硬盘,这对于C语言来说是完全合法的。因此,编译器不知道如何使用内置函数,它拒绝使用它们。


The GCC docs at http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html say (under -ffreestanding) that a freestanding environment implies -fno-builtin. I might be misunderstanding exactly what a freestanding environment is or how it works, but it seems to me that, since the builtins usually emit inline code instead of calling the library function, this is ideal for a freestanding environment where the standard library may be missing functionality or even missing entirely.

So why would we not want to use the biltins with a freestanding environment?

解决方案

In freestanding mode the compiler can not rely on semantical considerations.

Most builtins in GCC work silently -- for instance the compiler sees that you are using strcpy() and in hosted mode it may guess that, when you are using strcpy(), you are intending exactly to copy a string. Then it may replace strcpy with an extensionally equivalent builtin, which is better for the given target to copy a string.

In freestanding mode, using strcpy() function means ANYTHING. The idea is just not the standard library absence in linkage. The idea of freestanding mode is that there is no standard library even on definition level, except float.h, iso646.h, limits.h, stdarg.h, stdbool.h, stddef.h, stdint.h (C99 standard 4.6). You may in freestanding mode decide to format your hard drive with strcpy, and this is perfectly legal for the C language. The compiler thus don't know how to use builtins, and it declines to use them at all.

这篇关于独立的GCC和内置功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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