From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A9D92385842B; Wed, 2 Nov 2022 12:46:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9D92385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667393166; bh=kqMXa9+kIKOBWb6sBG6pcTGxomlgbX+ug73uXpJC4L8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UqUdk0m2fIOWHv6jfVC7TSuzEIcOxeDmYvwLAMJKyDBlS7kow4NI66L+cusj4ZiDK uwK2adwwUtHn2gb5NmxQ5avM6O+Ij1/B1s0uoRhqMIF/RoL6FyaiXH+l7V9Srk7jyN 4H/iCzv/MGyZLYp4Rj1yvS8anWYPMWmY9Jt0x9Rc= From: "rdiezmail-gcc at yahoo dot de" 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 12:46:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rdiezmail-gcc at yahoo dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107500 --- Comment #4 from R. Diez --- The 'constant_init' wrapper with the 'union' inside is a contrived hack, is= n't it? We may as well use a different hack then. How about a combination of '__attribute__ constructor' and 'placement new' = like this? uint8_t some_buffer[ sizeof( __cxa_eh_globals ) ]; // All objects with an init_priority attribute are constructed before any // object with no init_priority attribute. #define SOME_INIT_PRIORITY 200 // Priority range [101, 65535]. static __attribute__ ((constructor (SOME_INIT_PRIORITY))) void MyHackForInitWithoutAtExitDestructor ( void ) throw() { // Placement new. new ( some_buffer ) __cxa_eh_globals(); } You would then need a 'get_eh_globals()' wrapper to return a pointer or a reference to a '__cxa_eh_globals' object from 'some_buffer', by doing a type cast. Everybody should then use the wrapper to access that singleton object= .=