Closed refi64 closed 8 years ago
Most ABIs have a concept of a callee-saved register, which is one that the function being called is expected not to modify without backing it up first. You'd normally save/restore it with the stack in the prologue/epilogue, but I don't think x86_64.dasc does that.
In the amd64 Linux case this applies to rbx, rbp and r12-r15 (see http://www.x86-64.org/documentation/abi.pdf). Windows adds rdi and rsi to the list. 32-bit x86 seems to be esi, edi, ebx and ebp. It gets more complicated if floating registers are used, but fortunately you don't.
Anyway, in this case for ex.c my clang it storing the "m" pointer in r12. This gets dutifully saved by all the C code, but the JITed code ends up setting it to -1 (in my case). When we eventually get back to ex.c, we try looking up a field and it goes about as badly as you'd expect.
@TNorthover That makes sense! I have a copy of the X64 ABI, but I mismatched the rows and read r11's (not callee-save) as r12's (callee-save). So I'm guessing changing the register to r9 will fix the problem.
Thanks for the help!
Not sure why. From my tests, it seems to have something to do with groups, but I'm not experienced with GCC/Clang optimizations, so I'm not sure why...?