This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug dynamic-link/19509] New: dlsym, dlvsym do not report errors through dlerror when using RTLD_NEXT


https://sourceware.org/bugzilla/show_bug.cgi?id=19509

            Bug ID: 19509
           Summary: dlsym, dlvsym do not report errors through dlerror
                    when using RTLD_NEXT
           Product: glibc
           Version: 2.24
            Status: NEW
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: fweimer at redhat dot com
  Target Milestone: ---

This:

#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>

int
main (void)
{
  printf ("dlsym (RTLD_DEFAULT, \"no_such_symbol\"): %p\n",
          dlsym (RTLD_DEFAULT, "no_such_symbol"));
  printf ("dlerror (): %s\n", dlerror ());
  printf ("dlsym (RTLD_NEXT, \"no_such_symbol\"): %p\n",
          dlsym (RTLD_NEXT, "no_such_symbol"));
  printf ("dlerror (): %s\n", dlerror ());
  return 0;
}

outputs:

dlsym (RTLD_DEFAULT, "no_such_symbol"): (nil)
dlerror (): ./a.out: undefined symbol: no_such_symbol
dlsym (RTLD_NEXT, "no_such_symbol"): (nil)
dlerror (): (null)

This is unexpected.

In _dl_lookup_symbol_x, the error is deliberately masked here for the RTLD_NEXT
case (where skip_map == NULL):

    858   if (__glibc_unlikely (current_value.s == NULL))
    859     {
    860       if ((*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
    861           && skip_map == NULL
    862           && !(GLRO(dl_debug_mask) & DL_DEBUG_UNUSED))
    863         {
    864           /* We could find no value for a strong reference.  */
    865           const char *reference_name = undef_map ? undef_map->l_name :
"";
    866           const char *versionstr = version ? ", version " : "";
    867           const char *versionname = (version && version->name
    868                                      ? version->name : "");
    869 
    870           /* XXX We cannot translate the message.  */
    871           _dl_signal_cerror (0, DSO_FILENAME (reference_name),
    872                              N_("symbol lookup error"),
    873                              make_string ("undefined symbol: ",
undef_name,
    874                                           versionstr, versionname));
    875         }
    876       *ref = NULL;
    877       return 0;
    878     }

This was carried over from _dl_lookup_symbol_skip when the separate function
was removed in upstream commit  bdf4a4f1eabb2e085b0610b53bb37b5263f4728d.  The
original implementation of _dl_lookup_symbol_skip in commit
84384f5b6aaa622236ada8c9a7ff51f40b91fc20 did not have error reporting, either. 
Why this is so is unclear to me.

Solaris documentation implies that the dlerror return value changes if dlsym
with RTLD_NEXT is unsuccessful:

  <https://docs.oracle.com/cd/E19683-01/816-1386/chapter3-24/index.html>

(Under âUsing Interpositionâ.)

I think we should change glibc behavior regarding error reporting (although
RTLD_NEXT will still behave differently than other systems, see bug 1319.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]