1 /* $OpenBSD: main.c,v 1.1.1.1 2005/09/19 01:26:46 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 * checks that dependent libs are not promoted to RTLD_GLOBAL by mistake. 26 */ 27 int 28 main() 29 { 30 int ret = 0; 31 void *libbb = dlopen("libbb.so", RTLD_LAZY); 32 void *libcc = dlopen("libcc.so", RTLD_LAZY); 33 34 if (libbb == NULL) { 35 printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n"); 36 return (1); 37 } 38 39 if (libcc == NULL) { 40 printf("dlopen(\"libcc.so\", RTLD_LAZY) FAILED\n"); 41 return (1); 42 } 43 44 /* RTLD_DEFAULT should *not* see ccSymbol */ 45 if (dlsym(RTLD_DEFAULT, "ccSymbol") != NULL) { 46 printf("dlsym(RTLD_DEFAULT, \"ccSymbol\") != NULL\n"); 47 ret = 1; 48 } 49 50 dlclose(libbb); 51 dlclose(libcc); 52 53 return (ret); 54 } 55