public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/107500] Useless atexit entry for ~constant_init in eh_globals.cc
Date: Wed, 02 Nov 2022 14:17:00 +0000	[thread overview]
Message-ID: <bug-107500-4-JHnTec2ZnM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107500-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to R. Diez from comment #8)
> Why does this 'eh_globals' object have to use a constexpr constructor?

So it can be constinit.

> How does the current code avoid the "static initialization order fiasco"? If
> the user defines his/her own static C++ objects, how is it guaranteed now
> that 'eh_globals' is initialised before all other user code?

Because that's what constinit means.
https://en.cppreference.com/w/cpp/language/constinit

> Isn't using the "__attribute__ constructor" trick safer anyway? With it, you
> can document what priority levels libstdc++ uses. The user may even want to
> run a few routines before libstdc++ initialises. Flexibility in the
> initialisation order is often important in embedded environments.
> 
> Portability is not really an issue. You can just "#ifdef GCC" around the
> "better" hack. Is GCC not using "__attribute__ constructor" internally
> anyway to implement such static constructors? So anybody using C++ with GCC
> must support that mechanism already.

No, it doesn't work on all targets supported by GCC and libstdc++.

> And about saving a few bytes, 400 bytes is no small amount in
> tightly-embedded environments. But it is not just the amount of memory. As I
> mentioned, my code is checking that nothing unexpected registers an atexit()
> destructor. If libstdc++ does that on start-up, it becomes hard to tell
> whether something unexpected has been added recently.
> 
> I can surely put up with yet another little annoyance with this new GCC
> version. But bear in mind that flexibility and attention to detail in the
> embedded world is one of GCC's few remaining bastions. If GCC starts
> dropping the ball here too, even more people will consider moving to clang.

The "if you don't fix this people will switch to clang" threat is not as
motivating as you might think. It gets tedious after the thousandth time you
hear it.

I've confirmed the bug as a missed-optimization, and suggested ways the
compiler might be able to solve it. I am not going to reintroduce race
conditions in libstdc++ to work around your needs here.

If you think GCC (and libstdc++ in particular) doesn't care about embedded then
you're not paying attention. The changes to eh_globals.cc were introduced for
PR105880 specifically to solve a bug on embedded targets using newlib. And
there have been more than a dozen commits in the past month making huge parts
of libstdc++ more usable on bare metal.

If you think the codegen for empty functions can be improved, please file a
separate bug as that's not the same topic as optimizing away atexit calls for
empty destructors.

  parent reply	other threads:[~2022-11-02 14:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 17:53 [Bug c++/107500] New: " rdiezmail-gcc at yahoo dot de
2022-11-02 12:07 ` [Bug libstdc++/107500] " redi at gcc dot gnu.org
2022-11-02 12:08 ` [Bug c++/107500] " redi at gcc dot gnu.org
2022-11-02 12:13 ` redi at gcc dot gnu.org
2022-11-02 12:46 ` rdiezmail-gcc at yahoo dot de
2022-11-02 13:01 ` rdiezmail-gcc at yahoo dot de
2022-11-02 13:04 ` redi at gcc dot gnu.org
2022-11-02 13:09 ` redi at gcc dot gnu.org
2022-11-02 13:29 ` rdiezmail-gcc at yahoo dot de
2022-11-02 13:36 ` rdiezmail-gcc at yahoo dot de
2022-11-02 14:17 ` redi at gcc dot gnu.org [this message]
2022-11-02 14:38 ` redi at gcc dot gnu.org
2022-11-02 15:47 ` pinskia at gcc dot gnu.org
2022-11-02 16:12 ` rdiezmail-gcc at yahoo dot de
2022-11-02 17:16 ` redi at gcc dot gnu.org
2022-11-02 17:46 ` redi at gcc dot gnu.org
2022-11-03  7:57 ` rdiezmail-gcc at yahoo dot de
2022-11-03 11:52 ` redi at gcc dot gnu.org
2022-11-03 11:55 ` redi at gcc dot gnu.org
2022-11-04  9:42 ` sebastian.huber@embedded-brains.de
2022-11-04 12:43 ` rdiezmail-gcc at yahoo dot de
2022-11-04 14:05 ` cvs-commit at gcc dot gnu.org
2022-11-04 14:15 ` redi at gcc dot gnu.org
2022-11-04 14:58 ` rdiezmail-gcc at yahoo dot de
2022-11-04 20:40 ` rdiezmail-gcc at yahoo dot de
2023-05-08 12:25 ` rguenth at gcc dot gnu.org
2024-03-16 10:25 ` redi at gcc dot gnu.org
2024-03-16 10:29 ` [Bug c++/107500] [12 Regression] " redi at gcc dot gnu.org
2024-03-18 14:03 ` cvs-commit at gcc dot gnu.org
2024-05-22 15:48 ` redi at gcc dot gnu.org

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-107500-4-JHnTec2ZnM@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).