https://bugs.winehq.org/show_bug.cgi?id=38780
--- Comment #22 from Martin Storsjö martin@martin.st --- (In reply to Zebediah Figura from comment #16)
Essentially, to treat it as a caller-saved register (even though it's not being used as a scratch register).
After poking around a bit in the AArch64 target in llvm, this doesn't seem all that easy, necessarily, but I might of course be wrong.
To achieve what's wanted here (having x18 correct when calling callback functions from anywhere within wine code), the compiler would need to back up x18 before every single function call (which might be to a glibc function which could clobber x18), and restore it immediately afterwards on return. That's not how normal caller saved registers are used though; the register allocator (primarily) moves anything that needs to be stored across function calls into a callee saved register instead and uses it from there; it doesn't move it back into the caller save register unless it needs to.
So it's of course not impossible, but so far I didn't find any existing mechanism where I could just add x18 to the list and have it all work out automatically.