|
| 1 | +From a985e9b9deabd81e16754584f4397a638e9d3f36 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nick Clifton <nickc@redhat.com> |
| 3 | +Date: Mon, 5 Feb 2018 09:12:42 +0000 |
| 4 | +Subject: [PATCH] Import patch from mainline to remove PROVODE qualifiers |
| 5 | + around definitions of __CTOR_LIST__ and __DTOR_LIST__ in PE linker scripts. |
| 6 | + |
| 7 | + PR 22762 |
| 8 | + * scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and |
| 9 | + __DTOR_LIST__ symbols. Add a comment explaining why this is |
| 10 | + necessary. |
| 11 | + * scripttemp/pep.sc: Likewise. |
| 12 | + * ld.texinfo (PROVIDE): Add a note about the effect of common |
| 13 | + symbols. |
| 14 | +--- |
| 15 | + ld/ChangeLog | 14 ++++++++++++++ |
| 16 | + ld/ld.texinfo | 6 ++++++ |
| 17 | + ld/scripttempl/pe.sc | 24 ++++++++++++++++++++---- |
| 18 | + ld/scripttempl/pep.sc | 24 ++++++++++++++++++++---- |
| 19 | + 4 files changed, 60 insertions(+), 8 deletions(-) |
| 20 | + |
| 21 | +diff --git a/ld/ChangeLog b/ld/ChangeLog |
| 22 | +index 0f00265..bf129a1 100644 |
| 23 | +--- a/ld/ChangeLog |
| 24 | ++++ b/ld/ChangeLog |
| 25 | +@@ -1,3 +1,17 @@ |
| 26 | ++2018-02-05 Nick Clifton <nickc@redhat.com> |
| 27 | ++ |
| 28 | ++ Import from mainline: |
| 29 | ++ |
| 30 | ++ 2018-02-03 Nick Clifton <nickc@redhat.com> |
| 31 | ++ |
| 32 | ++ PR 22762 |
| 33 | ++ * scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and |
| 34 | ++ __DTOR_LIST__ symbols. Add a comment explaining why this is |
| 35 | ++ necessary. |
| 36 | ++ * scripttemp/pep.sc: Likewise. |
| 37 | ++ * ld.texinfo (PROVIDE): Add a note about the effect of common |
| 38 | ++ symbols. |
| 39 | ++ |
| 40 | + 2018-01-27 Nick Clifton <nickc@redhat.com> |
| 41 | + |
| 42 | + Back to development. |
| 43 | +diff --git a/ld/ld.texinfo b/ld/ld.texinfo |
| 44 | +index c89915f..764c401 100644 |
| 45 | +--- a/ld/ld.texinfo |
| 46 | ++++ b/ld/ld.texinfo |
| 47 | +@@ -4001,6 +4001,12 @@ underscore), the linker will silently use the definition in the program. |
| 48 | + If the program references @samp{etext} but does not define it, the |
| 49 | + linker will use the definition in the linker script. |
| 50 | + |
| 51 | ++Note - the @code{PROVIDE} directive considers a common symbol to be |
| 52 | ++defined, even though such a symbol could be combined with the symbol |
| 53 | ++that the @code{PROVIDE} would create. This is particularly important |
| 54 | ++when considering constructor and destructor list symbols such as |
| 55 | ++@samp{__CTOR_LIST__} as these are often defined as common symbols. |
| 56 | ++ |
| 57 | + @node PROVIDE_HIDDEN |
| 58 | + @subsection PROVIDE_HIDDEN |
| 59 | + @cindex PROVIDE_HIDDEN |
| 60 | +diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc |
| 61 | +index c8a45ca..f56d783 100644 |
| 62 | +--- a/ld/scripttempl/pe.sc |
| 63 | ++++ b/ld/scripttempl/pe.sc |
| 64 | +@@ -98,8 +98,22 @@ SECTIONS |
| 65 | + ${RELOCATING+*(.glue_7t)} |
| 66 | + ${RELOCATING+*(.glue_7)} |
| 67 | + ${CONSTRUCTING+ |
| 68 | +- PROVIDE(___CTOR_LIST__ = .); |
| 69 | +- PROVIDE(__CTOR_LIST__ = .); |
| 70 | ++ /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here, |
| 71 | ++ we do not PROVIDE them. This is because the ctors.o startup |
| 72 | ++ code in libgcc defines them as common symbols, with the |
| 73 | ++ expectation that they will be overridden by the definitions |
| 74 | ++ here. If we PROVIDE the symbols then they will not be |
| 75 | ++ overridden and global constructors will not be run. |
| 76 | ++ |
| 77 | ++ This does mean that it is not possible for a user to define |
| 78 | ++ their own __CTOR_LIST__ and __DTOR_LIST__ symbols. If that |
| 79 | ++ ability is needed a custom linker script will have to be |
| 80 | ++ used. (The custom script can just be a copy of this script |
| 81 | ++ with the PROVIDE() qualifiers added). |
| 82 | ++ |
| 83 | ++ See PR 22762 for more details. */ |
| 84 | ++ ___CTOR_LIST__ = .; |
| 85 | ++ __CTOR_LIST__ = .; |
| 86 | + LONG (-1); |
| 87 | + KEEP(*(.ctors)); |
| 88 | + KEEP(*(.ctor)); |
| 89 | +@@ -107,8 +121,10 @@ SECTIONS |
| 90 | + LONG (0); |
| 91 | + } |
| 92 | + ${CONSTRUCTING+ |
| 93 | +- PROVIDE(___DTOR_LIST__ = .); |
| 94 | +- PROVIDE(__DTOR_LIST__ = .); |
| 95 | ++ /* See comment about __CTOR_LIST__ above. The same reasoning |
| 96 | ++ applies here too. */ |
| 97 | ++ ___DTOR_LIST__ = .; |
| 98 | ++ __DTOR_LIST__ = .; |
| 99 | + LONG (-1); |
| 100 | + KEEP(*(.dtors)); |
| 101 | + KEEP(*(.dtor)); |
| 102 | +diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc |
| 103 | +index 8daacb2..3c6c84d 100644 |
| 104 | +--- a/ld/scripttempl/pep.sc |
| 105 | ++++ b/ld/scripttempl/pep.sc |
| 106 | +@@ -99,8 +99,22 @@ SECTIONS |
| 107 | + ${RELOCATING+*(.glue_7)} |
| 108 | + ${CONSTRUCTING+. = ALIGN(8);} |
| 109 | + ${CONSTRUCTING+ |
| 110 | +- PROVIDE(___CTOR_LIST__ = .); |
| 111 | +- PROVIDE(__CTOR_LIST__ = .); |
| 112 | ++ /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here, |
| 113 | ++ we do not PROVIDE them. This is because the ctors.o startup |
| 114 | ++ code in libgcc defines them as common symbols, with the |
| 115 | ++ expectation that they will be overridden by the definitions |
| 116 | ++ here. If we PROVIDE the symbols then they will not be |
| 117 | ++ overridden and global constructors will not be run. |
| 118 | ++ |
| 119 | ++ This does mean that it is not possible for a user to define |
| 120 | ++ their own __CTOR_LIST__ and __DTOR_LIST__ symbols. If that |
| 121 | ++ ability is needed a custom linker script will have to be |
| 122 | ++ used. (The custom script can just be a copy of this script |
| 123 | ++ with the PROVIDE() qualifiers added). |
| 124 | ++ |
| 125 | ++ See PR 22762 for more details. */ |
| 126 | ++ ___CTOR_LIST__ = .; |
| 127 | ++ __CTOR_LIST__ = .; |
| 128 | + LONG (-1); LONG (-1); |
| 129 | + KEEP (*(.ctors)); |
| 130 | + KEEP (*(.ctor)); |
| 131 | +@@ -108,8 +122,10 @@ SECTIONS |
| 132 | + LONG (0); LONG (0); |
| 133 | + } |
| 134 | + ${CONSTRUCTING+ |
| 135 | +- PROVIDE(___DTOR_LIST__ = .); |
| 136 | +- PROVIDE(__DTOR_LIST__ = .); |
| 137 | ++ /* See comment about __CTOR_LIST__ above. The same reasoning |
| 138 | ++ applies here too. */ |
| 139 | ++ ___DTOR_LIST__ = .; |
| 140 | ++ __DTOR_LIST__ = .; |
| 141 | + LONG (-1); LONG (-1); |
| 142 | + KEEP (*(.dtors)); |
| 143 | + KEEP (*(.dtor)); |
| 144 | +-- |
| 145 | +2.9.3 |
| 146 | + |
0 commit comments