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

Florian Weimer fweimer@redhat.com
Mon Aug 25 05:58:02 GMT 2025


* Uros Bizjak:

>> 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,

I think it's still valuable to tell GCC that the entire register is
cleared.  Otherwise, this

long int __rseq_offset;
int
f (void)
{
  unsigned char __value;
  asm volatile ("movzbl %%fs:%c1(%2), %k0"
                : "=r" (__value)
                : "i" (0),
                  "r" ((long long int) __rseq_offset)
                : "memory");
  return __value;
}

produces an additional movbzl.  On the other hand, it only works for
unsigned chars.

Thanks,
Florian



More information about the Libc-alpha mailing list