summaryrefslogtreecommitdiff
path: root/elf/dl-open.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-03-19 21:04:10 +0000
committerJakub Jelinek <jakub@redhat.com>2005-03-19 21:04:10 +0000
commit8f8ebbc438fcb4b22fba8beb3ef3d1aa59d9d7bf (patch)
treeb7091affa76bbaf47e78a59dfc72b2102554eaf9 /elf/dl-open.c
parentf5c3480e830e94e0e51a0bdb1053944daed8bc58 (diff)
downloadglibc-8f8ebbc438fcb4b22fba8beb3ef3d1aa59d9d7bf.tar.gz
Updated to fedora-glibc-20050319T1907cvs/fedora-glibc-2_3_4-15
Diffstat (limited to 'elf/dl-open.c')
-rw-r--r--elf/dl-open.c187
1 files changed, 85 insertions, 102 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 4de20720ed..7433d99ff9 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -281,23 +281,14 @@ dl_open_worker (void *a)
{
/* Let the user know about the opencount. */
if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0))
- _dl_debug_printf ("opening file=%s [%lu]; opencount=%u\n\n",
- new->l_name, new->l_ns, new->l_opencount);
+ _dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n",
+ new->l_name, new->l_ns, new->l_direct_opencount);
/* If the user requested the object to be in the global namespace
but it is not so far, add it now. */
if ((mode & RTLD_GLOBAL) && new->l_global == 0)
(void) add_to_global (new);
- if (new->l_direct_opencount == 1)
- /* This is the only direct reference. Increment all the
- dependencies' reference counter. */
- for (i = 0; i < new->l_searchlist.r_nlist; ++i)
- ++new->l_searchlist.r_list[i]->l_opencount;
- else
- /* Increment just the reference counter of the object. */
- ++new->l_opencount;
-
assert (_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT);
return;
@@ -386,94 +377,92 @@ dl_open_worker (void *a)
l = l->l_prev;
}
- /* Increment the open count for all dependencies. If the file is
- not loaded as a dependency here add the search list of the newly
- loaded object to the scope. */
+ /* If the file is not loaded now as a dependency, add the search
+ list of the newly loaded object to the scope. */
for (i = 0; i < new->l_searchlist.r_nlist; ++i)
- if (++new->l_searchlist.r_list[i]->l_opencount > 1
- && new->l_real->l_searchlist.r_list[i]->l_type == lt_loaded)
- {
- struct link_map *imap = new->l_searchlist.r_list[i];
- struct r_scope_elem **runp = imap->l_scope;
- size_t cnt = 0;
-
- while (*runp != NULL)
- {
- /* This can happen if imap was just loaded, but during
- relocation had l_opencount bumped because of relocation
- dependency. Avoid duplicates in l_scope. */
- if (__builtin_expect (*runp == &new->l_searchlist, 0))
- break;
-
- ++cnt;
- ++runp;
- }
-
- if (*runp != NULL)
- /* Avoid duplicates. */
- continue;
-
- if (__builtin_expect (cnt + 1 >= imap->l_scope_max, 0))
- {
- /* The 'r_scope' array is too small. Allocate a new one
- dynamically. */
- struct r_scope_elem **newp;
- size_t new_size = imap->l_scope_max * 2;
-
- if (imap->l_scope == imap->l_scope_mem)
- {
- newp = (struct r_scope_elem **)
- malloc (new_size * sizeof (struct r_scope_elem *));
- if (newp == NULL)
- _dl_signal_error (ENOMEM, "dlopen", NULL,
- N_("cannot create scope list"));
- imap->l_scope = memcpy (newp, imap->l_scope,
- cnt * sizeof (imap->l_scope[0]));
- }
- else
- {
- newp = (struct r_scope_elem **)
- realloc (imap->l_scope,
- new_size * sizeof (struct r_scope_elem *));
- if (newp == NULL)
- _dl_signal_error (ENOMEM, "dlopen", NULL,
- N_("cannot create scope list"));
- imap->l_scope = newp;
- }
-
- imap->l_scope_max = new_size;
- }
-
- imap->l_scope[cnt++] = &new->l_searchlist;
- imap->l_scope[cnt] = NULL;
- }
+ {
+ struct link_map *imap = new->l_searchlist.r_list[i];
+
+ /* If the initializer has been called already, the object has
+ not been loaded here and now. */
+ if (imap->l_init_called && imap->l_type == lt_loaded)
+ {
+ struct r_scope_elem **runp = imap->l_scope;
+ size_t cnt = 0;
+
+ while (*runp != NULL)
+ {
+ ++cnt;
+ ++runp;
+ }
+
+ if (*runp != NULL)
+ /* Avoid duplicates. */
+ continue;
+
+ if (__builtin_expect (cnt + 1 >= imap->l_scope_max, 0))
+ {
+ /* The 'r_scope' array is too small. Allocate a new one
+ dynamically. */
+ struct r_scope_elem **newp;
+ size_t new_size = imap->l_scope_max * 2;
+
+ if (imap->l_scope == imap->l_scope_mem)
+ {
+ newp = (struct r_scope_elem **)
+ malloc (new_size * sizeof (struct r_scope_elem *));
+ if (newp == NULL)
+ _dl_signal_error (ENOMEM, "dlopen", NULL,
+ N_("cannot create scope list"));
+ imap->l_scope = memcpy (newp, imap->l_scope,
+ cnt * sizeof (imap->l_scope[0]));
+ }
+ else
+ {
+ newp = (struct r_scope_elem **)
+ realloc (imap->l_scope,
+ new_size * sizeof (struct r_scope_elem *));
+ if (newp == NULL)
+ _dl_signal_error (ENOMEM, "dlopen", NULL,
+ N_("cannot create scope list"));
+ imap->l_scope = newp;
+ }
+
+ imap->l_scope_max = new_size;
+ }
+
+ imap->l_scope[cnt++] = &new->l_searchlist;
+ imap->l_scope[cnt] = NULL;
+ }
#if USE_TLS
- else if (new->l_searchlist.r_list[i]->l_opencount == 1
- /* Only if the module defines thread local data. */
- && __builtin_expect (new->l_searchlist.r_list[i]->l_tls_blocksize
- > 0, 0))
- {
- /* Now that we know the object is loaded successfully add
- modules containing TLS data to the slot info table. We
- might have to increase its size. */
- _dl_add_to_slotinfo (new->l_searchlist.r_list[i]);
-
- if (new->l_searchlist.r_list[i]->l_need_tls_init)
- {
- new->l_searchlist.r_list[i]->l_need_tls_init = 0;
+ /* Only add TLS memory if this object is loaded now and
+ therefore is not yet initialized. */
+ else if (! imap->l_init_called
+ /* Only if the module defines thread local data. */
+ && __builtin_expect (imap->l_tls_blocksize > 0, 0))
+ {
+ /* Now that we know the object is loaded successfully add
+ modules containing TLS data to the slot info table. We
+ might have to increase its size. */
+ _dl_add_to_slotinfo (imap);
+
+ if (imap->l_need_tls_init)
+ {
+ imap->l_need_tls_init = 0;
# ifdef SHARED
- /* Update the slot information data for at least the
- generation of the DSO we are allocating data for. */
- _dl_update_slotinfo (new->l_searchlist.r_list[i]->l_tls_modid);
+ /* Update the slot information data for at least the
+ generation of the DSO we are allocating data for. */
+ _dl_update_slotinfo (imap->l_tls_modid);
# endif
- GL(dl_init_static_tls) (new->l_searchlist.r_list[i]);
- assert (new->l_searchlist.r_list[i]->l_need_tls_init == 0);
- }
+ GL(dl_init_static_tls) (imap);
+ assert (imap->l_need_tls_init == 0);
+ }
- /* We have to bump the generation counter. */
- any_tls = true;
- }
+ /* We have to bump the generation counter. */
+ any_tls = true;
+ }
+ }
/* Bump the generation number if necessary. */
if (any_tls && __builtin_expect (++GL(dl_tls_generation) == 0, 0))
@@ -504,8 +493,8 @@ TLS generation counter wrapped! Please report this."));
/* Let the user know about the opencount. */
if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0))
- _dl_debug_printf ("opening file=%s [%lu]; opencount=%u\n\n",
- new->l_name, new->l_ns, new->l_opencount);
+ _dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n",
+ new->l_name, new->l_ns, new->l_direct_opencount);
}
@@ -581,12 +570,6 @@ no more namespaces available for dlmopen()"));
state if relocation failed, for example. */
if (args.map)
{
- /* Increment open counters for all objects since this
- sometimes has not happened yet. */
- if (args.map->l_searchlist.r_list[0]->l_opencount == 0)
- for (unsigned int i = 0; i < args.map->l_searchlist.r_nlist; ++i)
- ++args.map->l_searchlist.r_list[i]->l_opencount;
-
#ifdef USE_TLS
/* Maybe some of the modules which were loaded use TLS.
Since it will be removed in the following _dl_close call
@@ -618,7 +601,7 @@ no more namespaces available for dlmopen()"));
memcpy (local_errstring, errstring, len_errstring);
}
- if (errstring != INTUSE(_dl_out_of_memory))
+ if (errstring != _dl_out_of_memory)
free ((char *) errstring);
assert (_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT);