GL(dl_loaded)->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;
main_map->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;
dl_main (const ElfW(Phdr) *phdr,	 ElfW(Word) phnum,	 ElfW(Addr) *user_entry){  const ElfW(Phdr) *ph;  enum mode mode;  struct link_map **preloads;  unsigned int npreloads;  size_t file_size;  char *file;  bool has_interp = false;  unsigned int i;  bool prelinked = false;  bool rtld_is_main = false;#ifndef HP_TIMING_NONAVAIL  hp_timing_t start;  hp_timing_t stop;  hp_timing_t diff;#endif#ifdef USE_TLS  void *tcbp;#endif#ifdef _LIBC_REENTRANT  /* Explicit initialization since the reloc would just be more work.  */  GL(dl_error_catch_tsd) = &_dl_initial_error_catch_tsd;#endif#ifdef USE_TLS  GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;#endif#if defined SHARED && defined _LIBC_REENTRANT \    && defined __rtld_lock_default_lock_recursive  GL(dl_rtld_lock_recursive) = rtld_lock_default_lock_recursive;  GL(dl_rtld_unlock_recursive) = rtld_lock_default_unlock_recursive;#endif  /* The explicit initialization here is cheaper than processing the reloc     in the _rtld_local definition's initializer.  */  GL(dl_make_stack_executable_hook) = &_dl_make_stack_executable;  /* Process the environment variable which control the behaviour.  */  process_envvars (&mode);#ifndef HAVE_INLINED_SYSCALLS  /* Set up a flag which tells we are just starting.  */  INTUSE(_dl_starting_up) = 1;#endif  if (*user_entry == (ElfW(Addr)) ENTRY_POINT)    {      /* Ho ho.  We are not the program interpreter!  We are the program	 itself!  This means someone ran ld.so as a command.  Well, that	 might be convenient to do sometimes.  We support it by	 interpreting the args like this:	 ld.so PROGRAM ARGS...	 The first argument is the name of a file containing an ELF	 executable we will load and run with the following arguments.	 To simplify life here, PROGRAM is searched for using the	 normal rules for shared objects, rather than $PATH or anything	 like that.  We just load it and use its entry point; we don't	 pay attention to its PT_INTERP command (we are the interpreter	 ourselves).  This is an easy way to test a new ld.so before	 installing it.  */      rtld_is_main = true;      /* Note the place where the dynamic linker actually came from.  */      GL(dl_rtld_map).l_name = rtld_progname;      while (_dl_argc > 1)	if (! strcmp (INTUSE(_dl_argv)[1], "--list"))	  {	    mode = list;	    GLRO(dl_lazy) = -1;	/* This means do no dependency analysis.  */	    ++_dl_skip_args;	    --_dl_argc;	    ++INTUSE(_dl_argv);	  }	else if (! strcmp (INTUSE(_dl_argv)[1], "--verify"))	  {	    mode = verify;	    ++_dl_skip_args;	    --_dl_argc;	    ++INTUSE(_dl_argv);	  }	else if (! strcmp (INTUSE(_dl_argv)[1], "--library-path")		 && _dl_argc > 2)	  {	    library_path = INTUSE(_dl_argv)[2];	    _dl_skip_args += 2;	    _dl_argc -= 2;	    INTUSE(_dl_argv) += 2;	  }	else if (! strcmp (INTUSE(_dl_argv)[1], "--inhibit-rpath")		 && _dl_argc > 2)	  {	    GLRO(dl_inhibit_rpath) = INTUSE(_dl_argv)[2];	    _dl_skip_args += 2;	    _dl_argc -= 2;	    INTUSE(_dl_argv) += 2;	  }	else	  break;      /* If we have no further argument the program was called incorrectly.	 Grant the user some education.  */      if (_dl_argc < 2)	_dl_fatal_printf ("\Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\You have invoked `ld.so', the helper program for shared library executables.\n\This program usually lives in the file `/lib/ld.so', and special directives\n\in executable files using ELF shared libraries tell the system's program\n\loader to load the helper program from this file.  This helper program loads\n\the shared libraries needed by the program executable, prepares the program\n\to run, and runs it.  You may invoke this helper program directly from the\n\command line to load and run an ELF executable file; this is like executing\n\that file itself, but always uses this helper program from the file you\n\specified, instead of the helper program file specified in the executable\n\file you run.  This is mostly of use for maintainers to test new versions\n\of this helper program; chances are you did not intend to run this program.\n\\n\  --list                list all dependencies and how they are resolved\n\  --verify              verify that given object really is a dynamically linked\n\                        object we can handle\n\  --library-path PATH   use given PATH instead of content of the environment\n\                        variable LD_LIBRARY_PATH\n\  --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\                        in LIST\n");      ++_dl_skip_args;      --_dl_argc;      ++INTUSE(_dl_argv);      /* Initialize the data structures for the search paths for shared	 objects.  */      _dl_init_paths (library_path);      /* The initialization of _dl_stack_flags done below assumes the	 executable's PT_GNU_STACK may have been honored by the kernel, and	 so a PT_GNU_STACK with PF_X set means the stack started out with	 execute permission.  However, this is not really true if the	 dynamic linker is the executable the kernel loaded.  For this	 case, we must reinitialize _dl_stack_flags to match the dynamic	 linker itself.  If the dynamic linker was built with a	 PT_GNU_STACK, then the kernel may have loaded us with a	 nonexecutable stack that we will have to make executable when we	 load the program below unless it has a PT_GNU_STACK indicating	 nonexecutable stack is ok.  */      for (ph = phdr; ph < &phdr[phnum]; ++ph)	if (ph->p_type == PT_GNU_STACK)	  {	    GL(dl_stack_flags) = ph->p_flags;	    break;	  }      if (__builtin_expect (mode, normal) == verify)	{	  const char *objname;	  const char *err_str = NULL;	  struct map_args args;	  args.str = rtld_progname;	  args.loader = NULL;	  args.is_preloaded = 0;	  args.mode = __RTLD_OPENEXEC;	  (void) _dl_catch_error (&objname, &err_str, map_doit, &args);	  if (__builtin_expect (err_str != NULL, 0))	    /* We don't free the returned string, the programs stops	       anyway.  */	    _exit (EXIT_FAILURE);	}      else	{	  HP_TIMING_NOW (start);	  _dl_map_object (NULL, rtld_progname, 0, lt_library, 0,			  __RTLD_OPENEXEC);	  HP_TIMING_NOW (stop);	  HP_TIMING_DIFF (load_time, start, stop);	}      phdr = GL(dl_loaded)->l_phdr;      phnum = GL(dl_loaded)->l_phnum;      /* We overwrite here a pointer to a malloc()ed string.  But since	 the malloc() implementation used at this point is the dummy	 implementations which has no real free() function it does not	 makes sense to free the old string first.  */      GL(dl_loaded)->l_name = (char *) "";      *user_entry = GL(dl_loaded)->l_entry;    }  else    {      /* Create a link_map for the executable itself.	 This will be what dlopen on "" returns.  */      _dl_new_object ((char *) "", "", lt_executable, NULL, 0);      if (GL(dl_loaded) == NULL)	_dl_fatal_printf ("cannot allocate memory for link map\n");      GL(dl_loaded)->l_phdr = phdr;      GL(dl_loaded)->l_phnum = phnum;      GL(dl_loaded)->l_entry = *user_entry;      /* At this point we are in a bit of trouble.  We would have to	 fill in the values for l_dev and l_ino.  But in general we	 do not know where the file is.  We also do not handle AT_EXECFD	 even if it would be passed up.	 We leave the values here defined to 0.  This is normally no	 problem as the program code itself is normally no shared	 object and therefore cannot be loaded dynamically.  Nothing	 prevent the use of dynamic binaries and in these situations	 we might get problems.  We might not be able to find out	 whether the object is already loaded.  But since there is no	 easy way out and because the dynamic binary must also not	 have an SONAME we ignore this program for now.  If it becomes	 a problem we can force people using SONAMEs.  */      /* We delay initializing the path structure until we got the dynamic	 information for the program.  */    }  GL(dl_loaded)->l_map_end = 0;  GL(dl_loaded)->l_text_end = 0;  /* Perhaps the executable has no PT_LOAD header entries at all.  */  GL(dl_loaded)->l_map_start = ~0;  /* We opened the file, account for it.  */  ++GL(dl_loaded)->l_opencount;  /* Scan the program header table for the dynamic section.  */  for (ph = phdr; ph < &phdr[phnum]; ++ph)    switch (ph->p_type)      {      case PT_PHDR:	/* Find out the load address.  */	GL(dl_loaded)->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;	break;      case PT_DYNAMIC:	/* This tells us where to find the dynamic section,	   which tells us everything we need to do.  */	GL(dl_loaded)->l_ld = (void *) GL(dl_loaded)->l_addr + ph->p_vaddr;	break;      case PT_INTERP:	/* This "interpreter segment" was used by the program loader to	   find the program interpreter, which is this program itself, the	   dynamic linker.  We note what name finds us, so that a future	   dlopen call or DT_NEEDED entry, for something that wants to link	   against the dynamic linker as a shared library, will know that	   the shared object is already loaded.  */	_dl_rtld_libname.name = ((const char *) GL(dl_loaded)->l_addr				 + ph->p_vaddr);	/* _dl_rtld_libname.next = NULL;	Already zero.  */	GL(dl_rtld_map).l_libname = &_dl_rtld_libname;	/* Ordinarilly, we would get additional names for the loader from	   our DT_SONAME.  This can't happen if we were actually linked as	   a static executable (detect this case when we have no DYNAMIC).	   If so, assume the filename component of the interpreter path to	   be our SONAME, and add it to our name list.  */	if (GL(dl_rtld_map).l_ld == NULL)	  {	    const char *p = NULL;	    const char *cp = _dl_rtld_libname.name;	    /* Find the filename part of the path.  */	    while (*cp != '\0')	      if (*cp++ == '/')		p = cp;	    if (p != NULL)	      {		_dl_rtld_libname2.name = p;		/* _dl_rtld_libname2.next = NULL;  Already zero.  */		_dl_rtld_libname.next = &_dl_rtld_libname2;	      }	  }	has_interp = true;	break;      case PT_LOAD:	{	  ElfW(Addr) mapstart;	  ElfW(Addr) allocend;	  /* Remember where the main program starts in memory.  */	  mapstart = (GL(dl_loaded)->l_addr		      + (ph->p_vaddr & ~(ph->p_align - 1)));	  if (GL(dl_loaded)->l_map_start > mapstart)	    GL(dl_loaded)->l_map_start = mapstart;	  /* Also where it ends.  */	  allocend = GL(dl_loaded)->l_addr + ph->p_vaddr + ph->p_memsz;	  if (GL(dl_loaded)->l_map_end < allocend)	    GL(dl_loaded)->l_map_end = allocend;	  if ((ph->p_flags & PF_X) && allocend > GL(dl_loaded)->l_text_end)	    GL(dl_loaded)->l_text_end = allocend;	}	break;#ifdef USE_TLS      case PT_TLS:	if (ph->p_memsz > 0)	  {	    /* Note that in the case the dynamic linker we duplicate work	       here since we read the PT_TLS entry already in	       _dl_start_final.  But the result is repeatable so do not	       check for this special but unimportant case.  */	    GL(dl_loaded)->l_tls_blocksize = ph->p_memsz;	    GL(dl_loaded)->l_tls_align = ph->p_align;	    if (ph->p_align == 0)	      GL(dl_loaded)->l_tls_firstbyte_offset = 0;	    else	      GL(dl_loaded)->l_tls_firstbyte_offset = (ph->p_vaddr						       & (ph->p_align - 1));	    GL(dl_loaded)->l_tls_initimage_size = ph->p_filesz;	    GL(dl_loaded)->l_tls_initimage = (void *) ph->p_vaddr;	    /* This image gets the ID one.  */	    GL(dl_tls_max_dtv_idx) = GL(dl_loaded)->l_tls_modid = 1;	  }	break;#endif      case PT_GNU_STACK:	GL(dl_stack_flags) = ph->p_flags;	break;      case PT_GNU_RELRO:	GL(dl_loaded)->l_relro_addr = ph->p_vaddr;	GL(dl_loaded)->l_relro_size = ph->p_memsz;	break;      }#ifdef USE_TLS    /* Adjust the address of the TLS initialization image in case       the executable is actually an ET_DYN object.  */    if (GL(dl_loaded)->l_tls_initimage != NULL)      GL(dl_loaded)->l_tls_initimage	= (char *) GL(dl_loaded)->l_tls_initimage + GL(dl_loaded)->l_addr;#endif  if (! GL(dl_loaded)->l_map_end)    GL(dl_loaded)->l_map_end = ~0;  if (! GL(dl_loaded)->l_text_end)    GL(dl_loaded)->l_text_end = ~0;  if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name)    {      /* We were invoked directly, so the program might not have a	 PT_INTERP.  */      _dl_rtld_libname.name = GL(dl_rtld_map).l_name;      /* _dl_rtld_libname.next = NULL; 	Already zero.  */      GL(dl_rtld_map).l_libname =  &_dl_rtld_libname;    }  else    assert (GL(dl_rtld_map).l_libname); /* How else did we get here?  */  if (! rtld_is_main)    {      /* Extract the contents of the dynamic section for easy access.  */      elf_get_dynamic_info (GL(dl_loaded), NULL);      /* Set up our cache of pointers into the hash table.  */      _dl_setup_hash (GL(dl_loaded));    }  if (__builtin_expect (mode, normal) == verify)    {      /* We were called just to verify that this is a dynamic	 executable using us as the program interpreter.  Exit with an	 error if we were not able to load the binary or no interpreter	 is specified (i.e., this is no dynamically linked binary.  */      if (GL(dl_loaded)->l_ld == NULL)	_exit (1);      /* We allow here some platform specific code.  */#ifdef DISTINGUISH_LIB_VERSIONS      DISTINGUISH_LIB_VERSIONS;#endif      _exit (has_interp ? 0 : 2);    }  if (! rtld_is_main)    /* Initialize the data structures for the search paths for shared       objects.  */    _dl_init_paths (library_path);  /* Put the link_map for ourselves on the chain so it can be found by     name.  Note that at this point the global chain of link maps contains     exactly one element, which is pointed to by dl_loaded.  */  if (! GL(dl_rtld_map).l_name)    /* If not invoked directly, the dynamic linker shared object file was       found by the PT_INTERP name.  */    GL(dl_rtld_map).l_name = (char *) GL(dl_rtld_map).l_libname->name;  GL(dl_rtld_map).l_type = lt_library;  GL(dl_loaded)->l_next = &GL(dl_rtld_map);  GL(dl_rtld_map).l_prev = GL(dl_loaded);  ++GL(dl_nloaded);  ++GL(dl_load_adds);  /* If LD_USE_LOAD_BIAS env variable has not been seen, default     to not using bias for non-prelinked PIEs and libraries     and using it for executables or prelinked PIEs or libraries.  */  if (GLRO(dl_use_load_bias) == (ElfW(Addr)) -2)    GLRO(dl_use_load_bias) = (GL(dl_loaded)->l_addr == 0) ? -1 : 0;  /* Set up the program header information for the dynamic linker     itself.  It is needed in the dl_iterate_phdr() callbacks.  */  ElfW(Ehdr) *rtld_ehdr = (ElfW(Ehdr) *) GL(dl_rtld_map).l_map_start;  ElfW(Phdr) *rtld_phdr = (ElfW(Phdr) *) (GL(dl_rtld_map).l_map_start					  + rtld_ehdr->e_phoff);  GL(dl_rtld_map).l_phdr = rtld_phdr;  GL(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum;  /* PT_GNU_RELRO is usually the last phdr.  */  size_t cnt = rtld_ehdr->e_phnum;  while (cnt-- > 0)    if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)      {	GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;	GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;	break;      }  /* We have two ways to specify objects to preload: via environment     variable and via the file /etc/ld.so.preload.  The latter can also     be used when security is enabled.  */  preloads = NULL;  npreloads = 0;  if (__builtin_expect (preloadlist != NULL, 0))    {      /* The LD_PRELOAD environment variable gives list of libraries	 separated by white space or colons that are loaded before the	 executable's dependencies and prepended to the global scope	 list.  If the binary is running setuid all elements	 containing a '/' are ignored since it is insecure.  */      char *list = strdupa (preloadlist);      char *p;      HP_TIMING_NOW (start);      /* Prevent optimizing strsep.  Speed is not important here.  */      while ((p = (strsep) (&list, " :")) != NULL)	if (p[0] != '\0'	    && (__builtin_expect (! INTUSE(__libc_enable_secure), 1)		|| strchr (p, '/') == NULL))	  {	    struct link_map *new_map = _dl_map_object (GL(dl_loaded), p, 1,						       lt_library, 0, 0);	    if (++new_map->l_opencount == 1)	      /* It is no duplicate.  */	      ++npreloads;	  }      HP_TIMING_NOW (stop);      HP_TIMING_DIFF (diff, start, stop);      HP_TIMING_ACCUM_NT (load_time, diff);    }  /* There usually is no ld.so.preload file, it should only be used     for emergencies and testing.  So the open call etc should usually     fail.  Using access() on a non-existing file is faster than using     open().  So we do this first.  If it succeeds we do almost twice     the work but this does not matter, since it is not for production     use.  */  static const char preload_file[] = "/etc/ld.so.preload";  if (__builtin_expect (__access (preload_file, R_OK) == 0, 0))    {      /* Read the contents of the file.  */      file = _dl_sysdep_read_whole_file (preload_file, &file_size,					 PROT_READ | PROT_WRITE);      if (__builtin_expect (file != MAP_FAILED, 0))	{	  /* Parse the file.  It contains names of libraries to be loaded,	     separated by white spaces or `:'.  It may also contain	     comments introduced by `#'.  */	  char *problem;	  char *runp;	  size_t rest;	  /* Eliminate comments.  */	  runp = file;	  rest = file_size;	  while (rest > 0)	    {	      char *comment = memchr (runp, '#', rest);	      if (comment == NULL)		break;	      rest -= comment - runp;	      do		*comment = ' ';	      while (--rest > 0 && *++comment != '\n');	    }	  /* We have one problematic case: if we have a name at the end of	     the file without a trailing terminating characters, we cannot	     place the \0.  Handle the case separately.  */	  if (file[file_size - 1] != ' ' && file[file_size - 1] != '\t'	      && file[file_size - 1] != '\n' && file[file_size - 1] != ':')	    {	      problem = &file[file_size];	      while (problem > file && problem[-1] != ' '		     && problem[-1] != '\t'		     && problem[-1] != '\n' && problem[-1] != ':')		--problem;	      if (problem > file)		problem[-1] = '\0';	    }	  else	    {	      problem = NULL;	      file[file_size - 1] = '\0';	    }	  HP_TIMING_NOW (start);	  if (file != problem)	    {	      char *p;	      runp = file;	      while ((p = strsep (&runp, ": \t\n")) != NULL)		if (p[0] != '\0')		  {		    const char *objname;		    const char *err_str = NULL;		    struct map_args args;		    args.str = p;		    args.loader = GL(dl_loaded);		    args.is_preloaded = 1;		    args.mode = 0;		    (void) _dl_catch_error (&objname, &err_str, map_doit,					    &args);		    if (__builtin_expect (err_str != NULL, 0))		      {			_dl_error_printf ("\ERROR: ld.so: object '%s' from %s cannot be preloaded: ignored.\n",					  p, preload_file);			/* No need to call free, this is still before			   the libc's malloc is used.  */		      }		    else if (++args.map->l_opencount == 1)		      /* It is no duplicate.  */		      ++npreloads;		  }	    }	  if (problem != NULL)	    {	      char *p = strndupa (problem, file_size - (problem - file));	      struct link_map *new_map = _dl_map_object (GL(dl_loaded), p, 1,							 lt_library, 0, 0);	      if (++new_map->l_opencount == 1)		/* It is no duplicate.  */		++npreloads;	    }	  HP_TIMING_NOW (stop);	  HP_TIMING_DIFF (diff, start, stop);	  HP_TIMING_ACCUM_NT (load_time, diff);	  /* We don't need the file anymore.  */	  __munmap (file, file_size);	}    }  if (__builtin_expect (npreloads, 0) != 0)    {      /* Set up PRELOADS with a vector of the preloaded libraries.  */      struct link_map *l;      preloads = __alloca (npreloads * sizeof preloads[0]);      l = GL(dl_rtld_map).l_next; /* End of the chain before preloads.  */      i = 0;      do	{	  preloads[i++] = l;	  l = l->l_next;	} while (l);      assert (i == npreloads);    }#ifdef NEED_DL_SYSINFO  struct link_map *sysinfo_map = NULL;  if (GLRO(dl_sysinfo_dso) != NULL)    {      /* Do an abridged version of the work _dl_map_object_from_fd would do	 to map in the object.  It's already mapped and prelinked (and	 better be, since it's read-only and so we couldn't relocate it).	 We just want our data structures to describe it as if we had just	 mapped and relocated it normally.  */      struct link_map *l = _dl_new_object ((char *) "", "", lt_library, NULL,					   0);      if (__builtin_expect (l != NULL, 1))	{	  static ElfW(Dyn) dyn_temp[DL_RO_DYN_TEMP_CNT] attribute_relro;	  l->l_phdr = ((const void *) GLRO(dl_sysinfo_dso)		       + GLRO(dl_sysinfo_dso)->e_phoff);	  l->l_phnum = GLRO(dl_sysinfo_dso)->e_phnum;	  for (uint_fast16_t i = 0; i < l->l_phnum; ++i)	    {	      const ElfW(Phdr) *const ph = &l->l_phdr[i];	      if (ph->p_type == PT_DYNAMIC)		{		  l->l_ld = (void *) ph->p_vaddr;		  l->l_ldnum = ph->p_memsz / sizeof (ElfW(Dyn));		}	      else if (ph->p_type == PT_LOAD)		{		  if (! l->l_addr)		    l->l_addr = ph->p_vaddr;		  else if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)		    l->l_map_end = ph->p_vaddr + ph->p_memsz;		  else if ((ph->p_flags & PF_X)			   && ph->p_vaddr + ph->p_memsz >= l->l_text_end)		    l->l_text_end = ph->p_vaddr + ph->p_memsz;		}	    }	  l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);	  l->l_addr = l->l_map_start - l->l_addr;	  l->l_map_end += l->l_addr;	  l->l_text_end += l->l_addr;	  l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);	  elf_get_dynamic_info (l, dyn_temp);	  _dl_setup_hash (l);	  l->l_relocated = 1;	  /* Now that we have the info handy, use the DSO image's soname	     so this object can be looked up by name.  Note that we do not	     set l_name here.  That field gives the file name of the DSO,	     and this DSO is not associated with any file.  */	  if (l->l_info[DT_SONAME] != NULL)	    {	      /* Work around a kernel problem.  The kernel cannot handle		 addresses in the vsyscall DSO pages in writev() calls.  */	      const char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])				     + l->l_info[DT_SONAME]->d_un.d_val);	      size_t len = strlen (dsoname);	      char *copy = malloc (len);	      if (copy == NULL)		_dl_fatal_printf ("out of memory\n");	      l->l_libname->name = memcpy (copy, dsoname, len);	    }	  /* We have a prelinked DSO preloaded by the system.  */	  if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)	    GLRO(dl_sysinfo) = GLRO(dl_sysinfo_dso)->e_entry + l->l_addr;	  sysinfo_map = l;	}    }#endif  /* Load all the libraries specified by DT_NEEDED entries.  If LD_PRELOAD     specified some libraries to load, these are inserted before the actual     dependencies in the executable's searchlist for symbol resolution.  */  HP_TIMING_NOW (start);  _dl_map_object_deps (GL(dl_loaded), preloads, npreloads, mode == trace, 0);  HP_TIMING_NOW (stop);  HP_TIMING_DIFF (diff, start, stop);  HP_TIMING_ACCUM_NT (load_time, diff);  /* Mark all objects as being in the global scope and set the open     counter.  */  for (i = GL(dl_loaded)->l_searchlist.r_nlist; i > 0; )    {      --i;      GL(dl_loaded)->l_searchlist.r_list[i]->l_global = 1;      ++GL(dl_loaded)->l_searchlist.r_list[i]->l_opencount;    }#ifndef MAP_ANON  /* We are done mapping things, so close the zero-fill descriptor.  */  __close (_dl_zerofd);  _dl_zerofd = -1;#endif  /* Remove _dl_rtld_map from the chain.  */  GL(dl_rtld_map).l_prev->l_next = GL(dl_rtld_map).l_next;  if (GL(dl_rtld_map).l_next)    GL(dl_rtld_map).l_next->l_prev = GL(dl_rtld_map).l_prev;  if (__builtin_expect (GL(dl_rtld_map).l_opencount > 1, 1))    {      /* Some DT_NEEDED entry referred to the interpreter object itself, so	 put it back in the list of visible objects.  We insert it into the	 chain in symbol search order because gdb uses the chain's order as	 its symbol search order.  */      i = 1;      while (GL(dl_loaded)->l_searchlist.r_list[i] != &GL(dl_rtld_map))	++i;      GL(dl_rtld_map).l_prev = GL(dl_loaded)->l_searchlist.r_list[i - 1];      if (__builtin_expect (mode, normal) == normal)	{	  GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist				    ? GL(dl_loaded)->l_searchlist.r_list[i + 1]				    : NULL);#ifdef NEED_DL_SYSINFO	  if (sysinfo_map != NULL	      && GL(dl_rtld_map).l_prev->l_next == sysinfo_map	      && GL(dl_rtld_map).l_next != sysinfo_map)	    GL(dl_rtld_map).l_prev = sysinfo_map;#endif	}      else	/* In trace mode there might be an invisible object (which we	   could not find) after the previous one in the search list.	   In this case it doesn't matter much where we put the	   interpreter object, so we just initialize the list pointer so	   that the assertion below holds.  */	GL(dl_rtld_map).l_next = GL(dl_rtld_map).l_prev->l_next;      assert (GL(dl_rtld_map).l_prev->l_next == GL(dl_rtld_map).l_next);      GL(dl_rtld_map).l_prev->l_next = &GL(dl_rtld_map);      if (GL(dl_rtld_map).l_next != NULL)	{	  assert (GL(dl_rtld_map).l_next->l_prev == GL(dl_rtld_map).l_prev);	  GL(dl_rtld_map).l_next->l_prev = &GL(dl_rtld_map);	}    }  /* Now let us see whether all libraries are available in the     versions we need.  */  {    struct version_check_args args;    args.doexit = mode == normal;    args.dotrace = mode == trace;    _dl_receive_error (print_missing_version, version_check_doit, &args);  }#ifdef USE_TLS  /* Now it is time to determine the layout of the static TLS block     and allocate it for the initial thread.  Note that we always     allocate the static block, we never defer it even if no     DF_STATIC_TLS bit is set.  The reason is that we know glibc will     use the static model.  First add the dynamic linker to the list     if it also uses TLS.  */  if (GL(dl_rtld_map).l_tls_blocksize != 0)    /* Assign a module ID.  */    GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();# ifndef TLS_INIT_TP_EXPENSIVE#  define TLS_INIT_TP_EXPENSIVE 0# endif  /* We do not initialize any of the TLS functionality unless any of the     initial modules uses TLS.  This makes dynamic loading of modules with     TLS impossible, but to support it requires either eagerly doing setup     now or lazily doing it later.  Doing it now makes us incompatible with     an old kernel that can't perform TLS_INIT_TP, even if no TLS is ever     used.  Trying to do it lazily is too hairy to try when there could be     multiple threads (from a non-TLS-using libpthread).  */  if (!TLS_INIT_TP_EXPENSIVE || GL(dl_tls_max_dtv_idx) > 0)    {      struct link_map *l;      size_t nelem;      struct dtv_slotinfo *slotinfo;      /* Number of elements in the static TLS block.  */      GL(dl_tls_static_nelem) = GL(dl_tls_max_dtv_idx);      /* Allocate the array which contains the information about the	 dtv slots.  We allocate a few entries more than needed to	 avoid the need for reallocation.  */      nelem = GL(dl_tls_max_dtv_idx) + 1 + TLS_SLOTINFO_SURPLUS;      /* Allocate.  */      GL(dl_tls_dtv_slotinfo_list) = (struct dtv_slotinfo_list *)	malloc (sizeof (struct dtv_slotinfo_list)		+ nelem * sizeof (struct dtv_slotinfo));      /* No need to check the return value.  If memory allocation failed	 the program would have been terminated.  */      slotinfo = memset (GL(dl_tls_dtv_slotinfo_list)->slotinfo, '\0',			 nelem * sizeof (struct dtv_slotinfo));      GL(dl_tls_dtv_slotinfo_list)->len = nelem;      GL(dl_tls_dtv_slotinfo_list)->next = NULL;      /* Fill in the information from the loaded modules.  */      for (l = GL(dl_loaded), i = 0; l != NULL; l = l->l_next)	if (l->l_tls_blocksize != 0)	  /* This is a module with TLS data.  Store the map reference.	     The generation counter is zero.  */	  slotinfo[++i].map = l;      assert (i == GL(dl_tls_max_dtv_idx));      /* Compute the TLS offsets for the various blocks.  */      _dl_determine_tlsoffset ();      /* Construct the static TLS block and the dtv for the initial	 thread.  For some platforms this will include allocating memory	 for the thread descriptor.  The memory for the TLS block will	 never be freed.  It should be allocated accordingly.  The dtv	 array can be changed if dynamic loading requires it.  */      tcbp = _dl_allocate_tls_storage ();      if (tcbp == NULL)	_dl_fatal_printf ("\cannot allocate TLS data structures for initial thread");      /* Store for detection of the special case by __tls_get_addr	 so it knows not to pass this dtv to the normal realloc.  */      GL(dl_initial_dtv) = GET_DTV (tcbp);    }#endif  if (__builtin_expect (mode, normal) != normal)    {      /* We were run just to list the shared libraries.  It is	 important that we do this before real relocation, because the	 functions we call below for output may no longer work properly	 after relocation.  */      struct link_map *l;      if (GLRO(dl_debug_mask) & DL_DEBUG_PRELINK)	{	  struct r_scope_elem *scope = &GL(dl_loaded)->l_searchlist;	  for (i = 0; i < scope->r_nlist; i++)	    {	      l = scope->r_list [i];	      if (l->l_faked)		{		  _dl_printf ("\t%s => not found\n", l->l_libname->name);		  continue;		}	      if (_dl_name_match_p (GLRO(dl_trace_prelink), l))		GLRO(dl_trace_prelink_map) = l;	      _dl_printf ("\t%s => %s (0x%0*Zx, 0x%0*Zx)",			  l->l_libname->name[0] ? l->l_libname->name			  : rtld_progname ?: "<main program>",			  l->l_name[0] ? l->l_name			  : rtld_progname ?: "<main program>",			  (int) sizeof l->l_map_start * 2,			  (size_t) l->l_map_start,			  (int) sizeof l->l_addr * 2,			  (size_t) l->l_addr);#ifdef USE_TLS	      if (l->l_tls_modid)		_dl_printf (" TLS(0x%Zx, 0x%0*Zx)\n", l->l_tls_modid,			    (int) sizeof l->l_tls_offset * 2,			    (size_t) l->l_tls_offset);	      else#endif		_dl_printf ("\n");	    }	}      else if (GLRO(dl_debug_mask) & DL_DEBUG_UNUSED)	{	  /* Look through the dependencies of the main executable	     and determine which of them is not actually	     required.  */	  struct link_map *l = GL(dl_loaded);	  /* Relocate the main executable.  */	  struct relocate_args args = { .l = l, .lazy = GLRO(dl_lazy) };	  _dl_receive_error (print_unresolved, relocate_doit, &args);	  /* This loop depends on the dependencies of the executable to	     correspond in number and order to the DT_NEEDED entries.  */	  ElfW(Dyn) *dyn = GL(dl_loaded)->l_ld;	  bool first = true;	  while (dyn->d_tag != DT_NULL)	    {	      if (dyn->d_tag == DT_NEEDED)		{		  l = l->l_next;		  if (!l->l_used)		    {		      if (first)			{			  _dl_printf ("Unused direct dependencies:\n");			  first = false;			}		      _dl_printf ("\t%s\n", l->l_name);		    }		}	      ++dyn;	    }	  _exit (first != true);	}      else if (! GL(dl_loaded)->l_info[DT_NEEDED])	_dl_printf ("\tstatically linked\n");      else	{	  for (l = GL(dl_loaded)->l_next; l; l = l->l_next)	    if (l->l_faked)	      /* The library was not found.  */	      _dl_printf ("\t%s => not found\n", l->l_libname->name);	    else if (strcmp (l->l_libname->name, l->l_name) == 0)	      _dl_printf ("\t%s (0x%0*Zx)\n", l->l_libname->name,			  (int) sizeof l->l_map_start * 2,			  (size_t) l->l_map_start);	    else	      _dl_printf ("\t%s => %s (0x%0*Zx)\n", l->l_libname->name,			  l->l_name, (int) sizeof l->l_map_start * 2,			  (size_t) l->l_map_start);	}      if (__builtin_expect (mode, trace) != trace)	for (i = 1; i < (unsigned int) _dl_argc; ++i)	  {	    const ElfW(Sym) *ref = NULL;	    ElfW(Addr) loadbase;	    lookup_t result;	    result = _dl_lookup_symbol_x (INTUSE(_dl_argv)[i], GL(dl_loaded),					  &ref, GL(dl_loaded)->l_scope, NULL,					  ELF_RTYPE_CLASS_PLT,					  DL_LOOKUP_ADD_DEPENDENCY, NULL);	    loadbase = LOOKUP_VALUE_ADDRESS (result);	    _dl_printf ("%s found at 0x%0*Zd in object at 0x%0*Zd\n",			INTUSE(_dl_argv)[i],			(int) sizeof ref->st_value * 2,			(size_t) ref->st_value,			(int) sizeof loadbase * 2, (size_t) loadbase);	  }      else	{	  /* If LD_WARN is set warn about undefined symbols.  */	  if (GLRO(dl_lazy) >= 0 && GLRO(dl_verbose))	    {	      /* We have to do symbol dependency testing.  */	      struct relocate_args args;	      struct link_map *l;	      args.lazy = GLRO(dl_lazy);	      l = GL(dl_loaded);	      while (l->l_next)		l = l->l_next;	      do		{		  if (l != &GL(dl_rtld_map) && ! l->l_faked)		    {		      args.l = l;		      _dl_receive_error (print_unresolved, relocate_doit,					 &args);		    }		  l = l->l_prev;		} while (l);	      if ((GLRO(dl_debug_mask) & DL_DEBUG_PRELINK)		  && GL(dl_rtld_map).l_opencount > 1)		_dl_relocate_object (&GL(dl_rtld_map), GL(dl_loaded)->l_scope,				     0, 0);	    }#define VERNEEDTAG (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (DT_VERNEED))	  if (version_info)	    {	      /* Print more information.  This means here, print information		 about the versions needed.  */	      int first = 1;	      struct link_map *map = GL(dl_loaded);	      for (map = GL(dl_loaded); map != NULL; map = map->l_next)		{		  const char *strtab;		  ElfW(Dyn) *dyn = map->l_info[VERNEEDTAG];		  ElfW(Verneed) *ent;		  if (dyn == NULL)		    continue;		  strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);		  ent = (ElfW(Verneed) *) (map->l_addr + dyn->d_un.d_ptr);		  if (first)		    {		      _dl_printf ("\n\tVersion information:\n");		      first = 0;		    }		  _dl_printf ("\t%s:\n",			      map->l_name[0] ? map->l_name : rtld_progname);		  while (1)		    {		      ElfW(Vernaux) *aux;		      struct link_map *needed;		      needed = find_needed (strtab + ent->vn_file);		      aux = (ElfW(Vernaux) *) ((char *) ent + ent->vn_aux);		      while (1)			{			  const char *fname = NULL;			  if (needed != NULL			      && match_version (strtab + aux->vna_name,						needed))			    fname = needed->l_name;			  _dl_printf ("\t\t%s (%s) %s=> %s\n",				      strtab + ent->vn_file,				      strtab + aux->vna_name,				      aux->vna_flags & VER_FLG_WEAK				      ? "[WEAK] " : "",				      fname ?: "not found");			  if (aux->vna_next == 0)			    /* No more symbols.  */			    break;			  /* Next symbol.  */			  aux = (ElfW(Vernaux) *) ((char *) aux						   + aux->vna_next);			}		      if (ent->vn_next == 0)			/* No more dependencies.  */			break;		      /* Next dependency.  */		      ent = (ElfW(Verneed) *) ((char *) ent + ent->vn_next);		    }		}	    }	}      _exit (0);    }  if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]      && ! __builtin_expect (GLRO(dl_profile) != NULL, 0))    {      ElfW(Lib) *liblist, *liblistend;      struct link_map **r_list, **r_listend, *l;      const char *strtab = (const void *) D_PTR (GL(dl_loaded),						 l_info[DT_STRTAB]);      assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL);      liblist = (ElfW(Lib) *)		GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]->d_un.d_ptr;      liblistend = (ElfW(Lib) *)		   ((char *) liblist		    + GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);      r_list = GL(dl_loaded)->l_searchlist.r_list;      r_listend = r_list + GL(dl_loaded)->l_searchlist.r_nlist;      for (; r_list < r_listend && liblist < liblistend; r_list++)	{	  l = *r_list;	  if (l == GL(dl_loaded))	    continue;	  /* If the library is not mapped where it should, fail.  */	  if (l->l_addr)	    break;	  /* Next, check if checksum matches.  */	  if (l->l_info [VALIDX(DT_CHECKSUM)] == NULL	      || l->l_info [VALIDX(DT_CHECKSUM)]->d_un.d_val		 != liblist->l_checksum)	    break;	  if (l->l_info [VALIDX(DT_GNU_PRELINKED)] == NULL	      || l->l_info [VALIDX(DT_GNU_PRELINKED)]->d_un.d_val		 != liblist->l_time_stamp)	    break;	  if (! _dl_name_match_p (strtab + liblist->l_name, l))	    break;	  ++liblist;	}      if (r_list == r_listend && liblist == liblistend)	prelinked = true;      if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS, 0))	_dl_debug_printf ("\nprelink checking: %s\n",			  prelinked ? "ok" : "failed");    }  /* Initialize _r_debug.  */  struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr);  {    struct link_map *l;    l = GL(dl_loaded);#ifdef ELF_MACHINE_DEBUG_SETUP    /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */    ELF_MACHINE_DEBUG_SETUP (l, r);    ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);#else    if (l->l_info[DT_DEBUG] != NULL)      /* There is a DT_DEBUG entry in the dynamic section.  Fill it in	 with the run-time address of the r_debug structure  */      l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;    /* Fill in the pointer in the dynamic linker's own dynamic section, in       case you run gdb on the dynamic linker directly.  */    if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)      GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;#endif  }  /* Now set up the variable which helps the assembler startup code.  */  GL(dl_main_searchlist) = &GL(dl_loaded)->l_searchlist;  GL(dl_global_scope)[0] = &GL(dl_loaded)->l_searchlist;  /* Save the information about the original global scope list since     we need it in the memory handling later.  */  GLRO(dl_initial_searchlist) = *GL(dl_main_searchlist);  if (prelinked)    {      struct link_map *l;      if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)	{	  ElfW(Rela) *conflict, *conflictend;#ifndef HP_TIMING_NONAVAIL	  hp_timing_t start;	  hp_timing_t stop;#endif	  HP_TIMING_NOW (start);	  assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);	  conflict = (ElfW(Rela) *)	    GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;	  conflictend = (ElfW(Rela) *)	    ((char *) conflict	     + GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);	  _dl_resolve_conflicts (GL(dl_loaded), conflict, conflictend);	  HP_TIMING_NOW (stop);	  HP_TIMING_DIFF (relocate_time, start, stop);	}      /* Mark all the objects so we know they have been already relocated.  */      for (l = GL(dl_loaded); l != NULL; l = l->l_next)	{	  l->l_relocated = 1;	  if (l->l_relro_size)	    _dl_protect_relro (l);	}      _dl_sysdep_start_cleanup ();    }  else    {      /* Now we have all the objects loaded.  Relocate them all except for	 the dynamic linker itself.  We do this in reverse order so that copy	 relocs of earlier objects overwrite the data written by later	 objects.  We do not re-relocate the dynamic linker itself in this	 loop because that could result in the GOT entries for functions we	 call being changed, and that would break us.  It is safe to relocate	 the dynamic linker out of order because it has no copy relocs (we	 know that because it is self-contained).  */      struct link_map *l;      int consider_profiling = GLRO(dl_profile) != NULL;#ifndef HP_TIMING_NONAVAIL      hp_timing_t start;      hp_timing_t stop;      hp_timing_t add;#endif      /* If we are profiling we also must do lazy reloaction.  */      GLRO(dl_lazy) |= consider_profiling;      l = GL(dl_loaded);      while (l->l_next)	l = l->l_next;      HP_TIMING_NOW (start);      do	{	  /* While we are at it, help the memory handling a bit.  We have to	     mark some data structures as allocated with the fake malloc()	     implementation in ld.so.  */	  struct libname_list *lnp = l->l_libname->next;	  while (__builtin_expect (lnp != NULL, 0))	    {	      lnp->dont_free = 1;	      lnp = lnp->next;	    }	  if (l != &GL(dl_rtld_map))	    _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy),				 consider_profiling);	  l = l->l_prev;	}      while (l);      HP_TIMING_NOW (stop);      HP_TIMING_DIFF (relocate_time, start, stop);      /* Do any necessary cleanups for the startup OS interface code.	 We do these now so that no calls are made after rtld re-relocation	 which might be resolved to different functions than we expect.	 We cannot do this before relocating the other objects because	 _dl_relocate_object might need to call `mprotect' for DT_TEXTREL.  */      _dl_sysdep_start_cleanup ();      /* Now enable profiling if needed.  Like the previous call,	 this has to go here because the calls it makes should use the	 rtld versions of the functions (particularly calloc()), but it	 needs to have _dl_profile_map set up by the relocator.  */      if (__builtin_expect (GL(dl_profile_map) != NULL, 0))	/* We must prepare the profiling.  */	_dl_start_profile ();      if (GL(dl_rtld_map).l_opencount > 1)	{	  /* There was an explicit ref to the dynamic linker as a shared lib.	     Re-relocate ourselves with user-controlled symbol definitions.  */	  HP_TIMING_NOW (start);	  _dl_relocate_object (&GL(dl_rtld_map), GL(dl_loaded)->l_scope, 0, 0);	  HP_TIMING_NOW (stop);	  HP_TIMING_DIFF (add, start, stop);	  HP_TIMING_ACCUM_NT (relocate_time, add);	}    }#ifndef NONTLS_INIT_TP# define NONTLS_INIT_TP do { } while (0)#endif#ifdef USE_TLS  if (GL(dl_tls_max_dtv_idx) > 0 || USE___THREAD || !TLS_INIT_TP_EXPENSIVE)    {      /* Now that we have completed relocation, the initializer data	 for the TLS blocks has its final values and we can copy them	 into the main thread's TLS area, which we allocated above.  */      _dl_allocate_tls_init (tcbp);      /* And finally install it for the main thread.  If ld.so itself uses	 TLS we know the thread pointer was initialized earlier.  */      const char *lossage = TLS_INIT_TP (tcbp, USE___THREAD);      if (__builtin_expect (lossage != NULL, 0))	_dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);    }  else#endif    NONTLS_INIT_TP;  /* Notify the debugger that all objects are now mapped in.  */  r->r_state = RT_ADD;  _dl_debug_state ();#ifndef MAP_COPY  /* We must munmap() the cache file.  */  _dl_unload_cache ();#endif  /* Once we return, _dl_sysdep_start will invoke     the DT_INIT functions and then *USER_ENTRY.  */}