On 10/02/2025 9:29 pm, Julien Grall wrote: > Hi, > > On 08/02/2025 00:02, Andrew Cooper wrote: >> Right now, run_in_exception_handler() takes an input in an arbitrary >> register, >> and clobbers BUG_FN_REG. This causes the compiler to calculate fn in >> the >> wrong regsiter. > > Just to confirm, you mean, the compiler is not clever enough to notice > that the value should be in the register BUG_FN_REG and therefore, two > registers will be clobbered. Is that correct?
Not quite. The clobbered register set is always disjoint from inputs and outputs, so the combination of one clobbered + one input always means two different registers. For "here's an input but it gets modified", you need to express that as an output into a variable which isn't subsequently used. For ARM, that is best spelt "+r" (foo) so it can also be used with register asm() to tie to a single register. On x86, you can use "=a" (tmp) : "a" (input). In principle you can do it with named parameters, so [fn] "=r" (tmp) : "[fn]" (input) I believe works too. Here is a contrived example https://godbolt.org/z/WjqTKjWWb showing how the output (discard only) is forced into r0, causing the compiler to copy a into r3 around the asm block. Notice that GCC and Clang pick the input operand differently, as both r0 and r3 are valid candidates in this case. However, for run_in_exception_handler(), "fn" isn't even modified (AFAICT), so it's correct to describe it as an input only. ~Andrew
