On Tue, Apr 29, 2025 at 6:49 PM Uros Bizjak <ubiz...@gmail.com> wrote:
>
> On Tue, Apr 29, 2025 at 12:41 PM H.J. Lu <hjl.to...@gmail.com> wrote:
> >
> > On Tue, Apr 29, 2025 at 5:52 PM Uros Bizjak <ubiz...@gmail.com> wrote:
> > >
> > > MOVS instructions allow segment override of their source operand, e.g.:
> > >
> > >     rep movsq %gs:(%rsi), (%rdi)
> > >
> > > where %rsi is the address of the source location (with %gs segment 
> > > override)
> > > and %rdi is the address of the destination location.
> >
> > Please be aware that 0x67 prefix (used by x32) is applied before segment
> > register.  That is in
> >
> >  rep movsq %gs:(%esi), (%edi)
> >
> > the address is %gs + %esi.
>
> Uh, yes, now I remember this x32 peculiarity.
>
> So, we want the segment prefix disabled with "-mx32 -maddress-mode=short" ?
>
> Thanks,
> Uros.

Yes, it should be disabled when address size prefix is used, like TLS:

[hjl@gnu-tgl-3 tmp]$ cat t.c
extern __thread int x;

int
foo (void)
{
  return x;
}
[hjl@gnu-tgl-3 tmp]$ gcc -S -O2  t.c
[hjl@gnu-tgl-3 tmp]$ cat t.s
.file "t.c"
.text
.p2align 4
.globl foo
.type foo, @function
foo:
.LFB0:
.cfi_startproc
movq x@gottpoff(%rip), %rax
movl %fs:(%rax), %eax
ret
.cfi_endproc
.LFE0:
.size foo, .-foo
.ident "GCC: (GNU) 15.1.1 20250425 (Red Hat 15.1.1-1)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 tmp]$ gcc -S -O2  t.c -mx32
[hjl@gnu-tgl-3 tmp]$ cat t.s
.file "t.c"
.text
.p2align 4
.globl foo
.type foo, @function
foo:
.LFB0:
.cfi_startproc
movl %fs:0, %eax
addl x@gottpoff(%rip), %eax
movl (%eax), %eax
ret
.cfi_endproc
.LFE0:
.size foo, .-foo
.ident "GCC: (GNU) 15.1.1 20250425 (Red Hat 15.1.1-1)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 tmp]$


-- 
H.J.

Reply via email to