public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107500] New: Useless atexit entry for ~constant_init in eh_globals.cc
@ 2022-11-01 17:53 rdiezmail-gcc at yahoo dot de
  2022-11-02 12:07 ` [Bug libstdc++/107500] " redi at gcc dot gnu.org
                   ` (28 more replies)
  0 siblings, 29 replies; 30+ messages in thread
From: rdiezmail-gcc at yahoo dot de @ 2022-11-01 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107500
           Summary: Useless atexit entry for ~constant_init in
                    eh_globals.cc
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rdiezmail-gcc at yahoo dot de
  Target Milestone: ---

I have this embedded firmware project of mine, which uses Newlib:

https://github.com/rdiez/DebugDue

It is the template for other similar bare-metal projects I have. Even though
some targets have very little SRAM (like 16 KiB), I am still using C++ and
exceptions. The project above documents how I configure GCC to that effect.

Up until GCC 11.2, I have been doing this check:

  if ( _GLOBAL_ATEXIT != nullptr )
  {
    Panic( "Unexpected entries in atexit table." );
  }

On devices with very little RAM and without an operating system, initialisation
and destruction can be tricky. With the check above, I am making sure that
nothing unexpected comes up in that respect. I am initialising all static
objects manually anyway, to prevent any ordering surprises (the initialisation
order of C++ static objects can be problematic too).

The check above fails with GCC 12.2. Apparently, a destructor called
constant_init::~constant_init() gets added to the atexit table on start-up.

Because of the way that Newlib works, that wastes 400 bytes of SRAM, which
corresponds to sizeof( _global_atexit0 ). The structure has room for 32 atexit
calls (because of some ANSI conformance), but we are only using 1 entry.

The interesting thing is that the destructor is supposed to be empty, see:

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_globals.cc

~constant_init() { /* do nothing, union member is not destroyed */ }

GCC generates the following code for that empty destructor:

0008da68 <(anonymous namespace)::constant_init::~constant_init()>:
  8da68:  b580  push  {r7, lr}
  8da6a:  af00  add   r7, sp, #0
  8da6c:  bd80  pop   {r7, pc}

That does not make any sense. Is there a way to prevent GCC from registering
such an empty atexit function? Failing that, is there a way to prevent GCC from
registering a particular atexit function, even if it is not empty?

I find surprising that GCC emits such code. My project is building its own
GCC/Newlib toolchain with optimisation level "-Os", so I would expect at least
the "add r7, sp, #0" to be optimised away.

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

end of thread, other threads:[~2024-05-22 15:48 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 17:53 [Bug c++/107500] New: Useless atexit entry for ~constant_init in eh_globals.cc 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
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

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