1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4 Original version by Per Bothner.
5 Full support added by Ian Lance Taylor, ian@cygnus.com.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "aout/ranlib.h"
30 #include "aout/stab_gnu.h"
32 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
33 some other stuff which we don't want and which conflicts with stuff
36 #include "aout/aout64.h"
39 #undef obj_sym_filepos
41 #include "coff/internal.h"
43 #include "coff/symconst.h"
44 #include "coff/ecoff.h"
47 #include "libiberty.h"
49 #define streq(a, b) (strcmp ((a), (b)) == 0)
50 #define strneq(a, b, n) (strncmp ((a), (b), (n)) == 0)
53 /* This stuff is somewhat copied from coffcode.h. */
54 static asection bfd_debug_section
=
56 /* name, id, index, next, prev, flags, user_set_vma, */
57 "*DEBUG*", 0, 0, NULL
, NULL
, 0, 0,
58 /* linker_mark, linker_has_input, gc_mark, gc_mark_from_eh, */
60 /* segment_mark, sec_info_type, use_rela_p, has_tls_reloc, */
62 /* has_gp_reloc, need_finalize_relax, reloc_done, */
64 /* vma, lma, size, rawsize, */
66 /* output_offset, output_section, alignment_power, */
68 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */
70 /* line_filepos, userdata, contents, lineno, lineno_count, */
71 0, NULL
, NULL
, NULL
, 0,
72 /* entsize, kept_section, moving_line_filepos, */
74 /* target_index, used_by_bfd, constructor_chain, owner, */
80 /* map_head, map_tail */
84 /* Create an ECOFF object. */
87 _bfd_ecoff_mkobject (bfd
*abfd
)
89 bfd_size_type amt
= sizeof (ecoff_data_type
);
91 abfd
->tdata
.ecoff_obj_data
= bfd_zalloc (abfd
, amt
);
92 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
98 /* This is a hook called by coff_real_object_p to create any backend
99 specific information. */
102 _bfd_ecoff_mkobject_hook (bfd
*abfd
, void * filehdr
, void * aouthdr
)
104 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
105 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
106 ecoff_data_type
*ecoff
;
108 if (! _bfd_ecoff_mkobject (abfd
))
111 ecoff
= ecoff_data (abfd
);
113 ecoff
->sym_filepos
= internal_f
->f_symptr
;
115 if (internal_a
!= NULL
)
119 ecoff
->text_start
= internal_a
->text_start
;
120 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
121 ecoff
->gp
= internal_a
->gp_value
;
122 ecoff
->gprmask
= internal_a
->gprmask
;
123 for (i
= 0; i
< 4; i
++)
124 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
125 ecoff
->fprmask
= internal_a
->fprmask
;
126 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
127 abfd
->flags
|= D_PAGED
;
129 abfd
->flags
&=~ D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
138 return (void *) ecoff
;
141 /* Initialize a new section. */
144 _bfd_ecoff_new_section_hook (bfd
*abfd
, asection
*section
)
154 { _TEXT
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
155 { _INIT
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
156 { _FINI
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
157 { _DATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
},
158 { _SDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
},
159 { _RDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
160 { _LIT8
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
161 { _LIT4
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
162 { _RCONST
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
163 { _PDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
166 /* An Irix 4 shared libary. */
167 { _LIB
, SEC_COFF_SHARED_LIBRARY
}
170 section
->alignment_power
= 4;
172 for (i
= 0; i
< ARRAY_SIZE (section_flags
); i
++)
173 if (streq (section
->name
, section_flags
[i
].name
))
175 section
->flags
|= section_flags
[i
].flags
;
180 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
181 uncertain about .init on some systems and I don't know how shared
184 return _bfd_generic_new_section_hook (abfd
, section
);
187 /* Determine the machine architecture and type. This is called from
188 the generic COFF routines. It is the inverse of ecoff_get_magic,
189 below. This could be an ECOFF backend routine, with one version
190 for each target, but there aren't all that many ECOFF targets. */
193 _bfd_ecoff_set_arch_mach_hook (bfd
*abfd
, void * filehdr
)
195 struct internal_filehdr
*internal_f
= filehdr
;
196 enum bfd_architecture arch
;
199 switch (internal_f
->f_magic
)
202 case MIPS_MAGIC_LITTLE
:
204 arch
= bfd_arch_mips
;
205 mach
= bfd_mach_mips3000
;
208 case MIPS_MAGIC_LITTLE2
:
209 case MIPS_MAGIC_BIG2
:
210 /* MIPS ISA level 2: the r6000. */
211 arch
= bfd_arch_mips
;
212 mach
= bfd_mach_mips6000
;
215 case MIPS_MAGIC_LITTLE3
:
216 case MIPS_MAGIC_BIG3
:
217 /* MIPS ISA level 3: the r4000. */
218 arch
= bfd_arch_mips
;
219 mach
= bfd_mach_mips4000
;
223 arch
= bfd_arch_alpha
;
228 arch
= bfd_arch_obscure
;
233 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
236 /* Get the magic number to use based on the architecture and machine.
237 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
240 ecoff_get_magic (bfd
*abfd
)
244 switch (bfd_get_arch (abfd
))
247 switch (bfd_get_mach (abfd
))
251 case bfd_mach_mips3000
:
252 big
= MIPS_MAGIC_BIG
;
253 little
= MIPS_MAGIC_LITTLE
;
256 case bfd_mach_mips6000
:
257 big
= MIPS_MAGIC_BIG2
;
258 little
= MIPS_MAGIC_LITTLE2
;
261 case bfd_mach_mips4000
:
262 big
= MIPS_MAGIC_BIG3
;
263 little
= MIPS_MAGIC_LITTLE3
;
267 return bfd_big_endian (abfd
) ? big
: little
;
278 /* Get the section s_flags to use for a section. */
281 ecoff_sec_to_styp_flags (const char *name
, flagword flags
)
291 { _TEXT
, STYP_TEXT
},
292 { _DATA
, STYP_DATA
},
293 { _SDATA
, STYP_SDATA
},
294 { _RDATA
, STYP_RDATA
},
295 { _LITA
, STYP_LITA
},
296 { _LIT8
, STYP_LIT8
},
297 { _LIT4
, STYP_LIT4
},
299 { _SBSS
, STYP_SBSS
},
300 { _INIT
, STYP_ECOFF_INIT
},
301 { _FINI
, STYP_ECOFF_FINI
},
302 { _PDATA
, STYP_PDATA
},
303 { _XDATA
, STYP_XDATA
},
304 { _LIB
, STYP_ECOFF_LIB
},
306 { _HASH
, STYP_HASH
},
307 { _DYNAMIC
, STYP_DYNAMIC
},
308 { _LIBLIST
, STYP_LIBLIST
},
309 { _RELDYN
, STYP_RELDYN
},
310 { _CONFLIC
, STYP_CONFLIC
},
311 { _DYNSTR
, STYP_DYNSTR
},
312 { _DYNSYM
, STYP_DYNSYM
},
313 { _RCONST
, STYP_RCONST
}
317 for (i
= 0; i
< ARRAY_SIZE (styp_flags
); i
++)
318 if (streq (name
, styp_flags
[i
].name
))
320 styp
= styp_flags
[i
].flags
;
326 if (streq (name
, _COMMENT
))
329 flags
&=~ SEC_NEVER_LOAD
;
331 else if (flags
& SEC_CODE
)
333 else if (flags
& SEC_DATA
)
335 else if (flags
& SEC_READONLY
)
337 else if (flags
& SEC_LOAD
)
343 if (flags
& SEC_NEVER_LOAD
)
349 /* Get the BFD flags to use for a section. */
352 _bfd_ecoff_styp_to_sec_flags (bfd
*abfd ATTRIBUTE_UNUSED
,
354 const char *name ATTRIBUTE_UNUSED
,
355 asection
*section ATTRIBUTE_UNUSED
,
356 flagword
* flags_ptr
)
358 struct internal_scnhdr
*internal_s
= hdr
;
359 long styp_flags
= internal_s
->s_flags
;
360 flagword sec_flags
= 0;
362 if (styp_flags
& STYP_NOLOAD
)
363 sec_flags
|= SEC_NEVER_LOAD
;
365 /* For 386 COFF, at least, an unloadable text or data section is
366 actually a shared library section. */
367 if ((styp_flags
& STYP_TEXT
)
368 || (styp_flags
& STYP_ECOFF_INIT
)
369 || (styp_flags
& STYP_ECOFF_FINI
)
370 || (styp_flags
& STYP_DYNAMIC
)
371 || (styp_flags
& STYP_LIBLIST
)
372 || (styp_flags
& STYP_RELDYN
)
373 || styp_flags
== STYP_CONFLIC
374 || (styp_flags
& STYP_DYNSTR
)
375 || (styp_flags
& STYP_DYNSYM
)
376 || (styp_flags
& STYP_HASH
))
378 if (sec_flags
& SEC_NEVER_LOAD
)
379 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
381 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
383 else if ((styp_flags
& STYP_DATA
)
384 || (styp_flags
& STYP_RDATA
)
385 || (styp_flags
& STYP_SDATA
)
386 || styp_flags
== STYP_PDATA
387 || styp_flags
== STYP_XDATA
388 || (styp_flags
& STYP_GOT
)
389 || styp_flags
== STYP_RCONST
)
391 if (sec_flags
& SEC_NEVER_LOAD
)
392 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
394 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
395 if ((styp_flags
& STYP_RDATA
)
396 || styp_flags
== STYP_PDATA
397 || styp_flags
== STYP_RCONST
)
398 sec_flags
|= SEC_READONLY
;
400 else if ((styp_flags
& STYP_BSS
)
401 || (styp_flags
& STYP_SBSS
))
402 sec_flags
|= SEC_ALLOC
;
403 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
404 sec_flags
|= SEC_NEVER_LOAD
;
405 else if ((styp_flags
& STYP_LITA
)
406 || (styp_flags
& STYP_LIT8
)
407 || (styp_flags
& STYP_LIT4
))
408 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
409 else if (styp_flags
& STYP_ECOFF_LIB
)
410 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
412 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
414 * flags_ptr
= sec_flags
;
418 /* Read in the symbolic header for an ECOFF object file. */
421 ecoff_slurp_symbolic_header (bfd
*abfd
)
423 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
424 bfd_size_type external_hdr_size
;
426 HDRR
*internal_symhdr
;
428 /* See if we've already read it in. */
429 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
430 backend
->debug_swap
.sym_magic
)
433 /* See whether there is a symbolic header. */
434 if (ecoff_data (abfd
)->sym_filepos
== 0)
436 bfd_get_symcount (abfd
) = 0;
440 /* At this point bfd_get_symcount (abfd) holds the number of symbols
441 as read from the file header, but on ECOFF this is always the
442 size of the symbolic information header. It would be cleaner to
443 handle this when we first read the file in coffgen.c. */
444 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
445 if (bfd_get_symcount (abfd
) != external_hdr_size
)
447 bfd_set_error (bfd_error_bad_value
);
451 /* Read the symbolic information header. */
452 raw
= bfd_malloc (external_hdr_size
);
456 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0
457 || bfd_bread (raw
, external_hdr_size
, abfd
) != external_hdr_size
)
459 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
460 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
462 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
464 bfd_set_error (bfd_error_bad_value
);
468 /* Now we can get the correct number of symbols. */
469 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
470 + internal_symhdr
->iextMax
);
481 /* Read in and swap the important symbolic information for an ECOFF
482 object file. This is called by gdb via the read_debug_info entry
483 point in the backend structure. */
486 _bfd_ecoff_slurp_symbolic_info (bfd
*abfd
,
487 asection
*ignore ATTRIBUTE_UNUSED
,
488 struct ecoff_debug_info
*debug
)
490 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
491 HDRR
*internal_symhdr
;
492 bfd_size_type raw_base
;
493 bfd_size_type raw_size
;
495 bfd_size_type external_fdr_size
;
499 bfd_size_type raw_end
;
500 bfd_size_type cb_end
;
504 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
506 /* Check whether we've already gotten it, and whether there's any to
508 if (ecoff_data (abfd
)->raw_syments
!= NULL
)
510 if (ecoff_data (abfd
)->sym_filepos
== 0)
512 bfd_get_symcount (abfd
) = 0;
516 if (! ecoff_slurp_symbolic_header (abfd
))
519 internal_symhdr
= &debug
->symbolic_header
;
521 /* Read all the symbolic information at once. */
522 raw_base
= (ecoff_data (abfd
)->sym_filepos
523 + backend
->debug_swap
.external_hdr_size
);
525 /* Alpha ecoff makes the determination of raw_size difficult. It has
526 an undocumented debug data section between the symhdr and the first
527 documented section. And the ordering of the sections varies between
528 statically and dynamically linked executables.
529 If bfd supports SEEK_END someday, this code could be simplified. */
532 #define UPDATE_RAW_END(start, count, size) \
533 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
534 if (cb_end > raw_end) \
537 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
538 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
539 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
540 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
541 /* eraxxon@alumni.rice.edu: ioptMax refers to the size of the
542 optimization symtab, not the number of entries. */
543 UPDATE_RAW_END (cbOptOffset
, ioptMax
, sizeof (char));
544 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
545 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
546 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
547 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
548 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
549 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
551 #undef UPDATE_RAW_END
553 raw_size
= raw_end
- raw_base
;
556 ecoff_data (abfd
)->sym_filepos
= 0;
559 raw
= bfd_alloc (abfd
, raw_size
);
563 pos
= ecoff_data (abfd
)->sym_filepos
;
564 pos
+= backend
->debug_swap
.external_hdr_size
;
565 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
566 || bfd_bread (raw
, raw_size
, abfd
) != raw_size
)
568 bfd_release (abfd
, raw
);
572 ecoff_data (abfd
)->raw_syments
= raw
;
574 /* Get pointers for the numeric offsets in the HDRR structure. */
575 #define FIX(off1, off2, type) \
576 if (internal_symhdr->off1 == 0) \
577 debug->off2 = NULL; \
579 debug->off2 = (type) ((char *) raw \
580 + (internal_symhdr->off1 \
583 FIX (cbLineOffset
, line
, unsigned char *);
584 FIX (cbDnOffset
, external_dnr
, void *);
585 FIX (cbPdOffset
, external_pdr
, void *);
586 FIX (cbSymOffset
, external_sym
, void *);
587 FIX (cbOptOffset
, external_opt
, void *);
588 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
589 FIX (cbSsOffset
, ss
, char *);
590 FIX (cbSsExtOffset
, ssext
, char *);
591 FIX (cbFdOffset
, external_fdr
, void *);
592 FIX (cbRfdOffset
, external_rfd
, void *);
593 FIX (cbExtOffset
, external_ext
, void *);
596 /* I don't want to always swap all the data, because it will just
597 waste time and most programs will never look at it. The only
598 time the linker needs most of the debugging information swapped
599 is when linking big-endian and little-endian MIPS object files
600 together, which is not a common occurrence.
602 We need to look at the fdr to deal with a lot of information in
603 the symbols, so we swap them here. */
604 amt
= internal_symhdr
->ifdMax
;
605 amt
*= sizeof (struct fdr
);
606 debug
->fdr
= bfd_alloc (abfd
, amt
);
607 if (debug
->fdr
== NULL
)
609 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
610 fdr_ptr
= debug
->fdr
;
611 fraw_src
= (char *) debug
->external_fdr
;
612 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
613 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
614 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (void *) fraw_src
, fdr_ptr
);
619 /* ECOFF symbol table routines. The ECOFF symbol table is described
620 in gcc/mips-tfile.c. */
622 /* ECOFF uses two common sections. One is the usual one, and the
623 other is for small objects. All the small objects are kept
624 together, and then referenced via the gp pointer, which yields
625 faster assembler code. This is what we use for the small common
627 static asection ecoff_scom_section
;
628 static asymbol ecoff_scom_symbol
;
629 static asymbol
*ecoff_scom_symbol_ptr
;
631 /* Create an empty symbol. */
634 _bfd_ecoff_make_empty_symbol (bfd
*abfd
)
636 ecoff_symbol_type
*new;
637 bfd_size_type amt
= sizeof (ecoff_symbol_type
);
639 new = bfd_zalloc (abfd
, amt
);
642 new->symbol
.section
= NULL
;
646 new->symbol
.the_bfd
= abfd
;
650 /* Set the BFD flags and section for an ECOFF symbol. */
653 ecoff_set_symbol_info (bfd
*abfd
,
659 asym
->the_bfd
= abfd
;
660 asym
->value
= ecoff_sym
->value
;
661 asym
->section
= &bfd_debug_section
;
664 /* Most symbol types are just for debugging. */
665 switch (ecoff_sym
->st
)
674 if (ECOFF_IS_STAB (ecoff_sym
))
676 asym
->flags
= BSF_DEBUGGING
;
681 asym
->flags
= BSF_DEBUGGING
;
686 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
688 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
691 asym
->flags
= BSF_LOCAL
;
692 /* Normally, a local stProc symbol will have a corresponding
693 external symbol. We mark the local symbol as a debugging
694 symbol, in order to prevent nm from printing both out.
695 Similarly, we mark stLabel and stabs symbols as debugging
696 symbols. In both cases, we do want to set the value
697 correctly based on the symbol class. */
698 if (ecoff_sym
->st
== stProc
699 || ecoff_sym
->st
== stLabel
700 || ECOFF_IS_STAB (ecoff_sym
))
701 asym
->flags
|= BSF_DEBUGGING
;
704 if (ecoff_sym
->st
== stProc
|| ecoff_sym
->st
== stStaticProc
)
705 asym
->flags
|= BSF_FUNCTION
;
707 switch (ecoff_sym
->sc
)
710 /* Used for compiler generated labels. Leave them in the
711 debugging section, and mark them as local. If BSF_DEBUGGING
712 is set, then nm does not display them for some reason. If no
713 flags are set then the linker whines about them. */
714 asym
->flags
= BSF_LOCAL
;
717 asym
->section
= bfd_make_section_old_way (abfd
, _TEXT
);
718 asym
->value
-= asym
->section
->vma
;
721 asym
->section
= bfd_make_section_old_way (abfd
, _DATA
);
722 asym
->value
-= asym
->section
->vma
;
725 asym
->section
= bfd_make_section_old_way (abfd
, _BSS
);
726 asym
->value
-= asym
->section
->vma
;
729 asym
->flags
= BSF_DEBUGGING
;
732 asym
->section
= bfd_abs_section_ptr
;
735 asym
->section
= bfd_und_section_ptr
;
745 asym
->flags
= BSF_DEBUGGING
;
748 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
749 asym
->value
-= asym
->section
->vma
;
752 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
753 asym
->value
-= asym
->section
->vma
;
756 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
757 asym
->value
-= asym
->section
->vma
;
760 asym
->flags
= BSF_DEBUGGING
;
763 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
765 asym
->section
= bfd_com_section_ptr
;
771 if (ecoff_scom_section
.name
== NULL
)
773 /* Initialize the small common section. */
774 ecoff_scom_section
.name
= SCOMMON
;
775 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
776 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
777 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
778 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
779 ecoff_scom_symbol
.name
= SCOMMON
;
780 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
781 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
782 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
784 asym
->section
= &ecoff_scom_section
;
789 asym
->flags
= BSF_DEBUGGING
;
792 asym
->section
= bfd_und_section_ptr
;
797 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
798 asym
->value
-= asym
->section
->vma
;
803 asym
->flags
= BSF_DEBUGGING
;
806 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
807 asym
->value
-= asym
->section
->vma
;
810 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
811 asym
->value
-= asym
->section
->vma
;
817 /* Look for special constructors symbols and make relocation entries
818 in a special construction section. These are produced by the
819 -fgnu-linker argument to g++. */
820 if (ECOFF_IS_STAB (ecoff_sym
))
822 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
831 /* Mark the symbol as a constructor. */
832 asym
->flags
|= BSF_CONSTRUCTOR
;
839 /* Read an ECOFF symbol table. */
842 _bfd_ecoff_slurp_symbol_table (bfd
*abfd
)
844 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
845 const bfd_size_type external_ext_size
846 = backend
->debug_swap
.external_ext_size
;
847 const bfd_size_type external_sym_size
848 = backend
->debug_swap
.external_sym_size
;
849 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
850 = backend
->debug_swap
.swap_ext_in
;
851 void (* const swap_sym_in
) (bfd
*, void *, SYMR
*)
852 = backend
->debug_swap
.swap_sym_in
;
853 bfd_size_type internal_size
;
854 ecoff_symbol_type
*internal
;
855 ecoff_symbol_type
*internal_ptr
;
861 /* If we've already read in the symbol table, do nothing. */
862 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
865 /* Get the symbolic information. */
866 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
,
867 &ecoff_data (abfd
)->debug_info
))
869 if (bfd_get_symcount (abfd
) == 0)
872 internal_size
= bfd_get_symcount (abfd
);
873 internal_size
*= sizeof (ecoff_symbol_type
);
874 internal
= bfd_alloc (abfd
, internal_size
);
875 if (internal
== NULL
)
878 internal_ptr
= internal
;
879 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
881 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
882 * external_ext_size
));
883 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
887 (*swap_ext_in
) (abfd
, (void *) eraw_src
, &internal_esym
);
888 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
889 + internal_esym
.asym
.iss
);
890 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
891 &internal_ptr
->symbol
, 1,
892 internal_esym
.weakext
))
894 /* The alpha uses a negative ifd field for section symbols. */
895 if (internal_esym
.ifd
>= 0)
896 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
897 + internal_esym
.ifd
);
899 internal_ptr
->fdr
= NULL
;
900 internal_ptr
->local
= FALSE
;
901 internal_ptr
->native
= (void *) eraw_src
;
904 /* The local symbols must be accessed via the fdr's, because the
905 string and aux indices are relative to the fdr information. */
906 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
907 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
908 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
913 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
914 + fdr_ptr
->isymBase
* external_sym_size
);
915 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
918 lraw_src
+= external_sym_size
, internal_ptr
++)
922 (*swap_sym_in
) (abfd
, (void *) lraw_src
, &internal_sym
);
923 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
926 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
927 &internal_ptr
->symbol
, 0, 0))
929 internal_ptr
->fdr
= fdr_ptr
;
930 internal_ptr
->local
= TRUE
;
931 internal_ptr
->native
= (void *) lraw_src
;
935 ecoff_data (abfd
)->canonical_symbols
= internal
;
940 /* Return the amount of space needed for the canonical symbols. */
943 _bfd_ecoff_get_symtab_upper_bound (bfd
*abfd
)
945 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
,
946 &ecoff_data (abfd
)->debug_info
))
949 if (bfd_get_symcount (abfd
) == 0)
952 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
955 /* Get the canonical symbols. */
958 _bfd_ecoff_canonicalize_symtab (bfd
*abfd
, asymbol
**alocation
)
960 unsigned int counter
= 0;
961 ecoff_symbol_type
*symbase
;
962 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
964 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
966 if (bfd_get_symcount (abfd
) == 0)
969 symbase
= ecoff_data (abfd
)->canonical_symbols
;
970 while (counter
< bfd_get_symcount (abfd
))
972 *(location
++) = symbase
++;
976 return bfd_get_symcount (abfd
);
979 /* Turn ECOFF type information into a printable string.
980 ecoff_emit_aggregate and ecoff_type_to_string are from
981 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
983 /* Write aggregate information to a string. */
986 ecoff_emit_aggregate (bfd
*abfd
,
993 const struct ecoff_debug_swap
* const debug_swap
=
994 &ecoff_backend (abfd
)->debug_swap
;
995 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
996 unsigned int ifd
= rndx
->rfd
;
997 unsigned int indx
= rndx
->index
;
1003 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1004 struct return type of a procedure compiled without -g. */
1005 if (ifd
== 0xffffffff
1006 || (rndx
->rfd
== 0xfff && indx
== 0))
1007 name
= "<undefined>";
1008 else if (indx
== indexNil
)
1014 if (debug_info
->external_rfd
== NULL
)
1015 fdr
= debug_info
->fdr
+ ifd
;
1020 (*debug_swap
->swap_rfd_in
) (abfd
,
1021 ((char *) debug_info
->external_rfd
1022 + ((fdr
->rfdBase
+ ifd
)
1023 * debug_swap
->external_rfd_size
)),
1025 fdr
= debug_info
->fdr
+ rfd
;
1028 indx
+= fdr
->isymBase
;
1030 (*debug_swap
->swap_sym_in
) (abfd
,
1031 ((char *) debug_info
->external_sym
1032 + indx
* debug_swap
->external_sym_size
),
1035 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1039 "%s %s { ifd = %u, index = %lu }",
1042 + debug_info
->symbolic_header
.iextMax
));
1045 /* Convert the type information to string format. */
1048 ecoff_type_to_string (bfd
*abfd
, FDR
*fdr
, unsigned int indx
)
1050 union aux_ext
*aux_ptr
;
1060 unsigned int basic_type
;
1063 static char buffer2
[1024];
1068 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1069 bigendian
= fdr
->fBigendian
;
1071 for (i
= 0; i
< 7; i
++)
1073 qualifiers
[i
].low_bound
= 0;
1074 qualifiers
[i
].high_bound
= 0;
1075 qualifiers
[i
].stride
= 0;
1078 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1079 return "-1 (no type)";
1080 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1082 basic_type
= u
.ti
.bt
;
1083 qualifiers
[0].type
= u
.ti
.tq0
;
1084 qualifiers
[1].type
= u
.ti
.tq1
;
1085 qualifiers
[2].type
= u
.ti
.tq2
;
1086 qualifiers
[3].type
= u
.ti
.tq3
;
1087 qualifiers
[4].type
= u
.ti
.tq4
;
1088 qualifiers
[5].type
= u
.ti
.tq5
;
1089 qualifiers
[6].type
= tqNil
;
1091 /* Go get the basic type. */
1094 case btNil
: /* Undefined. */
1098 case btAdr
: /* Address - integer same size as pointer. */
1099 strcpy (p1
, "address");
1102 case btChar
: /* Character. */
1103 strcpy (p1
, "char");
1106 case btUChar
: /* Unsigned character. */
1107 strcpy (p1
, "unsigned char");
1110 case btShort
: /* Short. */
1111 strcpy (p1
, "short");
1114 case btUShort
: /* Unsigned short. */
1115 strcpy (p1
, "unsigned short");
1118 case btInt
: /* Int. */
1122 case btUInt
: /* Unsigned int. */
1123 strcpy (p1
, "unsigned int");
1126 case btLong
: /* Long. */
1127 strcpy (p1
, "long");
1130 case btULong
: /* Unsigned long. */
1131 strcpy (p1
, "unsigned long");
1134 case btFloat
: /* Float (real). */
1135 strcpy (p1
, "float");
1138 case btDouble
: /* Double (real). */
1139 strcpy (p1
, "double");
1142 /* Structures add 1-2 aux words:
1143 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1144 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1146 case btStruct
: /* Structure (Record). */
1147 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1148 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1149 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1151 indx
++; /* Skip aux words. */
1154 /* Unions add 1-2 aux words:
1155 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1156 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1158 case btUnion
: /* Union. */
1159 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1160 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1161 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1163 indx
++; /* Skip aux words. */
1166 /* Enumerations add 1-2 aux words:
1167 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1168 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1170 case btEnum
: /* Enumeration. */
1171 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1172 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1173 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1175 indx
++; /* Skip aux words. */
1178 case btTypedef
: /* Defined via a typedef, isymRef points. */
1179 strcpy (p1
, "typedef");
1182 case btRange
: /* Subrange of int. */
1183 strcpy (p1
, "subrange");
1186 case btSet
: /* Pascal sets. */
1190 case btComplex
: /* Fortran complex. */
1191 strcpy (p1
, "complex");
1194 case btDComplex
: /* Fortran double complex. */
1195 strcpy (p1
, "double complex");
1198 case btIndirect
: /* Forward or unnamed typedef. */
1199 strcpy (p1
, "forward/unamed typedef");
1202 case btFixedDec
: /* Fixed Decimal. */
1203 strcpy (p1
, "fixed decimal");
1206 case btFloatDec
: /* Float Decimal. */
1207 strcpy (p1
, "float decimal");
1210 case btString
: /* Varying Length Character String. */
1211 strcpy (p1
, "string");
1214 case btBit
: /* Aligned Bit String. */
1218 case btPicture
: /* Picture. */
1219 strcpy (p1
, "picture");
1222 case btVoid
: /* Void. */
1223 strcpy (p1
, "void");
1227 sprintf (p1
, _("Unknown basic type %d"), (int) basic_type
);
1231 p1
+= strlen (buffer1
);
1233 /* If this is a bitfield, get the bitsize. */
1238 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1239 sprintf (p1
, " : %d", bitsize
);
1240 p1
+= strlen (buffer1
);
1243 /* Deal with any qualifiers. */
1244 if (qualifiers
[0].type
!= tqNil
)
1246 /* Snarf up any array bounds in the correct order. Arrays
1247 store 5 successive words in the aux. table:
1248 word 0 RNDXR to type of the bounds (ie, int)
1249 word 1 Current file descriptor index
1251 word 3 high bound (or -1 if [])
1252 word 4 stride size in bits. */
1253 for (i
= 0; i
< 7; i
++)
1255 if (qualifiers
[i
].type
== tqArray
)
1257 qualifiers
[i
].low_bound
=
1258 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1259 qualifiers
[i
].high_bound
=
1260 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1261 qualifiers
[i
].stride
=
1262 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1267 /* Now print out the qualifiers. */
1268 for (i
= 0; i
< 6; i
++)
1270 switch (qualifiers
[i
].type
)
1277 strcpy (p2
, "ptr to ");
1278 p2
+= sizeof ("ptr to ")-1;
1282 strcpy (p2
, "volatile ");
1283 p2
+= sizeof ("volatile ")-1;
1287 strcpy (p2
, "far ");
1288 p2
+= sizeof ("far ")-1;
1292 strcpy (p2
, "func. ret. ");
1293 p2
+= sizeof ("func. ret. ");
1298 int first_array
= i
;
1301 /* Print array bounds reversed (ie, in the order the C
1302 programmer writes them). C is such a fun language.... */
1303 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1306 for (j
= i
; j
>= first_array
; j
--)
1308 strcpy (p2
, "array [");
1309 p2
+= sizeof ("array [")-1;
1310 if (qualifiers
[j
].low_bound
!= 0)
1312 "%ld:%ld {%ld bits}",
1313 (long) qualifiers
[j
].low_bound
,
1314 (long) qualifiers
[j
].high_bound
,
1315 (long) qualifiers
[j
].stride
);
1317 else if (qualifiers
[j
].high_bound
!= -1)
1320 (long) (qualifiers
[j
].high_bound
+ 1),
1321 (long) (qualifiers
[j
].stride
));
1324 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1327 strcpy (p2
, "] of ");
1328 p2
+= sizeof ("] of ")-1;
1336 strcpy (p2
, buffer1
);
1340 /* Return information about ECOFF symbol SYMBOL in RET. */
1343 _bfd_ecoff_get_symbol_info (bfd
*abfd ATTRIBUTE_UNUSED
,
1347 bfd_symbol_info (symbol
, ret
);
1350 /* Return whether this is a local label. */
1353 _bfd_ecoff_bfd_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
1356 return name
[0] == '$';
1359 /* Print information about an ECOFF symbol. */
1362 _bfd_ecoff_print_symbol (bfd
*abfd
,
1365 bfd_print_symbol_type how
)
1367 const struct ecoff_debug_swap
* const debug_swap
1368 = &ecoff_backend (abfd
)->debug_swap
;
1369 FILE *file
= (FILE *)filep
;
1373 case bfd_print_symbol_name
:
1374 fprintf (file
, "%s", symbol
->name
);
1376 case bfd_print_symbol_more
:
1377 if (ecoffsymbol (symbol
)->local
)
1381 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1383 fprintf (file
, "ecoff local ");
1384 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1385 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1386 (unsigned) ecoff_sym
.sc
);
1392 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1394 fprintf (file
, "ecoff extern ");
1395 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1396 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1397 (unsigned) ecoff_ext
.asym
.sc
);
1400 case bfd_print_symbol_all
:
1401 /* Print out the symbols in a reasonable way. */
1410 if (ecoffsymbol (symbol
)->local
)
1412 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1415 pos
= ((((char *) ecoffsymbol (symbol
)->native
1416 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1417 / debug_swap
->external_sym_size
)
1418 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1425 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1428 pos
= (((char *) ecoffsymbol (symbol
)->native
1429 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1430 / debug_swap
->external_ext_size
);
1431 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1432 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1433 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1436 fprintf (file
, "[%3d] %c ",
1438 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1439 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1440 (unsigned) ecoff_ext
.asym
.st
,
1441 (unsigned) ecoff_ext
.asym
.sc
,
1442 (unsigned) ecoff_ext
.asym
.index
,
1443 jmptbl
, cobol_main
, weakext
,
1446 if (ecoffsymbol (symbol
)->fdr
!= NULL
1447 && ecoff_ext
.asym
.index
!= indexNil
)
1452 bfd_size_type sym_base
;
1453 union aux_ext
*aux_base
;
1455 fdr
= ecoffsymbol (symbol
)->fdr
;
1456 indx
= ecoff_ext
.asym
.index
;
1458 /* sym_base is used to map the fdr relative indices which
1459 appear in the file to the position number which we are
1461 sym_base
= fdr
->isymBase
;
1462 if (ecoffsymbol (symbol
)->local
)
1464 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1466 /* aux_base is the start of the aux entries for this file;
1467 asym.index is an offset from this. */
1468 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1471 /* The aux entries are stored in host byte order; the
1472 order is indicated by a bit in the fdr. */
1473 bigendian
= fdr
->fBigendian
;
1475 /* This switch is basically from gcc/mips-tdump.c. */
1476 switch (ecoff_ext
.asym
.st
)
1484 fprintf (file
, _("\n End+1 symbol: %ld"),
1485 (long) (indx
+ sym_base
));
1489 if (ecoff_ext
.asym
.sc
== scText
1490 || ecoff_ext
.asym
.sc
== scInfo
)
1491 fprintf (file
, _("\n First symbol: %ld"),
1492 (long) (indx
+ sym_base
));
1494 fprintf (file
, _("\n First symbol: %ld"),
1496 (AUX_GET_ISYM (bigendian
,
1497 &aux_base
[ecoff_ext
.asym
.index
])
1503 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1505 else if (ecoffsymbol (symbol
)->local
)
1506 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1508 (AUX_GET_ISYM (bigendian
,
1509 &aux_base
[ecoff_ext
.asym
.index
])
1511 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1513 fprintf (file
, _("\n Local symbol: %ld"),
1516 + (ecoff_data (abfd
)
1517 ->debug_info
.symbolic_header
.iextMax
)));
1521 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1522 (long) (indx
+ sym_base
));
1526 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1527 (long) (indx
+ sym_base
));
1531 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1532 (long) (indx
+ sym_base
));
1536 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1537 fprintf (file
, _("\n Type: %s"),
1538 ecoff_type_to_string (abfd
, fdr
, indx
));
1547 /* Read in the relocs for a section. */
1550 ecoff_slurp_reloc_table (bfd
*abfd
,
1554 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1555 arelent
*internal_relocs
;
1556 bfd_size_type external_reloc_size
;
1558 char *external_relocs
;
1562 if (section
->relocation
!= NULL
1563 || section
->reloc_count
== 0
1564 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1567 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1570 amt
= section
->reloc_count
;
1571 amt
*= sizeof (arelent
);
1572 internal_relocs
= bfd_alloc (abfd
, amt
);
1574 external_reloc_size
= backend
->external_reloc_size
;
1575 amt
= external_reloc_size
* section
->reloc_count
;
1576 external_relocs
= bfd_alloc (abfd
, amt
);
1577 if (internal_relocs
== NULL
|| external_relocs
== NULL
)
1579 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1581 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
1584 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1586 struct internal_reloc intern
;
1588 (*backend
->swap_reloc_in
) (abfd
,
1589 external_relocs
+ i
* external_reloc_size
,
1592 if (intern
.r_extern
)
1594 /* r_symndx is an index into the external symbols. */
1595 BFD_ASSERT (intern
.r_symndx
>= 0
1597 < (ecoff_data (abfd
)
1598 ->debug_info
.symbolic_header
.iextMax
)));
1599 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1602 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1603 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1605 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1610 const char *sec_name
;
1613 /* r_symndx is a section key. */
1614 switch (intern
.r_symndx
)
1616 case RELOC_SECTION_TEXT
: sec_name
= _TEXT
; break;
1617 case RELOC_SECTION_RDATA
: sec_name
= _RDATA
; break;
1618 case RELOC_SECTION_DATA
: sec_name
= _DATA
; break;
1619 case RELOC_SECTION_SDATA
: sec_name
= _SDATA
; break;
1620 case RELOC_SECTION_SBSS
: sec_name
= _SBSS
; break;
1621 case RELOC_SECTION_BSS
: sec_name
= _BSS
; break;
1622 case RELOC_SECTION_INIT
: sec_name
= _INIT
; break;
1623 case RELOC_SECTION_LIT8
: sec_name
= _LIT8
; break;
1624 case RELOC_SECTION_LIT4
: sec_name
= _LIT4
; break;
1625 case RELOC_SECTION_XDATA
: sec_name
= _XDATA
; break;
1626 case RELOC_SECTION_PDATA
: sec_name
= _PDATA
; break;
1627 case RELOC_SECTION_FINI
: sec_name
= _FINI
; break;
1628 case RELOC_SECTION_LITA
: sec_name
= _LITA
; break;
1629 case RELOC_SECTION_RCONST
: sec_name
= _RCONST
; break;
1633 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1636 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1638 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1641 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1643 /* Let the backend select the howto field and do any other
1644 required processing. */
1645 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1648 bfd_release (abfd
, external_relocs
);
1650 section
->relocation
= internal_relocs
;
1655 /* Get a canonical list of relocs. */
1658 _bfd_ecoff_canonicalize_reloc (bfd
*abfd
,
1665 if (section
->flags
& SEC_CONSTRUCTOR
)
1667 arelent_chain
*chain
;
1669 /* This section has relocs made up by us, not the file, so take
1670 them out of their chain and place them into the data area
1672 for (count
= 0, chain
= section
->constructor_chain
;
1673 count
< section
->reloc_count
;
1674 count
++, chain
= chain
->next
)
1675 *relptr
++ = &chain
->relent
;
1681 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1684 tblptr
= section
->relocation
;
1686 for (count
= 0; count
< section
->reloc_count
; count
++)
1687 *relptr
++ = tblptr
++;
1692 return section
->reloc_count
;
1695 /* Provided a BFD, a section and an offset into the section, calculate
1696 and return the name of the source file and the line nearest to the
1700 _bfd_ecoff_find_nearest_line (bfd
*abfd
,
1702 asymbol
**ignore_symbols ATTRIBUTE_UNUSED
,
1704 const char **filename_ptr
,
1705 const char **functionname_ptr
,
1706 unsigned int *retline_ptr
)
1708 const struct ecoff_debug_swap
* const debug_swap
1709 = &ecoff_backend (abfd
)->debug_swap
;
1710 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1711 struct ecoff_find_line
*line_info
;
1713 /* Make sure we have the FDR's. */
1714 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
, debug_info
)
1715 || bfd_get_symcount (abfd
) == 0)
1718 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1720 bfd_size_type amt
= sizeof (struct ecoff_find_line
);
1722 ecoff_data (abfd
)->find_line_info
= bfd_zalloc (abfd
, amt
);
1723 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1726 line_info
= ecoff_data (abfd
)->find_line_info
;
1728 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1729 debug_swap
, line_info
, filename_ptr
,
1730 functionname_ptr
, retline_ptr
);
1733 /* Copy private BFD data. This is called by objcopy and strip. We
1734 use it to copy the ECOFF debugging information from one BFD to the
1735 other. It would be theoretically possible to represent the ECOFF
1736 debugging information in the symbol table. However, it would be a
1737 lot of work, and there would be little gain (gas, gdb, and ld
1738 already access the ECOFF debugging information via the
1739 ecoff_debug_info structure, and that structure would have to be
1740 retained in order to support ECOFF debugging in MIPS ELF).
1742 The debugging information for the ECOFF external symbols comes from
1743 the symbol table, so this function only handles the other debugging
1747 _bfd_ecoff_bfd_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
1749 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1750 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1752 asymbol
**sym_ptr_ptr
;
1756 /* We only want to copy information over if both BFD's use ECOFF
1758 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1759 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1762 /* Copy the GP value and the register masks. */
1763 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1764 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1765 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1766 for (i
= 0; i
< 3; i
++)
1767 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1769 /* Copy the version stamp. */
1770 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1772 /* If there are no symbols, don't copy any debugging information. */
1773 c
= bfd_get_symcount (obfd
);
1774 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1775 if (c
== 0 || sym_ptr_ptr
== NULL
)
1778 /* See if there are any local symbols. */
1780 for (; c
> 0; c
--, sym_ptr_ptr
++)
1782 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1791 /* There are some local symbols. We just bring over all the
1792 debugging information. FIXME: This is not quite the right
1793 thing to do. If the user has asked us to discard all
1794 debugging information, then we are probably going to wind up
1795 keeping it because there will probably be some local symbol
1796 which objcopy did not discard. We should actually break
1797 apart the debugging information and only keep that which
1798 applies to the symbols we want to keep. */
1799 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1800 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1801 oinfo
->line
= iinfo
->line
;
1803 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1804 oinfo
->external_dnr
= iinfo
->external_dnr
;
1806 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1807 oinfo
->external_pdr
= iinfo
->external_pdr
;
1809 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1810 oinfo
->external_sym
= iinfo
->external_sym
;
1812 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1813 oinfo
->external_opt
= iinfo
->external_opt
;
1815 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1816 oinfo
->external_aux
= iinfo
->external_aux
;
1818 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1819 oinfo
->ss
= iinfo
->ss
;
1821 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1822 oinfo
->external_fdr
= iinfo
->external_fdr
;
1824 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1825 oinfo
->external_rfd
= iinfo
->external_rfd
;
1829 /* We are discarding all the local symbol information. Look
1830 through the external symbols and remove all references to FDR
1831 or aux information. */
1832 c
= bfd_get_symcount (obfd
);
1833 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1834 for (; c
> 0; c
--, sym_ptr_ptr
++)
1838 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1839 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1841 esym
.asym
.index
= indexNil
;
1842 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1843 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1850 /* Set the architecture. The supported architecture is stored in the
1851 backend pointer. We always set the architecture anyhow, since many
1852 callers ignore the return value. */
1855 _bfd_ecoff_set_arch_mach (bfd
*abfd
,
1856 enum bfd_architecture arch
,
1857 unsigned long machine
)
1859 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1860 return arch
== ecoff_backend (abfd
)->arch
;
1863 /* Get the size of the section headers. */
1866 _bfd_ecoff_sizeof_headers (bfd
*abfd
,
1867 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1874 for (current
= abfd
->sections
;
1876 current
= current
->next
)
1879 ret
= (bfd_coff_filhsz (abfd
)
1880 + bfd_coff_aoutsz (abfd
)
1881 + c
* bfd_coff_scnhsz (abfd
));
1882 return BFD_ALIGN (ret
, 16);
1885 /* Get the contents of a section. */
1888 _bfd_ecoff_get_section_contents (bfd
*abfd
,
1892 bfd_size_type count
)
1894 return _bfd_generic_get_section_contents (abfd
, section
, location
,
1898 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
1899 called via qsort. */
1902 ecoff_sort_hdrs (const void * arg1
, const void * arg2
)
1904 const asection
*hdr1
= *(const asection
**) arg1
;
1905 const asection
*hdr2
= *(const asection
**) arg2
;
1907 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
1909 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
1914 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
1917 if (hdr1
->vma
< hdr2
->vma
)
1919 else if (hdr1
->vma
> hdr2
->vma
)
1925 /* Calculate the file position for each section, and set
1929 ecoff_compute_section_file_positions (bfd
*abfd
)
1931 file_ptr sofar
, file_sofar
;
1932 asection
**sorted_hdrs
;
1936 bfd_boolean rdata_in_text
;
1937 bfd_boolean first_data
, first_nonalloc
;
1938 const bfd_vma round
= ecoff_backend (abfd
)->round
;
1941 sofar
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
1944 /* Sort the sections by VMA. */
1945 amt
= abfd
->section_count
;
1946 amt
*= sizeof (asection
*);
1947 sorted_hdrs
= bfd_malloc (amt
);
1948 if (sorted_hdrs
== NULL
)
1950 for (current
= abfd
->sections
, i
= 0;
1952 current
= current
->next
, i
++)
1953 sorted_hdrs
[i
] = current
;
1954 BFD_ASSERT (i
== abfd
->section_count
);
1956 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
1959 /* Some versions of the OSF linker put the .rdata section in the
1960 text segment, and some do not. */
1961 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
1964 for (i
= 0; i
< abfd
->section_count
; i
++)
1966 current
= sorted_hdrs
[i
];
1967 if (streq (current
->name
, _RDATA
))
1969 if ((current
->flags
& SEC_CODE
) == 0
1970 && ! streq (current
->name
, _PDATA
)
1971 && ! streq (current
->name
, _RCONST
))
1973 rdata_in_text
= FALSE
;
1978 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
1981 first_nonalloc
= TRUE
;
1982 for (i
= 0; i
< abfd
->section_count
; i
++)
1984 unsigned int alignment_power
;
1986 current
= sorted_hdrs
[i
];
1988 /* For the Alpha ECOFF .pdata section the lnnoptr field is
1989 supposed to indicate the number of .pdata entries that are
1990 really in the section. Each entry is 8 bytes. We store this
1991 away in line_filepos before increasing the section size. */
1992 if (streq (current
->name
, _PDATA
))
1993 current
->line_filepos
= current
->size
/ 8;
1995 alignment_power
= current
->alignment_power
;
1997 /* On Ultrix, the data sections in an executable file must be
1998 aligned to a page boundary within the file. This does not
1999 affect the section size, though. FIXME: Does this work for
2000 other platforms? It requires some modification for the
2001 Alpha, because .rdata on the Alpha goes with the text, not
2003 if ((abfd
->flags
& EXEC_P
) != 0
2004 && (abfd
->flags
& D_PAGED
) != 0
2006 && (current
->flags
& SEC_CODE
) == 0
2008 || ! streq (current
->name
, _RDATA
))
2009 && ! streq (current
->name
, _PDATA
)
2010 && ! streq (current
->name
, _RCONST
))
2012 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2013 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2016 else if (streq (current
->name
, _LIB
))
2018 /* On Irix 4, the location of contents of the .lib section
2019 from a shared library section is also rounded up to a
2022 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2023 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2025 else if (first_nonalloc
2026 && (current
->flags
& SEC_ALLOC
) == 0
2027 && (abfd
->flags
& D_PAGED
) != 0)
2029 /* Skip up to the next page for an unallocated section, such
2030 as the .comment section on the Alpha. This leaves room
2031 for the .bss section. */
2032 first_nonalloc
= FALSE
;
2033 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2034 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2037 /* Align the sections in the file to the same boundary on
2038 which they are aligned in virtual memory. */
2039 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2040 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2041 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2043 if ((abfd
->flags
& D_PAGED
) != 0
2044 && (current
->flags
& SEC_ALLOC
) != 0)
2046 sofar
+= (current
->vma
- sofar
) % round
;
2047 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2048 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2051 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2052 current
->filepos
= file_sofar
;
2054 sofar
+= current
->size
;
2055 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2056 file_sofar
+= current
->size
;
2058 /* Make sure that this section is of the right size too. */
2060 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2061 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2062 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2063 current
->size
+= sofar
- old_sofar
;
2069 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2074 /* Determine the location of the relocs for all the sections in the
2075 output file, as well as the location of the symbolic debugging
2078 static bfd_size_type
2079 ecoff_compute_reloc_file_positions (bfd
*abfd
)
2081 const bfd_size_type external_reloc_size
=
2082 ecoff_backend (abfd
)->external_reloc_size
;
2083 file_ptr reloc_base
;
2084 bfd_size_type reloc_size
;
2088 if (! abfd
->output_has_begun
)
2090 if (! ecoff_compute_section_file_positions (abfd
))
2092 abfd
->output_has_begun
= TRUE
;
2095 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2098 for (current
= abfd
->sections
;
2100 current
= current
->next
)
2102 if (current
->reloc_count
== 0)
2103 current
->rel_filepos
= 0;
2106 bfd_size_type relsize
;
2108 current
->rel_filepos
= reloc_base
;
2109 relsize
= current
->reloc_count
* external_reloc_size
;
2110 reloc_size
+= relsize
;
2111 reloc_base
+= relsize
;
2115 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2117 /* At least on Ultrix, the symbol table of an executable file must
2118 be aligned to a page boundary. FIXME: Is this true on other
2120 if ((abfd
->flags
& EXEC_P
) != 0
2121 && (abfd
->flags
& D_PAGED
) != 0)
2122 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2123 &~ (ecoff_backend (abfd
)->round
- 1));
2125 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2130 /* Set the contents of a section. */
2133 _bfd_ecoff_set_section_contents (bfd
*abfd
,
2135 const void * location
,
2137 bfd_size_type count
)
2141 /* This must be done first, because bfd_set_section_contents is
2142 going to set output_has_begun to TRUE. */
2143 if (! abfd
->output_has_begun
2144 && ! ecoff_compute_section_file_positions (abfd
))
2147 /* Handle the .lib section specially so that Irix 4 shared libraries
2148 work out. See coff_set_section_contents in coffcode.h. */
2149 if (streq (section
->name
, _LIB
))
2151 bfd_byte
*rec
, *recend
;
2153 rec
= (bfd_byte
*) location
;
2154 recend
= rec
+ count
;
2155 while (rec
< recend
)
2158 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2161 BFD_ASSERT (rec
== recend
);
2167 pos
= section
->filepos
+ offset
;
2168 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2169 || bfd_bwrite (location
, count
, abfd
) != count
)
2175 /* Get the GP value for an ECOFF file. This is a hook used by
2179 bfd_ecoff_get_gp_value (bfd
*abfd
)
2181 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2182 || bfd_get_format (abfd
) != bfd_object
)
2184 bfd_set_error (bfd_error_invalid_operation
);
2188 return ecoff_data (abfd
)->gp
;
2191 /* Set the GP value for an ECOFF file. This is a hook used by the
2195 bfd_ecoff_set_gp_value (bfd
*abfd
, bfd_vma gp_value
)
2197 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2198 || bfd_get_format (abfd
) != bfd_object
)
2200 bfd_set_error (bfd_error_invalid_operation
);
2204 ecoff_data (abfd
)->gp
= gp_value
;
2209 /* Set the register masks for an ECOFF file. This is a hook used by
2213 bfd_ecoff_set_regmasks (bfd
*abfd
,
2214 unsigned long gprmask
,
2215 unsigned long fprmask
,
2216 unsigned long *cprmask
)
2218 ecoff_data_type
*tdata
;
2220 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2221 || bfd_get_format (abfd
) != bfd_object
)
2223 bfd_set_error (bfd_error_invalid_operation
);
2227 tdata
= ecoff_data (abfd
);
2228 tdata
->gprmask
= gprmask
;
2229 tdata
->fprmask
= fprmask
;
2230 if (cprmask
!= NULL
)
2234 for (i
= 0; i
< 3; i
++)
2235 tdata
->cprmask
[i
] = cprmask
[i
];
2241 /* Get ECOFF EXTR information for an external symbol. This function
2242 is passed to bfd_ecoff_debug_externals. */
2245 ecoff_get_extr (asymbol
*sym
, EXTR
*esym
)
2247 ecoff_symbol_type
*ecoff_sym_ptr
;
2250 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2251 || ecoffsymbol (sym
)->native
== NULL
)
2253 /* Don't include debugging, local, or section symbols. */
2254 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2255 || (sym
->flags
& BSF_LOCAL
) != 0
2256 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2260 esym
->cobol_main
= 0;
2261 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2264 /* FIXME: we can do better than this for st and sc. */
2265 esym
->asym
.st
= stGlobal
;
2266 esym
->asym
.sc
= scAbs
;
2267 esym
->asym
.reserved
= 0;
2268 esym
->asym
.index
= indexNil
;
2272 ecoff_sym_ptr
= ecoffsymbol (sym
);
2274 if (ecoff_sym_ptr
->local
)
2277 input_bfd
= bfd_asymbol_bfd (sym
);
2278 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2279 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2281 /* If the symbol was defined by the linker, then esym will be
2282 undefined but sym will not be. Get a better class for such a
2284 if ((esym
->asym
.sc
== scUndefined
2285 || esym
->asym
.sc
== scSUndefined
)
2286 && ! bfd_is_und_section (bfd_get_section (sym
)))
2287 esym
->asym
.sc
= scAbs
;
2289 /* Adjust the FDR index for the symbol by that used for the input
2291 if (esym
->ifd
!= -1)
2293 struct ecoff_debug_info
*input_debug
;
2295 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2296 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2297 if (input_debug
->ifdmap
!= NULL
)
2298 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2304 /* Set the external symbol index. This routine is passed to
2305 bfd_ecoff_debug_externals. */
2308 ecoff_set_index (asymbol
*sym
, bfd_size_type indx
)
2310 ecoff_set_sym_index (sym
, indx
);
2313 /* Write out an ECOFF file. */
2316 _bfd_ecoff_write_object_contents (bfd
*abfd
)
2318 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2319 const bfd_vma round
= backend
->round
;
2320 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2321 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2322 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2323 const bfd_size_type external_hdr_size
2324 = backend
->debug_swap
.external_hdr_size
;
2325 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2326 void (* const adjust_reloc_out
) (bfd
*, const arelent
*, struct internal_reloc
*)
2327 = backend
->adjust_reloc_out
;
2328 void (* const swap_reloc_out
) (bfd
*, const struct internal_reloc
*, void *)
2329 = backend
->swap_reloc_out
;
2330 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2331 HDRR
* const symhdr
= &debug
->symbolic_header
;
2334 bfd_size_type reloc_size
;
2335 bfd_size_type text_size
;
2337 bfd_boolean set_text_start
;
2338 bfd_size_type data_size
;
2340 bfd_boolean set_data_start
;
2341 bfd_size_type bss_size
;
2343 void * reloc_buff
= NULL
;
2344 struct internal_filehdr internal_f
;
2345 struct internal_aouthdr internal_a
;
2348 /* Determine where the sections and relocs will go in the output
2350 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2353 for (current
= abfd
->sections
;
2355 current
= current
->next
)
2357 current
->target_index
= count
;
2361 if ((abfd
->flags
& D_PAGED
) != 0)
2362 text_size
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
2366 set_text_start
= FALSE
;
2369 set_data_start
= FALSE
;
2372 /* Write section headers to the file. */
2374 /* Allocate buff big enough to hold a section header,
2375 file header, or a.out header. */
2384 buff
= bfd_malloc (siz
);
2389 internal_f
.f_nscns
= 0;
2390 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2393 for (current
= abfd
->sections
;
2395 current
= current
->next
)
2397 struct internal_scnhdr section
;
2400 ++internal_f
.f_nscns
;
2402 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2404 /* This seems to be correct for Irix 4 shared libraries. */
2405 vma
= bfd_get_section_vma (abfd
, current
);
2406 if (streq (current
->name
, _LIB
))
2407 section
.s_vaddr
= 0;
2409 section
.s_vaddr
= vma
;
2411 section
.s_paddr
= current
->lma
;
2412 section
.s_size
= current
->size
;
2414 /* If this section is unloadable then the scnptr will be 0. */
2415 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2416 section
.s_scnptr
= 0;
2418 section
.s_scnptr
= current
->filepos
;
2419 section
.s_relptr
= current
->rel_filepos
;
2421 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2422 object file produced by the assembler is supposed to point to
2423 information about how much room is required by objects of
2424 various different sizes. I think this only matters if we
2425 want the linker to compute the best size to use, or
2426 something. I don't know what happens if the information is
2428 if (! streq (current
->name
, _PDATA
))
2429 section
.s_lnnoptr
= 0;
2432 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2433 hold the number of entries in the section (each entry is
2434 8 bytes). We stored this in the line_filepos field in
2435 ecoff_compute_section_file_positions. */
2436 section
.s_lnnoptr
= current
->line_filepos
;
2439 section
.s_nreloc
= current
->reloc_count
;
2440 section
.s_nlnno
= 0;
2441 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2444 if (bfd_coff_swap_scnhdr_out (abfd
, (void *) §ion
, buff
) == 0
2445 || bfd_bwrite (buff
, scnhsz
, abfd
) != scnhsz
)
2448 if ((section
.s_flags
& STYP_TEXT
) != 0
2449 || ((section
.s_flags
& STYP_RDATA
) != 0
2450 && ecoff_data (abfd
)->rdata_in_text
)
2451 || section
.s_flags
== STYP_PDATA
2452 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2453 || (section
.s_flags
& STYP_LIBLIST
) != 0
2454 || (section
.s_flags
& STYP_RELDYN
) != 0
2455 || section
.s_flags
== STYP_CONFLIC
2456 || (section
.s_flags
& STYP_DYNSTR
) != 0
2457 || (section
.s_flags
& STYP_DYNSYM
) != 0
2458 || (section
.s_flags
& STYP_HASH
) != 0
2459 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2460 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2461 || section
.s_flags
== STYP_RCONST
)
2463 text_size
+= current
->size
;
2464 if (! set_text_start
|| text_start
> vma
)
2467 set_text_start
= TRUE
;
2470 else if ((section
.s_flags
& STYP_RDATA
) != 0
2471 || (section
.s_flags
& STYP_DATA
) != 0
2472 || (section
.s_flags
& STYP_LITA
) != 0
2473 || (section
.s_flags
& STYP_LIT8
) != 0
2474 || (section
.s_flags
& STYP_LIT4
) != 0
2475 || (section
.s_flags
& STYP_SDATA
) != 0
2476 || section
.s_flags
== STYP_XDATA
2477 || (section
.s_flags
& STYP_GOT
) != 0)
2479 data_size
+= current
->size
;
2480 if (! set_data_start
|| data_start
> vma
)
2483 set_data_start
= TRUE
;
2486 else if ((section
.s_flags
& STYP_BSS
) != 0
2487 || (section
.s_flags
& STYP_SBSS
) != 0)
2488 bss_size
+= current
->size
;
2489 else if (section
.s_flags
== 0
2490 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2491 || section
.s_flags
== STYP_COMMENT
)
2497 /* Set up the file header. */
2498 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2500 /* We will NOT put a fucking timestamp in the header here. Every
2501 time you put it back, I will come in and take it out again. I'm
2502 sorry. This field does not belong here. We fill it with a 0 so
2503 it compares the same but is not a reasonable time. --
2505 internal_f
.f_timdat
= 0;
2507 if (bfd_get_symcount (abfd
) != 0)
2509 /* The ECOFF f_nsyms field is not actually the number of
2510 symbols, it's the size of symbolic information header. */
2511 internal_f
.f_nsyms
= external_hdr_size
;
2512 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2516 internal_f
.f_nsyms
= 0;
2517 internal_f
.f_symptr
= 0;
2520 internal_f
.f_opthdr
= aoutsz
;
2522 internal_f
.f_flags
= F_LNNO
;
2523 if (reloc_size
== 0)
2524 internal_f
.f_flags
|= F_RELFLG
;
2525 if (bfd_get_symcount (abfd
) == 0)
2526 internal_f
.f_flags
|= F_LSYMS
;
2527 if (abfd
->flags
& EXEC_P
)
2528 internal_f
.f_flags
|= F_EXEC
;
2530 if (bfd_little_endian (abfd
))
2531 internal_f
.f_flags
|= F_AR32WR
;
2533 internal_f
.f_flags
|= F_AR32W
;
2535 /* Set up the ``optional'' header. */
2536 if ((abfd
->flags
& D_PAGED
) != 0)
2537 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2539 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2541 /* FIXME: Is this really correct? */
2542 internal_a
.vstamp
= symhdr
->vstamp
;
2544 /* At least on Ultrix, these have to be rounded to page boundaries.
2545 FIXME: Is this true on other platforms? */
2546 if ((abfd
->flags
& D_PAGED
) != 0)
2548 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2549 internal_a
.text_start
= text_start
&~ (round
- 1);
2550 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2551 internal_a
.data_start
= data_start
&~ (round
- 1);
2555 internal_a
.tsize
= text_size
;
2556 internal_a
.text_start
= text_start
;
2557 internal_a
.dsize
= data_size
;
2558 internal_a
.data_start
= data_start
;
2561 /* On Ultrix, the initial portions of the .sbss and .bss segments
2562 are at the end of the data section. The bsize field in the
2563 optional header records how many bss bytes are required beyond
2564 those in the data section. The value is not rounded to a page
2566 if (bss_size
< internal_a
.dsize
- data_size
)
2569 bss_size
-= internal_a
.dsize
- data_size
;
2570 internal_a
.bsize
= bss_size
;
2571 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2573 internal_a
.entry
= bfd_get_start_address (abfd
);
2575 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2577 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2578 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2579 for (i
= 0; i
< 4; i
++)
2580 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2582 /* Let the backend adjust the headers if necessary. */
2583 if (backend
->adjust_headers
)
2585 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2589 /* Write out the file header and the optional header. */
2590 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2593 bfd_coff_swap_filehdr_out (abfd
, (void *) &internal_f
, buff
);
2594 if (bfd_bwrite (buff
, filhsz
, abfd
) != filhsz
)
2597 bfd_coff_swap_aouthdr_out (abfd
, (void *) &internal_a
, buff
);
2598 if (bfd_bwrite (buff
, aoutsz
, abfd
) != aoutsz
)
2601 /* Build the external symbol information. This must be done before
2602 writing out the relocs so that we know the symbol indices. We
2603 don't do this if this BFD was created by the backend linker,
2604 since it will have already handled the symbols and relocs. */
2605 if (! ecoff_data (abfd
)->linker
)
2607 symhdr
->iextMax
= 0;
2608 symhdr
->issExtMax
= 0;
2609 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2610 debug
->ssext
= debug
->ssext_end
= NULL
;
2611 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2612 (abfd
->flags
& EXEC_P
) == 0,
2613 ecoff_get_extr
, ecoff_set_index
))
2616 /* Write out the relocs. */
2617 for (current
= abfd
->sections
;
2619 current
= current
->next
)
2621 arelent
**reloc_ptr_ptr
;
2622 arelent
**reloc_end
;
2626 if (current
->reloc_count
== 0)
2629 amt
= current
->reloc_count
* external_reloc_size
;
2630 reloc_buff
= bfd_alloc (abfd
, amt
);
2631 if (reloc_buff
== NULL
)
2634 reloc_ptr_ptr
= current
->orelocation
;
2635 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2636 out_ptr
= (char *) reloc_buff
;
2639 reloc_ptr_ptr
< reloc_end
;
2640 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2644 struct internal_reloc in
;
2646 memset ((void *) &in
, 0, sizeof in
);
2648 reloc
= *reloc_ptr_ptr
;
2649 sym
= *reloc
->sym_ptr_ptr
;
2651 /* If the howto field has not been initialised then skip this reloc.
2652 This assumes that an error message has been issued elsewhere. */
2653 if (reloc
->howto
== NULL
)
2656 in
.r_vaddr
= (reloc
->address
2657 + bfd_get_section_vma (abfd
, current
));
2658 in
.r_type
= reloc
->howto
->type
;
2660 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2662 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2676 { _TEXT
, RELOC_SECTION_TEXT
},
2677 { _RDATA
, RELOC_SECTION_RDATA
},
2678 { _DATA
, RELOC_SECTION_DATA
},
2679 { _SDATA
, RELOC_SECTION_SDATA
},
2680 { _SBSS
, RELOC_SECTION_SBSS
},
2681 { _BSS
, RELOC_SECTION_BSS
},
2682 { _INIT
, RELOC_SECTION_INIT
},
2683 { _LIT8
, RELOC_SECTION_LIT8
},
2684 { _LIT4
, RELOC_SECTION_LIT4
},
2685 { _XDATA
, RELOC_SECTION_XDATA
},
2686 { _PDATA
, RELOC_SECTION_PDATA
},
2687 { _FINI
, RELOC_SECTION_FINI
},
2688 { _LITA
, RELOC_SECTION_LITA
},
2689 { "*ABS*", RELOC_SECTION_ABS
},
2690 { _RCONST
, RELOC_SECTION_RCONST
}
2693 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2695 for (i
= 0; i
< ARRAY_SIZE (section_symndx
); i
++)
2696 if (streq (name
, section_symndx
[i
].name
))
2698 in
.r_symndx
= section_symndx
[i
].r_symndx
;
2702 if (i
== ARRAY_SIZE (section_symndx
))
2707 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2709 (*swap_reloc_out
) (abfd
, &in
, (void *) out_ptr
);
2712 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2714 amt
= current
->reloc_count
* external_reloc_size
;
2715 if (bfd_bwrite (reloc_buff
, amt
, abfd
) != amt
)
2717 bfd_release (abfd
, reloc_buff
);
2721 /* Write out the symbolic debugging information. */
2722 if (bfd_get_symcount (abfd
) > 0)
2724 /* Write out the debugging information. */
2725 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2726 ecoff_data (abfd
)->sym_filepos
))
2731 /* The .bss section of a demand paged executable must receive an
2732 entire page. If there are symbols, the symbols will start on the
2733 next page. If there are no symbols, we must fill out the page by
2735 if (bfd_get_symcount (abfd
) == 0
2736 && (abfd
->flags
& EXEC_P
) != 0
2737 && (abfd
->flags
& D_PAGED
) != 0)
2741 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2744 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) == 0)
2746 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2749 if (bfd_bwrite (&c
, (bfd_size_type
) 1, abfd
) != 1)
2753 if (reloc_buff
!= NULL
)
2754 bfd_release (abfd
, reloc_buff
);
2759 if (reloc_buff
!= NULL
)
2760 bfd_release (abfd
, reloc_buff
);
2766 /* Archive handling. ECOFF uses what appears to be a unique type of
2767 archive header (armap). The byte ordering of the armap and the
2768 contents are encoded in the name of the armap itself. At least for
2769 now, we only support archives with the same byte ordering in the
2770 armap and the contents.
2772 The first four bytes in the armap are the number of symbol
2773 definitions. This is always a power of two.
2775 This is followed by the symbol definitions. Each symbol definition
2776 occupies 8 bytes. The first four bytes are the offset from the
2777 start of the armap strings to the null-terminated string naming
2778 this symbol. The second four bytes are the file offset to the
2779 archive member which defines this symbol. If the second four bytes
2780 are 0, then this is not actually a symbol definition, and it should
2783 The symbols are hashed into the armap with a closed hashing scheme.
2784 See the functions below for the details of the algorithm.
2786 After the symbol definitions comes four bytes holding the size of
2787 the string table, followed by the string table itself. */
2789 /* The name of an archive headers looks like this:
2790 __________E[BL]E[BL]_ (with a trailing space).
2791 The trailing space is changed to an X if the archive is changed to
2792 indicate that the armap is out of date.
2794 The Alpha seems to use ________64E[BL]E[BL]_. */
2796 #define ARMAP_BIG_ENDIAN 'B'
2797 #define ARMAP_LITTLE_ENDIAN 'L'
2798 #define ARMAP_MARKER 'E'
2799 #define ARMAP_START_LENGTH 10
2800 #define ARMAP_HEADER_MARKER_INDEX 10
2801 #define ARMAP_HEADER_ENDIAN_INDEX 11
2802 #define ARMAP_OBJECT_MARKER_INDEX 12
2803 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2804 #define ARMAP_END_INDEX 14
2805 #define ARMAP_END "_ "
2807 /* This is a magic number used in the hashing algorithm. */
2808 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2810 /* This returns the hash value to use for a string. It also sets
2811 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2812 is the number of entries in the hash table, and HLOG is the log
2816 ecoff_armap_hash (const char *s
,
2817 unsigned int *rehash
,
2827 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2828 hash
*= ARMAP_HASH_MAGIC
;
2829 *rehash
= (hash
& (size
- 1)) | 1;
2830 return hash
>> (32 - hlog
);
2833 /* Read in the armap. */
2836 _bfd_ecoff_slurp_armap (bfd
*abfd
)
2840 struct areltdata
*mapdata
;
2841 bfd_size_type parsed_size
;
2843 struct artdata
*ardata
;
2846 struct symdef
*symdef_ptr
;
2850 /* Get the name of the first element. */
2851 i
= bfd_bread ((void *) nextname
, (bfd_size_type
) 16, abfd
);
2857 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2860 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2861 standard COFF armap. We could move the ECOFF armap stuff into
2862 bfd_slurp_armap, but that seems inappropriate since no other
2863 target uses this format. Instead, we check directly for a COFF
2865 if (CONST_STRNEQ (nextname
, "/ "))
2866 return bfd_slurp_armap (abfd
);
2868 /* See if the first element is an armap. */
2869 if (! strneq (nextname
, ecoff_backend (abfd
)->armap_start
, ARMAP_START_LENGTH
)
2870 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2871 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2872 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2873 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2874 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2875 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2876 || ! strneq (nextname
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1))
2878 bfd_has_map (abfd
) = FALSE
;
2882 /* Make sure we have the right byte ordering. */
2883 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2884 ^ (bfd_header_big_endian (abfd
)))
2885 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2886 ^ (bfd_big_endian (abfd
))))
2888 bfd_set_error (bfd_error_wrong_format
);
2892 /* Read in the armap. */
2893 ardata
= bfd_ardata (abfd
);
2894 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
2895 if (mapdata
== NULL
)
2897 parsed_size
= mapdata
->parsed_size
;
2898 bfd_release (abfd
, (void *) mapdata
);
2900 raw_armap
= bfd_alloc (abfd
, parsed_size
);
2901 if (raw_armap
== NULL
)
2904 if (bfd_bread ((void *) raw_armap
, parsed_size
, abfd
) != parsed_size
)
2906 if (bfd_get_error () != bfd_error_system_call
)
2907 bfd_set_error (bfd_error_malformed_archive
);
2908 bfd_release (abfd
, (void *) raw_armap
);
2912 ardata
->tdata
= (void *) raw_armap
;
2914 count
= H_GET_32 (abfd
, raw_armap
);
2916 ardata
->symdef_count
= 0;
2917 ardata
->cache
= NULL
;
2919 /* This code used to overlay the symdefs over the raw archive data,
2920 but that doesn't work on a 64 bit host. */
2921 stringbase
= raw_armap
+ count
* 8 + 8;
2923 #ifdef CHECK_ARMAP_HASH
2927 /* Double check that I have the hashing algorithm right by making
2928 sure that every symbol can be looked up successfully. */
2930 for (i
= 1; i
< count
; i
<<= 1)
2932 BFD_ASSERT (i
== count
);
2934 raw_ptr
= raw_armap
+ 4;
2935 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2937 unsigned int name_offset
, file_offset
;
2938 unsigned int hash
, rehash
, srch
;
2940 name_offset
= H_GET_32 (abfd
, raw_ptr
);
2941 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
2942 if (file_offset
== 0)
2944 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
2949 /* See if we can rehash to this location. */
2950 for (srch
= (hash
+ rehash
) & (count
- 1);
2951 srch
!= hash
&& srch
!= i
;
2952 srch
= (srch
+ rehash
) & (count
- 1))
2953 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
2954 BFD_ASSERT (srch
== i
);
2958 #endif /* CHECK_ARMAP_HASH */
2960 raw_ptr
= raw_armap
+ 4;
2961 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2962 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
2963 ++ardata
->symdef_count
;
2965 amt
= ardata
->symdef_count
;
2966 amt
*= sizeof (struct symdef
);
2967 symdef_ptr
= bfd_alloc (abfd
, amt
);
2971 ardata
->symdefs
= (carsym
*) symdef_ptr
;
2973 raw_ptr
= raw_armap
+ 4;
2974 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2976 unsigned int name_offset
, file_offset
;
2978 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
2979 if (file_offset
== 0)
2981 name_offset
= H_GET_32 (abfd
, raw_ptr
);
2982 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
2983 symdef_ptr
->file_offset
= file_offset
;
2987 ardata
->first_file_filepos
= bfd_tell (abfd
);
2988 /* Pad to an even boundary. */
2989 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
2991 bfd_has_map (abfd
) = TRUE
;
2996 /* Write out an armap. */
2999 _bfd_ecoff_write_armap (bfd
*abfd
,
3000 unsigned int elength
,
3002 unsigned int orl_count
,
3005 unsigned int hashsize
, hashlog
;
3006 bfd_size_type symdefsize
;
3008 unsigned int stringsize
;
3009 unsigned int mapsize
;
3012 struct stat statbuf
;
3015 bfd_byte
*hashtable
;
3019 /* Ultrix appears to use as a hash table size the least power of two
3020 greater than twice the number of entries. */
3021 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3023 hashsize
= 1 << hashlog
;
3025 symdefsize
= hashsize
* 8;
3027 stringsize
= stridx
+ padit
;
3029 /* Include 8 bytes to store symdefsize and stringsize in output. */
3030 mapsize
= symdefsize
+ stringsize
+ 8;
3032 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3034 memset ((void *) &hdr
, 0, sizeof hdr
);
3036 /* Work out the ECOFF armap name. */
3037 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3038 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3039 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3040 (bfd_header_big_endian (abfd
)
3042 : ARMAP_LITTLE_ENDIAN
);
3043 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3044 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3045 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3046 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3048 /* Write the timestamp of the archive header to be just a little bit
3049 later than the timestamp of the file, otherwise the linker will
3050 complain that the index is out of date. Actually, the Ultrix
3051 linker just checks the archive name; the GNU linker may check the
3053 stat (abfd
->filename
, &statbuf
);
3054 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3056 /* The DECstation uses zeroes for the uid, gid and mode of the
3058 hdr
.ar_uid
[0] = '0';
3059 hdr
.ar_gid
[0] = '0';
3060 /* Building gcc ends up extracting the armap as a file - twice. */
3061 hdr
.ar_mode
[0] = '6';
3062 hdr
.ar_mode
[1] = '4';
3063 hdr
.ar_mode
[2] = '4';
3065 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3067 hdr
.ar_fmag
[0] = '`';
3068 hdr
.ar_fmag
[1] = '\012';
3070 /* Turn all null bytes in the header into spaces. */
3071 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3072 if (((char *) (&hdr
))[i
] == '\0')
3073 (((char *) (&hdr
))[i
]) = ' ';
3075 if (bfd_bwrite ((void *) &hdr
, (bfd_size_type
) sizeof (struct ar_hdr
), abfd
)
3076 != sizeof (struct ar_hdr
))
3079 H_PUT_32 (abfd
, hashsize
, temp
);
3080 if (bfd_bwrite ((void *) temp
, (bfd_size_type
) 4, abfd
) != 4)
3083 hashtable
= bfd_zalloc (abfd
, symdefsize
);
3087 current
= abfd
->archive_head
;
3089 for (i
= 0; i
< orl_count
; i
++)
3091 unsigned int hash
, rehash
= 0;
3093 /* Advance firstreal to the file position of this archive
3095 if (map
[i
].u
.abfd
!= last_elt
)
3099 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3100 firstreal
+= firstreal
% 2;
3101 current
= current
->archive_next
;
3103 while (current
!= map
[i
].u
.abfd
);
3108 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3109 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3113 /* The desired slot is already taken. */
3114 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3116 srch
= (srch
+ rehash
) & (hashsize
- 1))
3117 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3120 BFD_ASSERT (srch
!= hash
);
3125 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3126 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3129 if (bfd_bwrite ((void *) hashtable
, symdefsize
, abfd
) != symdefsize
)
3132 bfd_release (abfd
, hashtable
);
3134 /* Now write the strings. */
3135 H_PUT_32 (abfd
, stringsize
, temp
);
3136 if (bfd_bwrite ((void *) temp
, (bfd_size_type
) 4, abfd
) != 4)
3138 for (i
= 0; i
< orl_count
; i
++)
3142 len
= strlen (*map
[i
].name
) + 1;
3143 if (bfd_bwrite ((void *) (*map
[i
].name
), len
, abfd
) != len
)
3147 /* The spec sez this should be a newline. But in order to be
3148 bug-compatible for DECstation ar we use a null. */
3151 if (bfd_bwrite ("", (bfd_size_type
) 1, abfd
) != 1)
3158 /* See whether this BFD is an archive. If it is, read in the armap
3159 and the extended name table. */
3162 _bfd_ecoff_archive_p (bfd
*abfd
)
3164 struct artdata
*tdata_hold
;
3165 char armag
[SARMAG
+ 1];
3168 if (bfd_bread ((void *) armag
, (bfd_size_type
) SARMAG
, abfd
) != SARMAG
)
3170 if (bfd_get_error () != bfd_error_system_call
)
3171 bfd_set_error (bfd_error_wrong_format
);
3175 if (! strneq (armag
, ARMAG
, SARMAG
))
3177 bfd_set_error (bfd_error_wrong_format
);
3181 tdata_hold
= bfd_ardata (abfd
);
3183 amt
= sizeof (struct artdata
);
3184 bfd_ardata (abfd
) = bfd_zalloc (abfd
, amt
);
3185 if (bfd_ardata (abfd
) == NULL
)
3187 bfd_ardata (abfd
) = tdata_hold
;
3191 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3192 /* Already cleared by bfd_zalloc above.
3193 bfd_ardata (abfd)->cache = NULL;
3194 bfd_ardata (abfd)->archive_head = NULL;
3195 bfd_ardata (abfd)->symdefs = NULL;
3196 bfd_ardata (abfd)->extended_names = NULL;
3197 bfd_ardata (abfd)->extended_names_size = 0;
3198 bfd_ardata (abfd)->tdata = NULL; */
3200 if (! _bfd_ecoff_slurp_armap (abfd
)
3201 || ! _bfd_ecoff_slurp_extended_name_table (abfd
))
3203 bfd_release (abfd
, bfd_ardata (abfd
));
3204 bfd_ardata (abfd
) = tdata_hold
;
3208 if (bfd_has_map (abfd
))
3212 /* This archive has a map, so we may presume that the contents
3213 are object files. Make sure that if the first file in the
3214 archive can be recognized as an object file, it is for this
3215 target. If not, assume that this is the wrong format. If
3216 the first file is not an object file, somebody is doing
3217 something weird, and we permit it so that ar -t will work. */
3219 first
= bfd_openr_next_archived_file (abfd
, NULL
);
3222 first
->target_defaulted
= FALSE
;
3223 if (bfd_check_format (first
, bfd_object
)
3224 && first
->xvec
!= abfd
->xvec
)
3226 /* We ought to close `first' here, but we can't, because
3227 we have no way to remove it from the archive cache.
3228 It's almost impossible to figure out when we can
3229 release bfd_ardata. FIXME. */
3230 bfd_set_error (bfd_error_wrong_object_format
);
3231 bfd_ardata (abfd
) = tdata_hold
;
3234 /* And we ought to close `first' here too. */
3241 /* ECOFF linker code. */
3243 /* Routine to create an entry in an ECOFF link hash table. */
3245 static struct bfd_hash_entry
*
3246 ecoff_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3247 struct bfd_hash_table
*table
,
3250 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3252 /* Allocate the structure if it has not already been allocated by a
3255 ret
= ((struct ecoff_link_hash_entry
*)
3256 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3260 /* Call the allocation method of the superclass. */
3261 ret
= ((struct ecoff_link_hash_entry
*)
3262 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3267 /* Set local fields. */
3273 memset ((void *) &ret
->esym
, 0, sizeof ret
->esym
);
3275 return (struct bfd_hash_entry
*) ret
;
3278 /* Create an ECOFF link hash table. */
3280 struct bfd_link_hash_table
*
3281 _bfd_ecoff_bfd_link_hash_table_create (bfd
*abfd
)
3283 struct ecoff_link_hash_table
*ret
;
3284 bfd_size_type amt
= sizeof (struct ecoff_link_hash_table
);
3286 ret
= bfd_malloc (amt
);
3289 if (!_bfd_link_hash_table_init (&ret
->root
, abfd
,
3290 ecoff_link_hash_newfunc
,
3291 sizeof (struct ecoff_link_hash_entry
)))
3299 /* Look up an entry in an ECOFF link hash table. */
3301 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3302 ((struct ecoff_link_hash_entry *) \
3303 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3305 /* Traverse an ECOFF link hash table. */
3307 #define ecoff_link_hash_traverse(table, func, info) \
3308 (bfd_link_hash_traverse \
3310 (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func), \
3313 /* Get the ECOFF link hash table from the info structure. This is
3316 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3318 /* Add the external symbols of an object file to the global linker
3319 hash table. The external symbols and strings we are passed are
3320 just allocated on the stack, and will be discarded. We must
3321 explicitly save any information we may need later on in the link.
3322 We do not want to read the external symbol information again. */
3325 ecoff_link_add_externals (bfd
*abfd
,
3326 struct bfd_link_info
*info
,
3327 void * external_ext
,
3330 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3331 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
3332 = backend
->debug_swap
.swap_ext_in
;
3333 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3334 unsigned long ext_count
;
3335 struct bfd_link_hash_entry
**sym_hash
;
3340 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3343 amt
*= sizeof (struct bfd_link_hash_entry
*);
3344 sym_hash
= bfd_alloc (abfd
, amt
);
3347 ecoff_data (abfd
)->sym_hashes
= (struct ecoff_link_hash_entry
**) sym_hash
;
3349 ext_ptr
= (char *) external_ext
;
3350 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3351 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3358 struct ecoff_link_hash_entry
*h
;
3362 (*swap_ext_in
) (abfd
, (void *) ext_ptr
, &esym
);
3364 /* Skip debugging symbols. */
3366 switch (esym
.asym
.st
)
3382 /* Get the information for this symbol. */
3383 value
= esym
.asym
.value
;
3384 switch (esym
.asym
.sc
)
3404 section
= bfd_make_section_old_way (abfd
, _TEXT
);
3405 value
-= section
->vma
;
3408 section
= bfd_make_section_old_way (abfd
, _DATA
);
3409 value
-= section
->vma
;
3412 section
= bfd_make_section_old_way (abfd
, _BSS
);
3413 value
-= section
->vma
;
3416 section
= bfd_abs_section_ptr
;
3419 section
= bfd_und_section_ptr
;
3422 section
= bfd_make_section_old_way (abfd
, _SDATA
);
3423 value
-= section
->vma
;
3426 section
= bfd_make_section_old_way (abfd
, _SBSS
);
3427 value
-= section
->vma
;
3430 section
= bfd_make_section_old_way (abfd
, _RDATA
);
3431 value
-= section
->vma
;
3434 if (value
> ecoff_data (abfd
)->gp_size
)
3436 section
= bfd_com_section_ptr
;
3441 if (ecoff_scom_section
.name
== NULL
)
3443 /* Initialize the small common section. */
3444 ecoff_scom_section
.name
= SCOMMON
;
3445 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3446 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3447 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3448 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3449 ecoff_scom_symbol
.name
= SCOMMON
;
3450 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3451 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3452 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3454 section
= &ecoff_scom_section
;
3457 section
= bfd_und_section_ptr
;
3460 section
= bfd_make_section_old_way (abfd
, _INIT
);
3461 value
-= section
->vma
;
3464 section
= bfd_make_section_old_way (abfd
, _FINI
);
3465 value
-= section
->vma
;
3468 section
= bfd_make_section_old_way (abfd
, _RCONST
);
3469 value
-= section
->vma
;
3473 if (section
== NULL
)
3476 name
= ssext
+ esym
.asym
.iss
;
3478 if (! (_bfd_generic_link_add_one_symbol
3480 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
3481 section
, value
, NULL
, TRUE
, TRUE
, sym_hash
)))
3484 h
= (struct ecoff_link_hash_entry
*) *sym_hash
;
3486 /* If we are building an ECOFF hash table, save the external
3487 symbol information. */
3488 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3491 || (! bfd_is_und_section (section
)
3492 && (! bfd_is_com_section (section
)
3493 || (h
->root
.type
!= bfd_link_hash_defined
3494 && h
->root
.type
!= bfd_link_hash_defweak
))))
3500 /* Remember whether this symbol was small undefined. */
3501 if (esym
.asym
.sc
== scSUndefined
)
3504 /* If this symbol was ever small undefined, it needs to wind
3505 up in a GP relative section. We can't control the
3506 section of a defined symbol, but we can control the
3507 section of a common symbol. This case is actually needed
3508 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
3510 && h
->root
.type
== bfd_link_hash_common
3511 && streq (h
->root
.u
.c
.p
->section
->name
, SCOMMON
))
3513 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
3515 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
3516 if (h
->esym
.asym
.sc
== scCommon
)
3517 h
->esym
.asym
.sc
= scSCommon
;
3525 /* Add symbols from an ECOFF object file to the global linker hash
3529 ecoff_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3532 bfd_size_type external_ext_size
;
3533 void * external_ext
= NULL
;
3534 bfd_size_type esize
;
3538 if (! ecoff_slurp_symbolic_header (abfd
))
3541 /* If there are no symbols, we don't want it. */
3542 if (bfd_get_symcount (abfd
) == 0)
3545 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3547 /* Read in the external symbols and external strings. */
3548 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3549 esize
= symhdr
->iextMax
* external_ext_size
;
3550 external_ext
= bfd_malloc (esize
);
3551 if (external_ext
== NULL
&& esize
!= 0)
3554 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3555 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3558 ssext
= bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3559 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3562 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3563 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3564 != (bfd_size_type
) symhdr
->issExtMax
))
3567 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3571 if (external_ext
!= NULL
)
3572 free (external_ext
);
3578 if (external_ext
!= NULL
)
3579 free (external_ext
);
3583 /* This is called if we used _bfd_generic_link_add_archive_symbols
3584 because we were not dealing with an ECOFF archive. */
3587 ecoff_link_check_archive_element (bfd
*abfd
,
3588 struct bfd_link_info
*info
,
3589 bfd_boolean
*pneeded
)
3591 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3592 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
3593 = backend
->debug_swap
.swap_ext_in
;
3595 bfd_size_type external_ext_size
;
3596 void * external_ext
= NULL
;
3597 bfd_size_type esize
;
3604 if (! ecoff_slurp_symbolic_header (abfd
))
3607 /* If there are no symbols, we don't want it. */
3608 if (bfd_get_symcount (abfd
) == 0)
3609 goto successful_return
;
3611 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3613 /* Read in the external symbols and external strings. */
3614 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3615 esize
= symhdr
->iextMax
* external_ext_size
;
3616 external_ext
= bfd_malloc (esize
);
3617 if (external_ext
== NULL
&& esize
!= 0)
3620 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3621 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3624 ssext
= bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3625 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3628 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3629 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3630 != (bfd_size_type
) symhdr
->issExtMax
))
3633 /* Look through the external symbols to see if they define some
3634 symbol that is currently undefined. */
3635 ext_ptr
= (char *) external_ext
;
3636 ext_end
= ext_ptr
+ esize
;
3637 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3642 struct bfd_link_hash_entry
*h
;
3644 (*swap_ext_in
) (abfd
, (void *) ext_ptr
, &esym
);
3646 /* See if this symbol defines something. */
3647 if (esym
.asym
.st
!= stGlobal
3648 && esym
.asym
.st
!= stLabel
3649 && esym
.asym
.st
!= stProc
)
3652 switch (esym
.asym
.sc
)
3676 name
= ssext
+ esym
.asym
.iss
;
3677 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3679 /* Unlike the generic linker, we do not pull in elements because
3680 of common symbols. */
3682 || h
->type
!= bfd_link_hash_undefined
)
3685 /* Include this element. */
3686 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3688 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3692 goto successful_return
;
3696 if (external_ext
!= NULL
)
3697 free (external_ext
);
3702 if (external_ext
!= NULL
)
3703 free (external_ext
);
3709 /* Add the symbols from an archive file to the global hash table.
3710 This looks through the undefined symbols, looks each one up in the
3711 archive hash table, and adds any associated object file. We do not
3712 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3713 already have a hash table, so there is no reason to construct
3717 ecoff_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3719 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3720 const bfd_byte
*raw_armap
;
3721 struct bfd_link_hash_entry
**pundef
;
3722 unsigned int armap_count
;
3723 unsigned int armap_log
;
3725 const bfd_byte
*hashtable
;
3726 const char *stringbase
;
3728 if (! bfd_has_map (abfd
))
3730 /* An empty archive is a special case. */
3731 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
3733 bfd_set_error (bfd_error_no_armap
);
3737 /* If we don't have any raw data for this archive, as can happen on
3738 Irix 4.0.5F, we call the generic routine.
3739 FIXME: We should be more clever about this, since someday tdata
3740 may get to something for a generic archive. */
3741 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3742 if (raw_armap
== NULL
)
3743 return (_bfd_generic_link_add_archive_symbols
3744 (abfd
, info
, ecoff_link_check_archive_element
));
3746 armap_count
= H_GET_32 (abfd
, raw_armap
);
3749 for (i
= 1; i
< armap_count
; i
<<= 1)
3751 BFD_ASSERT (i
== armap_count
);
3753 hashtable
= raw_armap
+ 4;
3754 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3756 /* Look through the list of undefined symbols. */
3757 pundef
= &info
->hash
->undefs
;
3758 while (*pundef
!= NULL
)
3760 struct bfd_link_hash_entry
*h
;
3761 unsigned int hash
, rehash
= 0;
3762 unsigned int file_offset
;
3768 /* When a symbol is defined, it is not necessarily removed from
3770 if (h
->type
!= bfd_link_hash_undefined
3771 && h
->type
!= bfd_link_hash_common
)
3773 /* Remove this entry from the list, for general cleanliness
3774 and because we are going to look through the list again
3775 if we search any more libraries. We can't remove the
3776 entry if it is the tail, because that would lose any
3777 entries we add to the list later on. */
3778 if (*pundef
!= info
->hash
->undefs_tail
)
3779 *pundef
= (*pundef
)->u
.undef
.next
;
3781 pundef
= &(*pundef
)->u
.undef
.next
;
3785 /* Native ECOFF linkers do not pull in archive elements merely
3786 to satisfy common definitions, so neither do we. We leave
3787 them on the list, though, in case we are linking against some
3788 other object format. */
3789 if (h
->type
!= bfd_link_hash_undefined
)
3791 pundef
= &(*pundef
)->u
.undef
.next
;
3795 /* Look for this symbol in the archive hash table. */
3796 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3799 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3800 if (file_offset
== 0)
3802 /* Nothing in this slot. */
3803 pundef
= &(*pundef
)->u
.undef
.next
;
3807 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3808 if (name
[0] != h
->root
.string
[0]
3809 || ! streq (name
, h
->root
.string
))
3814 /* That was the wrong symbol. Try rehashing. */
3816 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3818 srch
= (srch
+ rehash
) & (armap_count
- 1))
3820 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3821 if (file_offset
== 0)
3823 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3824 if (name
[0] == h
->root
.string
[0]
3825 && streq (name
, h
->root
.string
))
3834 pundef
= &(*pundef
)->u
.undef
.next
;
3841 element
= (*backend
->get_elt_at_filepos
) (abfd
, (file_ptr
) file_offset
);
3842 if (element
== NULL
)
3845 if (! bfd_check_format (element
, bfd_object
))
3848 /* Unlike the generic linker, we know that this element provides
3849 a definition for an undefined symbol and we know that we want
3850 to include it. We don't need to check anything. */
3851 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3853 if (! ecoff_link_add_object_symbols (element
, info
))
3856 pundef
= &(*pundef
)->u
.undef
.next
;
3862 /* Given an ECOFF BFD, add symbols to the global hash table as
3866 _bfd_ecoff_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3868 switch (bfd_get_format (abfd
))
3871 return ecoff_link_add_object_symbols (abfd
, info
);
3873 return ecoff_link_add_archive_symbols (abfd
, info
);
3875 bfd_set_error (bfd_error_wrong_format
);
3881 /* ECOFF final link routines. */
3883 /* Structure used to pass information to ecoff_link_write_external. */
3888 struct bfd_link_info
*info
;
3891 /* Accumulate the debugging information for an input BFD into the
3892 output BFD. This must read in the symbolic information of the
3896 ecoff_final_link_debug_accumulate (bfd
*output_bfd
,
3898 struct bfd_link_info
*info
,
3901 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
3902 const struct ecoff_debug_swap
* const swap
=
3903 &ecoff_backend (input_bfd
)->debug_swap
;
3904 HDRR
*symhdr
= &debug
->symbolic_header
;
3907 #define READ(ptr, offset, count, size, type) \
3908 if (symhdr->count == 0) \
3909 debug->ptr = NULL; \
3912 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
3913 debug->ptr = bfd_malloc (amt); \
3914 if (debug->ptr == NULL) \
3917 goto return_something; \
3919 if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3920 || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
3923 goto return_something; \
3927 /* If raw_syments is not NULL, then the data was already by read by
3928 _bfd_ecoff_slurp_symbolic_info. */
3929 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
3931 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
3933 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
3934 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
3935 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
3936 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
3937 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3939 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3940 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
3941 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
3945 /* We do not read the external strings or the external symbols. */
3947 ret
= (bfd_ecoff_debug_accumulate
3948 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
3949 &ecoff_backend (output_bfd
)->debug_swap
,
3950 input_bfd
, debug
, swap
, info
));
3953 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
3955 if (debug
->line
!= NULL
)
3957 if (debug
->external_dnr
!= NULL
)
3958 free (debug
->external_dnr
);
3959 if (debug
->external_pdr
!= NULL
)
3960 free (debug
->external_pdr
);
3961 if (debug
->external_sym
!= NULL
)
3962 free (debug
->external_sym
);
3963 if (debug
->external_opt
!= NULL
)
3964 free (debug
->external_opt
);
3965 if (debug
->external_aux
!= NULL
)
3966 free (debug
->external_aux
);
3967 if (debug
->ss
!= NULL
)
3969 if (debug
->external_fdr
!= NULL
)
3970 free (debug
->external_fdr
);
3971 if (debug
->external_rfd
!= NULL
)
3972 free (debug
->external_rfd
);
3974 /* Make sure we don't accidentally follow one of these pointers
3975 into freed memory. */
3977 debug
->external_dnr
= NULL
;
3978 debug
->external_pdr
= NULL
;
3979 debug
->external_sym
= NULL
;
3980 debug
->external_opt
= NULL
;
3981 debug
->external_aux
= NULL
;
3983 debug
->external_fdr
= NULL
;
3984 debug
->external_rfd
= NULL
;
3990 /* Relocate and write an ECOFF section into an ECOFF output file. */
3993 ecoff_indirect_link_order (bfd
*output_bfd
,
3994 struct bfd_link_info
*info
,
3995 asection
*output_section
,
3996 struct bfd_link_order
*link_order
)
3998 asection
*input_section
;
4000 bfd_byte
*contents
= NULL
;
4001 bfd_size_type external_reloc_size
;
4002 bfd_size_type external_relocs_size
;
4003 void * external_relocs
= NULL
;
4005 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4007 input_section
= link_order
->u
.indirect
.section
;
4008 input_bfd
= input_section
->owner
;
4009 if (input_section
->size
== 0)
4012 BFD_ASSERT (input_section
->output_section
== output_section
);
4013 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4014 BFD_ASSERT (input_section
->size
== link_order
->size
);
4016 /* Get the section contents. */
4017 if (!bfd_malloc_and_get_section (input_bfd
, input_section
, &contents
))
4020 /* Get the relocs. If we are relaxing MIPS code, they will already
4021 have been read in. Otherwise, we read them in now. */
4022 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4023 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4025 external_relocs
= bfd_malloc (external_relocs_size
);
4026 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4029 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4030 || (bfd_bread (external_relocs
, external_relocs_size
, input_bfd
)
4031 != external_relocs_size
))
4034 /* Relocate the section contents. */
4035 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4036 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4040 /* Write out the relocated section. */
4041 if (! bfd_set_section_contents (output_bfd
,
4044 input_section
->output_offset
,
4045 input_section
->size
))
4048 /* If we are producing relocatable output, the relocs were
4049 modified, and we write them out now. We use the reloc_count
4050 field of output_section to keep track of the number of relocs we
4051 have output so far. */
4052 if (info
->relocatable
)
4054 file_ptr pos
= (output_section
->rel_filepos
4055 + output_section
->reloc_count
* external_reloc_size
);
4056 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4057 || (bfd_bwrite (external_relocs
, external_relocs_size
, output_bfd
)
4058 != external_relocs_size
))
4060 output_section
->reloc_count
+= input_section
->reloc_count
;
4063 if (contents
!= NULL
)
4065 if (external_relocs
!= NULL
)
4066 free (external_relocs
);
4070 if (contents
!= NULL
)
4072 if (external_relocs
!= NULL
)
4073 free (external_relocs
);
4077 /* Generate a reloc when linking an ECOFF file. This is a reloc
4078 requested by the linker, and does come from any input file. This
4079 is used to build constructor and destructor tables when linking
4083 ecoff_reloc_link_order (bfd
*output_bfd
,
4084 struct bfd_link_info
*info
,
4085 asection
*output_section
,
4086 struct bfd_link_order
*link_order
)
4088 enum bfd_link_order_type type
;
4092 struct internal_reloc in
;
4093 bfd_size_type external_reloc_size
;
4098 type
= link_order
->type
;
4100 addend
= link_order
->u
.reloc
.p
->addend
;
4102 /* We set up an arelent to pass to the backend adjust_reloc_out
4104 rel
.address
= link_order
->offset
;
4106 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4109 bfd_set_error (bfd_error_bad_value
);
4113 if (type
== bfd_section_reloc_link_order
)
4115 section
= link_order
->u
.reloc
.p
->u
.section
;
4116 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4120 struct bfd_link_hash_entry
*h
;
4122 /* Treat a reloc against a defined symbol as though it were
4123 actually against the section. */
4124 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4125 link_order
->u
.reloc
.p
->u
.name
,
4126 FALSE
, FALSE
, FALSE
);
4128 && (h
->type
== bfd_link_hash_defined
4129 || h
->type
== bfd_link_hash_defweak
))
4131 type
= bfd_section_reloc_link_order
;
4132 section
= h
->u
.def
.section
->output_section
;
4133 /* It seems that we ought to add the symbol value to the
4134 addend here, but in practice it has already been added
4135 because it was passed to constructor_callback. */
4136 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4140 /* We can't set up a reloc against a symbol correctly,
4141 because we have no asymbol structure. Currently no
4142 adjust_reloc_out routine cares. */
4143 rel
.sym_ptr_ptr
= NULL
;
4147 /* All ECOFF relocs are in-place. Put the addend into the object
4150 BFD_ASSERT (rel
.howto
->partial_inplace
);
4154 bfd_reloc_status_type rstat
;
4157 size
= bfd_get_reloc_size (rel
.howto
);
4158 buf
= bfd_zmalloc (size
);
4161 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4162 (bfd_vma
) addend
, buf
);
4168 case bfd_reloc_outofrange
:
4170 case bfd_reloc_overflow
:
4171 if (! ((*info
->callbacks
->reloc_overflow
)
4173 (link_order
->type
== bfd_section_reloc_link_order
4174 ? bfd_section_name (output_bfd
, section
)
4175 : link_order
->u
.reloc
.p
->u
.name
),
4176 rel
.howto
->name
, addend
, NULL
,
4177 NULL
, (bfd_vma
) 0)))
4184 ok
= bfd_set_section_contents (output_bfd
, output_section
, (void *) buf
,
4185 (file_ptr
) link_order
->offset
, size
);
4193 /* Move the information into an internal_reloc structure. */
4194 in
.r_vaddr
= (rel
.address
4195 + bfd_get_section_vma (output_bfd
, output_section
));
4196 in
.r_type
= rel
.howto
->type
;
4198 if (type
== bfd_symbol_reloc_link_order
)
4200 struct ecoff_link_hash_entry
*h
;
4202 h
= ((struct ecoff_link_hash_entry
*)
4203 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4204 link_order
->u
.reloc
.p
->u
.name
,
4205 FALSE
, FALSE
, TRUE
));
4208 in
.r_symndx
= h
->indx
;
4211 if (! ((*info
->callbacks
->unattached_reloc
)
4212 (info
, link_order
->u
.reloc
.p
->u
.name
, NULL
,
4213 NULL
, (bfd_vma
) 0)))
4230 { _TEXT
, RELOC_SECTION_TEXT
},
4231 { _RDATA
, RELOC_SECTION_RDATA
},
4232 { _DATA
, RELOC_SECTION_DATA
},
4233 { _SDATA
, RELOC_SECTION_SDATA
},
4234 { _SBSS
, RELOC_SECTION_SBSS
},
4235 { _BSS
, RELOC_SECTION_BSS
},
4236 { _INIT
, RELOC_SECTION_INIT
},
4237 { _LIT8
, RELOC_SECTION_LIT8
},
4238 { _LIT4
, RELOC_SECTION_LIT4
},
4239 { _XDATA
, RELOC_SECTION_XDATA
},
4240 { _PDATA
, RELOC_SECTION_PDATA
},
4241 { _FINI
, RELOC_SECTION_FINI
},
4242 { _LITA
, RELOC_SECTION_LITA
},
4243 { "*ABS*", RELOC_SECTION_ABS
},
4244 { _RCONST
, RELOC_SECTION_RCONST
}
4247 name
= bfd_get_section_name (output_bfd
, section
);
4249 for (i
= 0; i
< ARRAY_SIZE (section_symndx
); i
++)
4250 if (streq (name
, section_symndx
[i
].name
))
4252 in
.r_symndx
= section_symndx
[i
].r_symndx
;
4256 if (i
== ARRAY_SIZE (section_symndx
))
4262 /* Let the BFD backend adjust the reloc. */
4263 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4265 /* Get some memory and swap out the reloc. */
4266 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4267 rbuf
= bfd_malloc (external_reloc_size
);
4271 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (void *) rbuf
);
4273 pos
= (output_section
->rel_filepos
4274 + output_section
->reloc_count
* external_reloc_size
);
4275 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4276 && (bfd_bwrite ((void *) rbuf
, external_reloc_size
, output_bfd
)
4277 == external_reloc_size
));
4280 ++output_section
->reloc_count
;
4287 /* Put out information for an external symbol. These come only from
4291 ecoff_link_write_external (struct ecoff_link_hash_entry
*h
, void * data
)
4293 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4294 bfd
*output_bfd
= einfo
->abfd
;
4297 if (h
->root
.type
== bfd_link_hash_warning
)
4299 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4300 if (h
->root
.type
== bfd_link_hash_new
)
4304 /* We need to check if this symbol is being stripped. */
4305 if (h
->root
.type
== bfd_link_hash_undefined
4306 || h
->root
.type
== bfd_link_hash_undefweak
)
4308 else if (einfo
->info
->strip
== strip_all
4309 || (einfo
->info
->strip
== strip_some
4310 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4311 h
->root
.root
.string
,
4312 FALSE
, FALSE
) == NULL
))
4317 if (strip
|| h
->written
)
4320 if (h
->abfd
== NULL
)
4323 h
->esym
.cobol_main
= 0;
4324 h
->esym
.weakext
= 0;
4325 h
->esym
.reserved
= 0;
4326 h
->esym
.ifd
= ifdNil
;
4327 h
->esym
.asym
.value
= 0;
4328 h
->esym
.asym
.st
= stGlobal
;
4330 if (h
->root
.type
!= bfd_link_hash_defined
4331 && h
->root
.type
!= bfd_link_hash_defweak
)
4332 h
->esym
.asym
.sc
= scAbs
;
4335 asection
*output_section
;
4343 section_storage_classes
[] =
4347 { _SDATA
, scSData
},
4348 { _RDATA
, scRData
},
4353 { _PDATA
, scPData
},
4354 { _XDATA
, scXData
},
4355 { _RCONST
, scRConst
}
4358 output_section
= h
->root
.u
.def
.section
->output_section
;
4359 name
= bfd_section_name (output_section
->owner
, output_section
);
4361 for (i
= 0; i
< ARRAY_SIZE (section_storage_classes
); i
++)
4362 if (streq (name
, section_storage_classes
[i
].name
))
4364 h
->esym
.asym
.sc
= section_storage_classes
[i
].sc
;
4368 if (i
== ARRAY_SIZE (section_storage_classes
))
4369 h
->esym
.asym
.sc
= scAbs
;
4372 h
->esym
.asym
.reserved
= 0;
4373 h
->esym
.asym
.index
= indexNil
;
4375 else if (h
->esym
.ifd
!= -1)
4377 struct ecoff_debug_info
*debug
;
4379 /* Adjust the FDR index for the symbol by that used for the
4381 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4382 BFD_ASSERT (h
->esym
.ifd
>= 0
4383 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4384 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4387 switch (h
->root
.type
)
4390 case bfd_link_hash_warning
:
4391 case bfd_link_hash_new
:
4393 case bfd_link_hash_undefined
:
4394 case bfd_link_hash_undefweak
:
4395 if (h
->esym
.asym
.sc
!= scUndefined
4396 && h
->esym
.asym
.sc
!= scSUndefined
)
4397 h
->esym
.asym
.sc
= scUndefined
;
4399 case bfd_link_hash_defined
:
4400 case bfd_link_hash_defweak
:
4401 if (h
->esym
.asym
.sc
== scUndefined
4402 || h
->esym
.asym
.sc
== scSUndefined
)
4403 h
->esym
.asym
.sc
= scAbs
;
4404 else if (h
->esym
.asym
.sc
== scCommon
)
4405 h
->esym
.asym
.sc
= scBss
;
4406 else if (h
->esym
.asym
.sc
== scSCommon
)
4407 h
->esym
.asym
.sc
= scSBss
;
4408 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4409 + h
->root
.u
.def
.section
->output_section
->vma
4410 + h
->root
.u
.def
.section
->output_offset
);
4412 case bfd_link_hash_common
:
4413 if (h
->esym
.asym
.sc
!= scCommon
4414 && h
->esym
.asym
.sc
!= scSCommon
)
4415 h
->esym
.asym
.sc
= scCommon
;
4416 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4418 case bfd_link_hash_indirect
:
4419 /* We ignore these symbols, since the indirected symbol is
4420 already in the hash table. */
4424 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4426 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4429 return (bfd_ecoff_debug_one_external
4430 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4431 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4435 /* ECOFF final link routine. This looks through all the input BFDs
4436 and gathers together all the debugging information, and then
4437 processes all the link order information. This may cause it to
4438 close and reopen some input BFDs; I'll see how bad this is. */
4441 _bfd_ecoff_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4443 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4444 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4449 struct bfd_link_order
*p
;
4450 struct extsym_info einfo
;
4452 /* We accumulate the debugging information counts in the symbolic
4454 symhdr
= &debug
->symbolic_header
;
4456 symhdr
->ilineMax
= 0;
4460 symhdr
->isymMax
= 0;
4461 symhdr
->ioptMax
= 0;
4462 symhdr
->iauxMax
= 0;
4464 symhdr
->issExtMax
= 0;
4467 symhdr
->iextMax
= 0;
4469 /* We accumulate the debugging information itself in the debug_info
4472 debug
->external_dnr
= NULL
;
4473 debug
->external_pdr
= NULL
;
4474 debug
->external_sym
= NULL
;
4475 debug
->external_opt
= NULL
;
4476 debug
->external_aux
= NULL
;
4478 debug
->ssext
= debug
->ssext_end
= NULL
;
4479 debug
->external_fdr
= NULL
;
4480 debug
->external_rfd
= NULL
;
4481 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4483 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4487 /* Accumulate the debugging symbols from each input BFD. */
4488 for (input_bfd
= info
->input_bfds
;
4490 input_bfd
= input_bfd
->link_next
)
4494 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4496 /* Arbitrarily set the symbolic header vstamp to the vstamp
4497 of the first object file in the link. */
4498 if (symhdr
->vstamp
== 0)
4500 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4501 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4505 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4506 debug
, &backend
->debug_swap
,
4511 /* Combine the register masks. */
4512 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4513 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4514 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4515 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4516 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4517 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4520 /* Write out the external symbols. */
4523 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4524 ecoff_link_write_external
,
4527 if (info
->relocatable
)
4529 /* We need to make a pass over the link_orders to count up the
4530 number of relocations we will need to output, so that we know
4531 how much space they will take up. */
4532 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4535 for (p
= o
->map_head
.link_order
;
4538 if (p
->type
== bfd_indirect_link_order
)
4539 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4540 else if (p
->type
== bfd_section_reloc_link_order
4541 || p
->type
== bfd_symbol_reloc_link_order
)
4546 /* Compute the reloc and symbol file positions. */
4547 ecoff_compute_reloc_file_positions (abfd
);
4549 /* Write out the debugging information. */
4550 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4551 &backend
->debug_swap
, info
,
4552 ecoff_data (abfd
)->sym_filepos
))
4555 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4557 if (info
->relocatable
)
4559 /* Now reset the reloc_count field of the sections in the output
4560 BFD to 0, so that we can use them to keep track of how many
4561 relocs we have output thus far. */
4562 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4566 /* Get a value for the GP register. */
4567 if (ecoff_data (abfd
)->gp
== 0)
4569 struct bfd_link_hash_entry
*h
;
4571 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
4573 && h
->type
== bfd_link_hash_defined
)
4574 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4575 + h
->u
.def
.section
->output_section
->vma
4576 + h
->u
.def
.section
->output_offset
);
4577 else if (info
->relocatable
)
4581 /* Make up a value. */
4583 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4586 && (streq (o
->name
, _SBSS
)
4587 || streq (o
->name
, _SDATA
)
4588 || streq (o
->name
, _LIT4
)
4589 || streq (o
->name
, _LIT8
)
4590 || streq (o
->name
, _LITA
)))
4593 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4597 /* If the relocate_section function needs to do a reloc
4598 involving the GP value, it should make a reloc_dangerous
4599 callback to warn that GP is not defined. */
4603 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4605 for (p
= o
->map_head
.link_order
;
4609 if (p
->type
== bfd_indirect_link_order
4610 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4611 == bfd_target_ecoff_flavour
))
4613 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4616 else if (p
->type
== bfd_section_reloc_link_order
4617 || p
->type
== bfd_symbol_reloc_link_order
)
4619 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4624 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4630 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4632 ecoff_data (abfd
)->linker
= TRUE
;