Jeff Squyres wrote:
> Since this now has me intrigued :-), I downloaded glibc and had a look
> at dlerror(). I didn't follow it all the way through, but it looks
> like it *could* be erroneous to call dlerror() without first calling
> dlopen(). Here's some code right at the top of dlerror():
>
> -----
> /* Get error string. */
> result = (struct dl_action_result *) __libc_getspecific (key);
> if (result == NULL)
> result = &last_result;
>
> /* Test whether we already returned the string. */
> if (result->returned != 0)
> -----
>
> I *think* the __libc_getspecific() thing will return 0. So result
> will == NULL, and it'll use &last_result. And last_result does not
> appear to be statically initialized. So "result->returned" could well
> generate Badness.
>
> I'm not 100% sure that's happening, but I think it is...
Very interesting. When I 'nm /lib/libdl.so.2' I see '00002d60 b
last_result', which means that last_result is in the uninitialized BSS
section. I would have thought that it would be declared in a way that
initializes static data to 0 by default. It looks like a libdl bug to
me, too, but then ...
The man page seems to imply that the library is initialized at some
point. I take that to mean 'loaded and linked', including
initialization of data. So I would consider this an outright dlerror
bug, not just an undocumented pitfall in the dl- function specs.
It's hard to believe that this kind of bug has been around for very long
or just recently was introduced. Since the man page explicitly
describes how dlerror gives the last error from any call to a dl-
function (similar to errno), who wouldn't want to call dlerror before
calling dlopen, to make sure that the error message is from the most
recent call? I would expect a lot of people to use this technique (even
if it's not absolutely necessary).
Do you know anything about BSS data? I would think that this has to be
allocated and initialized separately for each process that links to
libdl.so. The BSS data in libdl (including key, last_result, and
static_buf) can't be shared.
If the ELF linkage for BSS data requires initialization to 0, then the
problem lies in the shared library linking. Pardon me for thinking out
loud, but I don't know anything about how Linux takes care of this stuff.
--
Dick Hadsell 914-259-6320 Fax: 914-259-6499
Reply-to: hadsell_at_[hidden]
Blue Sky Studios http://www.blueskystudios.com
44 South Broadway, White Plains, NY 10601
|