b1dca6
commit 50b1b7a3905cbcdfbcc7eab335aa81478d711d1a
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Thu Oct 8 15:33:00 2020 +0200
b1dca6
b1dca6
    elf: Make __rtld_env_path_list and __rtld_search_dirs global variables
b1dca6
    
b1dca6
    They have been renamed from env_path_list and rtld_search_dirs to
b1dca6
    avoid linknamespace issues.
b1dca6
    
b1dca6
    This change will allow future use these variables in diagnostics.
b1dca6
    
b1dca6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
b1dca6
b1dca6
diff --git a/elf/dl-load.c b/elf/dl-load.c
b1dca6
index 1403a2e9c04e9a16..2eb4f35b2467f7d8 100644
b1dca6
--- a/elf/dl-load.c
b1dca6
+++ b/elf/dl-load.c
b1dca6
@@ -98,7 +98,7 @@ int __stack_prot attribute_hidden attribute_relro
b1dca6
 
b1dca6
 
b1dca6
 /* This is the decomposed LD_LIBRARY_PATH search path.  */
b1dca6
-static struct r_search_path_struct env_path_list attribute_relro;
b1dca6
+struct r_search_path_struct __rtld_env_path_list attribute_relro;
b1dca6
 
b1dca6
 /* List of the hardware capabilities we might end up using.  */
b1dca6
 #ifdef SHARED
b1dca6
@@ -442,7 +442,7 @@ add_name_to_object (struct link_map *l, const char *name)
b1dca6
 }
b1dca6
 
b1dca6
 /* Standard search directories.  */
b1dca6
-static struct r_search_path_struct rtld_search_dirs attribute_relro;
b1dca6
+struct r_search_path_struct __rtld_search_dirs attribute_relro;
b1dca6
 
b1dca6
 static size_t max_dirnamelen;
b1dca6
 
b1dca6
@@ -702,9 +702,9 @@ _dl_init_paths (const char *llp, const char *source)
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
+  aelem = __rtld_search_dirs.dirs = (struct r_search_path_elem **)
b1dca6
     malloc ((nsystem_dirs_len + 1) * sizeof (struct r_search_path_elem *));
b1dca6
-  if (rtld_search_dirs.dirs == NULL)
b1dca6
+  if (__rtld_search_dirs.dirs == NULL)
b1dca6
     {
b1dca6
       errstring = N_("cannot create search path array");
b1dca6
     signal_error:
b1dca6
@@ -715,16 +715,17 @@ _dl_init_paths (const char *llp, const char *source)
b1dca6
 		 + ncapstr * sizeof (enum r_dir_status))
b1dca6
 		/ sizeof (struct r_search_path_elem));
b1dca6
 
b1dca6
-  rtld_search_dirs.dirs[0] = malloc (nsystem_dirs_len * round_size
b1dca6
-				     * sizeof (*rtld_search_dirs.dirs[0]));
b1dca6
-  if (rtld_search_dirs.dirs[0] == NULL)
b1dca6
+  __rtld_search_dirs.dirs[0]
b1dca6
+    = malloc (nsystem_dirs_len * round_size
b1dca6
+	      * sizeof (*__rtld_search_dirs.dirs[0]));
b1dca6
+  if (__rtld_search_dirs.dirs[0] == NULL)
b1dca6
     {
b1dca6
       errstring = N_("cannot create cache for search path");
b1dca6
       goto signal_error;
b1dca6
     }
b1dca6
 
b1dca6
-  rtld_search_dirs.malloced = 0;
b1dca6
-  pelem = GL(dl_all_dirs) = rtld_search_dirs.dirs[0];
b1dca6
+  __rtld_search_dirs.malloced = 0;
b1dca6
+  pelem = GL(dl_all_dirs) = __rtld_search_dirs.dirs[0];
b1dca6
   strp = system_dirs;
b1dca6
   idx = 0;
b1dca6
 
b1dca6
@@ -811,27 +812,27 @@ _dl_init_paths (const char *llp, const char *source)
b1dca6
 	if (*cp == ':' || *cp == ';')
b1dca6
 	  ++nllp;
b1dca6
 
b1dca6
-      env_path_list.dirs = (struct r_search_path_elem **)
b1dca6
+      __rtld_env_path_list.dirs = (struct r_search_path_elem **)
b1dca6
 	malloc ((nllp + 1) * sizeof (struct r_search_path_elem *));
b1dca6
-      if (env_path_list.dirs == NULL)
b1dca6
+      if (__rtld_env_path_list.dirs == NULL)
b1dca6
 	{
b1dca6
 	  errstring = N_("cannot create cache for search path");
b1dca6
 	  goto signal_error;
b1dca6
 	}
b1dca6
 
