1
|
1 // dynamic-ld.cc -*- C++ -*- |
|
2 /* |
|
3 |
499
|
4 Copyright (C) 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 extern "C" |
|
29 { |
184
|
30 #include "dld/dld.h" |
1
|
31 } |
|
32 |
|
33 #include "dynamic-ld.h" |
|
34 #include "tree-const.h" |
|
35 #include "user-prefs.h" |
|
36 #include "octave.h" |
|
37 #include "utils.h" |
|
38 #include "error.h" |
|
39 |
|
40 void |
164
|
41 octave_dld_tc2_unlink_by_symbol (const char *name, int hard = 1) |
1
|
42 { |
527
|
43 // XXX FIXME XXX -- need to determine the name mangling scheme |
|
44 // automatically, in case it changes, or is different on different |
|
45 // systems, even if they have g++. |
|
46 char *mangled_fcn_name = strconcat (name, "__FRC13Octave_objecti"); |
1
|
47 int status = dld_unlink_by_symbol (mangled_fcn_name, hard); |
|
48 if (status != 0) |
|
49 dld_perror ("octave_dld_tc2_unlink_by_symbol"); |
|
50 delete [] mangled_fcn_name; |
|
51 } |
|
52 |
|
53 void |
164
|
54 octave_dld_tc2_unlink_by_file (const char *name, int hard = 1) |
1
|
55 { |
|
56 int status = dld_unlink_by_file (name, hard); |
|
57 if (status != 0) |
|
58 dld_perror ("octave_dld_tc2_unlink_by_file"); |
|
59 } |
|
60 |
|
61 static void |
|
62 octave_dld_init (void) |
|
63 { |
|
64 static int initialized = 0; |
|
65 |
|
66 if (! initialized) |
|
67 { |
|
68 char *full_path = dld_find_executable (raw_prog_name); |
527
|
69 if (full_path) |
1
|
70 { |
|
71 int status = dld_init (full_path); |
|
72 if (status != 0) |
|
73 { |
|
74 dld_perror ("octave_dld_tc2_and_go"); |
|
75 error ("failed to load symbols from `%s'", full_path); |
|
76 } |
|
77 else |
|
78 initialized = 1; |
|
79 } |
|
80 else |
|
81 error ("octave_dld_tc2_and_go: can't find full path to `%s'", |
|
82 prog_name); |
|
83 } |
|
84 } |
|
85 |
|
86 /* |
|
87 * Look for object in path. It should provide a definition for the |
|
88 * function we just marked as undefined. If we find it, we\'ll also |
|
89 * try to load the remaining undefined symbols. |
|
90 */ |
|
91 static int |
164
|
92 octave_dld_link (const char *object) |
1
|
93 { |
527
|
94 char *file = file_in_path (object, 0); |
1
|
95 int status = dld_link (file); |
|
96 if (status != 0) |
|
97 dld_perror ("octave_dld_link"); |
|
98 |
|
99 delete [] file; |
|
100 return status; |
|
101 } |
|
102 |
|
103 int |
164
|
104 octave_dld_tc2_link (const char *object) |
1
|
105 { |
|
106 int status = octave_dld_link (object); |
|
107 if (status == 0) |
|
108 { |
527
|
109 // XXX FIXME XXX -- this obviously won't work everywhere... |
|
110 char *octave_lib = "/home/jwe/src/octave/sun4-dld/liboctave.a"; |
|
111 status = octave_dld_link (octave_lib); |
1
|
112 if (status == 0) |
527
|
113 { |
|
114 // XXX FIXME XXX -- this obviously won't work everywhere... |
|
115 char *cruft_library = "/home/jwe/src/octave/sun4-dld/libcruft.a"; |
|
116 octave_dld_link (cruft_library); |
|
117 } |
1
|
118 } |
|
119 return status; |
|
120 } |
|
121 |
|
122 builtin_fcn_ptr |
527
|
123 octave_dld_tc2 (const char *name, const char *fcn) |
1
|
124 { |
527
|
125 builtin_fcn_ptr retval = 0; |
1
|
126 |
|
127 octave_dld_init (); |
|
128 |
527
|
129 // XXX FIXME XXX -- need to determine the name mangling scheme |
|
130 // automatically, in case it changes, or is different on different |
|
131 // systems, even if they have g++. |
|
132 char *mangled_fcn_name = strconcat (fcn, "__FRC13Octave_objecti"); |
1
|
133 |
|
134 // See if the function has already been loaded. If not, mark it as |
|
135 // undefined. |
|
136 |
|
137 if (dld_get_func (mangled_fcn_name) == 0) |
|
138 dld_create_reference (mangled_fcn_name); |
|
139 |
527
|
140 // XXX FIXME XXX -- this obviously won't work everywhere... |
|
141 char *octave_dld_library = "/home/jwe/src/octave/sun4-dld/liboctdld.a"; |
|
142 int status = octave_dld_tc2_link (octave_dld_library); |
1
|
143 if (status == 0) |
|
144 { |
|
145 // Return a pointer to the function we just loaded. If we can\'t find |
|
146 // it, this will return NULL. |
|
147 |
|
148 retval = (builtin_fcn_ptr) dld_get_func (mangled_fcn_name); |
|
149 } |
|
150 |
|
151 delete [] mangled_fcn_name; |
|
152 |
|
153 return retval; |
|
154 |
|
155 } |
|
156 |
499
|
157 Octave_object |
506
|
158 octave_dld_tc2_and_go (const Octave_object& args, int nargout, |
527
|
159 const char *name, const char *fcn) |
1
|
160 { |
499
|
161 Octave_object retval; |
1
|
162 |
527
|
163 builtin_fcn_ptr fcn_to_call = octave_dld_tc2 (name, fcn); |
1
|
164 |
527
|
165 if (fcn_to_call) |
506
|
166 retval = (*fcn_to_call) (args, nargout); |
1
|
167 else |
|
168 error ("octave_dld_tc2_and_go: failed to load `%s'", name); |
|
169 |
|
170 return retval; |
|
171 } |
|
172 |
|
173 /* |
|
174 ;;; Local Variables: *** |
|
175 ;;; mode: C++ *** |
|
176 ;;; page-delimiter: "^/\\*" *** |
|
177 ;;; End: *** |
|
178 */ |