This is an archive of the discontinued LLVM Phabricator instance.

[XRay][compiler-rt] Cleanup CFI/CFA annotations on trampolines
ClosedPublic

Authored by dberris on Apr 19 2017, 12:02 AM.

Details

Summary

This is a follow-up to D32202.

While the previous change (D32202) did fix the stack alignment issue, we
were still at a weird state in terms of the CFI/CFA directives (as the
offsets were wrong). This change cleans up the SAVE/RESTORE macros for
the trampoline, accounting the stack pointer adjustments with less
instructions and with some clearer math. We note that the offsets will
be different on the exit trampolines, because we don't typically 'call'
into this trampoline and we only ever jump into them (i.e. treated as a
tail call that's patched in at runtime).

Event Timeline

dberris created this revision.Apr 19 2017, 12:02 AM
kpw accepted this revision.Apr 19 2017, 12:44 AM
kpw added inline comments.
lib/xray/xray_trampoline_x86_64.S
101

If the exit handler is jumped into, does the exit sled explicitly push the return address onto the stack (accounting for the extra 8 bytes compared to the subq insn above)?

This revision is now accepted and ready to land.Apr 19 2017, 12:44 AM
pelikan accepted this revision.Apr 19 2017, 6:00 PM

Third time does the charm?

lib/xray/xray_trampoline_x86_64.S
101

Either the sled (unpatched) or this trampoline (patched) will execute the RET instruction which will pop the address from the stack. It will happen precisely once and therefore offset 8 is correct. The push happens before the entry into the function, and has nothing to do with XRay.

dberris updated this revision to Diff 95869.Apr 19 2017, 6:47 PM
  • fixup: update with a comment explaining the stack alignment expectations
dberris marked 2 inline comments as done.Apr 19 2017, 6:49 PM

Updated the macro with a comment explaining the situation for stack alignment (taking @eugenis' advice in D32202).

This revision was automatically updated to reflect the committed changes.