08c3a6
commit b0bd6a1323c3eccd16c45bae359a76877fa75639
08c3a6
Author: Florian Weimer <fweimer@redhat.com>
08c3a6
Date:   Thu May 19 11:43:53 2022 +0200
08c3a6
08c3a6
    elf: Merge dl-sysdep.c into the Linux version
08c3a6
    
08c3a6
    The generic version is the de-facto Linux implementation.  It
08c3a6
    requires an auxiliary vector, so Hurd does not use it.
08c3a6
    
08c3a6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
08c3a6
    (cherry picked from commit 91c0a47ffb66e7cd802de870686465db3b3976a0)
08c3a6
08c3a6
Conflicts:
08c3a6
	elf/dl-sysdep.c
08c3a6
	  (missing ld.so dependency sorting optimization upstream)
08c3a6
08c3a6
diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c
08c3a6
index 1c78dc89c9cbe54d..7aa90ad6eeb35cad 100644
08c3a6
--- a/elf/dl-sysdep.c
08c3a6
+++ b/elf/dl-sysdep.c
08c3a6
@@ -1,5 +1,5 @@
08c3a6
-/* Operating system support for run-time dynamic linker.  Generic Unix version.
08c3a6
-   Copyright (C) 1995-2021 Free Software Foundation, Inc.
08c3a6
+/* Operating system support for run-time dynamic linker.  Stub version.
08c3a6
+   Copyright (C) 1995-2022 Free Software Foundation, Inc.
08c3a6
    This file is part of the GNU C Library.
08c3a6
 
08c3a6
    The GNU C Library is free software; you can redistribute it and/or
08c3a6
@@ -16,352 +16,4 @@
08c3a6
    License along with the GNU C Library; if not, see
08c3a6
    <https://www.gnu.org/licenses/>.  */
08c3a6
 
