Blame SOURCES/0001-Remove-PROVIDE-qualifiers.patch

2d9895
From a985e9b9deabd81e16754584f4397a638e9d3f36 Mon Sep 17 00:00:00 2001
2d9895
From: Nick Clifton <nickc@redhat.com>
2d9895
Date: Mon, 5 Feb 2018 09:12:42 +0000
2d9895
Subject: [PATCH] Import patch from mainline to remove PROVODE qualifiers
2d9895
 around definitions of __CTOR_LIST__ and __DTOR_LIST__ in PE linker scripts.
2d9895
2d9895
	PR 22762
2d9895
	* scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
2d9895
	__DTOR_LIST__ symbols.  Add a comment explaining why this is
2d9895
	necessary.
2d9895
	* scripttemp/pep.sc: Likewise.
2d9895
	* ld.texinfo (PROVIDE): Add a note about the effect of common
2d9895
	symbols.
2d9895
---
2d9895
 ld/ChangeLog          | 14 ++++++++++++++
2d9895
 ld/ld.texinfo         |  6 ++++++
2d9895
 ld/scripttempl/pe.sc  | 24 ++++++++++++++++++++----
2d9895
 ld/scripttempl/pep.sc | 24 ++++++++++++++++++++----
2d9895
 4 files changed, 60 insertions(+), 8 deletions(-)
2d9895
2d9895
diff --git a/ld/ChangeLog b/ld/ChangeLog
2d9895
index 0f00265029c..bf129a121cc 100644
2d9895
--- a/ld/ChangeLog
2d9895
+++ b/ld/ChangeLog
2d9895
@@ -1,3 +1,17 @@
2d9895
+2018-02-05  Nick Clifton  <nickc@redhat.com>
2d9895
+
2d9895
+	Import from mainline:
2d9895
+
2d9895
+	2018-02-03  Nick Clifton  <nickc@redhat.com>
2d9895
+
2d9895
+	PR 22762
2d9895
+	* scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
2d9895
+	__DTOR_LIST__ symbols.  Add a comment explaining why this is
2d9895
+	necessary.
2d9895
+	* scripttemp/pep.sc: Likewise.
2d9895
+	* ld.texinfo (PROVIDE): Add a note about the effect of common
2d9895
+	symbols.
2d9895
+
2d9895
 2018-01-27  Nick Clifton  <nickc@redhat.com>
2d9895
 
2d9895
 	This is the 2.30 release:
2d9895
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
2d9895
index c89915f1aaa..764c4017c7b 100644
2d9895
--- a/ld/ld.texinfo
2d9895
+++ b/ld/ld.texinfo
2d9895
@@ -4001,6 +4001,12 @@ underscore), the linker will silently use the definition in the program.
2d9895
 If the program references @samp{etext} but does not define it, the
2d9895
 linker will use the definition in the linker script.
2d9895
 
2d9895
+Note - the @code{PROVIDE} directive considers a common symbol to be
2d9895
+defined, even though such a symbol could be combined with the symbol
2d9895
+that the @code{PROVIDE} would create.  This is particularly important
2d9895
+when considering constructor and destructor list symbols such as
2d9895
+@samp{__CTOR_LIST__} as these are often defined as common symbols.
2d9895
+
2d9895
 @node PROVIDE_HIDDEN
2d9895
 @subsection PROVIDE_HIDDEN
2d9895
 @cindex PROVIDE_HIDDEN
2d9895
diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
2d9895
index c8a45ca09d1..f56d783ea03 100644
2d9895
--- a/ld/scripttempl/pe.sc
2d9895
+++ b/ld/scripttempl/pe.sc
2d9895
@@ -98,8 +98,22 @@ SECTIONS
2d9895
     ${RELOCATING+*(.glue_7t)}
2d9895
     ${RELOCATING+*(.glue_7)}
