Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freestanding GCC and builtin functions

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?

like image 741
Baruch Avatar asked Sep 10 '13 06:09

Baruch


People also ask

What are GCC builtin functions?

GCC provides built-in versions of the ISO C99 floating-point comparison macros that avoid raising exceptions for unordered operands. They have the same names as the standard macros ( isgreater , isgreaterequal , isless , islessequal , islessgreater , and isunordered ) , with __builtin_ prefixed.

What is FNO builtin?

Tells the compiler not to use generic (non-Arm specific) handling and optimization of standard C and C++ library functions and operators, for example for the printf() , strlen() , and malloc() functions from the C standard library, or for the new and delete operators from the C++ standard library.


1 Answers

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.

like image 80
Konstantin Vladimirov Avatar answered Oct 02 '22 09:10

Konstantin Vladimirov