xref: /netbsd-src/lib/libc/dlfcn/dlfcn_elf.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: dlfcn_elf.c,v 1.5 2004/07/18 17:26:19 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Takuya SHIOZAKI
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 #if defined(LIBC_SCCS) && !defined(lint)
30 __RCSID("$NetBSD: dlfcn_elf.c,v 1.5 2004/07/18 17:26:19 thorpej Exp $");
31 #endif /* LIBC_SCCS and not lint */
32 
33 #include "namespace.h"
34 
35 #undef dlopen
36 #undef dlclose
37 #undef dlsym
38 #undef dlerror
39 #undef dladdr
40 
41 #define	dlopen		___dlopen
42 #define	dlclose		___dlclose
43 #define	dlsym		___dlsym
44 #define	dlerror		___dlerror
45 #define	dladdr		___dladdr
46 
47 #define ELFSIZE ARCH_ELFSIZE
48 #include "rtld.h"
49 
50 #ifdef __weak_alias
51 __weak_alias(dlopen,___dlopen)
52 __weak_alias(dlclose,___dlclose)
53 __weak_alias(dlsym,___dlsym)
54 __weak_alias(dlerror,___dlerror)
55 __weak_alias(dladdr,___dladdr)
56 
57 __weak_alias(__dlopen,___dlopen)
58 __weak_alias(__dlclose,___dlclose)
59 __weak_alias(__dlsym,___dlsym)
60 __weak_alias(__dlerror,___dlerror)
61 __weak_alias(__dladdr,___dladdr)
62 #endif
63 
64 /*
65  * For ELF, the dynamic linker directly resolves references to its
66  * services to functions inside the dynamic linker itself.  These
67  * weak-symbol stubs are necessary so that "ld" won't complain about
68  * undefined symbols.  The stubs are executed only when the program is
69  * linked statically, or when a given service isn't implemented in the
70  * dynamic linker.  They must return an error if called, and they must
71  * be weak symbols so that the dynamic linker can override them.
72  */
73 
74 static char dlfcn_error[] = "Service unavailable";
75 
76 /*ARGSUSED*/
77 void *
78 dlopen(const char *name, int mode)
79 {
80 
81 	return NULL;
82 }
83 
84 /*ARGSUSED*/
85 int
86 dlclose(void *fd)
87 {
88 
89 	return -1;
90 }
91 
92 /*ARGSUSED*/
93 void *
94 dlsym(void *handle, const char *name)
95 {
96 
97 	return NULL;
98 }
99 
100 /*ARGSUSED*/
101 __aconst char *
102 dlerror()
103 {
104 
105 	return dlfcn_error;
106 }
107 
108 /*ARGSUSED*/
109 int
110 dladdr(const void *addr, Dl_info *dli)
111 {
112 
113 	return 0;
114 }
115