include dummied-out dlopen and dlsym functions for static binaries
[musl] / src / ldso / dynlink.c
index df54230..057a4cd 100644 (file)
@@ -563,10 +563,13 @@ void *__dynlink(int argc, char **argv)
                ehdr->e_phentsize, ehdr->e_phnum);
 
        /* Load preload/needed libraries, add their symbols to the global
-        * namespace, and perform all remaining relocations. */
+        * namespace, and perform all remaining relocations. The main
+        * program must be relocated LAST since it may contain copy
+        * relocations which depend on libraries' relocations. */
        if (env_preload) load_preload(env_preload);
        load_deps(app);
        make_global(app);
+       reloc_all(app->next);
        reloc_all(app);
 
        /* Switch to runtime mode: any further failures in the dynamic
@@ -671,6 +674,16 @@ void *__dlsym(void *p, const char *s, void *ra)
        pthread_rwlock_unlock(&lock);
        return res;
 }
+#else
+void *dlopen(const char *file, int mode)
+{
+       return 0;
+}
+void *__dlsym(void *p, const char *s, void *ra)
+{
+       return 0;
+}
+#endif
 
 char *dlerror()
 {
@@ -681,4 +694,3 @@ int dlclose(void *p)
 {
        return 0;
 }
-#endif