Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How GCC handles built-in function

Tags:

People also ask

What is builtin functions in GCC?

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.

Is GCC a build tool?

The GNU Compiler Collection (usually shortened to GCC) is a compiler system produced by the GNU Project supporting various programming languages. make is a "build tool" that invokes the compiler (which could be gcc) in a particular sequence to compile multiple sources and link them together.

What is __ Builtin_ffs?

int__builtin_ffs (unsigned int x) Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero. int__builtin_clz (unsigned int x) Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.


I have trouble understanding GCC built-in functions, and feel very confused.

  • What is the difference between a library function and an built-in function?

  • Is there something a built-in function can do but a library function cannot?

  • Can I write a library function that performs the same task as the built-in function printf? How can I tell the type of the input parameters (%f, float or double)?

  • Machine instructions of GCC built-in functions are not stored in a library, right? Where are they?

  • When doing linking, how can you control where to put these built-in function codes?

  • Why sometimes I can error messages like "undefined reference to __builtin_stdarg_start" when doing linking

    // main.c #include <stdio.h> int main(void) {   printf("hello world!\n");   return 0; } 

    gcc -c main.c, nm shows that there is no symbol printf in main.o, (only main(T) and puts(U)) , why?