问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/18711719/freestanding-gcc-and-builtin-functions