Open 2e1c2d01-a631-41c2-93fe-8d40b95d8607 opened 3 years ago
builtin_frame_address effective returns the address-of the return address, not the contents of RBP, since those are effectively not useful to most callers of builtin_frame_address.
Hang on, that's not what I'm observing. There's something going on that I don't understand. As you say, it is returning the established SP value after the prologue, which seems inconsistent with the code I linked to.
This was intentional: https://github.com/llvm/llvm-project/commit/13d0b11d7b4e22da01dcef85e5302296edd8aa9e
builtin_frame_address effective returns the address-of the return address, not the contents of RBP, since those are effectively not useful to most callers of builtin_frame_address.
If you increase the stack memory used by foo in your example, you will see how RBP and the frame address begin to diverge.
I'm unaware of anyone successfully using __builtin_setjmp/longjmp on Windows. We have taken steps to make regular MSVC setjmp/longjmp work well.
Extended Description
$ cat frameaddr.c
void bar(int *n);
void foo(int *p, int n) { asm volatile ("nop"); p = builtin_frame_address(0); asm volatile__ ("nop"); bar(&n); }
$ clang --target=x86_64-windows frameaddr.c -c -o - | llvm-objdump -d -