[PATCH] x32: Fix, optimize and cleanup RSEQ_* accessors

Uros Bizjak ubizjak@gmail.com
Sun Aug 24 21:07:54 GMT 2025


On Sun, Aug 24, 2025 at 10:03 PM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * Uros Bizjak:
>
> > Add missing "memory" clobber to accessors.
> >
> > Use MOVZBL instead of MOVB to read 1-byte memory location to
> > a register.
> >
> > Change %P asm operand modifiers to %c.
> >
> > Add explicit casts instead of using %b and %q asm operand modifiers.
>
> Please use the commit message to explain the reasons behind these
> changes.  The changes themselves are evident from the diff.

OK, will do.

> If you use movzbl, should you change the type of __value to long long
> int, to hint to the compiler that the entire register is cleared?

No, the fact that the register is cleared is just a side effect of
some other x86 (mis-)feature. MOVB to a register is actually an insert
to a LSB of the word-sized register, so the result becomes dependent
on the previous value of the register. MOVZBL avoids this issue, and
that is the reason that GCC compiles the following:

char m;
char a (void) { return m; }

to:

movzbl  m(%rip), %eax

The author of the original code tried to solve this partial register
issue by clearing the register first and then copying (== inserting)
the byte to the register with '"=q" (__value) : "0" (0)' part. This
solution is suboptimal, it generates:

       xorl    %eax, %eax
       movb (%eax),%al

The need for "memory" clobber is nicely explained in GCC
documentation, Section 6.11.2.6 "Clobbers and Scratch Registers":

‘"memory"
    The ‘"memory"’ clobber tells the compiler that the assembly code
    performs memory reads or writes to items other than those listed in
    the input and output operands (for example, accessing the memory
    pointed to by one of the input parameters).

This is exactly what these accessors do.

Uros.


More information about the Libc-alpha mailing list