All of lore.kernel.org
 help / color / mirror / Atom feed
* Portable inline asm to get address of TLS variable
@ 2022-02-16 17:46 Stefan Hajnoczi
  2022-02-16 18:13 ` Florian Weimer
  2022-02-16 22:28 ` Paolo Bonzini
  0 siblings, 2 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2022-02-16 17:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Florian Weimer, qemu-devel, Serge Guelton

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Hi,
I've been trying to make the inline asm that gets the address of a TLS
variable for QEMU coroutines pass QEMU's GitLab CI.
https://gitlab.com/stefanha/qemu/-/blob/coroutine-tls-fix/include/qemu/coroutine-tls.h#L89

The code isn't -fPIC-friendly (R_X86_64_TPOFF32 relocations aren't
allowed in -fPIC shared libraries) so builds fail with ./configure
--enable-modules. While I was tackling this I stumbled on this:

  void *dst_ptr;
  asm volatile("" : "=r"(dst_ptr) : "0"(&tls_var))

What's nice about it:
- It's portable, there are no arch-specific assembly instructions.
- It works for both -fPIC and non-PIC.

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.

Thoughts?

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-04-20 14:38 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 17:46 Portable inline asm to get address of TLS variable Stefan Hajnoczi
2022-02-16 18:13 ` Florian Weimer
2022-02-16 20:28   ` Stefan Hajnoczi
2022-02-16 20:33     ` Stefan Hajnoczi
2022-02-16 20:46       ` Florian Weimer
2022-02-17  9:30         ` Stefan Hajnoczi
2022-02-16 20:40     ` Florian Weimer
2022-02-17  9:28       ` Stefan Hajnoczi
2022-02-17 11:40         ` Paolo Bonzini
2022-02-17 15:02           ` Serge Guelton
2022-02-17 15:11             ` Stefan Hajnoczi
2022-02-17 15:51             ` Paolo Bonzini
2022-02-17 14:59         ` Serge Guelton
2022-03-01 11:54         ` Florian Weimer
2022-03-01 13:39           ` Stefan Hajnoczi
2022-04-19 11:32             ` Florian Weimer
2022-04-19 18:38               ` Thomas Rodgers
2022-04-20 14:12               ` Stefan Hajnoczi
2022-02-16 22:28 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.