Subject: dlerror returns a string for even when dlsym succeeds?
To: 386 Port NetBSD <port-i386@netbsd.org>
From: Scott Presnell <srp@zgi.com>
List: port-i386
Date: 03/20/2000 08:42:44
Hi Folks,
When using dlsym() to get a symbol address, and that lookup
succeeds (i.e. there was no error), dlerror() will still return a
string based on error 0: "Undefined error: 0"
Here is a code snippet that represents the logic often used
(this is from the Utah glx project):
static int any_error;
static void *my_dlsym(void *handle, const char *name)
{
void *tmp = dlsym(handle, name);
char *error;
if ((error = dlerror()) != 0) {
fprintf( stderr, "%s\n", error );
any_error = 1;
return 0;
}
return tmp;
}
This code fails even if the symbol is found because dlerror returns
something other than NULL. From the man page for dlerror, it
appears that dlerror should return NULL after a successful call
to dlsym. But it doesn't... and so I hack the code to check
whether tmp was indeed NULL.
This is the second time I've come across this, I've also seen this
situation/problem in the gmodule subsystem of glib-1.2.7, but....
My reading of csu/common_aout/common.c seems to indicate that this
cannot happen...
Whats the deal here? Has anyone else come across this? Thanks.
- Scott Presnell (srp@zgi.com)
(I'm running NetBSD 1.4.1 on a Pentium Pro, custom kernel, but no mods
to the system libraries).
csu/common_aout/common.c:
char *
dlerror()
{
int error;
if ((*ld_entry) == NULL ||
(*(*ld_entry)->dlctl)(NULL, DL_GETERRNO, &error) == -1)
return "Service unavailable";
return ((char *)(error == 0 ? NULL : strerror(error)));
}