wok annotate glibc/stuff/glibc-2.14.1-sort-1.patch @ rev 23499

updated python-jcconv (0.1.6 -> 0.2.3)
author Hans-G?nter Theisgen
date Mon Apr 06 07:43:47 2020 +0100 (2020-04-06)
parents
children
rev   line source
pankso@12269 1 Submitted By: Bruce Dubbs <bdubbs_at_linuxfromscratch_dot_org>
pankso@12269 2 Date: 2012-02-24
pankso@12269 3 Initial Package Version: 2.14.1
pankso@12269 4 Upstream Status: From upstream
pankso@12269 5 Origin: Upstream
pankso@12269 6 Description: Sort objects by dependency before relocation.
pankso@12269 7 Fixes segfault in dlopen for several programs.
pankso@12269 8
pankso@12269 9 diff --git a/Makeconfig b/Makeconfig
pankso@12269 10 index 2db2821..68547b2 100644
pankso@12269 11 --- a/Makeconfig
pankso@12269 12 +++ b/Makeconfig
pankso@12269 13 @@ -938,6 +938,12 @@ libdl =
pankso@12269 14 endif
pankso@12269 15 endif
pankso@12269 16
pankso@12269 17 +ifeq ($(build-shared),yes)
pankso@12269 18 +libm = $(common-objpfx)math/libm.so$(libm.so-version)
pankso@12269 19 +else
pankso@12269 20 +libm = $(common-objpfx)math/libm.a
pankso@12269 21 +endif
pankso@12269 22 +
pankso@12269 23 # These are the subdirectories containing the library source. The order
pankso@12269 24 # is more or less arbitrary. The sorting step will take care of the
pankso@12269 25 # dependencies.
pankso@12269 26 diff --git a/elf/Makefile b/elf/Makefile
pankso@12269 27 index 052e763..3f1772a 100644
pankso@12269 28 --- a/elf/Makefile
pankso@12269 29 +++ b/elf/Makefile
pankso@12269 30 @@ -124,7 +124,8 @@ distribute := rtld-Rules \
pankso@12269 31 tst-initordera1.c tst-initordera2.c tst-initorderb1.c \
pankso@12269 32 tst-initorderb2.c tst-initordera3.c tst-initordera4.c \
pankso@12269 33 tst-initorder.c \
pankso@12269 34 - tst-initorder2.c
pankso@12269 35 + tst-initorder2.c \
pankso@12269 36 + tst-relsort1.c tst-relsort1mod1.c tst-relsort1mod2.c
pankso@12269 37
pankso@12269 38 CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables
pankso@12269 39 CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables
pankso@12269 40 @@ -227,7 +228,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
pankso@12269 41 tst-audit1 tst-audit2 \
pankso@12269 42 tst-stackguard1 tst-addr1 tst-thrlock \
pankso@12269 43 tst-unique1 tst-unique2 tst-unique3 tst-unique4 \
pankso@12269 44 - tst-initorder tst-initorder2
pankso@12269 45 + tst-initorder tst-initorder2 tst-relsort1
pankso@12269 46 # reldep9
pankso@12269 47 test-srcs = tst-pathopt
pankso@12269 48 selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
pankso@12269 49 @@ -290,7 +291,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
pankso@12269 50 tst-initordera1 tst-initorderb1 \
pankso@12269 51 tst-initordera2 tst-initorderb2 \
pankso@12269 52 tst-initordera3 tst-initordera4 \
pankso@12269 53 - tst-initorder2a tst-initorder2b tst-initorder2c tst-initorder2d
pankso@12269 54 + tst-initorder2a tst-initorder2b tst-initorder2c \
pankso@12269 55 + tst-initorder2d \
pankso@12269 56 + tst-relsort1mod1 tst-relsort1mod2
pankso@12269 57 ifeq (yes,$(have-initfini-array))
pankso@12269 58 modules-names += tst-array2dep tst-array5dep
pankso@12269 59 endif
pankso@12269 60 @@ -1195,3 +1198,9 @@ CFLAGS-tst-auditmod6b.c += $(AVX-CFLAGS)
pankso@12269 61 CFLAGS-tst-auditmod6c.c += $(AVX-CFLAGS)
pankso@12269 62 CFLAGS-tst-auditmod7b.c += $(AVX-CFLAGS)
pankso@12269 63 endif
pankso@12269 64 +
pankso@12269 65 +$(objpfx)tst-relsort1: $(libdl)
pankso@12269 66 +$(objpfx)tst-relsort1mod1.so: $(libm) $(objpfx)tst-relsort1mod2.so
pankso@12269 67 +$(objpfx)tst-relsort1mod2.so: $(libm)
pankso@12269 68 +$(objpfx)tst-relsort1.out: $(objpfx)tst-relsort1mod1.so \
pankso@12269 69 + $(objpfx)tst-relsort1mod2.so
pankso@12269 70 diff --git a/elf/dl-open.c b/elf/dl-open.c
pankso@12269 71 index a0b5c50..a56bdc1 100644
pankso@12269 72 --- a/elf/dl-open.c
pankso@12269 73 +++ b/elf/dl-open.c
pankso@12269 74 @@ -1,5 +1,5 @@
pankso@12269 75 /* Load a shared object at runtime, relocate it, and run its initializer.
pankso@12269 76 - Copyright (C) 1996-2007, 2009, 2010, 2011 Free Software Foundation, Inc.
pankso@12269 77 + Copyright (C) 1996-2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
pankso@12269 78 This file is part of the GNU C Library.
pankso@12269 79
pankso@12269 80 The GNU C Library is free software; you can redistribute it and/or
pankso@12269 81 @@ -303,45 +303,109 @@ dl_open_worker (void *a)
pankso@12269 82 if (GLRO(dl_lazy))
pankso@12269 83 reloc_mode |= mode & RTLD_LAZY;
pankso@12269 84
pankso@12269 85 - /* Relocate the objects loaded. We do this in reverse order so that copy
pankso@12269 86 - relocs of earlier objects overwrite the data written by later objects. */
pankso@12269 87 -
pankso@12269 88 + /* Sort the objects by dependency for the relocation process. This
pankso@12269 89 + allows IFUNC relocations to work and it also means copy
pankso@12269 90 + relocation of dependencies are if necessary overwritten. */
pankso@12269 91 + size_t nmaps = 0;
pankso@12269 92 struct link_map *l = new;
pankso@12269 93 - while (l->l_next)
pankso@12269 94 - l = l->l_next;
pankso@12269 95 - while (1)
pankso@12269 96 + do
pankso@12269 97 + {
pankso@12269 98 + if (! l->l_real->l_relocated)
pankso@12269 99 + ++nmaps;
pankso@12269 100 + l = l->l_next;
pankso@12269 101 + }
pankso@12269 102 + while (l != NULL);
pankso@12269 103 + struct link_map *maps[nmaps];
pankso@12269 104 + nmaps = 0;
pankso@12269 105 + l = new;
pankso@12269 106 + do
pankso@12269 107 {
pankso@12269 108 if (! l->l_real->l_relocated)
pankso@12269 109 + maps[nmaps++] = l;
pankso@12269 110 + l = l->l_next;
pankso@12269 111 + }
pankso@12269 112 + while (l != NULL);
pankso@12269 113 + if (nmaps > 1)
pankso@12269 114 + {
pankso@12269 115 + char seen[nmaps];
pankso@12269 116 + memset (seen, '\0', nmaps);
pankso@12269 117 + size_t i = 0;
pankso@12269 118 + while (1)
pankso@12269 119 {
pankso@12269 120 -#ifdef SHARED
pankso@12269 121 - if (__builtin_expect (GLRO(dl_profile) != NULL, 0))
pankso@12269 122 + ++seen[i];
pankso@12269 123 + struct link_map *thisp = maps[i];
pankso@12269 124 +
pankso@12269 125 + /* Find the last object in the list for which the current one is
pankso@12269 126 + a dependency and move the current object behind the object
pankso@12269 127 + with the dependency. */
pankso@12269 128 + size_t k = nmaps - 1;
pankso@12269 129 + while (k > i)
pankso@12269 130 {
pankso@12269 131 - /* If this here is the shared object which we want to profile
pankso@12269 132 - make sure the profile is started. We can find out whether
pankso@12269 133 - this is necessary or not by observing the `_dl_profile_map'
pankso@12269 134 - variable. If was NULL but is not NULL afterwars we must
pankso@12269 135 - start the profiling. */
pankso@12269 136 - struct link_map *old_profile_map = GL(dl_profile_map);
pankso@12269 137 + struct link_map **runp = maps[k]->l_initfini;
pankso@12269 138 + if (runp != NULL)
pankso@12269 139 + /* Look through the dependencies of the object. */
pankso@12269 140 + while (*runp != NULL)
pankso@12269 141 + if (__builtin_expect (*runp++ == thisp, 0))
pankso@12269 142 + {
pankso@12269 143 + /* Move the current object to the back past the last
pankso@12269 144 + object with it as the dependency. */
pankso@12269 145 + memmove (&maps[i], &maps[i + 1],
pankso@12269 146 + (k - i) * sizeof (maps[0]));
pankso@12269 147 + maps[k] = thisp;
pankso@12269 148 +
pankso@12269 149 + if (seen[i + 1] > 1)
pankso@12269 150 + {
pankso@12269 151 + ++i;
pankso@12269 152 + goto next_clear;
pankso@12269 153 + }
pankso@12269 154 +
pankso@12269 155 + char this_seen = seen[i];
pankso@12269 156 + memmove (&seen[i], &seen[i + 1],
pankso@12269 157 + (k - i) * sizeof (seen[0]));
pankso@12269 158 + seen[k] = this_seen;
pankso@12269 159 +
pankso@12269 160 + goto next;
pankso@12269 161 + }
pankso@12269 162 +
pankso@12269 163 + --k;
pankso@12269 164 + }
pankso@12269 165
pankso@12269 166 - _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1);
pankso@12269 167 + if (++i == nmaps)
pankso@12269 168 + break;
pankso@12269 169 + next_clear:
pankso@12269 170 + memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0]));
pankso@12269 171 + next:;
pankso@12269 172 + }
pankso@12269 173 + }
pankso@12269 174
pankso@12269 175 - if (old_profile_map == NULL && GL(dl_profile_map) != NULL)
pankso@12269 176 - {
pankso@12269 177 - /* We must prepare the profiling. */
pankso@12269 178 - _dl_start_profile ();
pankso@12269 179 + for (size_t i = nmaps; i-- > 0; )
pankso@12269 180 + {
pankso@12269 181 + l = maps[i];
pankso@12269 182
pankso@12269 183 - /* Prevent unloading the object. */
pankso@12269 184 - GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE;
pankso@12269 185 - }
pankso@12269 186 +#ifdef SHARED
pankso@12269 187 + if (__builtin_expect (GLRO(dl_profile) != NULL, 0))
pankso@12269 188 + {
pankso@12269 189 + /* If this here is the shared object which we want to profile
pankso@12269 190 + make sure the profile is started. We can find out whether
pankso@12269 191 + this is necessary or not by observing the `_dl_profile_map'
pankso@12269 192 + variable. If it was NULL but is not NULL afterwars we must
pankso@12269 193 + start the profiling. */
pankso@12269 194 + struct link_map *old_profile_map = GL(dl_profile_map);
pankso@12269 195 +
pankso@12269 196 + _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1);
pankso@12269 197 +
pankso@12269 198 + if (old_profile_map == NULL && GL(dl_profile_map) != NULL)
pankso@12269 199 + {
pankso@12269 200 + /* We must prepare the profiling. */
pankso@12269 201 + _dl_start_profile ();
pankso@12269 202 +
pankso@12269 203 + /* Prevent unloading the object. */
pankso@12269 204 + GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE;
pankso@12269 205 }
pankso@12269 206 - else
pankso@12269 207 -#endif
pankso@12269 208 - _dl_relocate_object (l, l->l_scope, reloc_mode, 0);
pankso@12269 209 }
pankso@12269 210 -
pankso@12269 211 - if (l == new)
pankso@12269 212 - break;
pankso@12269 213 - l = l->l_prev;
pankso@12269 214 + else
pankso@12269 215 +#endif
pankso@12269 216 + _dl_relocate_object (l, l->l_scope, reloc_mode, 0);
pankso@12269 217 }
pankso@12269 218
pankso@12269 219 /* If the file is not loaded now as a dependency, add the search
pankso@12269 220 diff --git a/elf/tst-relsort1.c b/elf/tst-relsort1.c
pankso@12269 221 new file mode 100644
pankso@12269 222 index 0000000..972100c
pankso@12269 223 --- /dev/null
pankso@12269 224 +++ b/elf/tst-relsort1.c
pankso@12269 225 @@ -0,0 +1,19 @@
pankso@12269 226 +#include <dlfcn.h>
pankso@12269 227 +#include <stdio.h>
pankso@12269 228 +
pankso@12269 229 +
pankso@12269 230 +static int
pankso@12269 231 +do_test ()
pankso@12269 232 +{
pankso@12269 233 + const char lib[] = "$ORIGIN/tst-relsort1mod1.so";
pankso@12269 234 + void *h = dlopen (lib, RTLD_NOW);
pankso@12269 235 + if (h == NULL)
pankso@12269 236 + {
pankso@12269 237 + puts (dlerror ());
pankso@12269 238 + return 1;
pankso@12269 239 + }
pankso@12269 240 + return 0;
pankso@12269 241 +}
pankso@12269 242 +
pankso@12269 243 +#define TEST_FUNCTION do_test ()
pankso@12269 244 +#include "../test-skeleton.c"
pankso@12269 245 diff --git a/elf/tst-relsort1mod1.c b/elf/tst-relsort1mod1.c
pankso@12269 246 new file mode 100644
pankso@12269 247 index 0000000..9e4a943
pankso@12269 248 --- /dev/null
pankso@12269 249 +++ b/elf/tst-relsort1mod1.c
pankso@12269 250 @@ -0,0 +1,7 @@
pankso@12269 251 +extern int foo (double);
pankso@12269 252 +
pankso@12269 253 +int
pankso@12269 254 +bar (void)
pankso@12269 255 +{
pankso@12269 256 + return foo (1.2);
pankso@12269 257 +}
pankso@12269 258 diff --git a/elf/tst-relsort1mod2.c b/elf/tst-relsort1mod2.c
pankso@12269 259 new file mode 100644
pankso@12269 260 index 0000000..a2c3e55
pankso@12269 261 --- /dev/null
pankso@12269 262 +++ b/elf/tst-relsort1mod2.c
pankso@12269 263 @@ -0,0 +1,7 @@
pankso@12269 264 +#include <math.h>
pankso@12269 265 +
pankso@12269 266 +int
pankso@12269 267 +foo (double d)
pankso@12269 268 +{
pankso@12269 269 + return floor (d) != 0.0;
pankso@12269 270 +}
pankso@12269 271 --
pankso@12269 272 1.7.3.4
pankso@12269 273