public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Thomas Schwinge <thomas@codesourcery.com>,
	Alexandre Oliva <oliva@adacore.com>,
	gcc-patches@gcc.gnu.org,  libstdc++@gcc.gnu.org,
	David Edelsohn <dje.gcc@gmail.com>
Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime
Date: Wed, 6 Dec 2023 14:40:48 +0000	[thread overview]
Message-ID: <CAH6eHdR4mBwMue9PCLJ-6AtDy2zGn7f5JXsQDGWHSnZEdT+M1g@mail.gmail.com> (raw)
In-Reply-To: <CACb0b4k1LXGOLhiwBOzgA7zt5SHDBS3GX-VEKMC+FWTzC8+NqQ@mail.gmail.com>

On Wed, 6 Dec 2023 at 13:53, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Wed, 6 Dec 2023 at 12:30, Thomas Schwinge <thomas@codesourcery.com> wrote:
> >
> > Hi Alexandre!
> >
> > On 2023-12-06T02:28:42-0300, Alexandre Oliva <oliva@adacore.com> wrote:
> > > libsupc++: try cxa_thread_atexit_impl at runtime
> > >
> > > g++.dg/tls/thread_local-order2.C fails when the toolchain is built for
> > > a platform that lacks __cxa_thread_atexit_impl, even if the program is
> > > built and run using that toolchain on a (later) platform that offers
> > > __cxa_thread_atexit_impl.
> > >
> > > This patch adds runtime testing for __cxa_thread_atexit_impl on select
> > > platforms (GNU variants, for starters) that support weak symbols.
> >
> > Need something like:
> >
> >     --- libstdc++-v3/libsupc++/atexit_thread.cc
> >     +++ libstdc++-v3/libsupc++/atexit_thread.cc
> >     @@ -164,2 +164,4 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> >          return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> >     +#else
> >     +  (void) dso_handle;
> >      #endif
>
> I would prefer:
>
> --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> @@ -148,7 +148,7 @@ __cxa_thread_atexit_impl (void
> (_GLIBCXX_CDTOR_CALLABI *func) (void *),
>  // ??? We can't make it an ifunc, can we?
>  extern "C" int
>  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> -                                void *obj, void *dso_handle)
> +                                void *obj, [[maybe_unused]] void *dso_handle)
>    _GLIBCXX_NOTHROW
>  {
>  #if __GXX_WEAK__


The patch is OK with that change.


>
>
>
>
> >
> > ... to avoid:
> >
> >     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In function ‘int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, void*)’:
> >     [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: error: unused parameter ‘dso_handle’ [-Werror=unused-parameter]
> >       151 |                                  void *obj, void *dso_handle)
> >           |                                             ~~~~~~^~~~~~~~~~
> >     cc1plus: all warnings being treated as errors
> >     make[4]: *** [atexit_thread.lo] Error 1
> >
> > With that, GCC/nvptx then is back to:
> >
> >     UNSUPPORTED: g++.dg/tls/thread_local6.C  -std=c++98
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++14 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++14 execution test
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++17 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++17 execution test
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++20 (test for excess errors)
> >     PASS: g++.dg/tls/thread_local6.C  -std=c++20 execution test
> >
> >
> > Grüße
> >  Thomas
> >
> >
> > > for  libstdc++-v3/ChangeLog
> > >
> > >       * config/os/gnu-linux/os_defines.h
> > >       (_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define.
> > >       * libsupc++/atexit_thread.cc [__GXX_WEAK__ &&
> > >       _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL]
> > >       (__cxa_thread_atexit): Add dynamic detection of
> > >       __cxa_thread_atexit_impl.
> > > ---
> > >  libstdc++-v3/config/os/gnu-linux/os_defines.h |    5 +++++
> > >  libstdc++-v3/libsupc++/atexit_thread.cc       |   23 ++++++++++++++++++++++-
> > >  2 files changed, 27 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > index 87317031fcd71..a2e4baec069d5 100644
> > > --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
> > > @@ -60,6 +60,11 @@
> > >  # define _GLIBCXX_HAVE_FLOAT128_MATH 1
> > >  #endif
> > >
> > > +// Enable __cxa_thread_atexit to rely on a (presumably libc-provided)
> > > +// __cxa_thread_atexit_impl, if it happens to be defined, even if
> > > +// configure couldn't find it during the build.
> > > +#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1
> > > +
> > >  #ifdef __linux__
> > >  // The following libpthread properties only apply to Linux, not GNU/Hurd.
> > >
> > > diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
> > > index 9346d50f5dafe..aa4ed5312bfe3 100644
> > > --- a/libstdc++-v3/libsupc++/atexit_thread.cc
> > > +++ b/libstdc++-v3/libsupc++/atexit_thread.cc
> > > @@ -138,11 +138,32 @@ namespace {
> > >    }
> > >  }
> > >
> > > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +extern "C"
> > > +int __attribute__ ((__weak__))
> > > +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *),
> > > +                       void *arg, void *d);
> > > +#endif
> > > +
> > > +// ??? We can't make it an ifunc, can we?
> > >  extern "C" int
> > >  __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
> > > -                              void *obj, void */*dso_handle*/)
> > > +                              void *obj, void *dso_handle)
> > >    _GLIBCXX_NOTHROW
> > >  {
> > > +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +  if (__cxa_thread_atexit_impl)
> > > +    // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl,
> > > +    // if it happens to be defined, even if configure couldn't find it
> > > +    // during the build.  _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL
> > > +    // may be defined e.g. in os_defines.h on platforms where some
> > > +    // versions of libc have a __cxa_thread_atexit_impl definition,
> > > +    // but whose earlier versions didn't.  This enables programs build
> > > +    // by toolchains compatible with earlier libc versions to still
> > > +    // benefit from a libc-provided __cxa_thread_atexit_impl.
> > > +    return __cxa_thread_atexit_impl (dtor, obj, dso_handle);
> > > +#endif
> > > +
> > >    // Do this initialization once.
> > >    if (__gthread_active_p ())
> > >      {
> > -----------------
> > Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
> >
>

  reply	other threads:[~2023-12-06 14:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09  1:55 Alexandre Oliva
2023-11-09  8:20 ` Jonathan Wakely
2023-12-01 20:40   ` Alexandre Oliva
2023-12-01 20:41     ` Jason Merrill
     [not found] ` <CAGWvny=8391BCUZF8eyYgP-NMoWM+qa6Yra6OGVVXuQNuAi9kw@mail.gmail.com>
     [not found]   ` <orr0k0rw0g.fsf@lxoliva.fsfla.org>
     [not found]     ` <or1qbzsxv9.fsf@lxoliva.fsfla.org>
2023-12-06 12:30       ` Thomas Schwinge
2023-12-06 13:52         ` Jonathan Wakely
2023-12-06 14:40           ` Jonathan Wakely [this message]
2023-12-06 22:46             ` Alexandre Oliva

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=CAH6eHdR4mBwMue9PCLJ-6AtDy2zGn7f5JXsQDGWHSnZEdT+M1g@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=oliva@adacore.com \
    --cc=thomas@codesourcery.com \
    /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).