171 |
|
|
172 |
static bfd *bself; |
static bfd *bself; |
173 |
|
|
174 |
|
#ifdef __mips__ |
175 |
|
#include "sfaslbfd_mips.c" |
176 |
|
#endif |
177 |
|
|
178 |
int |
int |
179 |
fasload(object faslfile) { |
fasload(object faslfile) { |
244 |
FEerror ("Could not craft fp register preservation stubs",0); |
FEerror ("Could not craft fp register preservation stubs",0); |
245 |
#endif |
#endif |
246 |
|
|
247 |
|
if ((u=bfd_get_symtab_upper_bound(b))<0) |
248 |
|
FEerror("Cannot get symtab uppoer bound",0); |
249 |
|
q=(asymbol **)alloca(u); |
250 |
|
if ((v=bfd_canonicalize_symtab(b,q))<0) |
251 |
|
FEerror("cannot canonicalize symtab",0); |
252 |
|
|
253 |
|
*entry_name=bfd_get_symbol_leading_char(b); |
254 |
|
entry_name_ptr=*entry_name ? entry_name : entry_name+1; |
255 |
|
|
256 |
|
for (u=0;u<v;u++) { |
257 |
|
|
258 |
|
struct bfd_link_hash_entry *h; |
259 |
|
|
260 |
|
if (!strncmp(entry_name_ptr,q[u]->name,5)) { |
261 |
|
init_address=u; |
262 |
|
continue; |
263 |
|
} |
264 |
|
|
265 |
|
if (!(h=bfd_link_hash_lookup(link_info.hash,q[u]->name,MY_BFD_FALSE,MY_BFD_FALSE,MY_BFD_TRUE))) |
266 |
|
continue; |
267 |
|
|
268 |
|
if (h->type!=bfd_link_hash_defined) |
269 |
|
FEerror("Undefined symbol ~S",1,make_simple_string(q[u]->name)); |
270 |
|
|
271 |
|
if (h->u.def.section) { |
272 |
|
q[u]->value=h->u.def.value+h->u.def.section->vma; |
273 |
|
q[u]->flags|=BSF_WEAK; |
274 |
|
} else |
275 |
|
FEerror("Symbol without section",0); |
276 |
|
|
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
/* Perhaps all arch dependent stuff could be placed here, e.g. the |
281 |
|
darwin code below. Aurelien? This snippet should likely be a |
282 |
|
CPP define in config.h.*/ |
283 |
|
|
284 |
|
#ifdef __mips__ |
285 |
|
mipself_special(b,q,v); |
286 |
|
#endif |
287 |
|
|
288 |
current=NULL; |
current=NULL; |
289 |
for (s=b->sections;s;s=s->next) { |
for (s=b->sections;s;s=s->next) { |
290 |
|
|
329 |
|
|
330 |
} |
} |
331 |
|
|
332 |
if ((u=bfd_get_symtab_upper_bound(b))<0) |
init_address=q[init_address]->value+ |
333 |
FEerror("Cannot get symtab uppoer bound",0); |
(q[init_address]->section->output_section->vma-(unsigned long)memory->cfd.cfd_start); |
|
q=(asymbol **)alloca(u); |
|
|
if ((v=bfd_canonicalize_symtab(b,q))<0) |
|
|
FEerror("cannot canonicalize symtab",0); |
|
|
|
|
|
*entry_name=bfd_get_symbol_leading_char(b); |
|
|
entry_name_ptr=*entry_name ? entry_name : entry_name+1; |
|
|
|
|
|
for (u=0;u<v;u++) { |
|
|
|
|
|
struct bfd_link_hash_entry *h; |
|
|
|
|
|
if (!strncmp(entry_name_ptr,q[u]->name,5)) { |
|
|
init_address=q[u]->value+(q[u]->section->output_section->vma-(unsigned long)memory->cfd.cfd_start); |
|
|
continue; |
|
|
} |
|
|
|
|
|
if (!(h=bfd_link_hash_lookup(link_info.hash,q[u]->name,MY_BFD_FALSE,MY_BFD_FALSE,MY_BFD_TRUE))) |
|
|
continue; |
|
|
|
|
|
if (h->type!=bfd_link_hash_defined) |
|
|
FEerror("Undefined symbol ~S",1,make_simple_string(q[u]->name)); |
|
|
|
|
|
if (h->u.def.section) { |
|
|
q[u]->value=h->u.def.value+h->u.def.section->vma; |
|
|
q[u]->flags|=BSF_WEAK; |
|
|
} else |
|
|
FEerror("Symbol without section",0); |
|
|
|
|
|
} |
|
334 |
|
|
335 |
#if defined(DARWIN) |
#if defined(DARWIN) |
336 |
if (!bfd_mach_o_inject_fp_branch_islands (b, bi, q)) |
if (!bfd_mach_o_inject_fp_branch_islands (b, bi, q)) |
337 |
FEerror ("Could not inject fp register preservation stubs",0); |
FEerror ("Could not inject fp register preservation stubs",0); |
338 |
#endif |
#endif |
339 |
|
|
340 |
#ifndef HAVE_ALLOCA |
/* MIPS native relocs: As these use GOT and HI/LOW relocs which must |
341 |
#error Cannot use bfd relocations without alloca at present |
reference the final address of the code, we can no longer rely on |
342 |
#endif |
our previous strategy of bfd_get_relocated_section_contents to |
343 |
/* We have to do this to avoid the possibility that |
alloca'ed memory followed by a memcpy to the real location as a |
344 |
bfd_get_relocated_section_contents will run GBC via its alloc, thereby |
means of avoiding a bfd alloc induced sgc-off/sgc-on which write |
345 |
write protecting the pages of memory->cfd again and causing bfd reads of |
protects memory->cfd.cfd_start and causes certain system calls |
346 |
the section contents to return an error code after a 'stratified' segfault */ |
(e.g. read) to return error codes. Here we try to accomplish the |
347 |
|
same via SGC_PERM_WRITABLE. We don't want to leave this on |
348 |
|
forever, as thee is quite a bit of loaded code in a given system |
349 |
|
which need not be in the small SGC working heap. 20050409 CM*/ |
350 |
|
|
351 |
|
#ifdef SGC |
352 |
{ |
{ |
353 |
void *v=alloca(memory->cfd.cfd_size); |
extern int sgc_enabled; |
354 |
|
if (sgc_enabled) |
355 |
if (!v) |
perm_writable(memory->cfd.cfd_start,memory->cfd.cfd_size); |
356 |
FEerror("Cannot alloca for bfd",0); |
} |
357 |
|
#endif |
358 |
|
|
359 |
for (s=b->sections;s;s=s->next) { |
for (s=b->sections;s;s=s->next) { |
360 |
|
|
|
unsigned long ss=bfd_section_size(b,s); |
|
|
|
|
361 |
if (!(s->flags & SEC_LOAD)) |
if (!(s->flags & SEC_LOAD)) |
362 |
continue; |
continue; |
363 |
|
|
364 |
link_order.u.indirect.section=s; |
link_order.u.indirect.section=s; |
365 |
|
|
366 |
if (!bfd_get_relocated_section_contents(b,&link_info,&link_order, |
if (!bfd_get_relocated_section_contents(b,&link_info,&link_order, |
367 |
v,0,q)) |
(void *)(unsigned long)s->output_section->vma,0,q)) |
368 |
FEerror("Cannot get relocated section contents\n",0); |
FEerror("Cannot get relocated section contents\n",0); |
|
|
|
|
memcpy((void *)(unsigned long)s->output_section->vma,v,ss); |
|
369 |
|
|
370 |
} |
} |
371 |
|
|
372 |
|
#ifdef SGC |
373 |
|
{ |
374 |
|
extern int sgc_enabled; |
375 |
|
if (sgc_enabled) |
376 |
|
un_perm_writable(memory->cfd.cfd_start,memory->cfd.cfd_size); |
377 |
} |
} |
378 |
|
#endif |
379 |
|
|
380 |
dum.sm.sm_object1=faslfile; |
dum.sm.sm_object1=faslfile; |
381 |
dum.sm.sm_fp=b->iostream; |
dum.sm.sm_fp=b->iostream; |
382 |
|
|