add tls_init_dlopen test and fix tls_align_dlopen.mk so it is run properly
authorSzabolcs Nagy <nsz@port70.net>
Mon, 27 Jan 2014 13:17:28 +0000 (14:17 +0100)
committerSzabolcs Nagy <nsz@port70.net>
Mon, 27 Jan 2014 13:17:28 +0000 (14:17 +0100)
src/functional/tls_align_dlopen.c
src/functional/tls_align_dlopen.mk
src/functional/tls_init_dlopen.c [new file with mode: 0644]
src/functional/tls_init_dlopen.mk [new file with mode: 0644]
src/functional/tls_init_dso.c [new file with mode: 0644]
src/functional/tls_init_dso.mk [new file with mode: 0644]

index 709964e..77a7b93 100644 (file)
@@ -12,7 +12,7 @@ int main()
                unsigned long addr;
        } *t;
 
-       h = dlopen("./tls_align_dso.so", RTLD_LAZY);
+       h = dlopen("src/functional/tls_align_dso.so", RTLD_LAZY);
        if (!h)
                t_error("dlopen failed\n");
        t = dlsym(h, "t");
index bd5b740..6632623 100644 (file)
@@ -1,2 +1,2 @@
-$(N).BINS=$(B)/$(N).exe
+$(N).BINS:=$(B)/$(N).exe
 $(B)/$(N).err: $(B)/$(D)/tls_align_dso.so
diff --git a/src/functional/tls_init_dlopen.c b/src/functional/tls_init_dlopen.c
new file mode 100644 (file)
index 0000000..ef3d10a
--- /dev/null
@@ -0,0 +1,24 @@
+#include <string.h>
+#include <dlfcn.h>
+#include "test.h"
+
+int main()
+{
+       void *h;
+       char *(*f)(void);
+       char *s;
+
+       h = dlopen("src/functional/tls_init_dso.so", RTLD_NOW|RTLD_GLOBAL);
+       if (!h)
+               t_error("dlopen failed: %s\n", dlerror());
+       f = dlsym(h, "gettls");
+       if (!f)
+               t_error("dlsym failed: %s\n", dlerror());
+       s = f();
+       if (!s)
+               t_error("tls was not initialized at dlopen\n");
+       if (strcmp(s, "foobar")!=0)
+               t_error("tls was not initialized correctly at dlopen (got \"%s\", want \"foobar\"\n", s);
+
+       return t_status;
+}
diff --git a/src/functional/tls_init_dlopen.mk b/src/functional/tls_init_dlopen.mk
new file mode 100644 (file)
index 0000000..f6435b8
--- /dev/null
@@ -0,0 +1,2 @@
+$(N).BINS:=$(B)/$(N).exe
+$(B)/$(N).err: $(B)/$(D)/tls_init_dso.so
diff --git a/src/functional/tls_init_dso.c b/src/functional/tls_init_dso.c
new file mode 100644 (file)
index 0000000..eff1a58
--- /dev/null
@@ -0,0 +1,8 @@
+static char buf[] = "foobar";
+__thread char *tls = buf;
+
+char *gettls()
+{
+       return tls;
+}
+
diff --git a/src/functional/tls_init_dso.mk b/src/functional/tls_init_dso.mk
new file mode 100644 (file)
index 0000000..2b1c25b
--- /dev/null
@@ -0,0 +1,2 @@
+$(N).BINS:=
+$(N).LIBS:=$(B)/$(N).so