https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a985e9b9deabd81e16754584f4397a638e9d3f36
From: Nick Clifton <nickc@redhat.com>
Date: Mon, 5 Feb 2018 09:12:42 +0000
Subject: [PATCH] Import patch from mainline to remove PROVODE qualifiers
around definitions of __CTOR_LIST__ and __DTOR_LIST__ in PE linker scripts.
* scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
__DTOR_LIST__ symbols. Add a comment explaining why this is
* scripttemp/pep.sc: Likewise.
* ld.texinfo (PROVIDE): Add a note about the effect of common
@@ -4001,6 +4001,12 @@ underscore), the linker will silently use the definition in the program.
If the program references @samp{etext} but does not define it, the
linker will use the definition in the linker script.
+Note - the @code{PROVIDE} directive considers a common symbol to be
+defined, even though such a symbol could be combined with the symbol
+that the @code{PROVIDE} would create. This is particularly important
+when considering constructor and destructor list symbols such as
+@samp{__CTOR_LIST__} as these are often defined as common symbols.
@subsection PROVIDE_HIDDEN
--- ld/scripttempl/pe.sc.orig
@@ -98,8 +98,22 @@ SECTIONS
${RELOCATING+*(.glue_7t)}
- PROVIDE(___CTOR_LIST__ = .);
- PROVIDE(__CTOR_LIST__ = .);
+ /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
+ we do not PROVIDE them. This is because the ctors.o startup
+ code in libgcc defines them as common symbols, with the
+ expectation that they will be overridden by the definitions
+ here. If we PROVIDE the symbols then they will not be
+ overridden and global constructors will not be run.
+ This does mean that it is not possible for a user to define
+ their own __CTOR_LIST__ and __DTOR_LIST__ symbols. If that
+ ability is needed a custom linker script will have to be
+ used. (The custom script can just be a copy of this script
+ with the PROVIDE() qualifiers added).
+ See PR 22762 for more details. */
@@ -107,8 +121,10 @@ SECTIONS
- PROVIDE(___DTOR_LIST__ = .);
- PROVIDE(__DTOR_LIST__ = .);