2d9895
     ${CONSTRUCTING+
2d9895
-       PROVIDE(___CTOR_LIST__ = .);
2d9895
-       PROVIDE(__CTOR_LIST__ = .);
2d9895
+       /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
2d9895
+          we do not PROVIDE them.  This is because the ctors.o startup
2d9895
+	  code in libgcc defines them as common symbols, with the 
2d9895
+          expectation that they will be overridden by the definitions
2d9895
+	  here.  If we PROVIDE the symbols then they will not be
2d9895
+	  overridden and global constructors will not be run.
2d9895
+	  
2d9895
+	  This does mean that it is not possible for a user to define
2d9895
+	  their own __CTOR_LIST__ and __DTOR_LIST__ symbols.  If that
2d9895
+	  ability is needed a custom linker script will have to be
2d9895
+	  used.  (The custom script can just be a copy of this script
2d9895
+	  with the PROVIDE() qualifiers added).
2d9895
+
2d9895
+	  See PR 22762 for more details.  */
2d9895
+       ___CTOR_LIST__ = .;
2d9895
+       __CTOR_LIST__ = .;
2d9895
        LONG (-1);
2d9895
        KEEP(*(.ctors));
2d9895
        KEEP(*(.ctor));
2d9895
@@ -107,8 +121,10 @@ SECTIONS
2d9895
        LONG (0);
2d9895
      }
2d9895
     ${CONSTRUCTING+
2d9895
-       PROVIDE(___DTOR_LIST__ = .);
2d9895
-       PROVIDE(__DTOR_LIST__ = .);
2d9895
+       /* See comment about __CTOR_LIST__ above.  The same reasoning
2d9895
+          applies here too.  */
2d9895
+       ___DTOR_LIST__ = .;
2d9895
+       __DTOR_LIST__ = .;
2d9895
        LONG (-1);
2d9895
        KEEP(*(.dtors));
2d9895
        KEEP(*(.dtor));
2d9895
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
2d9895
index 8daacb27630..3c6c84da9bf 100644
2d9895
--- a/ld/scripttempl/pep.sc
2d9895
+++ b/ld/scripttempl/pep.sc
2d9895
@@ -99,8 +99,22 @@ SECTIONS
2d9895
     ${RELOCATING+*(.glue_7)}
2d9895
     ${CONSTRUCTING+. = ALIGN(8);}
2d9895
     ${CONSTRUCTING+
2d9895
-       PROVIDE(___CTOR_LIST__ = .);
2d9895
-       PROVIDE(__CTOR_LIST__ = .);
2d9895
+       /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
2d9895
+          we do not PROVIDE them.  This is because the ctors.o startup
2d9895
+	  code in libgcc defines them as common symbols, with the 
2d9895
+          expectation that they will be overridden by the definitions
2d9895
+	  here.  If we PROVIDE the symbols then they will not be
2d9895
+	  overridden and global constructors will not be run.
2d9895
+	  
2d9895
+	  This does mean that it is not possible for a user to define
2d9895
+	  their own __CTOR_LIST__ and __DTOR_LIST__ symbols.  If that
2d9895
+	  ability is needed a custom linker script will have to be
2d9895
+	  used.  (The custom script can just be a copy of this script
2d9895
+	  with the PROVIDE() qualifiers added).
2d9895
+
2d9895
+	  See PR 22762 for more details.  */
2d9895
+       ___CTOR_LIST__ = .;
2d9895
+       __CTOR_LIST__ = .;
2d9895
        LONG (-1); LONG (-1);
2d9895
        KEEP (*(.ctors));
2d9895
        KEEP (*(.ctor));
2d9895
@@ -108,8 +122,10 @@ SECTIONS
2d9895
        LONG (0); LONG (0);
2d9895
      }
2d9895
     ${CONSTRUCTING+
2d9895
-       PROVIDE(___DTOR_LIST__ = .);
2d9895
-       PROVIDE(__DTOR_LIST__ = .);
2d9895
+       /* See comment about __CTOR_LIST__ above.  The same reasoning
2d9895
+    	  applies here too.  */
2d9895
+       ___DTOR_LIST__ = .;
2d9895
+       __DTOR_LIST__ = .;
2d9895
        LONG (-1); LONG (-1);
2d9895
        KEEP (*(.dtors));
2d9895
        KEEP (*(.dtor));
2d9895
-- 
2d9895
2.18.2
2d9895