From patchwork Wed Nov 6 16:16:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 1190537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512623-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="imsMoJio"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mittosystems.com header.i=@mittosystems.com header.b="IYQcevPM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477WrG0lkSz9sP6 for ; Thu, 7 Nov 2019 03:16:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=t366R366Isxz00amv/+PeHtdaZA5T jwTwMQuQDc1lZ9q+l6eZ5ocnC8mE4TiWAbn4FWUftFGPy8CxX+K3QHZv8qyvUh3G Cw+co2gVdy7R1Z2A5QTkHaInraVO3OyqM9YA97czoqQq52VOgf4iS1dLDyL30b8P 8wzkTIDd09Llqk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=jNVv2cyGc5FcwvnzxhZcTkxR1iI=; b=ims MoJioI3C2QONRpDIRTwbtuWYnmZH6bDhCwncXIEvNsUqYNqZ9Cs+eewDOtshz+ld M4/VL9RKnix129TrFAzP6Wxq/NOtN0oThwqLGZ2P2eCFfsqvCnWNU1zy+Y45GV4q xk5TZ7HCGH4NmmuUZR/jRNJ5NwAC2jZCX/aj5mWw= Received: (qmail 65286 invoked by alias); 6 Nov 2019 16:16:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 65227 invoked by uid 89); 6 Nov 2019 16:16:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=thereby, 3037 X-HELO: mail-wm1-f53.google.com Received: from mail-wm1-f53.google.com (HELO mail-wm1-f53.google.com) (209.85.128.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Nov 2019 16:16:31 +0000 Received: by mail-wm1-f53.google.com with SMTP id c17so4220113wmk.2 for ; Wed, 06 Nov 2019 08:16:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:in-reply-to:references:mime-version; bh=uEPYrSHOwQkGFCqGmI+oKkwRcg6jMPkf5so25DVr4KQ=; b=IYQcevPMU0ooK3AxaCQbhVjUgsAUpSSH1fsmVSNMa/d+zmTqpZjtYT/hmwm3+QCycm vxl7YlfxV//7SV8OXgFMVHu1grcAqPIeGhpvIjVlUBdHjbLvnsYiruLuPaD5IVjxHVm/ SR1qbDfvIUSCsdvZGuve26Z1fsryFAzwKRu6QRF4L8/t+09q2WwfFDS4ANWDlhGQMAm6 1cDmx4rYeMH5fVrdRXli1L5j107lL+RxVZBNIwY0OzOCrLcnPGR8ADUDVJTSANz9PRL8 X/aMa0/NUx6DZTpYgP3gdX99ESJZls0dZ6CEqwxMgSRo6e+6F/VZMiPAZ0Pl7YJQI5wm fTkg== Received: from jozef-kubuntu ([2a01:4b00:87fd:900:e1ba:1c62:d07d:e2d4]) by smtp.gmail.com with ESMTPSA id l2sm23340513wrt.15.2019.11.06.08.16.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Nov 2019 08:16:28 -0800 (PST) Date: Wed, 6 Nov 2019 16:16:27 +0000 From: Jozef Lawrynowicz To: "gcc-patches@gcc.gnu.org" Subject: [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Message-ID: <20191106161627.0cd62fdf@jozef-kubuntu> In-Reply-To: <20191106161420.2e16dba9@jozef-kubuntu> References: <20191106161420.2e16dba9@jozef-kubuntu> MIME-Version: 1.0 X-IsSubscribed: yes The attached patch enables the EH Frame Registry to be explicitly disabled with a configure option "-disable-eh-frame-registry", thereby removing code to support it in crtstuff.c Default behaviour is unchanged since USE_EH_FRAME_REGISTRY was previously referenced only internally in crtstuff.c, and now is only defined to 0 when it would previously have not been defined at all. From 31fdea3564fd0a9a25547df0d5052133d7bdc8a6 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Tue, 29 Oct 2019 12:55:11 +0000 Subject: [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option gcc/ChangeLog: 2019-11-06 Jozef Lawrynowicz * doc/install.texi: Document --disable-eh-frame-registry. libgcc/ChangeLog: 2019-11-06 Jozef Lawrynowicz * Makefile.in: Add USE_EH_FRAME_REGISTRY variable. Use USE_EH_FRAME_REGISTRY variable in CRTSTUFF_CFLAGS. * configure: Regenerate. * configure.ac: Support --disable-eh-frame-registry. * crtstuff.c [!USE_EH_FRAME_REGISTRY]: Define USE_EH_FRAME_REGISTRY. s/#ifdef USE_EH_FRAME_REGISTRY/#if USE_EH_FRAME_REGISTRY/. s/#if defined(USE_EH_FRAME_REGISTRY)/#if USE_EH_FRAME_REGISTRY/. --- gcc/doc/install.texi | 11 +++++++++++ libgcc/Makefile.in | 4 +++- libgcc/configure | 22 ++++++++++++++++++++++ libgcc/configure.ac | 17 +++++++++++++++++ libgcc/crtstuff.c | 22 +++++++++++++--------- 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 563de705881..af61a34a477 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1314,6 +1314,17 @@ Disable TM clone registry in libgcc. It is enabled in libgcc by default. This option helps to reduce code size for embedded targets which do not use transactional memory. +@item --disable-eh-frame-registry +Disable the EH frame registry in libgcc. It is enabled in libgcc by default +for most ELF targets. + +This should not be used unless exceptions have been disabled for the target +configuration. + +This option reduces code size by removing functionality to register the +exception handling frame information that would normally run before +@samp{main()}. + @item --with-cpu=@var{cpu} @itemx --with-cpu-32=@var{cpu} @itemx --with-cpu-64=@var{cpu} diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 5608352a900..59f7f3cc381 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,8 @@ CET_FLAGS = @CET_FLAGS@ USE_TM_CLONE_REGISTRY = @use_tm_clone_registry@ +USE_EH_FRAME_REGISTRY = @use_eh_frame_registry@ + # Defined in libgcc2.c, included only in the static library. LIB2FUNCS_ST = _eprintf __gcc_bcmp @@ -301,7 +303,7 @@ CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \ $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \ -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \ -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \ - $(INHIBIT_LIBC_CFLAGS) $(USE_TM_CLONE_REGISTRY) + $(INHIBIT_LIBC_CFLAGS) $(USE_TM_CLONE_REGISTRY) $(USE_EH_FRAME_REGSITRY) # Extra flags to use when compiling crt{begin,end}.o. CRTSTUFF_T_CFLAGS = diff --git a/libgcc/configure b/libgcc/configure index 117e9c97e57..341c609252e 100755 --- a/libgcc/configure +++ b/libgcc/configure @@ -605,6 +605,7 @@ solaris_ld_v2_maps real_host_noncanonical accel_dir_suffix use_tm_clone_registry +use_eh_frame_registry force_explicit_eh_registry CET_FLAGS fixed_point @@ -713,6 +714,7 @@ enable_decimal_float with_system_libunwind enable_cet enable_explicit_exception_frame_registration +enable_eh_frame_registry enable_tm_clone_registry with_glibc_version enable_tls @@ -1357,6 +1359,7 @@ Optional Features: register exception tables explicitly at module start, for use e.g. for compatibility with installations without PT_GNU_EH_FRAME support + --disable-eh-frame-registry disable EH frame registry --disable-tm-clone-registry disable TM clone registry --enable-tls Use thread-local storage [default=yes] @@ -4956,6 +4959,25 @@ fi +# EH Frame Registry is implicitly enabled by default (although it is not +# "forced"), and libgcc/crtstuff.c will setup the support for it if it is +# supported by the target. So we don't handle --enable-eh-frame-registry. +# Check whether --enable-eh-frame-registry was given. +if test "${enable_eh_frame_registry+set}" = set; then : + enableval=$enable_eh_frame_registry; +use_eh_frame_registry= +if test "$enable_eh_frame_registry" = no; then + if test "$enable_explicit_exception_frame_registration" = yes; then + as_fn_error $? "Can't --disable-eh-frame-registry with + with --enable-explicit-exception-frame-registration" "$LINENO" 5 + fi + use_eh_frame_registry=-DUSE_EH_FRAME_REGISTRY=0 +fi + +fi + + + # Check whether --enable-tm-clone-registry was given. if test "${enable_tm_clone_registry+set}" = set; then : enableval=$enable_tm_clone_registry; diff --git a/libgcc/configure.ac b/libgcc/configure.ac index f63c5e736e5..cf2eb9c984a 100644 --- a/libgcc/configure.ac +++ b/libgcc/configure.ac @@ -261,6 +261,23 @@ fi ]) AC_SUBST([force_explicit_eh_registry]) +# EH Frame Registry is implicitly enabled by default (although it is not +# "forced"), and libgcc/crtstuff.c will setup the support for it if it is +# supported by the target. So we don't handle --enable-eh-frame-registry. +AC_ARG_ENABLE([eh-frame-registry], +[ --disable-eh-frame-registry disable EH frame registry], +[ +use_eh_frame_registry= +if test "$enable_eh_frame_registry" = no; then + if test "$enable_explicit_exception_frame_registration" = yes; then + AC_MSG_ERROR([Can't --disable-eh-frame-registry with + with --enable-explicit-exception-frame-registration]) + fi + use_eh_frame_registry=-DUSE_EH_FRAME_REGISTRY=0 +fi +]) +AC_SUBST([use_eh_frame_registry]) + AC_ARG_ENABLE([tm-clone-registry], [ --disable-tm-clone-registry disable TM clone registry], [ diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c index ae6328d317d..9a3247b7848 100644 --- a/libgcc/crtstuff.c +++ b/libgcc/crtstuff.c @@ -136,9 +136,13 @@ call_ ## FUNC (void) \ # error "Can't use explicit exception-frame-registration without __LIBGCC_EH_FRAME_SECTION_NAME__" # endif #endif +#ifndef USE_EH_FRAME_REGISTRY #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) && (!defined(USE_PT_GNU_EH_FRAME) || defined(USE_EH_FRAME_REGISTRY_ALWAYS)) -# define USE_EH_FRAME_REGISTRY +# define USE_EH_FRAME_REGISTRY 1 +#else +# define USE_EH_FRAME_REGISTRY 0 #endif +#endif /* USE_EH_FRAME_REGISTRY */ #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) \ && __LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__ # define EH_FRAME_SECTION_CONST const @@ -257,7 +261,7 @@ STATIC func_ptr __DTOR_LIST__[1] #endif /* __DTOR_LIST__ alternatives */ #endif /* USE_INITFINI_ARRAY */ -#ifdef USE_EH_FRAME_REGISTRY +#if USE_EH_FRAME_REGISTRY /* Stick a label at the beginning of the frame unwind info so we can register and deregister it with the exception handling library code. */ STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[] @@ -412,7 +416,7 @@ __do_global_dtors_aux (void) deregister_tm_clones (); #endif /* USE_TM_CLONE_REGISTRY */ -#ifdef USE_EH_FRAME_REGISTRY +#if USE_EH_FRAME_REGISTRY #ifdef CRT_GET_RFIB_DATA /* If we used the new __register_frame_info_bases interface, make sure that we deregister from the same place. */ @@ -452,7 +456,7 @@ CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, __do_global_dtors_aux_1) #endif -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY /* Stick a call to __register_frame_info into the .init section. For some reason calls with no arguments work more reliably in .init, so stick the call in another function. */ @@ -460,7 +464,7 @@ CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, static void __attribute__((used)) frame_dummy (void) { -#ifdef USE_EH_FRAME_REGISTRY +#if USE_EH_FRAME_REGISTRY static struct object object; #ifdef CRT_GET_RFIB_DATA void *tbase, *dbase; @@ -555,13 +559,13 @@ __do_global_dtors (void) deregister_tm_clones (); #endif /* USE_TM_CLONE_REGISTRY */ -#ifdef USE_EH_FRAME_REGISTRY +#if USE_EH_FRAME_REGISTRY if (__deregister_frame_info) __deregister_frame_info (__EH_FRAME_BEGIN__); #endif } -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY /* A helper function for __do_global_ctors, which is in crtend.o. Here in crtbegin.o, we can reference a couple of symbols not visible there. Plus, since we're before libgcc.a, we have no problems referencing @@ -569,7 +573,7 @@ __do_global_dtors (void) void __do_global_ctors_1(void) { -#ifdef USE_EH_FRAME_REGISTRY +#if USE_EH_FRAME_REGISTRY static struct object object; if (__register_frame_info) __register_frame_info (__EH_FRAME_BEGIN__, &object); @@ -733,7 +737,7 @@ void __do_global_ctors (void) { func_ptr *p; -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY __do_global_ctors_1(); #endif for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) -- 2.17.1 From patchwork Wed Nov 6 16:17:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 1190538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512624-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oaHvPUxF"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mittosystems.com header.i=@mittosystems.com header.b="gdl+ysUD"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477Wsn2Q3Hz9sP6 for ; Thu, 7 Nov 2019 03:18:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=ux3jxTSNjnqUZI28p2fNa3gB4Tpy/ RJzG4GOqIvur5ggHjXVpBy1RkiTHKLRaJI2Mup1fEynzWRWTHZY/r9n7zt5jyXwj f8QNlFhtkwrb4lA9oSBz8JoLe/hJvb+pBIRk1waDC2k4gh+qH/h/6/IQF7iOubK1 ab+RSfKiG/7oIw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=R+C6VXpnMU5cWzwbwyi/vMYkLzg=; b=oaH vPUxFuMsdJJO+4kv45VIn6/3KQxEVRimY6cKmlTiAJv8H1x1PtFRSRBy0ww305iL wh4UH23zHs5/vfxo5jLocMppS8nMthFKfmMvnR3v7JXhlfDQLDgvMecrrTRCt4Nn cNqyuUcie9ugX9sT9OIJBEAcYHnAz2PuBF9gZy0g= Received: (qmail 67520 invoked by alias); 6 Nov 2019 16:17:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67504 invoked by uid 89); 6 Nov 2019 16:17:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=arrange X-HELO: mail-wm1-f43.google.com Received: from mail-wm1-f43.google.com (HELO mail-wm1-f43.google.com) (209.85.128.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Nov 2019 16:17:54 +0000 Received: by mail-wm1-f43.google.com with SMTP id 8so4103938wmo.0 for ; Wed, 06 Nov 2019 08:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:in-reply-to:references:mime-version; bh=7uIbCOGYhyNmyiHAAXPsyTDv9IWNQ56UvrQz07++Id4=; b=gdl+ysUDjYcdvdSnYcwXUB/42OayB1eDnm68/nhqTuVlfbDYAidNq/VcR56XOrezcp X2iu2U6uHeR+ounSx7rtDmOGzpsSuoOCP4r0BaEwxU07rWdxJc3LRJWms/mfEu8wgKQt W3WLERVmHbmYDOWLb5kljbsz6bA32nkjXDiZIfgiFmJJi/HwPHJsiF/wTRiCThPPMA/Y frwFgYnGtsEJskhBfIcJoB5MtwHr7Xc1bNtWLQRWT3W5dB1hSagjtMImQOpIe+Gt+tl5 xbdiEiPFRi4rdadvHCatO+0uvI/QmKU6Fm+KuOyFmcHeHM2v98uZgMbGR8h8imU5m5Qn dM5Q== Received: from jozef-kubuntu ([2a01:4b00:87fd:900:e1ba:1c62:d07d:e2d4]) by smtp.gmail.com with ESMTPSA id x8sm24847091wrr.43.2019.11.06.08.17.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Nov 2019 08:17:52 -0800 (PST) Date: Wed, 6 Nov 2019 16:17:50 +0000 From: Jozef Lawrynowicz To: "gcc-patches@gcc.gnu.org" Subject: [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Message-ID: <20191106161750.0ac390fe@jozef-kubuntu> In-Reply-To: <20191106161420.2e16dba9@jozef-kubuntu> References: <20191106161420.2e16dba9@jozef-kubuntu> MIME-Version: 1.0 X-IsSubscribed: yes __do_global_dtors_aux in crtstuff.c will not do anything meaningful if: * crtstuff.c is not being compiled for use in a shared library * the target uses .{init,fini}_array sections * TM clone registry is disabled * EH frame registry is disabled The attached patch prevents it from being defined at all if all the above conditions are true. This saves code size in the final linked executable. From 967262117f0c838fe8a9226484bf6e014c86f0ba Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Tue, 29 Oct 2019 13:02:08 +0000 Subject: [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty libgcc/ChangeLog: 2019-11-06 Jozef Lawrynowicz * crtstuff.c (__do_global_dtors_aux): Wrap in #if so it's only defined if it will have contents. --- libgcc/crtstuff.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c index 9a3247b7848..0b0a0b865fe 100644 --- a/libgcc/crtstuff.c +++ b/libgcc/crtstuff.c @@ -368,8 +368,12 @@ extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK; On some systems, this routine is run more than once from the .fini, when exit is called recursively, so we arrange to remember where in the list we left off processing, and we resume at that point, - should we be re-invoked. */ + should we be re-invoked. + This routine does not need to be run if none of the following clauses are + true, as it will not do anything, so can be removed. */ +#if defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) \ + || USE_TM_CLONE_REGISTRY || USE_EH_FRAME_REGISTRY static void __attribute__((used)) __do_global_dtors_aux (void) { @@ -455,6 +459,9 @@ __do_global_dtors_aux_1 (void) CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, __do_global_dtors_aux_1) #endif +#endif /* defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) + || defined(USE_TM_CLONE_REGISTRY) || defined(USE_EH_FRAME_REGISTRY) */ + #if USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY /* Stick a call to __register_frame_info into the .init section. For some -- 2.17.1 From patchwork Wed Nov 6 16:19:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 1190539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512625-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IWf8QhaC"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mittosystems.com header.i=@mittosystems.com header.b="POE+A686"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477Wvf5HcFz9sP6 for ; Thu, 7 Nov 2019 03:19:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=eEHkkWDiHYoqkCMcjpZ5aQGN8hazR dSqdCP3f9uMkA87nAoXwTVCMR+k1L970t51PrOwUXC942R2yvmQ0DFZpJamqZ/sG lAIBCVXeKrOxNgQqIaqFJxtTaz9nWWqgT+JVlR3HIdH8s1EAjiQew1TFrWUedmDf un2L3rx75N/Pk8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=S9Gyi67hDo1eH8epQ05q/nD3CQs=; b=IWf 8QhaC3/HsSlPLYTKEHbgOWWyb3VGN36cCJNrqIUomTS7PBIZ2ZihxSTQQAjLZSFd plrZuIW++mjRqN7loEKcGZ1rMTfVjAM/3gdhYeA+MBWn26ZTFB98bwu99WAIXbki 1X24JMXmd2R7r14CIGKCQZK8le5ePuUVnAefhTvA= Received: (qmail 71270 invoked by alias); 6 Nov 2019 16:19:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 71257 invoked by uid 89); 6 Nov 2019 16:19:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f47.google.com Received: from mail-wm1-f47.google.com (HELO mail-wm1-f47.google.com) (209.85.128.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Nov 2019 16:19:32 +0000 Received: by mail-wm1-f47.google.com with SMTP id z26so4209936wmi.4 for ; Wed, 06 Nov 2019 08:19:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:in-reply-to:references:mime-version; bh=OvDr4Pl8buGmXAZgUUH40JNAreeemoG/KTu2+o2kbe4=; b=POE+A6861lyK6B4j6Ncgtk7tdZJJFr4HlIJGDeH3Wll8+9uTOmx8uyvbtBDMfirLhY qVYML/z5GUrf3dM3mwgjgl/SDK46/BLK6ruVI+a4XROzREjwwxTvNixg+uZfsaooADz+ 5DDIFlUfRZGgGBiPqLkGSXS934k41lVU2hsnK1bCLTtZsTuU1zXolq2kAiS0hfMkvN6O KWdNZ21mkqd1I/0ZsHlFuHW+k9sHuv+N2QTvmxGc4ZCTAPUl9Mv3s6Dqwo8XxGFVWzCY HanGYDqnkSykc8kYX7KfHftToWnxOWaPY3EJMpOQUMiLIArsWIPRKRlWIcALJnpNT8Qv iQoQ== Received: from jozef-kubuntu ([2a01:4b00:87fd:900:e1ba:1c62:d07d:e2d4]) by smtp.gmail.com with ESMTPSA id w4sm2923448wmi.39.2019.11.06.08.19.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Nov 2019 08:19:30 -0800 (PST) Date: Wed, 6 Nov 2019 16:19:28 +0000 From: Jozef Lawrynowicz To: "gcc-patches@gcc.gnu.org" Subject: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE Message-ID: <20191106161928.227fd9ae@jozef-kubuntu> In-Reply-To: <20191106161420.2e16dba9@jozef-kubuntu> References: <20191106161420.2e16dba9@jozef-kubuntu> MIME-Version: 1.0 X-IsSubscribed: yes For some targets __dso_handle will never be used, and its definition in crtstuff.c can cause a domino effect resulting in the size of the final executable increasing much more than just the size of this piece of data. For msp430, CRT functions to initialize global data are only included if there is global data to initialize and it is more than feasible to write functional programs which do not use any global data. In these cases, the definition of __dso_handle will cause code size to increase by around 100 bytes as library code to initialize data is linked into the executable. Removing __dso_handle can therefore save on code size. This does require the target to NOT use __cxa_atexit, so either TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT must return true or -fno-use-cxa-atexit must be used as a target flag when building GCC. This is because __cxa_atexit includes functionality to unload dynamic shared objects and so cp/decl.c will create a reference to __dso_handle to facilitate this in programs with static destructors. From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Mon, 4 Nov 2019 17:38:13 +0000 Subject: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE gcc/ChangeLog: 2019-11-06 Jozef Lawrynowicz * doc/tm.texi: Regenerate. * doc/tm.texi.in: Define TARGET_LIBGCC_REMOVE_DSO_HANDLE. libgcc/ChangeLog: 2019-11-06 Jozef Lawrynowicz * crtstuff.c: Don't declare __dso_handle if TARGET_LIBGCC_REMOVE_DSO_HANDLE is defined. --- gcc/doc/tm.texi | 11 +++++++++++ gcc/doc/tm.texi.in | 11 +++++++++++ libgcc/crtstuff.c | 2 ++ 3 files changed, 24 insertions(+) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index cd9aed9874f..89ef0a8e616 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -11425,6 +11425,17 @@ from shared libraries (DLLs). You need not define this macro if it would always evaluate to zero. @end defmac +@defmac TARGET_LIBGCC_REMOVE_DSO_HANDLE +Define this macro if, for targets where dynamic shared objects cannot be used, +the declaration of @samp{__dso_handle} in libgcc/crtstuff.c can be removed. + +If this macro is defined, __cxa_atexit must be disabled at GCC configure time, +otherwise references to __dso_handle will be created when the middle-end +creates destructors for static objects. + +This macro is undefined by default. +@end defmac + @deftypefn {Target Hook} {rtx_insn *} TARGET_MD_ASM_ADJUST (vec& @var{outputs}, vec& @var{inputs}, vec& @var{constraints}, vec& @var{clobbers}, HARD_REG_SET& @var{clobbered_regs}) This target hook may add @dfn{clobbers} to @var{clobbers} and @var{clobbered_regs} for any hard regs the port wishes to automatically diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 2739e9ceec5..3a211a7658a 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7853,6 +7853,17 @@ from shared libraries (DLLs). You need not define this macro if it would always evaluate to zero. @end defmac +@defmac TARGET_LIBGCC_REMOVE_DSO_HANDLE +Define this macro if, for targets where dynamic shared objects cannot be used, +the declaration of @samp{__dso_handle} in libgcc/crtstuff.c can be removed. + +If this macro is defined, __cxa_atexit must be disabled at GCC configure time, +otherwise references to __dso_handle will be created when the middle-end +creates destructors for static objects. + +This macro is undefined by default. +@end defmac + @hook TARGET_MD_ASM_ADJUST @defmac MATH_LIBRARY diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c index 0b0a0b865fe..d1d17f959d3 100644 --- a/libgcc/crtstuff.c +++ b/libgcc/crtstuff.c @@ -335,6 +335,7 @@ register_tm_clones (void) in one DSO or the main program is not used in another object. The dynamic linker takes care of this. */ +#ifndef TARGET_LIBGCC_REMOVE_DSO_HANDLE #ifdef TARGET_LIBGCC_SDATA_SECTION extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION))); #endif @@ -346,6 +347,7 @@ void *__dso_handle = &__dso_handle; #else void *__dso_handle = 0; #endif +#endif /* TARGET_LIBGCC_REMOVE_DSO_HANDLE */ /* The __cxa_finalize function may not be available so we use only a weak declaration. */ -- 2.17.1