1 /*	$OpenBSD: main.c,v 1.1.1.1 2005/09/19 03:23:51 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 
22 int mainSymbol;
23 
24 /*
25  * confirm that libcc gets promoted to RTLD_GLOBAL when opened as part of
26  * libbb with RTLD_GLOBAL
27  */
28 int
29 main()
30 {
31 	int ret = 0;
32 	void *libcc = dlopen("libcc.so", RTLD_LAZY);
33 	void *libbb = dlopen("libbb.so", RTLD_LAZY|RTLD_GLOBAL);
34 
35 	if (libbb == NULL) {
36 		printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
37 		return (1);
38 	}
39 
40 	if (libcc == NULL) {
41 		printf("dlopen(\"libcc.so\", RTLD_LAZY) FAILED\n");
42 		return (1);
43 	}
44 
45 	/* RTLD_DEFAULT should see ccSymbol */
46 	if (dlsym(RTLD_DEFAULT, "ccSymbol") == NULL) {
47 		printf("dlsym(RTLD_DEFAULT, \"ccSymbol\") == NULL\n");
48 		ret = 1;
49 	}
50 
51 	dlclose(libbb);
52 	dlclose(libcc);
53 
54 	return (ret);
55 }
56