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