qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portable inline asm to get address of TLS variable


From: Stefan Hajnoczi
Subject: Re: Portable inline asm to get address of TLS variable
Date: Thu, 17 Feb 2022 09:30:19 +0000

On Wed, Feb 16, 2022 at 09:46:02PM +0100, Florian Weimer wrote:
> * Stefan Hajnoczi:
> 
> > I'm basically asking whether the &tls_var input operand is treated as
> > volatile and part of the inline assembly or whether it's just regular
> > C code that the compiler may optimize with the surrounding function?
> 
> &tls_var is evaluated outside of the inline assembly, any compiler
> barrier will come after that.  It's subject to CSE (or whatever it's
> called.  Three asm statements in a row
> 
>   asm volatile("" : "=r"(dst_ptr) : "0"(&tls_var));
>   asm volatile("" : "=r"(dst_ptr) : "0"(&tls_var));
>   asm volatile("" : "=r"(dst_ptr) : "0"(&tls_var));
> 
> result in
> 
>       movq    tls_var@gottpoff(%rip), %rax
>       addq    %fs:0, %rax
>       movq    %rax, %rdx
>       movq    %rax, %rdx
> 
> which is probably not what you want.

Right, the approach I suggested doesn't work. Thanks for sharing the
example!

Stefan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]