summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2013-05-03 16:09:12 +0300
committerEli Zaretskii <eliz@gnu.org>2013-05-03 16:09:12 +0300
commita66469e003526679b793f2d4623219aab2230b2f (patch)
treea8f532fab0ab0dcc11221c06896dbaf99fba5cc5 /load.c
parentb5ea49bae7e5074e472605e5d0c2413e62461718 (diff)
downloadgunmake-a66469e003526679b793f2d4623219aab2230b2f.tar.gz
Fix interfacing with and remaking dynamic objects on MS-Windows.
load.c (load_object, load_file): Accept an additional argument DLP and return in it a pointer that can be used to unload the dynamic object. read.c (eval): Call load_file with an additional argument, and record the pointer returned there in the 'struct file' object of dynamic objects in that object's 'struct file'. commands.c (execute_file_commands): Unload dynamic objects before remaking them, to avoid failure to remake if the OS doesn't allow overwriting objects that are in use. filedef.h (struct file): New member dlopen_ptr. gnumake.h (GMK_EXPORT): Define to dllexport/dllimport decorations for Windows and to nothing on other platforms. (gmk_eval, gmk_expand, gmk_add_function): Add GMK_EXPORT qualifier to prototypes. makeint.h (MAIN): Define before including gnumake.h, to give correct dllexport decorations to exported functions. (load_file): Adjust prototype. loadapi.c: Don't include gnumake.h, since makeint.h already includes it, and takes care of defining MAIN before doing so. build_w32.bat (LinkGCC): Produce an import library for functions exported by Make for loadable dynamic objects. w32/compat/posixfcn.c (dlclose): New function. w32/include/dlfcn.h (dlclose): Add prototype. scripts/features/load: Fix signatures of testload_gmk_setup and explicit_setup, to bring them in line with the documentation.
Diffstat (limited to 'load.c')
-rw-r--r--load.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/load.c b/load.c
index 9a83829..f20c1c7 100644
--- a/load.c
+++ b/load.c
@@ -32,11 +32,13 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
static load_func_t
load_object (const gmk_floc *flocp, int noerror,
- const char *ldname, const char *symname)
+ const char *ldname, const char *symname, void **dlp)
{
static void *global_dl = NULL;
load_func_t symp;
+ *dlp = NULL;
+
if (! global_dl)
{
global_dl = dlopen (NULL, RTLD_NOW|RTLD_GLOBAL);
@@ -46,7 +48,6 @@ load_object (const gmk_floc *flocp, int noerror,
symp = (load_func_t) dlsym (global_dl, symname);
if (! symp) {
- void *dlp = NULL;
/* If the path has no "/", try the current directory first. */
if (! strchr (ldname, '/')
@@ -54,14 +55,14 @@ load_object (const gmk_floc *flocp, int noerror,
&& ! strchr (ldname, '\\')
#endif
)
- dlp = dlopen (concat (2, "./", ldname), RTLD_LAZY|RTLD_GLOBAL);
+ *dlp = dlopen (concat (2, "./", ldname), RTLD_LAZY|RTLD_GLOBAL);
/* If we haven't opened it yet, try the default search path. */
- if (! dlp)
- dlp = dlopen (ldname, RTLD_LAZY|RTLD_GLOBAL);
+ if (! *dlp)
+ *dlp = dlopen (ldname, RTLD_LAZY|RTLD_GLOBAL);
/* Still no? Then fail. */
- if (! dlp)
+ if (! *dlp)
{
if (noerror)
DB (DB_BASIC, ("%s", dlerror()));
@@ -70,7 +71,7 @@ load_object (const gmk_floc *flocp, int noerror,
return NULL;
}
- symp = dlsym (dlp, symname);
+ symp = dlsym (*dlp, symname);
if (! symp)
fatal (flocp, _("Failed to load symbol %s from %s: %s"),
symname, ldname, dlerror());
@@ -80,7 +81,7 @@ load_object (const gmk_floc *flocp, int noerror,
}
int
-load_file (const gmk_floc *flocp, const char **ldname, int noerror)
+load_file (const gmk_floc *flocp, const char **ldname, int noerror, void **dlp)
{
int nmlen = strlen (*ldname);
char *new = alloca (nmlen + CSTRLEN (SYMBOL_EXTENSION) + 1);
@@ -90,6 +91,8 @@ load_file (const gmk_floc *flocp, const char **ldname, int noerror)
int r;
load_func_t symp;
+ *dlp = NULL;
+
/* Break the input into an object file name and a symbol name. If no symbol
name was provided, compute one from the object file name. */
fp = strchr (*ldname, '(');
@@ -165,7 +168,7 @@ load_file (const gmk_floc *flocp, const char **ldname, int noerror)
DB (DB_VERBOSE, (_("Loading symbol %s from %s\n"), symname, *ldname));
/* Load it! */
- symp = load_object(flocp, noerror, *ldname, symname);
+ symp = load_object(flocp, noerror, *ldname, symname, dlp);
if (! symp)
return 0;