b1dca6
-      (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
b1dca6
+      (void) fillin_rpath (llp_tmp, __rtld_env_path_list.dirs, ":;",
b1dca6
 			   source, NULL, l);
b1dca6
 
b1dca6
-      if (env_path_list.dirs[0] == NULL)
b1dca6
+      if (__rtld_env_path_list.dirs[0] == NULL)
b1dca6
 	{
b1dca6
-	  free (env_path_list.dirs);
b1dca6
-	  env_path_list.dirs = (void *) -1;
b1dca6
+	  free (__rtld_env_path_list.dirs);
b1dca6
+	  __rtld_env_path_list.dirs = (void *) -1;
b1dca6
 	}
b1dca6
 
b1dca6
-      env_path_list.malloced = 0;
b1dca6
+      __rtld_env_path_list.malloced = 0;
b1dca6
     }
b1dca6
   else
b1dca6
-    env_path_list.dirs = (void *) -1;
b1dca6
+    __rtld_env_path_list.dirs = (void *) -1;
b1dca6
 }
b1dca6
 
b1dca6
 
b1dca6
@@ -1946,9 +1947,9 @@ open_path (const char *name, size_t namelen, int mode,
b1dca6
       if (sps->malloced)
b1dca6
 	free (sps->dirs);
b1dca6
 
b1dca6
-      /* rtld_search_dirs and env_path_list are attribute_relro, therefore
b1dca6
-	 avoid writing into it.  */
b1dca6
-      if (sps != &rtld_search_dirs && sps != &env_path_list)
b1dca6
+      /* __rtld_search_dirs and __rtld_env_path_list are
b1dca6
+	 attribute_relro, therefore avoid writing to them.  */
b1dca6
+      if (sps != &__rtld_search_dirs && sps != &__rtld_env_path_list)
b1dca6
 	sps->dirs = (void *) -1;
b1dca6
     }
b1dca6
 
b1dca6
@@ -2096,8 +2097,8 @@ _dl_map_object (struct link_map *loader, const char *name,
b1dca6
 	}
b1dca6
 
b1dca6
       /* Try the LD_LIBRARY_PATH environment variable.  */
b1dca6
-      if (fd == -1 && env_path_list.dirs != (void *) -1)
b1dca6
-	fd = open_path (name, namelen, mode, &env_path_list,
b1dca6
+      if (fd == -1 && __rtld_env_path_list.dirs != (void *) -1)
b1dca6
+	fd = open_path (name, namelen, mode, &__rtld_env_path_list,
b1dca6
 			&realname, &fb,
b1dca6
 			loader ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded,
b1dca6
 			LA_SER_LIBPATH, &found_other_class);
b1dca6
@@ -2186,8 +2187,8 @@ _dl_map_object (struct link_map *loader, const char *name,
b1dca6
       if (fd == -1
b1dca6
 	  && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL
b1dca6
 	      || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB)))
b1dca6
-	  && rtld_search_dirs.dirs != (void *) -1)
b1dca6
-	fd = open_path (name, namelen, mode, &rtld_search_dirs,
b1dca6
+	  && __rtld_search_dirs.dirs != (void *) -1)
b1dca6
+	fd = open_path (name, namelen, mode, &__rtld_search_dirs,
b1dca6
 			&realname, &fb, l, LA_SER_DEFAULT, &found_other_class);
b1dca6
 
b1dca6
       /* Add another newline when we are tracing the library loading.  */
b1dca6
@@ -2355,7 +2356,7 @@ _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting)
b1dca6
     }
b1dca6
 
b1dca6
   /* Try the LD_LIBRARY_PATH environment variable.  */
b1dca6
-  add_path (&p, &env_path_list, XXX_ENV);
b1dca6
+  add_path (&p, &__rtld_env_path_list, XXX_ENV);
b1dca6
 
b1dca6
   /* Look at the RUNPATH information for this binary.  */
b1dca6
   if (cache_rpath (loader, &loader->l_runpath_dirs, DT_RUNPATH, "RUNPATH"))
b1dca6
@@ -2367,7 +2368,7 @@ _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting)
b1dca6
 
b1dca6
   /* Finally, try the default path.  */
b1dca6
   if (!(loader->l_flags_1 & DF_1_NODEFLIB))
b1dca6
-    add_path (&p, &rtld_search_dirs, XXX_default);
b1dca6
+    add_path (&p, &__rtld_search_dirs, XXX_default);
b1dca6
 
b1dca6
   if (counting)
b1dca6
     /* Count the struct size before the string area, which we didn't
b1dca6
diff --git a/include/link.h b/include/link.h
b1dca6
index e90fa79a0b332087..cdd011f59445e490 100644
b1dca6
--- a/include/link.h
b1dca6
+++ b/include/link.h
b1dca6
@@ -79,6 +79,10 @@ struct r_search_path_struct
b1dca6
     int malloced;
b1dca6
   };
b1dca6
 
b1dca6
+/* Search path information computed by _dl_init_paths.  */
b1dca6
+extern struct r_search_path_struct __rtld_search_dirs attribute_hidden;
b1dca6
+extern struct r_search_path_struct __rtld_env_path_list attribute_hidden;
b1dca6
+
b1dca6
 /* Structure describing a loaded shared object.  The `l_next' and `l_prev'
b1dca6
    members form a chain of all the shared objects loaded at startup.
b1dca6