diff mbox series

[06/28] elf: Record whether paths come from LD_LIBRARY_PATH or --library-path

Message ID ab35cf9efe79980a59e58ed59fdadcd8084941be.1601569371.git.fweimer@redhat.com
State Committed
Headers show
Series glibc-hwcaps support | expand

Commit Message

Florian Weimer Oct. 1, 2020, 4:32 p.m. UTC
This allows more precise diagnostics.
---
 elf/dl-load.c              | 4 ++--
 elf/dl-main.h              | 5 ++++-
 elf/dl-support.c           | 2 +-
 elf/rtld.c                 | 3 +++
 sysdeps/generic/ldsodefs.h | 6 ++++--
 5 files changed, 14 insertions(+), 6 deletions(-)

Comments

Adhemerval Zanella Oct. 7, 2020, 4:39 p.m. UTC | #1
On 01/10/2020 13:32, Florian Weimer via Libc-alpha wrote:
> This allows more precise diagnostics.

I haven't check the rest of the patchset to see how this information
would be used, but one option might to define the source with an 
enumeration instead of an string (to fully use a type and avoid wrong
usage).

In either case, patch looks good thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  elf/dl-load.c              | 4 ++--
>  elf/dl-main.h              | 5 ++++-
>  elf/dl-support.c           | 2 +-
>  elf/rtld.c                 | 3 +++
>  sysdeps/generic/ldsodefs.h | 6 ++++--
>  5 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index 5ba117d597..5fbb8c9ad4 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -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)
>  	{

Ok.

> diff --git a/elf/dl-main.h b/elf/dl-main.h
> index 681f366871..68dd27d0d7 100644
> --- a/elf/dl-main.h
> +++ b/elf/dl-main.h
> @@ -71,6 +71,9 @@ struct dl_main_state
>    /* The library search path.  */
>    const char *library_path;
>  
> +  /* Where library_path comes from.  LD_LIBRARY_PATH or --library.  */
> +  const char *library_path_source;
> +
>    /* The list preloaded objects from LD_PRELOAD.  */
>    const char *preloadlist;
>  

Ok.

> @@ -91,7 +94,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.  */

Ok.

> diff --git a/elf/dl-support.c b/elf/dl-support.c
> index 7704c101c5..afbc94df54 100644
> --- a/elf/dl-support.c
> +++ b/elf/dl-support.c
> @@ -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);

Ok.

> diff --git a/elf/rtld.c b/elf/rtld.c
> index f3e1791e2f..d11fe22b83 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -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 = 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;
>  	    }
>  

Ok.

> diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
> index 7cb1fccc80..510a2f6841 100644
> --- a/sysdeps/generic/ldsodefs.h
> +++ b/sysdeps/generic/ldsodefs.h
> @@ -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.  */
> 

Ok.
Florian Weimer Oct. 7, 2020, 4:49 p.m. UTC | #2
* Adhemerval Zanella via Libc-alpha:

> On 01/10/2020 13:32, Florian Weimer via Libc-alpha wrote:
>> This allows more precise diagnostics.
>
> I haven't check the rest of the patchset to see how this information
> would be used, but one option might to define the source with an 
> enumeration instead of an string (to fully use a type and avoid wrong
> usage).

It's immediately used by the existing LD_DEBUG diagnostics (those that
currently show LD_LIBRARY_PATH, RUNPATH, RPATH).

>> +  /* Where library_path comes from.  LD_LIBRARY_PATH or --library.  */

>> +	    state.library_path_source = "--library_path";

I'm going to fix those typos before comitting.
diff mbox series

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 5ba117d597..5fbb8c9ad4 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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)
 	{
diff --git a/elf/dl-main.h b/elf/dl-main.h
index 681f366871..68dd27d0d7 100644
--- a/elf/dl-main.h
+++ b/elf/dl-main.h
@@ -71,6 +71,9 @@  struct dl_main_state
   /* The library search path.  */
   const char *library_path;
 
+  /* Where library_path comes from.  LD_LIBRARY_PATH or --library.  */
+  const char *library_path_source;
+
   /* The list preloaded objects from LD_PRELOAD.  */
   const char *preloadlist;
 
@@ -91,7 +94,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.  */
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 7704c101c5..afbc94df54 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -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);
diff --git a/elf/rtld.c b/elf/rtld.c
index f3e1791e2f..d11fe22b83 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -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 = 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;
 	    }
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 7cb1fccc80..510a2f6841 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -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.  */