Submitted By: Miklos Karacsony <mkaracsony81 at gmail dot com>
Date: 2014-11-06
Initial Package Version: 2.24
Upstream Status: Applied
Origin: Upstream
Description: Handle more than one plugin in /usr/lib/bfd-plugins
diff --git a/bfd/plugin.c b/bfd/plugin.c
index c9d53c89a61f..d336b6731116 100644
a
|
b
|
bfd_plugin_set_program_name (const char *program_name)
|
156 | 156 | } |
157 | 157 | |
158 | 158 | static int |
159 | | try_load_plugin (const char *pname) |
| 159 | try_claim (bfd *abfd) |
160 | 160 | { |
161 | | static void *plugin_handle; |
| 161 | int claimed = 0; |
| 162 | struct ld_plugin_input_file file; |
| 163 | bfd *iobfd; |
| 164 | |
| 165 | file.name = abfd->filename; |
| 166 | |
| 167 | if (abfd->my_archive) |
| 168 | { |
| 169 | iobfd = abfd->my_archive; |
| 170 | file.offset = abfd->origin; |
| 171 | file.filesize = arelt_size (abfd); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | iobfd = abfd; |
| 176 | file.offset = 0; |
| 177 | file.filesize = 0; |
| 178 | } |
| 179 | |
| 180 | if (!iobfd->iostream && !bfd_open_file (iobfd)) |
| 181 | return 0; |
| 182 | |
| 183 | file.fd = fileno ((FILE *) iobfd->iostream); |
| 184 | |
| 185 | if (!abfd->my_archive) |
| 186 | { |
| 187 | struct stat stat_buf; |
| 188 | if (fstat (file.fd, &stat_buf)) |
| 189 | return 0; |
| 190 | file.filesize = stat_buf.st_size; |
| 191 | } |
| 192 | |
| 193 | file.handle = abfd; |
| 194 | off_t cur_offset = lseek(file.fd, 0, SEEK_CUR); |
| 195 | claim_file (&file, &claimed); |
| 196 | lseek(file.fd, cur_offset, SEEK_SET); |
| 197 | if (!claimed) |
| 198 | return 0; |
| 199 | |
| 200 | return 1; |
| 201 | } |
| 202 | |
| 203 | static int |
| 204 | try_load_plugin (const char *pname, bfd *abfd) |
| 205 | { |
| 206 | void *plugin_handle; |
162 | 207 | int tv_size = 4; |
163 | 208 | struct ld_plugin_tv tv[tv_size]; |
164 | 209 | int i; |
… |
… |
try_load_plugin (const char *pname)
|
200 | 245 | if (!claim_file) |
201 | 246 | goto err; |
202 | 247 | |
| 248 | if (!try_claim (abfd)) |
| 249 | goto err; |
| 250 | |
203 | 251 | return 1; |
204 | 252 | |
205 | 253 | err: |
… |
… |
bfd_plugin_set_plugin (const char *p)
|
216 | 264 | } |
217 | 265 | |
218 | 266 | static int |
219 | | load_plugin (void) |
| 267 | load_plugin (bfd *abfd) |
220 | 268 | { |
221 | 269 | char *plugin_dir; |
222 | 270 | char *p; |
… |
… |
load_plugin (void)
|
225 | 273 | int found = 0; |
226 | 274 | |
227 | 275 | if (plugin_name) |
228 | | return try_load_plugin (plugin_name); |
| 276 | return try_load_plugin (plugin_name, abfd); |
229 | 277 | |
230 | 278 | if (plugin_program_name == NULL) |
231 | 279 | return 0; |
… |
… |
load_plugin (void)
|
248 | 296 | |
249 | 297 | full_name = concat (p, "/", ent->d_name, NULL); |
250 | 298 | if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode)) |
251 | | found = try_load_plugin (full_name); |
| 299 | found = try_load_plugin (full_name, abfd); |
252 | 300 | free (full_name); |
253 | 301 | if (found) |
254 | 302 | break; |
… |
… |
load_plugin (void)
|
266 | 314 | static const bfd_target * |
267 | 315 | bfd_plugin_object_p (bfd *abfd) |
268 | 316 | { |
269 | | int claimed = 0; |
270 | | struct ld_plugin_input_file file; |
271 | | bfd *iobfd; |
272 | | static int have_loaded = 0; |
273 | | static int have_plugin = 0; |
274 | | |
275 | | if (!have_loaded) |
276 | | { |
277 | | have_loaded = 1; |
278 | | have_plugin = load_plugin (); |
279 | | } |
280 | | if (!have_plugin) |
281 | | return NULL; |
282 | | |
283 | | file.name = abfd->filename; |
284 | | |
285 | | if (abfd->my_archive) |
286 | | { |
287 | | iobfd = abfd->my_archive; |
288 | | file.offset = abfd->origin; |
289 | | file.filesize = arelt_size (abfd); |
290 | | } |
291 | | else |
292 | | { |
293 | | iobfd = abfd; |
294 | | file.offset = 0; |
295 | | file.filesize = 0; |
296 | | } |
297 | | |
298 | | if (!iobfd->iostream && !bfd_open_file (iobfd)) |
299 | | return NULL; |
300 | | |
301 | | file.fd = fileno ((FILE *) iobfd->iostream); |
302 | | |
303 | | if (!abfd->my_archive) |
304 | | { |
305 | | struct stat stat_buf; |
306 | | if (fstat (file.fd, &stat_buf)) |
307 | | return NULL; |
308 | | file.filesize = stat_buf.st_size; |
309 | | } |
310 | | |
311 | | file.handle = abfd; |
312 | | off_t cur_offset = lseek(file.fd, 0, SEEK_CUR); |
313 | | claim_file (&file, &claimed); |
314 | | lseek(file.fd, cur_offset, SEEK_SET); |
315 | | if (!claimed) |
| 317 | if (!load_plugin (abfd)) |
316 | 318 | return NULL; |
317 | 319 | |
318 | 320 | return abfd->xvec; |