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