mirror of
https://github.com/fluencelabs/musl
synced 2025-05-30 16:11:40 +00:00
make dlerror produce informative results
note that dlerror is specified to be non-thread-safe, so no locking is performed on the error flag or message aside from the rwlock already held by dlopen or dlsym. if 2 invocations of dlsym are generating errors at the same time, they could clobber each other's results, but the resulting string, albeit corrupt, will still be null-terminated. any use of dlerror in such a situation could not be expected to give meaningful results anyway.
This commit is contained in:
parent
90da74ef51
commit
a5d10eb1f5
@ -18,6 +18,7 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
static int errflag;
|
static int errflag;
|
||||||
|
static char errbuf[128];
|
||||||
|
|
||||||
#ifdef __PIC__
|
#ifdef __PIC__
|
||||||
|
|
||||||
@ -142,8 +143,11 @@ static void do_relocs(unsigned char *base, size_t *rel, size_t rel_size, size_t
|
|||||||
ctx = IS_COPY(type) ? dso->next : dso;
|
ctx = IS_COPY(type) ? dso->next : dso;
|
||||||
sym_val = (size_t)find_sym(ctx, name, IS_PLT(type));
|
sym_val = (size_t)find_sym(ctx, name, IS_PLT(type));
|
||||||
if (!sym_val && sym->st_info>>4 != STB_WEAK) {
|
if (!sym_val && sym->st_info>>4 != STB_WEAK) {
|
||||||
|
snprintf(errbuf, sizeof errbuf,
|
||||||
|
"Error relocating %s: %s: symbol not found",
|
||||||
|
dso->name, name);
|
||||||
if (runtime) longjmp(rtld_fail, 1);
|
if (runtime) longjmp(rtld_fail, 1);
|
||||||
dprintf(2, "%s: symbol not found\n", name);
|
dprintf(2, "%s\n", errbuf);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
sym_size = sym->st_size;
|
sym_size = sym->st_size;
|
||||||
@ -405,9 +409,11 @@ static void load_deps(struct dso *p)
|
|||||||
if (p->dynv[i] != DT_NEEDED) continue;
|
if (p->dynv[i] != DT_NEEDED) continue;
|
||||||
dep = load_library(p->strings + p->dynv[i+1]);
|
dep = load_library(p->strings + p->dynv[i+1]);
|
||||||
if (!dep) {
|
if (!dep) {
|
||||||
if (runtime) longjmp(rtld_fail, 1);
|
snprintf(errbuf, sizeof errbuf,
|
||||||
dprintf(2, "%s: %m (needed by %s)\n",
|
"Error loading shared library %s: %m (needed by %s)",
|
||||||
p->strings + p->dynv[i+1], p->name);
|
p->strings + p->dynv[i+1], p->name);
|
||||||
|
if (runtime) longjmp(rtld_fail, 1);
|
||||||
|
dprintf(2, "%s\n", errbuf);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
if (runtime) {
|
if (runtime) {
|
||||||
@ -634,9 +640,13 @@ void *dlopen(const char *file, int mode)
|
|||||||
tail = orig_tail;
|
tail = orig_tail;
|
||||||
tail->next = 0;
|
tail->next = 0;
|
||||||
p = 0;
|
p = 0;
|
||||||
|
errflag = 1;
|
||||||
|
goto end;
|
||||||
} else p = load_library(file);
|
} else p = load_library(file);
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
|
snprintf(errbuf, sizeof errbuf,
|
||||||
|
"Error loading shared library %s: %m", file);
|
||||||
errflag = 1;
|
errflag = 1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -694,6 +704,7 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
|
|||||||
return p->deps[i]->base + sym->st_value;
|
return p->deps[i]->base + sym->st_value;
|
||||||
}
|
}
|
||||||
errflag = 1;
|
errflag = 1;
|
||||||
|
snprintf(errbuf, sizeof errbuf, "Symbol not found: %s", s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +731,7 @@ char *dlerror()
|
|||||||
{
|
{
|
||||||
if (!errflag) return 0;
|
if (!errflag) return 0;
|
||||||
errflag = 0;
|
errflag = 0;
|
||||||
return "unknown error";
|
return errbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dlclose(void *p)
|
int dlclose(void *p)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user