1 /* $OpenBSD: dlfcn_stubs.c,v 1.13 2015/11/01 03:00:01 guenther Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29 #include <stddef.h> 30 31 /* 32 * All functions here are just stubs that will be overridden 33 * by the real functions in ld.so when dynamic loading is 34 * performed at exec. The symbols here are provided as a link 35 * helper so we can link a program using the dl functions 36 * without getting any unresolved references. 37 */ 38 39 void *dlopen(const char *libname, int how) __attribute__((weak)); 40 int dlclose(void *handle) __attribute__((weak)); 41 void *dlsym(void *handle, const char *name) __attribute__((weak)); 42 int dlctl(void *handle, int command, void *data) __attribute__((weak)); 43 char *dlerror(void) __attribute__((weak)); 44 45 struct dl_info; 46 int dladdr(const void *addr, struct dl_info *info) __attribute__((weak)); 47 48 struct dl_phdr_info; 49 int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *date) __attribute__((weak)); 50 51 #include <stdio.h> 52 53 void * 54 dlopen(const char *libname, int how) 55 { 56 printf("Wrong dl symbols!\n"); 57 return NULL; 58 } 59 60 int 61 dlclose(void *handle) 62 { 63 printf("Wrong dl symbols!\n"); 64 return 0; 65 } 66 67 void * 68 dlsym(void *handle, const char *name) 69 { 70 printf("Wrong dl symbols!\n"); 71 return NULL; 72 } 73 74 int 75 dlctl(void *handle, int command, void *data) 76 { 77 return -1; 78 } 79 80 char * 81 dlerror(void) 82 { 83 return "Wrong dl symbols!\n"; 84 } 85 86 int 87 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), 88 void *data) 89 { 90 return -1; 91 } 92 93 int 94 dladdr(const void *addr, struct dl_info *info) 95 { 96 printf("Wrong dl symbols!\n"); 97 return -1; 98 } 99