Remove PROVIDE() qualifiers from definition of __CTOR_LIST__ and __DTOR_LIST__ symbol...
authorNick Clifton <nickc@redhat.com>
Sat, 3 Feb 2018 13:11:35 +0000 (13:11 +0000)
committerNick Clifton <nickc@redhat.com>
Sat, 3 Feb 2018 13:11:35 +0000 (13:11 +0000)
PR 22762
* scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
__DTOR_LIST__ symbols.  Add a comment explaining why this is
necessary.
* scripttemp/pep.sc: Likewise.
* ld.texinfo (PROVIDE): Add a note about the effect of common
symbols.

ld/ChangeLog
ld/ld.texinfo
ld/scripttempl/pe.sc
ld/scripttempl/pep.sc

index 25614193cf82c386583b7633d1c9571433e44ec8..01d1fdc1f83965c2c8991c339a6f9b931be03c9e 100644 (file)
@@ -1,3 +1,13 @@
+2018-02-03  Nick Clifton  <nickc@redhat.com>
+
+       PR 22762
+       * scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
+       __DTOR_LIST__ symbols.  Add a comment explaining why this is
+       necessary.
+       * scripttemp/pep.sc: Likewise.
+       * ld.texinfo (PROVIDE): Add a note about the effect of common
+       symbols.
+
 2018-02-03  Sandra Loosemore  <sandra@codesourcery.com>
 
        * emulparams/nios2elf.sh (GENERATE_SHLIB_SCRIPT): Don't set.
index c89915f1aaad707493c97e4f607012182643a873..764c4017c7b75eeb7ffbf92b9b59d178cabaf7ec 100644 (file)
@@ -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.
+
 @node PROVIDE_HIDDEN
 @subsection PROVIDE_HIDDEN
 @cindex PROVIDE_HIDDEN
index c8a45ca09d1ba6f3314ce81e4b565cab95a5afcf..f56d783ea035309a1b5d2138ec629e7c08e91984 100644 (file)
@@ -98,8 +98,22 @@ SECTIONS
     ${RELOCATING+*(.glue_7t)}
     ${RELOCATING+*(.glue_7)}
     ${CONSTRUCTING+
-       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.  */
+       ___CTOR_LIST__ = .;
+       __CTOR_LIST__ = .;
        LONG (-1);
        KEEP(*(.ctors));
        KEEP(*(.ctor));
@@ -107,8 +121,10 @@ SECTIONS
        LONG (0);
      }
     ${CONSTRUCTING+
-       PROVIDE(___DTOR_LIST__ = .);
-       PROVIDE(__DTOR_LIST__ = .);
+       /* See comment about __CTOR_LIST__ above.  The same reasoning
+          applies here too.  */
+       ___DTOR_LIST__ = .;
+       __DTOR_LIST__ = .;
        LONG (-1);
        KEEP(*(.dtors));
        KEEP(*(.dtor));
index 8daacb276301ea0b2603bab298da300163b0b6fa..3c6c84da9bf2ad5daaaf3b19019a5f762cb4eb31 100644 (file)
@@ -99,8 +99,22 @@ SECTIONS
     ${RELOCATING+*(.glue_7)}
     ${CONSTRUCTING+. = ALIGN(8);}
     ${CONSTRUCTING+
-       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.  */
+       ___CTOR_LIST__ = .;
+       __CTOR_LIST__ = .;
        LONG (-1); LONG (-1);
        KEEP (*(.ctors));
        KEEP (*(.ctor));
@@ -108,8 +122,10 @@ SECTIONS
        LONG (0); LONG (0);
      }
     ${CONSTRUCTING+
-       PROVIDE(___DTOR_LIST__ = .);
-       PROVIDE(__DTOR_LIST__ = .);
+       /* See comment about __CTOR_LIST__ above.  The same reasoning
+         applies here too.  */
+       ___DTOR_LIST__ = .;
+       __DTOR_LIST__ = .;
        LONG (-1); LONG (-1);
        KEEP (*(.dtors));
        KEEP (*(.dtor));
This page took 0.030304 seconds and 4 git commands to generate.