summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-01-25 17:56:00 -0500
committerRich Felker <dalias@aerifal.cx>2016-01-25 18:44:09 -0500
commita4fbc82c8e2a311baa0c6b5a4a4cdbb6c8f66edb (patch)
treeeb368017345db9128a508f4222794cd7fe6763c9
parente7a1118984d071fdd65c486c52271ad4f1561fb8 (diff)
downloadmusl-a4fbc82c8e2a311baa0c6b5a4a4cdbb6c8f66edb.tar.gz
musl-a4fbc82c8e2a311baa0c6b5a4a4cdbb6c8f66edb.tar.bz2
musl-a4fbc82c8e2a311baa0c6b5a4a4cdbb6c8f66edb.tar.xz
musl-a4fbc82c8e2a311baa0c6b5a4a4cdbb6c8f66edb.zip
factor dlerror and error-setting code out of dynlink.c
the ultimate goal of this change is to get all code used in libc.a out of dynlink.c, so that the dynamic linker code can be moved to its own tree and object files in the src tree can all be shared between libc.a and libc.so.
-rw-r--r--src/ldso/dlerror.c52
-rw-r--r--src/ldso/dynlink.c35
2 files changed, 55 insertions, 32 deletions
diff --git a/src/ldso/dlerror.c b/src/ldso/dlerror.c
new file mode 100644
index 00000000..588828e9
--- /dev/null
+++ b/src/ldso/dlerror.c
@@ -0,0 +1,52 @@
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include "pthread_impl.h"
+
+char *dlerror()
+{
+ pthread_t self = __pthread_self();
+ if (!self->dlerror_flag) return 0;
+ self->dlerror_flag = 0;
+ char *s = self->dlerror_buf;
+ if (s == (void *)-1)
+ return "Dynamic linker failed to allocate memory for error message";
+ else
+ return s;
+}
+
+void __dl_thread_cleanup(void)
+{
+ pthread_t self = __pthread_self();
+ if (self->dlerror_buf != (void *)-1)
+ free(self->dlerror_buf);
+}
+
+__attribute__((__visibility__("hidden")))
+void __dl_vseterr(const char *fmt, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+ pthread_t self = __pthread_self();
+ if (self->dlerror_buf != (void *)-1)
+ free(self->dlerror_buf);
+ size_t len = vsnprintf(0, 0, fmt, ap2);
+ va_end(ap2);
+ char *buf = malloc(len+1);
+ if (buf) {
+ vsnprintf(buf, len+1, fmt, ap);
+ } else {
+ buf = (void *)-1;
+ }
+ self->dlerror_buf = buf;
+ self->dlerror_flag = 1;
+}
+
+__attribute__((__visibility__("hidden")))
+void __dl_seterr(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ __dl_vseterr(fmt, ap);
+ va_end(ap);
+}
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index b42b3360..492c22a8 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -1945,29 +1945,13 @@ int __dlinfo(void *dso, int req, void *res)
return 0;
}
-char *dlerror()
-{
- pthread_t self = __pthread_self();
- if (!self->dlerror_flag) return 0;
- self->dlerror_flag = 0;
- char *s = self->dlerror_buf;
- if (s == (void *)-1)
- return "Dynamic linker failed to allocate memory for error message";
- else
- return s;
-}
-
int dlclose(void *p)
{
return invalid_dso_handle(p);
}
-void __dl_thread_cleanup(void)
-{
- pthread_t self = __pthread_self();
- if (self->dlerror_buf != (void *)-1)
- free(self->dlerror_buf);
-}
+__attribute__((__visibility__("hidden")))
+void __dl_vseterr(const char *, va_list);
static void error(const char *fmt, ...)
{
@@ -1982,19 +1966,6 @@ static void error(const char *fmt, ...)
return;
}
#endif
- pthread_t self = __pthread_self();
- if (self->dlerror_buf != (void *)-1)
- free(self->dlerror_buf);
- size_t len = vsnprintf(0, 0, fmt, ap);
+ __dl_vseterr(fmt, ap);
va_end(ap);
- char *buf = malloc(len+1);
- if (buf) {
- va_start(ap, fmt);
- vsnprintf(buf, len+1, fmt, ap);
- va_end(ap);
- } else {
- buf = (void *)-1;
- }
- self->dlerror_buf = buf;
- self->dlerror_flag = 1;
}