0

I'm trying to implement a variadic function declared as sysv_abi, so I have to use va_start in this function, but didn't find a way.

I compile the code on Win64, using vs2017, the compiler is clang-cl. The target is a x86_64 executable(PE file on windows, of course).

int __attribute__((sysv_abi)) my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...)
{
    va_list arg_list;
    va_start(arg_list, format);
    int ret = vsprintf_s(buffer, sizeOfBuffer, format, arg_list);
    va_end(arg_list);

    //__builtin_va_list v_list;
    //__builtin_va_start(v_list, format);
    //int ret = vsprintf_s(buffer, sizeOfBuffer, format, v_list);
    //__builtin_va_end(v_list);

    return ret;
}

Neither will compile, I get:

error : 'va_start' used in System V ABI function

How can I deal with this?

Asuka
  • 71
  • 1
  • 4
  • I suppose that being variadic and using the SysV ABI are non-negotiable, so try a different compiler? Or maybe a newer version of clang? There is no *inherent* incompatibility between the SysV ABI and variadic functions -- your version of clang just refuses to support it. Which it is totally within its rights to do, since `__attribute__` is a language extension. – John Bollinger Jun 21 '19 at 17:19
  • @JohnBollinger Tring a different compiler is impossible...my clang version is 8.0.0, it's the latest prebuild version which can be downloaded. I'll try to compile the latest 9.x version and then reply. – Asuka Jun 21 '19 at 17:32
  • @JohnBollinger I think maybe the problem is that I use Microsoft's header file since I'm using visual studio, and I just change the compiler using [llvm extension](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain). But I also tried `__builtin_va_start` and `__builtin_ms_va_start`, neither worked. – Asuka Jun 21 '19 at 17:35
  • `clang` is not the only C compiler for Windows, nor even the only one that recognizes `__attribute__` -- that's a GCC invention, in fact. You're in any case not free to swap out one version of the standard library headers for another. You must use the version that is appropriate for your toolchain and standard library. Normally, you can expect the compiler to select that automatically if more than one is available. – John Bollinger Jun 21 '19 at 17:40
  • @JohnBollinger Well, since the project get bigger and bigger, it's not that easy to just change to another compiler for such a "bug". clang-cl is designed for use with windows headers, besides I've already tried `__builtin_xxx` functions which is not include in any header. Maybe that's a compiler bug or lack of such a feature. I'm trying to build the latest clang. – Asuka Jun 21 '19 at 18:14
  • I'm mainly saying that your options are limited -- depending on extensions can have that effect. It is possible, in fact, that there aren't *any* viable alternatives that fulfill all your requirements. – John Bollinger Jun 21 '19 at 20:49

0 Answers0