[RFC] elf: fine-grained output LD_DEBUG log when symbol lookup error

Florian Weimer fweimer@redhat.com
Mon Aug 8 13:19:16 GMT 2022


* Lv Ying:

> When LD_DEBUG environment variable is set except "unused" value, symbol lookup error
> in _dl_lookup_symbol_x will output unrelated debugging information which mess up the
> "files" "libs" "reloc" log.
>
> "undefined symbol" debugging information should only output when LD_DEBUG="symbols|all".
> ---
>  elf/dl-lookup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
> index 4c86dc694e..6085c6c90c 100644
> --- a/elf/dl-lookup.c
> +++ b/elf/dl-lookup.c
> @@ -781,7 +781,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map,
>    if (__glibc_unlikely (current_value.s == NULL))
>      {
>        if ((*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
> -	  && !(GLRO(dl_debug_mask) & DL_DEBUG_UNUSED))
> +	  && (GLRO(dl_debug_mask) & DL_DEBUG_SYMBOLS))
>  	{
>  	  /* We could find no value for a strong reference.  */
>  	  const char *reference_name = undef_map ? undef_map->l_name : "";

The current code looks like this:

      if ((*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
	  && !(GLRO(dl_debug_mask) & DL_DEBUG_UNUSED))
	{
	  /* We could find no value for a strong reference.  */
	  const char *reference_name = undef_map ? undef_map->l_name : "";
	  const char *versionstr = version ? ", version " : "";
	  const char *versionname = (version && version->name
				     ? version->name : "");
	  struct dl_exception exception;
	  /* XXX We cannot translate the message.  */
	  _dl_exception_create_format
	    (&exception, DSO_FILENAME (reference_name),
	     "undefined symbol: %s%s%s",
	     undef_name, versionstr, versionname);
	  _dl_signal_cexception (0, &exception, N_("symbol lookup error"));
	  _dl_exception_free (&exception);
	}

I think in general, we want to signal an exception here, and we can't
mask that except in debug mode because it does not result in the right
behavior.

Do you have a reproducer that shows what you want to fix?

Thanks,
Florian



More information about the Libc-alpha mailing list