On 25.02.2025 23:45, Andrew Cooper wrote:
> A CALL with 0 displacement is handled specially, and is why this logic
> functions even with CET Shadow Stacks active.  Nevertheless a rip-relative LEA
> is the more normal way of doing this in 64bit code.
> 
> The retrieval of flags modifies the stack pointer so needs to state a
> dependency on the stack pointer.  Despite it's name, ASM_CALL_CONSTRAINT is
> the way to do this.
> 
> read_sreg() forces the answer through a register, causing code generation of
> the form:
> 
>     mov    %gs, %eax
>     mov    %eax, %eax
>     mov    %rax, 0x140(%rsi)
> 
> Encode the reads directly with a memory operand.  This results in a 16bit
> store instead of an 64bit store, but the backing memory is zeroed.

Raises the question whether we shouldn't change read_sreg(). At least the
emulator uses of it would also benefit from storing straight to memory. And
the remaining uses ought to be optimizable by the compiler, except that I
don't expect we'd be able to express the zero-extending nature when the
destination is a register. Or wait, maybe I can make up something (whether
that's going to be liked is a separate question).

Jan

Reply via email to