08c3a6
-/* We conditionalize the whole of this file rather than simply eliding it
08c3a6
-   from the static build, because other sysdeps/ versions of this file
08c3a6
-   might define things needed by a static build.  */
08c3a6
-
08c3a6
-#ifdef SHARED
08c3a6
-
08c3a6
-#include <assert.h>
08c3a6
-#include <elf.h>
08c3a6
-#include <errno.h>
08c3a6
-#include <fcntl.h>
08c3a6
-#include <libintl.h>
08c3a6
-#include <stdlib.h>
08c3a6
-#include <string.h>
08c3a6
-#include <unistd.h>
08c3a6
-#include <sys/types.h>
08c3a6
-#include <sys/stat.h>
08c3a6
-#include <sys/mman.h>
08c3a6
-#include <ldsodefs.h>
08c3a6
-#include <_itoa.h>
08c3a6
-#include <fpu_control.h>
08c3a6
-
08c3a6
-#include <entry.h>
08c3a6
-#include <dl-machine.h>
08c3a6
-#include <dl-procinfo.h>
08c3a6
-#include <dl-osinfo.h>
08c3a6
-#include <libc-internal.h>
08c3a6
-#include <tls.h>
08c3a6
-
08c3a6
-#include <dl-tunables.h>
08c3a6
-#include <dl-auxv.h>
08c3a6
-#include <dl-hwcap-check.h>
08c3a6
-
08c3a6
-extern char **_environ attribute_hidden;
08c3a6
-extern char _end[] attribute_hidden;
08c3a6
-
08c3a6
-/* Protect SUID program against misuse of file descriptors.  */
08c3a6
-extern void __libc_check_standard_fds (void);
08c3a6
-
08c3a6
-int __libc_enable_secure attribute_relro = 0;
08c3a6
-rtld_hidden_data_def (__libc_enable_secure)
08c3a6
-/* This variable contains the lowest stack address ever used.  */
08c3a6
-void *__libc_stack_end attribute_relro = NULL;
08c3a6
-rtld_hidden_data_def(__libc_stack_end)
08c3a6
-void *_dl_random attribute_relro = NULL;
08c3a6
-
08c3a6
-#ifndef DL_FIND_ARG_COMPONENTS
08c3a6
-# define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp)	\
08c3a6
-  do {									      \
08c3a6
-    void **_tmp;							      \
08c3a6
-    (argc) = *(long int *) cookie;					      \
08c3a6
-    (argv) = (char **) ((long int *) cookie + 1);			      \
08c3a6
-    (envp) = (argv) + (argc) + 1;					      \
08c3a6
-    for (_tmp = (void **) (envp); *_tmp; ++_tmp)			      \
08c3a6
-      continue;								      \
08c3a6
-    (auxp) = (void *) ++_tmp;						      \
08c3a6
-  } while (0)
08c3a6
-#endif
08c3a6
-
08c3a6
-#ifndef DL_STACK_END
08c3a6
-# define DL_STACK_END(cookie) ((void *) (cookie))
08c3a6
-#endif
08c3a6
-
08c3a6
-ElfW(Addr)
08c3a6
-_dl_sysdep_start (void **start_argptr,
08c3a6
-		  void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
08c3a6
-				   ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv))
08c3a6
-{
08c3a6
-  const ElfW(Phdr) *phdr = NULL;
08c3a6
-  ElfW(Word) phnum = 0;
08c3a6
-  ElfW(Addr) user_entry;
08c3a6
-  ElfW(auxv_t) *av;
08c3a6
-#ifdef HAVE_AUX_SECURE
08c3a6
-# define set_seen(tag) (tag)	/* Evaluate for the side effects.  */
08c3a6
-# define set_seen_secure() ((void) 0)
08c3a6
-#else
08c3a6
-  uid_t uid = 0;
08c3a6
-  gid_t gid = 0;
08c3a6
-  unsigned int seen = 0;
08c3a6
-# define set_seen_secure() (seen = -1)
08c3a6
-# ifdef HAVE_AUX_XID
08c3a6
-#  define set_seen(tag) (tag)	/* Evaluate for the side effects.  */
08c3a6
-# else
08c3a6
-#  define M(type) (1 << (type))
08c3a6
-#  define set_seen(tag) seen |= M ((tag)->a_type)
08c3a6
-# endif
08c3a6
-#endif
08c3a6
-#ifdef NEED_DL_SYSINFO
08c3a6
-  uintptr_t new_sysinfo = 0;
08c3a6
-#endif
08c3a6
-
08c3a6
-  __libc_stack_end = DL_STACK_END (start_argptr);
08c3a6
-  DL_FIND_ARG_COMPONENTS (start_argptr, _dl_argc, _dl_argv, _environ,
08c3a6
-			  GLRO(dl_auxv));
08c3a6
-
08c3a6
-  user_entry = (ElfW(Addr)) ENTRY_POINT;
08c3a6
-  GLRO(dl_platform) = NULL; /* Default to nothing known about the platform.  */
08c3a6
-
08c3a6
-  /* NB: Default to a constant CONSTANT_MINSIGSTKSZ.  */
08c3a6
-  _Static_assert (__builtin_constant_p (CONSTANT_MINSIGSTKSZ),
08c3a6
-		  "CONSTANT_MINSIGSTKSZ is constant");
08c3a6
-  GLRO(dl_minsigstacksize) = CONSTANT_MINSIGSTKSZ;
08c3a6
-
08c3a6
-  for (av = GLRO(dl_auxv); av->a_type != AT_NULL; set_seen (av++))
08c3a6
-    switch (av->a_type)
08c3a6
-      {
08c3a6
-      case AT_PHDR:
08c3a6
-	phdr = (void *) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_PHNUM:
08c3a6
-	phnum = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_PAGESZ:
08c3a6
-	GLRO(dl_pagesize) = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_ENTRY:
08c3a6
-	user_entry = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-#ifndef HAVE_AUX_SECURE
08c3a6
-      case AT_UID:
08c3a6
-      case AT_EUID:
08c3a6
-	uid ^= av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_GID:
08c3a6
-      case AT_EGID:
08c3a6
-	gid ^= av->a_un.a_val;
08c3a6
-	break;
08c3a6
-#endif
08c3a6
-      case AT_SECURE:
08c3a6
-#ifndef HAVE_AUX_SECURE
08c3a6
-	seen = -1;
08c3a6
-#endif
08c3a6
-	__libc_enable_secure = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_PLATFORM:
08c3a6
-	GLRO(dl_platform) = (void *) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_HWCAP:
08c3a6
-	GLRO(dl_hwcap) = (unsigned long int) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_HWCAP2:
08c3a6
-	GLRO(dl_hwcap2) = (unsigned long int) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_CLKTCK:
08c3a6
-	GLRO(dl_clktck) = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_FPUCW:
08c3a6
-	GLRO(dl_fpu_control) = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-#ifdef NEED_DL_SYSINFO
08c3a6
-      case AT_SYSINFO:
08c3a6
-	new_sysinfo = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-#endif
08c3a6
-#ifdef NEED_DL_SYSINFO_DSO
08c3a6
-      case AT_SYSINFO_EHDR:
08c3a6
-	GLRO(dl_sysinfo_dso) = (void *) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-#endif
08c3a6
-      case AT_RANDOM:
08c3a6
-	_dl_random = (void *) av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      case AT_MINSIGSTKSZ:
08c3a6
-	GLRO(dl_minsigstacksize) = av->a_un.a_val;
08c3a6
-	break;
08c3a6
-      DL_PLATFORM_AUXV
08c3a6
-      }
08c3a6
-
08c3a6
-  dl_hwcap_check ();
08c3a6
-
08c3a6
-#ifndef HAVE_AUX_SECURE
08c3a6
-  if (seen != -1)
08c3a6
-    {
08c3a6
-      /* Fill in the values we have not gotten from the kernel through the
08c3a6
-	 auxiliary vector.  */
08c3a6
-# ifndef HAVE_AUX_XID
08c3a6
-#  define SEE(UID, var, uid) \
08c3a6
-   if ((seen & M (AT_##UID)) == 0) var ^= __get##uid ()
08c3a6
-      SEE (UID, uid, uid);
08c3a6
-      SEE (EUID, uid, euid);
08c3a6
-      SEE (GID, gid, gid);
08c3a6
-      SEE (EGID, gid, egid);
08c3a6
-# endif
08c3a6
-
08c3a6
-      /* If one of the two pairs of IDs does not match this is a setuid
08c3a6
-	 or setgid run.  */
08c3a6
-      __libc_enable_secure = uid | gid;
08c3a6
-    }
08c3a6
-#endif
08c3a6
-
08c3a6
-#ifndef HAVE_AUX_PAGESIZE
08c3a6
-  if (GLRO(dl_pagesize) == 0)
08c3a6
-    GLRO(dl_pagesize) = __getpagesize ();
08c3a6
-#endif
08c3a6
-
08c3a6
-#ifdef NEED_DL_SYSINFO
08c3a6
-  if (new_sysinfo != 0)
08c3a6
-    {
08c3a6
-# ifdef NEED_DL_SYSINFO_DSO
08c3a6
-      /* Only set the sysinfo value if we also have the vsyscall DSO.  */
08c3a6
-      if (GLRO(dl_sysinfo_dso) != 0)
08c3a6
-# endif
08c3a6
-        GLRO(dl_sysinfo) = new_sysinfo;
08c3a6
-    }
08c3a6
-#endif
08c3a6
-
08c3a6
-  __tunables_init (_environ);
08c3a6
-
08c3a6
-  /* Initialize DSO sorting algorithm after tunables.  */
08c3a6
-  _dl_sort_maps_init ();
08c3a6
-
08c3a6
-#ifdef DL_SYSDEP_INIT
08c3a6
-  DL_SYSDEP_INIT;
08c3a6
-#endif
08c3a6
-
08c3a6
-#ifdef DL_PLATFORM_INIT
08c3a6
-  DL_PLATFORM_INIT;
08c3a6
-#endif
08c3a6
-
08c3a6
-  /* Determine the length of the platform name.  */
08c3a6
-  if (GLRO(dl_platform) != NULL)
08c3a6
-    GLRO(dl_platformlen) = strlen (GLRO(dl_platform));
08c3a6
-
08c3a6
-  if (__sbrk (0) == _end)
08c3a6
-    /* The dynamic linker was run as a program, and so the initial break
08c3a6
-       starts just after our bss, at &_end.  The malloc in dl-minimal.c
08c3a6
-       will consume the rest of this page, so tell the kernel to move the
08c3a6
-       break up that far.  When the user program examines its break, it
08c3a6
-       will see this new value and not clobber our data.  */
08c3a6
-    __sbrk (GLRO(dl_pagesize)
08c3a6
-	    - ((_end - (char *) 0) & (GLRO(dl_pagesize) - 1)));
08c3a6
-
08c3a6
-  /* If this is a SUID program we make sure that FDs 0, 1, and 2 are
08c3a6
-     allocated.  If necessary we are doing it ourself.  If it is not
08c3a6
-     possible we stop the program.  */
08c3a6
-  if (__builtin_expect (__libc_enable_secure, 0))
08c3a6
-    __libc_check_standard_fds ();
08c3a6
-
08c3a6
-  (*dl_main) (phdr, phnum, &user_entry, GLRO(dl_auxv));
08c3a6
-  return user_entry;
08c3a6
-}
08c3a6
-
08c3a6
-void
08c3a6
-_dl_sysdep_start_cleanup (void)
08c3a6
-{
08c3a6
-}
08c3a6
-
08c3a6
-void
08c3a6
-_dl_show_auxv (void)
08c3a6
-{
08c3a6
-  char buf[64];
08c3a6
-  ElfW(auxv_t) *av;
08c3a6
-
08c3a6
-  /* Terminate string.  */
08c3a6
-  buf[63] = '\0';
08c3a6
-
08c3a6
-  /* The following code assumes that the AT_* values are encoded
08c3a6
-     starting from 0 with AT_NULL, 1 for AT_IGNORE, and all other values
08c3a6
-     close by (otherwise the array will be too large).  In case we have
08c3a6
-     to support a platform where these requirements are not fulfilled
08c3a6
-     some alternative implementation has to be used.  */
08c3a6
-  for (av = GLRO(dl_auxv); av->a_type != AT_NULL; ++av)
08c3a6
-    {
08c3a6
-      static const struct
08c3a6
-      {
08c3a6
-	const char label[22];
08c3a6
-	enum { unknown = 0, dec, hex, str, ignore } form : 8;
08c3a6
-      } auxvars[] =
08c3a6
-	{
08c3a6
-	  [AT_EXECFD - 2] =		{ "EXECFD:            ", dec },
08c3a6
-	  [AT_EXECFN - 2] =		{ "EXECFN:            ", str },
08c3a6
-	  [AT_PHDR - 2] =		{ "PHDR:              0x", hex },
08c3a6
-	  [AT_PHENT - 2] =		{ "PHENT:             ", dec },
08c3a6
-	  [AT_PHNUM - 2] =		{ "PHNUM:             ", dec },
08c3a6
-	  [AT_PAGESZ - 2] =		{ "PAGESZ:            ", dec },
08c3a6
-	  [AT_BASE - 2] =		{ "BASE:              0x", hex },
08c3a6
-	  [AT_FLAGS - 2] =		{ "FLAGS:             0x", hex },
08c3a6
-	  [AT_ENTRY - 2] =		{ "ENTRY:             0x", hex },
08c3a6
-	  [AT_NOTELF - 2] =		{ "NOTELF:            ", hex },
08c3a6
-	  [AT_UID - 2] =		{ "UID:               ", dec },
08c3a6
-	  [AT_EUID - 2] =		{ "EUID:              ", dec },
08c3a6
-	  [AT_GID - 2] =		{ "GID:               ", dec },
08c3a6
-	  [AT_EGID - 2] =		{ "EGID:              ", dec },
08c3a6
-	  [AT_PLATFORM - 2] =		{ "PLATFORM:          ", str },
08c3a6
-	  [AT_HWCAP - 2] =		{ "HWCAP:             ", hex },
08c3a6
-	  [AT_CLKTCK - 2] =		{ "CLKTCK:            ", dec },
08c3a6
-	  [AT_FPUCW - 2] =		{ "FPUCW:             ", hex },
08c3a6
-	  [AT_DCACHEBSIZE - 2] =	{ "DCACHEBSIZE:       0x", hex },
08c3a6
-	  [AT_ICACHEBSIZE - 2] =	{ "ICACHEBSIZE:       0x", hex },
08c3a6
-	  [AT_UCACHEBSIZE - 2] =	{ "UCACHEBSIZE:       0x", hex },
08c3a6
-	  [AT_IGNOREPPC - 2] =		{ "IGNOREPPC", ignore },
08c3a6
-	  [AT_SECURE - 2] =		{ "SECURE:            ", dec },
08c3a6
-	  [AT_BASE_PLATFORM - 2] =	{ "BASE_PLATFORM:     ", str },
08c3a6
-	  [AT_SYSINFO - 2] =		{ "SYSINFO:           0x", hex },
08c3a6
-	  [AT_SYSINFO_EHDR - 2] =	{ "SYSINFO_EHDR:      0x", hex },
08c3a6
-	  [AT_RANDOM - 2] =		{ "RANDOM:            0x", hex },
08c3a6
-	  [AT_HWCAP2 - 2] =		{ "HWCAP2:            0x", hex },
08c3a6
-	  [AT_MINSIGSTKSZ - 2] =	{ "MINSIGSTKSZ:       ", dec },
08c3a6
-	  [AT_L1I_CACHESIZE - 2] =	{ "L1I_CACHESIZE:     ", dec },
08c3a6
-	  [AT_L1I_CACHEGEOMETRY - 2] =	{ "L1I_CACHEGEOMETRY: 0x", hex },
08c3a6
-	  [AT_L1D_CACHESIZE - 2] =	{ "L1D_CACHESIZE:     ", dec },
08c3a6
-	  [AT_L1D_CACHEGEOMETRY - 2] =	{ "L1D_CACHEGEOMETRY: 0x", hex },
08c3a6
-	  [AT_L2_CACHESIZE - 2] =	{ "L2_CACHESIZE:      ", dec },
08c3a6
-	  [AT_L2_CACHEGEOMETRY - 2] =	{ "L2_CACHEGEOMETRY:  0x", hex },
08c3a6
-	  [AT_L3_CACHESIZE - 2] =	{ "L3_CACHESIZE:      ", dec },
08c3a6
-	  [AT_L3_CACHEGEOMETRY - 2] =	{ "L3_CACHEGEOMETRY:  0x", hex },
08c3a6
-	};
08c3a6
-      unsigned int idx = (unsigned int) (av->a_type - 2);
08c3a6
-
08c3a6
-      if ((unsigned int) av->a_type < 2u
08c3a6
-	  || (idx < sizeof (auxvars) / sizeof (auxvars[0])
08c3a6
-	      && auxvars[idx].form == ignore))
08c3a6
-	continue;
08c3a6
-
08c3a6
-      assert (AT_NULL == 0);
08c3a6
-      assert (AT_IGNORE == 1);
08c3a6
-
08c3a6
-      /* Some entries are handled in a special way per platform.  */
08c3a6
-      if (_dl_procinfo (av->a_type, av->a_un.a_val) == 0)
08c3a6
-	continue;
08c3a6
-
08c3a6
-      if (idx < sizeof (auxvars) / sizeof (auxvars[0])
08c3a6
-	  && auxvars[idx].form != unknown)
08c3a6
-	{
08c3a6
-	  const char *val = (char *) av->a_un.a_val;
08c3a6
-
08c3a6
-	  if (__builtin_expect (auxvars[idx].form, dec) == dec)
08c3a6
-	    val = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
-			 buf + sizeof buf - 1, 10, 0);
08c3a6
-	  else if (__builtin_expect (auxvars[idx].form, hex) == hex)
08c3a6
-	    val = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
-			 buf + sizeof buf - 1, 16, 0);
08c3a6
-
08c3a6
-	  _dl_printf ("AT_%s%s\n", auxvars[idx].label, val);
08c3a6
-
08c3a6
-	  continue;
08c3a6
-	}
08c3a6
-
08c3a6
-      /* Unknown value: print a generic line.  */
08c3a6
-      char buf2[17];
08c3a6
-      buf2[sizeof (buf2) - 1] = '\0';
08c3a6
-      const char *val2 = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
-				buf2 + sizeof buf2 - 1, 16, 0);
08c3a6
-      const char *val =  _itoa ((unsigned long int) av->a_type,
08c3a6
-				buf + sizeof buf - 1, 16, 0);
08c3a6
-      _dl_printf ("AT_??? (0x%s): 0x%s\n", val, val2);
08c3a6
-    }
08c3a6
-}
08c3a6
-
08c3a6
-#endif
08c3a6
+#error dl-sysdep support missing.
08c3a6
diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c
08c3a6
index 144dc5ce5a1bba17..3e41469bcc395179 100644
08c3a6
--- a/sysdeps/unix/sysv/linux/dl-sysdep.c
08c3a6
+++ b/sysdeps/unix/sysv/linux/dl-sysdep.c
08c3a6
@@ -16,29 +16,352 @@
08c3a6
    License along with the GNU C Library; if not, see
