On 10/26/24 16:28, H. Peter Anvin wrote:
cl
By any sane definition, the constraint should actually be an input constraint on the frame pointer itself; something like:
#define ASM_CALL_CONSTRAINT "r" (__builtin_frame_address(0))
... except that "r" really should be a %rbp constraint, but %rbp doesn't seem to have a constraint letter. At least gcc 14.2 seems to do the right thing anyway, though: __builtin_frame_address(0) seems to force a frame pointer to have been created (even with -fomit-frame- pointer specified, and in a leaf function), and the value is always passed in %rbp (because why on Earth would it do it differently, when it is sitting right there?)
This also matches the "tell the compiler [and programmer] what we actually mean" issue that you have mentioned in other contexts.
Anyway, here is a simple test case that can be used to verify that this construct does indeed work; at least with gcc 14.2.1 and clang 18.1.8 (the ones I ran a very quick test on).
It's simple enough that it is pretty straightforward to mess around with various modifications. So far I haven't been able to trip up the compilers this way.