e354a5
commit 56f8d442942ee51824b4683be83f776a811a3f2a
e354a5
Author: Florian Weimer <fweimer@redhat.com>
e354a5
Date:   Wed Oct 7 16:40:23 2020 +0200
e354a5
e354a5
    elf: Do not search HWCAP subdirectories in statically linked binaries
e354a5
    
e354a5
    This functionality does not seem to be useful since static dlopen
e354a5
    is mostly used for iconv/character set conversion and NSS support.
e354a5
    gconv modules are loaded with full paths anyway, so that the
e354a5
    HWCAP subdirectory logic does not apply.
e354a5
    
e354a5
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
e354a5
e354a5
diff --git a/elf/Makefile b/elf/Makefile
e354a5
index 837a070c267527e1..ef655630d50b07aa 100644
e354a5
--- a/elf/Makefile
e354a5
+++ b/elf/Makefile
e354a5
@@ -29,7 +29,7 @@ routines	= $(all-dl-routines) dl-support dl-iteratephdr \
e354a5
 
e354a5
 # The core dynamic linking functions are in libc for the static and
e354a5
 # profiled libraries.
e354a5
-dl-routines	= $(addprefix dl-,load lookup object reloc deps hwcaps \
e354a5
+dl-routines	= $(addprefix dl-,load lookup object reloc deps \
e354a5
 				  runtime init fini debug misc \
e354a5
 				  version profile tls origin scope \
e354a5
 				  execstack open close trampoline \
e354a5
@@ -59,7 +59,7 @@ elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
e354a5
 # ld.so uses those routines, plus some special stuff for being the program
e354a5
 # interpreter and operating independent of libc.
e354a5
 rtld-routines	= rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
e354a5
-  dl-error-minimal dl-conflict
e354a5
+  dl-error-minimal dl-conflict dl-hwcaps
e354a5
 all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
e354a5
 
e354a5
 CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
e354a5
diff --git a/elf/dl-load.c b/elf/dl-load.c
e354a5
index 64da5323d0e368c1..2b4dd9a0f3e27b70 100644
e354a5
--- a/elf/dl-load.c
e354a5
+++ b/elf/dl-load.c
e354a5
@@ -101,9 +101,13 @@ int __stack_prot attribute_hidden attribute_relro
e354a5
 static struct r_search_path_struct env_path_list attribute_relro;
e354a5
 
e354a5
 /* List of the hardware capabilities we might end up using.  */
e354a5
+#ifdef SHARED
e354a5
 static const struct r_strlenpair *capstr attribute_relro;
e354a5
 static size_t ncapstr attribute_relro;
e354a5
 static size_t max_capstrlen attribute_relro;
e354a5
+#else
e354a5
+enum { ncapstr = 1, max_capstrlen = 0 };
e354a5
+#endif
e354a5
 
e354a5
 
e354a5
 /* Get the generated information about the trusted directories.  Use
e354a5
@@ -691,9 +695,11 @@ _dl_init_paths (const char *llp)
e354a5
   /* Fill in the information about the application's RPATH and the
e354a5
      directories addressed by the LD_LIBRARY_PATH environment variable.  */
e354a5
 
e354a5
+#ifdef SHARED
e354a5
   /* Get the capabilities.  */
e354a5
   capstr = _dl_important_hwcaps (GLRO(dl_platform), GLRO(dl_platformlen),
e354a5
 				 &ncapstr, &max_capstrlen);
e354a5
+#endif
e354a5
 
e354a5
   /* First set up the rest of the default search directory entries.  */
e354a5
   aelem = rtld_search_dirs.dirs = (struct r_search_path_elem **)
e354a5
@@ -1459,11 +1465,15 @@ print_search_path (struct r_search_path_elem **list,
e354a5
       for (cnt = 0; cnt < ncapstr; ++cnt)
e354a5
 	if ((*list)->status[cnt] != nonexisting)
e354a5
 	  {
e354a5
+#ifdef SHARED
e354a5
 	    char *cp = __mempcpy (endp, capstr[cnt].str, capstr[cnt].len);
e354a5
 	    if (cp == buf || (cp == buf + 1 && buf[0] == '/'))
e354a5
 	      cp[0] = '\0';
e354a5
 	    else
e354a5
 	      cp[-1] = '\0';
e354a5
+#else
e354a5
+	    *endp = '\0';
e354a5
+#endif
e354a5
 
e354a5
 	    _dl_debug_printf_c (first ? "%s" : ":%s", buf);
e354a5
 	    first = 0;
e354a5
@@ -1836,11 +1846,15 @@ open_path (const char *name, size_t namelen, int mode,
e354a5
 	  if (this_dir->status[cnt] == nonexisting)
e354a5
 	    continue;
e354a5
 
e354a5
+#ifdef SHARED
e354a5
 	  buflen =
e354a5
 	    ((char *) __mempcpy (__mempcpy (edp, capstr[cnt].str,
e354a5
 					    capstr[cnt].len),
e354a5
 				 name, namelen)
e354a5
 	     - buf);
e354a5
+#else
e354a5
+	  buflen = (char *) __mempcpy (edp, name, namelen) - buf;
e354a5
+#endif
e354a5
 
e354a5
 	  /* Print name we try if this is wanted.  */
e354a5
 	  if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))