Annotation of parser3/src/lib/ltdl/loaders/shl_load.c, revision 1.2
1.1 moko 1: /* loader-shl_load.c -- dynamic linking with shl_load (HP-UX)
2:
1.2 ! moko 3: Copyright (C) 1998-2000, 2004, 2006-2008, 2011-2019, 2021-2024 Free
! 4: Software Foundation, Inc.
1.1 moko 5: Written by Thomas Tanner, 1998
6:
7: NOTE: The canonical source of this file is maintained with the
8: GNU Libtool package. Report bugs to bug-libtool@gnu.org.
9:
10: GNU Libltdl is free software; you can redistribute it and/or
11: modify it under the terms of the GNU Lesser General Public
12: License as published by the Free Software Foundation; either
13: version 2 of the License, or (at your option) any later version.
14:
15: As a special exception to the GNU Lesser General Public License,
16: if you distribute this file as part of a program or library that
17: is built using GNU Libtool, you may include this file under the
18: same distribution terms that you use for the rest of that program.
19:
20: GNU Libltdl is distributed in the hope that it will be useful,
21: but WITHOUT ANY WARRANTY; without even the implied warranty of
22: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: GNU Lesser General Public License for more details.
24:
25: You should have received a copy of the GNU Lesser General Public
1.2 ! moko 26: License along with GNU Libltdl. If not, see <https://www.gnu.org/licenses/>.
1.1 moko 27: */
28:
29: #include "lt__private.h"
30: #include "lt_dlloader.h"
31:
32: /* Use the preprocessor to rename non-static symbols to avoid namespace
33: collisions when the loader code is statically linked into libltdl.
34: Use the "<module_name>_LTX_" prefix so that the symbol addresses can
35: be fetched from the preloaded symbol list by lt_dlsym(): */
36: #define get_vtable shl_load_LTX_get_vtable
37:
38: LT_BEGIN_C_DECLS
39: LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
40: LT_END_C_DECLS
41:
42:
43: /* Boilerplate code to set up the vtable for hooking this loader into
44: libltdl's loader list: */
45: static int vl_exit (lt_user_data loader_data);
46: static lt_module vm_open (lt_user_data loader_data, const char *filename,
47: lt_dladvise advise);
48: static int vm_close (lt_user_data loader_data, lt_module module);
49: static void * vm_sym (lt_user_data loader_data, lt_module module,
50: const char *symbolname);
51:
52: static lt_dlvtable *vtable = 0;
53:
54: /* Return the vtable for this loader, only the name and sym_prefix
55: attributes (plus the virtual function implementations, obviously)
56: change between loaders. */
57: lt_dlvtable *
58: get_vtable (lt_user_data loader_data)
59: {
60: if (!vtable)
61: {
62: vtable = lt__zalloc (sizeof *vtable);
63: }
64:
65: if (vtable && !vtable->name)
66: {
67: vtable->name = "lt_shl_load";
68: vtable->module_open = vm_open;
69: vtable->module_close = vm_close;
70: vtable->find_sym = vm_sym;
71: vtable->dlloader_exit = vl_exit;
72: vtable->dlloader_data = loader_data;
73: vtable->priority = LT_DLLOADER_APPEND;
74: }
75:
76: if (vtable && (vtable->dlloader_data != loader_data))
77: {
78: LT__SETERROR (INIT_LOADER);
79: return 0;
80: }
81:
82: return vtable;
83: }
84:
85:
86:
87: /* --- IMPLEMENTATION --- */
88:
89:
1.2 ! moko 90: #if defined HAVE_DL_H
1.1 moko 91: # include <dl.h>
92: #endif
93:
94: /* some flags are missing on some systems, so we provide
95: * harmless defaults.
96: *
97: * Mandatory:
98: * BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
99: * BIND_DEFERRED - Delay code symbol resolution until actual reference.
100: *
101: * Optionally:
102: * BIND_FIRST - Place the library at the head of the symbol search
1.2 ! moko 103: * order.
1.1 moko 104: * BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all
1.2 ! moko 105: * unsatisfied symbols as fatal. This flag allows
! 106: * binding of unsatisfied code symbols to be deferred
! 107: * until use.
1.1 moko 108: * [Perl: For certain libraries, like DCE, deferred
109: * binding often causes run time problems. Adding
110: * BIND_NONFATAL to BIND_IMMEDIATE still allows
111: * unresolved references in situations like this.]
112: * BIND_NOSTART - Do not call the initializer for the shared library
113: * when the library is loaded, nor on a future call to
114: * shl_unload().
115: * BIND_VERBOSE - Print verbose messages concerning possible
116: * unsatisfied symbols.
117: *
118: * hp9000s700/hp9000s800:
119: * BIND_RESTRICTED - Restrict symbols visible by the library to those
120: * present at library load time.
121: * DYNAMIC_PATH - Allow the loader to dynamically search for the
122: * library specified by the path argument.
123: */
124:
1.2 ! moko 125: #if !defined DYNAMIC_PATH
1.1 moko 126: # define DYNAMIC_PATH 0
127: #endif
1.2 ! moko 128: #if !defined BIND_RESTRICTED
1.1 moko 129: # define BIND_RESTRICTED 0
130: #endif
131:
132: #define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH)
133:
134:
135: /* A function called through the vtable when this loader is no
136: longer needed by the application. */
137: static int
1.2 ! moko 138: vl_exit (lt_user_data loader_data LT__UNUSED)
1.1 moko 139: {
140: vtable = NULL;
141: return 0;
142: }
143:
144: /* A function called through the vtable to open a module with this
145: loader. Returns an opaque representation of the newly opened
146: module for processing with this loader's other vtable functions. */
147: static lt_module
1.2 ! moko 148: vm_open (lt_user_data loader_data LT__UNUSED, const char *filename,
! 149: lt_dladvise advise LT__UNUSED)
1.1 moko 150: {
151: static shl_t self = (shl_t) 0;
152: lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L);
153:
154: /* Since searching for a symbol against a NULL module handle will also
155: look in everything else that was already loaded and exported with
156: the -E compiler flag, we always cache a handle saved before any
157: modules are loaded. */
158: if (!self)
159: {
160: void *address;
161: shl_findsym (&self, "main", TYPE_UNDEFINED, &address);
162: }
163:
164: if (!filename)
165: {
166: module = self;
167: }
168: else
169: {
170: module = shl_load (filename, LT_BIND_FLAGS, 0L);
171:
172: if (!module)
173: {
174: LT__SETERROR (CANNOT_OPEN);
175: }
176: }
177:
178: return module;
179: }
180:
181: /* A function called through the vtable when a particular module
182: should be unloaded. */
183: static int
1.2 ! moko 184: vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
1.1 moko 185: {
186: int errors = 0;
187:
188: if (module && (shl_unload ((shl_t) (module)) != 0))
189: {
190: LT__SETERROR (CANNOT_CLOSE);
191: ++errors;
192: }
193:
194: return errors;
195: }
196:
197:
198: /* A function called through the vtable to get the address of
199: a symbol loaded from a particular module. */
200: static void *
1.2 ! moko 201: vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char *name)
1.1 moko 202: {
203: void *address = 0;
204:
205: /* sys_shl_open should never return a NULL module handle */
206: if (module == (lt_module) 0)
207: {
208: LT__SETERROR (INVALID_HANDLE);
209: }
210: else if (!shl_findsym((shl_t*) &module, name, TYPE_UNDEFINED, &address))
211: {
212: if (!address)
213: {
214: LT__SETERROR (SYMBOL_NOT_FOUND);
215: }
216: }
217:
218: return address;
219: }
E-mail: