__Builtin_va_start (v, l) implementation

After lowering the rabbit hole of the variation macros in glibc, Ive reached /usr/lib/gcc/x86_64-linux-gnu/4.8.2/include/stdarg.h , where, for example, the va_start macro va_start defined as:

#define va_start(v,l) __builtin_va_start(v,l)

But I tried to find the actual implementation of __builtin_va_start(v,l) without success. Ive googled and grepped for this, and the farthest Ive got to Microsoft's implementation of Visual Studio, which I suppose is not radically different.

Does anyone know where the glibc implementation is implemented?

TIA.

+6
source share
3 answers

To view the gcc source code, download the appropriate version from http://www.netgull.com/gcc/releases/ For example, version 4.8.2 is located at http://www.netgull.com/gcc/releases/gcc-4.8. 2 / (82 MB).

The builtin keyword is processed on line 4169 from gcc/builtins.c

+10
source

In general, to find out how gcc extends the built-in gcc function, whose name is __builtin_foo, look in the gcc source for a declaration of the expand_builtin_foo function.

+1
source

take a look at stdarg.h in the 0.01 linux kernel for an idea - va_start is a macro that initializes ap with as an increment, starting with the first argument plus its size (rounded to the size of a machine word); va_arg sets ap as the given type and increases the ap step in the same way (rounding the type to machine words)

 #define __va_rounded_size(TYPE) \ ( ( (sizeof (TYPE) + sizeof (int) - 1) / sizeof (int) ) * sizeof (int) ) #define va_start(AP, LASTARG) \ (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) #define va_arg(AP, TYPE) \ (AP += __va_rounded_size (TYPE), \ *((TYPE *) (AP - __va_rounded_size (TYPE)) )) 
-1
source

Source: https://habr.com/ru/post/974776/


All Articles