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: Paolo Bonzini
Subject: Re: Portable inline asm to get address of TLS variable
Date: Wed, 16 Feb 2022 23:28:34 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

On 2/16/22 18:46, Stefan Hajnoczi wrote:
However, I wonder if the compiler might reuse a register that already
contains the address. Then we'd have the coroutine problem again when
qemu_coroutine_yield() is called between the earlier address calculation
and the asm volatile statement.

Yes, the compiler should be able to reuse the register. volatile only says that the contents of the "asm" cannot be subject to e.g. loop optimizations:

        for (i = 0; i < 10; i++) {
                asm("# assembly": "=r"(k) : "0"(10));
                j += k;
        }

will likely execute the asm once, while "asm volatile" (or an asm without inputs, which is always volatile) will execute it ten times.

However, the input of the assembly can be evaluated only once either way. For example, in the case above you might have "movl $10, %edx" outside the loop even with asm volatile.

One way to fix it for modules could be to define a (global, non-TLS) variable in QEMU with the %fs-based offset of the relevant thread-local variable, and initialize it before modules are loaded.

Paolo



reply via email to

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