[XRay][compiler-rt][x86_64] Fix CFI directives in assembly trampolines
authorElia Geretto <elia.f.geretto@gmail.com>
Sat, 6 Mar 2021 18:38:27 +0000 (10:38 -0800)
committerFangrui Song <i@maskray.me>
Sat, 6 Mar 2021 18:38:27 +0000 (10:38 -0800)
commitb46c89892fe25bec197fd30f09b3a312da126422
tree7b98b1e3e5625160e434b5877c72f1397812e44c
parentca747e48afa091afd8568df8973dfcbd43b8e334
[XRay][compiler-rt][x86_64] Fix CFI directives in assembly trampolines

This patch modifies the x86_64 XRay trampolines to fix the CFI information
generated by the assembler. One of the main issues in correcting the CFI
directives is the `ALIGNED_CALL_RAX` macro, which makes the CFA dependent on
the alignment of the stack. However, this macro is not really necessary because
some additional assumptions can be made on the alignment of the stack when the
trampolines are called. The code has been written as if the stack is guaranteed
to be 8-bytes aligned; however, it is instead guaranteed to be misaligned by 8
bytes with respect to a 16-bytes alignment. For this reason, always moving the
stack pointer by 8 bytes is sufficient to restore the appropriate alignment.

Trampolines that are called from within a function as a result of the builtins
`__xray_typedevent` and `__xray_customevent` are necessarely called with the
stack properly aligned so, in this case too, `ALIGNED_CALL_RAX` can be
eliminated.

Fixes https://bugs.llvm.org/show_bug.cgi?id=49060

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D96785
compiler-rt/lib/xray/xray_trampoline_x86_64.S