]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - elf/rtld.c
iconv, localedef: avoid floating point rounding differences [BZ #24372]
[thirdparty/glibc.git] / elf / rtld.c
index 2e4f97ffed58306e722ea64c3d2182e6ed4757b2..1b38c6b73278a3baa0540841bcc8c52d87a11daf 100644 (file)
@@ -1,5 +1,5 @@
 /* Run time dynamic linker.
-   Copyright (C) 1995-2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <ldsodefs.h>
-#include <stdio-common/_itoa.h>
+#include <_itoa.h>
 #include <entry.h>
 #include <fpu_control.h>
 #include <hp-timing.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
 #include "dynamic-link.h"
 #include <dl-librecon.h>
 #include <unsecvars.h>
 #include <dl-cache.h>
 #include <dl-osinfo.h>
 #include <dl-procinfo.h>
+#include <dl-prop.h>
 #include <tls.h>
+#include <stap-probe.h>
 #include <stackinfo.h>
+#include <not-cancel.h>
 
 #include <assert.h>
 
@@ -82,7 +85,7 @@ int _dl_argc attribute_relro attribute_hidden;
 char **_dl_argv attribute_relro = NULL;
 unsigned int _dl_skip_args attribute_relro attribute_hidden;
 #endif
-INTDEF(_dl_argv)
+rtld_hidden_data_def (_dl_argv)
 
 #ifndef THREAD_SET_STACK_GUARD
 /* Only exported for architectures that don't store the stack guard canary
@@ -98,14 +101,121 @@ uintptr_t __pointer_chk_guard_local
 strong_alias (__pointer_chk_guard_local, __pointer_chk_guard)
 #endif
 
+/* Length limits for names and paths, to protect the dynamic linker,
+   particularly when __libc_enable_secure is active.  */
+#ifdef NAME_MAX
+# define SECURE_NAME_LIMIT NAME_MAX
+#else
+# define SECURE_NAME_LIMIT 255
+#endif
+#ifdef PATH_MAX
+# define SECURE_PATH_LIMIT PATH_MAX
+#else
+# define SECURE_PATH_LIMIT 1024
+#endif
+
+/* Check that AT_SECURE=0, or that the passed name does not contain
+   directories and is not overly long.  Reject empty names
+   unconditionally.  */
+static bool
+dso_name_valid_for_suid (const char *p)
+{
+  if (__glibc_unlikely (__libc_enable_secure))
+    {
+      /* Ignore pathnames with directories for AT_SECURE=1
+        programs, and also skip overlong names.  */
+      size_t len = strlen (p);
+      if (len >= SECURE_NAME_LIMIT || memchr (p, '/', len) != NULL)
+       return false;
+    }
+  return *p != '\0';
+}
 
-/* List of auditing DSOs.  */
+/* LD_AUDIT variable contents.  Must be processed before the
+   audit_list below.  */
+const char *audit_list_string;
+
+/* Cyclic list of auditing DSOs.  audit_list->next is the first
+   element.  */
 static struct audit_list
 {
   const char *name;
   struct audit_list *next;
 } *audit_list;
 
+/* Iterator for audit_list_string followed by audit_list.  */
+struct audit_list_iter
+{
+  /* Tail of audit_list_string still needing processing, or NULL.  */
+  const char *audit_list_tail;
+
+  /* The list element returned in the previous iteration.  NULL before
+     the first element.  */
+  struct audit_list *previous;
+
+  /* Scratch buffer for returning a name which is part of
+     audit_list_string.  */
+  char fname[SECURE_NAME_LIMIT];
+};
+
+/* Initialize an audit list iterator.  */
+static void
+audit_list_iter_init (struct audit_list_iter *iter)
+{
+  iter->audit_list_tail = audit_list_string;
+  iter->previous = NULL;
+}
+
+/* Iterate through both audit_list_string and audit_list.  */
+static const char *
+audit_list_iter_next (struct audit_list_iter *iter)
+{
+  if (iter->audit_list_tail != NULL)
+    {
+      /* First iterate over audit_list_string.  */
+      while (*iter->audit_list_tail != '\0')
+       {
+         /* Split audit list at colon.  */
+         size_t len = strcspn (iter->audit_list_tail, ":");
+         if (len > 0 && len < sizeof (iter->fname))
+           {
+             memcpy (iter->fname, iter->audit_list_tail, len);
+             iter->fname[len] = '\0';
+           }
+         else
+           /* Do not return this name to the caller.  */
+           iter->fname[0] = '\0';
+
+         /* Skip over the substring and the following delimiter.  */
+         iter->audit_list_tail += len;
+         if (*iter->audit_list_tail == ':')
+           ++iter->audit_list_tail;
+
+         /* If the name is valid, return it.  */
+         if (dso_name_valid_for_suid (iter->fname))
+           return iter->fname;
+         /* Otherwise, wrap around and try the next name.  */
+       }
+      /* Fall through to the procesing of audit_list.  */
+    }
+
+  if (iter->previous == NULL)
+    {
+      if (audit_list == NULL)
+       /* No pre-parsed audit list.  */
+       return NULL;
+      /* Start of audit list.  The first list element is at
+        audit_list->next (cyclic list).  */
+      iter->previous = audit_list->next;
+      return iter->previous->name;
+    }
+  if (iter->previous == audit_list)
+    /* Cyclic list wrap-around.  */
+    return NULL;
+  iter->previous = iter->previous->next;
+  return iter->previous->name;
+}
+
 #ifndef HAVE_INLINED_SYSCALLS
 /* Set nonzero during loading and initialization of executable and
    libraries, cleared before the executable's entry point runs.  This
@@ -115,7 +225,7 @@ static struct audit_list
    and will be since that dynamic linker's _dl_start and dl_main will
    never be called.  */
 int _dl_starting_up = 0;
-INTVARDEF(_dl_starting_up)
+rtld_hidden_def (_dl_starting_up)
 #endif
 
 /* This is the structure which defines all variables global to ld.so
@@ -132,8 +242,10 @@ struct rtld_global _rtld_global =
     ._dl_nns = 1,
     ._dl_ns =
     {
+#ifdef _LIBC_REENTRANT
       [LM_ID_BASE] = { ._ns_unique_sym_table
                       = { .lock = _RTLD_LOCK_RECURSIVE_INITIALIZER } }
+#endif
     }
   };
 /* If we would use strong_alias here the compiler would see a
@@ -156,19 +268,18 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_debug_fd = STDERR_FILENO,
     ._dl_use_load_bias = -2,
     ._dl_correct_cache_id = _DL_CACHE_DEFAULT_ID,
+#if !HAVE_TUNABLES
     ._dl_hwcap_mask = HWCAP_IMPORTANT,
+#endif
     ._dl_lazy = 1,
     ._dl_fpu_control = _FPU_DEFAULT,
-    ._dl_pointer_guard = 1,
     ._dl_pagesize = EXEC_PAGESIZE,
+    ._dl_inhibit_cache = 0,
 
     /* Function pointers.  */
     ._dl_debug_printf = _dl_debug_printf,
-    ._dl_catch_error = _dl_catch_error,
-    ._dl_signal_error = _dl_signal_error,
-    ._dl_mcount = _dl_mcount_internal,
+    ._dl_mcount = _dl_mcount,
     ._dl_lookup_symbol_x = _dl_lookup_symbol_x,
-    ._dl_check_caller = _dl_check_caller,
     ._dl_open = _dl_open,
     ._dl_close = _dl_close,
     ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
@@ -191,12 +302,6 @@ static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
 static struct libname_list _dl_rtld_libname;
 static struct libname_list _dl_rtld_libname2;
 
-/* We expect less than a second for relocation.  */
-#ifdef HP_SMALL_TIMING_AVAIL
-# undef HP_TIMING_AVAIL
-# define HP_TIMING_AVAIL HP_SMALL_TIMING_AVAIL
-#endif
-
 /* Variable for statistics.  */
 #ifndef HP_TIMING_NONAVAIL
 static hp_timing_t relocate_time;
@@ -250,15 +355,6 @@ RTLD_START
 # error "sysdeps/MACHINE/dl-machine.h fails to define RTLD_START"
 #endif
 
-#ifndef VALIDX
-# define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
-                     + DT_EXTRANUM + DT_VALTAGIDX (tag))
-#endif
-#ifndef ADDRIDX
-# define ADDRIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
-                      + DT_EXTRANUM + DT_VALNUM + DT_ADDRTAGIDX (tag))
-#endif
-
 /* This is the second half of _dl_start (below).  It can be inlined safely
    under DONT_USE_BOOTSTRAP_MAP, where it is careful not to make any GOT
    references.  When the tools don't permit us to avoid using a GOT entry
@@ -275,7 +371,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
 {
   ElfW(Addr) start_addr;
 
-  if (HP_TIMING_AVAIL)
+  if (HP_SMALL_TIMING_AVAIL)
     {
       /* If it hasn't happen yet record the startup time.  */
       if (! HP_TIMING_INLINE)
