public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] libgcc/crtstuff.c tweaks to reduce code size
@ 2019-11-06 16:14 Jozef Lawrynowicz
  2019-11-06 16:16 ` [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Jozef Lawrynowicz
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-06 16:14 UTC (permalink / raw)
  To: gcc-patches

Some functionality in crtstuff.c will never be used for some targets,
resulting in unnecessary code bloat in the crt* object files.

For example, msp430-elf uses .{init,fini}_array, does not support shared
objects, does not support transactional memory and could be configured
to remove support for exceptions.

Therefore __do_global_dtors_aux(), frame_dummy(),
{,de}register_tm_clones could be safely removed, saving code size.

The following patches implement the generic mechanisms which enable the features
associated with the this functionality to be removed.

Successfully bootstrapped and regtested for x86_64-pc-linx-gnu.
Successfully regtested for msp430-elf.

Ok to apply?

P.S. An MSP430-specific series of patches to make use of the functionality added
here will be submitted separately.

Jozef Lawrynowicz (3):
  libgcc: Add --disable-eh-frame-registry configure option
  libgcc: Dont define __do_global_dtors_aux if it will be empty
  libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE

 gcc/doc/install.texi | 11 +++++++++++
 gcc/doc/tm.texi      | 11 +++++++++++
 gcc/doc/tm.texi.in   | 11 +++++++++++
 libgcc/Makefile.in   |  4 +++-
 libgcc/configure     | 22 ++++++++++++++++++++++
 libgcc/configure.ac  | 17 +++++++++++++++++
 libgcc/crtstuff.c    | 33 +++++++++++++++++++++++----------
 7 files changed, 98 insertions(+), 11 deletions(-)

-- 
2.17.1

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

* [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option
  2019-11-06 16:14 [PATCH 0/3] libgcc/crtstuff.c tweaks to reduce code size Jozef Lawrynowicz
@ 2019-11-06 16:16 ` Jozef Lawrynowicz
  2019-11-06 21:05   ` Jozef Lawrynowicz
  2019-11-06 16:17 ` [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Jozef Lawrynowicz
  2019-11-06 16:19 ` [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE Jozef Lawrynowicz
  2 siblings, 1 reply; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-06 16:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]

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.

[-- Attachment #2: 0001-libgcc-Add-disable-eh-frame-registry-configure-optio.patch --]
[-- Type: text/x-patch, Size: 9021 bytes --]

From 31fdea3564fd0a9a25547df0d5052133d7bdc8a6 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
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  <jozef.l@mittosystems.com>

	* doc/install.texi: Document --disable-eh-frame-registry.

libgcc/ChangeLog:

2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* 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


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

* [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty
  2019-11-06 16:14 [PATCH 0/3] libgcc/crtstuff.c tweaks to reduce code size Jozef Lawrynowicz
  2019-11-06 16:16 ` [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Jozef Lawrynowicz
@ 2019-11-06 16:17 ` Jozef Lawrynowicz
  2019-12-07 18:29   ` Jeff Law
  2019-12-09 12:19   ` Tobias Burnus
  2019-11-06 16:19 ` [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE Jozef Lawrynowicz
  2 siblings, 2 replies; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-06 16:17 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

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

[-- Attachment #2: 0002-libgcc-Dont-define-__do_global_dtors_aux-if-it-will-.patch --]
[-- Type: text/x-patch, Size: 1765 bytes --]

From 967262117f0c838fe8a9226484bf6e014c86f0ba Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
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  <jozef.l@mittosystems.com>

	* 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


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

* [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE
  2019-11-06 16:14 [PATCH 0/3] libgcc/crtstuff.c tweaks to reduce code size Jozef Lawrynowicz
  2019-11-06 16:16 ` [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Jozef Lawrynowicz
  2019-11-06 16:17 ` [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Jozef Lawrynowicz
@ 2019-11-06 16:19 ` Jozef Lawrynowicz
  2019-12-07 18:28   ` Jeff Law
  2 siblings, 1 reply; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-06 16:19 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

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.

[-- Attachment #2: 0003-libgcc-Implement-TARGET_LIBGCC_REMOVE_DSO_HANDLE.patch --]
[-- Type: text/x-patch, Size: 3271 bytes --]

From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
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  <jozef.l@mittosystems.com>

	* doc/tm.texi: Regenerate.
	* doc/tm.texi.in: Define TARGET_LIBGCC_REMOVE_DSO_HANDLE.

libgcc/ChangeLog:

2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* 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<rtx>& @var{outputs}, vec<rtx>& @var{inputs}, vec<const char *>& @var{constraints}, vec<rtx>& @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


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

* Re: [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option
  2019-11-06 16:16 ` [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Jozef Lawrynowicz
@ 2019-11-06 21:05   ` Jozef Lawrynowicz
  0 siblings, 0 replies; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-06 21:05 UTC (permalink / raw)
  To: gcc-patches

On Wed, 6 Nov 2019 16:16:27 +0000
Jozef Lawrynowicz <jozef.l@mittosystems.com> wrote:

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

I retract this patch, since I have found a better solution to the problem this
was going to solve.

Passing "-U__LIBGCC_EH_FRAME_SECTION_NAME__" when building crtstuff.c objects
completely removes references to .eh_frame.

The original patch still resulted in the .eh_frame section being created,
since code to add a 4byte NULL sentinel to the end of the section was retained.

If someone thinks the original patch might still be useful, I can go ahead and
commit it anyway.

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

* Re: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE
  2019-11-06 16:19 ` [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE Jozef Lawrynowicz
@ 2019-12-07 18:28   ` Jeff Law
  2019-12-09 13:05     ` Jozef Lawrynowicz
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Law @ 2019-12-07 18:28 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

On Wed, 2019-11-06 at 16:19 +0000, Jozef Lawrynowicz wrote:
> From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> 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  <jozef.l@mittosystems.com>
> 
> 	* doc/tm.texi: Regenerate.
> 	* doc/tm.texi.in: Define TARGET_LIBGCC_REMOVE_DSO_HANDLE.
> 
> libgcc/ChangeLog:
> 
> 2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> 
> 	* crtstuff.c: Don't declare __dso_handle if
> 	TARGET_LIBGCC_REMOVE_DSO_HANDLE is defined.
Presumably you'll switch this on for your bare elf target
configuration?

Are there other things, particularly related to shared library support,
that we wouldn't need to use as well?  The reason I ask is I'm trying
to figure out if REMOVE_DSO_HANDLE is the right name or if we should
generalize it to a name that indicates shared libraries in general
aren't supported on the target.

Jeff

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

* Re: [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty
  2019-11-06 16:17 ` [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Jozef Lawrynowicz
@ 2019-12-07 18:29   ` Jeff Law
  2019-12-09 12:19   ` Tobias Burnus
  1 sibling, 0 replies; 12+ messages in thread
From: Jeff Law @ 2019-12-07 18:29 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

On Wed, 2019-11-06 at 16:17 +0000, Jozef Lawrynowicz wrote:
> From 967262117f0c838fe8a9226484bf6e014c86f0ba Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> 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  <jozef.l@mittosystems.com>
> 
> 	* crtstuff.c (__do_global_dtors_aux): Wrap in #if so it's only defined
> 	if it will have contents.
Generally OK with this as well.

jeff

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

* Re: [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty
  2019-11-06 16:17 ` [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Jozef Lawrynowicz
  2019-12-07 18:29   ` Jeff Law
@ 2019-12-09 12:19   ` Tobias Burnus
  2019-12-09 12:24     ` Jozef Lawrynowicz
  1 sibling, 1 reply; 12+ messages in thread
From: Tobias Burnus @ 2019-12-09 12:19 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

Hi, I see now the following error:

Â…/libgcc/crtstuff.c:372:52: error: operator '||' has no right operand
   372 |   || USE_TM_CLONE_REGISTRY || USE_EH_FRAME_REGISTRY
       |                                                    ^
/net/build5-trusty-cs/scratch/tburnus/mainline-nv/src/gcc-mainline/libgcc/crtstuff.c:254:17: warning: '__DTOR_LIST__' defined but not used [-Wunused-variable]
   254 | STATIC func_ptr __DTOR_LIST__[1]
       |                 ^~~~~~~~~~~~~
Makefile:1038: recipe for target 'crtbeginT.o' failed

Cheers,

Tobias

On 11/6/19 5:17 PM, Jozef Lawrynowicz wrote:
> __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.
>
> 0002-libgcc-Dont-define-__do_global_dtors_aux-if-it-will-.patch
>
>  From 967262117f0c838fe8a9226484bf6e014c86f0ba Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz<jozef.l@mittosystems.com>
> 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<jozef.l@mittosystems.com>
>
> 	* 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

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

* Re: [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty
  2019-12-09 12:19   ` Tobias Burnus
@ 2019-12-09 12:24     ` Jozef Lawrynowicz
  0 siblings, 0 replies; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-12-09 12:24 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches

On Mon, 9 Dec 2019 13:19:22 +0100
Tobias Burnus <tobias@codesourcery.com> wrote:

> Hi, I see now the following error:
> 
> …/libgcc/crtstuff.c:372:52: error: operator '||' has no right operand
>    372 |   || USE_TM_CLONE_REGISTRY || USE_EH_FRAME_REGISTRY
>        |                                                    ^
> /net/build5-trusty-cs/scratch/tburnus/mainline-nv/src/gcc-mainline/libgcc/crtstuff.c:254:17: warning: '__DTOR_LIST__' defined but not used [-Wunused-variable]
>    254 | STATIC func_ptr __DTOR_LIST__[1]
>        |                 ^~~~~~~~~~~~~
> Makefile:1038: recipe for target 'crtbeginT.o' failed
> 
> Cheers,
> 
> Tobias

Sorry, I need to change that to defined(USE_EH_FRAME_REGISTRY). Committing
shortly.

Thanks,
Jozef

> 
> On 11/6/19 5:17 PM, Jozef Lawrynowicz wrote:
> > __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.
> >
> > 0002-libgcc-Dont-define-__do_global_dtors_aux-if-it-will-.patch
> >
> >  From 967262117f0c838fe8a9226484bf6e014c86f0ba Mon Sep 17 00:00:00 2001
> > From: Jozef Lawrynowicz<jozef.l@mittosystems.com>
> > 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<jozef.l@mittosystems.com>
> >
> > 	* 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  

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

* Re: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE
  2019-12-07 18:28   ` Jeff Law
@ 2019-12-09 13:05     ` Jozef Lawrynowicz
  2019-12-11 11:49       ` Jozef Lawrynowicz
  0 siblings, 1 reply; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-12-09 13:05 UTC (permalink / raw)
  To: Jeff Law

On Sat, 07 Dec 2019 11:27:54 -0700
Jeff Law <law@redhat.com> wrote:

> On Wed, 2019-11-06 at 16:19 +0000, Jozef Lawrynowicz wrote:
> > From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17 00:00:00 2001
> > From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> > 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  <jozef.l@mittosystems.com>
> > 
> > 	* doc/tm.texi: Regenerate.
> > 	* doc/tm.texi.in: Define TARGET_LIBGCC_REMOVE_DSO_HANDLE.
> > 
> > libgcc/ChangeLog:
> > 
> > 2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> > 
> > 	* crtstuff.c: Don't declare __dso_handle if
> > 	TARGET_LIBGCC_REMOVE_DSO_HANDLE is defined.  
> Presumably you'll switch this on for your bare elf target
> configuration?

Yep that's the plan. I originally didn't include the target changes in
this patch since other target changes (disabling __cxa_atexit) were required for
the removal of __dso_handle to be OK.

> 
> Are there other things, particularly related to shared library support,
> that we wouldn't need to use as well?  The reason I ask is I'm trying
> to figure out if REMOVE_DSO_HANDLE is the right name or if we should
> generalize it to a name that indicates shared libraries in general
> aren't supported on the target.

CRTSTUFFS_O is defined when compiling shared versions of crt{begin,end} and
handles an extra case in crtstuff.c where there's some shared library related
functionality we don't need on MSP430.

But when CRTSTUFFS_O is undefined __dso_handle is still declared - to 0. The
comment gives some additional insight:

/* Declare the __dso_handle variable.  It should have a unique value  
   in every shared-object; in a main program its value is zero.  The  
   object should in any case be protected.  This means the instance   
   in one DSO or the main program is not used in another object.  The 
   dynamic linker takes care of this.  */                             

I haven't noticed any further shared library-related bloat coming from libgcc.

I think a better way of solving this problem is just to check
DEFAULT_USE_CXA_ATEXIT rather than adding this new macro. If __cxa_atexit is
not enabled then as far as I understand __dso_handle serves no purpose.
DEFAULT_USE_CXA_ATEXIT is defined at configure time for any targets that want
__cxa_atexit support.

A quick bootstrap and test of dg.exp on x86_64-pc-linux-gnu shows no issues
with the following:

> diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
> index ae6328d317d..349f8191e61 100644
> --- a/libgcc/crtstuff.c
> +++ b/libgcc/crtstuff.c
> @@ -340,8 +340,10 @@ extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
>  #ifdef CRTSTUFFS_O
>  void *__dso_handle = &__dso_handle;
>  #else
> +#if DEFAULT_USE_CXA_ATEXIT
>  void *__dso_handle = 0;
>  #endif
> +#endif
>  
>  /* The __cxa_finalize function may not be available so we use only a
>     weak declaration.  */

I'll put that patch through some more rigorous testing.

Thanks,
Jozef
> 
> Jeff

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

* Re: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE
  2019-12-09 13:05     ` Jozef Lawrynowicz
@ 2019-12-11 11:49       ` Jozef Lawrynowicz
  2019-12-11 18:44         ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: Jozef Lawrynowicz @ 2019-12-11 11:49 UTC (permalink / raw)
  To: Jeff Law

[-- Attachment #1: Type: text/plain, Size: 3576 bytes --]

On Mon, 9 Dec 2019 13:05:22 +0000
Jozef Lawrynowicz <jozef.l@mittosystems.com> wrote:

> On Sat, 07 Dec 2019 11:27:54 -0700
> Jeff Law <law@redhat.com> wrote:
> 
> > On Wed, 2019-11-06 at 16:19 +0000, Jozef Lawrynowicz wrote:  
> > > From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17 00:00:00 2001
> > > From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> > > 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  <jozef.l@mittosystems.com>
> > > 
> > > 	* doc/tm.texi: Regenerate.
> > > 	* doc/tm.texi.in: Define TARGET_LIBGCC_REMOVE_DSO_HANDLE.
> > > 
> > > libgcc/ChangeLog:
> > > 
> > > 2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> > > 
> > > 	* crtstuff.c: Don't declare __dso_handle if
> > > 	TARGET_LIBGCC_REMOVE_DSO_HANDLE is defined.    
> > Presumably you'll switch this on for your bare elf target
> > configuration?  
> 
> Yep that's the plan. I originally didn't include the target changes in
> this patch since other target changes (disabling __cxa_atexit) were required for
> the removal of __dso_handle to be OK.
> 
> > 
> > Are there other things, particularly related to shared library support,
> > that we wouldn't need to use as well?  The reason I ask is I'm trying
> > to figure out if REMOVE_DSO_HANDLE is the right name or if we should
> > generalize it to a name that indicates shared libraries in general
> > aren't supported on the target.  
> 
> CRTSTUFFS_O is defined when compiling shared versions of crt{begin,end} and
> handles an extra case in crtstuff.c where there's some shared library related
> functionality we don't need on MSP430.
> 
> But when CRTSTUFFS_O is undefined __dso_handle is still declared - to 0. The
> comment gives some additional insight:
> 
> /* Declare the __dso_handle variable.  It should have a unique value  
>    in every shared-object; in a main program its value is zero.  The  
>    object should in any case be protected.  This means the instance   
>    in one DSO or the main program is not used in another object.  The 
>    dynamic linker takes care of this.  */                             
> 
> I haven't noticed any further shared library-related bloat coming from libgcc.
> 
> I think a better way of solving this problem is just to check
> DEFAULT_USE_CXA_ATEXIT rather than adding this new macro. If __cxa_atexit is
> not enabled then as far as I understand __dso_handle serves no purpose.
> DEFAULT_USE_CXA_ATEXIT is defined at configure time for any targets that want
> __cxa_atexit support.
> 
> A quick bootstrap and test of dg.exp on x86_64-pc-linux-gnu shows no issues
> with the following:
> 
> > diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
> > index ae6328d317d..349f8191e61 100644
> > --- a/libgcc/crtstuff.c
> > +++ b/libgcc/crtstuff.c
> > @@ -340,8 +340,10 @@ extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
> >  #ifdef CRTSTUFFS_O
> >  void *__dso_handle = &__dso_handle;
> >  #else
> > +#if DEFAULT_USE_CXA_ATEXIT
> >  void *__dso_handle = 0;
> >  #endif
> > +#endif
> >  
> >  /* The __cxa_finalize function may not be available so we use only a
> >     weak declaration.  */  
> 
> I'll put that patch through some more rigorous testing.

Successfully bootstrapped and regtested the attached patch for
x86_64-pc-linux-gnu (where DEFAULT_USE_CXA_ATEXIT is set to 1) and the proposed
msp430-elfbare target (where DEFAULT_USE_CXA_ATEXIT is set to 0).

Ok to apply?
> 
> Thanks,
> Jozef
> > 
> > Jeff  


[-- Attachment #2: 0001-libgcc-Only-define-__dso_handle-if-DEFAULT_USE_CXA_A.patch --]
[-- Type: text/x-patch, Size: 1567 bytes --]

From fc2564803c33229184926a5ac6db62ae36ea8d77 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Mon, 9 Dec 2019 15:20:23 +0000
Subject: [PATCH] libgcc: Only define __dso_handle if DEFAULT_USE_CXA_ATEXIT is
 true

libgcc/ChangeLog:

2019-12-11  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* crtstuff.c: Declare __dso_handle only if DEFAULT_USE_CXA_ATEXIT is
	true.

---
 libgcc/crtstuff.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index 9346cc5ca54..e282cb1aabb 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -325,11 +325,14 @@ register_tm_clones (void)
 
 #ifdef OBJECT_FORMAT_ELF
 
+#if DEFAULT_USE_CXA_ATEXIT
 /* Declare the __dso_handle variable.  It should have a unique value
    in every shared-object; in a main program its value is zero.  The
    object should in any case be protected.  This means the instance
    in one DSO or the main program is not used in another object.  The
-   dynamic linker takes care of this.  */
+   dynamic linker takes care of this.
+   If __cxa_atexit is not being used, __dso_handle will not be used and
+   doesn't need to be defined.  */
 
 #ifdef TARGET_LIBGCC_SDATA_SECTION
 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
@@ -342,6 +345,7 @@ void *__dso_handle = &__dso_handle;
 #else
 void *__dso_handle = 0;
 #endif
+#endif /* DEFAULT_USE_CXA_ATEXIT */
 
 /* The __cxa_finalize function may not be available so we use only a
    weak declaration.  */
-- 
2.17.1


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

* Re: [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE
  2019-12-11 11:49       ` Jozef Lawrynowicz
@ 2019-12-11 18:44         ` Jeff Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Law @ 2019-12-11 18:44 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: gcc-patches

On Wed, 2019-12-11 at 11:49 +0000, Jozef Lawrynowicz wrote:
> On Mon, 9 Dec 2019 13:05:22 +0000
> Jozef Lawrynowicz <jozef.l@mittosystems.com> wrote:
> 
> > On Sat, 07 Dec 2019 11:27:54 -0700
> > Jeff Law <law@redhat.com> wrote:
> > 
> > > On Wed, 2019-11-06 at 16:19 +0000, Jozef Lawrynowicz wrote:  
> > > > From 7bc0971d2936ebe71e7b7d3d805cf1bbf9f9f5af Mon Sep 17
> > > > 00:00:00 2001
> > > > From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> > > > 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  <jozef.l@mittosystems.com>
> > > > 
> > > > 	* doc/tm.texi: Regenerate.
> > > > 	* doc/tm.texi.in: Define
> > > > TARGET_LIBGCC_REMOVE_DSO_HANDLE.
> > > > 
> > > > libgcc/ChangeLog:
> > > > 
> > > > 2019-11-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> > > > 
> > > > 	* crtstuff.c: Don't declare __dso_handle if
> > > > 	TARGET_LIBGCC_REMOVE_DSO_HANDLE is defined.    
> > > Presumably you'll switch this on for your bare elf target
> > > configuration?  
> > 
> > Yep that's the plan. I originally didn't include the target changes
> > in
> > this patch since other target changes (disabling __cxa_atexit) were
> > required for
> > the removal of __dso_handle to be OK.
> > 
> > > Are there other things, particularly related to shared library
> > > support,
> > > that we wouldn't need to use as well?  The reason I ask is I'm
> > > trying
> > > to figure out if REMOVE_DSO_HANDLE is the right name or if we
> > > should
> > > generalize it to a name that indicates shared libraries in
> > > general
> > > aren't supported on the target.  
> > 
> > CRTSTUFFS_O is defined when compiling shared versions of
> > crt{begin,end} and
> > handles an extra case in crtstuff.c where there's some shared
> > library related
> > functionality we don't need on MSP430.
> > 
> > But when CRTSTUFFS_O is undefined __dso_handle is still declared -
> > to 0. The
> > comment gives some additional insight:
> > 
> > /* Declare the __dso_handle variable.  It should have a unique
> > value  
> >    in every shared-object; in a main program its value is
> > zero.  The  
> >    object should in any case be protected.  This means the
> > instance   
> >    in one DSO or the main program is not used in another
> > object.  The 
> >    dynamic linker takes care of
> > this.  */                             
> > 
> > I haven't noticed any further shared library-related bloat coming
> > from libgcc.
> > 
> > I think a better way of solving this problem is just to check
> > DEFAULT_USE_CXA_ATEXIT rather than adding this new macro. If
> > __cxa_atexit is
> > not enabled then as far as I understand __dso_handle serves no
> > purpose.
> > DEFAULT_USE_CXA_ATEXIT is defined at configure time for any targets
> > that want
> > __cxa_atexit support.
> > 
> > A quick bootstrap and test of dg.exp on x86_64-pc-linux-gnu shows
> > no issues
> > with the following:
> > 
> > > diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
> > > index ae6328d317d..349f8191e61 100644
> > > --- a/libgcc/crtstuff.c
> > > +++ b/libgcc/crtstuff.c
> > > @@ -340,8 +340,10 @@ extern void *__dso_handle __attribute__
> > > ((__visibility__ ("hidden")));
> > >  #ifdef CRTSTUFFS_O
> > >  void *__dso_handle = &__dso_handle;
> > >  #else
> > > +#if DEFAULT_USE_CXA_ATEXIT
> > >  void *__dso_handle = 0;
> > >  #endif
> > > +#endif
> > >  
> > >  /* The __cxa_finalize function may not be available so we use
> > > only a
> > >     weak declaration.  */  
> > 
> > I'll put that patch through some more rigorous testing.
> 
> Successfully bootstrapped and regtested the attached patch for
> x86_64-pc-linux-gnu (where DEFAULT_USE_CXA_ATEXIT is set to 1) and
> the proposed
> msp430-elfbare target (where DEFAULT_USE_CXA_ATEXIT is set to 0).
> 
> > libgcc/ChangeLog:
> > 
> > 2019-12-11  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> > 
> > 	* crtstuff.c: Declare __dso_handle only if
> > DEFAULT_USE_CXA_ATEXIT is
> > 	true.
OK
jeff

ps.  Sorry about the formatting.  Had to switch MUAs last week and
still haven't gotten all the kinks worked out.

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

end of thread, other threads:[~2019-12-11 18:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-06 16:14 [PATCH 0/3] libgcc/crtstuff.c tweaks to reduce code size Jozef Lawrynowicz
2019-11-06 16:16 ` [PATCH 1/3] libgcc: Add --disable-eh-frame-registry configure option Jozef Lawrynowicz
2019-11-06 21:05   ` Jozef Lawrynowicz
2019-11-06 16:17 ` [PATCH 2/3] libgcc: Dont define __do_global_dtors_aux if it will be empty Jozef Lawrynowicz
2019-12-07 18:29   ` Jeff Law
2019-12-09 12:19   ` Tobias Burnus
2019-12-09 12:24     ` Jozef Lawrynowicz
2019-11-06 16:19 ` [PATCH 3/3] libgcc: Implement TARGET_LIBGCC_REMOVE_DSO_HANDLE Jozef Lawrynowicz
2019-12-07 18:28   ` Jeff Law
2019-12-09 13:05     ` Jozef Lawrynowicz
2019-12-11 11:49       ` Jozef Lawrynowicz
2019-12-11 18:44         ` Jeff Law

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