Update.
[glibc.git] / elf / reldep6.c
blobbf80ec57733403f2795d723784c9618f7656ef74
1 #include <dlfcn.h>
2 #include <mcheck.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 typedef int (*fn)(void);
7 #define CHUNKS 1024
8 #define REPEAT 64
10 int
11 main (void)
13 void *h1;
14 void *h2;
15 fn **foopp;
16 fn bar, baz;
17 int i, j;
18 int n;
19 void *allocs[REPEAT][CHUNKS];
21 mtrace ();
23 /* Open the two objects. */
24 h1 = dlopen ("reldep6mod3.so", RTLD_LAZY);
25 if (h1 == NULL)
27 printf ("cannot open reldep6mod3.so: %s\n", dlerror ());
28 exit (1);
31 foopp = dlsym (h1, "foopp");
32 if (foopp == NULL)
34 printf ("cannot get address of \"foopp\": %s\n", dlerror ());
35 exit (1);
37 n = (**foopp) ();
38 if (n != 20)
40 printf ("(**foopp)() return %d, not return 20\n", n);
41 exit (1);
44 h2 = dlopen ("reldep6mod4.so", RTLD_LAZY);
45 if (h2 == NULL)
47 printf ("cannot open reldep6mod4.so: %s\n", dlerror ());
48 exit (1);
51 if (dlclose (h1) != 0)
53 printf ("closing h1 failed: %s\n", dlerror ());
54 exit (1);
57 /* Clobber memory. */
58 for (i = 0; i < REPEAT; ++i)
59 for (j = 0; j < CHUNKS; ++j)
60 allocs[i][j] = calloc (1, j + 1);
62 bar = dlsym (h2, "bar");
63 if (bar == NULL)
65 printf ("cannot get address of \"bar\": %s\n", dlerror ());
66 exit (1);
68 if (bar () != 40)
70 printf ("bar() did not return 40\n");
71 exit (1);
74 baz = dlsym (h2, "baz");
75 if (baz == NULL)
77 printf ("cannot get address of \"baz\": %s\n", dlerror ());
78 exit (1);
80 if (baz () != 31)
82 printf ("baz() did not return 31\n");
83 exit (1);
86 for (i = 0; i < REPEAT; ++i)
87 for (j = 0; j < CHUNKS; ++j)
88 free (allocs[i][j]);
90 if (dlclose (h2) != 0)
92 printf ("closing h2 failed: %s\n", dlerror ());
93 exit (1);
96 return 0;