GL(dl_global_scope_alloc) = 0;
GL(dl_ns)[new->l_ns]._ns_global_scope_alloc = 0;
extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,				    void (*dl_main) (const ElfW(Phdr) *phdr,						     ElfW(Word) phnum,						     ElfW(Addr) *user_entry));weak_extern (BP_SYM (_dl_sysdep_start))extern int __libc_multiple_libcs;	/* Defined in init-first.c.  */extern int __libc_argc attribute_hidden;extern char **__libc_argv attribute_hidden;extern char **__environ;/* Undefine the following for debugging.  *//* #define SCOPE_DEBUG 1 */#ifdef SCOPE_DEBUGstatic void show_scope (struct link_map *new);#endif/* We must be carefull not to leave us in an inconsistent state.  Thus we   catch any error and re-raise it after cleaning up.  */struct dl_open_args{  const char *file;  int mode;  /* This is the caller of the dlopen() function.  */  const void *caller_dlopen;  /* This is the caller if _dl_open().  */  const void *caller_dl_open;  struct link_map *map;};static intadd_to_global (struct link_map *new){  struct link_map **new_global;  unsigned int to_add = 0;  unsigned int cnt;  /* Count the objects we have to put in the global scope.  */  for (cnt = 0; cnt < new->l_searchlist.r_nlist; ++cnt)    if (new->l_searchlist.r_list[cnt]->l_global == 0)      ++to_add;  /* The symbols of the new objects and its dependencies are to be     introduced into the global scope that will be used to resolve     references from other dynamically-loaded objects.     The global scope is the searchlist in the main link map.  We     extend this list if necessary.  There is one problem though:     since this structure was allocated very early (before the libc     is loaded) the memory it uses is allocated by the malloc()-stub     in the ld.so.  When we come here these functions are not used     anymore.  Instead the malloc() implementation of the libc is     used.  But this means the block from the main map cannot be used     in an realloc() call.  Therefore we allocate a completely new     array the first time we have to add something to the locale scope.  */  if (GL(dl_global_scope_alloc) == 0)    {      /* This is the first dynamic object given global scope.  */      GL(dl_global_scope_alloc) = GL(dl_main_searchlist)->r_nlist + to_add + 8;      new_global = (struct link_map **)	malloc (GL(dl_global_scope_alloc) * sizeof (struct link_map *));      if (new_global == NULL)	{	  GL(dl_global_scope_alloc) = 0;	nomem:	  GLRO(dl_signal_error) (ENOMEM, new->l_libname->name, NULL,				 N_("cannot extend global scope"));	  return 1;	}      /* Copy over the old entries.  */      memcpy (new_global, GL(dl_main_searchlist)->r_list,	      (GL(dl_main_searchlist)->r_nlist * sizeof (struct link_map *)));      GL(dl_main_searchlist)->r_list = new_global;    }  else if (GL(dl_main_searchlist)->r_nlist + to_add	   > GL(dl_global_scope_alloc))    {      /* We have to extend the existing array of link maps in the	 main map.  */      new_global = (struct link_map **)	realloc (GL(dl_main_searchlist)->r_list,		 ((GL(dl_global_scope_alloc) + to_add + 8)		  * sizeof (struct link_map *)));      if (new_global == NULL)	goto nomem;      GL(dl_global_scope_alloc) += to_add + 8;      GL(dl_main_searchlist)->r_list = new_global;    }  /* Now add the new entries.  */  for (cnt = 0; cnt < new->l_searchlist.r_nlist; ++cnt)    {      struct link_map *map = new->l_searchlist.r_list[cnt];      if (map->l_global == 0)	{	  map->l_global = 1;	  GL(dl_main_searchlist)->r_list[GL(dl_main_searchlist)->r_nlist]	    = map;	  ++GL(dl_main_searchlist)->r_nlist;	}    }  return 0;}