1 /* $OpenBSD: main.c,v 1.2 2005/09/16 23:30:25 kurt Exp $ */
2
3 /*
4 * Copyright (c) 2005 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 <stdio.h>
21 #include "aa.h"
22
23 /*
24 * Verifies dlsym works as expected when called from the main executable.
25 * libaa and libc are in the main object group, so their symbols are visable.
26 */
27 int
main()28 main()
29 {
30 int ret = 0;
31 void *exe_handle = dlopen(NULL, RTLD_LAZY);
32
33 if (dlsym(RTLD_DEFAULT, "aaSymbol") == NULL) {
34 printf("dlsym(RTLD_DEFAULT, \"aaSymbol\") FAILED\n");
35 ret = 1;
36 }
37
38 if (dlsym(RTLD_SELF, "aaSymbol") == NULL) {
39 printf("dlsym(RTLD_SELF, \"aaSymbol\") FAILED\n");
40 ret = 1;
41 }
42
43 if (dlsym(RTLD_NEXT, "aaSymbol") == NULL) {
44 printf("dlsym(RTLD_NEXT, \"aaSymbol\") FAILED\n");
45 ret = 1;
46 }
47
48 if (dlsym(NULL, "aaSymbol") == NULL) {
49 printf("dlsym(RTLD_NEXT, \"aaSymbol\") FAILED\n");
50 ret = 1;
51 }
52
53 if (dlsym(exe_handle, "aaSymbol") == NULL) {
54 printf("dlsym(exe_handle, \"aaSymbol\") FAILED\n");
55 ret = 1;
56 }
57
58 dlclose(exe_handle);
59
60 return (ret);
61 }
62