|
Packit |
6c4009 |
/* Load a shared object at runtime, relocate it, and run its initializer.
|
|
Packit |
6c4009 |
Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <assert.h>
|
|
Packit |
6c4009 |
#include <dlfcn.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <libintl.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <sys/mman.h> /* Check whether MAP_COPY is defined. */
|
|
Packit |
6c4009 |
#include <sys/param.h>
|
|
Packit |
6c4009 |
#include <libc-lock.h>
|
|
Packit |
6c4009 |
#include <ldsodefs.h>
|
|
Packit |
6c4009 |
#include <sysdep-cancel.h>
|
|
Packit |
6c4009 |
#include <tls.h>
|
|
Packit |
6c4009 |
#include <stap-probe.h>
|
|
Packit |
6c4009 |
#include <atomic.h>
|
|
Packit |
6c4009 |
#include <libc-internal.h>
|
|
Packit Bot |
ce0f5f |
#include <array_length.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <dl-dst.h>
|
|
Packit |
6c4009 |
#include <dl-prop.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We must be careful not to leave us in an inconsistent state. Thus we
|
|
Packit |
6c4009 |
catch any error and re-raise it after cleaning up. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct dl_open_args
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const char *file;
|
|
Packit |
6c4009 |
int mode;
|
|
Packit |
6c4009 |
/* This is the caller of the dlopen() function. */
|
|
Packit |
6c4009 |
const void *caller_dlopen;
|
|
Packit |
6c4009 |
struct link_map *map;
|
|
Packit |
6c4009 |
/* Namespace ID. */
|
|
Packit |
6c4009 |
Lmid_t nsid;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
/* Original value of _ns_global_scope_pending_adds. Set by
|
|
Packit Bot |
8ab9c5 |
dl_open_worker. Only valid if nsid is a real namespace
|
|
Packit Bot |
8ab9c5 |
(non-negative). */
|
|
Packit Bot |
8ab9c5 |
unsigned int original_global_scope_pending_adds;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
/* Original parameters to the program and the current environment. */
|
|
Packit |
6c4009 |
int argc;
|
|
Packit |
6c4009 |
char **argv;
|
|
Packit |
6c4009 |
char **env;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Called in case the global scope cannot be extended. */
|
|
Packit Bot |
8ab9c5 |
static void __attribute__ ((noreturn))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (struct link_map *new)
|
|
Packit Bot |
8ab9c5 |
{
|
|
Packit Bot |
8ab9c5 |
_dl_signal_error (ENOMEM, new->l_libname->name, NULL,
|
|
Packit Bot |
8ab9c5 |
N_ ("cannot extend global scope"));
|
|
Packit Bot |
8ab9c5 |
}
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Grow the global scope array for the namespace, so that all the new
|
|
Packit Bot |
8ab9c5 |
global objects can be added later in add_to_global_update, without
|
|
Packit Bot |
8ab9c5 |
risk of memory allocation failure. add_to_global_resize raises
|
|
Packit Bot |
8ab9c5 |
exceptions for memory allocation errors. */
|
|
Packit Bot |
8ab9c5 |
static void
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize (struct link_map *new)
|
|
Packit |
6c4009 |
{
|
|
Packit Bot |
8ab9c5 |
struct link_namespaces *ns = &GL (dl_ns)[new->l_ns];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Count the objects we have to put in the global scope. */
|
|
Packit Bot |
8ab9c5 |
unsigned int to_add = 0;
|
|
Packit Bot |
8ab9c5 |
for (unsigned int cnt = 0; cnt < new->l_searchlist.r_nlist; ++cnt)
|
|
Packit |
6c4009 |
if (new->l_searchlist.r_list[cnt]->l_global == 0)
|
|
Packit |
6c4009 |
++to_add;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The symbols of the new objects and its dependencies are to be
|
|
Packit |
6c4009 |
introduced into the global scope that will be used to resolve
|
|
Packit |
6c4009 |
references from other dynamically-loaded objects.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The global scope is the searchlist in the main link map. We
|
|
Packit |
6c4009 |
extend this list if necessary. There is one problem though:
|
|
Packit |
6c4009 |
since this structure was allocated very early (before the libc
|
|
Packit |
6c4009 |
is loaded) the memory it uses is allocated by the malloc()-stub
|
|
Packit |
6c4009 |
in the ld.so. When we come here these functions are not used
|
|
Packit |
6c4009 |
anymore. Instead the malloc() implementation of the libc is
|
|
Packit |
6c4009 |
used. But this means the block from the main map cannot be used
|
|
Packit |
6c4009 |
in an realloc() call. Therefore we allocate a completely new
|
|
Packit |
6c4009 |
array the first time we have to add something to the locale scope. */
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
if (__builtin_add_overflow (ns->_ns_global_scope_pending_adds, to_add,
|
|
Packit Bot |
8ab9c5 |
&ns->_ns_global_scope_pending_adds))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
unsigned int new_size = 0; /* 0 means no new allocation. */
|
|
Packit Bot |
8ab9c5 |
void *old_global = NULL; /* Old allocation if free-able. */
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
/* Minimum required element count for resizing. Adjusted below for
|
|
Packit Bot |
8ab9c5 |
an exponential resizing policy. */
|
|
Packit Bot |
8ab9c5 |
size_t required_new_size;
|
|
Packit Bot |
8ab9c5 |
if (__builtin_add_overflow (ns->_ns_main_searchlist->r_nlist,
|
|
Packit Bot |
8ab9c5 |
ns->_ns_global_scope_pending_adds,
|
|
Packit Bot |
8ab9c5 |
&required_new_size))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
if (ns->_ns_global_scope_alloc == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit Bot |
8ab9c5 |
if (__builtin_add_overflow (required_new_size, 8, &new_size))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit Bot |
8ab9c5 |
}
|
|
Packit Bot |
8ab9c5 |
else if (required_new_size > ns->_ns_global_scope_alloc)
|
|
Packit Bot |
8ab9c5 |
{
|
|
Packit Bot |
8ab9c5 |
if (__builtin_mul_overflow (required_new_size, 2, &new_size))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* The old array was allocated with our malloc, not the minimal
|
|
Packit Bot |
8ab9c5 |
malloc. */
|
|
Packit Bot |
8ab9c5 |
old_global = ns->_ns_main_searchlist->r_list;
|
|
Packit |
6c4009 |
}
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
if (new_size > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit Bot |
8ab9c5 |
size_t allocation_size;
|
|
Packit Bot |
8ab9c5 |
if (__builtin_mul_overflow (new_size, sizeof (struct link_map *),
|
|
Packit Bot |
8ab9c5 |
&allocation_size))
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit Bot |
8ab9c5 |
struct link_map **new_global = malloc (allocation_size);
|
|
Packit |
6c4009 |
if (new_global == NULL)
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize_failure (new);
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Copy over the old entries. */
|
|
Packit Bot |
8ab9c5 |
memcpy (new_global, ns->_ns_main_searchlist->r_list,
|
|
Packit Bot |
8ab9c5 |
ns->_ns_main_searchlist->r_nlist * sizeof (struct link_map *));
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
ns->_ns_global_scope_alloc = new_size;
|
|
Packit |
6c4009 |
ns->_ns_main_searchlist->r_list = new_global;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (!RTLD_SINGLE_THREAD_P)
|
|
Packit |
6c4009 |
THREAD_GSCOPE_WAIT ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
free (old_global);
|
|
Packit |
6c4009 |
}
|
|
Packit Bot |
8ab9c5 |
}
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
/* Actually add the new global objects to the global scope. Must be
|
|
Packit Bot |
8ab9c5 |
called after add_to_global_resize. This function cannot fail. */
|
|
Packit Bot |
8ab9c5 |
static void
|
|
Packit Bot |
8ab9c5 |
add_to_global_update (struct link_map *new)
|
|
Packit Bot |
8ab9c5 |
{
|
|
Packit Bot |
8ab9c5 |
struct link_namespaces *ns = &GL (dl_ns)[new->l_ns];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now add the new entries. */
|
|
Packit |
6c4009 |
unsigned int new_nlist = ns->_ns_main_searchlist->r_nlist;
|
|
Packit Bot |
8ab9c5 |
for (unsigned int cnt = 0; cnt < new->l_searchlist.r_nlist; ++cnt)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct link_map *map = new->l_searchlist.r_list[cnt];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (map->l_global == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
map->l_global = 1;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
/* The array has been resized by add_to_global_resize. */
|
|
Packit Bot |
8ab9c5 |
assert (new_nlist < ns->_ns_global_scope_alloc);
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
ns->_ns_main_searchlist->r_list[new_nlist++] = map;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We modify the global scope. Report this. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES))
|
|
Packit |
6c4009 |
_dl_debug_printf ("\nadd %s [%lu] to global scope\n",
|
|
Packit |
6c4009 |
map->l_name, map->l_ns);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
8ab9c5 |
/* Some of the pending adds have been performed by the loop above.
|
|
Packit Bot |
8ab9c5 |
Adjust the counter accordingly. */
|
|
Packit Bot |
8ab9c5 |
unsigned int added = new_nlist - ns->_ns_main_searchlist->r_nlist;
|
|
Packit Bot |
8ab9c5 |
assert (added <= ns->_ns_global_scope_pending_adds);
|
|
Packit Bot |
8ab9c5 |
ns->_ns_global_scope_pending_adds -= added;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
atomic_write_barrier ();
|
|
Packit |
6c4009 |
ns->_ns_main_searchlist->r_nlist = new_nlist;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Search link maps in all namespaces for the DSO that contains the object at
|
|
Packit |
6c4009 |
address ADDR. Returns the pointer to the link map of the matching DSO, or
|
|
Packit |
6c4009 |
NULL if a match is not found. */
|
|
Packit |
6c4009 |
struct link_map *
|
|
Packit |
6c4009 |
_dl_find_dso_for_object (const ElfW(Addr) addr)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct link_map *l;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Find the highest-addressed object that ADDR is not below. */
|
|
Packit |
6c4009 |
for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
|
|
Packit |
6c4009 |
for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
|
|
Packit |
6c4009 |
if (addr >= l->l_map_start && addr < l->l_map_end
|
|
Packit |
6c4009 |
&& (l->l_contiguous
|
|
Packit |
6c4009 |
|| _dl_addr_inside_object (l, (ElfW(Addr)) addr)))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
assert (ns == l->l_ns);
|
|
Packit |
6c4009 |
return l;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
rtld_hidden_def (_dl_find_dso_for_object);
|
|
Packit |
6c4009 |
|
|
Packit Bot |
ce0f5f |
/* Return true if NEW is found in the scope for MAP. */
|
|
Packit Bot |
ce0f5f |
static size_t
|
|
Packit Bot |
ce0f5f |
scope_has_map (struct link_map *map, struct link_map *new)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
size_t cnt;
|
|
Packit Bot |
ce0f5f |
for (cnt = 0; map->l_scope[cnt] != NULL; ++cnt)
|
|
Packit Bot |
ce0f5f |
if (map->l_scope[cnt] == &new->l_searchlist)
|
|
Packit Bot |
ce0f5f |
return true;
|
|
Packit Bot |
ce0f5f |
return false;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Return the length of the scope for MAP. */
|
|
Packit Bot |
ce0f5f |
static size_t
|
|
Packit Bot |
ce0f5f |
scope_size (struct link_map *map)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
size_t cnt;
|
|
Packit Bot |
ce0f5f |
for (cnt = 0; map->l_scope[cnt] != NULL; )
|
|
Packit Bot |
ce0f5f |
++cnt;
|
|
Packit Bot |
ce0f5f |
return cnt;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Resize the scopes of depended-upon objects, so that the new object
|
|
Packit Bot |
ce0f5f |
can be added later without further allocation of memory. This
|
|
Packit Bot |
ce0f5f |
function can raise an exceptions due to malloc failure. */
|
|
Packit Bot |
ce0f5f |
static void
|
|
Packit Bot |
ce0f5f |
resize_scopes (struct link_map *new)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
/* If the file is not loaded now as a dependency, add the search
|
|
Packit Bot |
ce0f5f |
list of the newly loaded object to the scope. */
|
|
Packit Bot |
ce0f5f |
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
struct link_map *imap = new->l_searchlist.r_list[i];
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* If the initializer has been called already, the object has
|
|
Packit Bot |
ce0f5f |
not been loaded here and now. */
|
|
Packit Bot |
ce0f5f |
if (imap->l_init_called && imap->l_type == lt_loaded)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
if (scope_has_map (imap, new))
|
|
Packit Bot |
ce0f5f |
/* Avoid duplicates. */
|
|
Packit Bot |
ce0f5f |
continue;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
size_t cnt = scope_size (imap);
|
|
Packit Bot |
ce0f5f |
if (__glibc_unlikely (cnt + 1 >= imap->l_scope_max))
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
/* The l_scope array is too small. Allocate a new one
|
|
Packit Bot |
ce0f5f |
dynamically. */
|
|
Packit Bot |
ce0f5f |
size_t new_size;
|
|
Packit Bot |
ce0f5f |
struct r_scope_elem **newp;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (imap->l_scope != imap->l_scope_mem
|
|
Packit Bot |
ce0f5f |
&& imap->l_scope_max < array_length (imap->l_scope_mem))
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
/* If the current l_scope memory is not pointing to
|
|
Packit Bot |
ce0f5f |
the static memory in the structure, but the
|
|
Packit Bot |
ce0f5f |
static memory in the structure is large enough to
|
|
Packit Bot |
ce0f5f |
use for cnt + 1 scope entries, then switch to
|
|
Packit Bot |
ce0f5f |
using the static memory. */
|
|
Packit Bot |
ce0f5f |
new_size = array_length (imap->l_scope_mem);
|
|
Packit Bot |
ce0f5f |
newp = imap->l_scope_mem;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
else
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
new_size = imap->l_scope_max * 2;
|
|
Packit Bot |
ce0f5f |
newp = (struct r_scope_elem **)
|
|
Packit Bot |
ce0f5f |
malloc (new_size * sizeof (struct r_scope_elem *));
|
|
Packit Bot |
ce0f5f |
if (newp == NULL)
|
|
Packit Bot |
ce0f5f |
_dl_signal_error (ENOMEM, "dlopen", NULL,
|
|
Packit Bot |
ce0f5f |
N_("cannot create scope list"));
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Copy the array and the terminating NULL. */
|
|
Packit Bot |
ce0f5f |
memcpy (newp, imap->l_scope,
|
|
Packit Bot |
ce0f5f |
(cnt + 1) * sizeof (imap->l_scope[0]));
|
|
Packit Bot |
ce0f5f |
struct r_scope_elem **old = imap->l_scope;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
imap->l_scope = newp;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (old != imap->l_scope_mem)
|
|
Packit Bot |
ce0f5f |
_dl_scope_free (old);
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
imap->l_scope_max = new_size;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Second stage of resize_scopes: Add NEW to the scopes. Also print
|
|
Packit Bot |
ce0f5f |
debugging information about scopes if requested.
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
This function cannot raise an exception because all required memory
|
|
Packit Bot |
ce0f5f |
has been allocated by a previous call to resize_scopes. */
|
|
Packit Bot |
ce0f5f |
static void
|
|
Packit Bot |
ce0f5f |
update_scopes (struct link_map *new)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
struct link_map *imap = new->l_searchlist.r_list[i];
|
|
Packit Bot |
ce0f5f |
int from_scope = 0;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (imap->l_init_called && imap->l_type == lt_loaded)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
if (scope_has_map (imap, new))
|
|
Packit Bot |
ce0f5f |
/* Avoid duplicates. */
|
|
Packit Bot |
ce0f5f |
continue;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
size_t cnt = scope_size (imap);
|
|
Packit Bot |
ce0f5f |
/* Assert that resize_scopes has sufficiently enlarged the
|
|
Packit Bot |
ce0f5f |
array. */
|
|
Packit Bot |
ce0f5f |
assert (cnt + 1 < imap->l_scope_max);
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* First terminate the extended list. Otherwise a thread
|
|
Packit Bot |
ce0f5f |
might use the new last element and then use the garbage
|
|
Packit Bot |
ce0f5f |
at offset IDX+1. */
|
|
Packit Bot |
ce0f5f |
imap->l_scope[cnt + 1] = NULL;
|
|
Packit Bot |
ce0f5f |
atomic_write_barrier ();
|
|
Packit Bot |
ce0f5f |
imap->l_scope[cnt] = &new->l_searchlist;
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
from_scope = cnt;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Print scope information. */
|
|
Packit Bot |
ce0f5f |
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES))
|
|
Packit Bot |
ce0f5f |
_dl_show_scope (imap, from_scope);
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Call _dl_add_to_slotinfo with DO_ADD set to false, to allocate
|
|
Packit Bot |
ce0f5f |
space in GL (dl_tls_dtv_slotinfo_list). This can raise an
|
|
Packit Bot |
ce0f5f |
exception. The return value is true if any of the new objects use
|
|
Packit Bot |
ce0f5f |
TLS. */
|
|
Packit Bot |
ce0f5f |
static bool
|
|
Packit Bot |
ce0f5f |
resize_tls_slotinfo (struct link_map *new)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
bool any_tls = false;
|
|
Packit Bot |
ce0f5f |
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
struct link_map *imap = new->l_searchlist.r_list[i];
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Only add TLS memory if this object is loaded now and
|
|
Packit Bot |
ce0f5f |
therefore is not yet initialized. */
|
|
Packit Bot |
ce0f5f |
if (! imap->l_init_called && imap->l_tls_blocksize > 0)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
_dl_add_to_slotinfo (imap, false);
|
|
Packit Bot |
ce0f5f |
any_tls = true;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
return any_tls;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Second stage of TLS update, after resize_tls_slotinfo. This
|
|
Packit Bot |
ce0f5f |
function does not raise any exception. It should only be called if
|
|
Packit Bot |
ce0f5f |
resize_tls_slotinfo returned true. */
|
|
Packit Bot |
ce0f5f |
static void
|
|
Packit Bot |
ce0f5f |
update_tls_slotinfo (struct link_map *new)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
unsigned int first_static_tls = new->l_searchlist.r_nlist;
|
|
Packit Bot |
ce0f5f |
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
struct link_map *imap = new->l_searchlist.r_list[i];
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Only add TLS memory if this object is loaded now and
|
|
Packit Bot |
ce0f5f |
therefore is not yet initialized. */
|
|
Packit Bot |
ce0f5f |
if (! imap->l_init_called && imap->l_tls_blocksize > 0)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
_dl_add_to_slotinfo (imap, true);
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (imap->l_need_tls_init
|
|
Packit Bot |
ce0f5f |
&& first_static_tls == new->l_searchlist.r_nlist)
|
|
Packit Bot |
ce0f5f |
first_static_tls = i;
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (__builtin_expect (++GL(dl_tls_generation) == 0, 0))
|
|
Packit Bot |
ce0f5f |
_dl_fatal_printf (N_("\
|
|
Packit Bot |
ce0f5f |
TLS generation counter wrapped! Please report this."));
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* We need a second pass for static tls data, because
|
|
Packit Bot |
ce0f5f |
_dl_update_slotinfo must not be run while calls to
|
|
Packit Bot |
ce0f5f |
_dl_add_to_slotinfo are still pending. */
|
|
Packit Bot |
ce0f5f |
for (unsigned int i = first_static_tls; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
struct link_map *imap = new->l_searchlist.r_list[i];
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
if (imap->l_need_tls_init
|
|
Packit Bot |
ce0f5f |
&& ! imap->l_init_called
|
|
Packit Bot |
ce0f5f |
&& imap->l_tls_blocksize > 0)
|
|
Packit Bot |
ce0f5f |
{
|
|
Packit Bot |
ce0f5f |
/* For static TLS we have to allocate the memory here and
|
|
Packit Bot |
ce0f5f |
now, but we can delay updating the DTV. */
|
|
Packit Bot |
ce0f5f |
imap->l_need_tls_init = 0;
|
|
Packit Bot |
ce0f5f |
#ifdef SHARED
|
|
Packit Bot |
ce0f5f |
/* Update the slot information data for at least the
|
|
Packit Bot |
ce0f5f |
generation of the DSO we are allocating data for. */
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* FIXME: This can terminate the process on memory
|
|
Packit Bot |
ce0f5f |
allocation failure. It is not possible to raise
|
|
Packit Bot |
ce0f5f |
exceptions from this context; to fix this bug,
|
|
Packit Bot |
ce0f5f |
_dl_update_slotinfo would have to be split into two
|
|
Packit Bot |
ce0f5f |
operations, similar to resize_scopes and update_scopes
|
|
Packit Bot |
ce0f5f |
above. This is related to bug 16134. */
|
|
Packit Bot |
ce0f5f |
_dl_update_slotinfo (imap->l_tls_modid);
|
|
Packit Bot |
ce0f5f |
#endif
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
GL(dl_init_static_tls) (imap);
|
|
Packit Bot |
ce0f5f |
assert (imap->l_need_tls_init == 0);
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
}
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
f2790b |
/* Mark the objects as NODELETE if required. This is delayed until
|
|
Packit Bot |
f2790b |
after dlopen failure is not possible, so that _dl_close can clean
|
|
Packit Bot |
f2790b |
up objects if necessary. */
|
|
Packit Bot |
f2790b |
static void
|
|
Packit Bot |
a917fd |
activate_nodelete (struct link_map *new)
|
|
Packit Bot |
f2790b |
{
|
|
Packit Bot |
a917fd |
/* It is necessary to traverse the entire namespace. References to
|
|
Packit Bot |
a917fd |
objects in the global scope and unique symbol bindings can force
|
|
Packit Bot |
a917fd |
NODELETE status for objects outside the local scope. */
|
|
Packit Bot |
a917fd |
for (struct link_map *l = GL (dl_ns)[new->l_ns]._ns_loaded; l != NULL;
|
|
Packit Bot |
a917fd |
l = l->l_next)
|
|
Packit Bot |
69412d |
if (l->l_nodelete_pending)
|
|
Packit Bot |
a917fd |
{
|
|
Packit Bot |
a917fd |
if (__glibc_unlikely (GLRO (dl_debug_mask) & DL_DEBUG_FILES))
|
|
Packit Bot |
a917fd |
_dl_debug_printf ("activating NODELETE for %s [%lu]\n",
|
|
Packit Bot |
a917fd |
l->l_name, l->l_ns);
|
|
Packit Bot |
a917fd |
|
|
Packit Bot |
2a59fd |
/* The flag can already be true at this point, e.g. a signal
|
|
Packit Bot |
2a59fd |
handler may have triggered lazy binding and set NODELETE
|
|
Packit Bot |
2a59fd |
status immediately. */
|
|
Packit Bot |
69412d |
l->l_nodelete_active = true;
|
|
Packit Bot |
69412d |
|
|
Packit Bot |
69412d |
/* This is just a debugging aid, to indicate that
|
|
Packit Bot |
69412d |
activate_nodelete has run for this map. */
|
|
Packit Bot |
69412d |
l->l_nodelete_pending = false;
|
|
Packit Bot |
a917fd |
}
|
|
Packit Bot |
f2790b |
}
|
|
Packit Bot |
f2790b |
|
|
Packit Bot |
45a627 |
/* struct dl_init_args and call_dl_init are used to call _dl_init with
|
|
Packit Bot |
45a627 |
exception handling disabled. */
|
|
Packit Bot |
45a627 |
struct dl_init_args
|
|
Packit Bot |
45a627 |
{
|
|
Packit Bot |
45a627 |
struct link_map *new;
|
|
Packit Bot |
45a627 |
int argc;
|
|
Packit Bot |
45a627 |
char **argv;
|
|
Packit Bot |
45a627 |
char **env;
|
|
Packit Bot |
45a627 |
};
|
|
Packit Bot |
45a627 |
|
|
Packit Bot |
45a627 |
static void
|
|
Packit Bot |
45a627 |
call_dl_init (void *closure)
|
|
Packit Bot |
45a627 |
{
|
|
Packit Bot |
45a627 |
struct dl_init_args *args = closure;
|
|
Packit Bot |
45a627 |
_dl_init (args->new, args->argc, args->argv, args->env);
|
|
Packit Bot |
45a627 |
}
|
|
Packit Bot |
45a627 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
dl_open_worker (void *a)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct dl_open_args *args = a;
|
|
Packit |
6c4009 |
const char *file = args->file;
|
|
Packit |
6c4009 |
int mode = args->mode;
|
|
Packit |
6c4009 |
struct link_map *call_map = NULL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Determine the caller's map if necessary. This is needed in case
|
|
Packit |
6c4009 |
we have a DST, when we don't know the namespace ID we have to put
|
|
Packit |
6c4009 |
the new object in, or when the file name has no path in which
|
|
Packit |
6c4009 |
case we need to look along the RUNPATH/RPATH of the caller. */
|
|
Packit |
6c4009 |
const char *dst = strchr (file, '$');
|
|
Packit |
6c4009 |
if (dst != NULL || args->nsid == __LM_ID_CALLER
|
|
Packit |
6c4009 |
|| strchr (file, '/') == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const void *caller_dlopen = args->caller_dlopen;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We have to find out from which object the caller is calling.
|
|
Packit |
6c4009 |
By default we assume this is the main application. */
|
|
Packit |
6c4009 |
call_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct link_map *l = _dl_find_dso_for_object ((ElfW(Addr)) caller_dlopen);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (l)
|
|
Packit |
6c4009 |
call_map = l;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (args->nsid == __LM_ID_CALLER)
|
|
Packit |
6c4009 |
args->nsid = call_map->l_ns;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Retain the old value, so that it can be restored. */
|
|
Packit Bot |
8ab9c5 |
args->original_global_scope_pending_adds
|
|
Packit Bot |
8ab9c5 |
= GL (dl_ns)[args->nsid]._ns_global_scope_pending_adds;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
/* One might be tempted to assert that we are RT_CONSISTENT at this point, but that
|
|
Packit |
6c4009 |
may not be true if this is a recursive call to dlopen. */
|
|
Packit |
6c4009 |
_dl_debug_initialize (0, args->nsid);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load the named object. */
|
|
Packit |
6c4009 |
struct link_map *new;
|
|
Packit |
6c4009 |
args->map = new = _dl_map_object (call_map, file, lt_loaded, 0,
|
|
Packit |
6c4009 |
mode | __RTLD_CALLMAP, args->nsid);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* If the pointer returned is NULL this means the RTLD_NOLOAD flag is
|
|
Packit |
6c4009 |
set and the object is not already loaded. */
|
|
Packit |
6c4009 |
if (new == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
assert (mode & RTLD_NOLOAD);
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__glibc_unlikely (mode & __RTLD_SPROF))
|
|
Packit Bot |
2a59fd |
/* This happens only if we load a DSO for 'sprof'. */
|
|
Packit Bot |
2a59fd |
return;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This object is directly loaded. */
|
|
Packit |
6c4009 |
++new->l_direct_opencount;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* It was already open. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (new->l_searchlist.r_list != NULL))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Let the user know about the opencount. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
|
Packit |
6c4009 |
_dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n",
|
|
Packit |
6c4009 |
new->l_name, new->l_ns, new->l_direct_opencount);
|
|
Packit |
6c4009 |
|
|
Packit Bot |
f2790b |
/* If the user requested the object to be in the global
|
|
Packit Bot |
f2790b |
namespace but it is not so far, prepare to add it now. This
|
|
Packit Bot |
f2790b |
can raise an exception to do a malloc failure. */
|
|
Packit |
6c4009 |
if ((mode & RTLD_GLOBAL) && new->l_global == 0)
|
|
Packit Bot |
f2790b |
add_to_global_resize (new);
|
|
Packit Bot |
f2790b |
|
|
Packit Bot |
f2790b |
/* Mark the object as not deletable if the RTLD_NODELETE flags
|
|
Packit Bot |
f2790b |
was passed. */
|
|
Packit Bot |
f2790b |
if (__glibc_unlikely (mode & RTLD_NODELETE))
|
|
Packit Bot |
8ab9c5 |
{
|
|
Packit Bot |
f2790b |
if (__glibc_unlikely (GLRO (dl_debug_mask) & DL_DEBUG_FILES)
|
|
Packit Bot |
69412d |
&& !new->l_nodelete_active)
|
|
Packit Bot |
f2790b |
_dl_debug_printf ("marking %s [%lu] as NODELETE\n",
|
|
Packit Bot |
f2790b |
new->l_name, new->l_ns);
|
|
Packit Bot |
69412d |
new->l_nodelete_active = true;
|
|
Packit Bot |
8ab9c5 |
}
|
|
Packit Service |
2d0921 |
|
|
Packit Bot |
f2790b |
/* Finalize the addition to the global scope. */
|
|
Packit Bot |
f2790b |
if ((mode & RTLD_GLOBAL) && new->l_global == 0)
|
|
Packit Bot |
f2790b |
add_to_global_update (new);
|
|
Packit Bot |
f2790b |
|
|
Packit |
6c4009 |
assert (_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit Bot |
f2790b |
/* Schedule NODELETE marking for the directly loaded object if
|
|
Packit Bot |
f2790b |
requested. */
|
|
Packit Bot |
f2790b |
if (__glibc_unlikely (mode & RTLD_NODELETE))
|
|
Packit Bot |
69412d |
new->l_nodelete_pending = true;
|
|
Packit Bot |
f2790b |
|
|
Packit |
6c4009 |
/* Load that object's dependencies. */
|
|
Packit |
6c4009 |
_dl_map_object_deps (new, NULL, 0, 0,
|
|
Packit |
6c4009 |
mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* So far, so good. Now check the versions. */
|
|
Packit |
6c4009 |
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
|
|
Packit |
6c4009 |
if (new->l_searchlist.r_list[i]->l_real->l_versions == NULL)
|
|
Packit |
6c4009 |
(void) _dl_check_map_versions (new->l_searchlist.r_list[i]->l_real,
|
|
Packit |
6c4009 |
0, 0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
/* Auditing checkpoint: we have added all objects. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_naudit) > 0))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct link_map *head = GL(dl_ns)[new->l_ns]._ns_loaded;
|
|
Packit |
6c4009 |
/* Do not call the functions for any auditing object. */
|
|
Packit |
6c4009 |
if (head->l_auditing == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct audit_ifaces *afct = GLRO(dl_audit);
|
|
Packit |
6c4009 |
for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (afct->activity != NULL)
|
|
Packit Bot |
0c2104 |
afct->activity (&head->l_audit[cnt].cookie, LA_ACT_CONSISTENT);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
afct = afct->next;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Notify the debugger all new objects are now ready to go. */
|
|
Packit |
6c4009 |
struct r_debug *r = _dl_debug_initialize (0, args->nsid);
|
|
Packit |
6c4009 |
r->r_state = RT_CONSISTENT;
|
|
Packit |
6c4009 |
_dl_debug_state ();
|
|
Packit |
6c4009 |
LIBC_PROBE (map_complete, 3, args->nsid, r, new);
|
|
Packit |
6c4009 |
|
|
Packit Bot |
4c9884 |
_dl_open_check (new);
|
|
Packit Bot |
4c9884 |
|
|
Packit |
6c4009 |
/* Print scope information. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES))
|
|
Packit |
6c4009 |
_dl_show_scope (new, 0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Only do lazy relocation if `LD_BIND_NOW' is not set. */
|
|
Packit |
6c4009 |
int reloc_mode = mode & __RTLD_AUDIT;
|
|
Packit |
6c4009 |
if (GLRO(dl_lazy))
|
|
Packit |
6c4009 |
reloc_mode |= mode & RTLD_LAZY;
|
|
Packit |
6c4009 |
|
|
Packit Bot |
0c2104 |
/* Sort the objects by dependency for the relocation process. This
|
|
Packit Bot |
0c2104 |
allows IFUNC relocations to work and it also means copy
|
|
Packit Bot |
0c2104 |
relocation of dependencies are if necessary overwritten. */
|
|
Packit Bot |
0c2104 |
unsigned int nmaps = 0;
|
|
Packit Bot |
0c2104 |
struct link_map *l = new;
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (! l->l_real->l_relocated)
|
|
Packit Bot |
0c2104 |
++nmaps;
|
|
Packit Bot |
0c2104 |
l = l->l_next;
|
|
Packit Bot |
0c2104 |
}
|
|
Packit Bot |
0c2104 |
while (l != NULL);
|
|
Packit Bot |
0c2104 |
struct link_map *maps[nmaps];
|
|
Packit Bot |
0c2104 |
nmaps = 0;
|
|
Packit Bot |
0c2104 |
l = new;
|
|
Packit Bot |
0c2104 |
do
|
|
Packit Bot |
0c2104 |
{
|
|
Packit Bot |
0c2104 |
if (! l->l_real->l_relocated)
|
|
Packit Bot |
0c2104 |
maps[nmaps++] = l;
|
|
Packit Bot |
0c2104 |
l = l->l_next;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (l != NULL);
|
|
Packit Bot |
0c2104 |
_dl_sort_maps (maps, nmaps, NULL, false);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int relocation_in_progress = 0;
|
|
Packit |
6c4009 |
|
|
Packit Bot |
f2790b |
/* Perform relocation. This can trigger lazy binding in IFUNC
|
|
Packit Bot |
f2790b |
resolvers. For NODELETE mappings, these dependencies are not
|
|
Packit Bot |
f2790b |
recorded because the flag has not been applied to the newly
|
|
Packit Bot |
f2790b |
loaded objects. This means that upon dlopen failure, these
|
|
Packit Bot |
f2790b |
NODELETE objects can be unloaded despite existing references to
|
|
Packit Bot |
f2790b |
them. However, such relocation dependencies in IFUNC resolvers
|
|
Packit Bot |
f2790b |
are undefined anyway, so this is not a problem. */
|
|
Packit Bot |
f2790b |
|
|
Packit Bot |
0c2104 |
for (unsigned int i = nmaps; i-- > 0; )
|
|
Packit |
6c4009 |
{
|
|
Packit Bot |
0c2104 |
l = maps[i];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (! relocation_in_progress)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Notify the debugger that relocations are about to happen. */
|
|
Packit |
6c4009 |
LIBC_PROBE (reloc_start, 2, args->nsid, r);
|
|
Packit |
6c4009 |
relocation_in_progress = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_profile) != NULL))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* If this here is the shared object which we want to profile
|
|
Packit |
6c4009 |
make sure the profile is started. We can find out whether
|
|
Packit |
6c4009 |
this is necessary or not by observing the `_dl_profile_map'
|
|
Packit |
6c4009 |
variable. If it was NULL but is not NULL afterwards we must
|
|
Packit |
6c4009 |
start the profiling. */
|
|
Packit |
6c4009 |
struct link_map *old_profile_map = GL(dl_profile_map);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (old_profile_map == NULL && GL(dl_profile_map) != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* We must prepare the profiling. */
|
|
Packit |
6c4009 |
_dl_start_profile ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Prevent unloading the object. */
|
|
Packit Bot |
69412d |
GL(dl_profile_map)->l_nodelete_active = true;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
_dl_relocate_object (l, l->l_scope, reloc_mode, 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit Bot |
ce0f5f |
/* This only performs the memory allocations. The actual update of
|
|
Packit Bot |
ce0f5f |
the scopes happens below, after failure is impossible. */
|
|
Packit Bot |
ce0f5f |
resize_scopes (new);
|
|
Packit Service |
6de65a |
|
|
Packit Bot |
ce0f5f |
/* Increase the size of the GL (dl_tls_dtv_slotinfo_list) data
|
|
Packit Bot |
ce0f5f |
structure. */
|
|
Packit Bot |
ce0f5f |
bool any_tls = resize_tls_slotinfo (new);
|
|
Packit Bot |
0c2104 |
|
|
Packit Bot |
ce0f5f |
/* Perform the necessary allocations for adding new global objects
|
|
Packit Bot |
ce0f5f |
to the global scope below. */
|
|
Packit Bot |
ce0f5f |
if (mode & RTLD_GLOBAL)
|
|
Packit Bot |
ce0f5f |
add_to_global_resize (new);
|
|
Packit Bot |
0c2104 |
|
|
Packit Bot |
ce0f5f |
/* Demarcation point: After this, no recoverable errors are allowed.
|
|
Packit Bot |
ce0f5f |
All memory allocations for new objects must have happened
|
|
Packit Bot |
ce0f5f |
before. */
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
2a59fd |
/* Finalize the NODELETE status first. This comes before
|
|
Packit Bot |
2a59fd |
update_scopes, so that lazy binding will not see pending NODELETE
|
|
Packit Bot |
2a59fd |
state for newly loaded objects. There is a compiler barrier in
|
|
Packit Bot |
2a59fd |
update_scopes which ensures that the changes from
|
|
Packit Bot |
2a59fd |
activate_nodelete are visible before new objects show up in the
|
|
Packit Bot |
2a59fd |
local scope. */
|
|
Packit Bot |
a917fd |
activate_nodelete (new);
|
|
Packit Bot |
f2790b |
|
|
Packit Bot |
ce0f5f |
/* Second stage after resize_scopes: Actually perform the scope
|
|
Packit Bot |
ce0f5f |
update. After this, dlsym and lazy binding can bind to new
|
|
Packit Bot |
ce0f5f |
objects. */
|
|
Packit Bot |
ce0f5f |
update_scopes (new);
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* FIXME: It is unclear whether the order here is correct.
|
|
Packit Bot |
ce0f5f |
Shouldn't new objects be made available for binding (and thus
|
|
Packit Bot |
ce0f5f |
execution) only after there TLS data has been set up fully?
|
|
Packit Bot |
ce0f5f |
Fixing bug 16134 will likely make this distinction less
|
|
Packit Bot |
ce0f5f |
important. */
|
|
Packit Bot |
ce0f5f |
|
|
Packit Bot |
ce0f5f |
/* Second stage after resize_tls_slotinfo: Update the slotinfo data
|
|
Packit Bot |
ce0f5f |
structures. */
|
|
Packit Bot |
ce0f5f |
if (any_tls)
|
|
Packit Bot |
ce0f5f |
/* FIXME: This calls _dl_update_slotinfo, which aborts the process
|
|
Packit Bot |
ce0f5f |
on memory allocation failure. See bug 16134. */
|
|
Packit Bot |
ce0f5f |
update_tls_slotinfo (new);
|
|
Packit Service |
4a0975 |
|
|
Packit Bot |
0c2104 |
/* Notify the debugger all new objects have been relocated. */
|
|
Packit Bot |
0c2104 |
if (relocation_in_progress)
|
|
Packit Bot |
0c2104 |
LIBC_PROBE (reloc_complete, 3, args->nsid, r, new);
|
|
Packit Bot |
0c2104 |
|
|
Packit |
6c4009 |
#ifndef SHARED
|
|
Packit |
6c4009 |
DL_STATIC_INIT (new);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Perform the necessary allocations for adding new global objects
|
|
Packit Bot |
8ab9c5 |
to the global scope below, via add_to_global_update. */
|
|
Packit Bot |
8ab9c5 |
if (mode & RTLD_GLOBAL)
|
|
Packit Bot |
8ab9c5 |
add_to_global_resize (new);
|
|
Packit Bot |
8ab9c5 |
|
|
Packit Bot |
45a627 |
/* Run the initializer functions of new objects. Temporarily
|
|
Packit Bot |
45a627 |
disable the exception handler, so that lazy binding failures are
|
|
Packit Bot |
45a627 |
fatal. */
|
|
Packit Bot |
45a627 |
{
|
|
Packit Bot |
45a627 |
struct dl_init_args init_args =
|
|
Packit Bot |
45a627 |
{
|
|
Packit Bot |
45a627 |
.new = new,
|
|
Packit Bot |
45a627 |
.argc = args->argc,
|
|
Packit Bot |
45a627 |
.argv = args->argv,
|
|
Packit Bot |
45a627 |
.env = args->env
|
|
Packit Bot |
45a627 |
};
|
|
Packit Bot |
45a627 |
_dl_catch_exception (NULL, call_dl_init, &init_args);
|
|
Packit Bot |
45a627 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now we can make the new map available in the global scope. */
|
|
Packit |
6c4009 |
if (mode & RTLD_GLOBAL)
|
|
Packit Bot |
8ab9c5 |
add_to_global_update (new);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef SHARED
|
|
Packit |
6c4009 |
/* We must be the static _dl_open in libc.a. A static program that
|
|
Packit |
6c4009 |
has loaded a dynamic object now has competition. */
|
|
Packit |
6c4009 |
__libc_multiple_libcs = 1;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Let the user know about the opencount. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
|
Packit |
6c4009 |
_dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n",
|
|
Packit |
6c4009 |
new->l_name, new->l_ns, new->l_direct_opencount);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void *
|
|
Packit |
6c4009 |
_dl_open (const char *file, int mode, const void *caller_dlopen, Lmid_t nsid,
|
|
Packit |
6c4009 |
int argc, char *argv[], char *env[])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if ((mode & RTLD_BINDING_MASK) == 0)
|
|
Packit |
6c4009 |
/* One of the flags must be set. */
|
|
Packit |
6c4009 |
_dl_signal_error (EINVAL, file, NULL, N_("invalid mode for dlopen()"));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make sure we are alone. */
|
|
Packit |
6c4009 |
__rtld_lock_lock_recursive (GL(dl_load_lock));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__glibc_unlikely (nsid == LM_ID_NEWLM))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Find a new namespace. */
|
|
Packit |
6c4009 |
for (nsid = 1; DL_NNS > 1 && nsid < GL(dl_nns); ++nsid)
|
|
Packit |
6c4009 |
if (GL(dl_ns)[nsid]._ns_loaded == NULL)
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__glibc_unlikely (nsid == DL_NNS))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* No more namespace available. */
|
|
Packit |
6c4009 |
__rtld_lock_unlock_recursive (GL(dl_load_lock));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_dl_signal_error (EINVAL, file, NULL, N_("\
|
|
Packit |
6c4009 |
no more namespaces available for dlmopen()"));
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (nsid == GL(dl_nns))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__rtld_lock_initialize (GL(dl_ns)[nsid]._ns_unique_sym_table.lock);
|
|
Packit |
6c4009 |
++GL(dl_nns);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_dl_debug_initialize (0, nsid)->r_state = RT_CONSISTENT;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
/* Never allow loading a DSO in a namespace which is empty. Such
|
|
Packit |
6c4009 |
direct placements is only causing problems. Also don't allow
|
|
Packit |
6c4009 |
loading into a namespace used for auditing. */
|
|
Packit |
6c4009 |
else if (__glibc_unlikely (nsid != LM_ID_BASE && nsid != __LM_ID_CALLER)
|
|
Packit |
6c4009 |
&& (__glibc_unlikely (nsid < 0 || nsid >= GL(dl_nns))
|
|
Packit |
6c4009 |
/* This prevents the [NSID] index expressions from being
|
|
Packit |
6c4009 |
evaluated, so the compiler won't think that we are
|
|
Packit |
6c4009 |
accessing an invalid index here in the !SHARED case where
|
|
Packit |
6c4009 |
DL_NNS is 1 and so any NSID != 0 is invalid. */
|
|
Packit |
6c4009 |
|| DL_NNS == 1
|
|
Packit |
6c4009 |
|| GL(dl_ns)[nsid]._ns_nloaded == 0
|
|
Packit |
6c4009 |
|| GL(dl_ns)[nsid]._ns_loaded->l_auditing))
|
|
Packit |
6c4009 |
_dl_signal_error (EINVAL, file, NULL,
|
|
Packit |
6c4009 |
N_("invalid target namespace in dlmopen()"));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct dl_open_args args;
|
|
Packit |
6c4009 |
args.file = file;
|
|
Packit |
6c4009 |
args.mode = mode;
|
|
Packit |
6c4009 |
args.caller_dlopen = caller_dlopen;
|
|
Packit |
6c4009 |
args.map = NULL;
|
|
Packit |
6c4009 |
args.nsid = nsid;
|
|
Packit |
6c4009 |
args.argc = argc;
|
|
Packit |
6c4009 |
args.argv = argv;
|
|
Packit |
6c4009 |
args.env = env;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct dl_exception exception;
|
|
Packit |
6c4009 |
int errcode = _dl_catch_exception (&exception, dl_open_worker, &args);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined USE_LDCONFIG && !defined MAP_COPY
|
|
Packit |
6c4009 |
/* We must unmap the cache file. */
|
|
Packit |
6c4009 |
_dl_unload_cache ();
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit Bot |
8ab9c5 |
/* Do this for both the error and success cases. The old value has
|
|
Packit Bot |
8ab9c5 |
only been determined if the namespace ID was assigned (i.e., it
|
|
Packit Bot |
8ab9c5 |
is not __LM_ID_CALLER). In the success case, we actually may
|
|
Packit Bot |
8ab9c5 |
have consumed more pending adds than planned (because the local
|
|
Packit Bot |
8ab9c5 |
scopes overlap in case of a recursive dlopen, the inner dlopen
|
|
Packit Bot |
8ab9c5 |
doing some of the globalization work of the outer dlopen), so the
|
|
Packit Bot |
8ab9c5 |
old pending adds value is larger than absolutely necessary.
|
|
Packit Bot |
8ab9c5 |
Since it is just a conservative upper bound, this is harmless.
|
|
Packit Bot |
8ab9c5 |
The top-level dlopen call will restore the field to zero. */
|
|
Packit Bot |
8ab9c5 |
if (args.nsid >= 0)
|
|
Packit Bot |
8ab9c5 |
GL (dl_ns)[args.nsid]._ns_global_scope_pending_adds
|
|
Packit Bot |
8ab9c5 |
= args.original_global_scope_pending_adds;
|
|
Packit Bot |
8ab9c5 |
|
|
Packit |
6c4009 |
/* See if an error occurred during loading. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (exception.errstring != NULL))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Remove the object from memory. It may be in an inconsistent
|
|
Packit |
6c4009 |
state if relocation failed, for example. */
|
|
Packit |
6c4009 |
if (args.map)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Maybe some of the modules which were loaded use TLS.
|
|
Packit |
6c4009 |
Since it will be removed in the following _dl_close call
|
|
Packit |
6c4009 |
we have to mark the dtv array as having gaps to fill the
|
|
Packit |
6c4009 |
holes. This is a pessimistic assumption which won't hurt
|
|
Packit |
6c4009 |
if not true. There is no need to do this when we are
|
|
Packit |
6c4009 |
loading the auditing DSOs since TLS has not yet been set
|
|
Packit |
6c4009 |
up. */
|
|
Packit |
6c4009 |
if ((mode & __RTLD_AUDIT) == 0)
|
|
Packit |
6c4009 |
GL(dl_tls_dtv_gaps) = true;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_dl_close_worker (args.map, true);
|
|
Packit Bot |
f2790b |
|
|
Packit Bot |
69412d |
/* All l_nodelete_pending objects should have been deleted
|
|
Packit Bot |
69412d |
at this point, which is why it is not necessary to reset
|
|
Packit Bot |
69412d |
the flag here. */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
assert (_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Release the lock. */
|
|
Packit |
6c4009 |
__rtld_lock_unlock_recursive (GL(dl_load_lock));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Reraise the error. */
|
|
Packit |
6c4009 |
_dl_signal_exception (errcode, &exception, NULL);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
assert (_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Release the lock. */
|
|
Packit |
6c4009 |
__rtld_lock_unlock_recursive (GL(dl_load_lock));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return args.map;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
_dl_show_scope (struct link_map *l, int from)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
_dl_debug_printf ("object=%s [%lu]\n",
|
|
Packit |
6c4009 |
DSO_FILENAME (l->l_name), l->l_ns);
|
|
Packit |
6c4009 |
if (l->l_scope != NULL)
|
|
Packit |
6c4009 |
for (int scope_cnt = from; l->l_scope[scope_cnt] != NULL; ++scope_cnt)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
_dl_debug_printf (" scope %u:", scope_cnt);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (unsigned int cnt = 0; cnt < l->l_scope[scope_cnt]->r_nlist; ++cnt)
|
|
Packit |
6c4009 |
if (*l->l_scope[scope_cnt]->r_list[cnt]->l_name)
|
|
Packit |
6c4009 |
_dl_debug_printf_c (" %s",
|
|
Packit |
6c4009 |
l->l_scope[scope_cnt]->r_list[cnt]->l_name);
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
_dl_debug_printf_c (" %s", RTLD_PROGNAME);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_dl_debug_printf_c ("\n");
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
_dl_debug_printf (" no scope\n");
|
|
Packit |
6c4009 |
_dl_debug_printf ("\n");
|
|
Packit |
6c4009 |
}
|