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

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