Question

Going down the rabbit hole of variadic macros in glibc, I’ve reached /usr/lib/gcc/x86_64-linux-gnu/4.8.2/include/stdarg.h where, for example, the va_start macro is defined as:

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

But I’ve been trying to look for the actual implementation of __builtin_va_start(v,l) without success. I’ve googled and grepped for it, and the furthest I’ve gotten to is Microsoft’s implementation for Visual Studio, which I suppose isn’t radically different.

Does anybody know where glibc implementation is?

TIA.

Was it helpful?

Solution

To look in the source code of gcc, download the matching version from http://www.netgull.com/gcc/releases/ For example, the 4.8.2 version is at http://www.netgull.com/gcc/releases/gcc-4.8.2/ (82 MB).

The builtin keyword is handled at line 4169 of gcc/builtins.c

OTHER TIPS

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

have a look at stdarg.h in kernel 0.01 linux for an idea - va_start is a macro that initializes ap with as an increment starting at the first argument plus its size (rounded to machine word size); va_arg sets ap as the type given, and increments further the ap 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)) ))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top