1 /* $OpenBSD: test1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */
2
3 /*
4 * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <dlfcn.h>
20 #include <err.h>
21 #include <stdio.h>
22
23 int check1, check2;
24
25 int
main()26 main()
27 {
28 void *libgd1, *libgd2;
29 void (*gd_test)();
30 int i;
31
32 for (i=0; i < 50; i++) {
33 check1 = check2 = 1;
34
35 libgd1 = dlopen(LIBGD1, RTLD_LAZY);
36 if (libgd1 == NULL)
37 errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD1);
38
39 gd_test = (void (*)())dlsym(libgd1, "gd_test1");
40 if (gd_test == NULL)
41 errx(1, "dlsym(libgd1, \"gd_test1\") FAILED\n");
42
43 (*gd_test)();
44
45 libgd2 = dlopen(LIBGD2, RTLD_LAZY);
46 if (libgd2 == NULL)
47 errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD2);
48
49 gd_test = (void (*)())dlsym(libgd2, "gd_test2");
50 if (gd_test == NULL)
51 errx(1, "dlsym(libgd2, \"gd_test2\") FAILED\n");
52
53 (*gd_test)();
54
55 dlclose(libgd1);
56 dlclose(libgd2);
57
58 if (check1 || check2)
59 errx(1, "global destructors not called\n");
60 }
61
62 return (0);
63 }
64