[PATCH] D61892: [AArch64] Treat x18 as callee-saved in functions with windows calling convention on non-windows OSes

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 12:33:44 PDT 2020


efriedma added inline comments.


================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:2447
+    SavedRegs.set(AArch64::X18);
+  }
+
----------------
mstorsjo wrote:
> efriedma wrote:
> > This change shouldn't be necessary. If some code in the function modifies x18, or calls some non-Win64 function, x18 will be clobbered.  Frame lowering should see that, and figure out it needs to save x18 without any extra help.
> No, this is actually the core of the intent of this change.
> 
> When windows code (which expects x18 to be unmodified) calls an entry point in wine (marked with the windows calling convention), the entry point function (linux code but with a windows calling convention) itself probably won't clobber x18 (it's potentially even compiled with `-ffixed-x18` to avoid doing that) - but this function can call other functions (glibc, other userland libraries), and these functions can freely clobber x18.
> 
> So this is meant to always restore x18 on return from a windows calling convention function, as we can't really know what happened meanwhile.
Hmm...

So the functions using the Windows calling convention are compiled with -ffixed-x18, which means they don't treat x18 as allocatable at all.  And potentially, Unix calling convention code in the same file is compiled the same way.  But eventually, somewhere in the callstack, there might be a function that clobbers x18, so you want to save/restore it despite the fact that it's marked "fixed".

If x18 is fixed anyway, why do you need to mess with AArch64RegisterInfo::getCalleeSavedRegs?  It shouldn't participate in any computation related to the calling convention.

It seems a little magical to me that functions using the Win64 calling convention are making assumptions about the behavior of x18 despite the -ffixed-x18 marking.  The alternative would be to add a function attribute to specifically request this behavior, I guess, separate from the calling convention.  That would separate the concerns a bit more, but realistically I'm not sure anyone other than Wine is using the Win64 convention on non-Windows targets, so maybe it's not important.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61892/new/

https://reviews.llvm.org/D61892





More information about the llvm-commits mailing list