Stdargs [va_start (), va_arg () etc.] is broken on arm64?

I have a c function that uses varadic arguments in a standard way, below a simplified example:

    void func(parameter,...) {
     va_list args;
     va_start(args, parameter);

     //process args
     v1 = va_arg(args,sometype);
     v2 = va_arg(args,sometype);
        ...
     vn = va_arg(args,sometype);

     va_end(args);
}


//call func

func(parameter, p1, p2, ..., pn);

On all armv7s devices and below, as well as on all simulators, including a 64-bit simulator, this succeeds, and the variable v1-vn is assigned to p1-pn, but when it runs on arm64, it looks like the variational list is reversed (v1 = pn, v2 = pn-1, ..., vn = p1)

Is there any fix for this? Or did I skip the documentation describing this change?

thanks

EDIT:

I did not mention a key element of this problem that I did not think to mention before. I tried to use non-invariant functions with a common variational function.

Note: the compiler used was Apple LLVM 5.0

+4
3

-, , . .

Apple, , , , , .

, armv7 armv7s, , arm64 .

, , ABI, , .

+1

, , .

: , , . , ARMv6, ARMv7 ARM64, ABI.

, , , , , ( , ).

Apple , , .

, ARM , . 5.5 ARM (ARMv6, ARMv7 5.4 64- ABI

+2

Varargs only work if you use the same types in the calling and called parties. If, for example, you pass 1 and try to read it as NSInteger, this will not work for 64 bits, because the programmer did not understand varargs, and not because of a compiler error.

We still have not seen any code that fails.

0
source

All Articles