wok-undigest annotate cross-arm-glibc/stuff/glibc-2.14.1-sort-1.patch @ rev 702

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