From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 9DDF73858403 for ; Sat, 13 Nov 2021 15:16:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9DDF73858403 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 8B259280872; Sat, 13 Nov 2021 16:16:11 +0100 (CET) Date: Sat, 13 Nov 2021 16:16:11 +0100 From: Jan Hubicka To: Iain Sandoe Cc: GCC Patches , Richard Biener Subject: Re: [PATCH v2] IPA: Provide a mechanism to register static DTORs via cxa_atexit. Message-ID: <20211113151611.GA38289@kam.mff.cuni.cz> References: <20211104204645.25097-1-iain@sandoe.co.uk> <3846F6D3-7701-4162-89A4-FB7C252C802F@gmail.com> <1F3A5D86-7684-4AF7-A26B-81CA96E4468E@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1F3A5D86-7684-4AF7-A26B-81CA96E4468E@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Nov 2021 15:16:14 -0000 > sheesh … EWRONGREVISEDPATCH > > > On 5 Nov 2021, at 13:08, Iain Sandoe wrote: > > > > I tried enabling this on x86-64-linux (just for interest) and it seems to work > > OK there too - but that testing revealed a thinko that didn’t show with a > > a normal regstrap. > > … now with the correct patch. > > [PATCH v2] IPA: Provide a mechanism to register static DTORs via > cxa_atexit. > > For at least one target (Darwin) the platform convention is to > register static destructors (i.e. __attribute__((destructor))) > with __cxa_atexit rather than placing them into a list that is > run by some other mechanism. > > This patch provides a target hook that allows a target to opt > into this and handling for the process in ipa_cdtor_merge (). > > When the mode is enabled (dtors_from_cxa_atexit is set) we: > > * Generate new CTORs to register static destructors with > __cxa_atexit and add them to the existing list of CTORs; > we then process the revised CTORs list. > > * We sort the DTORs into priority and then TU order, this > means that they are registered in that order with > __cxa_atexit () and therefore will be run in the reverse > order. > > * Likewise, CTORs are sorted into priority and then TU order, > which means that they will run in that order. > > This matches the behavior of using init/fini (or > mod_init_func/mod_term_func) sections. > > Signed-off-by: Iain Sandoe > > gcc/ChangeLog: > > * config/darwin.h (TARGET_DTORS_FROM_CXA_ATEXIT): New. > * doc/tm.texi: Regenerated. > * doc/tm.texi.in: Add TARGET_DTORS_FROM_CXA_ATEXIT hook. > * ipa.c (ipa_discover_variable_flags): > (cgraph_build_static_cdtor_1): Return the built function > decl. > (build_cxa_atexit_decl): New. > (build_dso_handle_decl): New. > (build_cxa_dtor_registrations): New. > (compare_cdtor_tu_order): New. > (build_cxa_atexit_fns): New. > (ipa_cdtor_merge): If dtors_from_cxa_atexit is set, > process the DTORs/CTORs accordingly. > (pass_ipa_cdtor_merge::gate): Also run if > dtors_from_cxa_atexit is set. > * target.def (dtors_from_cxa_atexit): New hook. OK, thanks! Honza