b1dca6
commit 27316f4a23efdc90bdfe4569a6c4b7e27941606e
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Thu Oct 8 10:57:10 2020 +0200
b1dca6
b1dca6
    elf: Record whether paths come from LD_LIBRARY_PATH or --library-path
b1dca6
    
b1dca6
    This allows more precise LD_DEBUG 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 2b4dd9a0f3e27b70..1403a2e9c04e9a16 100644
b1dca6
--- a/elf/dl-load.c
b1dca6
+++ b/elf/dl-load.c
b1dca6
@@ -682,7 +682,7 @@ cache_rpath (struct link_map *l,
b1dca6
 
b1dca6
 
b1dca6
 void
b1dca6
-_dl_init_paths (const char *llp)
b1dca6
+_dl_init_paths (const char *llp, const char *source)
b1dca6
 {
b1dca6
   size_t idx;
b1dca6
   const char *strp;
b1dca6
@@ -820,7 +820,7 @@ _dl_init_paths (const char *llp)
b1dca6
 	}
b1dca6
 
b1dca6
       (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
b1dca6
-			   "LD_LIBRARY_PATH", NULL, l);
b1dca6
+			   source, NULL, l);
b1dca6
 
b1dca6
       if (env_path_list.dirs[0] == NULL)
b1dca6
 	{
b1dca6
diff --git a/elf/dl-main.h b/elf/dl-main.h
b1dca6
index b01f433f9c8d9e1a..79c9c40056504f80 100644
b1dca6
--- a/elf/dl-main.h
b1dca6
+++ b/elf/dl-main.h
b1dca6
@@ -74,6 +74,9 @@ struct dl_main_state
b1dca6
   /* The library search path.  */
b1dca6
   const char *library_path;
b1dca6
 
b1dca6
+  /* Where library_path comes from.  LD_LIBRARY_PATH or --library-path.  */
b1dca6
+  const char *library_path_source;
b1dca6
+
b1dca6
   /* The list preloaded objects from LD_PRELOAD.  */
b1dca6
   const char *preloadlist;
b1dca6
 
b1dca6
@@ -94,7 +97,7 @@ struct dl_main_state
b1dca6
 static inline void
b1dca6
 call_init_paths (const struct dl_main_state *state)
b1dca6
 {
b1dca6
-  _dl_init_paths (state->library_path);
b1dca6
+  _dl_init_paths (state->library_path, state->library_path_source);
b1dca6
 }
b1dca6
 
b1dca6
 /* Print ld.so usage information and exit.  */
b1dca6
diff --git a/elf/dl-support.c b/elf/dl-support.c
b1dca6
index ef5455b91c17ca30..fb9672367f8d6abd 100644
b1dca6
--- a/elf/dl-support.c
b1dca6
+++ b/elf/dl-support.c
b1dca6
@@ -315,7 +315,7 @@ _dl_non_dynamic_init (void)
b1dca6
 
b1dca6
   /* Initialize the data structures for the search paths for shared
b1dca6
      objects.  */
b1dca6
-  _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
b1dca6
+  _dl_init_paths (getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH");
b1dca6
 
b1dca6
   /* Remember the last search directory added at startup.  */
b1dca6
   _dl_init_all_dirs = GL(dl_all_dirs);
b1dca6
diff --git a/elf/rtld.c b/elf/rtld.c
b1dca6
index a12a56b550bbc837..8e91cee41b62b894 100644
b1dca6
--- a/elf/rtld.c
b1dca6
+++ b/elf/rtld.c
b1dca6
@@ -284,6 +284,7 @@ dl_main_state_init (struct dl_main_state *state)
b1dca6
 {
b1dca6
   audit_list_init (&state->audit_list);
b1dca6
   state->library_path = NULL;
b1dca6
+  state->library_path_source = NULL;
b1dca6
   state->preloadlist = NULL;
b1dca6
   state->preloadarg = NULL;
b1dca6
   state->mode = rtld_mode_normal;
b1dca6
@@ -1197,6 +1198,7 @@ dl_main (const ElfW(Phdr) *phdr,
b1dca6
 		 && _dl_argc > 2)
b1dca6
 	  {
b1dca6
 	    state.library_path = _dl_argv[2];
b1dca6
+	    state.library_path_source = "--library-path";
b1dca6
 
b1dca6
 	    _dl_skip_args += 2;
b1dca6
 	    _dl_argc -= 2;
b1dca6
@@ -2640,6 +2642,7 @@ process_envvars (struct dl_main_state *state)
b1dca6
 	      && memcmp (envline, "LIBRARY_PATH", 12) == 0)
b1dca6
 	    {
b1dca6
 	      state->library_path = &envline[13];
b1dca6
+	      state->library_path_source = "LD_LIBRARY_PATH";
b1dca6
 	      break;
b1dca6
 	    }
b1dca6
 
b1dca6
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
b1dca6
index 4aa28b0229e0b339..aa006afafaf46dee 100644
b1dca6
--- a/sysdeps/generic/ldsodefs.h
b1dca6
+++ b/sysdeps/generic/ldsodefs.h
b1dca6
@@ -1044,8 +1044,10 @@ rtld_hidden_proto (_dl_debug_state)
b1dca6
 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
b1dca6
      attribute_hidden;
b1dca6
 
b1dca6
-/* Initialize the basic data structure for the search paths.  */
b1dca6
-extern void _dl_init_paths (const char *library_path) attribute_hidden;
b1dca6
+/* Initialize the basic data structure for the search paths.  SOURCE
b1dca6
+   is either "LD_LIBRARY_PATH" or "--library-path".  */
b1dca6
+extern void _dl_init_paths (const char *library_path, const char *source)
b1dca6
+  attribute_hidden;
b1dca6
 
b1dca6
 /* Gather the information needed to install the profiling tables and start
b1dca6
    the timers.  */