elf: Record whether paths come from LD_LIBRARY_PATH or --library-path
authorFlorian Weimer <fweimer@redhat.com>
Thu, 8 Oct 2020 08:57:10 +0000 (10:57 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 8 Oct 2020 12:29:49 +0000 (14:29 +0200)
This allows more precise LD_DEBUG diagnostics.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/dl-load.c
elf/dl-main.h
elf/dl-support.c
elf/rtld.c
sysdeps/generic/ldsodefs.h

index 5ba117d..5fbb8c9 100644 (file)
@@ -682,7 +682,7 @@ cache_rpath (struct link_map *l,
 
 
 void
-_dl_init_paths (const char *llp)
+_dl_init_paths (const char *llp, const char *source)
 {
   size_t idx;
   const char *strp;
@@ -820,7 +820,7 @@ _dl_init_paths (const char *llp)
        }
 
       (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
-                          "LD_LIBRARY_PATH", NULL, l);
+                          source, NULL, l);
 
       if (env_path_list.dirs[0] == NULL)
        {
index b01f433..79c9c40 100644 (file)
@@ -74,6 +74,9 @@ struct dl_main_state
   /* The library search path.  */
   const char *library_path;
 
+  /* Where library_path comes from.  LD_LIBRARY_PATH or --library-path.  */
+  const char *library_path_source;
+
   /* The list preloaded objects from LD_PRELOAD.  */
   const char *preloadlist;
 
@@ -94,7 +97,7 @@ struct dl_main_state
 static inline void
 call_init_paths (const struct dl_main_state *state)
 {
-  _dl_init_paths (state->library_path);
+  _dl_init_paths (state->library_path, state->library_path_source);
 }
 
 /* Print ld.so usage information and exit.  */
index 7704c10..afbc94d 100644 (file)
@@ -323,7 +323,7 @@ _dl_non_dynamic_init (void)
 
   /* Initialize the data structures for the search paths for shared
      objects.  */
-  _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
+  _dl_init_paths (getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH");
 
   /* Remember the last search directory added at startup.  */
   _dl_init_all_dirs = GL(dl_all_dirs);
index ee5bf17..c0609e4 100644 (file)
@@ -286,6 +286,7 @@ dl_main_state_init (struct dl_main_state *state)
 {
   audit_list_init (&state->audit_list);
   state->library_path = NULL;
+  state->library_path_source = NULL;
   state->preloadlist = NULL;
   state->preloadarg = NULL;
   state->mode = rtld_mode_normal;
@@ -1203,6 +1204,7 @@ dl_main (const ElfW(Phdr) *phdr,
                 && _dl_argc > 2)
          {
            state.library_path = _dl_argv[2];
+           state.library_path_source = "--library-path";
 
            _dl_skip_args += 2;
            _dl_argc -= 2;
@@ -2655,6 +2657,7 @@ process_envvars (struct dl_main_state *state)
              && memcmp (envline, "LIBRARY_PATH", 12) == 0)
            {
              state->library_path = &envline[13];
+             state->library_path_source = "LD_LIBRARY_PATH";
              break;
            }
 
index 7cb1fcc..510a2f6 100644 (file)
@@ -1046,8 +1046,10 @@ rtld_hidden_proto (_dl_debug_state)
 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
      attribute_hidden;
 
-/* Initialize the basic data structure for the search paths.  */
-extern void _dl_init_paths (const char *library_path) attribute_hidden;
+/* Initialize the basic data structure for the search paths.  SOURCE
+   is either "LD_LIBRARY_PATH" or "--library-path".  */
+extern void _dl_init_paths (const char *library_path, const char *source)
+  attribute_hidden;
 
 /* Gather the information needed to install the profiling tables and start
    the timers.  */