I'm writing a 64bit operating system using g++, and I have a variadic function like:
void DbgPrint(const char *fmt, ...);
which shall behave quite like printf. The problem here is that g++ follows the System V ABI, and thus it passes the first arguments in RDI, RSI, RDX, RCX, R8, R9, then pushes remaining (if any) on the stack.
Using the old stdarg.h macros va_start, va_arg, etc, with cdecl, was all quite easy as va_arg just took the next element on the stack. But now those macros won't work at all until the 7th argument.
The only possibile solutions are (IMHO):
- Forcing g++ to create a cdecl function. This seems impossible as __attribute__((cdecl)) is deliberately and clearly highlighted as ignored.
- Have a new set of macros that work with the new way of passing arguments.
(I'm actually working on Win, so I don't have the glibc headers to check their implementation).
Anyone with a solution? Thanks in advance.