1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
28 #include "aout/stab_gnu.h"
30 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
31 some other stuff which we don't want and which conflicts with stuff
34 #include "aout/aout64.h"
37 #undef obj_sym_filepos
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
46 /* Prototypes for static functions. */
48 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
49 static long ecoff_sec_to_styp_flags
PARAMS ((const char *name
,
51 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
52 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
53 asymbol
*asym
, int ext
,
54 asymbol
**indirect_ptr_ptr
));
55 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
57 RNDXR
*rndx
, long isym
,
59 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
61 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
63 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
64 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
65 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
66 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
67 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
72 /* This stuff is somewhat copied from coffcode.h. */
74 static asection bfd_debug_section
= { "*DEBUG*" };
76 /* Create an ECOFF object. */
79 _bfd_ecoff_mkobject (abfd
)
82 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
83 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
84 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
86 bfd_set_error (bfd_error_no_memory
);
93 /* This is a hook called by coff_real_object_p to create any backend
94 specific information. */
97 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
102 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
103 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
104 ecoff_data_type
*ecoff
;
106 if (_bfd_ecoff_mkobject (abfd
) == false)
109 ecoff
= ecoff_data (abfd
);
111 ecoff
->sym_filepos
= internal_f
->f_symptr
;
113 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
117 ecoff
->text_start
= internal_a
->text_start
;
118 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
119 ecoff
->gp
= internal_a
->gp_value
;
120 ecoff
->gprmask
= internal_a
->gprmask
;
121 for (i
= 0; i
< 4; i
++)
122 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
123 ecoff
->fprmask
= internal_a
->fprmask
;
124 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
125 abfd
->flags
|= D_PAGED
;
127 abfd
->flags
&=~ D_PAGED
;
130 /* It turns out that no special action is required by the MIPS or
131 Alpha ECOFF backends. They have different information in the
132 a.out header, but we just copy it all (e.g., gprmask, cprmask and
133 fprmask) and let the swapping routines ensure that only relevant
134 information is written out. */
139 /* This is a hook needed by SCO COFF, but we have nothing to do. */
143 _bfd_ecoff_make_section_hook (abfd
, name
)
147 return (asection
*) NULL
;
150 /* Initialize a new section. */
153 _bfd_ecoff_new_section_hook (abfd
, section
)
157 /* For the .pdata section, which has a special meaning on the Alpha,
158 we set the alignment power to 3. We correct this later in
159 ecoff_compute_section_file_positions. We do this hackery because
160 we need to know the exact unaligned size of the .pdata section in
161 order to set the lnnoptr field correctly. For every other
162 section we use an alignment power of 4; this could be made target
163 dependent by adding a field to ecoff_backend_data, but 4 appears
164 to be correct for both the MIPS and the Alpha. */
165 if (strcmp (section
->name
, _PDATA
) == 0)
166 section
->alignment_power
= 3;
168 section
->alignment_power
= 4;
170 if (strcmp (section
->name
, _TEXT
) == 0)
171 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
172 else if (strcmp (section
->name
, _DATA
) == 0
173 || strcmp (section
->name
, _SDATA
) == 0)
174 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
175 else if (strcmp (section
->name
, _RDATA
) == 0
176 || strcmp (section
->name
, _LIT8
) == 0
177 || strcmp (section
->name
, _LIT4
) == 0)
178 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
179 else if (strcmp (section
->name
, _BSS
) == 0
180 || strcmp (section
->name
, _SBSS
) == 0)
181 section
->flags
|= SEC_ALLOC
;
182 else if (strcmp (section
->name
, _LIB
) == 0)
184 /* An Irix 4 shared libary. */
185 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
188 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
189 uncertain about .init on some systems and I don't know how shared
195 /* Determine the machine architecture and type. This is called from
196 the generic COFF routines. It is the inverse of ecoff_get_magic,
197 below. This could be an ECOFF backend routine, with one version
198 for each target, but there aren't all that many ECOFF targets. */
201 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
205 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
206 enum bfd_architecture arch
;
209 switch (internal_f
->f_magic
)
212 case MIPS_MAGIC_LITTLE
:
214 arch
= bfd_arch_mips
;
218 case MIPS_MAGIC_LITTLE2
:
219 case MIPS_MAGIC_BIG2
:
220 /* MIPS ISA level 2: the r6000 */
221 arch
= bfd_arch_mips
;
225 case MIPS_MAGIC_LITTLE3
:
226 case MIPS_MAGIC_BIG3
:
227 /* MIPS ISA level 3: the r4000 */
228 arch
= bfd_arch_mips
;
233 arch
= bfd_arch_alpha
;
238 arch
= bfd_arch_obscure
;
243 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
246 /* Get the magic number to use based on the architecture and machine.
247 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
250 ecoff_get_magic (abfd
)
255 switch (bfd_get_arch (abfd
))
258 switch (bfd_get_mach (abfd
))
263 big
= MIPS_MAGIC_BIG
;
264 little
= MIPS_MAGIC_LITTLE
;
268 big
= MIPS_MAGIC_BIG2
;
269 little
= MIPS_MAGIC_LITTLE2
;
273 big
= MIPS_MAGIC_BIG3
;
274 little
= MIPS_MAGIC_LITTLE3
;
278 return abfd
->xvec
->byteorder_big_p
? big
: little
;
289 /* Get the section s_flags to use for a section. */
292 ecoff_sec_to_styp_flags (name
, flags
)
300 if (strcmp (name
, _TEXT
) == 0)
302 else if (strcmp (name
, _DATA
) == 0)
304 else if (strcmp (name
, _SDATA
) == 0)
306 else if (strcmp (name
, _RDATA
) == 0)
308 else if (strcmp (name
, _LITA
) == 0)
310 else if (strcmp (name
, _LIT8
) == 0)
312 else if (strcmp (name
, _LIT4
) == 0)
314 else if (strcmp (name
, _BSS
) == 0)
316 else if (strcmp (name
, _SBSS
) == 0)
318 else if (strcmp (name
, _INIT
) == 0)
319 styp
= STYP_ECOFF_INIT
;
320 else if (strcmp (name
, _FINI
) == 0)
321 styp
= STYP_ECOFF_FINI
;
322 else if (strcmp (name
, _PDATA
) == 0)
324 else if (strcmp (name
, _XDATA
) == 0)
326 else if (strcmp (name
, _LIB
) == 0)
327 styp
= STYP_ECOFF_LIB
;
328 else if (flags
& SEC_CODE
)
330 else if (flags
& SEC_DATA
)
332 else if (flags
& SEC_READONLY
)
334 else if (flags
& SEC_LOAD
)
339 if (flags
& SEC_NEVER_LOAD
)
345 /* Get the BFD flags to use for a section. */
349 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
)
354 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
355 long styp_flags
= internal_s
->s_flags
;
356 flagword sec_flags
=0;
358 if (styp_flags
& STYP_NOLOAD
)
359 sec_flags
|= SEC_NEVER_LOAD
;
361 /* For 386 COFF, at least, an unloadable text or data section is
362 actually a shared library section. */
363 if ((styp_flags
& STYP_TEXT
)
364 || (styp_flags
& STYP_ECOFF_INIT
)
365 || (styp_flags
& STYP_ECOFF_FINI
))
367 if (sec_flags
& SEC_NEVER_LOAD
)
368 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
370 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
372 else if ((styp_flags
& STYP_DATA
)
373 || (styp_flags
& STYP_RDATA
)
374 || (styp_flags
& STYP_SDATA
)
375 || styp_flags
== STYP_PDATA
376 || styp_flags
== STYP_XDATA
)
378 if (sec_flags
& SEC_NEVER_LOAD
)
379 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
381 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
382 if ((styp_flags
& STYP_RDATA
)
383 || styp_flags
== STYP_PDATA
)
384 sec_flags
|= SEC_READONLY
;
386 else if ((styp_flags
& STYP_BSS
)
387 || (styp_flags
& STYP_SBSS
))
389 sec_flags
|= SEC_ALLOC
;
391 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
393 sec_flags
|= SEC_NEVER_LOAD
;
395 else if ((styp_flags
& STYP_LITA
)
396 || (styp_flags
& STYP_LIT8
)
397 || (styp_flags
& STYP_LIT4
))
399 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
401 else if (styp_flags
& STYP_ECOFF_LIB
)
403 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
407 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
413 /* Read in the symbolic header for an ECOFF object file. */
416 ecoff_slurp_symbolic_header (abfd
)
419 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
420 bfd_size_type external_hdr_size
;
422 HDRR
*internal_symhdr
;
424 /* See if we've already read it in. */
425 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
426 backend
->debug_swap
.sym_magic
)
429 /* See whether there is a symbolic header. */
430 if (ecoff_data (abfd
)->sym_filepos
== 0)
432 bfd_get_symcount (abfd
) = 0;
436 /* At this point bfd_get_symcount (abfd) holds the number of symbols
437 as read from the file header, but on ECOFF this is always the
438 size of the symbolic information header. It would be cleaner to
439 handle this when we first read the file in coffgen.c. */
440 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
441 if (bfd_get_symcount (abfd
) != external_hdr_size
)
443 bfd_set_error (bfd_error_bad_value
);
447 /* Read the symbolic information header. */
448 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
451 bfd_set_error (bfd_error_no_memory
);
455 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
456 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
457 != 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. */
487 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
490 struct ecoff_debug_info
*debug
;
492 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
493 HDRR
*internal_symhdr
;
494 bfd_size_type raw_base
;
495 bfd_size_type raw_size
;
497 bfd_size_type external_fdr_size
;
501 bfd_size_type raw_end
;
502 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
!= (PTR
) 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. */
533 #define UPDATE_RAW_END(start, count, size) \
534 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
535 if (cb_end > raw_end) \
538 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
539 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
540 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
541 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
542 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
543 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
544 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
545 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
546 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
547 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
548 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
550 #undef UPDATE_RAW_END
552 raw_size
= raw_end
- raw_base
;
555 ecoff_data (abfd
)->sym_filepos
= 0;
558 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
561 bfd_set_error (bfd_error_no_memory
);
565 (ecoff_data (abfd
)->sym_filepos
566 + backend
->debug_swap
.external_hdr_size
),
568 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
570 bfd_release (abfd
, raw
);
574 ecoff_data (abfd
)->raw_syments
= raw
;
576 /* Get pointers for the numeric offsets in the HDRR structure. */
577 #define FIX(off1, off2, type) \
578 if (internal_symhdr->off1 == 0) \
579 debug->off2 = (type) NULL; \
581 debug->off2 = (type) ((char *) raw \
582 + internal_symhdr->off1 \
584 FIX (cbLineOffset
, line
, unsigned char *);
585 FIX (cbDnOffset
, external_dnr
, PTR
);
586 FIX (cbPdOffset
, external_pdr
, PTR
);
587 FIX (cbSymOffset
, external_sym
, PTR
);
588 FIX (cbOptOffset
, external_opt
, PTR
);
589 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
590 FIX (cbSsOffset
, ss
, char *);
591 FIX (cbSsExtOffset
, ssext
, char *);
592 FIX (cbFdOffset
, external_fdr
, PTR
);
593 FIX (cbRfdOffset
, external_rfd
, PTR
);
594 FIX (cbExtOffset
, external_ext
, PTR
);
597 /* I don't want to always swap all the data, because it will just
598 waste time and most programs will never look at it. The only
599 time the linker needs most of the debugging information swapped
600 is when linking big-endian and little-endian MIPS object files
601 together, which is not a common occurrence.
603 We need to look at the fdr to deal with a lot of information in
604 the symbols, so we swap them here. */
605 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
,
606 (internal_symhdr
->ifdMax
*
607 sizeof (struct fdr
)));
608 if (debug
->fdr
== NULL
)
610 bfd_set_error (bfd_error_no_memory
);
613 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
614 fdr_ptr
= debug
->fdr
;
615 fraw_src
= (char *) debug
->external_fdr
;
616 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
617 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
618 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
623 /* ECOFF symbol table routines. The ECOFF symbol table is described
624 in gcc/mips-tfile.c. */
626 /* ECOFF uses two common sections. One is the usual one, and the
627 other is for small objects. All the small objects are kept
628 together, and then referenced via the gp pointer, which yields
629 faster assembler code. This is what we use for the small common
631 static asection ecoff_scom_section
;
632 static asymbol ecoff_scom_symbol
;
633 static asymbol
*ecoff_scom_symbol_ptr
;
635 /* Create an empty symbol. */
638 _bfd_ecoff_make_empty_symbol (abfd
)
641 ecoff_symbol_type
*new;
643 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
644 if (new == (ecoff_symbol_type
*) NULL
)
646 bfd_set_error (bfd_error_no_memory
);
647 return (asymbol
*) NULL
;
649 memset ((PTR
) new, 0, sizeof *new);
650 new->symbol
.section
= (asection
*) NULL
;
651 new->fdr
= (FDR
*) NULL
;
654 new->symbol
.the_bfd
= abfd
;
658 /* Set the BFD flags and section for an ECOFF symbol. */
661 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
666 asymbol
**indirect_ptr_ptr
;
668 asym
->the_bfd
= abfd
;
669 asym
->value
= ecoff_sym
->value
;
670 asym
->section
= &bfd_debug_section
;
673 /* An indirect symbol requires two consecutive stabs symbols. */
674 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
676 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
678 /* @@ Stuffing pointers into integers is a no-no.
679 We can usually get away with it if the integer is
680 large enough though. */
681 if (sizeof (asym
) > sizeof (bfd_vma
))
683 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
685 asym
->flags
= BSF_DEBUGGING
;
686 asym
->section
= bfd_und_section_ptr
;
687 *indirect_ptr_ptr
= NULL
;
691 if (ECOFF_IS_STAB (ecoff_sym
)
692 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
694 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
695 asym
->section
= bfd_ind_section_ptr
;
696 /* Pass this symbol on to the next call to this function. */
697 *indirect_ptr_ptr
= asym
;
701 /* Most symbol types are just for debugging. */
702 switch (ecoff_sym
->st
)
711 if (ECOFF_IS_STAB (ecoff_sym
))
713 asym
->flags
= BSF_DEBUGGING
;
718 asym
->flags
= BSF_DEBUGGING
;
723 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
726 asym
->flags
= BSF_LOCAL
;
727 /* Normally, a local stProc symbol will have a corresponding
728 external symbol. We mark the local symbol as a debugging
729 symbol, in order to prevent nm from printing both out.
730 Similarly, we mark stLabel and stabs symbols as debugging
731 symbols. In both cases, we do want to set the value
732 correctly based on the symbol class. */
733 if (ecoff_sym
->st
== stProc
734 || ecoff_sym
->st
== stLabel
735 || ECOFF_IS_STAB (ecoff_sym
))
736 asym
->flags
|= BSF_DEBUGGING
;
738 switch (ecoff_sym
->sc
)
741 /* Used for compiler generated labels. Leave them in the
742 debugging section, and mark them as local. If BSF_DEBUGGING
743 is set, then nm does not display them for some reason. If no
744 flags are set then the linker whines about them. */
745 asym
->flags
= BSF_LOCAL
;
748 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
749 asym
->value
-= asym
->section
->vma
;
752 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
753 asym
->value
-= asym
->section
->vma
;
756 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
757 asym
->value
-= asym
->section
->vma
;
760 asym
->flags
= BSF_DEBUGGING
;
763 asym
->section
= bfd_abs_section_ptr
;
766 asym
->section
= bfd_und_section_ptr
;
776 asym
->flags
= BSF_DEBUGGING
;
779 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
780 asym
->value
-= asym
->section
->vma
;
783 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
784 asym
->value
-= asym
->section
->vma
;
787 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
788 asym
->value
-= asym
->section
->vma
;
791 asym
->flags
= BSF_DEBUGGING
;
794 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
796 asym
->section
= bfd_com_section_ptr
;
802 if (ecoff_scom_section
.name
== NULL
)
804 /* Initialize the small common section. */
805 ecoff_scom_section
.name
= SCOMMON
;
806 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
807 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
808 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
809 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
810 ecoff_scom_symbol
.name
= SCOMMON
;
811 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
812 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
813 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
815 asym
->section
= &ecoff_scom_section
;
820 asym
->flags
= BSF_DEBUGGING
;
823 asym
->section
= bfd_und_section_ptr
;
828 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
829 asym
->value
-= asym
->section
->vma
;
834 asym
->flags
= BSF_DEBUGGING
;
837 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
838 asym
->value
-= asym
->section
->vma
;
844 /* Look for special constructors symbols and make relocation entries
845 in a special construction section. These are produced by the
846 -fgnu-linker argument to g++. */
847 if (ECOFF_IS_STAB (ecoff_sym
))
849 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
861 arelent_chain
*reloc_chain
;
862 unsigned int bitsize
;
864 /* Get a section with the same name as the symbol (usually
865 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
866 name ___CTOR_LIST (three underscores). We need
867 __CTOR_LIST (two underscores), since ECOFF doesn't use
868 a leading underscore. This should be handled by gcc,
869 but instead we do it here. Actually, this should all
870 be done differently anyhow. */
871 name
= bfd_asymbol_name (asym
);
872 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
877 section
= bfd_get_section_by_name (abfd
, name
);
878 if (section
== (asection
*) NULL
)
882 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
885 bfd_set_error (bfd_error_no_memory
);
889 section
= bfd_make_section (abfd
, copy
);
892 /* Build a reloc pointing to this constructor. */
894 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
897 bfd_set_error (bfd_error_no_memory
);
900 reloc_chain
->relent
.sym_ptr_ptr
=
901 bfd_get_section (asym
)->symbol_ptr_ptr
;
902 reloc_chain
->relent
.address
= section
->_raw_size
;
903 reloc_chain
->relent
.addend
= asym
->value
;
904 reloc_chain
->relent
.howto
=
905 ecoff_backend (abfd
)->constructor_reloc
;
907 /* Set up the constructor section to hold the reloc. */
908 section
->flags
= SEC_CONSTRUCTOR
;
909 ++section
->reloc_count
;
911 /* Constructor sections must be rounded to a boundary
912 based on the bitsize. These are not real sections--
913 they are handled specially by the linker--so the ECOFF
914 16 byte alignment restriction does not apply. */
915 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
916 section
->alignment_power
= 1;
917 while ((1 << section
->alignment_power
) < bitsize
/ 8)
918 ++section
->alignment_power
;
920 reloc_chain
->next
= section
->constructor_chain
;
921 section
->constructor_chain
= reloc_chain
;
922 section
->_raw_size
+= bitsize
/ 8;
924 /* Mark the symbol as a constructor. */
925 asym
->flags
|= BSF_CONSTRUCTOR
;
933 /* Read an ECOFF symbol table. */
936 _bfd_ecoff_slurp_symbol_table (abfd
)
939 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
940 const bfd_size_type external_ext_size
941 = backend
->debug_swap
.external_ext_size
;
942 const bfd_size_type external_sym_size
943 = backend
->debug_swap
.external_sym_size
;
944 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
945 = backend
->debug_swap
.swap_ext_in
;
946 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
947 = backend
->debug_swap
.swap_sym_in
;
948 bfd_size_type internal_size
;
949 ecoff_symbol_type
*internal
;
950 ecoff_symbol_type
*internal_ptr
;
951 asymbol
*indirect_ptr
;
957 /* If we've already read in the symbol table, do nothing. */
958 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
961 /* Get the symbolic information. */
962 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
963 &ecoff_data (abfd
)->debug_info
))
965 if (bfd_get_symcount (abfd
) == 0)
968 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
969 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
970 if (internal
== NULL
)
972 bfd_set_error (bfd_error_no_memory
);
976 internal_ptr
= internal
;
978 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
980 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
981 * external_ext_size
));
982 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
986 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
987 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
988 + internal_esym
.asym
.iss
);
989 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
990 &internal_ptr
->symbol
, 1, &indirect_ptr
))
992 /* The alpha uses a negative ifd field for section symbols. */
993 if (internal_esym
.ifd
>= 0)
994 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
995 + internal_esym
.ifd
);
997 internal_ptr
->fdr
= NULL
;
998 internal_ptr
->local
= false;
999 internal_ptr
->native
= (PTR
) eraw_src
;
1001 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1003 /* The local symbols must be accessed via the fdr's, because the
1004 string and aux indices are relative to the fdr information. */
1005 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1006 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1007 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1012 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1013 + fdr_ptr
->isymBase
* external_sym_size
);
1014 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1016 lraw_src
< lraw_end
;
1017 lraw_src
+= external_sym_size
, internal_ptr
++)
1021 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1022 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1024 + internal_sym
.iss
);
1025 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1026 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1028 internal_ptr
->fdr
= fdr_ptr
;
1029 internal_ptr
->local
= true;
1030 internal_ptr
->native
= (PTR
) lraw_src
;
1033 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1035 ecoff_data (abfd
)->canonical_symbols
= internal
;
1040 /* Return the amount of space needed for the canonical symbols. */
1043 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1046 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1047 &ecoff_data (abfd
)->debug_info
))
1050 if (bfd_get_symcount (abfd
) == 0)
1053 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1056 /* Get the canonical symbols. */
1059 _bfd_ecoff_get_symtab (abfd
, alocation
)
1061 asymbol
**alocation
;
1063 unsigned int counter
= 0;
1064 ecoff_symbol_type
*symbase
;
1065 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1067 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1069 if (bfd_get_symcount (abfd
) == 0)
1072 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1073 while (counter
< bfd_get_symcount (abfd
))
1075 *(location
++) = symbase
++;
1078 *location
++ = (ecoff_symbol_type
*) NULL
;
1079 return bfd_get_symcount (abfd
);
1082 /* Turn ECOFF type information into a printable string.
1083 ecoff_emit_aggregate and ecoff_type_to_string are from
1084 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1086 /* Write aggregate information to a string. */
1089 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1097 const struct ecoff_debug_swap
* const debug_swap
=
1098 &ecoff_backend (abfd
)->debug_swap
;
1099 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1100 unsigned int ifd
= rndx
->rfd
;
1101 unsigned int indx
= rndx
->index
;
1107 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1108 struct return type of a procedure compiled without -g. */
1109 if (ifd
== 0xffffffff
1110 || (rndx
->rfd
== 0xfff && indx
== 0))
1111 name
= "<undefined>";
1112 else if (indx
== indexNil
)
1118 if (debug_info
->external_rfd
== NULL
)
1119 fdr
= debug_info
->fdr
+ ifd
;
1124 (*debug_swap
->swap_rfd_in
) (abfd
,
1125 ((char *) debug_info
->external_rfd
1126 + ((fdr
->rfdBase
+ ifd
)
1127 * debug_swap
->external_rfd_size
)),
1129 fdr
= debug_info
->fdr
+ rfd
;
1132 indx
+= fdr
->isymBase
;
1134 (*debug_swap
->swap_sym_in
) (abfd
,
1135 ((char *) debug_info
->external_sym
1136 + indx
* debug_swap
->external_sym_size
),
1139 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1143 "%s %s { ifd = %u, index = %lu }",
1146 + debug_info
->symbolic_header
.iextMax
));
1149 /* Convert the type information to string format. */
1152 ecoff_type_to_string (abfd
, fdr
, indx
)
1157 union aux_ext
*aux_ptr
;
1166 unsigned int basic_type
;
1169 static char buffer2
[1024];
1174 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1175 bigendian
= fdr
->fBigendian
;
1177 for (i
= 0; i
< 7; i
++)
1179 qualifiers
[i
].low_bound
= 0;
1180 qualifiers
[i
].high_bound
= 0;
1181 qualifiers
[i
].stride
= 0;
1184 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1185 return "-1 (no type)";
1186 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1188 basic_type
= u
.ti
.bt
;
1189 qualifiers
[0].type
= u
.ti
.tq0
;
1190 qualifiers
[1].type
= u
.ti
.tq1
;
1191 qualifiers
[2].type
= u
.ti
.tq2
;
1192 qualifiers
[3].type
= u
.ti
.tq3
;
1193 qualifiers
[4].type
= u
.ti
.tq4
;
1194 qualifiers
[5].type
= u
.ti
.tq5
;
1195 qualifiers
[6].type
= tqNil
;
1198 * Go get the basic type.
1202 case btNil
: /* undefined */
1206 case btAdr
: /* address - integer same size as pointer */
1207 strcpy (p1
, "address");
1210 case btChar
: /* character */
1211 strcpy (p1
, "char");
1214 case btUChar
: /* unsigned character */
1215 strcpy (p1
, "unsigned char");
1218 case btShort
: /* short */
1219 strcpy (p1
, "short");
1222 case btUShort
: /* unsigned short */
1223 strcpy (p1
, "unsigned short");
1226 case btInt
: /* int */
1230 case btUInt
: /* unsigned int */
1231 strcpy (p1
, "unsigned int");
1234 case btLong
: /* long */
1235 strcpy (p1
, "long");
1238 case btULong
: /* unsigned long */
1239 strcpy (p1
, "unsigned long");
1242 case btFloat
: /* float (real) */
1243 strcpy (p1
, "float");
1246 case btDouble
: /* Double (real) */
1247 strcpy (p1
, "double");
1250 /* Structures add 1-2 aux words:
1251 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1252 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1254 case btStruct
: /* Structure (Record) */
1255 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1256 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1257 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1259 indx
++; /* skip aux words */
1262 /* Unions add 1-2 aux words:
1263 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1264 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1266 case btUnion
: /* Union */
1267 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1268 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1269 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1271 indx
++; /* skip aux words */
1274 /* Enumerations add 1-2 aux words:
1275 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1276 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1278 case btEnum
: /* Enumeration */
1279 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1280 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1281 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1283 indx
++; /* skip aux words */
1286 case btTypedef
: /* defined via a typedef, isymRef points */
1287 strcpy (p1
, "typedef");
1290 case btRange
: /* subrange of int */
1291 strcpy (p1
, "subrange");
1294 case btSet
: /* pascal sets */
1298 case btComplex
: /* fortran complex */
1299 strcpy (p1
, "complex");
1302 case btDComplex
: /* fortran double complex */
1303 strcpy (p1
, "double complex");
1306 case btIndirect
: /* forward or unnamed typedef */
1307 strcpy (p1
, "forward/unamed typedef");
1310 case btFixedDec
: /* Fixed Decimal */
1311 strcpy (p1
, "fixed decimal");
1314 case btFloatDec
: /* Float Decimal */
1315 strcpy (p1
, "float decimal");
1318 case btString
: /* Varying Length Character String */
1319 strcpy (p1
, "string");
1322 case btBit
: /* Aligned Bit String */
1326 case btPicture
: /* Picture */
1327 strcpy (p1
, "picture");
1330 case btVoid
: /* Void */
1331 strcpy (p1
, "void");
1335 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1339 p1
+= strlen (buffer1
);
1342 * If this is a bitfield, get the bitsize.
1348 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1349 sprintf (p1
, " : %d", bitsize
);
1350 p1
+= strlen (buffer1
);
1355 * Deal with any qualifiers.
1357 if (qualifiers
[0].type
!= tqNil
)
1360 * Snarf up any array bounds in the correct order. Arrays
1361 * store 5 successive words in the aux. table:
1362 * word 0 RNDXR to type of the bounds (ie, int)
1363 * word 1 Current file descriptor index
1365 * word 3 high bound (or -1 if [])
1366 * word 4 stride size in bits
1368 for (i
= 0; i
< 7; i
++)
1370 if (qualifiers
[i
].type
== tqArray
)
1372 qualifiers
[i
].low_bound
=
1373 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1374 qualifiers
[i
].high_bound
=
1375 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1376 qualifiers
[i
].stride
=
1377 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1383 * Now print out the qualifiers.
1385 for (i
= 0; i
< 6; i
++)
1387 switch (qualifiers
[i
].type
)
1394 strcpy (p2
, "ptr to ");
1395 p2
+= sizeof ("ptr to ")-1;
1399 strcpy (p2
, "volatile ");
1400 p2
+= sizeof ("volatile ")-1;
1404 strcpy (p2
, "far ");
1405 p2
+= sizeof ("far ")-1;
1409 strcpy (p2
, "func. ret. ");
1410 p2
+= sizeof ("func. ret. ");
1415 int first_array
= i
;
1418 /* Print array bounds reversed (ie, in the order the C
1419 programmer writes them). C is such a fun language.... */
1421 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1424 for (j
= i
; j
>= first_array
; j
--)
1426 strcpy (p2
, "array [");
1427 p2
+= sizeof ("array [")-1;
1428 if (qualifiers
[j
].low_bound
!= 0)
1430 "%ld:%ld {%ld bits}",
1431 (long) qualifiers
[j
].low_bound
,
1432 (long) qualifiers
[j
].high_bound
,
1433 (long) qualifiers
[j
].stride
);
1435 else if (qualifiers
[j
].high_bound
!= -1)
1438 (long) (qualifiers
[j
].high_bound
+ 1),
1439 (long) (qualifiers
[j
].stride
));
1442 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1445 strcpy (p2
, "] of ");
1446 p2
+= sizeof ("] of ")-1;
1454 strcpy (p2
, buffer1
);
1458 /* Return information about ECOFF symbol SYMBOL in RET. */
1462 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1463 bfd
*abfd
; /* Ignored. */
1467 bfd_symbol_info (symbol
, ret
);
1470 /* Print information about an ECOFF symbol. */
1473 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1477 bfd_print_symbol_type how
;
1479 const struct ecoff_debug_swap
* const debug_swap
1480 = &ecoff_backend (abfd
)->debug_swap
;
1481 FILE *file
= (FILE *)filep
;
1485 case bfd_print_symbol_name
:
1486 fprintf (file
, "%s", symbol
->name
);
1488 case bfd_print_symbol_more
:
1489 if (ecoffsymbol (symbol
)->local
)
1493 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1495 fprintf (file
, "ecoff local ");
1496 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1497 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1498 (unsigned) ecoff_sym
.sc
);
1504 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1506 fprintf (file
, "ecoff extern ");
1507 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1508 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1509 (unsigned) ecoff_ext
.asym
.sc
);
1512 case bfd_print_symbol_all
:
1513 /* Print out the symbols in a reasonable way */
1522 if (ecoffsymbol (symbol
)->local
)
1524 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1527 pos
= ((((char *) ecoffsymbol (symbol
)->native
1528 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1529 / debug_swap
->external_sym_size
)
1530 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1537 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1540 pos
= (((char *) ecoffsymbol (symbol
)->native
1541 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1542 / debug_swap
->external_ext_size
);
1543 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1544 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1545 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1548 fprintf (file
, "[%3d] %c ",
1550 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1551 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1552 (unsigned) ecoff_ext
.asym
.st
,
1553 (unsigned) ecoff_ext
.asym
.sc
,
1554 (unsigned) ecoff_ext
.asym
.index
,
1555 jmptbl
, cobol_main
, weakext
,
1558 if (ecoffsymbol (symbol
)->fdr
!= NULL
1559 && ecoff_ext
.asym
.index
!= indexNil
)
1564 bfd_size_type sym_base
;
1565 union aux_ext
*aux_base
;
1567 fdr
= ecoffsymbol (symbol
)->fdr
;
1568 indx
= ecoff_ext
.asym
.index
;
1570 /* sym_base is used to map the fdr relative indices which
1571 appear in the file to the position number which we are
1573 sym_base
= fdr
->isymBase
;
1574 if (ecoffsymbol (symbol
)->local
)
1576 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1578 /* aux_base is the start of the aux entries for this file;
1579 asym.index is an offset from this. */
1580 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1583 /* The aux entries are stored in host byte order; the
1584 order is indicated by a bit in the fdr. */
1585 bigendian
= fdr
->fBigendian
;
1587 /* This switch is basically from gcc/mips-tdump.c */
1588 switch (ecoff_ext
.asym
.st
)
1596 fprintf (file
, "\n End+1 symbol: %ld",
1597 (long) (indx
+ sym_base
));
1601 if (ecoff_ext
.asym
.sc
== scText
1602 || ecoff_ext
.asym
.sc
== scInfo
)
1603 fprintf (file
, "\n First symbol: %ld",
1604 (long) (indx
+ sym_base
));
1606 fprintf (file
, "\n First symbol: %ld",
1608 (AUX_GET_ISYM (bigendian
,
1609 &aux_base
[ecoff_ext
.asym
.index
])
1615 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1617 else if (ecoffsymbol (symbol
)->local
)
1618 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1620 (AUX_GET_ISYM (bigendian
,
1621 &aux_base
[ecoff_ext
.asym
.index
])
1623 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1625 fprintf (file
, "\n Local symbol: %ld",
1628 + (ecoff_data (abfd
)
1629 ->debug_info
.symbolic_header
.iextMax
)));
1633 fprintf (file
, "\n struct; End+1 symbol: %ld",
1634 (long) (indx
+ sym_base
));
1638 fprintf (file
, "\n union; End+1 symbol: %ld",
1639 (long) (indx
+ sym_base
));
1643 fprintf (file
, "\n enum; End+1 symbol: %ld",
1644 (long) (indx
+ sym_base
));
1648 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1649 fprintf (file
, "\n Type: %s",
1650 ecoff_type_to_string (abfd
, fdr
, indx
));
1659 /* Read in the relocs for a section. */
1662 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1667 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1668 arelent
*internal_relocs
;
1669 bfd_size_type external_reloc_size
;
1670 bfd_size_type external_relocs_size
;
1671 char *external_relocs
;
1675 if (section
->relocation
!= (arelent
*) NULL
1676 || section
->reloc_count
== 0
1677 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1680 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1683 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1685 * section
->reloc_count
));
1686 external_reloc_size
= backend
->external_reloc_size
;
1687 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1688 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1689 if (internal_relocs
== (arelent
*) NULL
1690 || external_relocs
== (char *) NULL
)
1692 bfd_set_error (bfd_error_no_memory
);
1695 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1697 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1698 != external_relocs_size
)
1701 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1703 struct internal_reloc intern
;
1705 (*backend
->swap_reloc_in
) (abfd
,
1706 external_relocs
+ i
* external_reloc_size
,
1709 if (intern
.r_extern
)
1711 /* r_symndx is an index into the external symbols. */
1712 BFD_ASSERT (intern
.r_symndx
>= 0
1714 < (ecoff_data (abfd
)
1715 ->debug_info
.symbolic_header
.iextMax
)));
1716 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1719 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1720 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1722 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1727 CONST
char *sec_name
;
1730 /* r_symndx is a section key. */
1731 switch (intern
.r_symndx
)
1733 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1734 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1735 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1736 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1737 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1738 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1739 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1740 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1741 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1742 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1743 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1744 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1745 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1749 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1750 if (sec
== (asection
*) NULL
)
1752 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1754 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1757 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1759 /* Let the backend select the howto field and do any other
1760 required processing. */
1761 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1764 bfd_release (abfd
, external_relocs
);
1766 section
->relocation
= internal_relocs
;
1771 /* Get a canonical list of relocs. */
1774 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1782 if (section
->flags
& SEC_CONSTRUCTOR
)
1784 arelent_chain
*chain
;
1786 /* This section has relocs made up by us, not the file, so take
1787 them out of their chain and place them into the data area
1789 for (count
= 0, chain
= section
->constructor_chain
;
1790 count
< section
->reloc_count
;
1791 count
++, chain
= chain
->next
)
1792 *relptr
++ = &chain
->relent
;
1798 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1801 tblptr
= section
->relocation
;
1803 for (count
= 0; count
< section
->reloc_count
; count
++)
1804 *relptr
++ = tblptr
++;
1807 *relptr
= (arelent
*) NULL
;
1809 return section
->reloc_count
;
1812 /* Provided a BFD, a section and an offset into the section, calculate
1813 and return the name of the source file and the line nearest to the
1818 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1819 filename_ptr
, functionname_ptr
, retline_ptr
)
1822 asymbol
**ignore_symbols
;
1824 CONST
char **filename_ptr
;
1825 CONST
char **functionname_ptr
;
1826 unsigned int *retline_ptr
;
1828 const struct ecoff_debug_swap
* const debug_swap
1829 = &ecoff_backend (abfd
)->debug_swap
;
1830 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1831 struct ecoff_find_line
*line_info
;
1833 /* If we're not in the .text section, we don't have any line
1835 if (strcmp (section
->name
, _TEXT
) != 0
1836 || offset
< ecoff_data (abfd
)->text_start
1837 || offset
>= ecoff_data (abfd
)->text_end
)
1840 /* Make sure we have the FDR's. */
1841 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1842 || bfd_get_symcount (abfd
) == 0)
1845 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1847 ecoff_data (abfd
)->find_line_info
=
1848 ((struct ecoff_find_line
*)
1849 bfd_alloc (abfd
, sizeof (struct ecoff_find_line
)));
1850 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1852 bfd_set_error (bfd_error_no_memory
);
1856 line_info
= ecoff_data (abfd
)->find_line_info
;
1858 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1859 debug_swap
, line_info
, filename_ptr
,
1860 functionname_ptr
, retline_ptr
);
1863 /* Copy private BFD data. This is called by objcopy and strip. We
1864 use it to copy the ECOFF debugging information from one BFD to the
1865 other. It would be theoretically possible to represent the ECOFF
1866 debugging information in the symbol table. However, it would be a
1867 lot of work, and there would be little gain (gas, gdb, and ld
1868 already access the ECOFF debugging information via the
1869 ecoff_debug_info structure, and that structure would have to be
1870 retained in order to support ECOFF debugging in MIPS ELF).
1872 The debugging information for the ECOFF external symbols comes from
1873 the symbol table, so this function only handles the other debugging
1877 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1881 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1882 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1884 asymbol
**sym_ptr_ptr
;
1888 /* This function is selected based on the input vector. We only
1889 want to copy information over if the output BFD also uses ECOFF
1891 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1894 /* Copy the GP value and the register masks. */
1895 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1896 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1897 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1898 for (i
= 0; i
< 3; i
++)
1899 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1901 /* Copy the version stamp. */
1902 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1904 /* If there are no symbols, don't copy any debugging information. */
1905 c
= bfd_get_symcount (obfd
);
1906 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1907 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1910 /* See if there are any local symbols. */
1912 for (; c
> 0; c
--, sym_ptr_ptr
++)
1914 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1923 /* There are some local symbols. We just bring over all the
1924 debugging information. FIXME: This is not quite the right
1925 thing to do. If the user has asked us to discard all
1926 debugging information, then we are probably going to wind up
1927 keeping it because there will probably be some local symbol
1928 which objcopy did not discard. We should actually break
1929 apart the debugging information and only keep that which
1930 applies to the symbols we want to keep. */
1931 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1932 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1933 oinfo
->line
= iinfo
->line
;
1935 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1936 oinfo
->external_dnr
= iinfo
->external_dnr
;
1938 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1939 oinfo
->external_pdr
= iinfo
->external_pdr
;
1941 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1942 oinfo
->external_sym
= iinfo
->external_sym
;
1944 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1945 oinfo
->external_opt
= iinfo
->external_opt
;
1947 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1948 oinfo
->external_aux
= iinfo
->external_aux
;
1950 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1951 oinfo
->ss
= iinfo
->ss
;
1953 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1954 oinfo
->external_fdr
= iinfo
->external_fdr
;
1956 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1957 oinfo
->external_rfd
= iinfo
->external_rfd
;
1961 /* We are discarding all the local symbol information. Look
1962 through the external symbols and remove all references to FDR
1963 or aux information. */
1964 c
= bfd_get_symcount (obfd
);
1965 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1966 for (; c
> 0; c
--, sym_ptr_ptr
++)
1970 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1971 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1973 esym
.asym
.index
= indexNil
;
1974 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1975 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1982 /* Set the architecture. The supported architecture is stored in the
1983 backend pointer. We always set the architecture anyhow, since many
1984 callers ignore the return value. */
1987 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1989 enum bfd_architecture arch
;
1990 unsigned long machine
;
1992 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1993 return arch
== ecoff_backend (abfd
)->arch
;
1996 /* Get the size of the section headers. */
2000 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
2009 for (current
= abfd
->sections
;
2010 current
!= (asection
*)NULL
;
2011 current
= current
->next
)
2014 ret
= (bfd_coff_filhsz (abfd
)
2015 + bfd_coff_aoutsz (abfd
)
2016 + c
* bfd_coff_scnhsz (abfd
));
2017 return BFD_ALIGN (ret
, 16);
2020 /* Get the contents of a section. */
2023 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2028 bfd_size_type count
;
2030 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2034 /* Calculate the file position for each section, and set
2038 ecoff_compute_section_file_positions (abfd
)
2046 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2049 for (current
= abfd
->sections
;
2050 current
!= (asection
*) NULL
;
2051 current
= current
->next
)
2053 unsigned int alignment_power
;
2055 /* Only deal with sections which have contents */
2056 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2059 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2060 supposed to indicate the number of .pdata entries that are
2061 really in the section. Each entry is 8 bytes. We store this
2062 away in line_filepos before increasing the section size. */
2063 if (strcmp (current
->name
, _PDATA
) != 0)
2064 alignment_power
= current
->alignment_power
;
2067 current
->line_filepos
= current
->_raw_size
/ 8;
2068 alignment_power
= 4;
2071 /* On Ultrix, the data sections in an executable file must be
2072 aligned to a page boundary within the file. This does not
2073 affect the section size, though. FIXME: Does this work for
2074 other platforms? It requires some modification for the
2075 Alpha, because .rdata on the Alpha goes with the text, not
2077 if ((abfd
->flags
& EXEC_P
) != 0
2078 && (abfd
->flags
& D_PAGED
) != 0
2079 && first_data
!= false
2080 && (current
->flags
& SEC_CODE
) == 0
2081 && (! ecoff_backend (abfd
)->rdata_in_text
2082 || strcmp (current
->name
, _RDATA
) != 0)
2083 && strcmp (current
->name
, _PDATA
) != 0)
2085 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2087 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2090 else if (strcmp (current
->name
, _LIB
) == 0)
2092 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2093 /* On Irix 4, the location of contents of the .lib section
2094 from a shared library section is also rounded up to a
2097 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2100 /* Align the sections in the file to the same boundary on
2101 which they are aligned in virtual memory. */
2103 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2105 current
->filepos
= sofar
;
2107 sofar
+= current
->_raw_size
;
2109 /* make sure that this section is of the right size too */
2111 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2112 current
->_raw_size
+= sofar
- old_sofar
;
2115 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2118 /* Determine the location of the relocs for all the sections in the
2119 output file, as well as the location of the symbolic debugging
2122 static bfd_size_type
2123 ecoff_compute_reloc_file_positions (abfd
)
2126 const bfd_size_type external_reloc_size
=
2127 ecoff_backend (abfd
)->external_reloc_size
;
2128 file_ptr reloc_base
;
2129 bfd_size_type reloc_size
;
2133 if (! abfd
->output_has_begun
)
2135 ecoff_compute_section_file_positions (abfd
);
2136 abfd
->output_has_begun
= true;
2139 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2142 for (current
= abfd
->sections
;
2143 current
!= (asection
*)NULL
;
2144 current
= current
->next
)
2146 if (current
->reloc_count
== 0)
2147 current
->rel_filepos
= 0;
2150 bfd_size_type relsize
;
2152 current
->rel_filepos
= reloc_base
;
2153 relsize
= current
->reloc_count
* external_reloc_size
;
2154 reloc_size
+= relsize
;
2155 reloc_base
+= relsize
;
2159 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2161 /* At least on Ultrix, the symbol table of an executable file must
2162 be aligned to a page boundary. FIXME: Is this true on other
2164 if ((abfd
->flags
& EXEC_P
) != 0
2165 && (abfd
->flags
& D_PAGED
) != 0)
2166 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2167 &~ (ecoff_backend (abfd
)->round
- 1));
2169 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2174 /* Set the contents of a section. */
2177 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2182 bfd_size_type count
;
2184 /* This must be done first, because bfd_set_section_contents is
2185 going to set output_has_begun to true. */
2186 if (abfd
->output_has_begun
== false)
2187 ecoff_compute_section_file_positions (abfd
);
2189 /* If this is a .lib section, bump the vma address so that it winds
2190 up being the number of .lib sections output. This is right for
2191 Irix 4. Ian Taylor <ian@cygnus.com>. */
2192 if (strcmp (section
->name
, _LIB
) == 0)
2198 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2199 || bfd_write (location
, 1, count
, abfd
) != count
)
2205 /* Get the GP value for an ECOFF file. This is a hook used by
2209 bfd_ecoff_get_gp_value (abfd
)
2212 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2213 || bfd_get_format (abfd
) != bfd_object
)
2215 bfd_set_error (bfd_error_invalid_operation
);
2219 return ecoff_data (abfd
)->gp
;
2222 /* Set the GP value for an ECOFF file. This is a hook used by the
2226 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2230 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2231 || bfd_get_format (abfd
) != bfd_object
)
2233 bfd_set_error (bfd_error_invalid_operation
);
2237 ecoff_data (abfd
)->gp
= gp_value
;
2242 /* Set the register masks for an ECOFF file. This is a hook used by
2246 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2248 unsigned long gprmask
;
2249 unsigned long fprmask
;
2250 unsigned long *cprmask
;
2252 ecoff_data_type
*tdata
;
2254 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2255 || bfd_get_format (abfd
) != bfd_object
)
2257 bfd_set_error (bfd_error_invalid_operation
);
2261 tdata
= ecoff_data (abfd
);
2262 tdata
->gprmask
= gprmask
;
2263 tdata
->fprmask
= fprmask
;
2264 if (cprmask
!= (unsigned long *) NULL
)
2268 for (i
= 0; i
< 3; i
++)
2269 tdata
->cprmask
[i
] = cprmask
[i
];
2275 /* Get ECOFF EXTR information for an external symbol. This function
2276 is passed to bfd_ecoff_debug_externals. */
2279 ecoff_get_extr (sym
, esym
)
2283 ecoff_symbol_type
*ecoff_sym_ptr
;
2286 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2287 || ecoffsymbol (sym
)->native
== NULL
)
2289 /* Don't include debugging, local, or section symbols. */
2290 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2291 || (sym
->flags
& BSF_LOCAL
) != 0
2292 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2296 esym
->cobol_main
= 0;
2300 /* FIXME: we can do better than this for st and sc. */
2301 esym
->asym
.st
= stGlobal
;
2302 esym
->asym
.sc
= scAbs
;
2303 esym
->asym
.reserved
= 0;
2304 esym
->asym
.index
= indexNil
;
2308 ecoff_sym_ptr
= ecoffsymbol (sym
);
2310 if (ecoff_sym_ptr
->local
)
2313 input_bfd
= bfd_asymbol_bfd (sym
);
2314 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2315 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2317 /* If the symbol was defined by the linker, then esym will be
2318 undefined but sym will not be. Get a better class for such a
2320 if ((esym
->asym
.sc
== scUndefined
2321 || esym
->asym
.sc
== scSUndefined
)
2322 && ! bfd_is_und_section (bfd_get_section (sym
)))
2323 esym
->asym
.sc
= scAbs
;
2325 /* Adjust the FDR index for the symbol by that used for the input
2327 if (esym
->ifd
!= -1)
2329 struct ecoff_debug_info
*input_debug
;
2331 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2332 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2333 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2334 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2340 /* Set the external symbol index. This routine is passed to
2341 bfd_ecoff_debug_externals. */
2344 ecoff_set_index (sym
, indx
)
2348 ecoff_set_sym_index (sym
, indx
);
2351 /* Write out an ECOFF file. */
2354 _bfd_ecoff_write_object_contents (abfd
)
2357 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2358 const bfd_vma round
= backend
->round
;
2359 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2360 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2361 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2362 const bfd_size_type external_hdr_size
2363 = backend
->debug_swap
.external_hdr_size
;
2364 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2365 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2367 struct internal_reloc
*))
2368 = backend
->adjust_reloc_out
;
2369 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2370 const struct internal_reloc
*,
2372 = backend
->swap_reloc_out
;
2373 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2374 HDRR
* const symhdr
= &debug
->symbolic_header
;
2377 bfd_size_type reloc_size
;
2378 bfd_size_type text_size
;
2380 boolean set_text_start
;
2381 bfd_size_type data_size
;
2383 boolean set_data_start
;
2384 bfd_size_type bss_size
;
2386 PTR reloc_buff
= NULL
;
2387 struct internal_filehdr internal_f
;
2388 struct internal_aouthdr internal_a
;
2391 /* Determine where the sections and relocs will go in the output
2393 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2396 for (current
= abfd
->sections
;
2397 current
!= (asection
*)NULL
;
2398 current
= current
->next
)
2400 current
->target_index
= count
;
2404 if ((abfd
->flags
& D_PAGED
) != 0)
2405 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2409 set_text_start
= false;
2412 set_data_start
= false;
2415 /* Write section headers to the file. */
2417 /* Allocate buff big enough to hold a section header,
2418 file header, or a.out header. */
2426 buff
= (PTR
) malloc (siz
);
2429 bfd_set_error (bfd_error_no_memory
);
2434 internal_f
.f_nscns
= 0;
2435 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2437 for (current
= abfd
->sections
;
2438 current
!= (asection
*) NULL
;
2439 current
= current
->next
)
2441 struct internal_scnhdr section
;
2444 ++internal_f
.f_nscns
;
2446 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2448 /* This seems to be correct for Irix 4 shared libraries. */
2449 vma
= bfd_get_section_vma (abfd
, current
);
2450 if (strcmp (current
->name
, _LIB
) == 0)
2451 section
.s_vaddr
= 0;
2453 section
.s_vaddr
= vma
;
2455 section
.s_paddr
= vma
;
2456 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2458 /* If this section is unloadable then the scnptr will be 0. */
2459 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2460 section
.s_scnptr
= 0;
2462 section
.s_scnptr
= current
->filepos
;
2463 section
.s_relptr
= current
->rel_filepos
;
2465 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2466 object file produced by the assembler is supposed to point to
2467 information about how much room is required by objects of
2468 various different sizes. I think this only matters if we
2469 want the linker to compute the best size to use, or
2470 something. I don't know what happens if the information is
2472 if (strcmp (current
->name
, _PDATA
) != 0)
2473 section
.s_lnnoptr
= 0;
2476 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2477 hold the number of entries in the section (each entry is
2478 8 bytes). We stored this in the line_filepos field in
2479 ecoff_compute_section_file_positions. */
2480 section
.s_lnnoptr
= current
->line_filepos
;
2483 section
.s_nreloc
= current
->reloc_count
;
2484 section
.s_nlnno
= 0;
2485 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2488 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2489 || bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2492 if ((section
.s_flags
& STYP_TEXT
) != 0
2493 || ((section
.s_flags
& STYP_RDATA
) != 0
2494 && backend
->rdata_in_text
)
2495 || strcmp (current
->name
, _PDATA
) == 0)
2497 text_size
+= bfd_get_section_size_before_reloc (current
);
2498 if (! set_text_start
|| text_start
> vma
)
2501 set_text_start
= true;
2504 else if ((section
.s_flags
& STYP_RDATA
) != 0
2505 || (section
.s_flags
& STYP_DATA
) != 0
2506 || (section
.s_flags
& STYP_LITA
) != 0
2507 || (section
.s_flags
& STYP_LIT8
) != 0
2508 || (section
.s_flags
& STYP_LIT4
) != 0
2509 || (section
.s_flags
& STYP_SDATA
) != 0
2510 || strcmp (current
->name
, _XDATA
) == 0)
2512 data_size
+= bfd_get_section_size_before_reloc (current
);
2513 if (! set_data_start
|| data_start
> vma
)
2516 set_data_start
= true;
2519 else if ((section
.s_flags
& STYP_BSS
) != 0
2520 || (section
.s_flags
& STYP_SBSS
) != 0)
2521 bss_size
+= bfd_get_section_size_before_reloc (current
);
2522 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
2528 /* Set up the file header. */
2530 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2532 /* We will NOT put a fucking timestamp in the header here. Every
2533 time you put it back, I will come in and take it out again. I'm
2534 sorry. This field does not belong here. We fill it with a 0 so
2535 it compares the same but is not a reasonable time. --
2537 internal_f
.f_timdat
= 0;
2539 if (bfd_get_symcount (abfd
) != 0)
2541 /* The ECOFF f_nsyms field is not actually the number of
2542 symbols, it's the size of symbolic information header. */
2543 internal_f
.f_nsyms
= external_hdr_size
;
2544 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2548 internal_f
.f_nsyms
= 0;
2549 internal_f
.f_symptr
= 0;
2552 internal_f
.f_opthdr
= aoutsz
;
2554 internal_f
.f_flags
= F_LNNO
;
2555 if (reloc_size
== 0)
2556 internal_f
.f_flags
|= F_RELFLG
;
2557 if (bfd_get_symcount (abfd
) == 0)
2558 internal_f
.f_flags
|= F_LSYMS
;
2559 if (abfd
->flags
& EXEC_P
)
2560 internal_f
.f_flags
|= F_EXEC
;
2562 if (! abfd
->xvec
->byteorder_big_p
)
2563 internal_f
.f_flags
|= F_AR32WR
;
2565 internal_f
.f_flags
|= F_AR32W
;
2567 /* Set up the ``optional'' header. */
2568 if ((abfd
->flags
& D_PAGED
) != 0)
2569 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2571 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2573 /* FIXME: Is this really correct? */
2574 internal_a
.vstamp
= symhdr
->vstamp
;
2576 /* At least on Ultrix, these have to be rounded to page boundaries.
2577 FIXME: Is this true on other platforms? */
2578 if ((abfd
->flags
& D_PAGED
) != 0)
2580 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2581 internal_a
.text_start
= text_start
&~ (round
- 1);
2582 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2583 internal_a
.data_start
= data_start
&~ (round
- 1);
2587 internal_a
.tsize
= text_size
;
2588 internal_a
.text_start
= text_start
;
2589 internal_a
.dsize
= data_size
;
2590 internal_a
.data_start
= data_start
;
2593 /* On Ultrix, the initial portions of the .sbss and .bss segments
2594 are at the end of the data section. The bsize field in the
2595 optional header records how many bss bytes are required beyond
2596 those in the data section. The value is not rounded to a page
2598 if (bss_size
< internal_a
.dsize
- data_size
)
2601 bss_size
-= internal_a
.dsize
- data_size
;
2602 internal_a
.bsize
= bss_size
;
2603 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2605 internal_a
.entry
= bfd_get_start_address (abfd
);
2607 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2609 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2610 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2611 for (i
= 0; i
< 4; i
++)
2612 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2614 /* Write out the file header and the optional header. */
2616 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2619 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2620 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2623 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2624 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2627 /* Build the external symbol information. This must be done before
2628 writing out the relocs so that we know the symbol indices. We
2629 don't do this if this BFD was created by the backend linker,
2630 since it will have already handled the symbols and relocs. */
2631 if (! ecoff_data (abfd
)->linker
)
2633 symhdr
->iextMax
= 0;
2634 symhdr
->issExtMax
= 0;
2635 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2636 debug
->ssext
= debug
->ssext_end
= NULL
;
2637 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2638 (((abfd
->flags
& EXEC_P
) == 0)
2640 ecoff_get_extr
, ecoff_set_index
)
2644 /* Write out the relocs. */
2645 for (current
= abfd
->sections
;
2646 current
!= (asection
*) NULL
;
2647 current
= current
->next
)
2649 arelent
**reloc_ptr_ptr
;
2650 arelent
**reloc_end
;
2653 if (current
->reloc_count
== 0)
2657 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2658 if (reloc_buff
== NULL
)
2660 bfd_set_error (bfd_error_no_memory
);
2664 reloc_ptr_ptr
= current
->orelocation
;
2665 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2666 out_ptr
= (char *) reloc_buff
;
2668 reloc_ptr_ptr
< reloc_end
;
2669 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2673 struct internal_reloc in
;
2675 memset ((PTR
) &in
, 0, sizeof in
);
2677 reloc
= *reloc_ptr_ptr
;
2678 sym
= *reloc
->sym_ptr_ptr
;
2680 in
.r_vaddr
= (reloc
->address
2681 + bfd_get_section_vma (abfd
, current
));
2682 in
.r_type
= reloc
->howto
->type
;
2684 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2686 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2693 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2694 if (strcmp (name
, ".text") == 0)
2695 in
.r_symndx
= RELOC_SECTION_TEXT
;
2696 else if (strcmp (name
, ".rdata") == 0)
2697 in
.r_symndx
= RELOC_SECTION_RDATA
;
2698 else if (strcmp (name
, ".data") == 0)
2699 in
.r_symndx
= RELOC_SECTION_DATA
;
2700 else if (strcmp (name
, ".sdata") == 0)
2701 in
.r_symndx
= RELOC_SECTION_SDATA
;
2702 else if (strcmp (name
, ".sbss") == 0)
2703 in
.r_symndx
= RELOC_SECTION_SBSS
;
2704 else if (strcmp (name
, ".bss") == 0)
2705 in
.r_symndx
= RELOC_SECTION_BSS
;
2706 else if (strcmp (name
, ".init") == 0)
2707 in
.r_symndx
= RELOC_SECTION_INIT
;
2708 else if (strcmp (name
, ".lit8") == 0)
2709 in
.r_symndx
= RELOC_SECTION_LIT8
;
2710 else if (strcmp (name
, ".lit4") == 0)
2711 in
.r_symndx
= RELOC_SECTION_LIT4
;
2712 else if (strcmp (name
, ".xdata") == 0)
2713 in
.r_symndx
= RELOC_SECTION_XDATA
;
2714 else if (strcmp (name
, ".pdata") == 0)
2715 in
.r_symndx
= RELOC_SECTION_PDATA
;
2716 else if (strcmp (name
, ".fini") == 0)
2717 in
.r_symndx
= RELOC_SECTION_FINI
;
2718 else if (strcmp (name
, ".lita") == 0)
2719 in
.r_symndx
= RELOC_SECTION_LITA
;
2720 else if (strcmp (name
, "*ABS*") == 0)
2721 in
.r_symndx
= RELOC_SECTION_ABS
;
2727 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2729 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2732 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2734 if (bfd_write (reloc_buff
,
2735 external_reloc_size
, current
->reloc_count
, abfd
)
2736 != external_reloc_size
* current
->reloc_count
)
2738 bfd_release (abfd
, reloc_buff
);
2742 /* Write out the symbolic debugging information. */
2743 if (bfd_get_symcount (abfd
) > 0)
2745 /* Write out the debugging information. */
2746 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2747 ecoff_data (abfd
)->sym_filepos
)
2753 /* The .bss section of a demand paged executable must receive an
2754 entire page. If there are symbols, the symbols will start on the
2755 next page. If there are no symbols, we must fill out the page by
2757 if (bfd_get_symcount (abfd
) == 0
2758 && (abfd
->flags
& EXEC_P
) != 0
2759 && (abfd
->flags
& D_PAGED
) != 0)
2763 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2766 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2768 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2771 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2775 if (reloc_buff
!= NULL
)
2776 bfd_release (abfd
, reloc_buff
);
2781 if (reloc_buff
!= NULL
)
2782 bfd_release (abfd
, reloc_buff
);
2788 /* Archive handling. ECOFF uses what appears to be a unique type of
2789 archive header (armap). The byte ordering of the armap and the
2790 contents are encoded in the name of the armap itself. At least for
2791 now, we only support archives with the same byte ordering in the
2792 armap and the contents.
2794 The first four bytes in the armap are the number of symbol
2795 definitions. This is always a power of two.
2797 This is followed by the symbol definitions. Each symbol definition
2798 occupies 8 bytes. The first four bytes are the offset from the
2799 start of the armap strings to the null-terminated string naming
2800 this symbol. The second four bytes are the file offset to the
2801 archive member which defines this symbol. If the second four bytes
2802 are 0, then this is not actually a symbol definition, and it should
2805 The symbols are hashed into the armap with a closed hashing scheme.
2806 See the functions below for the details of the algorithm.
2808 After the symbol definitions comes four bytes holding the size of
2809 the string table, followed by the string table itself. */
2811 /* The name of an archive headers looks like this:
2812 __________E[BL]E[BL]_ (with a trailing space).
2813 The trailing space is changed to an X if the archive is changed to
2814 indicate that the armap is out of date.
2816 The Alpha seems to use ________64E[BL]E[BL]_. */
2818 #define ARMAP_BIG_ENDIAN 'B'
2819 #define ARMAP_LITTLE_ENDIAN 'L'
2820 #define ARMAP_MARKER 'E'
2821 #define ARMAP_START_LENGTH 10
2822 #define ARMAP_HEADER_MARKER_INDEX 10
2823 #define ARMAP_HEADER_ENDIAN_INDEX 11
2824 #define ARMAP_OBJECT_MARKER_INDEX 12
2825 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2826 #define ARMAP_END_INDEX 14
2827 #define ARMAP_END "_ "
2829 /* This is a magic number used in the hashing algorithm. */
2830 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2832 /* This returns the hash value to use for a string. It also sets
2833 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2834 is the number of entries in the hash table, and HLOG is the log
2838 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2840 unsigned int *rehash
;
2848 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2849 hash
*= ARMAP_HASH_MAGIC
;
2850 *rehash
= (hash
& (size
- 1)) | 1;
2851 return hash
>> (32 - hlog
);
2854 /* Read in the armap. */
2857 _bfd_ecoff_slurp_armap (abfd
)
2862 struct areltdata
*mapdata
;
2863 bfd_size_type parsed_size
;
2865 struct artdata
*ardata
;
2868 struct symdef
*symdef_ptr
;
2871 /* Get the name of the first element. */
2872 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2878 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2881 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2882 standard COFF armap. We could move the ECOFF armap stuff into
2883 bfd_slurp_armap, but that seems inappropriate since no other
2884 target uses this format. Instead, we check directly for a COFF
2886 if (strncmp (nextname
, "/ ", 16) == 0)
2887 return bfd_slurp_armap (abfd
);
2889 /* See if the first element is an armap. */
2890 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2891 ARMAP_START_LENGTH
) != 0
2892 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2893 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2894 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2895 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2896 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2897 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2898 || strncmp (nextname
+ ARMAP_END_INDEX
,
2899 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2901 bfd_has_map (abfd
) = false;
2905 /* Make sure we have the right byte ordering. */
2906 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2907 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2908 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2909 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2911 bfd_set_error (bfd_error_wrong_format
);
2915 /* Read in the armap. */
2916 ardata
= bfd_ardata (abfd
);
2917 mapdata
= _bfd_snarf_ar_hdr (abfd
);
2918 if (mapdata
== (struct areltdata
*) NULL
)
2920 parsed_size
= mapdata
->parsed_size
;
2921 bfd_release (abfd
, (PTR
) mapdata
);
2923 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2924 if (raw_armap
== (char *) NULL
)
2926 bfd_set_error (bfd_error_no_memory
);
2930 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
2932 if (bfd_get_error () != bfd_error_system_call
)
2933 bfd_set_error (bfd_error_malformed_archive
);
2934 bfd_release (abfd
, (PTR
) raw_armap
);
2938 ardata
->tdata
= (PTR
) raw_armap
;
2940 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
2942 ardata
->symdef_count
= 0;
2943 ardata
->cache
= (struct ar_cache
*) NULL
;
2945 /* This code used to overlay the symdefs over the raw archive data,
2946 but that doesn't work on a 64 bit host. */
2948 stringbase
= raw_armap
+ count
* 8 + 8;
2950 #ifdef CHECK_ARMAP_HASH
2954 /* Double check that I have the hashing algorithm right by making
2955 sure that every symbol can be looked up successfully. */
2957 for (i
= 1; i
< count
; i
<<= 1)
2959 BFD_ASSERT (i
== count
);
2961 raw_ptr
= raw_armap
+ 4;
2962 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2964 unsigned int name_offset
, file_offset
;
2965 unsigned int hash
, rehash
, srch
;
2967 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
2968 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
2969 if (file_offset
== 0)
2971 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
2976 /* See if we can rehash to this location. */
2977 for (srch
= (hash
+ rehash
) & (count
- 1);
2978 srch
!= hash
&& srch
!= i
;
2979 srch
= (srch
+ rehash
) & (count
- 1))
2980 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
2982 BFD_ASSERT (srch
== i
);
2986 #endif /* CHECK_ARMAP_HASH */
2988 raw_ptr
= raw_armap
+ 4;
2989 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2990 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
2991 ++ardata
->symdef_count
;
2993 symdef_ptr
= ((struct symdef
*)
2995 ardata
->symdef_count
* sizeof (struct symdef
)));
2998 bfd_set_error (bfd_error_no_memory
);
3002 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3004 raw_ptr
= raw_armap
+ 4;
3005 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3007 unsigned int name_offset
, file_offset
;
3009 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3010 if (file_offset
== 0)
3012 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3013 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3014 symdef_ptr
->file_offset
= file_offset
;
3018 ardata
->first_file_filepos
= bfd_tell (abfd
);
3019 /* Pad to an even boundary. */
3020 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3022 bfd_has_map (abfd
) = true;
3027 /* Write out an armap. */
3030 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3032 unsigned int elength
;
3034 unsigned int orl_count
;
3037 unsigned int hashsize
, hashlog
;
3038 unsigned int symdefsize
;
3040 unsigned int stringsize
;
3041 unsigned int mapsize
;
3044 struct stat statbuf
;
3047 bfd_byte
*hashtable
;
3051 /* Ultrix appears to use as a hash table size the least power of two
3052 greater than twice the number of entries. */
3053 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3055 hashsize
= 1 << hashlog
;
3057 symdefsize
= hashsize
* 8;
3059 stringsize
= stridx
+ padit
;
3061 /* Include 8 bytes to store symdefsize and stringsize in output. */
3062 mapsize
= symdefsize
+ stringsize
+ 8;
3064 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3066 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3068 /* Work out the ECOFF armap name. */
3069 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3070 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3071 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3072 (abfd
->xvec
->header_byteorder_big_p
3074 : ARMAP_LITTLE_ENDIAN
);
3075 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3076 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3077 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3078 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3080 /* Write the timestamp of the archive header to be just a little bit
3081 later than the timestamp of the file, otherwise the linker will
3082 complain that the index is out of date. Actually, the Ultrix
3083 linker just checks the archive name; the GNU linker may check the
3085 stat (abfd
->filename
, &statbuf
);
3086 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3088 /* The DECstation uses zeroes for the uid, gid and mode of the
3090 hdr
.ar_uid
[0] = '0';
3091 hdr
.ar_gid
[0] = '0';
3092 hdr
.ar_mode
[0] = '0';
3094 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3096 hdr
.ar_fmag
[0] = '`';
3097 hdr
.ar_fmag
[1] = '\012';
3099 /* Turn all null bytes in the header into spaces. */
3100 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3101 if (((char *)(&hdr
))[i
] == '\0')
3102 (((char *)(&hdr
))[i
]) = ' ';
3104 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3105 != sizeof (struct ar_hdr
))
3108 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3109 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3112 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3115 bfd_set_error (bfd_error_no_memory
);
3119 current
= abfd
->archive_head
;
3121 for (i
= 0; i
< orl_count
; i
++)
3123 unsigned int hash
, rehash
;
3125 /* Advance firstreal to the file position of this archive
3127 if (((bfd
*) map
[i
].pos
) != last_elt
)
3131 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3132 firstreal
+= firstreal
% 2;
3133 current
= current
->next
;
3135 while (current
!= (bfd
*) map
[i
].pos
);
3140 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3141 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3145 /* The desired slot is already taken. */
3146 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3148 srch
= (srch
+ rehash
) & (hashsize
- 1))
3149 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3152 BFD_ASSERT (srch
!= hash
);
3157 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3158 (PTR
) (hashtable
+ hash
* 8));
3159 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3160 (PTR
) (hashtable
+ hash
* 8 + 4));
3163 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3166 bfd_release (abfd
, hashtable
);
3168 /* Now write the strings. */
3169 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3170 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3172 for (i
= 0; i
< orl_count
; i
++)
3176 len
= strlen (*map
[i
].name
) + 1;
3177 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3181 /* The spec sez this should be a newline. But in order to be
3182 bug-compatible for DECstation ar we use a null. */
3185 if (bfd_write ("", 1, 1, abfd
) != 1)
3192 /* See whether this BFD is an archive. If it is, read in the armap
3193 and the extended name table. */
3196 _bfd_ecoff_archive_p (abfd
)
3199 char armag
[SARMAG
+ 1];
3201 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3202 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3204 if (bfd_get_error () != bfd_error_system_call
)
3205 bfd_set_error (bfd_error_wrong_format
);
3206 return (const bfd_target
*) NULL
;
3209 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3210 involves a cast, we can't do it as the left operand of
3212 abfd
->tdata
.aout_ar_data
=
3213 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3215 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3217 bfd_set_error (bfd_error_no_memory
);
3218 return (const bfd_target
*) NULL
;
3221 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3222 bfd_ardata (abfd
)->cache
= NULL
;
3223 bfd_ardata (abfd
)->archive_head
= NULL
;
3224 bfd_ardata (abfd
)->symdefs
= NULL
;
3225 bfd_ardata (abfd
)->extended_names
= NULL
;
3226 bfd_ardata (abfd
)->tdata
= NULL
;
3228 if (_bfd_ecoff_slurp_armap (abfd
) == false
3229 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3231 bfd_release (abfd
, bfd_ardata (abfd
));
3232 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3233 return (const bfd_target
*) NULL
;
3239 /* ECOFF linker code. */
3241 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3242 PARAMS ((struct bfd_hash_entry
*entry
,
3243 struct bfd_hash_table
*table
,
3244 const char *string
));
3245 static boolean ecoff_link_add_archive_symbols
3246 PARAMS ((bfd
*, struct bfd_link_info
*));
3247 static boolean ecoff_link_check_archive_element
3248 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3249 static boolean ecoff_link_add_object_symbols
3250 PARAMS ((bfd
*, struct bfd_link_info
*));
3251 static boolean ecoff_link_add_externals
3252 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3254 /* Routine to create an entry in an ECOFF link hash table. */
3256 static struct bfd_hash_entry
*
3257 ecoff_link_hash_newfunc (entry
, table
, string
)
3258 struct bfd_hash_entry
*entry
;
3259 struct bfd_hash_table
*table
;
3262 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3264 /* Allocate the structure if it has not already been allocated by a
3266 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3267 ret
= ((struct ecoff_link_hash_entry
*)
3268 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3269 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3271 bfd_set_error (bfd_error_no_memory
);
3275 /* Call the allocation method of the superclass. */
3276 ret
= ((struct ecoff_link_hash_entry
*)
3277 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3282 /* Set local fields. */
3288 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3290 return (struct bfd_hash_entry
*) ret
;
3293 /* Create an ECOFF link hash table. */
3295 struct bfd_link_hash_table
*
3296 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3299 struct ecoff_link_hash_table
*ret
;
3301 ret
= ((struct ecoff_link_hash_table
*)
3302 malloc (sizeof (struct ecoff_link_hash_table
)));
3305 bfd_set_error (bfd_error_no_memory
);
3308 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3309 ecoff_link_hash_newfunc
))
3312 return (struct bfd_link_hash_table
*) NULL
;
3317 /* Look up an entry in an ECOFF link hash table. */
3319 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3320 ((struct ecoff_link_hash_entry *) \
3321 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3323 /* Traverse an ECOFF link hash table. */
3325 #define ecoff_link_hash_traverse(table, func, info) \
3326 (bfd_link_hash_traverse \
3328 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3331 /* Get the ECOFF link hash table from the info structure. This is
3334 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3336 /* Given an ECOFF BFD, add symbols to the global hash table as
3340 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3342 struct bfd_link_info
*info
;
3344 switch (bfd_get_format (abfd
))
3347 return ecoff_link_add_object_symbols (abfd
, info
);
3349 return ecoff_link_add_archive_symbols (abfd
, info
);
3351 bfd_set_error (bfd_error_wrong_format
);
3356 /* Add the symbols from an archive file to the global hash table.
3357 This looks through the undefined symbols, looks each one up in the
3358 archive hash table, and adds any associated object file. We do not
3359 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3360 already have a hash table, so there is no reason to construct
3364 ecoff_link_add_archive_symbols (abfd
, info
)
3366 struct bfd_link_info
*info
;
3368 const bfd_byte
*raw_armap
;
3369 struct bfd_link_hash_entry
**pundef
;
3370 unsigned int armap_count
;
3371 unsigned int armap_log
;
3373 const bfd_byte
*hashtable
;
3374 const char *stringbase
;
3376 if (! bfd_has_map (abfd
))
3378 /* An empty archive is a special case. */
3379 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3381 bfd_set_error (bfd_error_no_armap
);
3385 /* If we don't have any raw data for this archive, as can happen on
3386 Irix 4.0.5F, we call the generic routine.
3387 FIXME: We should be more clever about this, since someday tdata
3388 may get to something for a generic archive. */
3389 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3390 if (raw_armap
== (bfd_byte
*) NULL
)
3391 return (_bfd_generic_link_add_archive_symbols
3392 (abfd
, info
, ecoff_link_check_archive_element
));
3394 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3397 for (i
= 1; i
< armap_count
; i
<<= 1)
3399 BFD_ASSERT (i
== armap_count
);
3401 hashtable
= raw_armap
+ 4;
3402 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3404 /* Look through the list of undefined symbols. */
3405 pundef
= &info
->hash
->undefs
;
3406 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3408 struct bfd_link_hash_entry
*h
;
3409 unsigned int hash
, rehash
;
3410 unsigned int file_offset
;
3416 /* When a symbol is defined, it is not necessarily removed from
3418 if (h
->type
!= bfd_link_hash_undefined
3419 && h
->type
!= bfd_link_hash_common
)
3421 /* Remove this entry from the list, for general cleanliness
3422 and because we are going to look through the list again
3423 if we search any more libraries. We can't remove the
3424 entry if it is the tail, because that would lose any
3425 entries we add to the list later on. */
3426 if (*pundef
!= info
->hash
->undefs_tail
)
3427 *pundef
= (*pundef
)->next
;
3429 pundef
= &(*pundef
)->next
;
3433 /* Native ECOFF linkers do not pull in archive elements merely
3434 to satisfy common definitions, so neither do we. We leave
3435 them on the list, though, in case we are linking against some
3436 other object format. */
3437 if (h
->type
!= bfd_link_hash_undefined
)
3439 pundef
= &(*pundef
)->next
;
3443 /* Look for this symbol in the archive hash table. */
3444 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3447 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3448 if (file_offset
== 0)
3450 /* Nothing in this slot. */
3451 pundef
= &(*pundef
)->next
;
3455 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3456 if (name
[0] != h
->root
.string
[0]
3457 || strcmp (name
, h
->root
.string
) != 0)
3462 /* That was the wrong symbol. Try rehashing. */
3464 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3466 srch
= (srch
+ rehash
) & (armap_count
- 1))
3468 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3469 if (file_offset
== 0)
3471 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3472 if (name
[0] == h
->root
.string
[0]
3473 && strcmp (name
, h
->root
.string
) == 0)
3482 pundef
= &(*pundef
)->next
;
3489 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3490 if (element
== (bfd
*) NULL
)
3493 if (! bfd_check_format (element
, bfd_object
))
3496 /* Unlike the generic linker, we know that this element provides
3497 a definition for an undefined symbol and we know that we want
3498 to include it. We don't need to check anything. */
3499 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3501 if (! ecoff_link_add_object_symbols (element
, info
))
3504 pundef
= &(*pundef
)->next
;
3510 /* This is called if we used _bfd_generic_link_add_archive_symbols
3511 because we were not dealing with an ECOFF archive. */
3514 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3516 struct bfd_link_info
*info
;
3519 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3520 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3521 = backend
->debug_swap
.swap_ext_in
;
3523 bfd_size_type external_ext_size
;
3524 PTR external_ext
= NULL
;
3532 if (! ecoff_slurp_symbolic_header (abfd
))
3535 /* If there are no symbols, we don't want it. */
3536 if (bfd_get_symcount (abfd
) == 0)
3537 goto successful_return
;
3539 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3541 /* Read in the external symbols and external strings. */
3542 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3543 esize
= symhdr
->iextMax
* external_ext_size
;
3544 external_ext
= (PTR
) malloc (esize
);
3545 if (external_ext
== NULL
&& esize
!= 0)
3547 bfd_set_error (bfd_error_no_memory
);
3551 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3552 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3555 ssext
= (char *) malloc (symhdr
->issExtMax
);
3556 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3558 bfd_set_error (bfd_error_no_memory
);
3562 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3563 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3566 /* Look through the external symbols to see if they define some
3567 symbol that is currently undefined. */
3568 ext_ptr
= (char *) external_ext
;
3569 ext_end
= ext_ptr
+ esize
;
3570 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3575 struct bfd_link_hash_entry
*h
;
3577 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3579 /* See if this symbol defines something. */
3580 if (esym
.asym
.st
!= stGlobal
3581 && esym
.asym
.st
!= stLabel
3582 && esym
.asym
.st
!= stProc
)
3585 switch (esym
.asym
.sc
)
3608 name
= ssext
+ esym
.asym
.iss
;
3609 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3611 /* Unlike the generic linker, we do not pull in elements because
3612 of common symbols. */
3613 if (h
== (struct bfd_link_hash_entry
*) NULL
3614 || h
->type
!= bfd_link_hash_undefined
)
3617 /* Include this element. */
3618 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3620 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3624 goto successful_return
;
3628 if (external_ext
!= NULL
)
3629 free (external_ext
);
3634 if (external_ext
!= NULL
)
3635 free (external_ext
);
3641 /* Add symbols from an ECOFF object file to the global linker hash
3645 ecoff_link_add_object_symbols (abfd
, info
)
3647 struct bfd_link_info
*info
;
3650 bfd_size_type external_ext_size
;
3651 PTR external_ext
= NULL
;
3656 if (! ecoff_slurp_symbolic_header (abfd
))
3659 /* If there are no symbols, we don't want it. */
3660 if (bfd_get_symcount (abfd
) == 0)
3663 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3665 /* Read in the external symbols and external strings. */
3666 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3667 esize
= symhdr
->iextMax
* external_ext_size
;
3668 external_ext
= (PTR
) malloc (esize
);
3669 if (external_ext
== NULL
&& esize
!= 0)
3671 bfd_set_error (bfd_error_no_memory
);
3675 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3676 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3679 ssext
= (char *) malloc (symhdr
->issExtMax
);
3680 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3682 bfd_set_error (bfd_error_no_memory
);
3686 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3687 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3690 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3694 if (external_ext
!= NULL
)
3695 free (external_ext
);
3701 if (external_ext
!= NULL
)
3702 free (external_ext
);
3706 /* Add the external symbols of an object file to the global linker
3707 hash table. The external symbols and strings we are passed are
3708 just allocated on the stack, and will be discarded. We must
3709 explicitly save any information we may need later on in the link.
3710 We do not want to read the external symbol information again. */
3713 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3715 struct bfd_link_info
*info
;
3719 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3720 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3721 = backend
->debug_swap
.swap_ext_in
;
3722 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3723 unsigned long ext_count
;
3724 struct ecoff_link_hash_entry
**sym_hash
;
3728 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3730 sym_hash
= ((struct ecoff_link_hash_entry
**)
3732 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3735 bfd_set_error (bfd_error_no_memory
);
3738 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3740 ext_ptr
= (char *) external_ext
;
3741 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3742 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3749 struct ecoff_link_hash_entry
*h
;
3753 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3755 /* Skip debugging symbols. */
3757 switch (esym
.asym
.st
)
3773 /* Get the information for this symbol. */
3774 value
= esym
.asym
.value
;
3775 switch (esym
.asym
.sc
)
3795 section
= bfd_make_section_old_way (abfd
, ".text");
3796 value
-= section
->vma
;
3799 section
= bfd_make_section_old_way (abfd
, ".data");
3800 value
-= section
->vma
;
3803 section
= bfd_make_section_old_way (abfd
, ".bss");
3804 value
-= section
->vma
;
3807 section
= bfd_abs_section_ptr
;
3810 section
= bfd_und_section_ptr
;
3813 section
= bfd_make_section_old_way (abfd
, ".sdata");
3814 value
-= section
->vma
;
3817 section
= bfd_make_section_old_way (abfd
, ".sbss");
3818 value
-= section
->vma
;
3821 section
= bfd_make_section_old_way (abfd
, ".rdata");
3822 value
-= section
->vma
;
3825 if (value
> ecoff_data (abfd
)->gp_size
)
3827 section
= bfd_com_section_ptr
;
3832 if (ecoff_scom_section
.name
== NULL
)
3834 /* Initialize the small common section. */
3835 ecoff_scom_section
.name
= SCOMMON
;
3836 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3837 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3838 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3839 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3840 ecoff_scom_symbol
.name
= SCOMMON
;
3841 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3842 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3843 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3845 section
= &ecoff_scom_section
;
3848 section
= bfd_und_section_ptr
;
3851 section
= bfd_make_section_old_way (abfd
, ".init");
3852 value
-= section
->vma
;
3855 section
= bfd_make_section_old_way (abfd
, ".fini");
3856 value
-= section
->vma
;
3860 if (section
== (asection
*) NULL
)
3863 name
= ssext
+ esym
.asym
.iss
;
3866 if (! (_bfd_generic_link_add_one_symbol
3867 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3868 (const char *) NULL
, true, true,
3869 (struct bfd_link_hash_entry
**) &h
)))
3874 /* If we are building an ECOFF hash table, save the external
3875 symbol information. */
3876 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3878 if (h
->abfd
== (bfd
*) NULL
3879 || (! bfd_is_und_section (section
)
3880 && (! bfd_is_com_section (section
)
3881 || (h
->root
.type
!= bfd_link_hash_defined
3882 && h
->root
.type
!= bfd_link_hash_defweak
))))
3888 /* Remember whether this symbol was small undefined. */
3889 if (esym
.asym
.sc
== scSUndefined
)
3892 /* If this symbol was ever small undefined, it needs to wind
3893 up in a GP relative section. We can't control the
3894 section of a defined symbol, but we can control the
3895 section of a common symbol. This case is actually needed
3896 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
3898 && h
->root
.type
== bfd_link_hash_common
3899 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
3901 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
3903 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
3904 if (h
->esym
.asym
.sc
== scCommon
)
3905 h
->esym
.asym
.sc
= scSCommon
;
3913 /* ECOFF final link routines. */
3915 static boolean ecoff_final_link_debug_accumulate
3916 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
3918 static boolean ecoff_link_write_external
3919 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3920 static boolean ecoff_indirect_link_order
3921 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3922 struct bfd_link_order
*));
3923 static boolean ecoff_reloc_link_order
3924 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3925 struct bfd_link_order
*));
3927 /* ECOFF final link routine. This looks through all the input BFDs
3928 and gathers together all the debugging information, and then
3929 processes all the link order information. This may cause it to
3930 close and reopen some input BFDs; I'll see how bad this is. */
3933 _bfd_ecoff_bfd_final_link (abfd
, info
)
3935 struct bfd_link_info
*info
;
3937 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3938 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3941 register bfd
*input_bfd
;
3943 struct bfd_link_order
*p
;
3945 /* We accumulate the debugging information counts in the symbolic
3947 symhdr
= &debug
->symbolic_header
;
3949 symhdr
->ilineMax
= 0;
3953 symhdr
->isymMax
= 0;
3954 symhdr
->ioptMax
= 0;
3955 symhdr
->iauxMax
= 0;
3957 symhdr
->issExtMax
= 0;
3960 symhdr
->iextMax
= 0;
3962 /* We accumulate the debugging information itself in the debug_info
3965 debug
->external_dnr
= NULL
;
3966 debug
->external_pdr
= NULL
;
3967 debug
->external_sym
= NULL
;
3968 debug
->external_opt
= NULL
;
3969 debug
->external_aux
= NULL
;
3971 debug
->ssext
= debug
->ssext_end
= NULL
;
3972 debug
->external_fdr
= NULL
;
3973 debug
->external_rfd
= NULL
;
3974 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3976 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
3977 if (handle
== (PTR
) NULL
)
3980 /* Accumulate the debugging symbols from each input BFD. */
3981 for (input_bfd
= info
->input_bfds
;
3982 input_bfd
!= (bfd
*) NULL
;
3983 input_bfd
= input_bfd
->link_next
)
3987 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
3989 /* Abitrarily set the symbolic header vstamp to the vstamp
3990 of the first object file in the link. */
3991 if (symhdr
->vstamp
== 0)
3993 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
3994 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
3998 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
3999 debug
, &backend
->debug_swap
,
4004 /* Combine the register masks. */
4005 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4006 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4007 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4008 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4009 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4010 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4013 /* Write out the external symbols. */
4014 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4015 ecoff_link_write_external
,
4018 if (info
->relocateable
)
4020 /* We need to make a pass over the link_orders to count up the
4021 number of relocations we will need to output, so that we know
4022 how much space they will take up. */
4023 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4026 for (p
= o
->link_order_head
;
4027 p
!= (struct bfd_link_order
*) NULL
;
4029 if (p
->type
== bfd_indirect_link_order
)
4030 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4031 else if (p
->type
== bfd_section_reloc_link_order
4032 || p
->type
== bfd_symbol_reloc_link_order
)
4037 /* Compute the reloc and symbol file positions. */
4038 ecoff_compute_reloc_file_positions (abfd
);
4040 /* Write out the debugging information. */
4041 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4042 &backend
->debug_swap
, info
,
4043 ecoff_data (abfd
)->sym_filepos
))
4046 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4048 if (info
->relocateable
)
4050 /* Now reset the reloc_count field of the sections in the output
4051 BFD to 0, so that we can use them to keep track of how many
4052 relocs we have output thus far. */
4053 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4057 /* Get a value for the GP register. */
4058 if (ecoff_data (abfd
)->gp
== 0)
4060 struct bfd_link_hash_entry
*h
;
4062 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4063 if (h
!= (struct bfd_link_hash_entry
*) NULL
4064 && h
->type
== bfd_link_hash_defined
)
4065 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4066 + h
->u
.def
.section
->output_section
->vma
4067 + h
->u
.def
.section
->output_offset
);
4068 else if (info
->relocateable
)
4072 /* Make up a value. */
4074 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4077 && (strcmp (o
->name
, _SBSS
) == 0
4078 || strcmp (o
->name
, _SDATA
) == 0
4079 || strcmp (o
->name
, _LIT4
) == 0
4080 || strcmp (o
->name
, _LIT8
) == 0
4081 || strcmp (o
->name
, _LITA
) == 0))
4084 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4088 /* If the relocate_section function needs to do a reloc
4089 involving the GP value, it should make a reloc_dangerous
4090 callback to warn that GP is not defined. */
4094 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4096 for (p
= o
->link_order_head
;
4097 p
!= (struct bfd_link_order
*) NULL
;
4100 if (p
->type
== bfd_indirect_link_order
4101 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4102 == bfd_target_ecoff_flavour
))
4104 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4107 else if (p
->type
== bfd_section_reloc_link_order
4108 || p
->type
== bfd_symbol_reloc_link_order
)
4110 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4115 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4121 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4123 ecoff_data (abfd
)->linker
= true;
4128 /* Accumulate the debugging information for an input BFD into the
4129 output BFD. This must read in the symbolic information of the
4133 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4136 struct bfd_link_info
*info
;
4139 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4140 const struct ecoff_debug_swap
* const swap
=
4141 &ecoff_backend (input_bfd
)->debug_swap
;
4142 HDRR
*symhdr
= &debug
->symbolic_header
;
4145 #define READ(ptr, offset, count, size, type) \
4146 if (symhdr->count == 0) \
4147 debug->ptr = NULL; \
4150 debug->ptr = (type) malloc (size * symhdr->count); \
4151 if (debug->ptr == NULL) \
4153 bfd_set_error (bfd_error_no_memory); \
4155 goto return_something; \
4157 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4159 || (bfd_read (debug->ptr, size, symhdr->count, \
4160 input_bfd) != size * symhdr->count)) \
4163 goto return_something; \
4167 /* If raw_syments is not NULL, then the data was already by read by
4168 _bfd_ecoff_slurp_symbolic_info. */
4169 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4171 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4173 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4174 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4175 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4176 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4177 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4179 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4180 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4181 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4185 /* We do not read the external strings or the external symbols. */
4187 ret
= (bfd_ecoff_debug_accumulate
4188 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4189 &ecoff_backend (output_bfd
)->debug_swap
,
4190 input_bfd
, debug
, swap
, info
));
4193 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4195 if (debug
->line
!= NULL
)
4197 if (debug
->external_dnr
!= NULL
)
4198 free (debug
->external_dnr
);
4199 if (debug
->external_pdr
!= NULL
)
4200 free (debug
->external_pdr
);
4201 if (debug
->external_sym
!= NULL
)
4202 free (debug
->external_sym
);
4203 if (debug
->external_opt
!= NULL
)
4204 free (debug
->external_opt
);
4205 if (debug
->external_aux
!= NULL
)
4206 free (debug
->external_aux
);
4207 if (debug
->ss
!= NULL
)
4209 if (debug
->external_fdr
!= NULL
)
4210 free (debug
->external_fdr
);
4211 if (debug
->external_rfd
!= NULL
)
4212 free (debug
->external_rfd
);
4214 /* Make sure we don't accidentally follow one of these pointers
4215 into freed memory. */
4217 debug
->external_dnr
= NULL
;
4218 debug
->external_pdr
= NULL
;
4219 debug
->external_sym
= NULL
;
4220 debug
->external_opt
= NULL
;
4221 debug
->external_aux
= NULL
;
4223 debug
->external_fdr
= NULL
;
4224 debug
->external_rfd
= NULL
;
4230 /* Put out information for an external symbol. These come only from
4234 ecoff_link_write_external (h
, data
)
4235 struct ecoff_link_hash_entry
*h
;
4238 bfd
*output_bfd
= (bfd
*) data
;
4240 /* FIXME: We should check if this symbol is being stripped. */
4245 if (h
->abfd
== (bfd
*) NULL
)
4248 h
->esym
.cobol_main
= 0;
4249 h
->esym
.weakext
= 0;
4250 h
->esym
.reserved
= 0;
4251 h
->esym
.ifd
= ifdNil
;
4252 h
->esym
.asym
.value
= 0;
4253 h
->esym
.asym
.st
= stGlobal
;
4255 if (h
->root
.type
!= bfd_link_hash_defined
4256 && h
->root
.type
!= bfd_link_hash_defweak
)
4257 h
->esym
.asym
.sc
= scAbs
;
4260 asection
*output_section
;
4263 output_section
= h
->root
.u
.def
.section
->output_section
;
4264 name
= bfd_section_name (output_section
->owner
, output_section
);
4266 if (strcmp (name
, _TEXT
) == 0)
4267 h
->esym
.asym
.sc
= scText
;
4268 else if (strcmp (name
, _DATA
) == 0)
4269 h
->esym
.asym
.sc
= scData
;
4270 else if (strcmp (name
, _SDATA
) == 0)
4271 h
->esym
.asym
.sc
= scSData
;
4272 else if (strcmp (name
, _RDATA
) == 0)
4273 h
->esym
.asym
.sc
= scRData
;
4274 else if (strcmp (name
, _BSS
) == 0)
4275 h
->esym
.asym
.sc
= scBss
;
4276 else if (strcmp (name
, _SBSS
) == 0)
4277 h
->esym
.asym
.sc
= scSBss
;
4278 else if (strcmp (name
, _INIT
) == 0)
4279 h
->esym
.asym
.sc
= scInit
;
4280 else if (strcmp (name
, _FINI
) == 0)
4281 h
->esym
.asym
.sc
= scFini
;
4282 else if (strcmp (name
, _PDATA
) == 0)
4283 h
->esym
.asym
.sc
= scPData
;
4284 else if (strcmp (name
, _XDATA
) == 0)
4285 h
->esym
.asym
.sc
= scXData
;
4287 h
->esym
.asym
.sc
= scAbs
;
4290 h
->esym
.asym
.reserved
= 0;
4291 h
->esym
.asym
.index
= indexNil
;
4293 else if (h
->esym
.ifd
!= -1)
4295 struct ecoff_debug_info
*debug
;
4297 /* Adjust the FDR index for the symbol by that used for the
4299 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4300 BFD_ASSERT (h
->esym
.ifd
>= 0
4301 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4302 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4305 switch (h
->root
.type
)
4308 case bfd_link_hash_new
:
4310 case bfd_link_hash_undefined
:
4311 case bfd_link_hash_undefweak
:
4312 if (h
->esym
.asym
.sc
!= scUndefined
4313 && h
->esym
.asym
.sc
!= scSUndefined
)
4314 h
->esym
.asym
.sc
= scUndefined
;
4316 case bfd_link_hash_defined
:
4317 case bfd_link_hash_defweak
:
4318 if (h
->esym
.asym
.sc
== scUndefined
4319 || h
->esym
.asym
.sc
== scSUndefined
)
4320 h
->esym
.asym
.sc
= scAbs
;
4321 else if (h
->esym
.asym
.sc
== scCommon
)
4322 h
->esym
.asym
.sc
= scBss
;
4323 else if (h
->esym
.asym
.sc
== scSCommon
)
4324 h
->esym
.asym
.sc
= scSBss
;
4325 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4326 + h
->root
.u
.def
.section
->output_section
->vma
4327 + h
->root
.u
.def
.section
->output_offset
);
4329 case bfd_link_hash_common
:
4330 if (h
->esym
.asym
.sc
!= scCommon
4331 && h
->esym
.asym
.sc
!= scSCommon
)
4332 h
->esym
.asym
.sc
= scCommon
;
4333 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4335 case bfd_link_hash_indirect
:
4336 case bfd_link_hash_warning
:
4337 /* FIXME: Ignore these for now. The circumstances under which
4338 they should be written out are not clear to me. */
4342 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4344 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4347 return (bfd_ecoff_debug_one_external
4348 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4349 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4353 /* Relocate and write an ECOFF section into an ECOFF output file. */
4356 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4358 struct bfd_link_info
*info
;
4359 asection
*output_section
;
4360 struct bfd_link_order
*link_order
;
4362 asection
*input_section
;
4364 struct ecoff_section_tdata
*section_tdata
;
4365 bfd_size_type raw_size
;
4366 bfd_size_type cooked_size
;
4367 bfd_byte
*contents
= NULL
;
4368 bfd_size_type external_reloc_size
;
4369 bfd_size_type external_relocs_size
;
4370 PTR external_relocs
= NULL
;
4372 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4374 if (link_order
->size
== 0)
4377 input_section
= link_order
->u
.indirect
.section
;
4378 input_bfd
= input_section
->owner
;
4379 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4381 raw_size
= input_section
->_raw_size
;
4382 cooked_size
= input_section
->_cooked_size
;
4383 if (cooked_size
== 0)
4384 cooked_size
= raw_size
;
4386 BFD_ASSERT (input_section
->output_section
== output_section
);
4387 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4388 BFD_ASSERT (cooked_size
== link_order
->size
);
4390 /* Get the section contents. We allocate memory for the larger of
4391 the size before relocating and the size after relocating. */
4392 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4395 if (contents
== NULL
&& raw_size
!= 0)
4397 bfd_set_error (bfd_error_no_memory
);
4401 /* If we are relaxing, the contents may have already been read into
4402 memory, in which case we copy them into our new buffer. We don't
4403 simply reuse the old buffer in case cooked_size > raw_size. */
4404 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4405 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4406 memcpy (contents
, section_tdata
->contents
, raw_size
);
4409 if (! bfd_get_section_contents (input_bfd
, input_section
,
4411 (file_ptr
) 0, raw_size
))
4415 /* Get the relocs. If we are relaxing MIPS code, they will already
4416 have been read in. Otherwise, we read them in now. */
4417 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4418 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4420 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4421 external_relocs
= section_tdata
->external_relocs
;
4424 external_relocs
= (PTR
) malloc (external_relocs_size
);
4425 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4427 bfd_set_error (bfd_error_no_memory
);
4431 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4432 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4433 != external_relocs_size
))
4437 /* Relocate the section contents. */
4438 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4439 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4443 /* Write out the relocated section. */
4444 if (! bfd_set_section_contents (output_bfd
,
4447 input_section
->output_offset
,
4451 /* If we are producing relocateable output, the relocs were
4452 modified, and we write them out now. We use the reloc_count
4453 field of output_section to keep track of the number of relocs we
4454 have output so far. */
4455 if (info
->relocateable
)
4457 if (bfd_seek (output_bfd
,
4458 (output_section
->rel_filepos
+
4459 output_section
->reloc_count
* external_reloc_size
),
4461 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4462 != external_relocs_size
))
4464 output_section
->reloc_count
+= input_section
->reloc_count
;
4467 if (contents
!= NULL
)
4469 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4470 free (external_relocs
);
4474 if (contents
!= NULL
)
4476 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4477 free (external_relocs
);
4481 /* Generate a reloc when linking an ECOFF file. This is a reloc
4482 requested by the linker, and does come from any input file. This
4483 is used to build constructor and destructor tables when linking
4487 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4489 struct bfd_link_info
*info
;
4490 asection
*output_section
;
4491 struct bfd_link_order
*link_order
;
4494 struct internal_reloc in
;
4495 bfd_size_type external_reloc_size
;
4499 /* We set up an arelent to pass to the backend adjust_reloc_out
4501 rel
.address
= link_order
->offset
;
4503 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4506 bfd_set_error (bfd_error_bad_value
);
4510 if (link_order
->type
== bfd_section_reloc_link_order
)
4511 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4514 /* We can't set up a reloc against a symbol correctly, because
4515 we have no asymbol structure. Currently no adjust_reloc_out
4517 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4520 /* All ECOFF relocs are in-place. Put the addend into the object
4523 BFD_ASSERT (rel
.howto
->partial_inplace
);
4524 if (link_order
->u
.reloc
.p
->addend
!= 0)
4527 bfd_reloc_status_type rstat
;
4531 size
= bfd_get_reloc_size (rel
.howto
);
4532 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4533 if (buf
== (bfd_byte
*) NULL
)
4535 bfd_set_error (bfd_error_no_memory
);
4538 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4539 link_order
->u
.reloc
.p
->addend
, buf
);
4545 case bfd_reloc_outofrange
:
4547 case bfd_reloc_overflow
:
4548 if (! ((*info
->callbacks
->reloc_overflow
)
4550 (link_order
->type
== bfd_section_reloc_link_order
4551 ? bfd_section_name (output_bfd
,
4552 link_order
->u
.reloc
.p
->u
.section
)
4553 : link_order
->u
.reloc
.p
->u
.name
),
4554 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4555 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4562 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4563 (file_ptr
) link_order
->offset
, size
);
4571 /* Move the information into a internal_reloc structure. */
4572 in
.r_vaddr
= (rel
.address
4573 + bfd_get_section_vma (output_bfd
, output_section
));
4574 in
.r_type
= rel
.howto
->type
;
4576 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4578 struct ecoff_link_hash_entry
*h
;
4580 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4581 link_order
->u
.reloc
.p
->u
.name
,
4582 false, false, true);
4583 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4585 in
.r_symndx
= h
->indx
;
4588 if (! ((*info
->callbacks
->unattached_reloc
)
4589 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4590 (asection
*) NULL
, (bfd_vma
) 0)))
4600 name
= bfd_get_section_name (output_bfd
,
4601 link_order
->u
.reloc
.p
->u
.section
);
4602 if (strcmp (name
, ".text") == 0)
4603 in
.r_symndx
= RELOC_SECTION_TEXT
;
4604 else if (strcmp (name
, ".rdata") == 0)
4605 in
.r_symndx
= RELOC_SECTION_RDATA
;
4606 else if (strcmp (name
, ".data") == 0)
4607 in
.r_symndx
= RELOC_SECTION_DATA
;
4608 else if (strcmp (name
, ".sdata") == 0)
4609 in
.r_symndx
= RELOC_SECTION_SDATA
;
4610 else if (strcmp (name
, ".sbss") == 0)
4611 in
.r_symndx
= RELOC_SECTION_SBSS
;
4612 else if (strcmp (name
, ".bss") == 0)
4613 in
.r_symndx
= RELOC_SECTION_BSS
;
4614 else if (strcmp (name
, ".init") == 0)
4615 in
.r_symndx
= RELOC_SECTION_INIT
;
4616 else if (strcmp (name
, ".lit8") == 0)
4617 in
.r_symndx
= RELOC_SECTION_LIT8
;
4618 else if (strcmp (name
, ".lit4") == 0)
4619 in
.r_symndx
= RELOC_SECTION_LIT4
;
4620 else if (strcmp (name
, ".xdata") == 0)
4621 in
.r_symndx
= RELOC_SECTION_XDATA
;
4622 else if (strcmp (name
, ".pdata") == 0)
4623 in
.r_symndx
= RELOC_SECTION_PDATA
;
4624 else if (strcmp (name
, ".fini") == 0)
4625 in
.r_symndx
= RELOC_SECTION_FINI
;
4626 else if (strcmp (name
, ".lita") == 0)
4627 in
.r_symndx
= RELOC_SECTION_LITA
;
4628 else if (strcmp (name
, "*ABS*") == 0)
4629 in
.r_symndx
= RELOC_SECTION_ABS
;
4635 /* Let the BFD backend adjust the reloc. */
4636 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4638 /* Get some memory and swap out the reloc. */
4639 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4640 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4641 if (rbuf
== (bfd_byte
*) NULL
)
4643 bfd_set_error (bfd_error_no_memory
);
4647 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4649 ok
= (bfd_seek (output_bfd
,
4650 (output_section
->rel_filepos
+
4651 output_section
->reloc_count
* external_reloc_size
),
4653 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4654 == external_reloc_size
));
4657 ++output_section
->reloc_count
;