adapt static dl_iterate_phdr not to depend on !defined(SHARED)
[oweals/musl.git] / src / ldso / dynlink.c
index 8d793f26b8914c311ce54756483486b6292a2c04..e328679b877e913710de7cd0b353296e9eb36864 100644 (file)
@@ -1,3 +1,4 @@
+#ifdef SHARED
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
@@ -23,8 +24,6 @@
 
 static void error(const char *, ...);
 
-#ifdef SHARED
-
 #define MAXP2(a,b) (-(-(a)&-(b)))
 #define ALIGN(x,y) ((x)+(y)-1 & -(y))
 
@@ -1733,7 +1732,8 @@ end:
        return p;
 }
 
-static int invalid_dso_handle(void *h)
+__attribute__((__visibility__("hidden")))
+int __dl_invalid_handle(void *h)
 {
        struct dso *p;
        for (p=head; p; p=p->next) if (h==p) return 0;
@@ -1788,7 +1788,7 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
                        return def.dso->funcdescs + (def.sym - def.dso->syms);
                return laddr(def.dso, def.sym->st_value);
        }
-       if (invalid_dso_handle(p))
+       if (__dl_invalid_handle(p))
                return 0;
        if ((ght = p->ghashtab)) {
                gh = gnu_hash(s);
@@ -1912,39 +1912,6 @@ int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void
        }
        return ret;
 }
-#else
-static int invalid_dso_handle(void *h)
-{
-       error("Invalid library handle %p", (void *)h);
-       return 1;
-}
-void *dlopen(const char *file, int mode)
-{
-       error("Dynamic loading not supported");
-       return 0;
-}
-void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
-{
-       error("Symbol not found: %s", s);
-       return 0;
-}
-#endif
-
-int __dlinfo(void *dso, int req, void *res)
-{
-       if (invalid_dso_handle(dso)) return -1;
-       if (req != RTLD_DI_LINKMAP) {
-               error("Unsupported request %d", req);
-               return -1;
-       }
-       *(struct link_map **)res = dso;
-       return 0;
-}
-
-int dlclose(void *p)
-{
-       return invalid_dso_handle(p);
-}
 
 __attribute__((__visibility__("hidden")))
 void __dl_vseterr(const char *, va_list);
@@ -1953,7 +1920,6 @@ static void error(const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
-#ifdef SHARED
        if (!runtime) {
                vdprintf(2, fmt, ap);
                dprintf(2, "\n");
@@ -1961,7 +1927,7 @@ static void error(const char *fmt, ...)
                va_end(ap);
                return;
        }
-#endif
        __dl_vseterr(fmt, ap);
        va_end(ap);
 }
+#endif