[PATCH] x32: Use THREAD_SELF for RSEQ_* accessors
H.J. Lu
hjl.tools@gmail.com
Fri Aug 22 19:00:13 GMT 2025
On Fri, Aug 22, 2025 at 8:59 AM Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, Aug 22, 2025 at 5:46 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Fri, Aug 22, 2025 at 3:44 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > Use THREAD_SELF to get the %fs register to work around the GCC bug:
> > >
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121613
> > >
> > > with the negative offset from the %fs register.
> > >
> > > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> > > ---
> > > sysdeps/x86_64/x32/nptl/rseq-access.h | 110 ++++++++++++--------------
> > > 1 file changed, 49 insertions(+), 61 deletions(-)
> > >
> > > diff --git a/sysdeps/x86_64/x32/nptl/rseq-access.h
> b/sysdeps/x86_64/x32/nptl/rseq-access.h
> > > index 8386ebd4bf..0baf4e8ea1 100644
> > > --- a/sysdeps/x86_64/x32/nptl/rseq-access.h
> > > +++ b/sysdeps/x86_64/x32/nptl/rseq-access.h
> > > @@ -16,70 +16,58 @@
> > > License along with the GNU C Library; if not, see
> > > <https://www.gnu.org/licenses/>. */
> > >
> > > +/* Read member of the RSEQ area directly. */
> > > +#define RSEQ_GETMEM(member) \
> > > + ({ \
> > > + _Static_assert (sizeof (RSEQ_SELF()->member) == 1 \
> > > + || sizeof (RSEQ_SELF()->member) == 4 \
> > > + || sizeof (RSEQ_SELF()->member) == 8, \
> > > + "size of rseq data"); \
> > > + void *__self = THREAD_SELF; \
> > > + asm ("" ::: "memory"); \
> >
> > You can use:
> >
> > asm ("" : "+r" (__self));
> >
> > to keep the value in the register without clobbering all the memory.
>
> OTOH, your approach will have two mem accesses. Is it really better
> than assembly?
>
> Uros.
>
Here is the codegen difference for RSEQ_GETMEM_ONCE:
--- /tmp/old.s 2025-08-22 11:49:49.985420531 -0700
+++ /tmp/new.s 2025-08-22 11:50:35.122271178 -0700
@@ -9,14 +9,12 @@ sched_getcpu:
endbr64
subl $40, %esp
.cfi_def_cfa_offset 48
+ movl __rseq_offset(%rip), %edx
movl %fs:24, %eax
movl %eax, 28(%rsp)
- movslq __rseq_offset(%rip), %rax
-#APP
-# 40 "../sysdeps/unix/sysv/linux/sched_getcpu.c" 1
- movl %fs:4(%rax),%eax
-# 0 "" 2
-#NO_APP
+ movl %fs:8, %eax
+ leal 4(%rax,%rdx), %eax
+ movl (%eax), %eax
testl %eax, %eax
js .L12
.L1:
I prefer the non-asm version for readability. It's better if we can fix
GCC.
--
H.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250822/5b7c0b37/attachment.htm>
More information about the Libc-alpha
mailing list