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.
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
一般来说,为了找到gcc如何扩展名为'__builtin_ foo '的内置gcc函数,请在gcc源代码中查找函数'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)) ))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.