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: Florian Weimer
Subject: Re: Portable inline asm to get address of TLS variable
Date: Wed, 16 Feb 2022 21:46:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

* 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.

Thanks,
Florian




reply via email to

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