ola,
ive been looking at adding support for an -msave-args option for
use on x86_64. the short explanation of it is that it makes x86_64
function prologues store their register arguments on the stack. the
purpose of this is to make the arguments trivially accessible for
things like stack traces with arguments.
as per
https://blogs.oracle.com/sherrym/entry/obtaining_function_arguments_on_amd64,
this was originally implemented by sun in the various compilers
they use to support the debugging facilities in their system. ive
been looking at doing the same thing on openbsd for the same reasons
which you can see at
'add -msave-args to gcc on amd64' - MARC and
'arguments in amd64 ddb via -msave-args' - MARC.
there's a strong possibility that openbsd will switch to clang and
llvm on amd64, so i had a look at implementing this in clang. i
know the illumos community is interested in this functionality,
presumably as a way forward from the old gcc theyre still using.
i am a fair way along but i wanted to ask for advice on how to
proceed from this point. ive only been hacking on llvm for a day
or so, so id appreciate some advice from people with experience
before i head too far down what could be the wrong path.
its not obvious to me what what the etiquette is for sending diffs
so it's inline below. it is also available at
https://mild.embarrassm.net/~dlg/diff/llvm.msave.trunk
this does enough that it generally works. it basically shoves some
extra PUSHes into the prologue, and tries to account for them
properly so other uses of the frame and the epilogue works.
so there are some issues with the code:
- it (probably) doesnt handle functions that return structs
- it doesnt realign the stack pointer after consuming space on it
- it doesnt restrict the use of -msave-args to generation of 64bit
code.
so my questions are:
1. my understanding is if a function returns a struct, the caller
is responsible for allocating space for the struct and passes a
pointer to the callee via RDI, which takes a register away from
arguments.
is that true? what's the best way to detect that in
X86FrameLowering::emitPrologue()?
2. i copied get64BitArgumentGPRs from X86ISelLowering.cpp.
i need this so i know which registers to push onto the stack and
in which order.
should i move it to X86RegisterInfo.cpp? could someone give me a
pointer on following the FIXME, ie, how could i get that stuff from
tblgen?
if anyone has some tips for me, it would be greatly appreciated.
thanks in advance,
dlg
Index: lib/Target/X86/X86.td