08c3a6
    <https://www.gnu.org/licenses/>.  */
08c3a6
 
08c3a6
-/* Linux needs some special initialization, but otherwise uses
08c3a6
-   the generic dynamic linker system interface code.  */
08c3a6
-
08c3a6
-#include <string.h>
08c3a6
+#include <_itoa.h>
08c3a6
+#include <assert.h>
08c3a6
+#include <dl-auxv.h>
08c3a6
+#include <dl-hwcap-check.h>
08c3a6
+#include <dl-osinfo.h>
08c3a6
+#include <dl-procinfo.h>
08c3a6
+#include <dl-tunables.h>
08c3a6
+#include <elf.h>
08c3a6
+#include <entry.h>
08c3a6
+#include <errno.h>
08c3a6
 #include <fcntl.h>
08c3a6
-#include <unistd.h>
08c3a6
-#include <sys/param.h>
08c3a6
-#include <sys/utsname.h>
08c3a6
+#include <fpu_control.h>
08c3a6
 #include <ldsodefs.h>
08c3a6
+#include <libc-internal.h>
08c3a6
+#include <libintl.h>
08c3a6
 #include <not-cancel.h>
08c3a6
+#include <stdlib.h>
08c3a6
+#include <string.h>
08c3a6
+#include <string.h>
08c3a6
+#include <sys/mman.h>
08c3a6
+#include <sys/param.h>
08c3a6
+#include <sys/stat.h>
08c3a6
+#include <sys/types.h>
08c3a6
+#include <sys/utsname.h>
08c3a6
+#include <tls.h>
08c3a6
+#include <unistd.h>
08c3a6
+
08c3a6
+#include <dl-machine.h>
08c3a6
 
