1
/* loader-shl_load.c -- dynamic linking with shl_load (HP-UX)
3
Copyright (C) 1998, 1999, 2000, 2004, 2006,
4
2007, 2008 Free Software Foundation, Inc.
5
Written by Thomas Tanner, 1998
7
NOTE: The canonical source of this file is maintained with the
8
GNU Libtool package. Report bugs to bug-libtool@gnu.org.
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.
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.
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.
25
You should have received a copy of the GNU Lesser General Public
26
License along with GNU Libltdl; see the file COPYING.LIB. If not, a
27
copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
28
or obtained by writing to the Free Software Foundation, Inc.,
29
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32
#include "lt__private.h"
33
#include "lt_dlloader.h"
35
/* Use the preprocessor to rename non-static symbols to avoid namespace
36
collisions when the loader code is statically linked into libltdl.
37
Use the "<module_name>_LTX_" prefix so that the symbol addresses can
38
be fetched from the preloaded symbol list by lt_dlsym(): */
39
#define get_vtable shl_load_LTX_get_vtable
42
LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
46
/* Boilerplate code to set up the vtable for hooking this loader into
47
libltdl's loader list: */
48
static int vl_exit (lt_user_data loader_data);
49
static lt_module vm_open (lt_user_data loader_data, const char *filename,
51
static int vm_close (lt_user_data loader_data, lt_module module);
52
static void * vm_sym (lt_user_data loader_data, lt_module module,
53
const char *symbolname);
55
static lt_dlvtable *vtable = 0;
57
/* Return the vtable for this loader, only the name and sym_prefix
58
attributes (plus the virtual function implementations, obviously)
59
change between loaders. */
61
get_vtable (lt_user_data loader_data)
65
vtable = lt__zalloc (sizeof *vtable);
68
if (vtable && !vtable->name)
70
vtable->name = "lt_shl_load";
71
vtable->module_open = vm_open;
72
vtable->module_close = vm_close;
73
vtable->find_sym = vm_sym;
74
vtable->dlloader_exit = vl_exit;
75
vtable->dlloader_data = loader_data;
76
vtable->priority = LT_DLLOADER_APPEND;
79
if (vtable && (vtable->dlloader_data != loader_data))
81
LT__SETERROR (INIT_LOADER);
90
/* --- IMPLEMENTATION --- */
93
#if defined(HAVE_DL_H)
97
/* some flags are missing on some systems, so we provide
101
* BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
102
* BIND_DEFERRED - Delay code symbol resolution until actual reference.
105
* BIND_FIRST - Place the library at the head of the symbol search
107
* BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all
108
* unsatisfied symbols as fatal. This flag allows
109
* binding of unsatisfied code symbols to be deferred
111
* [Perl: For certain libraries, like DCE, deferred
112
* binding often causes run time problems. Adding
113
* BIND_NONFATAL to BIND_IMMEDIATE still allows
114
* unresolved references in situations like this.]
115
* BIND_NOSTART - Do not call the initializer for the shared library
116
* when the library is loaded, nor on a future call to
118
* BIND_VERBOSE - Print verbose messages concerning possible
119
* unsatisfied symbols.
121
* hp9000s700/hp9000s800:
122
* BIND_RESTRICTED - Restrict symbols visible by the library to those
123
* present at library load time.
124
* DYNAMIC_PATH - Allow the loader to dynamically search for the
125
* library specified by the path argument.
128
#if !defined(DYNAMIC_PATH)
129
# define DYNAMIC_PATH 0
131
#if !defined(BIND_RESTRICTED)
132
# define BIND_RESTRICTED 0
135
#define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH)
138
/* A function called through the vtable when this loader is no
139
longer needed by the application. */
141
vl_exit (lt_user_data LT__UNUSED loader_data)
147
/* A function called through the vtable to open a module with this
148
loader. Returns an opaque representation of the newly opened
149
module for processing with this loader's other vtable functions. */
151
vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
152
lt_dladvise LT__UNUSED advise)
154
static shl_t self = (shl_t) 0;
155
lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L);
157
/* Since searching for a symbol against a NULL module handle will also
158
look in everything else that was already loaded and exported with
159
the -E compiler flag, we always cache a handle saved before any
160
modules are loaded. */
164
shl_findsym (&self, "main", TYPE_UNDEFINED, &address);
173
module = shl_load (filename, LT_BIND_FLAGS, 0L);
177
LT__SETERROR (CANNOT_OPEN);
184
/* A function called through the vtable when a particular module
185
should be unloaded. */
187
vm_close (lt_user_data LT__UNUSED loader_data, lt_module module)
191
if (module && (shl_unload ((shl_t) (module)) != 0))
193
LT__SETERROR (CANNOT_CLOSE);
201
/* A function called through the vtable to get the address of
202
a symbol loaded from a particular module. */
204
vm_sym (lt_user_data LT__UNUSED loader_data, lt_module module, const char *name)
208
/* sys_shl_open should never return a NULL module handle */
209
if (module == (lt_module) 0)
211
LT__SETERROR (INVALID_HANDLE);
213
else if (!shl_findsym((shl_t*) &module, name, TYPE_UNDEFINED, &address))
217
LT__SETERROR (SYMBOL_NOT_FOUND);