[Bug libgcc/89714] New: allow for overriding the thread-detection mechanism

tneumann at users dot sourceforge.net gcc-bugzilla@gcc.gnu.org
Thu Mar 14 13:14:00 GMT 2019


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

            Bug ID: 89714
           Summary: allow for overriding the thread-detection mechanism
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tneumann at users dot sourceforge.net
  Target Milestone: ---

Currently the libgcc code uses a weak symbol to recognize if the program is
linked again pthreads (in __gthread_active_p()), and switches between
implementations at runtime based the presence of the weak symbol.
But if we know statically that we will always run multi-threaded, this dynamic
dispatch is quite wasteful.

This is particular visible for std C++ classes that indirectly inline this
code, for example std::shared_ptr. When copying a std::shared_ptr this check is
performed twice, each time with two code paths.
If we force __gthread_active_p to always return true the assembler code is
quite a bit shorter (and has less branches and executes less instructions, of
course).

This can be seen with the quick hack here

https://godbolt.org/z/946lzO

Changing the first line to #if 1 reduces the generated code significantly.

It would be good to offer a similar mechanism without having to resort to
horrible hacks.


More information about the Gcc-bugs mailing list