08c3a6
 #ifdef SHARED
08c3a6
-# define DL_SYSDEP_INIT frob_brk ()
08c3a6
+extern char **_environ attribute_hidden;
08c3a6
+extern char _end[] attribute_hidden;
08c3a6
+
08c3a6
+/* Protect SUID program against misuse of file descriptors.  */
08c3a6
+extern void __libc_check_standard_fds (void);
08c3a6
 
08c3a6
-static inline void
08c3a6
-frob_brk (void)
08c3a6
+int __libc_enable_secure attribute_relro = 0;
08c3a6
+rtld_hidden_data_def (__libc_enable_secure)
08c3a6
+/* This variable contains the lowest stack address ever used.  */
08c3a6
+void *__libc_stack_end attribute_relro = NULL;
08c3a6
+rtld_hidden_data_def(__libc_stack_end)
08c3a6
+void *_dl_random attribute_relro = NULL;
08c3a6
+
08c3a6
+#ifndef DL_FIND_ARG_COMPONENTS
08c3a6
+# define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp)	\
08c3a6
+  do {									      \
08c3a6
+    void **_tmp;							      \
08c3a6
+    (argc) = *(long int *) cookie;					      \
08c3a6
+    (argv) = (char **) ((long int *) cookie + 1);			      \
08c3a6
+    (envp) = (argv) + (argc) + 1;					      \
08c3a6
+    for (_tmp = (void **) (envp); *_tmp; ++_tmp)			      \
08c3a6
+      continue;								      \
08c3a6
+    (auxp) = (void *) ++_tmp;						      \
08c3a6
+  } while (0)
08c3a6
+#endif
08c3a6
+
08c3a6
+#ifndef DL_STACK_END
08c3a6
+# define DL_STACK_END(cookie) ((void *) (cookie))
08c3a6
+#endif
08c3a6
+
08c3a6
+ElfW(Addr)
08c3a6
+_dl_sysdep_start (void **start_argptr,
08c3a6
+		  void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
08c3a6
+				   ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv))
08c3a6
 {
08c3a6
+  const ElfW(Phdr) *phdr = NULL;
08c3a6
+  ElfW(Word) phnum = 0;
08c3a6
+  ElfW(Addr) user_entry;
08c3a6
+  ElfW(auxv_t) *av;
08c3a6
+#ifdef HAVE_AUX_SECURE
08c3a6
+# define set_seen(tag) (tag)	/* Evaluate for the side effects.  */
08c3a6
+# define set_seen_secure() ((void) 0)
08c3a6
+#else
08c3a6
+  uid_t uid = 0;
08c3a6
+  gid_t gid = 0;
08c3a6
+  unsigned int seen = 0;
08c3a6
+# define set_seen_secure() (seen = -1)
08c3a6
+# ifdef HAVE_AUX_XID
08c3a6
+#  define set_seen(tag) (tag)	/* Evaluate for the side effects.  */
08c3a6
+# else
08c3a6
+#  define M(type) (1 << (type))
08c3a6
+#  define set_seen(tag) seen |= M ((tag)->a_type)
08c3a6
+# endif
08c3a6
+#endif
08c3a6
+#ifdef NEED_DL_SYSINFO
08c3a6
+  uintptr_t new_sysinfo = 0;
08c3a6
+#endif
08c3a6
+
08c3a6
+  __libc_stack_end = DL_STACK_END (start_argptr);
08c3a6
+  DL_FIND_ARG_COMPONENTS (start_argptr, _dl_argc, _dl_argv, _environ,
08c3a6
+			  GLRO(dl_auxv));
08c3a6
+
08c3a6
+  user_entry = (ElfW(Addr)) ENTRY_POINT;
08c3a6
+  GLRO(dl_platform) = NULL; /* Default to nothing known about the platform.  */
08c3a6
+
08c3a6
+  /* NB: Default to a constant CONSTANT_MINSIGSTKSZ.  */
08c3a6
+  _Static_assert (__builtin_constant_p (CONSTANT_MINSIGSTKSZ),
08c3a6
+		  "CONSTANT_MINSIGSTKSZ is constant");
08c3a6
+  GLRO(dl_minsigstacksize) = CONSTANT_MINSIGSTKSZ;
08c3a6
+
08c3a6
+  for (av = GLRO(dl_auxv); av->a_type != AT_NULL; set_seen (av++))
08c3a6
+    switch (av->a_type)
08c3a6
+      {
08c3a6
+      case AT_PHDR:
08c3a6
+	phdr = (void *) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_PHNUM:
08c3a6
+	phnum = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_PAGESZ:
08c3a6
+	GLRO(dl_pagesize) = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_ENTRY:
08c3a6
+	user_entry = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+#ifndef HAVE_AUX_SECURE
08c3a6
+      case AT_UID:
08c3a6
+      case AT_EUID:
08c3a6
+	uid ^= av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_GID:
08c3a6
+      case AT_EGID:
08c3a6
+	gid ^= av->a_un.a_val;
08c3a6
+	break;
08c3a6
+#endif
08c3a6
+      case AT_SECURE:
08c3a6
+#ifndef HAVE_AUX_SECURE
08c3a6
+	seen = -1;
08c3a6
+#endif
08c3a6
+	__libc_enable_secure = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_PLATFORM:
08c3a6
+	GLRO(dl_platform) = (void *) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_HWCAP:
08c3a6
+	GLRO(dl_hwcap) = (unsigned long int) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_HWCAP2:
08c3a6
+	GLRO(dl_hwcap2) = (unsigned long int) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_CLKTCK:
08c3a6
+	GLRO(dl_clktck) = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_FPUCW:
08c3a6
+	GLRO(dl_fpu_control) = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+#ifdef NEED_DL_SYSINFO
08c3a6
+      case AT_SYSINFO:
08c3a6
+	new_sysinfo = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+#endif
08c3a6
+#ifdef NEED_DL_SYSINFO_DSO
08c3a6
+      case AT_SYSINFO_EHDR:
08c3a6
+	GLRO(dl_sysinfo_dso) = (void *) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+#endif
08c3a6
+      case AT_RANDOM:
08c3a6
+	_dl_random = (void *) av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      case AT_MINSIGSTKSZ:
08c3a6
+	GLRO(dl_minsigstacksize) = av->a_un.a_val;
08c3a6
+	break;
08c3a6
+      DL_PLATFORM_AUXV
08c3a6
+      }
08c3a6
+
08c3a6
+  dl_hwcap_check ();
08c3a6
+
08c3a6
+#ifndef HAVE_AUX_SECURE
08c3a6
+  if (seen != -1)
08c3a6
+    {
08c3a6
+      /* Fill in the values we have not gotten from the kernel through the
08c3a6
+	 auxiliary vector.  */
08c3a6
+# ifndef HAVE_AUX_XID
08c3a6
+#  define SEE(UID, var, uid) \
08c3a6
+   if ((seen & M (AT_##UID)) == 0) var ^= __get##uid ()
08c3a6
+      SEE (UID, uid, uid);
08c3a6
+      SEE (EUID, uid, euid);
08c3a6
+      SEE (GID, gid, gid);
08c3a6
+      SEE (EGID, gid, egid);
08c3a6
+# endif
08c3a6
+
08c3a6
+      /* If one of the two pairs of IDs does not match this is a setuid
08c3a6
+	 or setgid run.  */
08c3a6
+      __libc_enable_secure = uid | gid;
08c3a6
+    }
08c3a6
+#endif
08c3a6
+
08c3a6
+#ifndef HAVE_AUX_PAGESIZE
08c3a6
+  if (GLRO(dl_pagesize) == 0)
08c3a6
+    GLRO(dl_pagesize) = __getpagesize ();
08c3a6
+#endif
08c3a6
+
08c3a6
+#ifdef NEED_DL_SYSINFO
08c3a6
+  if (new_sysinfo != 0)
08c3a6
+    {
08c3a6
+# ifdef NEED_DL_SYSINFO_DSO
08c3a6
+      /* Only set the sysinfo value if we also have the vsyscall DSO.  */
08c3a6
+      if (GLRO(dl_sysinfo_dso) != 0)
08c3a6
+# endif
08c3a6
+        GLRO(dl_sysinfo) = new_sysinfo;
08c3a6
+    }
08c3a6
+#endif
08c3a6
+
08c3a6
+  __tunables_init (_environ);
08c3a6
+
08c3a6
+  /* Initialize DSO sorting algorithm after tunables.  */
08c3a6
+  _dl_sort_maps_init ();
08c3a6
+
08c3a6
   __brk (0);			/* Initialize the break.  */
08c3a6
-}
08c3a6
 
08c3a6
-# include <elf/dl-sysdep.c>
08c3a6
+#ifdef DL_PLATFORM_INIT
08c3a6
+  DL_PLATFORM_INIT;
08c3a6
 #endif
08c3a6
 
08c3a6
+  /* Determine the length of the platform name.  */
08c3a6
+  if (GLRO(dl_platform) != NULL)
08c3a6
+    GLRO(dl_platformlen) = strlen (GLRO(dl_platform));
08c3a6
+
08c3a6
+  if (__sbrk (0) == _end)
08c3a6
+    /* The dynamic linker was run as a program, and so the initial break
08c3a6
+       starts just after our bss, at &_end.  The malloc in dl-minimal.c
08c3a6
+       will consume the rest of this page, so tell the kernel to move the
08c3a6
+       break up that far.  When the user program examines its break, it
08c3a6
+       will see this new value and not clobber our data.  */
08c3a6
+    __sbrk (GLRO(dl_pagesize)
08c3a6
+	    - ((_end - (char *) 0) & (GLRO(dl_pagesize) - 1)));
08c3a6
+
08c3a6
+  /* If this is a SUID program we make sure that FDs 0, 1, and 2 are
08c3a6
+     allocated.  If necessary we are doing it ourself.  If it is not
08c3a6
+     possible we stop the program.  */
08c3a6
+  if (__builtin_expect (__libc_enable_secure, 0))
08c3a6
+    __libc_check_standard_fds ();
08c3a6
+
08c3a6
+  (*dl_main) (phdr, phnum, &user_entry, GLRO(dl_auxv));
08c3a6
+  return user_entry;
08c3a6
+}
08c3a6
+
08c3a6
+void
08c3a6
+_dl_sysdep_start_cleanup (void)
08c3a6
+{
08c3a6
+}
08c3a6
+
08c3a6
+void
08c3a6
+_dl_show_auxv (void)
08c3a6
+{
08c3a6
+  char buf[64];
08c3a6
+  ElfW(auxv_t) *av;
08c3a6
+
08c3a6
+  /* Terminate string.  */
08c3a6
+  buf[63] = '\0';
08c3a6
+
08c3a6
+  /* The following code assumes that the AT_* values are encoded
08c3a6
+     starting from 0 with AT_NULL, 1 for AT_IGNORE, and all other values
08c3a6
+     close by (otherwise the array will be too large).  In case we have
08c3a6
+     to support a platform where these requirements are not fulfilled
08c3a6
+     some alternative implementation has to be used.  */
08c3a6
+  for (av = GLRO(dl_auxv); av->a_type != AT_NULL; ++av)
08c3a6
+    {
08c3a6
+      static const struct
08c3a6
+      {
08c3a6
+	const char label[22];
08c3a6
+	enum { unknown = 0, dec, hex, str, ignore } form : 8;
08c3a6
+      } auxvars[] =
08c3a6
+	{
08c3a6
+	  [AT_EXECFD - 2] =		{ "EXECFD:            ", dec },
08c3a6
+	  [AT_EXECFN - 2] =		{ "EXECFN:            ", str },
08c3a6
+	  [AT_PHDR - 2] =		{ "PHDR:              0x", hex },
08c3a6
+	  [AT_PHENT - 2] =		{ "PHENT:             ", dec },
08c3a6
+	  [AT_PHNUM - 2] =		{ "PHNUM:             ", dec },
08c3a6
+	  [AT_PAGESZ - 2] =		{ "PAGESZ:            ", dec },
08c3a6
+	  [AT_BASE - 2] =		{ "BASE:              0x", hex },
08c3a6
+	  [AT_FLAGS - 2] =		{ "FLAGS:             0x", hex },
08c3a6
+	  [AT_ENTRY - 2] =		{ "ENTRY:             0x", hex },
08c3a6
+	  [AT_NOTELF - 2] =		{ "NOTELF:            ", hex },
08c3a6
+	  [AT_UID - 2] =		{ "UID:               ", dec },
08c3a6
+	  [AT_EUID - 2] =		{ "EUID:              ", dec },
08c3a6
+	  [AT_GID - 2] =		{ "GID:               ", dec },
08c3a6
+	  [AT_EGID - 2] =		{ "EGID:              ", dec },
08c3a6
+	  [AT_PLATFORM - 2] =		{ "PLATFORM:          ", str },
08c3a6
+	  [AT_HWCAP - 2] =		{ "HWCAP:             ", hex },
08c3a6
+	  [AT_CLKTCK - 2] =		{ "CLKTCK:            ", dec },
08c3a6
+	  [AT_FPUCW - 2] =		{ "FPUCW:             ", hex },
08c3a6
+	  [AT_DCACHEBSIZE - 2] =	{ "DCACHEBSIZE:       0x", hex },
08c3a6
+	  [AT_ICACHEBSIZE - 2] =	{ "ICACHEBSIZE:       0x", hex },
08c3a6
+	  [AT_UCACHEBSIZE - 2] =	{ "UCACHEBSIZE:       0x", hex },
08c3a6
+	  [AT_IGNOREPPC - 2] =		{ "IGNOREPPC", ignore },
08c3a6
+	  [AT_SECURE - 2] =		{ "SECURE:            ", dec },
08c3a6
+	  [AT_BASE_PLATFORM - 2] =	{ "BASE_PLATFORM:     ", str },
08c3a6
+	  [AT_SYSINFO - 2] =		{ "SYSINFO:           0x", hex },
08c3a6
+	  [AT_SYSINFO_EHDR - 2] =	{ "SYSINFO_EHDR:      0x", hex },
08c3a6
+	  [AT_RANDOM - 2] =		{ "RANDOM:            0x", hex },
08c3a6
+	  [AT_HWCAP2 - 2] =		{ "HWCAP2:            0x", hex },
08c3a6
+	  [AT_MINSIGSTKSZ - 2] =	{ "MINSIGSTKSZ:       ", dec },
08c3a6
+	  [AT_L1I_CACHESIZE - 2] =	{ "L1I_CACHESIZE:     ", dec },
08c3a6
+	  [AT_L1I_CACHEGEOMETRY - 2] =	{ "L1I_CACHEGEOMETRY: 0x", hex },
08c3a6
+	  [AT_L1D_CACHESIZE - 2] =	{ "L1D_CACHESIZE:     ", dec },
08c3a6
+	  [AT_L1D_CACHEGEOMETRY - 2] =	{ "L1D_CACHEGEOMETRY: 0x", hex },
08c3a6
+	  [AT_L2_CACHESIZE - 2] =	{ "L2_CACHESIZE:      ", dec },
08c3a6
+	  [AT_L2_CACHEGEOMETRY - 2] =	{ "L2_CACHEGEOMETRY:  0x", hex },
08c3a6
+	  [AT_L3_CACHESIZE - 2] =	{ "L3_CACHESIZE:      ", dec },
08c3a6
+	  [AT_L3_CACHEGEOMETRY - 2] =	{ "L3_CACHEGEOMETRY:  0x", hex },
08c3a6
+	};
08c3a6
+      unsigned int idx = (unsigned int) (av->a_type - 2);
08c3a6
+
08c3a6
+      if ((unsigned int) av->a_type < 2u
08c3a6
+	  || (idx < sizeof (auxvars) / sizeof (auxvars[0])
08c3a6
+	      && auxvars[idx].form == ignore))
08c3a6
+	continue;
08c3a6
+
08c3a6
+      assert (AT_NULL == 0);
08c3a6
+      assert (AT_IGNORE == 1);
08c3a6
+
08c3a6
+      /* Some entries are handled in a special way per platform.  */
08c3a6
+      if (_dl_procinfo (av->a_type, av->a_un.a_val) == 0)
08c3a6
+	continue;
08c3a6
+
08c3a6
+      if (idx < sizeof (auxvars) / sizeof (auxvars[0])
08c3a6
+	  && auxvars[idx].form != unknown)
08c3a6
+	{
08c3a6
+	  const char *val = (char *) av->a_un.a_val;
08c3a6
+
08c3a6
+	  if (__builtin_expect (auxvars[idx].form, dec) == dec)
08c3a6
+	    val = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
+			 buf + sizeof buf - 1, 10, 0);
08c3a6
+	  else if (__builtin_expect (auxvars[idx].form, hex) == hex)
08c3a6
+	    val = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
+			 buf + sizeof buf - 1, 16, 0);
08c3a6
+
08c3a6
+	  _dl_printf ("AT_%s%s\n", auxvars[idx].label, val);
08c3a6
+
08c3a6
+	  continue;
08c3a6
+	}
08c3a6
+
08c3a6
+      /* Unknown value: print a generic line.  */
08c3a6
+      char buf2[17];
08c3a6
+      buf2[sizeof (buf2) - 1] = '\0';
08c3a6
+      const char *val2 = _itoa ((unsigned long int) av->a_un.a_val,
08c3a6
+				buf2 + sizeof buf2 - 1, 16, 0);
08c3a6
+      const char *val =  _itoa ((unsigned long int) av->a_type,
08c3a6
+				buf + sizeof buf - 1, 16, 0);
08c3a6
+      _dl_printf ("AT_??? (0x%s): 0x%s\n", val, val2);
08c3a6
+    }
08c3a6
+}
08c3a6
+
08c3a6
+#endif /* SHARED */
08c3a6
+
08c3a6
 
08c3a6
 int
08c3a6
 attribute_hidden