public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info.
@ 2014-04-09  5:19 gary at intrepid dot com
  2014-04-09  5:28 ` [Bug go/60790] " gary at intrepid dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gary at intrepid dot com @ 2014-04-09  5:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

            Bug ID: 60790
           Summary: libatomic convenience library selects IFUNC
                    implementation before obtaining cpu info.
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: gary at intrepid dot com
                CC: nenad at intrepid dot com, PHHargrove at lbl dot gov,
                    rth at gcc dot gnu.org

Created attachment 32569
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32569&action=edit
libatomic cpuinfo patch

We ran into this issue recently while implementing atomic memory support for
GNU UPC.  We followed an approach similar to libgo -- we included
libatomic_convenience.a into libgupc.a.  This lets libgupc access GCC's
__atomic support without requiring the user to link explicitly with libatomic.

While debugging the UPC AMO library on a modern X86-64 platform, we noticed
that the locked implementation of compare-exchange-16 was being used in spite
of the fact of that the CPU supports the CMPX16 operation directly.

We determined that the IFUNC selector function was being called before the
constructor function in init.c had run.  Thus the libat_feat1_ecx variable was
zero.  Because the feature bit wasn't set, the selector function chose the CAS
function which requires explicit locks.  Interestingly,
__atomic_is_lock_free(16, NULL) returns true, as expected on this platform
because it is called after the init_cpuid() constructor is called.

One way to fix this issue is to re-work the logic that queries the CPU feature
register value, so that it explicitly initializes the value if it is zero.  The
assumption here is that __get_cpuid() will always return a non-zero value in
the ECX feature register.  A patch that implements this approach is attached.


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

* [Bug go/60790] libatomic convenience library selects IFUNC implementation before obtaining cpu info.
  2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
@ 2014-04-09  5:28 ` gary at intrepid dot com
  2014-04-09  5:38 ` [Bug libgcc/60790] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gary at intrepid dot com @ 2014-04-09  5:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

Gary Funck <gary at intrepid dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #32569|0                           |1
        is obsolete|                            |

--- Comment #1 from Gary Funck <gary at intrepid dot com> ---
Created attachment 32570
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32570&action=edit
libatomic cpuinfo patch

Test for edx when checking bit_CMPXCHG8B.


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

* [Bug libgcc/60790] libatomic convenience library selects IFUNC implementation before obtaining cpu info.
  2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
  2014-04-09  5:28 ` [Bug go/60790] " gary at intrepid dot com
@ 2014-04-09  5:38 ` pinskia at gcc dot gnu.org
  2014-04-09 13:32 ` ian at airs dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-04-09  5:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|go                          |libgcc
         Resolution|---                         |INVALID
           Assignee|ian at airs dot com                |unassigned at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is better if you just link directly against libatomic.  We already require
that for C11 _Atomic support in some/most cases.

>We followed an approach similar to libgo 

libgo needs to be fixed the same way really.


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

* [Bug libgcc/60790] libatomic convenience library selects IFUNC implementation before obtaining cpu info.
  2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
  2014-04-09  5:28 ` [Bug go/60790] " gary at intrepid dot com
  2014-04-09  5:38 ` [Bug libgcc/60790] " pinskia at gcc dot gnu.org
@ 2014-04-09 13:32 ` ian at airs dot com
  2014-04-09 13:44 ` jakub at gcc dot gnu.org
  2014-04-09 15:55 ` gary at intrepid dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ian at airs dot com @ 2014-04-09 13:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

Ian Lance Taylor <ian at airs dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2014-04-09
                 CC|                            |ian at airs dot com
         Resolution|INVALID                     |---
     Ever confirmed|0                           |1

--- Comment #3 from Ian Lance Taylor <ian at airs dot com> ---
Andrew, you are closing this way too fast.  This same problem is going to arise 
whenever libatomic is statically linked.  The library assumes that global
constructors are run before IFUNC selectors, but that is not the case in a
static link.  IFUNC selectors are run first.


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

* [Bug libgcc/60790] libatomic convenience library selects IFUNC implementation before obtaining cpu info.
  2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
                   ` (2 preceding siblings ...)
  2014-04-09 13:32 ` ian at airs dot com
@ 2014-04-09 13:44 ` jakub at gcc dot gnu.org
  2014-04-09 15:55 ` gary at intrepid dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-09 13:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

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

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is not guaranteed for shared libs either actually in some more complex
cases of shared library dependencies.


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

* [Bug libgcc/60790] libatomic convenience library selects IFUNC implementation before obtaining cpu info.
  2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
                   ` (3 preceding siblings ...)
  2014-04-09 13:44 ` jakub at gcc dot gnu.org
@ 2014-04-09 15:55 ` gary at intrepid dot com
  4 siblings, 0 replies; 6+ messages in thread
From: gary at intrepid dot com @ 2014-04-09 15:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60790

--- Comment #5 from Gary Funck <gary at intrepid dot com> ---
(In reply to Andrew Pinski from comment #2)
> It is better if you just link directly against libatomic.  We already
> require that for C11 _Atomic support in some/most cases.

As Ian notes, this issue would apply if libatomic were statically linked as
well.

In GNU UPC, we have a technical need to link in the (static) convenience
library, apart from it being "convenient" for the user: we need to substitute
our own locking routines.  I plan to submit a separate RFE on this.

Basically, we need process-level system wide locks because in the default
configuration UPC "threads" map to an operating system "process".  The current
libatomic implementation uses pthread mutexes.   We of course could build our
own libatomic types of facility, but that is a lot of work - libatomic is
well-engineered and apart from our need to have a different locking policy it
is a good fit for our application.  (detail: we had to build a
libatomic_convenience_nolock.a archive).

PS: It would be helpful to have a separate "libatomic" bug reporting category.


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

end of thread, other threads:[~2014-04-09 15:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09  5:19 [Bug go/60790] New: libatomic convenience library selects IFUNC implementation before obtaining cpu info gary at intrepid dot com
2014-04-09  5:28 ` [Bug go/60790] " gary at intrepid dot com
2014-04-09  5:38 ` [Bug libgcc/60790] " pinskia at gcc dot gnu.org
2014-04-09 13:32 ` ian at airs dot com
2014-04-09 13:44 ` jakub at gcc dot gnu.org
2014-04-09 15:55 ` gary at intrepid dot com

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).