@@ -284,9 +380,6 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
       else
        start_time = info->start_time;
 #endif
-
-      /* Initialize the timing functions.  */
-      HP_TIMING_DIFF_INIT ();
     }
 
   /* Transfer data about ourselves to the permanent link_map structure.  */
@@ -305,26 +398,12 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
   GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext;
   /* Copy the TLS related data if necessary.  */
 #ifndef DONT_USE_BOOTSTRAP_MAP
-# if USE___THREAD
-  assert (info->l.l_tls_modid != 0);
-  GL(dl_rtld_map).l_tls_blocksize = info->l.l_tls_blocksize;
-  GL(dl_rtld_map).l_tls_align = info->l.l_tls_align;
-  GL(dl_rtld_map).l_tls_firstbyte_offset = info->l.l_tls_firstbyte_offset;
-  GL(dl_rtld_map).l_tls_initimage_size = info->l.l_tls_initimage_size;
-  GL(dl_rtld_map).l_tls_initimage = info->l.l_tls_initimage;
-  GL(dl_rtld_map).l_tls_offset = info->l.l_tls_offset;
-  GL(dl_rtld_map).l_tls_modid = 1;
-# else
-#  if NO_TLS_OFFSET != 0
+# if NO_TLS_OFFSET != 0
   GL(dl_rtld_map).l_tls_offset = NO_TLS_OFFSET;
-#  endif
 # endif
-
 #endif
 
-#if HP_TIMING_AVAIL
   HP_TIMING_NOW (GL(dl_cpuclock_offset));
-#endif
 
   /* Initialize the stack end variable.  */
   __libc_stack_end = __builtin_frame_address (0);
@@ -337,7 +416,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
 
 #ifndef HP_TIMING_NONAVAIL
   hp_timing_t rtld_total_time;
-  if (HP_TIMING_AVAIL)
+  if (HP_SMALL_TIMING_AVAIL)
     {
       hp_timing_t end_time;
 
@@ -349,7 +428,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
     }
 #endif
 
-  if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_STATISTICS, 0))
+  if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_STATISTICS))
     {
 #ifndef HP_TIMING_NONAVAIL
       print_statistics (&rtld_total_time);
@@ -361,7 +440,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
   return start_addr;
 }
 
-static ElfW(Addr) __attribute_used__ internal_function
+static ElfW(Addr) __attribute_used__
 _dl_start (void *arg)
 {
 #ifdef DONT_USE_BOOTSTRAP_MAP
@@ -376,10 +455,11 @@ _dl_start (void *arg)
      Since ld.so must not have any undefined symbols the result
      is trivial: always the map of ld.so itself.  */
 #define RTLD_BOOTSTRAP
-#define RESOLVE_MAP(sym, version, flags) (&bootstrap_map)
+#define BOOTSTRAP_MAP (&bootstrap_map)
+#define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
 #include "dynamic-link.h"
 
-  if (HP_TIMING_INLINE && HP_TIMING_AVAIL)
+  if (HP_TIMING_INLINE && HP_SMALL_TIMING_AVAIL)
 #ifdef DONT_USE_BOOTSTRAP_MAP
     HP_TIMING_NOW (start_time);
 #else
@@ -401,9 +481,6 @@ _dl_start (void *arg)
        ++cnt)
     bootstrap_map.l_info[cnt] = 0;
 # endif
-# if USE___THREAD
-  bootstrap_map.l_tls_modid = 0;
-# endif
 #endif
 
   /* Figure out the run-time load address of the dynamic linker itself.  */
@@ -417,123 +494,6 @@ _dl_start (void *arg)
   bootstrap_map.l_tls_offset = NO_TLS_OFFSET;
 #endif
 
-  /* Get the dynamic linker's own program header.  First we need the ELF
-     file header.  The `_begin' symbol created by the linker script points
-     to it.  When we have something like GOTOFF relocs, we can use a plain
-     reference to find the runtime address.  Without that, we have to rely
-     on the `l_addr' value, which is not the value we want when prelinked.  */
-#if USE___THREAD
-  dtv_t initdtv[3];
-  ElfW(Ehdr) *ehdr
-# ifdef DONT_USE_BOOTSTRAP_MAP
-    = (ElfW(Ehdr) *) &_begin;
-# else
-#  error This will not work with prelink.
-    = (ElfW(Ehdr) *) bootstrap_map.l_addr;
-# endif
-  ElfW(Phdr) *phdr = (ElfW(Phdr) *) ((void *) ehdr + ehdr->e_phoff);
-  size_t cnt = ehdr->e_phnum;  /* PT_TLS is usually the last phdr.  */
-  while (cnt-- > 0)
-    if (phdr[cnt].p_type == PT_TLS)
-      {
-       void *tlsblock;
-       size_t max_align = MAX (TLS_INIT_TCB_ALIGN, phdr[cnt].p_align);
-       char *p;
-
-       bootstrap_map.l_tls_blocksize = phdr[cnt].p_memsz;
-       bootstrap_map.l_tls_align = phdr[cnt].p_align;
-       if (phdr[cnt].p_align == 0)
-         bootstrap_map.l_tls_firstbyte_offset = 0;
-       else
-         bootstrap_map.l_tls_firstbyte_offset = (phdr[cnt].p_vaddr
-                                                 & (phdr[cnt].p_align - 1));
-       assert (bootstrap_map.l_tls_blocksize != 0);
-       bootstrap_map.l_tls_initimage_size = phdr[cnt].p_filesz;
-       bootstrap_map.l_tls_initimage = (void *) (bootstrap_map.l_addr
-                                                 + phdr[cnt].p_vaddr);
-
-       /* We can now allocate the initial TLS block.  This can happen
-          on the stack.  We'll get the final memory later when we
-          know all about the various objects loaded at startup
-          time.  */
-# if TLS_TCB_AT_TP
-       tlsblock = alloca (roundup (bootstrap_map.l_tls_blocksize,
-                                   TLS_INIT_TCB_ALIGN)
-                          + TLS_INIT_TCB_SIZE
-                          + max_align);
-# elif TLS_DTV_AT_TP
-       tlsblock = alloca (roundup (TLS_INIT_TCB_SIZE,
-                                   bootstrap_map.l_tls_align)
-                          + bootstrap_map.l_tls_blocksize
-                          + max_align);
-# else
-       /* In case a model with a different layout for the TCB and DTV
-          is defined add another #elif here and in the following #ifs.  */
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
-# endif
-       /* Align the TLS block.  */
-       tlsblock = (void *) (((uintptr_t) tlsblock + max_align - 1)
-                            & ~(max_align - 1));
-
-       /* Initialize the dtv.  [0] is the length, [1] the generation
-          counter.  */
-       initdtv[0].counter = 1;
-       initdtv[1].counter = 0;
-
-       /* Initialize the TLS block.  */
-# if TLS_TCB_AT_TP
-       initdtv[2].pointer = tlsblock;
-# elif TLS_DTV_AT_TP
-       bootstrap_map.l_tls_offset = roundup (TLS_INIT_TCB_SIZE,
-                                             bootstrap_map.l_tls_align);
-       initdtv[2].pointer = (char *) tlsblock + bootstrap_map.l_tls_offset;
-# else
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
-# endif
-       p = __mempcpy (initdtv[2].pointer, bootstrap_map.l_tls_initimage,
-                      bootstrap_map.l_tls_initimage_size);
-# ifdef HAVE_BUILTIN_MEMSET
-       __builtin_memset (p, '\0', (bootstrap_map.l_tls_blocksize
-                                   - bootstrap_map.l_tls_initimage_size));
-# else
-       {
-         size_t remaining = (bootstrap_map.l_tls_blocksize
-                             - bootstrap_map.l_tls_initimage_size);
-         while (remaining-- > 0)
-           *p++ = '\0';
-       }
-# endif
-
-       /* Install the pointer to the dtv.  */
-
-       /* Initialize the thread pointer.  */
-# if TLS_TCB_AT_TP
-       bootstrap_map.l_tls_offset
-         = roundup (bootstrap_map.l_tls_blocksize, TLS_INIT_TCB_ALIGN);
-
-       INSTALL_DTV ((char *) tlsblock + bootstrap_map.l_tls_offset,
-                    initdtv);
-
-       const char *lossage = TLS_INIT_TP ((char *) tlsblock
-                                          + bootstrap_map.l_tls_offset, 0);
-# elif TLS_DTV_AT_TP
-       INSTALL_DTV (tlsblock, initdtv);
-       const char *lossage = TLS_INIT_TP (tlsblock, 0);
-# else
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
-# endif
-       if (__builtin_expect (lossage != NULL, 0))
-         _dl_fatal_printf ("cannot set up thread-local storage: %s\n",
-                           lossage);
-
-       /* So far this is module number one.  */
-       bootstrap_map.l_tls_modid = 1;
-
-       /* There can only be one PT_TLS entry.  */
-       break;
-      }
-#endif /* USE___THREAD */
-
 #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
   ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info);
 #endif
