1 /*	$OpenBSD: main.c,v 1.1 2005/09/19 21:50:27 drahn 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 
22 int mainSymbol;
23 
24 int
main()25 main()
26 {
27 	int ret = 1;
28 	void *libbb;
29 	void *libcc;
30 	void *bbsym;
31 	void *ccsym;
32 	void *a_sym;
33 
34 
35 	libbb = dlopen("libbb.so", RTLD_LAZY|RTLD_GLOBAL);
36 	if (libbb == NULL) {
37 		printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
38 		return (1);
39 	}
40 
41 	libcc = dlopen("libcc.so", RTLD_LAZY|RTLD_GLOBAL);
42 	if (libcc == NULL) {
43 		printf("dlopen(\"libcc.so\", RTLD_LAZY) FAILED\n");
44 		return (1);
45 	}
46 
47 	bbsym = dlsym(libbb, "commonSymbol");
48 	ccsym = dlsym(libcc, "commonSymbol");
49 	a_sym = dlsym(RTLD_DEFAULT, "commonSymbol");
50 
51 	if(a_sym == bbsym) {
52 		ret = 0;
53 	}
54 	if(a_sym == ccsym) {
55 		printf("found common symbol in libcc incorrect location\n");
56 		ret = 1;
57 	}
58 
59 	dlclose(libbb);
60 	dlclose(libcc);
61 
62 	return (ret);
63 }
64