summaryrefslogtreecommitdiff
path: root/libexec/ld.so/dlfcn.c
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2001-09-15 20:44:53 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2001-09-15 20:44:53 +0000
commit5dec863bc219a380e5985bc401e2a06dcdf291a2 (patch)
treea2ab5de45f2dcd53e7048b41f5e297dcf3b5c313 /libexec/ld.so/dlfcn.c
parentf252809cba0bb3295a7c736a41357418fdabe5f3 (diff)
Some cleanup in loader.c, initialize the symbol pointer with NULL,
add a missing initialization of the sym pointer. Add some functionality which allows a program to open itself dlopen(NULL), so that it can then look up symbols in the executable itself. Note that the program can only access exported variables, either by exporting all variables with the ld option -E or externally referrenced. Fix bug in dlsym() where it would return failure when looking up symbols. It was testing the offset of the found symbol, not if the symbol was found.
Diffstat (limited to 'libexec/ld.so/dlfcn.c')
-rw-r--r--libexec/ld.so/dlfcn.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c
index e42d7b895de..1749cb75f8c 100644
--- a/libexec/ld.so/dlfcn.c
+++ b/libexec/ld.so/dlfcn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dlfcn.c,v 1.7 2001/08/09 02:42:12 drahn Exp $ */
+/* $OpenBSD: dlfcn.c,v 1.8 2001/09/15 20:44:52 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -57,6 +57,9 @@ dlopen(const char *libname, int how)
elf_object_t *dynobj;
Elf_Dyn *dynp;
+ if (libname == NULL) {
+ return NULL;
+ }
DL_DEB(("loading: %s\n", libname));
object = _dl_load_shlib(libname, _dl_objects, OBJTYPE_DLO);
@@ -87,7 +90,7 @@ dlopen(const char *libname, int how)
continue;
}
libname = dynobj->dyn.strtab + dynp->d_un.d_val;
- depobj = _dl_load_shlib(libname, dynobj, OBJTYPE_DLO);
+ depobj = _dl_load_shlib(libname, dynobj, OBJTYPE_LIB);
if (!depobj) {
_dl_exit(4);
}
@@ -119,8 +122,18 @@ dlsym(void *handle, const char *name)
elf_object_t *object;
elf_object_t *dynobj;
void *retval;
- const Elf_Sym *sym = 0;
-
+ const Elf_Sym *sym = NULL;
+
+ if (handle == NULL) {
+ object = _dl_objects;
+ retval = (void *)_dl_find_symbol(name, object, &sym, 1, 1);
+ if (sym != NULL) {
+ retval += sym->st_value;
+ } else {
+ _dl_errno = DL_NO_SYMBOL;
+ }
+ return retval;
+ }
object = (elf_object_t *)handle;
dynobj = _dl_objects;
while (dynobj && dynobj != object) {
@@ -132,7 +145,7 @@ dlsym(void *handle, const char *name)
}
retval = (void *)_dl_find_symbol(name, object, &sym, 1, 1);
- if (retval) {
+ if (sym != NULL) {
retval += sym->st_value;
} else {
_dl_errno = DL_NO_SYMBOL;