summaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-rw-r--r--elf/Makefile4
-rw-r--r--elf/chroot_canon.c10
-rw-r--r--elf/dl-close.c5
-rw-r--r--elf/dl-iteratephdr.c11
-rw-r--r--elf/dl-load.c3
-rw-r--r--elf/dl-object.c5
-rw-r--r--elf/dl-support.c4
-rw-r--r--elf/ldconfig.c17
-rw-r--r--elf/rtld.c1
9 files changed, 43 insertions, 17 deletions
diff --git a/elf/Makefile b/elf/Makefile
index d57c7fe7ed..e600cc3982 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2007, 2008, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1995-2007,2008,2009,2010 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
@@ -654,7 +654,7 @@ $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
$(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
-$(objpfx)noload: $(objpfx)testobj1.so
+$(objpfx)noload: $(objpfx)testobj1.so $(common-objpfx)dlfcn/libdl.so
LDFLAGS-noload = -rdynamic
$(objpfx)noload.out: $(objpfx)testobj5.so
diff --git a/elf/chroot_canon.c b/elf/chroot_canon.c
index 3c16a43ebb..54a6a4cc96 100644
--- a/elf/chroot_canon.c
+++ b/elf/chroot_canon.c
@@ -1,5 +1,5 @@
/* Return the canonical absolute name of a given file inside chroot.
- Copyright (C) 1996,1997,1998,1999,2000,2001,2004,2005
+ Copyright (C) 1996,1997,1998,1999,2000,2001,2004,2005,2010
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -58,9 +58,7 @@ chroot_canon (const char *chroot, const char *name)
return NULL;
}
- rpath = malloc (chroot_len + PATH_MAX);
- if (rpath == NULL)
- return NULL;
+ rpath = xmalloc (chroot_len + PATH_MAX);
rpath_limit = rpath + chroot_len + PATH_MAX;
@@ -109,9 +107,7 @@ chroot_canon (const char *chroot, const char *name)
new_size += end - start + 1;
else
new_size += PATH_MAX;
- new_rpath = (char *) realloc (rpath, new_size);
- if (new_rpath == NULL)
- goto error;
+ new_rpath = (char *) xrealloc (rpath, new_size);
rpath = new_rpath;
rpath_limit = rpath + new_size;
diff --git a/elf/dl-close.c b/elf/dl-close.c
index b73a7adb1a..700e765c3c 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -507,6 +507,9 @@ _dl_close_worker (struct link_map *map)
size_t tls_free_end;
tls_free_start = tls_free_end = NO_TLS_OFFSET;
+ /* We modify the list of loaded objects. */
+ __rtld_lock_lock_recursive (GL(dl_load_write_lock));
+
/* Check each element of the search list to see if all references to
it are gone. */
for (unsigned int i = first_loaded; i < nloaded; ++i)
@@ -665,6 +668,8 @@ _dl_close_worker (struct link_map *map)
}
}
+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
+
/* If we removed any object which uses TLS bump the generation counter. */
if (any_tls)
{
diff --git a/elf/dl-iteratephdr.c b/elf/dl-iteratephdr.c
index fee19f3f04..5f1c20d755 100644
--- a/elf/dl-iteratephdr.c
+++ b/elf/dl-iteratephdr.c
@@ -1,5 +1,5 @@
/* Get loaded objects program headers.
- Copyright (C) 2001-2004, 2006-2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2001-2004, 2006-2009, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
@@ -26,7 +26,7 @@
static void
cancel_handler (void *arg __attribute__((unused)))
{
- __rtld_lock_unlock_recursive (GL(dl_load_lock));
+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
}
hidden_proto (__dl_iterate_phdr)
@@ -38,8 +38,8 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
struct dl_phdr_info info;
int ret = 0;
- /* Make sure we are alone. */
- __rtld_lock_lock_recursive (GL(dl_load_lock));
+ /* Make sure nobody modifies the list of loaded objects. */
+ __rtld_lock_lock_recursive (GL(dl_load_write_lock));
__libc_cleanup_push (cancel_handler, 0);
/* We have to determine the namespace of the caller since this determines
@@ -68,7 +68,6 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
info.dlpi_phnum = l->l_phnum;
info.dlpi_adds = GL(dl_load_adds);
info.dlpi_subs = GL(dl_load_adds) - nloaded;
- info.dlpi_tls_modid = 0;
info.dlpi_tls_data = NULL;
info.dlpi_tls_modid = l->l_tls_modid;
if (info.dlpi_tls_modid != 0)
@@ -80,7 +79,7 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
/* Release the lock. */
__libc_cleanup_pop (0);
- __rtld_lock_unlock_recursive (GL(dl_load_lock));
+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
return ret;
}
diff --git a/elf/dl-load.c b/elf/dl-load.c
index d8f9131dd6..0adddf5aaa 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -803,6 +803,8 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
(void) __close (fd);
if (l != NULL)
{
+ /* We modify the list of loaded objects. */
+ __rtld_lock_lock_recursive (GL(dl_load_write_lock));
/* Remove the stillborn object from the list and free it. */
assert (l->l_next == NULL);
if (l->l_prev == NULL)
@@ -813,6 +815,7 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
l->l_prev->l_next = NULL;
--GL(dl_ns)[l->l_ns]._ns_nloaded;
free (l);
+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
}
free (realname);
diff --git a/elf/dl-object.c b/elf/dl-object.c
index 788e2c07b9..22a163560b 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -93,6 +93,9 @@ _dl_new_object (char *realname, const char *libname, int type,
new->l_scope = new->l_scope_mem;
new->l_scope_max = sizeof (new->l_scope_mem) / sizeof (new->l_scope_mem[0]);
+ /* We modify the list of loaded objects. */
+ __rtld_lock_lock_recursive (GL(dl_load_write_lock));
+
/* Counter for the scopes we have to handle. */
idx = 0;
@@ -114,6 +117,8 @@ _dl_new_object (char *realname, const char *libname, int type,
new->l_serial = GL(dl_load_adds);
++GL(dl_load_adds);
+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
+
/* If we have no loader the new object acts as it. */
if (loader == NULL)
loader = new;
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 65b25750de..f94d2c4c6e 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -166,6 +166,10 @@ const ElfW(Ehdr) *_dl_sysinfo_dso;
the loaded object might as well require a call to this function.
At this time it is not anymore a problem to modify the tables. */
__rtld_lock_define_initialized_recursive (, _dl_load_lock)
+/* This lock is used to keep __dl_iterate_phdr from inspecting the
+ list of loaded objects while an object is added to or removed from
+ that list. */
+__rtld_lock_define_initialized_recursive (, _dl_load_write_lock)
#ifdef HAVE_AUX_VECTOR
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 1bebb11558..278137f8f9 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -773,7 +773,18 @@ search_dir (const struct dir_entry *entry)
{
/* In case of symlink, we check if the symlink refers to
a directory. */
- if (__builtin_expect (stat64 (real_file_name, &stat_buf), 0))
+ char *target_name = real_file_name;
+ if (opt_chroot)
+ {
+ target_name = chroot_canon (opt_chroot, file_name);
+ if (target_name == NULL)
+ {
+ if (strstr (file_name, ".so") == NULL)
+ error (0, 0, _("Input file %s not found.\n"), file_name);
+ continue;
+ }
+ }
+ if (__builtin_expect (stat64 (target_name, &stat_buf), 0))
{
if (opt_verbose)
error (0, errno, _("Cannot stat %s"), file_name);
@@ -1183,7 +1194,9 @@ parse_conf_include (const char *config_file, unsigned int lineno,
if (do_chroot && opt_chroot)
{
char *canon = chroot_canon (opt_chroot, pattern);
- result = glob64 (canon ?: pattern, 0, NULL, &gl);
+ if (canon == NULL)
+ return;
+ result = glob64 (canon, 0, NULL, &gl);
free (canon);
}
else
diff --git a/elf/rtld.c b/elf/rtld.c
index e26b2b9e1b..90f3ff126e 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -126,6 +126,7 @@ struct rtld_global _rtld_global =
._dl_stack_flags = PF_R|PF_W|PF_X,
#ifdef _LIBC_REENTRANT
._dl_load_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
+ ._dl_load_write_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
#endif
._dl_nns = 1,
._dl_ns =