Problem with variadic C functions

I am the author of the open-source Dynace. This is an OO extension to C. It has been in production use for around 20 years. It has been used on DOS, all Windows, Linux, macOS/Intel, VMS, PLAN9, COSMIC, SUNOS, etc. all without a problem. However it does not run on Apple M1, M2 machines.

I traced the problem to variadic function calls. I am creating a va_list in a ... function. I then pass the va_list to a second function. I wrote something to copy the the va_list (via va_copy) to see what I am getting. The first function works okay. But the second function does not. (I know you can't re-use a va_list.)

I have spend a couple of days on this and can't find a problem with my code. I tried creating a simple example but it worked. Apparently the problem is situational.

Anyway, I have no idea what is wrong or what to do next. I'd sure appreciate any help!

Thanks!

Can you post a small snippet that reproduces the problem? That is, the smallest possible C program that uses this technique and works on Intel but fails on Apple silicon.


Problems like this are not uncommon because the C standard offers a lot of latitude for how calling conventions are implemented. For example, on 32-bit Intel the variadic conventions closely match the normal conventions, meaning that you could get away with calling objc_msgSend as a variadic. That doesn’t work reliably on 64-bit Intel and really doesn’t work on Apple silicon, meaning that you have use functional pointers. See here for the details.

So, it’s hard to say, based on your description, whether your code follows all the rules, which is why I’d like to see a concrete example.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Found and fixed the problem. Thanks!

Problem with variadic C functions
 
 
Q