diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2014-02-07 21:13:28 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2014-02-07 21:13:28 +0000 |
commit | 891ea915baaa267b253cd0b7ad37893ae80d5f12 (patch) | |
tree | 7ad2b7f7dc53e157c1172644515d46a74bc14b22 /libc/elf | |
parent | baef8ab2ac4daea246a54919204f138ad57cac53 (diff) |
Merge changes between r25091 and r25240 from /fsf/glibc-2_15-branch.eglibc-2_15
git-svn-id: svn://svn.eglibc.org/branches/eglibc-2_15@25241 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/elf')
-rw-r--r-- | libc/elf/Makefile | 15 | ||||
-rw-r--r-- | libc/elf/dl-close.c | 15 | ||||
-rw-r--r-- | libc/elf/dl-deps.c | 7 | ||||
-rw-r--r-- | libc/elf/dl-libc.c | 9 | ||||
-rw-r--r-- | libc/elf/dl-open.c | 124 | ||||
-rw-r--r-- | libc/elf/rtld.c | 2 | ||||
-rw-r--r-- | libc/elf/tst-relsort1.c | 19 | ||||
-rw-r--r-- | libc/elf/tst-relsort1mod1.c | 7 | ||||
-rw-r--r-- | libc/elf/tst-relsort1mod2.c | 7 |
9 files changed, 154 insertions, 51 deletions
diff --git a/libc/elf/Makefile b/libc/elf/Makefile index f62aeb2f0..f5ae6d3c9 100644 --- a/libc/elf/Makefile +++ b/libc/elf/Makefile @@ -124,7 +124,8 @@ distribute := rtld-Rules \ tst-initordera1.c tst-initordera2.c tst-initorderb1.c \ tst-initorderb2.c tst-initordera3.c tst-initordera4.c \ tst-initorder.c \ - tst-initorder2.c + tst-initorder2.c \ + tst-relsort1.c tst-relsort1mod1.c tst-relsort1mod2.c CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables @@ -233,7 +234,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ tst-audit1 tst-audit2 \ tst-stackguard1 tst-addr1 tst-thrlock \ tst-unique1 tst-unique2 tst-unique3 tst-unique4 \ - tst-initorder tst-initorder2 + tst-initorder tst-initorder2 tst-relsort1 # reldep9 test-srcs = tst-pathopt selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) @@ -296,7 +297,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-initordera1 tst-initorderb1 \ tst-initordera2 tst-initorderb2 \ tst-initordera3 tst-initordera4 \ - tst-initorder2a tst-initorder2b tst-initorder2c tst-initorder2d + tst-initorder2a tst-initorder2b tst-initorder2c \ + tst-initorder2d \ + tst-relsort1mod1 tst-relsort1mod2 ifeq (yes,$(have-initfini-array)) modules-names += tst-array2dep tst-array5dep endif @@ -1217,3 +1220,9 @@ CFLAGS-tst-auditmod6b.c += $(AVX-CFLAGS) CFLAGS-tst-auditmod6c.c += $(AVX-CFLAGS) CFLAGS-tst-auditmod7b.c += $(AVX-CFLAGS) endif + +$(objpfx)tst-relsort1: $(libdl) +$(objpfx)tst-relsort1mod1.so: $(libm) $(objpfx)tst-relsort1mod2.so +$(objpfx)tst-relsort1mod2.so: $(libm) +$(objpfx)tst-relsort1.out: $(objpfx)tst-relsort1mod1.so \ + $(objpfx)tst-relsort1mod2.so diff --git a/libc/elf/dl-close.c b/libc/elf/dl-close.c index 4b17bf8d8..6364a0b73 100644 --- a/libc/elf/dl-close.c +++ b/libc/elf/dl-close.c @@ -1,5 +1,5 @@ /* Close a shared object opened by `_dl_open'. - Copyright (C) 1996-2007, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1996-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -119,17 +119,8 @@ _dl_close_worker (struct link_map *map) if (map->l_direct_opencount > 0 || map->l_type != lt_loaded || dl_close_state != not_pending) { - if (map->l_direct_opencount == 0) - { - if (map->l_type == lt_loaded) - dl_close_state = rerun; - else if (map->l_type == lt_library) - { - struct link_map **oldp = map->l_initfini; - map->l_initfini = map->l_orig_initfini; - _dl_scope_free (oldp); - } - } + if (map->l_direct_opencount == 0 && map->l_type == lt_loaded) + dl_close_state = rerun; /* There are still references to this object. Do nothing more. */ if (__builtin_expect (GLRO_dl_debug_mask & DL_DEBUG_FILES, 0)) diff --git a/libc/elf/dl-deps.c b/libc/elf/dl-deps.c index 51cb2fa59..c7d5f48b0 100644 --- a/libc/elf/dl-deps.c +++ b/libc/elf/dl-deps.c @@ -1,6 +1,5 @@ /* Load the dependencies of a mapped object. - Copyright (C) 1996-2003, 2004, 2005, 2006, 2007, 2010, 2011 - Free Software Foundation, Inc. + Copyright (C) 1996-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -489,6 +488,7 @@ _dl_map_object_deps (struct link_map *map, nneeded * sizeof needed[0]); atomic_write_barrier (); l->l_initfini = l_initfini; + l->l_free_initfini = 1; } /* If we have no auxiliary objects just go on to the next map. */ @@ -689,6 +689,7 @@ Filters not supported with LD_TRACE_PRELINKING")); l_initfini[nlist] = NULL; atomic_write_barrier (); map->l_initfini = l_initfini; + map->l_free_initfini = 1; if (l_reldeps != NULL) { atomic_write_barrier (); @@ -697,7 +698,7 @@ Filters not supported with LD_TRACE_PRELINKING")); _dl_scope_free (old_l_reldeps); } if (old_l_initfini != NULL) - map->l_orig_initfini = old_l_initfini; + _dl_scope_free (old_l_initfini); if (errno_reason) _dl_signal_error (errno_reason == -1 ? 0 : errno_reason, objname, diff --git a/libc/elf/dl-libc.c b/libc/elf/dl-libc.c index f44fa10e0..0a1921c06 100644 --- a/libc/elf/dl-libc.c +++ b/libc/elf/dl-libc.c @@ -1,6 +1,5 @@ /* Handle loading and unloading shared objects for internal libc purposes. - Copyright (C) 1999-2002,2004-2006,2009,2010,2011 - Free Software Foundation, Inc. + Copyright (C) 1999-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Zack Weinberg <zack@rabi.columbia.edu>, 1999. @@ -270,13 +269,13 @@ libc_freeres_fn (free_mem) for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns) { - /* Remove all additional names added to the objects. */ for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next) { struct libname_list *lnp = l->l_libname->next; l->l_libname->next = NULL; + /* Remove all additional names added to the objects. */ while (lnp != NULL) { struct libname_list *old = lnp; @@ -284,6 +283,10 @@ libc_freeres_fn (free_mem) if (! old->dont_free) free (old); } + + /* Free the initfini dependency list. */ + if (l->l_free_initfini) + free (l->l_initfini); } if (__builtin_expect (GL(dl_ns)[ns]._ns_global_scope_alloc, 0) != 0 diff --git a/libc/elf/dl-open.c b/libc/elf/dl-open.c index 5e780f6ef..9006446ed 100644 --- a/libc/elf/dl-open.c +++ b/libc/elf/dl-open.c @@ -1,5 +1,5 @@ /* Load a shared object at runtime, relocate it, and run its initializer. - Copyright (C) 1996-2007, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1996-2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -302,45 +302,109 @@ dl_open_worker (void *a) if (GLRO(dl_lazy)) reloc_mode |= mode & RTLD_LAZY; - /* Relocate the objects loaded. We do this in reverse order so that copy - relocs of earlier objects overwrite the data written by later objects. */ - + /* Sort the objects by dependency for the relocation process. This + allows IFUNC relocations to work and it also means copy + relocation of dependencies are if necessary overwritten. */ + size_t nmaps = 0; struct link_map *l = new; - while (l->l_next) - l = l->l_next; - while (1) + do + { + if (! l->l_real->l_relocated) + ++nmaps; + l = l->l_next; + } + while (l != NULL); + struct link_map *maps[nmaps]; + nmaps = 0; + l = new; + do { if (! l->l_real->l_relocated) + maps[nmaps++] = l; + l = l->l_next; + } + while (l != NULL); + if (nmaps > 1) + { + char seen[nmaps]; + memset (seen, '\0', nmaps); + size_t i = 0; + while (1) { -#ifdef SHARED - if (__builtin_expect (GLRO(dl_profile) != NULL, 0)) + ++seen[i]; + struct link_map *thisp = maps[i]; + + /* Find the last object in the list for which the current one is + a dependency and move the current object behind the object + with the dependency. */ + size_t k = nmaps - 1; + while (k > i) { - /* If this here is the shared object which we want to profile - make sure the profile is started. We can find out whether - this is necessary or not by observing the `_dl_profile_map' - variable. If was NULL but is not NULL afterwars we must - start the profiling. */ - struct link_map *old_profile_map = GL(dl_profile_map); + struct link_map **runp = maps[k]->l_initfini; + if (runp != NULL) + /* Look through the dependencies of the object. */ + while (*runp != NULL) + if (__builtin_expect (*runp++ == thisp, 0)) + { + /* Move the current object to the back past the last + object with it as the dependency. */ + memmove (&maps[i], &maps[i + 1], + (k - i) * sizeof (maps[0])); + maps[k] = thisp; + + if (seen[i + 1] > 1) + { + ++i; + goto next_clear; + } + + char this_seen = seen[i]; + memmove (&seen[i], &seen[i + 1], + (k - i) * sizeof (seen[0])); + seen[k] = this_seen; + + goto next; + } + + --k; + } - _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); + if (++i == nmaps) + break; + next_clear: + memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0])); + next:; + } + } - if (old_profile_map == NULL && GL(dl_profile_map) != NULL) - { - /* We must prepare the profiling. */ - _dl_start_profile (); + for (size_t i = nmaps; i-- > 0; ) + { + l = maps[i]; - /* Prevent unloading the object. */ - GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE; - } +#ifdef SHARED + if (__builtin_expect (GLRO(dl_profile) != NULL, 0)) + { + /* If this here is the shared object which we want to profile + make sure the profile is started. We can find out whether + this is necessary or not by observing the `_dl_profile_map' + variable. If it was NULL but is not NULL afterwars we must + start the profiling. */ + struct link_map *old_profile_map = GL(dl_profile_map); + + _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); + + if (old_profile_map == NULL && GL(dl_profile_map) != NULL) + { + /* We must prepare the profiling. */ + _dl_start_profile (); + + /* Prevent unloading the object. */ + GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE; } - else -#endif - _dl_relocate_object (l, l->l_scope, reloc_mode, 0); } - - if (l == new) - break; - l = l->l_prev; + else +#endif + _dl_relocate_object (l, l->l_scope, reloc_mode, 0); } /* If the file is not loaded now as a dependency, add the search diff --git a/libc/elf/rtld.c b/libc/elf/rtld.c index b93a01f72..5c39794bf 100644 --- a/libc/elf/rtld.c +++ b/libc/elf/rtld.c @@ -2277,6 +2277,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", lnp->dont_free = 1; lnp = lnp->next; } + /* Also allocated with the fake malloc(). */ + l->l_free_initfini = 0; if (l != &GL(dl_rtld_map)) _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0, diff --git a/libc/elf/tst-relsort1.c b/libc/elf/tst-relsort1.c new file mode 100644 index 000000000..972100c0e --- /dev/null +++ b/libc/elf/tst-relsort1.c @@ -0,0 +1,19 @@ +#include <dlfcn.h> +#include <stdio.h> + + +static int +do_test () +{ + const char lib[] = "$ORIGIN/tst-relsort1mod1.so"; + void *h = dlopen (lib, RTLD_NOW); + if (h == NULL) + { + puts (dlerror ()); + return 1; + } + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/libc/elf/tst-relsort1mod1.c b/libc/elf/tst-relsort1mod1.c new file mode 100644 index 000000000..9e4a94321 --- /dev/null +++ b/libc/elf/tst-relsort1mod1.c @@ -0,0 +1,7 @@ +extern int foo (double); + +int +bar (void) +{ + return foo (1.2); +} diff --git a/libc/elf/tst-relsort1mod2.c b/libc/elf/tst-relsort1mod2.c new file mode 100644 index 000000000..a2c3e551e --- /dev/null +++ b/libc/elf/tst-relsort1mod2.c @@ -0,0 +1,7 @@ +#include <math.h> + +int +foo (double d) +{ + return floor (d) != 0.0; +} |