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