source: branches/libc-0.6/src/libctests/glibc/elf/tst-tls6.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1#include <dlfcn.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5#include <link.h>
6#include <tls.h>
7
8
9#define TEST_FUNCTION do_test ()
10static int
11do_test (void)
12{
13#ifdef USE_TLS
14 static const char modname[] = "tst-tlsmod2.so";
15 int result = 0;
16 int *foop;
17 int *foop2;
18 int (*fp) (int, int *);
19 void *h;
20 int i;
21 int modid = -1;
22
23 for (i = 0; i < 10; ++i)
24 {
25 h = dlopen (modname, RTLD_LAZY);
26 if (h == NULL)
27 {
28 printf ("cannot open '%s': %s\n", modname, dlerror ());
29 exit (1);
30 }
31
32 /* Dirty test code here: we peek into a private data structure.
33 We make sure that the module gets assigned the same ID every
34 time. The value of the first round is used. */
35 if (modid == -1)
36 modid = ((struct link_map *) h)->l_tls_modid;
37 else if (((struct link_map *) h)->l_tls_modid != modid)
38 {
39 printf ("round %d: modid now %zd, initially %d\n",
40 i, ((struct link_map *) h)->l_tls_modid, modid);
41 result = 1;
42 }
43
44 foop = dlsym (h, "foo");
45 if (foop == NULL)
46 {
47 printf ("cannot get symbol 'foo': %s\n", dlerror ());
48 exit (1);
49 }
50
51 *foop = 42 + i;
52
53 fp = dlsym (h, "in_dso");
54 if (fp == NULL)
55 {
56 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
57 exit (1);
58 }
59
60 result |= fp (42 + i, foop);
61
62 foop2 = dlsym (h, "foo");
63 if (foop2 == NULL)
64 {
65 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
66 exit (1);
67 }
68
69 if (foop != foop2)
70 {
71 puts ("address of 'foo' different the second time");
72 result = 1;
73 }
74 else if (*foop != 16)
75 {
76 puts ("foo != 16");
77 result = 1;
78 }
79
80 dlclose (h);
81 }
82
83 return result;
84#else
85 return 0;
86#endif
87}
88
89
90#include "../test-skeleton.c"
Note: See TracBrowser for help on using the repository browser.