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