Commit | Line | Data |
---|---|---|
1edae076 MV |
1 | /* dynl-dld.c - dynamic linking with dld |
2 | * | |
96599e6a | 3 | * Copyright (C) 1990-1997 Free Software Foundation, Inc. |
1edae076 MV |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this software; see the file COPYING. If not, write to | |
82892bed JB |
17 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
18 | * Boston, MA 02111-1307 USA | |
1edae076 MV |
19 | * |
20 | * As a special exception, the Free Software Foundation gives permission | |
21 | * for additional uses of the text contained in its release of GUILE. | |
22 | * | |
23 | * The exception is that, if you link the GUILE library with other files | |
24 | * to produce an executable, this does not by itself cause the | |
25 | * resulting executable to be covered by the GNU General Public License. | |
26 | * Your use of that executable is in no way restricted on account of | |
27 | * linking the GUILE library code into it. | |
28 | * | |
29 | * This exception does not however invalidate any other reasons why | |
30 | * the executable file might be covered by the GNU General Public License. | |
31 | * | |
32 | * This exception applies only to the code released by the | |
33 | * Free Software Foundation under the name GUILE. If you copy | |
34 | * code from other Free Software Foundation releases into a copy of | |
35 | * GUILE, as the General Public License permits, the exception does | |
36 | * not apply to the code that you add in this way. To avoid misleading | |
37 | * anyone as to the status of such modified files, you must delete | |
38 | * this exception notice from them. | |
39 | * | |
40 | * If you write modifications of your own for GUILE, it is your choice | |
41 | * whether to permit this exception to apply to your modifications. | |
82892bed | 42 | * If you do not wish that, delete this exception notice. */ |
1edae076 MV |
43 | |
44 | /* "dynl.c" dynamically link&load object files. | |
45 | Author: Aubrey Jaffer | |
46 | Modified for libguile by Marius Vollmer */ | |
47 | ||
1edae076 MV |
48 | #include "dld.h" |
49 | ||
50 | static void listundef SCM_P ((void)); | |
51 | ||
52 | static void | |
53 | listundefs () | |
54 | { | |
55 | int i; | |
56 | char **undefs = dld_list_undefined_sym(); | |
57 | puts(" undefs:"); | |
58 | for(i = dld_undefined_sym_count;i--;) { | |
59 | putc('"', stdout); | |
60 | fputs(undefs[i], stdout); | |
61 | puts("\""); | |
62 | } | |
63 | free(undefs); | |
64 | } | |
65 | ||
80bc7890 | 66 | static void * |
56a19408 | 67 | sysdep_dynl_link (fname, int flags, subr) |
3eeba8d4 | 68 | const char *fname; |
56a19408 | 69 | int flags; |
3eeba8d4 | 70 | const char *subr; |
80bc7890 MV |
71 | { |
72 | int status; | |
1edae076 | 73 | |
80bc7890 MV |
74 | status = dld_link (fname); |
75 | if (status) | |
419e9e11 MV |
76 | { |
77 | SCM_ALLOW_INTS; | |
80bc7890 | 78 | scm_misc_error (subr, dld_strerror (status), SCM_EOL); |
419e9e11 | 79 | } |
80bc7890 MV |
80 | return fname; |
81 | } | |
82 | ||
83 | static void | |
84 | sysdep_dynl_unlink (handle, subr) | |
85 | void *handle; | |
3eeba8d4 | 86 | const char *subr; |
1edae076 MV |
87 | { |
88 | int status; | |
1edae076 | 89 | |
80bc7890 | 90 | status = dld_unlink_by_file ((char *)fname, 1); |
1edae076 | 91 | if (status) |
419e9e11 MV |
92 | { |
93 | SCM_ALLOW_INTS; | |
80bc7890 | 94 | scm_misc_error (s_dynamic_unlink, dld_strerror (status), SCM_EOL); |
419e9e11 | 95 | } |
1edae076 MV |
96 | } |
97 | ||
1edae076 | 98 | static void * |
80bc7890 | 99 | sysdep_dynl_func (symb, handle, subr) |
3eeba8d4 | 100 | const char *symb; |
80bc7890 | 101 | void *handle; |
3eeba8d4 | 102 | const char *subr; |
1edae076 MV |
103 | { |
104 | void *func; | |
105 | ||
80bc7890 MV |
106 | func = (void *) dld_get_func (func); |
107 | if (func == 0) | |
108 | scm_misc_error (subr, dld_strerror (dld_errno), SCM_EOL); | |
1edae076 MV |
109 | if (!dld_function_executable_p (func)) { |
110 | listundefs (); | |
419e9e11 | 111 | SCM_ALLOW_INTS; |
1edae076 MV |
112 | scm_misc_error (subr, "unresolved symbols remain", SCM_EOL); |
113 | } | |
80bc7890 | 114 | return func; |
1edae076 MV |
115 | } |
116 | ||
80bc7890 MV |
117 | static void |
118 | sysdep_dynl_init () | |
1edae076 MV |
119 | { |
120 | #ifndef RTL | |
121 | if (!execpath) | |
122 | execpath = dld_find_executable (SCM_CHARS (SCM_CAR (progargs))); | |
123 | if (dld_init (SCM_CHARS (SCM_CAR (progargs)))) { | |
124 | dld_perror("DLD"); | |
125 | return; | |
126 | } | |
127 | #endif | |
128 | ||
1edae076 MV |
129 | #ifdef DLD_DYNCM /* XXX - what's this? */ |
130 | add_feature("dld:dyncm"); | |
131 | #endif | |
132 | } |