@@ -589,7 +549,7 @@ struct relocate_args
 struct map_args
 {
   /* Argument to map_doit.  */
-  char *str;
+  const char *str;
   struct link_map *loader;
   int mode;
   /* Return value of map_doit.  */
@@ -628,7 +588,8 @@ static void
 map_doit (void *a)
 {
   struct map_args *args = (struct map_args *) a;
-  args->map = _dl_map_object (args->loader, args->str, lt_library, 0,
+  int type = (args->mode == __RTLD_OPENEXEC) ? lt_executable : lt_library;
+  args->map = _dl_map_object (args->loader, args->str, type, 0,
                              args->mode, LM_ID_BASE);
 }
 
@@ -639,7 +600,7 @@ dlmopen_doit (void *a)
   args->map = _dl_open (args->fname,
                        (RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT
                         | __RTLD_SECURE),
-                       dl_main, LM_ID_NEWLM, _dl_argc, INTUSE(_dl_argv),
+                       dl_main, LM_ID_NEWLM, _dl_argc, _dl_argv,
                        __environ);
 }
 
@@ -770,41 +731,23 @@ init_tls (void)
   void *tcbp = _dl_allocate_tls_storage ();
   if (tcbp == NULL)
     _dl_fatal_printf ("\
-cannot allocate TLS data structures for initial thread");
+cannot allocate TLS data structures for initial thread\n");
 
   /* 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);
 
-  /* 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
-#ifdef USE___THREAD
-    = TLS_INIT_TP (tcbp, USE___THREAD);
-#else
-    = TLS_INIT_TP (tcbp, 0);
-#endif
-  if (__builtin_expect (lossage != NULL, 0))
+  /* And finally install it for the main thread.  */
+  const char *lossage = TLS_INIT_TP (tcbp);
+  if (__glibc_unlikely (lossage != NULL))
     _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);
   tls_init_tp_called = true;
 
   return tcbp;
 }
 
-#ifdef _LIBC_REENTRANT
-/* _dl_error_catch_tsd points to this for the single-threaded case.
-   It's reset by the thread library for multithreaded programs.  */
-void ** __attribute__ ((const))
-_dl_initial_error_catch_tsd (void)
-{
-  static void *data;
-  return &data;
-}
-#endif
-
-
 static unsigned int
-do_preload (char *fname, struct link_map *main_map, const char *where)
+do_preload (const char *fname, struct link_map *main_map, const char *where)
 {
   const char *objname;
   const char *err_str = NULL;
@@ -818,11 +761,11 @@ do_preload (char *fname, struct link_map *main_map, const char *where)
   unsigned int old_nloaded = GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
 
   (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit, &args);
-  if (__builtin_expect (err_str != NULL, 0))
+  if (__glibc_unlikely (err_str != NULL))
     {
       _dl_error_printf ("\
-ERROR: ld.so: object '%s' from %s cannot be preloaded: ignored.\n",
-                       fname, where);
+ERROR: ld.so: object '%s' from %s cannot be preloaded (%s): ignored.\n",
+                       fname, where, err_str);
       /* No need to call free, this is still before
         the libc's malloc is used.  */
     }
@@ -862,15 +805,12 @@ security_init (void)
 #endif
 
   /* Set up the pointer guard as well, if necessary.  */
-  if (GLRO(dl_pointer_guard))
-    {
-      uintptr_t pointer_chk_guard = _dl_setup_pointer_guard (_dl_random,
-                                                            stack_chk_guard);
+  uintptr_t pointer_chk_guard
+    = _dl_setup_pointer_guard (_dl_random, stack_chk_guard);
 #ifdef THREAD_SET_POINTER_GUARD
-      THREAD_SET_POINTER_GUARD (pointer_chk_guard);
+  THREAD_SET_POINTER_GUARD (pointer_chk_guard);
 #endif
-      __pointer_chk_guard_local = pointer_chk_guard;
-    }
+  __pointer_chk_guard_local = pointer_chk_guard;
 
   /* We do not need the _dl_random value anymore.  The less
      information we leave behind, the better, so clear the
@@ -878,6 +818,7 @@ security_init (void)
   _dl_random = NULL;
 }
 
+#include "setup-vdso.h"
 
 /* The library search path.  */
 static const char *library_path attribute_relro;
@@ -885,6 +826,244 @@ static const char *library_path attribute_relro;
 static const char *preloadlist attribute_relro;
 /* Nonzero if information about versions has to be printed.  */
 static int version_info attribute_relro;
