fix a few bugs from last dynamic linking build system commit
[musl] / src / ldso / dynlink.c
index a23390e..9a0697c 100644 (file)
@@ -473,6 +473,7 @@ void *__dynlink(int argc, char **argv, size_t *got)
                *libc->prev->next = *libc;
                libc = libc->prev->next;
                if (libc->next) libc->next->prev = libc;
+               if (tail == &lib) tail = libc;
        } else {
                free_all(head);
                free(sys_path);
@@ -509,7 +510,7 @@ void *dlopen(const char *file, int mode)
        }
 
        p = load_library(file);
-       if (!p) return 0;
+       if (!p) goto end;
 
        /* First load handling */
        if (!p->deps) {
@@ -531,8 +532,8 @@ void *dlopen(const char *file, int mode)
                p->global = 1;
        }
 
+end:
        pthread_rwlock_unlock(&lock);
-
        return p;
 }
 
@@ -541,7 +542,8 @@ static void *do_dlsym(struct dso *p, const char *s)
        size_t i;
        uint32_t h;
        Sym *sym;
-       if (p == head) return find_sym(head, s, 0);
+       if (p == head || p == RTLD_DEFAULT)
+               return find_sym(head, s, 0);
        h = hash(s);
        sym = lookup(s, h, p->syms, p->hashtab, p->strings);
        if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))