1*e0cc212dSkurt /*	$OpenBSD: main.c,v 1.1.1.1 2005/09/19 01:26:46 kurt Exp $	*/
2*e0cc212dSkurt 
3*e0cc212dSkurt /*
4*e0cc212dSkurt  * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
5*e0cc212dSkurt  *
6*e0cc212dSkurt  * Permission to use, copy, modify, and distribute this software for any
7*e0cc212dSkurt  * purpose with or without fee is hereby granted, provided that the above
8*e0cc212dSkurt  * copyright notice and this permission notice appear in all copies.
9*e0cc212dSkurt  *
10*e0cc212dSkurt  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*e0cc212dSkurt  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*e0cc212dSkurt  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*e0cc212dSkurt  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*e0cc212dSkurt  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*e0cc212dSkurt  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*e0cc212dSkurt  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*e0cc212dSkurt  */
18*e0cc212dSkurt 
19*e0cc212dSkurt #include <dlfcn.h>
20*e0cc212dSkurt #include <stdio.h>
21*e0cc212dSkurt 
22*e0cc212dSkurt int mainSymbol;
23*e0cc212dSkurt 
24*e0cc212dSkurt /*
25*e0cc212dSkurt  * checks that dependent libs are not promoted to RTLD_GLOBAL by mistake.
26*e0cc212dSkurt  */
27*e0cc212dSkurt int
main()28*e0cc212dSkurt main()
29*e0cc212dSkurt {
30*e0cc212dSkurt 	int ret = 0;
31*e0cc212dSkurt 	void *libbb = dlopen("libbb.so", RTLD_LAZY);
32*e0cc212dSkurt 	void *libcc = dlopen("libcc.so", RTLD_LAZY);
33*e0cc212dSkurt 
34*e0cc212dSkurt 	if (libbb == NULL) {
35*e0cc212dSkurt 		printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
36*e0cc212dSkurt 		return (1);
37*e0cc212dSkurt 	}
38*e0cc212dSkurt 
39*e0cc212dSkurt 	if (libcc == NULL) {
40*e0cc212dSkurt 		printf("dlopen(\"libcc.so\", RTLD_LAZY) FAILED\n");
41*e0cc212dSkurt 		return (1);
42*e0cc212dSkurt 	}
43*e0cc212dSkurt 
44*e0cc212dSkurt 	/* RTLD_DEFAULT should *not* see ccSymbol */
45*e0cc212dSkurt 	if (dlsym(RTLD_DEFAULT, "ccSymbol") != NULL) {
46*e0cc212dSkurt 		printf("dlsym(RTLD_DEFAULT, \"ccSymbol\") != NULL\n");
47*e0cc212dSkurt 		ret = 1;
48*e0cc212dSkurt 	}
49*e0cc212dSkurt 
50*e0cc212dSkurt 	dlclose(libbb);
51*e0cc212dSkurt 	dlclose(libcc);
52*e0cc212dSkurt 
53*e0cc212dSkurt 	return (ret);
54*e0cc212dSkurt }
55