public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/96200] Implement __builtin_thread_pointer() and __builtin_set_thread_pointer() if TLS is supported
Date: Mon, 07 Sep 2020 14:02:04 +0000	[thread overview]
Message-ID: <bug-96200-4-sKowYTD0yX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96200-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Florian Weimer from comment #6)
> (In reply to H.J. Lu from comment #4)
> > On Linux/i386 and Linux/x86-64, thread pointer access is done via syscall.
> > On Linux/x86-64, __builtin_thread_pointer and __builtin_set_thread_pointer
> > may be implemented with FSGSBASE ISA.  Is it possible to implement these
> > builtins on Linux/i386 and Linux/x86-64 for all processors?
> 
> It's effectively part of the x86-64 ABI, but I think it's currently
> undocumented. On x86-64, it looks like this:
> 
> static inline void *
> thread_pointer (void)
> {
>   void *result;
>   asm ("mov %%fs:0, %0" : "=r" (result));
>   return result;
> }
> 
> i386 is similar, but with %gs, I think.
> 
> This is ABI since the early NPTL days, and GCC knows about this very
> explicitly, to implement the -mno-tls-direct-seg-refs option.

It is documented, see https://akkadia.org/drepper/tls.pdf
"The only requirement about this register is that the actual thread pointer tpt
can be loaded from the absolute address 0 via the %gs register. The following
code would load the thread pointer in the %eax register:
movl %gs:0, %eax"
for ia32.  For x86_64, it is not spelled explicitly, but it is implicit from:
"The x86-64 ABI is at its base virtually the same as the IA-32 ABI. The
difference is mainly in different size of variables containing pointers and
that it only provides one variant which closely matches the IA-32 GNU variant.
Instead of segment register %gs it uses the %fs segment register."
as well as all the explicit insn sequences that use it.  The psABI doesn't have
TLS details I believe, so Ulrich's tls.pdf is the ABI document that covers
that.

  parent reply	other threads:[~2020-09-07 14:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 21:21 [Bug middle-end/96200] New: " carlos at redhat dot com
2020-07-15  6:10 ` [Bug middle-end/96200] " fw at gcc dot gnu.org
2020-07-15 19:13 ` carlos at redhat dot com
2020-08-28 23:17 ` hjl.tools at gmail dot com
2020-08-29  0:49 ` hjl.tools at gmail dot com
2020-08-29  2:07 ` hjl.tools at gmail dot com
2020-08-29  5:48 ` fw at gcc dot gnu.org
2020-08-29 12:23 ` hjl.tools at gmail dot com
2020-08-29 12:57 ` fw at gcc dot gnu.org
2020-08-29 15:34 ` hjl.tools at gmail dot com
2020-09-07 14:02 ` jakub at gcc dot gnu.org [this message]
2020-09-09 11:05 ` hjl.tools at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96200-4-sKowYTD0yX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).