+/* The preload list passed as a command argument.  */
+static const char *preloadarg attribute_relro;
+
+/* 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.)  Return the number of preloads
+   performed.   Ditto for --preload command argument.  */
+unsigned int
+handle_preload_list (const char *preloadlist, struct link_map *main_map,
+                    const char *where)
+{
+  unsigned int npreloads = 0;
+  const char *p = preloadlist;
+  char fname[SECURE_PATH_LIMIT];
+
+  while (*p != '\0')
+    {
+      /* Split preload list at space/colon.  */
+      size_t len = strcspn (p, " :");
+      if (len > 0 && len < sizeof (fname))
+       {
+         memcpy (fname, p, len);
+         fname[len] = '\0';
+       }
+      else
+       fname[0] = '\0';
+
+      /* Skip over the substring and the following delimiter.  */
+      p += len;
+      if (*p != '\0')
+       ++p;
+
+      if (dso_name_valid_for_suid (fname))
+       npreloads += do_preload (fname, main_map, where);
+    }
+  return npreloads;
+}
+
+/* Called if the audit DSO cannot be used: if it does not have the
+   appropriate interfaces, or it expects a more recent version library
+   version than what the dynamic linker provides.  */
+static void
+unload_audit_module (struct link_map *map, int original_tls_idx)
+{
+#ifndef NDEBUG
+  Lmid_t ns = map->l_ns;
+#endif
+  _dl_close (map);
+
+  /* Make sure the namespace has been cleared entirely.  */
+  assert (GL(dl_ns)[ns]._ns_loaded == NULL);
+  assert (GL(dl_ns)[ns]._ns_nloaded == 0);
+
+  GL(dl_tls_max_dtv_idx) = original_tls_idx;
+}
+
+/* Called to print an error message if loading of an audit module
+   failed.  */
+static void
+report_audit_module_load_error (const char *name, const char *err_str,
+                               bool malloced)
+{
+  _dl_error_printf ("\
+ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
+                   name, err_str);
+  if (malloced)
+    free ((char *) err_str);
+}
+
+/* Load one audit module.  */
+static void
+load_audit_module (const char *name, struct audit_ifaces **last_audit)
+{
+  int original_tls_idx = GL(dl_tls_max_dtv_idx);
+
+  struct dlmopen_args dlmargs;
+  dlmargs.fname = name;
+  dlmargs.map = NULL;
+
+  const char *objname;
+  const char *err_str = NULL;
+  bool malloced;
+  _dl_catch_error (&objname, &err_str, &malloced, dlmopen_doit, &dlmargs);
+  if (__glibc_unlikely (err_str != NULL))
+    {
+      report_audit_module_load_error (name, err_str, malloced);
+      return;
+    }
+
+  struct lookup_args largs;
+  largs.name = "la_version";
+  largs.map = dlmargs.map;
+  _dl_catch_error (&objname, &err_str, &malloced, lookup_doit, &largs);
+  if (__glibc_likely (err_str != NULL))
+    {
+      unload_audit_module (dlmargs.map, original_tls_idx);
+      report_audit_module_load_error (name, err_str, malloced);
+      return;
+    }
+
+  unsigned int (*laversion) (unsigned int) = largs.result;
+
+ /* A null symbol indicates that something is very wrong with the
+    loaded object because defined symbols are supposed to have a
+    valid, non-null address.  */
+  assert (laversion != NULL);
+
+  unsigned int lav = laversion (LAV_CURRENT);
+  if (lav == 0)
+    {
+      /* Only print an error message if debugging because this can
+        happen deliberately.  */
+      if (GLRO(dl_debug_mask) & DL_DEBUG_FILES)
+       _dl_debug_printf ("\
+file=%s [%lu]; audit interface function la_version returned zero; ignored.\n",
+                         dlmargs.map->l_name, dlmargs.map->l_ns);
+      unload_audit_module (dlmargs.map, original_tls_idx);
+      return;
+    }
+
+  if (lav > LAV_CURRENT)
+    {
+      _dl_debug_printf ("\
+ERROR: audit interface '%s' requires version %d (maximum supported version %d); ignored.\n",
+                       name, lav, LAV_CURRENT);
+      unload_audit_module (dlmargs.map, original_tls_idx);
+      return;
+    }
+
+  enum { naudit_ifaces = 8 };
+  union
+  {
+    struct audit_ifaces ifaces;
+    void (*fptr[naudit_ifaces]) (void);
+  } *newp = malloc (sizeof (*newp));
+  if (newp == NULL)
+    _dl_fatal_printf ("Out of memory while loading audit modules\n");
+
+  /* Names of the auditing interfaces.  All in one
+     long string.  */
+  static const char audit_iface_names[] =
+    "la_activity\0"
+    "la_objsearch\0"
+    "la_objopen\0"
+    "la_preinit\0"
+#if __ELF_NATIVE_CLASS == 32
+    "la_symbind32\0"
+#elif __ELF_NATIVE_CLASS == 64
+    "la_symbind64\0"
+#else
+# error "__ELF_NATIVE_CLASS must be defined"
+#endif
+#define STRING(s) __STRING (s)
+    "la_" STRING (ARCH_LA_PLTENTER) "\0"
+    "la_" STRING (ARCH_LA_PLTEXIT) "\0"
+    "la_objclose\0";
+  unsigned int cnt = 0;
+  const char *cp = audit_iface_names;
+  do
+    {
+      largs.name = cp;
+      _dl_catch_error (&objname, &err_str, &malloced, lookup_doit, &largs);
+
+      /* Store the pointer.  */
+      if (err_str == NULL && largs.result != NULL)
+       {
+         newp->fptr[cnt] = largs.result;
+
+         /* The dynamic linker link map is statically allocated,
+            initialize the data now.  */
+         GL(dl_rtld_map).l_audit[cnt].cookie = (intptr_t) &GL(dl_rtld_map);
+       }
+      else
+       newp->fptr[cnt] = NULL;
+      ++cnt;
+
+      cp = rawmemchr (cp, '\0') + 1;
+    }
+  while (*cp != '\0');
+  assert (cnt == naudit_ifaces);
+
+  /* Now append the new auditing interface to the list.  */
+  newp->ifaces.next = NULL;
+  if (*last_audit == NULL)
+    *last_audit = GLRO(dl_audit) = &newp->ifaces;
+  else
+    *last_audit = (*last_audit)->next = &newp->ifaces;
+  ++GLRO(dl_naudit);
+
+  /* Mark the DSO as being used for auditing.  */
+  dlmargs.map->l_auditing = 1;
+}
+
+/* Notify the the audit modules that the object MAP has already been
+   loaded.  */
+static void
+notify_audit_modules_of_loaded_object (struct link_map *map)
+{
+  struct audit_ifaces *afct = GLRO(dl_audit);
+  for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+    {
+      if (afct->objopen != NULL)
+       {
+         map->l_audit[cnt].bindflags
+           = afct->objopen (map, LM_ID_BASE, &map->l_audit[cnt].cookie);
+         map->l_audit_any_plt |= map->l_audit[cnt].bindflags != 0;
+       }
+
+      afct = afct->next;
+    }
+}
+
+/* Load all audit modules.  */
+static void
+load_audit_modules (struct link_map *main_map)
+{
+  struct audit_ifaces *last_audit = NULL;
+  struct audit_list_iter al_iter;
+  audit_list_iter_init (&al_iter);
+
+  while (true)
+    {
+      const char *name = audit_list_iter_next (&al_iter);
+      if (name == NULL)
+       break;
+      load_audit_module (name, &last_audit);
+    }
+
+  /* Notify audit modules of the initially loaded modules (the main
+     program and the dynamic linker itself).  */
+  if (GLRO(dl_naudit) > 0)
+    {
+      notify_audit_modules_of_loaded_object (main_map);
+      notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+    }
+}
 
 static void
 dl_main (const ElfW(Phdr) *phdr,
@@ -908,11 +1087,6 @@ dl_main (const ElfW(Phdr) *phdr,
 #endif
   void *tcbp = NULL;
 
-#ifdef _LIBC_REENTRANT
-  /* Explicit initialization since the reloc would just be more work.  */
-  GL(dl_error_catch_tsd) = &_dl_initial_error_catch_tsd;
-#endif
-
   GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
 
 #if defined SHARED && defined _LIBC_REENTRANT \
@@ -930,7 +1104,7 @@ dl_main (const ElfW(Phdr) *phdr,
 
 #ifndef HAVE_INLINED_SYSCALLS
   /* Set up a flag which tells we are just starting.  */
-  INTUSE(_dl_starting_up) = 1;
+  _dl_starting_up = 1;
 #endif
 
   if (*user_entry == (ElfW(Addr)) ENTRY_POINT)
@@ -956,48 +1130,62 @@ dl_main (const ElfW(Phdr) *phdr,
       GL(dl_rtld_map).l_name = rtld_progname;
 
       while (_dl_argc > 1)
-       if (! strcmp (INTUSE(_dl_argv)[1], "--list"))
+       if (! strcmp (_dl_argv[1], "--list"))
          {
            mode = list;
            GLRO(dl_lazy) = -1; /* This means do no dependency analysis.  */
 
            ++_dl_skip_args;
            --_dl_argc;
-           ++INTUSE(_dl_argv);
+           ++_dl_argv;
          }
-       else if (! strcmp (INTUSE(_dl_argv)[1], "--verify"))
+       else if (! strcmp (_dl_argv[1], "--verify"))
          {
            mode = verify;
 
            ++_dl_skip_args;
            --_dl_argc;
-           ++INTUSE(_dl_argv);
+           ++_dl_argv;
+         }
+       else if (! strcmp (_dl_argv[1], "--inhibit-cache"))
+         {
+           GLRO(dl_inhibit_cache) = 1;
+           ++_dl_skip_args;
+           --_dl_argc;
+           ++_dl_argv;
          }
-       else if (! strcmp (INTUSE(_dl_argv)[1], "--library-path")
+       else if (! strcmp (_dl_argv[1], "--library-path")
                 && _dl_argc > 2)
          {
-           library_path = INTUSE(_dl_argv)[2];
+           library_path = _dl_argv[2];
 
            _dl_skip_args += 2;
            _dl_argc -= 2;
-           INTUSE(_dl_argv) += 2;
+           _dl_argv += 2;
          }
-       else if (! strcmp (INTUSE(_dl_argv)[1], "--inhibit-rpath")
+       else if (! strcmp (_dl_argv[1], "--inhibit-rpath")
                 && _dl_argc > 2)
          {
-           GLRO(dl_inhibit_rpath) = INTUSE(_dl_argv)[2];
+           GLRO(dl_inhibit_rpath) = _dl_argv[2];
 
            _dl_skip_args += 2;
            _dl_argc -= 2;
-           INTUSE(_dl_argv) += 2;
+           _dl_argv += 2;
          }
-       else if (! strcmp (INTUSE(_dl_argv)[1], "--audit") && _dl_argc > 2)
+       else if (! strcmp (_dl_argv[1], "--audit") && _dl_argc > 2)
          {
-           process_dl_audit (INTUSE(_dl_argv)[2]);
+           process_dl_audit (_dl_argv[2]);
 
            _dl_skip_args += 2;
            _dl_argc -= 2;
-           INTUSE(_dl_argv) += 2;
+           _dl_argv += 2;
+         }
+       else if (! strcmp (_dl_argv[1], "--preload") && _dl_argc > 2)
+         {
+           preloadarg = _dl_argv[2];
+           _dl_skip_args += 2;
+           _dl_argc -= 2;
+           _dl_argv += 2;
          }
        else
          break;
@@ -1022,15 +1210,17 @@ of this helper program; chances are you did not intend to run this program.\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\
+  --inhibit-cache       Do not use " LD_SO_CACHE "\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\
-  --audit LIST          use objects named in LIST as auditors\n");
+  --audit LIST          use objects named in LIST as auditors\n\
+  --preload LIST        preload objects named in LIST\n");
 
       ++_dl_skip_args;
       --_dl_argc;
-      ++INTUSE(_dl_argv);
+      ++_dl_argv;
 
       /* The initialization of _dl_stack_flags done below assumes the
         executable's PT_GNU_STACK may have been honored by the kernel, and
@@ -1063,7 +1253,7 @@ of this helper program; chances are you did not intend to run this program.\n\
          args.mode = __RTLD_OPENEXEC;
          (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit,
                                  &args);
-         if (__builtin_expect (err_str != NULL, 0))
+         if (__glibc_unlikely (err_str != NULL))
            /* We don't free the returned string, the programs stops
               anyway.  */
            _exit (EXIT_FAILURE);
@@ -1071,7 +1261,7 @@ of this helper program; chances are you did not intend to run this program.\n\
       else
        {
          HP_TIMING_NOW (start);
-         _dl_map_object (NULL, rtld_progname, lt_library, 0,
+         _dl_map_object (NULL, rtld_progname, lt_executable, 0,
                          __RTLD_OPENEXEC, LM_ID_BASE);
          HP_TIMING_NOW (stop);
 
@@ -1081,7 +1271,8 @@ of this helper program; chances are you did not intend to run this program.\n\
       /* Now the map for the main executable is available.  */
       main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
-      if (GL(dl_rtld_map).l_info[DT_SONAME] != NULL
+      if (__builtin_expect (mode, normal) == normal
+         && GL(dl_rtld_map).l_info[DT_SONAME] != NULL
          && main_map->l_info[DT_SONAME] != NULL
          && strcmp ((const char *) D_PTR (&GL(dl_rtld_map), l_info[DT_STRTAB])
                     + GL(dl_rtld_map).l_info[DT_SONAME]->d_un.d_val,
@@ -1113,6 +1304,9 @@ of this helper program; chances are you did not intend to run this program.\n\
          case AT_ENTRY:
            av->a_un.a_val = *user_entry;
            break;
+         case AT_EXECFN:
+           av->a_un.a_val = (uintptr_t) _dl_argv[0];
+           break;
          }
 #endif
     }
@@ -1258,6 +1452,12 @@ of this helper program; chances are you did not intend to run this program.\n\
        main_map->l_relro_addr = ph->p_vaddr;
        main_map->l_relro_size = ph->p_memsz;
        break;
+
+      case PT_NOTE:
+       if (_rtld_process_pt_note (main_map, ph))
+         _dl_error_printf ("\
+ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
+       break;
       }
 
   /* Adjust the address of the TLS initialization image in case
@@ -1325,102 +1525,12 @@ of this helper program; chances are you did not intend to run this program.\n\
     }
 
   struct link_map **first_preload = &GL(dl_rtld_map).l_next;
-#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
   /* Set up the data structures for the system-supplied DSO early,
      so they can influence _dl_init_paths.  */
-  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, LM_ID_BASE);
-      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;
-                 if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
-                   l->l_map_end = ph->p_vaddr + ph->p_memsz;
-                 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;
-               }
-             else
-               /* There must be no TLS segment.  */
-               assert (ph->p_type != PT_TLS);
-           }
-         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;
-
-         /* Initialize l_local_scope to contain just this map.  This allows
-            the use of dl_lookup_symbol_x to resolve symbols within the vdso.
-            So we create a single entry list pointing to l_real as its only
-            element */
-         l->l_local_scope[0]->r_nlist = 1;
-         l->l_local_scope[0]->r_list = &l->l_real;
-
-         /* 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 = l->l_name = memcpy (copy, dsoname, len);
-           }
-
-         /* Add the vDSO to the object list.  */
-         _dl_add_to_namespace_list (l, LM_ID_BASE);
-
-         /* Rearrange the list so this DSO appears after rtld_map.  */
-         assert (l->l_next == NULL);
-         assert (l->l_prev == main_map);
-         GL(dl_rtld_map).l_next = l;
-         l->l_prev = &GL(dl_rtld_map);
-         first_preload = &l->l_next;
-
-         /* We have a prelinked DSO preloaded by the system.  */
-         GLRO(dl_sysinfo_map) = l;
-# ifdef NEED_DL_SYSINFO
-         if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)
-           GLRO(dl_sysinfo) = GLRO(dl_sysinfo_dso)->e_entry + l->l_addr;
-# endif
-       }
-    }
-#endif
+  setup_vdso (main_map, &first_preload);
 
 #ifdef DL_SYSDEP_OSCHECK
-  DL_SYSDEP_OSCHECK (dl_fatal);
+  DL_SYSDEP_OSCHECK (_dl_fatal_printf);
 #endif
 
   /* Initialize the data structures for the search paths for shared
@@ -1452,10 +1562,25 @@ of this helper program; chances are you did not intend to run this program.\n\
     GLRO(dl_use_load_bias) = main_map->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);
+     itself.  It is needed in the dl_iterate_phdr callbacks.  */
+  const ElfW(Ehdr) *rtld_ehdr;
+
+  /* Starting from binutils-2.23, the linker will define the magic symbol
+     __ehdr_start to point to our own ELF header if it is visible in a
+     segment that also includes the phdrs.  If that's not available, we use
+     the old method that assumes the beginning of the file is part of the
+     lowest-addressed PT_LOAD segment.  */
+#ifdef HAVE_EHDR_START
+  extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden")));
+  rtld_ehdr = &__ehdr_start;
+#else
+  rtld_ehdr = (void *) GL(dl_rtld_map).l_map_start;
+#endif
+  assert (rtld_ehdr->e_ehsize == sizeof *rtld_ehdr);
+  assert (rtld_ehdr->e_phentsize == sizeof (ElfW(Phdr)));
+
+  const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff;
+
   GL(dl_rtld_map).l_phdr = rtld_phdr;
   GL(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum;
 
@@ -1476,12 +1601,10 @@ of this helper program; chances are you did not intend to run this program.\n\
     GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
 
   /* If we have auditing DSOs to load, do it now.  */
-  if (__builtin_expect (audit_list != NULL, 0))
+  bool need_security_init = true;
+  if (__glibc_unlikely (audit_list != NULL)
+      || __glibc_unlikely (audit_list_string != NULL))
     {
-      /* Iterate over all entries in the list.  The order is important.  */
-      struct audit_ifaces *last_audit = NULL;
-      struct audit_list *al = audit_list->next;
-
       /* Since we start using the auditing DSOs right away we need to
         initialize the data structures now.  */
       tcbp = init_tls ();
@@ -1491,166 +1614,15 @@ of this helper program; chances are you did not intend to run this program.\n\
         use different values (especially the pointer guard) and will
         fail later on.  */
       security_init ();
+      need_security_init = false;
 
-      do
-       {
-         int tls_idx = GL(dl_tls_max_dtv_idx);
-
-         /* 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.  */
-         struct dlmopen_args dlmargs;
-         dlmargs.fname = al->name;
-         dlmargs.map = NULL;
-
-         const char *objname;
-         const char *err_str = NULL;
-         bool malloced;
-         (void) _dl_catch_error (&objname, &err_str, &malloced, dlmopen_doit,
-                                 &dlmargs);
-         if (__builtin_expect (err_str != NULL, 0))
-           {
-           not_loaded:
-             _dl_error_printf ("\
-ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
-                               al->name, err_str);
-             if (malloced)
-               free ((char *) err_str);
-           }
-         else
-           {
-             struct lookup_args largs;
-             largs.name = "la_version";
-             largs.map = dlmargs.map;
-
-             /* Check whether the interface version matches.  */
-             (void) _dl_catch_error (&objname, &err_str, &malloced,
-                                     lookup_doit, &largs);
-
-             unsigned int (*laversion) (unsigned int);
-             unsigned int lav;
-             if  (err_str == NULL
-                  && (laversion = largs.result) != NULL
-                  && (lav = laversion (LAV_CURRENT)) > 0
-                  && lav <= LAV_CURRENT)
-               {
-                 /* Allocate structure for the callback function pointers.
-                    This call can never fail.  */
-                 union
-                 {
-                   struct audit_ifaces ifaces;
-#define naudit_ifaces 8
-                   void (*fptr[naudit_ifaces]) (void);
-                 } *newp = malloc (sizeof (*newp));
-
-                 /* Names of the auditing interfaces.  All in one
-                    long string.  */
-                 static const char audit_iface_names[] =
-                   "la_activity\0"
-                   "la_objsearch\0"
-                   "la_objopen\0"
-                   "la_preinit\0"
-#if __ELF_NATIVE_CLASS == 32
-                   "la_symbind32\0"
-#elif __ELF_NATIVE_CLASS == 64
-                   "la_symbind64\0"
-#else
-# error "__ELF_NATIVE_CLASS must be defined"
-#endif
-#define STRING(s) __STRING (s)
-                   "la_" STRING (ARCH_LA_PLTENTER) "\0"
-                   "la_" STRING (ARCH_LA_PLTEXIT) "\0"
-                   "la_objclose\0";
-                 unsigned int cnt = 0;
-                 const char *cp = audit_iface_names;
-                 do
-                   {
-                     largs.name = cp;
-                     (void) _dl_catch_error (&objname, &err_str, &malloced,
-                                             lookup_doit, &largs);
-
-                     /* Store the pointer.  */
-                     if (err_str == NULL && largs.result != NULL)
-                       {
-                         newp->fptr[cnt] = largs.result;
-
-                         /* The dynamic linker link map is statically
-                            allocated, initialize the data now.   */
-                         GL(dl_rtld_map).l_audit[cnt].cookie
-                           = (intptr_t) &GL(dl_rtld_map);
-                       }
-                     else
-                       newp->fptr[cnt] = NULL;
-                     ++cnt;
-
-                     cp = (char *) rawmemchr (cp, '\0') + 1;
-                   }
-                 while (*cp != '\0');
-                 assert (cnt == naudit_ifaces);
-
-                 /* Now append the new auditing interface to the list.  */
-                 newp->ifaces.next = NULL;
-                 if (last_audit == NULL)
-                   last_audit = GLRO(dl_audit) = &newp->ifaces;
-                 else
-                   last_audit = last_audit->next = &newp->ifaces;
-                 ++GLRO(dl_naudit);
-
-                 /* Mark the DSO as being used for auditing.  */
-                 dlmargs.map->l_auditing = 1;
-               }
-             else
-               {
-                 /* We cannot use the DSO, it does not have the
-                    appropriate interfaces or it expects something
-                    more recent.  */
-#ifndef NDEBUG
-                 Lmid_t ns = dlmargs.map->l_ns;
-#endif
-                 _dl_close (dlmargs.map);
-
-                 /* Make sure the namespace has been cleared entirely.  */
-                 assert (GL(dl_ns)[ns]._ns_loaded == NULL);
-                 assert (GL(dl_ns)[ns]._ns_nloaded == 0);
-
-                 GL(dl_tls_max_dtv_idx) = tls_idx;
-                 goto not_loaded;
-               }
-           }
-
-         al = al->next;
-       }
-      while (al != audit_list->next);
-
-      /* If we have any auditing modules, announce that we already
-        have two objects loaded.  */
-      if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
-       {
-         struct link_map *ls[2] = { main_map, &GL(dl_rtld_map) };
-
-         for (unsigned int outer = 0; outer < 2; ++outer)
-           {
-             struct audit_ifaces *afct = GLRO(dl_audit);
-             for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
-               {
-                 if (afct->objopen != NULL)
-                   {
-                     ls[outer]->l_audit[cnt].bindflags
-                       = afct->objopen (ls[outer], LM_ID_BASE,
-                                        &ls[outer]->l_audit[cnt].cookie);
-
-                     ls[outer]->l_audit_any_plt
-                       |= ls[outer]->l_audit[cnt].bindflags != 0;
-                   }
-
-                 afct = afct->next;
-               }
-           }
-       }
+      load_audit_modules (main_map);
     }
 
+  /* Keep track of the currently loaded modules to count how many
+     non-audit modules which use TLS are loaded.  */
+  size_t count_modids = _dl_count_modids ();
+
   /* Set up debugging before the debugger is notified for the first time.  */
 #ifdef ELF_MACHINE_DEBUG_SETUP
   /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
@@ -1671,10 +1643,11 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   /* We start adding objects.  */
   r->r_state = RT_ADD;
   _dl_debug_state ();
+  LIBC_PROBE (init_start, 2, LM_ID_BASE, r);
 
   /* Auditing checkpoint: we are ready to signal that the initial map
      is being constructed.  */
-  if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
+  if (__glibc_unlikely (GLRO(dl_naudit) > 0))
     {
       struct audit_ifaces *afct = GLRO(dl_audit);
       for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
@@ -1693,25 +1666,19 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   struct link_map **preloads = NULL;
   unsigned int npreloads = 0;
 
-  if (__builtin_expect (preloadlist != NULL, 0))
+  if (__glibc_unlikely (preloadlist != NULL))
     {
-      /* 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);
+      npreloads += handle_preload_list (preloadlist, main_map, "LD_PRELOAD");
+      HP_TIMING_NOW (stop);
+      HP_TIMING_DIFF (diff, start, stop);
+      HP_TIMING_ACCUM_NT (load_time, diff);
+    }
 
-      /* 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))
-         npreloads += do_preload (p, main_map, "LD_PRELOAD");
-
+  if (__glibc_unlikely (preloadarg != NULL))
+    {
+      HP_TIMING_NOW (start);
+      npreloads += handle_preload_list (preloadarg, main_map, "--preload");
       HP_TIMING_NOW (stop);
       HP_TIMING_DIFF (diff, start, stop);
       HP_TIMING_ACCUM_NT (load_time, diff);
@@ -1724,12 +1691,12 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
      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))
+  if (__glibc_unlikely (__access (preload_file, R_OK) == 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))
+      if (__glibc_unlikely (file != MAP_FAILED))
        {
          /* Parse the file.  It contains names of libraries to be loaded,
             separated by white spaces or `:'.  It may also contain
@@ -1801,7 +1768,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
        }
     }
 
-  if (__builtin_expect (*first_preload != NULL, 0))
+  if (__glibc_unlikely (*first_preload != NULL))
     {
       /* Set up PRELOADS with a vector of the preloaded libraries.  */
       struct link_map *l = *first_preload;
@@ -1838,7 +1805,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
       break;
 
   bool rtld_multiple_ref = false;
-  if (__builtin_expect (i < main_map->l_searchlist.r_nlist, 1))
+  if (__glibc_likely (i < main_map->l_searchlist.r_nlist))
     {
       /* 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
@@ -1852,7 +1819,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
          GL(dl_rtld_map).l_next = (i + 1 < main_map->l_searchlist.r_nlist
                                    ? main_map->l_searchlist.r_list[i + 1]
                                    : NULL);
-#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
+#ifdef NEED_DL_SYSINFO_DSO
          if (GLRO(dl_sysinfo_map) != NULL
              && GL(dl_rtld_map).l_prev->l_next == GLRO(dl_sysinfo_map)
              && GL(dl_rtld_map).l_next != GLRO(dl_sysinfo_map))
@@ -1896,7 +1863,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   if (tcbp == NULL)
     tcbp = init_tls ();
 
-  if (__builtin_expect (audit_list == NULL, 1))
+  if (__glibc_likely (need_security_init))
     /* Initialize security features.  But only if we have not done it
        earlier.  */
     security_init ();
@@ -1924,10 +1891,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
              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>",
+                         DSO_FILENAME (l->l_libname->name),
+                         DSO_FILENAME (l->l_name),
                          (int) sizeof l->l_map_start * 2,
                          (size_t) l->l_map_start,
                          (int) sizeof l->l_addr * 2,
@@ -1964,7 +1929,12 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
              if (dyn->d_tag == DT_NEEDED)
                {
                  l = l->l_next;
-
+#ifdef NEED_DL_SYSINFO_DSO
+                 /* Skip the VDSO since it's not part of the list
+                    of objects we brought in via DT_NEEDED entries.  */
+                 if (l == GLRO(dl_sysinfo_map))
+                   l = l->l_next;
+#endif
                  if (!l->l_used)
                    {
                      if (first)
@@ -2007,15 +1977,15 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
            ElfW(Addr) loadbase;
            lookup_t result;
 
-           result = _dl_lookup_symbol_x (INTUSE(_dl_argv)[i], main_map,
+           result = _dl_lookup_symbol_x (_dl_argv[i], main_map,
                                          &ref, main_map->l_scope,
                                          NULL, ELF_RTYPE_CLASS_PLT,
                                          DL_LOOKUP_ADD_DEPENDENCY, NULL);
 
-           loadbase = LOOKUP_VALUE_ADDRESS (result);
+           loadbase = LOOKUP_VALUE_ADDRESS (result, false);
 
            _dl_printf ("%s found at 0x%0*Zd in object at 0x%0*Zd\n",
-                       INTUSE(_dl_argv)[i],
+                       _dl_argv[i],
                        (int) sizeof ref->st_value * 2,
                        (size_t) ref->st_value,
                        (int) sizeof loadbase * 2, (size_t) loadbase);
@@ -2079,8 +2049,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
                      first = 0;
                    }
 
-                 _dl_printf ("\t%s:\n",
-                             map->l_name[0] ? map->l_name : rtld_progname);
+                 _dl_printf ("\t%s:\n", DSO_FILENAME (map->l_name));
 
                  while (1)
                    {
@@ -2141,8 +2110,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
       liblist = (ElfW(Lib) *)
                main_map->l_info[ADDRIDX (DT_GNU_LIBLIST)]->d_un.d_ptr;
       liblistend = (ElfW(Lib) *)
-                  ((char *) liblist +
-                   main_map->l_info[VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);
+                  ((char *) liblist
+                   main_map->l_info[VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);
       r_list = main_map->l_searchlist.r_list;
       r_listend = r_list + main_map->l_searchlist.r_nlist;
 
@@ -2178,7 +2147,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
       if (r_list == r_listend && liblist == liblistend)
        prelinked = true;
 
-      if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS, 0))
+      if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
        _dl_debug_printf ("\nprelink checking: %s\n",
                          prelinked ? "ok" : "failed");
     }
@@ -2192,11 +2161,13 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   GLRO(dl_initial_searchlist) = *GL(dl_ns)[LM_ID_BASE]._ns_main_searchlist;
 
   /* Remember the last search directory added at startup, now that
-     malloc will no longer be the one from dl-minimal.c.  */
+     malloc will no longer be the one from dl-minimal.c.  As a side
+     effect, this marks ld.so as initialized, so that the rtld_active
+     function returns true from now on.  */
   GLRO(dl_init_all_dirs) = GL(dl_all_dirs);
 
   /* Print scope information.  */
-  if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES, 0))
+  if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES))
     {
       _dl_debug_printf ("\nInitial object scopes\n");
 
@@ -2204,6 +2175,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
        _dl_show_scope (l, 0);
     }
 
+  _rtld_main_check (main_map, _dl_argv[0]);
+
   if (prelinked)
     {
       if (main_map->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
@@ -2275,6 +2248,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
              lnp->dont_free = 1;
              lnp = lnp->next;
            }
+         /* Also allocated with the fake malloc().  */
+         l->l_free_initfini = 0;
 
          if (l != &GL(dl_rtld_map))
            _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0,
@@ -2292,34 +2267,27 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
         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))
+      if (__glibc_unlikely (GL(dl_profile_map) != NULL))
        /* We must prepare the profiling.  */
        _dl_start_profile ();
     }
 
-#ifndef NONTLS_INIT_TP
-# define NONTLS_INIT_TP do { } while (0)
-#endif
-
-  if (!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0)
+  if ((!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0)
+      || count_modids != _dl_count_modids ())
     ++GL(dl_tls_generation);
 
   /* 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.  */
+     into the main thread's TLS area, which we allocated above.
+     Note: thread-local variables must only be accessed after completing
+     the next step.  */
   _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.  */
+  /* And finally install it for the main thread.  */
   if (! tls_init_tp_called)
     {
-      const char *lossage
-#ifdef USE___THREAD
-       = TLS_INIT_TP (tcbp, USE___THREAD);
-#else
-       = TLS_INIT_TP (tcbp, 0);
-#endif
-      if (__builtin_expect (lossage != NULL, 0))
+      const char *lossage = TLS_INIT_TP (tcbp);
+      if (__glibc_unlikely (lossage != NULL))
        _dl_fatal_printf ("cannot set up thread-local storage: %s\n",
                          lossage);
     }
@@ -2360,7 +2328,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 
 #ifdef SHARED
   /* Auditing checkpoint: we have added all objects.  */
-  if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
+  if (__glibc_unlikely (GLRO(dl_naudit) > 0))
     {
       struct link_map *head = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
       /* Do not call the functions for any auditing object.  */
@@ -2383,8 +2351,9 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
   r = _dl_debug_initialize (0, LM_ID_BASE);
   r->r_state = RT_CONSISTENT;
   _dl_debug_state ();
+  LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
 
-#ifndef MAP_COPY
+#if defined USE_LDCONFIG && !defined MAP_COPY
   /* We must munmap() the cache file.  */
   _dl_unload_cache ();
 #endif
@@ -2400,7 +2369,7 @@ print_unresolved (int errcode __attribute__ ((unused)), const char *objname,
                  const char *errstring)
 {
   if (objname[0] == '\0')
-    objname = rtld_progname ?: "<main program>";
+    objname = RTLD_PROGNAME;
   _dl_error_printf ("%s        (%s)\n", errstring, objname);
 }
 \f
@@ -2410,7 +2379,7 @@ static void
 print_missing_version (int errcode __attribute__ ((unused)),
                       const char *objname, const char *errstring)
 {
-  _dl_error_printf ("%s: %s: %s\n", rtld_progname ?: "<program name unknown>",
+  _dl_error_printf ("%s: %s: %s\n", RTLD_PROGNAME,
                    objname, errstring);
 }
 \f
@@ -2497,6 +2466,14 @@ warning: debug option `%s' unknown; try LD_DEBUG=help\n", copy);
       ++dl_debug;
     }
 
+  if (GLRO(dl_debug_mask) & DL_DEBUG_UNUSED)
+    {
+      /* In order to get an accurate picture of whether a particular
+        DT_NEEDED entry is actually used we have to process both
+        the PLT and non-PLT relocation entries.  */
+      GLRO(dl_lazy) = 0;
+    }
+
   if (GLRO(dl_debug_mask) & DL_DEBUG_HELP)
     {
       size_t cnt;
@@ -2523,9 +2500,7 @@ process_dl_audit (char *str)
   char *p;
 
   while ((p = (strsep) (&str, ":")) != NULL)
-    if (p[0] != '\0'
-       && (__builtin_expect (! INTUSE(__libc_enable_secure), 1)
-           || strchr (p, '/') == NULL))
+    if (dso_name_valid_for_suid (p))
       {
        /* This is using the local malloc, not the system malloc.  The
           memory can never be freed.  */
@@ -2558,7 +2533,7 @@ process_envvars (enum mode *modep)
 
   /* This is the default place for profiling data file.  */
   GLRO(dl_profile_output)
-    = &"/var/tmp\0/var/profile"[INTUSE(__libc_enable_secure) ? 9 : 0];
+    = &"/var/tmp\0/var/profile"[__libc_enable_secure ? 9 : 0];
 
   while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
     {
@@ -2589,7 +2564,7 @@ process_envvars (enum mode *modep)
              break;
            }
          if (memcmp (envline, "AUDIT", 5) == 0)
-           process_dl_audit (&envline[6]);
+           audit_list_string = &envline[6];
          break;
 
        case 7:
@@ -2626,28 +2601,31 @@ process_envvars (enum mode *modep)
        case 9:
          /* Test whether we want to see the content of the auxiliary
             array passed up from the kernel.  */
-         if (!INTUSE(__libc_enable_secure)
+         if (!__libc_enable_secure
              && memcmp (envline, "SHOW_AUXV", 9) == 0)
            _dl_show_auxv ();
          break;
 
+#if !HAVE_TUNABLES
        case 10:
          /* Mask for the important hardware capabilities.  */
-         if (memcmp (envline, "HWCAP_MASK", 10) == 0)
-           GLRO(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL,
-                                                     0, 0);
+         if (!__libc_enable_secure
+             && memcmp (envline, "HWCAP_MASK", 10) == 0)
+           GLRO(dl_hwcap_mask) = _dl_strtoul (&envline[11], NULL);
          break;
+#endif
 
        case 11:
          /* Path where the binary is found.  */
-         if (!INTUSE(__libc_enable_secure)
+         if (!__libc_enable_secure
              && memcmp (envline, "ORIGIN_PATH", 11) == 0)
            GLRO(dl_origin_path) = &envline[12];
          break;
 
        case 12:
          /* The library search path.  */
-         if (memcmp (envline, "LIBRARY_PATH", 12) == 0)
+         if (!__libc_enable_secure
+             && memcmp (envline, "LIBRARY_PATH", 12) == 0)
            {
              library_path = &envline[13];
              break;
@@ -2660,7 +2638,7 @@ process_envvars (enum mode *modep)
              break;
            }
 
-         if (!INTUSE(__libc_enable_secure)
+         if (!__libc_enable_secure
              && memcmp (envline, "DYNAMIC_WEAK", 12) == 0)
            GLRO(dl_dynamic_weak) = 1;
          break;
@@ -2671,20 +2649,17 @@ process_envvars (enum mode *modep)
 #ifdef EXTRA_LD_ENVVARS_13
          EXTRA_LD_ENVVARS_13
 #endif
-         if (!INTUSE(__libc_enable_secure)
+         if (!__libc_enable_secure
              && memcmp (envline, "USE_LOAD_BIAS", 13) == 0)
            {
              GLRO(dl_use_load_bias) = envline[14] == '1' ? -1 : 0;
              break;
            }
-
-         if (memcmp (envline, "POINTER_GUARD", 13) == 0)
-           GLRO(dl_pointer_guard) = envline[14] != '0';
          break;
 
        case 14:
          /* Where to place the profiling data file.  */
-         if (!INTUSE(__libc_enable_secure)
+         if (!__libc_enable_secure
              && memcmp (envline, "PROFILE_OUTPUT", 14) == 0
              && envline[15] != '\0')
            GLRO(dl_profile_output) = &envline[15];
@@ -2722,7 +2697,7 @@ process_envvars (enum mode *modep)
 
   /* Extra security for SUID binaries.  Remove all dangerous environment
      variables.  */
-  if (__builtin_expect (INTUSE(__libc_enable_secure), 0))
+  if (__builtin_expect (__libc_enable_secure, 0))
     {
       static const char unsecure_envvars[] =
 #ifdef EXTRA_UNSECURE_ENVVARS
@@ -2742,7 +2717,9 @@ process_envvars (enum mode *modep)
 
       if (__access ("/etc/suid-debug", F_OK) != 0)
        {
+#if !HAVE_TUNABLES
          unsetenv ("MALLOC_CHECK_");
+#endif
          GLRO(dl_debug_mask) = 0;
        }
 
@@ -2754,11 +2731,7 @@ process_envvars (enum mode *modep)
      messages to this file.  */
   else if (any_debug && debug_output != NULL)
     {
-#ifdef O_NOFOLLOW
       const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW;
-#else
-      const int flags = O_WRONLY | O_APPEND | O_CREAT;
-#endif
       size_t name_len = strlen (debug_output);
       char buf[name_len + 12];
       char *startp;
@@ -2768,7 +2741,7 @@ process_envvars (enum mode *modep)
       *--startp = '.';
       startp = memcpy (startp - name_len, debug_output, name_len);
 
-      GLRO(dl_debug_fd) = __open (startp, flags, DEFFILEMODE);
+      GLRO(dl_debug_fd) = __open64_nocancel (startp, flags, DEFFILEMODE);
       if (GLRO(dl_debug_fd) == -1)
        /* We use standard output if opening the file failed.  */
        GLRO(dl_debug_fd) = STDOUT_FILENO;
@@ -2787,7 +2760,7 @@ print_statistics (hp_timing_t *rtld_total_timep)
   char *wp;
 
   /* Total time rtld used.  */
-  if (HP_TIMING_AVAIL)
+  if (HP_SMALL_TIMING_AVAIL)
     {
       HP_TIMING_PRINT (buf, sizeof (buf), *rtld_total_timep);
       _dl_debug_printf ("\nruntime linker statistics:\n"
@@ -2803,8 +2776,10 @@ print_statistics (hp_timing_t *rtld_total_timep)
        {
        case 3:
          *wp++ = *cp++;
+         /* Fall through.  */
        case 2:
          *wp++ = *cp++;
+         /* Fall through.  */
        case 1:
          *wp++ = '.';
          *wp++ = *cp++;
@@ -2855,7 +2830,7 @@ print_statistics (hp_timing_t *rtld_total_timep)
 
 #ifndef HP_TIMING_NONAVAIL
   /* Time spend while loading the object and the dependencies.  */
-  if (HP_TIMING_AVAIL)
+  if (HP_SMALL_TIMING_AVAIL)
     {
       char pbuf[30];
       HP_TIMING_PRINT (buf, sizeof (buf), load_time);
@@ -2866,8 +2841,10 @@ print_statistics (hp_timing_t *rtld_total_timep)
        {
        case 3:
          *wp++ = *cp++;
+         /* Fall through.  */
        case 2:
          *wp++ = *cp++;
+         /* Fall through.  */
        case 1:
          *wp++ = '.';
          *wp++ = *cp++;