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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
, int weak
));
54 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
56 RNDXR
*rndx
, long isym
,
58 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
60 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
62 static int ecoff_sort_hdrs
PARAMS ((const PTR
, const PTR
));
63 static boolean 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 /* Initialize a new section. */
142 _bfd_ecoff_new_section_hook (abfd
, section
)
146 /* For the .pdata section, which has a special meaning on the Alpha,
147 we set the alignment power to 3. We correct this later in
148 ecoff_compute_section_file_positions. We do this hackery because
149 we need to know the exact unaligned size of the .pdata section in
150 order to set the lnnoptr field correctly. For every other
151 section we use an alignment power of 4; this could be made target
152 dependent by adding a field to ecoff_backend_data, but 4 appears
153 to be correct for both the MIPS and the Alpha. */
154 if (strcmp (section
->name
, _PDATA
) == 0)
155 section
->alignment_power
= 3;
157 section
->alignment_power
= 4;
159 if (strcmp (section
->name
, _TEXT
) == 0)
160 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
161 else if (strcmp (section
->name
, _DATA
) == 0
162 || strcmp (section
->name
, _SDATA
) == 0)
163 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
164 else if (strcmp (section
->name
, _RDATA
) == 0
165 || strcmp (section
->name
, _LIT8
) == 0
166 || strcmp (section
->name
, _LIT4
) == 0
167 || strcmp (section
->name
, _RCONST
) == 0)
168 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
169 else if (strcmp (section
->name
, _BSS
) == 0
170 || strcmp (section
->name
, _SBSS
) == 0)
171 section
->flags
|= SEC_ALLOC
;
172 else if (strcmp (section
->name
, _LIB
) == 0)
174 /* An Irix 4 shared libary. */
175 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
178 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
179 uncertain about .init on some systems and I don't know how shared
185 /* Determine the machine architecture and type. This is called from
186 the generic COFF routines. It is the inverse of ecoff_get_magic,
187 below. This could be an ECOFF backend routine, with one version
188 for each target, but there aren't all that many ECOFF targets. */
191 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
195 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
196 enum bfd_architecture arch
;
199 switch (internal_f
->f_magic
)
202 case MIPS_MAGIC_LITTLE
:
204 arch
= bfd_arch_mips
;
208 case MIPS_MAGIC_LITTLE2
:
209 case MIPS_MAGIC_BIG2
:
210 /* MIPS ISA level 2: the r6000 */
211 arch
= bfd_arch_mips
;
215 case MIPS_MAGIC_LITTLE3
:
216 case MIPS_MAGIC_BIG3
:
217 /* MIPS ISA level 3: the r4000 */
218 arch
= bfd_arch_mips
;
223 arch
= bfd_arch_alpha
;
228 arch
= bfd_arch_obscure
;
233 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
236 /* Get the magic number to use based on the architecture and machine.
237 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
240 ecoff_get_magic (abfd
)
245 switch (bfd_get_arch (abfd
))
248 switch (bfd_get_mach (abfd
))
253 big
= MIPS_MAGIC_BIG
;
254 little
= MIPS_MAGIC_LITTLE
;
258 big
= MIPS_MAGIC_BIG2
;
259 little
= MIPS_MAGIC_LITTLE2
;
263 big
= MIPS_MAGIC_BIG3
;
264 little
= MIPS_MAGIC_LITTLE3
;
268 return abfd
->xvec
->byteorder_big_p
? big
: little
;
279 /* Get the section s_flags to use for a section. */
282 ecoff_sec_to_styp_flags (name
, flags
)
290 if (strcmp (name
, _TEXT
) == 0)
292 else if (strcmp (name
, _DATA
) == 0)
294 else if (strcmp (name
, _SDATA
) == 0)
296 else if (strcmp (name
, _RDATA
) == 0)
298 else if (strcmp (name
, _LITA
) == 0)
300 else if (strcmp (name
, _LIT8
) == 0)
302 else if (strcmp (name
, _LIT4
) == 0)
304 else if (strcmp (name
, _BSS
) == 0)
306 else if (strcmp (name
, _SBSS
) == 0)
308 else if (strcmp (name
, _INIT
) == 0)
309 styp
= STYP_ECOFF_INIT
;
310 else if (strcmp (name
, _FINI
) == 0)
311 styp
= STYP_ECOFF_FINI
;
312 else if (strcmp (name
, _PDATA
) == 0)
314 else if (strcmp (name
, _XDATA
) == 0)
316 else if (strcmp (name
, _LIB
) == 0)
317 styp
= STYP_ECOFF_LIB
;
318 else if (strcmp (name
, _GOT
) == 0)
320 else if (strcmp (name
, _HASH
) == 0)
322 else if (strcmp (name
, _DYNAMIC
) == 0)
324 else if (strcmp (name
, _LIBLIST
) == 0)
326 else if (strcmp (name
, _RELDYN
) == 0)
328 else if (strcmp (name
, _CONFLIC
) == 0)
330 else if (strcmp (name
, _DYNSTR
) == 0)
332 else if (strcmp (name
, _DYNSYM
) == 0)
334 else if (strcmp (name
, _COMMENT
) == 0)
337 flags
&=~ SEC_NEVER_LOAD
;
339 else if (strcmp (name
, _RCONST
) == 0)
341 else if (flags
& SEC_CODE
)
343 else if (flags
& SEC_DATA
)
345 else if (flags
& SEC_READONLY
)
347 else if (flags
& SEC_LOAD
)
352 if (flags
& SEC_NEVER_LOAD
)
358 /* Get the BFD flags to use for a section. */
362 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
)
367 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
368 long styp_flags
= internal_s
->s_flags
;
369 flagword sec_flags
=0;
371 if (styp_flags
& STYP_NOLOAD
)
372 sec_flags
|= SEC_NEVER_LOAD
;
374 /* For 386 COFF, at least, an unloadable text or data section is
375 actually a shared library section. */
376 if ((styp_flags
& STYP_TEXT
)
377 || (styp_flags
& STYP_ECOFF_INIT
)
378 || (styp_flags
& STYP_ECOFF_FINI
)
379 || (styp_flags
& STYP_DYNAMIC
)
380 || (styp_flags
& STYP_LIBLIST
)
381 || (styp_flags
& STYP_RELDYN
)
382 || styp_flags
== STYP_CONFLIC
383 || (styp_flags
& STYP_DYNSTR
)
384 || (styp_flags
& STYP_DYNSYM
)
385 || (styp_flags
& STYP_HASH
))
387 if (sec_flags
& SEC_NEVER_LOAD
)
388 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
390 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
392 else if ((styp_flags
& STYP_DATA
)
393 || (styp_flags
& STYP_RDATA
)
394 || (styp_flags
& STYP_SDATA
)
395 || styp_flags
== STYP_PDATA
396 || styp_flags
== STYP_XDATA
397 || (styp_flags
& STYP_GOT
)
398 || styp_flags
== STYP_RCONST
)
400 if (sec_flags
& SEC_NEVER_LOAD
)
401 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
403 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
404 if ((styp_flags
& STYP_RDATA
)
405 || styp_flags
== STYP_PDATA
406 || styp_flags
== STYP_RCONST
)
407 sec_flags
|= SEC_READONLY
;
409 else if ((styp_flags
& STYP_BSS
)
410 || (styp_flags
& STYP_SBSS
))
412 sec_flags
|= SEC_ALLOC
;
414 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
416 sec_flags
|= SEC_NEVER_LOAD
;
418 else if ((styp_flags
& STYP_LITA
)
419 || (styp_flags
& STYP_LIT8
)
420 || (styp_flags
& STYP_LIT4
))
422 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
424 else if (styp_flags
& STYP_ECOFF_LIB
)
426 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
430 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
436 /* Read in the symbolic header for an ECOFF object file. */
439 ecoff_slurp_symbolic_header (abfd
)
442 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
443 bfd_size_type external_hdr_size
;
445 HDRR
*internal_symhdr
;
447 /* See if we've already read it in. */
448 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
449 backend
->debug_swap
.sym_magic
)
452 /* See whether there is a symbolic header. */
453 if (ecoff_data (abfd
)->sym_filepos
== 0)
455 bfd_get_symcount (abfd
) = 0;
459 /* At this point bfd_get_symcount (abfd) holds the number of symbols
460 as read from the file header, but on ECOFF this is always the
461 size of the symbolic information header. It would be cleaner to
462 handle this when we first read the file in coffgen.c. */
463 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
464 if (bfd_get_symcount (abfd
) != external_hdr_size
)
466 bfd_set_error (bfd_error_bad_value
);
470 /* Read the symbolic information header. */
471 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
474 bfd_set_error (bfd_error_no_memory
);
478 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
479 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
480 != external_hdr_size
))
482 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
483 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
485 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
487 bfd_set_error (bfd_error_bad_value
);
491 /* Now we can get the correct number of symbols. */
492 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
493 + internal_symhdr
->iextMax
);
504 /* Read in and swap the important symbolic information for an ECOFF
505 object file. This is called by gdb via the read_debug_info entry
506 point in the backend structure. */
510 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
513 struct ecoff_debug_info
*debug
;
515 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
516 HDRR
*internal_symhdr
;
517 bfd_size_type raw_base
;
518 bfd_size_type raw_size
;
520 bfd_size_type external_fdr_size
;
524 bfd_size_type raw_end
;
525 bfd_size_type cb_end
;
527 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
529 /* Check whether we've already gotten it, and whether there's any to
531 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
533 if (ecoff_data (abfd
)->sym_filepos
== 0)
535 bfd_get_symcount (abfd
) = 0;
539 if (! ecoff_slurp_symbolic_header (abfd
))
542 internal_symhdr
= &debug
->symbolic_header
;
544 /* Read all the symbolic information at once. */
545 raw_base
= (ecoff_data (abfd
)->sym_filepos
546 + backend
->debug_swap
.external_hdr_size
);
548 /* Alpha ecoff makes the determination of raw_size difficult. It has
549 an undocumented debug data section between the symhdr and the first
550 documented section. And the ordering of the sections varies between
551 statically and dynamically linked executables.
552 If bfd supports SEEK_END someday, this code could be simplified. */
556 #define UPDATE_RAW_END(start, count, size) \
557 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
558 if (cb_end > raw_end) \
561 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
562 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
563 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
564 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
565 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
566 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
567 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
568 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
569 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
570 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
571 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
573 #undef UPDATE_RAW_END
575 raw_size
= raw_end
- raw_base
;
578 ecoff_data (abfd
)->sym_filepos
= 0;
581 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
584 bfd_set_error (bfd_error_no_memory
);
588 (ecoff_data (abfd
)->sym_filepos
589 + backend
->debug_swap
.external_hdr_size
),
591 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
593 bfd_release (abfd
, raw
);
597 ecoff_data (abfd
)->raw_syments
= raw
;
599 /* Get pointers for the numeric offsets in the HDRR structure. */
600 #define FIX(off1, off2, type) \
601 if (internal_symhdr->off1 == 0) \
602 debug->off2 = (type) NULL; \
604 debug->off2 = (type) ((char *) raw \
605 + (internal_symhdr->off1 \
607 FIX (cbLineOffset
, line
, unsigned char *);
608 FIX (cbDnOffset
, external_dnr
, PTR
);
609 FIX (cbPdOffset
, external_pdr
, PTR
);
610 FIX (cbSymOffset
, external_sym
, PTR
);
611 FIX (cbOptOffset
, external_opt
, PTR
);
612 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
613 FIX (cbSsOffset
, ss
, char *);
614 FIX (cbSsExtOffset
, ssext
, char *);
615 FIX (cbFdOffset
, external_fdr
, PTR
);
616 FIX (cbRfdOffset
, external_rfd
, PTR
);
617 FIX (cbExtOffset
, external_ext
, PTR
);
620 /* I don't want to always swap all the data, because it will just
621 waste time and most programs will never look at it. The only
622 time the linker needs most of the debugging information swapped
623 is when linking big-endian and little-endian MIPS object files
624 together, which is not a common occurrence.
626 We need to look at the fdr to deal with a lot of information in
627 the symbols, so we swap them here. */
628 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
,
629 (internal_symhdr
->ifdMax
*
630 sizeof (struct fdr
)));
631 if (debug
->fdr
== NULL
)
633 bfd_set_error (bfd_error_no_memory
);
636 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
637 fdr_ptr
= debug
->fdr
;
638 fraw_src
= (char *) debug
->external_fdr
;
639 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
640 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
641 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
646 /* ECOFF symbol table routines. The ECOFF symbol table is described
647 in gcc/mips-tfile.c. */
649 /* ECOFF uses two common sections. One is the usual one, and the
650 other is for small objects. All the small objects are kept
651 together, and then referenced via the gp pointer, which yields
652 faster assembler code. This is what we use for the small common
654 static asection ecoff_scom_section
;
655 static asymbol ecoff_scom_symbol
;
656 static asymbol
*ecoff_scom_symbol_ptr
;
658 /* Create an empty symbol. */
661 _bfd_ecoff_make_empty_symbol (abfd
)
664 ecoff_symbol_type
*new;
666 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
667 if (new == (ecoff_symbol_type
*) NULL
)
669 bfd_set_error (bfd_error_no_memory
);
670 return (asymbol
*) NULL
;
672 memset ((PTR
) new, 0, sizeof *new);
673 new->symbol
.section
= (asection
*) NULL
;
674 new->fdr
= (FDR
*) NULL
;
677 new->symbol
.the_bfd
= abfd
;
681 /* Set the BFD flags and section for an ECOFF symbol. */
684 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
691 asym
->the_bfd
= abfd
;
692 asym
->value
= ecoff_sym
->value
;
693 asym
->section
= &bfd_debug_section
;
696 /* Most symbol types are just for debugging. */
697 switch (ecoff_sym
->st
)
706 if (ECOFF_IS_STAB (ecoff_sym
))
708 asym
->flags
= BSF_DEBUGGING
;
713 asym
->flags
= BSF_DEBUGGING
;
718 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
720 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
723 asym
->flags
= BSF_LOCAL
;
724 /* Normally, a local stProc symbol will have a corresponding
725 external symbol. We mark the local symbol as a debugging
726 symbol, in order to prevent nm from printing both out.
727 Similarly, we mark stLabel and stabs symbols as debugging
728 symbols. In both cases, we do want to set the value
729 correctly based on the symbol class. */
730 if (ecoff_sym
->st
== stProc
731 || ecoff_sym
->st
== stLabel
732 || ECOFF_IS_STAB (ecoff_sym
))
733 asym
->flags
|= BSF_DEBUGGING
;
735 switch (ecoff_sym
->sc
)
738 /* Used for compiler generated labels. Leave them in the
739 debugging section, and mark them as local. If BSF_DEBUGGING
740 is set, then nm does not display them for some reason. If no
741 flags are set then the linker whines about them. */
742 asym
->flags
= BSF_LOCAL
;
745 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
746 asym
->value
-= asym
->section
->vma
;
749 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
750 asym
->value
-= asym
->section
->vma
;
753 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
754 asym
->value
-= asym
->section
->vma
;
757 asym
->flags
= BSF_DEBUGGING
;
760 asym
->section
= bfd_abs_section_ptr
;
763 asym
->section
= bfd_und_section_ptr
;
773 asym
->flags
= BSF_DEBUGGING
;
776 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
777 asym
->value
-= asym
->section
->vma
;
780 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
781 asym
->value
-= asym
->section
->vma
;
784 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
785 asym
->value
-= asym
->section
->vma
;
788 asym
->flags
= BSF_DEBUGGING
;
791 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
793 asym
->section
= bfd_com_section_ptr
;
799 if (ecoff_scom_section
.name
== NULL
)
801 /* Initialize the small common section. */
802 ecoff_scom_section
.name
= SCOMMON
;
803 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
804 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
805 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
806 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
807 ecoff_scom_symbol
.name
= SCOMMON
;
808 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
809 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
810 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
812 asym
->section
= &ecoff_scom_section
;
817 asym
->flags
= BSF_DEBUGGING
;
820 asym
->section
= bfd_und_section_ptr
;
825 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
826 asym
->value
-= asym
->section
->vma
;
831 asym
->flags
= BSF_DEBUGGING
;
834 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
835 asym
->value
-= asym
->section
->vma
;
838 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
839 asym
->value
-= asym
->section
->vma
;
845 /* Look for special constructors symbols and make relocation entries
846 in a special construction section. These are produced by the
847 -fgnu-linker argument to g++. */
848 if (ECOFF_IS_STAB (ecoff_sym
))
850 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
862 arelent_chain
*reloc_chain
;
863 unsigned int bitsize
;
865 /* Get a section with the same name as the symbol (usually
866 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
867 name ___CTOR_LIST (three underscores). We need
868 __CTOR_LIST (two underscores), since ECOFF doesn't use
869 a leading underscore. This should be handled by gcc,
870 but instead we do it here. Actually, this should all
871 be done differently anyhow. */
872 name
= bfd_asymbol_name (asym
);
873 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
878 section
= bfd_get_section_by_name (abfd
, name
);
879 if (section
== (asection
*) NULL
)
883 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
886 bfd_set_error (bfd_error_no_memory
);
890 section
= bfd_make_section (abfd
, copy
);
893 /* Build a reloc pointing to this constructor. */
895 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
898 bfd_set_error (bfd_error_no_memory
);
901 reloc_chain
->relent
.sym_ptr_ptr
=
902 bfd_get_section (asym
)->symbol_ptr_ptr
;
903 reloc_chain
->relent
.address
= section
->_raw_size
;
904 reloc_chain
->relent
.addend
= asym
->value
;
905 reloc_chain
->relent
.howto
=
906 ecoff_backend (abfd
)->constructor_reloc
;
908 /* Set up the constructor section to hold the reloc. */
909 section
->flags
= SEC_CONSTRUCTOR
;
910 ++section
->reloc_count
;
912 /* Constructor sections must be rounded to a boundary
913 based on the bitsize. These are not real sections--
914 they are handled specially by the linker--so the ECOFF
915 16 byte alignment restriction does not apply. */
916 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
917 section
->alignment_power
= 1;
918 while ((1 << section
->alignment_power
) < bitsize
/ 8)
919 ++section
->alignment_power
;
921 reloc_chain
->next
= section
->constructor_chain
;
922 section
->constructor_chain
= reloc_chain
;
923 section
->_raw_size
+= bitsize
/ 8;
925 /* Mark the symbol as a constructor. */
926 asym
->flags
|= BSF_CONSTRUCTOR
;
934 /* Read an ECOFF symbol table. */
937 _bfd_ecoff_slurp_symbol_table (abfd
)
940 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
941 const bfd_size_type external_ext_size
942 = backend
->debug_swap
.external_ext_size
;
943 const bfd_size_type external_sym_size
944 = backend
->debug_swap
.external_sym_size
;
945 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
946 = backend
->debug_swap
.swap_ext_in
;
947 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
948 = backend
->debug_swap
.swap_sym_in
;
949 bfd_size_type internal_size
;
950 ecoff_symbol_type
*internal
;
951 ecoff_symbol_type
*internal_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
;
977 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
979 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
980 * external_ext_size
));
981 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
985 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
986 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
987 + internal_esym
.asym
.iss
);
988 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
989 &internal_ptr
->symbol
, 1,
990 internal_esym
.weakext
))
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
;
1002 /* The local symbols must be accessed via the fdr's, because the
1003 string and aux indices are relative to the fdr information. */
1004 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1005 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1006 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1011 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1012 + fdr_ptr
->isymBase
* external_sym_size
);
1013 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1015 lraw_src
< lraw_end
;
1016 lraw_src
+= external_sym_size
, internal_ptr
++)
1020 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1021 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1023 + internal_sym
.iss
);
1024 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1025 &internal_ptr
->symbol
, 0, 0))
1027 internal_ptr
->fdr
= fdr_ptr
;
1028 internal_ptr
->local
= true;
1029 internal_ptr
->native
= (PTR
) lraw_src
;
1033 ecoff_data (abfd
)->canonical_symbols
= internal
;
1038 /* Return the amount of space needed for the canonical symbols. */
1041 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1044 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1045 &ecoff_data (abfd
)->debug_info
))
1048 if (bfd_get_symcount (abfd
) == 0)
1051 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1054 /* Get the canonical symbols. */
1057 _bfd_ecoff_get_symtab (abfd
, alocation
)
1059 asymbol
**alocation
;
1061 unsigned int counter
= 0;
1062 ecoff_symbol_type
*symbase
;
1063 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1065 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1067 if (bfd_get_symcount (abfd
) == 0)
1070 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1071 while (counter
< bfd_get_symcount (abfd
))
1073 *(location
++) = symbase
++;
1076 *location
++ = (ecoff_symbol_type
*) NULL
;
1077 return bfd_get_symcount (abfd
);
1080 /* Turn ECOFF type information into a printable string.
1081 ecoff_emit_aggregate and ecoff_type_to_string are from
1082 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1084 /* Write aggregate information to a string. */
1087 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1095 const struct ecoff_debug_swap
* const debug_swap
=
1096 &ecoff_backend (abfd
)->debug_swap
;
1097 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1098 unsigned int ifd
= rndx
->rfd
;
1099 unsigned int indx
= rndx
->index
;
1105 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1106 struct return type of a procedure compiled without -g. */
1107 if (ifd
== 0xffffffff
1108 || (rndx
->rfd
== 0xfff && indx
== 0))
1109 name
= "<undefined>";
1110 else if (indx
== indexNil
)
1116 if (debug_info
->external_rfd
== NULL
)
1117 fdr
= debug_info
->fdr
+ ifd
;
1122 (*debug_swap
->swap_rfd_in
) (abfd
,
1123 ((char *) debug_info
->external_rfd
1124 + ((fdr
->rfdBase
+ ifd
)
1125 * debug_swap
->external_rfd_size
)),
1127 fdr
= debug_info
->fdr
+ rfd
;
1130 indx
+= fdr
->isymBase
;
1132 (*debug_swap
->swap_sym_in
) (abfd
,
1133 ((char *) debug_info
->external_sym
1134 + indx
* debug_swap
->external_sym_size
),
1137 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1141 "%s %s { ifd = %u, index = %lu }",
1144 + debug_info
->symbolic_header
.iextMax
));
1147 /* Convert the type information to string format. */
1150 ecoff_type_to_string (abfd
, fdr
, indx
)
1155 union aux_ext
*aux_ptr
;
1164 unsigned int basic_type
;
1167 static char buffer2
[1024];
1172 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1173 bigendian
= fdr
->fBigendian
;
1175 for (i
= 0; i
< 7; i
++)
1177 qualifiers
[i
].low_bound
= 0;
1178 qualifiers
[i
].high_bound
= 0;
1179 qualifiers
[i
].stride
= 0;
1182 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1183 return "-1 (no type)";
1184 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1186 basic_type
= u
.ti
.bt
;
1187 qualifiers
[0].type
= u
.ti
.tq0
;
1188 qualifiers
[1].type
= u
.ti
.tq1
;
1189 qualifiers
[2].type
= u
.ti
.tq2
;
1190 qualifiers
[3].type
= u
.ti
.tq3
;
1191 qualifiers
[4].type
= u
.ti
.tq4
;
1192 qualifiers
[5].type
= u
.ti
.tq5
;
1193 qualifiers
[6].type
= tqNil
;
1196 * Go get the basic type.
1200 case btNil
: /* undefined */
1204 case btAdr
: /* address - integer same size as pointer */
1205 strcpy (p1
, "address");
1208 case btChar
: /* character */
1209 strcpy (p1
, "char");
1212 case btUChar
: /* unsigned character */
1213 strcpy (p1
, "unsigned char");
1216 case btShort
: /* short */
1217 strcpy (p1
, "short");
1220 case btUShort
: /* unsigned short */
1221 strcpy (p1
, "unsigned short");
1224 case btInt
: /* int */
1228 case btUInt
: /* unsigned int */
1229 strcpy (p1
, "unsigned int");
1232 case btLong
: /* long */
1233 strcpy (p1
, "long");
1236 case btULong
: /* unsigned long */
1237 strcpy (p1
, "unsigned long");
1240 case btFloat
: /* float (real) */
1241 strcpy (p1
, "float");
1244 case btDouble
: /* Double (real) */
1245 strcpy (p1
, "double");
1248 /* Structures add 1-2 aux words:
1249 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1250 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1252 case btStruct
: /* Structure (Record) */
1253 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1254 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1255 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1257 indx
++; /* skip aux words */
1260 /* Unions add 1-2 aux words:
1261 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1262 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1264 case btUnion
: /* Union */
1265 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1266 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1267 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1269 indx
++; /* skip aux words */
1272 /* Enumerations add 1-2 aux words:
1273 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1274 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1276 case btEnum
: /* Enumeration */
1277 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1278 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1279 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1281 indx
++; /* skip aux words */
1284 case btTypedef
: /* defined via a typedef, isymRef points */
1285 strcpy (p1
, "typedef");
1288 case btRange
: /* subrange of int */
1289 strcpy (p1
, "subrange");
1292 case btSet
: /* pascal sets */
1296 case btComplex
: /* fortran complex */
1297 strcpy (p1
, "complex");
1300 case btDComplex
: /* fortran double complex */
1301 strcpy (p1
, "double complex");
1304 case btIndirect
: /* forward or unnamed typedef */
1305 strcpy (p1
, "forward/unamed typedef");
1308 case btFixedDec
: /* Fixed Decimal */
1309 strcpy (p1
, "fixed decimal");
1312 case btFloatDec
: /* Float Decimal */
1313 strcpy (p1
, "float decimal");
1316 case btString
: /* Varying Length Character String */
1317 strcpy (p1
, "string");
1320 case btBit
: /* Aligned Bit String */
1324 case btPicture
: /* Picture */
1325 strcpy (p1
, "picture");
1328 case btVoid
: /* Void */
1329 strcpy (p1
, "void");
1333 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1337 p1
+= strlen (buffer1
);
1340 * If this is a bitfield, get the bitsize.
1346 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1347 sprintf (p1
, " : %d", bitsize
);
1348 p1
+= strlen (buffer1
);
1353 * Deal with any qualifiers.
1355 if (qualifiers
[0].type
!= tqNil
)
1358 * Snarf up any array bounds in the correct order. Arrays
1359 * store 5 successive words in the aux. table:
1360 * word 0 RNDXR to type of the bounds (ie, int)
1361 * word 1 Current file descriptor index
1363 * word 3 high bound (or -1 if [])
1364 * word 4 stride size in bits
1366 for (i
= 0; i
< 7; i
++)
1368 if (qualifiers
[i
].type
== tqArray
)
1370 qualifiers
[i
].low_bound
=
1371 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1372 qualifiers
[i
].high_bound
=
1373 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1374 qualifiers
[i
].stride
=
1375 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1381 * Now print out the qualifiers.
1383 for (i
= 0; i
< 6; i
++)
1385 switch (qualifiers
[i
].type
)
1392 strcpy (p2
, "ptr to ");
1393 p2
+= sizeof ("ptr to ")-1;
1397 strcpy (p2
, "volatile ");
1398 p2
+= sizeof ("volatile ")-1;
1402 strcpy (p2
, "far ");
1403 p2
+= sizeof ("far ")-1;
1407 strcpy (p2
, "func. ret. ");
1408 p2
+= sizeof ("func. ret. ");
1413 int first_array
= i
;
1416 /* Print array bounds reversed (ie, in the order the C
1417 programmer writes them). C is such a fun language.... */
1419 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1422 for (j
= i
; j
>= first_array
; j
--)
1424 strcpy (p2
, "array [");
1425 p2
+= sizeof ("array [")-1;
1426 if (qualifiers
[j
].low_bound
!= 0)
1428 "%ld:%ld {%ld bits}",
1429 (long) qualifiers
[j
].low_bound
,
1430 (long) qualifiers
[j
].high_bound
,
1431 (long) qualifiers
[j
].stride
);
1433 else if (qualifiers
[j
].high_bound
!= -1)
1436 (long) (qualifiers
[j
].high_bound
+ 1),
1437 (long) (qualifiers
[j
].stride
));
1440 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1443 strcpy (p2
, "] of ");
1444 p2
+= sizeof ("] of ")-1;
1452 strcpy (p2
, buffer1
);
1456 /* Return information about ECOFF symbol SYMBOL in RET. */
1460 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1461 bfd
*abfd
; /* Ignored. */
1465 bfd_symbol_info (symbol
, ret
);
1468 /* Return whether this is a local label. */
1472 _bfd_ecoff_bfd_is_local_label (abfd
, symbol
)
1476 return symbol
->name
[0] == '$';
1479 /* Print information about an ECOFF symbol. */
1482 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1486 bfd_print_symbol_type how
;
1488 const struct ecoff_debug_swap
* const debug_swap
1489 = &ecoff_backend (abfd
)->debug_swap
;
1490 FILE *file
= (FILE *)filep
;
1494 case bfd_print_symbol_name
:
1495 fprintf (file
, "%s", symbol
->name
);
1497 case bfd_print_symbol_more
:
1498 if (ecoffsymbol (symbol
)->local
)
1502 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1504 fprintf (file
, "ecoff local ");
1505 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1506 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1507 (unsigned) ecoff_sym
.sc
);
1513 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1515 fprintf (file
, "ecoff extern ");
1516 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1517 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1518 (unsigned) ecoff_ext
.asym
.sc
);
1521 case bfd_print_symbol_all
:
1522 /* Print out the symbols in a reasonable way */
1531 if (ecoffsymbol (symbol
)->local
)
1533 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1536 pos
= ((((char *) ecoffsymbol (symbol
)->native
1537 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1538 / debug_swap
->external_sym_size
)
1539 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1546 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1549 pos
= (((char *) ecoffsymbol (symbol
)->native
1550 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1551 / debug_swap
->external_ext_size
);
1552 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1553 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1554 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1557 fprintf (file
, "[%3d] %c ",
1559 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1560 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1561 (unsigned) ecoff_ext
.asym
.st
,
1562 (unsigned) ecoff_ext
.asym
.sc
,
1563 (unsigned) ecoff_ext
.asym
.index
,
1564 jmptbl
, cobol_main
, weakext
,
1567 if (ecoffsymbol (symbol
)->fdr
!= NULL
1568 && ecoff_ext
.asym
.index
!= indexNil
)
1573 bfd_size_type sym_base
;
1574 union aux_ext
*aux_base
;
1576 fdr
= ecoffsymbol (symbol
)->fdr
;
1577 indx
= ecoff_ext
.asym
.index
;
1579 /* sym_base is used to map the fdr relative indices which
1580 appear in the file to the position number which we are
1582 sym_base
= fdr
->isymBase
;
1583 if (ecoffsymbol (symbol
)->local
)
1585 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1587 /* aux_base is the start of the aux entries for this file;
1588 asym.index is an offset from this. */
1589 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1592 /* The aux entries are stored in host byte order; the
1593 order is indicated by a bit in the fdr. */
1594 bigendian
= fdr
->fBigendian
;
1596 /* This switch is basically from gcc/mips-tdump.c */
1597 switch (ecoff_ext
.asym
.st
)
1605 fprintf (file
, "\n End+1 symbol: %ld",
1606 (long) (indx
+ sym_base
));
1610 if (ecoff_ext
.asym
.sc
== scText
1611 || ecoff_ext
.asym
.sc
== scInfo
)
1612 fprintf (file
, "\n First symbol: %ld",
1613 (long) (indx
+ sym_base
));
1615 fprintf (file
, "\n First symbol: %ld",
1617 (AUX_GET_ISYM (bigendian
,
1618 &aux_base
[ecoff_ext
.asym
.index
])
1624 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1626 else if (ecoffsymbol (symbol
)->local
)
1627 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1629 (AUX_GET_ISYM (bigendian
,
1630 &aux_base
[ecoff_ext
.asym
.index
])
1632 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1634 fprintf (file
, "\n Local symbol: %ld",
1637 + (ecoff_data (abfd
)
1638 ->debug_info
.symbolic_header
.iextMax
)));
1642 fprintf (file
, "\n struct; End+1 symbol: %ld",
1643 (long) (indx
+ sym_base
));
1647 fprintf (file
, "\n union; End+1 symbol: %ld",
1648 (long) (indx
+ sym_base
));
1652 fprintf (file
, "\n enum; End+1 symbol: %ld",
1653 (long) (indx
+ sym_base
));
1657 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1658 fprintf (file
, "\n Type: %s",
1659 ecoff_type_to_string (abfd
, fdr
, indx
));
1668 /* Read in the relocs for a section. */
1671 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1676 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1677 arelent
*internal_relocs
;
1678 bfd_size_type external_reloc_size
;
1679 bfd_size_type external_relocs_size
;
1680 char *external_relocs
;
1684 if (section
->relocation
!= (arelent
*) NULL
1685 || section
->reloc_count
== 0
1686 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1689 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1692 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1694 * section
->reloc_count
));
1695 external_reloc_size
= backend
->external_reloc_size
;
1696 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1697 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1698 if (internal_relocs
== (arelent
*) NULL
1699 || external_relocs
== (char *) NULL
)
1701 bfd_set_error (bfd_error_no_memory
);
1704 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1706 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1707 != external_relocs_size
)
1710 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1712 struct internal_reloc intern
;
1714 (*backend
->swap_reloc_in
) (abfd
,
1715 external_relocs
+ i
* external_reloc_size
,
1718 if (intern
.r_extern
)
1720 /* r_symndx is an index into the external symbols. */
1721 BFD_ASSERT (intern
.r_symndx
>= 0
1723 < (ecoff_data (abfd
)
1724 ->debug_info
.symbolic_header
.iextMax
)));
1725 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1728 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1729 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1731 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1736 CONST
char *sec_name
;
1739 /* r_symndx is a section key. */
1740 switch (intern
.r_symndx
)
1742 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1743 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1744 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1745 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1746 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1747 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1748 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1749 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1750 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1751 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1752 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1753 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1754 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1755 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1759 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1760 if (sec
== (asection
*) NULL
)
1762 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1764 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1767 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1769 /* Let the backend select the howto field and do any other
1770 required processing. */
1771 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1774 bfd_release (abfd
, external_relocs
);
1776 section
->relocation
= internal_relocs
;
1781 /* Get a canonical list of relocs. */
1784 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1792 if (section
->flags
& SEC_CONSTRUCTOR
)
1794 arelent_chain
*chain
;
1796 /* This section has relocs made up by us, not the file, so take
1797 them out of their chain and place them into the data area
1799 for (count
= 0, chain
= section
->constructor_chain
;
1800 count
< section
->reloc_count
;
1801 count
++, chain
= chain
->next
)
1802 *relptr
++ = &chain
->relent
;
1808 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1811 tblptr
= section
->relocation
;
1813 for (count
= 0; count
< section
->reloc_count
; count
++)
1814 *relptr
++ = tblptr
++;
1817 *relptr
= (arelent
*) NULL
;
1819 return section
->reloc_count
;
1822 /* Provided a BFD, a section and an offset into the section, calculate
1823 and return the name of the source file and the line nearest to the
1828 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1829 filename_ptr
, functionname_ptr
, retline_ptr
)
1832 asymbol
**ignore_symbols
;
1834 CONST
char **filename_ptr
;
1835 CONST
char **functionname_ptr
;
1836 unsigned int *retline_ptr
;
1838 const struct ecoff_debug_swap
* const debug_swap
1839 = &ecoff_backend (abfd
)->debug_swap
;
1840 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1841 struct ecoff_find_line
*line_info
;
1843 /* If we're not in the .text section, we don't have any line
1845 if (strcmp (section
->name
, _TEXT
) != 0
1846 || offset
>= bfd_section_size (abfd
, section
))
1849 /* Make sure we have the FDR's. */
1850 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1851 || bfd_get_symcount (abfd
) == 0)
1854 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1856 ecoff_data (abfd
)->find_line_info
=
1857 ((struct ecoff_find_line
*)
1858 bfd_alloc (abfd
, sizeof (struct ecoff_find_line
)));
1859 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1861 bfd_set_error (bfd_error_no_memory
);
1864 ecoff_data (abfd
)->find_line_info
->find_buffer
= NULL
;
1865 ecoff_data (abfd
)->find_line_info
->fdrtab_len
= 0;
1866 ecoff_data (abfd
)->find_line_info
->fdrtab
= NULL
;
1868 line_info
= ecoff_data (abfd
)->find_line_info
;
1870 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1871 debug_swap
, line_info
, filename_ptr
,
1872 functionname_ptr
, retline_ptr
);
1875 /* Copy private BFD data. This is called by objcopy and strip. We
1876 use it to copy the ECOFF debugging information from one BFD to the
1877 other. It would be theoretically possible to represent the ECOFF
1878 debugging information in the symbol table. However, it would be a
1879 lot of work, and there would be little gain (gas, gdb, and ld
1880 already access the ECOFF debugging information via the
1881 ecoff_debug_info structure, and that structure would have to be
1882 retained in order to support ECOFF debugging in MIPS ELF).
1884 The debugging information for the ECOFF external symbols comes from
1885 the symbol table, so this function only handles the other debugging
1889 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1893 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1894 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1896 asymbol
**sym_ptr_ptr
;
1900 /* This function is selected based on the input vector. We only
1901 want to copy information over if the output BFD also uses ECOFF
1903 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1906 /* Copy the GP value and the register masks. */
1907 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1908 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1909 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1910 for (i
= 0; i
< 3; i
++)
1911 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1913 /* Copy the version stamp. */
1914 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1916 /* If there are no symbols, don't copy any debugging information. */
1917 c
= bfd_get_symcount (obfd
);
1918 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1919 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1922 /* See if there are any local symbols. */
1924 for (; c
> 0; c
--, sym_ptr_ptr
++)
1926 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1935 /* There are some local symbols. We just bring over all the
1936 debugging information. FIXME: This is not quite the right
1937 thing to do. If the user has asked us to discard all
1938 debugging information, then we are probably going to wind up
1939 keeping it because there will probably be some local symbol
1940 which objcopy did not discard. We should actually break
1941 apart the debugging information and only keep that which
1942 applies to the symbols we want to keep. */
1943 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1944 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1945 oinfo
->line
= iinfo
->line
;
1947 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1948 oinfo
->external_dnr
= iinfo
->external_dnr
;
1950 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1951 oinfo
->external_pdr
= iinfo
->external_pdr
;
1953 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1954 oinfo
->external_sym
= iinfo
->external_sym
;
1956 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1957 oinfo
->external_opt
= iinfo
->external_opt
;
1959 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1960 oinfo
->external_aux
= iinfo
->external_aux
;
1962 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1963 oinfo
->ss
= iinfo
->ss
;
1965 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1966 oinfo
->external_fdr
= iinfo
->external_fdr
;
1968 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1969 oinfo
->external_rfd
= iinfo
->external_rfd
;
1973 /* We are discarding all the local symbol information. Look
1974 through the external symbols and remove all references to FDR
1975 or aux information. */
1976 c
= bfd_get_symcount (obfd
);
1977 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1978 for (; c
> 0; c
--, sym_ptr_ptr
++)
1982 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1983 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1985 esym
.asym
.index
= indexNil
;
1986 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1987 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1994 /* Set the architecture. The supported architecture is stored in the
1995 backend pointer. We always set the architecture anyhow, since many
1996 callers ignore the return value. */
1999 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
2001 enum bfd_architecture arch
;
2002 unsigned long machine
;
2004 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2005 return arch
== ecoff_backend (abfd
)->arch
;
2008 /* Get the size of the section headers. */
2012 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
2021 for (current
= abfd
->sections
;
2022 current
!= (asection
*)NULL
;
2023 current
= current
->next
)
2026 ret
= (bfd_coff_filhsz (abfd
)
2027 + bfd_coff_aoutsz (abfd
)
2028 + c
* bfd_coff_scnhsz (abfd
));
2029 return BFD_ALIGN (ret
, 16);
2032 /* Get the contents of a section. */
2035 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2040 bfd_size_type count
;
2042 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2046 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2047 called via qsort. */
2050 ecoff_sort_hdrs (arg1
, arg2
)
2054 const asection
*hdr1
= *(const asection
**) arg1
;
2055 const asection
*hdr2
= *(const asection
**) arg2
;
2057 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2059 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2064 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2067 if (hdr1
->vma
< hdr2
->vma
)
2069 else if (hdr1
->vma
> hdr2
->vma
)
2075 /* Calculate the file position for each section, and set
2079 ecoff_compute_section_file_positions (abfd
)
2083 asection
**sorted_hdrs
;
2087 boolean first_data
, first_nonalloc
;
2088 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2090 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2092 /* Sort the sections by VMA. */
2093 sorted_hdrs
= (asection
**) malloc (abfd
->section_count
2094 * sizeof (asection
*));
2095 if (sorted_hdrs
== NULL
)
2097 bfd_set_error (bfd_error_no_memory
);
2100 for (current
= abfd
->sections
, i
= 0;
2102 current
= current
->next
, i
++)
2103 sorted_hdrs
[i
] = current
;
2104 BFD_ASSERT (i
== abfd
->section_count
);
2106 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2110 first_nonalloc
= true;
2111 for (i
= 0; i
< abfd
->section_count
; i
++)
2113 unsigned int alignment_power
;
2115 current
= sorted_hdrs
[i
];
2117 /* Only deal with sections which have contents */
2118 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2121 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2122 supposed to indicate the number of .pdata entries that are
2123 really in the section. Each entry is 8 bytes. We store this
2124 away in line_filepos before increasing the section size. */
2125 if (strcmp (current
->name
, _PDATA
) != 0)
2126 alignment_power
= current
->alignment_power
;
2129 current
->line_filepos
= current
->_raw_size
/ 8;
2130 alignment_power
= 4;
2133 /* On Ultrix, the data sections in an executable file must be
2134 aligned to a page boundary within the file. This does not
2135 affect the section size, though. FIXME: Does this work for
2136 other platforms? It requires some modification for the
2137 Alpha, because .rdata on the Alpha goes with the text, not
2139 if ((abfd
->flags
& EXEC_P
) != 0
2140 && (abfd
->flags
& D_PAGED
) != 0
2142 && (current
->flags
& SEC_CODE
) == 0
2143 && (! ecoff_backend (abfd
)->rdata_in_text
2144 || strcmp (current
->name
, _RDATA
) != 0)
2145 && strcmp (current
->name
, _PDATA
) != 0
2146 && strcmp (current
->name
, _RCONST
) != 0)
2148 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2151 else if (strcmp (current
->name
, _LIB
) == 0)
2153 /* On Irix 4, the location of contents of the .lib section
2154 from a shared library section is also rounded up to a
2157 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2159 else if (first_nonalloc
2160 && (current
->flags
& SEC_ALLOC
) == 0
2161 && (abfd
->flags
& D_PAGED
) != 0)
2163 /* Skip up to the next page for an unallocated section, such
2164 as the .comment section on the Alpha. This leaves room
2165 for the .bss section. */
2166 first_nonalloc
= false;
2167 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2170 /* Align the sections in the file to the same boundary on
2171 which they are aligned in virtual memory. */
2173 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2175 if ((abfd
->flags
& D_PAGED
) != 0
2176 && (current
->flags
& SEC_ALLOC
) != 0)
2177 sofar
+= (current
->vma
- sofar
) % round
;
2179 current
->filepos
= sofar
;
2181 sofar
+= current
->_raw_size
;
2183 /* make sure that this section is of the right size too */
2185 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2186 current
->_raw_size
+= sofar
- old_sofar
;
2192 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2197 /* Determine the location of the relocs for all the sections in the
2198 output file, as well as the location of the symbolic debugging
2201 static bfd_size_type
2202 ecoff_compute_reloc_file_positions (abfd
)
2205 const bfd_size_type external_reloc_size
=
2206 ecoff_backend (abfd
)->external_reloc_size
;
2207 file_ptr reloc_base
;
2208 bfd_size_type reloc_size
;
2212 if (! abfd
->output_has_begun
)
2214 if (! ecoff_compute_section_file_positions (abfd
))
2216 abfd
->output_has_begun
= true;
2219 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2222 for (current
= abfd
->sections
;
2223 current
!= (asection
*)NULL
;
2224 current
= current
->next
)
2226 if (current
->reloc_count
== 0)
2227 current
->rel_filepos
= 0;
2230 bfd_size_type relsize
;
2232 current
->rel_filepos
= reloc_base
;
2233 relsize
= current
->reloc_count
* external_reloc_size
;
2234 reloc_size
+= relsize
;
2235 reloc_base
+= relsize
;
2239 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2241 /* At least on Ultrix, the symbol table of an executable file must
2242 be aligned to a page boundary. FIXME: Is this true on other
2244 if ((abfd
->flags
& EXEC_P
) != 0
2245 && (abfd
->flags
& D_PAGED
) != 0)
2246 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2247 &~ (ecoff_backend (abfd
)->round
- 1));
2249 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2254 /* Set the contents of a section. */
2257 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2262 bfd_size_type count
;
2264 /* This must be done first, because bfd_set_section_contents is
2265 going to set output_has_begun to true. */
2266 if (abfd
->output_has_begun
== false)
2268 if (! ecoff_compute_section_file_positions (abfd
))
2272 /* If this is a .lib section, bump the vma address so that it winds
2273 up being the number of .lib sections output. This is right for
2274 Irix 4. Ian Taylor <ian@cygnus.com>. */
2275 if (strcmp (section
->name
, _LIB
) == 0)
2281 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2282 || bfd_write (location
, 1, count
, abfd
) != count
)
2288 /* Get the GP value for an ECOFF file. This is a hook used by
2292 bfd_ecoff_get_gp_value (abfd
)
2295 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2296 || bfd_get_format (abfd
) != bfd_object
)
2298 bfd_set_error (bfd_error_invalid_operation
);
2302 return ecoff_data (abfd
)->gp
;
2305 /* Set the GP value for an ECOFF file. This is a hook used by the
2309 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2313 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2314 || bfd_get_format (abfd
) != bfd_object
)
2316 bfd_set_error (bfd_error_invalid_operation
);
2320 ecoff_data (abfd
)->gp
= gp_value
;
2325 /* Set the register masks for an ECOFF file. This is a hook used by
2329 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2331 unsigned long gprmask
;
2332 unsigned long fprmask
;
2333 unsigned long *cprmask
;
2335 ecoff_data_type
*tdata
;
2337 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2338 || bfd_get_format (abfd
) != bfd_object
)
2340 bfd_set_error (bfd_error_invalid_operation
);
2344 tdata
= ecoff_data (abfd
);
2345 tdata
->gprmask
= gprmask
;
2346 tdata
->fprmask
= fprmask
;
2347 if (cprmask
!= (unsigned long *) NULL
)
2351 for (i
= 0; i
< 3; i
++)
2352 tdata
->cprmask
[i
] = cprmask
[i
];
2358 /* Get ECOFF EXTR information for an external symbol. This function
2359 is passed to bfd_ecoff_debug_externals. */
2362 ecoff_get_extr (sym
, esym
)
2366 ecoff_symbol_type
*ecoff_sym_ptr
;
2369 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2370 || ecoffsymbol (sym
)->native
== NULL
)
2372 /* Don't include debugging, local, or section symbols. */
2373 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2374 || (sym
->flags
& BSF_LOCAL
) != 0
2375 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2379 esym
->cobol_main
= 0;
2380 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2383 /* FIXME: we can do better than this for st and sc. */
2384 esym
->asym
.st
= stGlobal
;
2385 esym
->asym
.sc
= scAbs
;
2386 esym
->asym
.reserved
= 0;
2387 esym
->asym
.index
= indexNil
;
2391 ecoff_sym_ptr
= ecoffsymbol (sym
);
2393 if (ecoff_sym_ptr
->local
)
2396 input_bfd
= bfd_asymbol_bfd (sym
);
2397 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2398 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2400 /* If the symbol was defined by the linker, then esym will be
2401 undefined but sym will not be. Get a better class for such a
2403 if ((esym
->asym
.sc
== scUndefined
2404 || esym
->asym
.sc
== scSUndefined
)
2405 && ! bfd_is_und_section (bfd_get_section (sym
)))
2406 esym
->asym
.sc
= scAbs
;
2408 /* Adjust the FDR index for the symbol by that used for the input
2410 if (esym
->ifd
!= -1)
2412 struct ecoff_debug_info
*input_debug
;
2414 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2415 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2416 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2417 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2423 /* Set the external symbol index. This routine is passed to
2424 bfd_ecoff_debug_externals. */
2427 ecoff_set_index (sym
, indx
)
2431 ecoff_set_sym_index (sym
, indx
);
2434 /* Write out an ECOFF file. */
2437 _bfd_ecoff_write_object_contents (abfd
)
2440 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2441 const bfd_vma round
= backend
->round
;
2442 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2443 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2444 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2445 const bfd_size_type external_hdr_size
2446 = backend
->debug_swap
.external_hdr_size
;
2447 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2448 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2450 struct internal_reloc
*))
2451 = backend
->adjust_reloc_out
;
2452 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2453 const struct internal_reloc
*,
2455 = backend
->swap_reloc_out
;
2456 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2457 HDRR
* const symhdr
= &debug
->symbolic_header
;
2460 bfd_size_type reloc_size
;
2461 bfd_size_type text_size
;
2463 boolean set_text_start
;
2464 bfd_size_type data_size
;
2466 boolean set_data_start
;
2467 bfd_size_type bss_size
;
2469 PTR reloc_buff
= NULL
;
2470 struct internal_filehdr internal_f
;
2471 struct internal_aouthdr internal_a
;
2474 /* Determine where the sections and relocs will go in the output
2476 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2479 for (current
= abfd
->sections
;
2480 current
!= (asection
*)NULL
;
2481 current
= current
->next
)
2483 current
->target_index
= count
;
2487 if ((abfd
->flags
& D_PAGED
) != 0)
2488 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2492 set_text_start
= false;
2495 set_data_start
= false;
2498 /* Write section headers to the file. */
2500 /* Allocate buff big enough to hold a section header,
2501 file header, or a.out header. */
2509 buff
= (PTR
) malloc ((size_t) siz
);
2512 bfd_set_error (bfd_error_no_memory
);
2517 internal_f
.f_nscns
= 0;
2518 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2520 for (current
= abfd
->sections
;
2521 current
!= (asection
*) NULL
;
2522 current
= current
->next
)
2524 struct internal_scnhdr section
;
2527 ++internal_f
.f_nscns
;
2529 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2531 /* This seems to be correct for Irix 4 shared libraries. */
2532 vma
= bfd_get_section_vma (abfd
, current
);
2533 if (strcmp (current
->name
, _LIB
) == 0)
2534 section
.s_vaddr
= 0;
2536 section
.s_vaddr
= vma
;
2538 section
.s_paddr
= vma
;
2539 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2541 /* If this section is unloadable then the scnptr will be 0. */
2542 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2543 section
.s_scnptr
= 0;
2545 section
.s_scnptr
= current
->filepos
;
2546 section
.s_relptr
= current
->rel_filepos
;
2548 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2549 object file produced by the assembler is supposed to point to
2550 information about how much room is required by objects of
2551 various different sizes. I think this only matters if we
2552 want the linker to compute the best size to use, or
2553 something. I don't know what happens if the information is
2555 if (strcmp (current
->name
, _PDATA
) != 0)
2556 section
.s_lnnoptr
= 0;
2559 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2560 hold the number of entries in the section (each entry is
2561 8 bytes). We stored this in the line_filepos field in
2562 ecoff_compute_section_file_positions. */
2563 section
.s_lnnoptr
= current
->line_filepos
;
2566 section
.s_nreloc
= current
->reloc_count
;
2567 section
.s_nlnno
= 0;
2568 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2571 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2572 || bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2575 if ((section
.s_flags
& STYP_TEXT
) != 0
2576 || ((section
.s_flags
& STYP_RDATA
) != 0
2577 && backend
->rdata_in_text
)
2578 || section
.s_flags
== STYP_PDATA
2579 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2580 || (section
.s_flags
& STYP_LIBLIST
) != 0
2581 || (section
.s_flags
& STYP_RELDYN
) != 0
2582 || section
.s_flags
== STYP_CONFLIC
2583 || (section
.s_flags
& STYP_DYNSTR
) != 0
2584 || (section
.s_flags
& STYP_DYNSYM
) != 0
2585 || (section
.s_flags
& STYP_HASH
) != 0
2586 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2587 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2588 || section
.s_flags
== STYP_RCONST
)
2590 text_size
+= bfd_get_section_size_before_reloc (current
);
2591 if (! set_text_start
|| text_start
> vma
)
2594 set_text_start
= true;
2597 else if ((section
.s_flags
& STYP_RDATA
) != 0
2598 || (section
.s_flags
& STYP_DATA
) != 0
2599 || (section
.s_flags
& STYP_LITA
) != 0
2600 || (section
.s_flags
& STYP_LIT8
) != 0
2601 || (section
.s_flags
& STYP_LIT4
) != 0
2602 || (section
.s_flags
& STYP_SDATA
) != 0
2603 || section
.s_flags
== STYP_XDATA
2604 || (section
.s_flags
& STYP_GOT
) != 0)
2606 data_size
+= bfd_get_section_size_before_reloc (current
);
2607 if (! set_data_start
|| data_start
> vma
)
2610 set_data_start
= true;
2613 else if ((section
.s_flags
& STYP_BSS
) != 0
2614 || (section
.s_flags
& STYP_SBSS
) != 0)
2615 bss_size
+= bfd_get_section_size_before_reloc (current
);
2616 else if (section
.s_flags
== 0
2617 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2618 || section
.s_flags
== STYP_COMMENT
)
2624 /* Set up the file header. */
2626 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2628 /* We will NOT put a fucking timestamp in the header here. Every
2629 time you put it back, I will come in and take it out again. I'm
2630 sorry. This field does not belong here. We fill it with a 0 so
2631 it compares the same but is not a reasonable time. --
2633 internal_f
.f_timdat
= 0;
2635 if (bfd_get_symcount (abfd
) != 0)
2637 /* The ECOFF f_nsyms field is not actually the number of
2638 symbols, it's the size of symbolic information header. */
2639 internal_f
.f_nsyms
= external_hdr_size
;
2640 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2644 internal_f
.f_nsyms
= 0;
2645 internal_f
.f_symptr
= 0;
2648 internal_f
.f_opthdr
= aoutsz
;
2650 internal_f
.f_flags
= F_LNNO
;
2651 if (reloc_size
== 0)
2652 internal_f
.f_flags
|= F_RELFLG
;
2653 if (bfd_get_symcount (abfd
) == 0)
2654 internal_f
.f_flags
|= F_LSYMS
;
2655 if (abfd
->flags
& EXEC_P
)
2656 internal_f
.f_flags
|= F_EXEC
;
2658 if (! abfd
->xvec
->byteorder_big_p
)
2659 internal_f
.f_flags
|= F_AR32WR
;
2661 internal_f
.f_flags
|= F_AR32W
;
2663 /* Set up the ``optional'' header. */
2664 if ((abfd
->flags
& D_PAGED
) != 0)
2665 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2667 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2669 /* FIXME: Is this really correct? */
2670 internal_a
.vstamp
= symhdr
->vstamp
;
2672 /* At least on Ultrix, these have to be rounded to page boundaries.
2673 FIXME: Is this true on other platforms? */
2674 if ((abfd
->flags
& D_PAGED
) != 0)
2676 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2677 internal_a
.text_start
= text_start
&~ (round
- 1);
2678 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2679 internal_a
.data_start
= data_start
&~ (round
- 1);
2683 internal_a
.tsize
= text_size
;
2684 internal_a
.text_start
= text_start
;
2685 internal_a
.dsize
= data_size
;
2686 internal_a
.data_start
= data_start
;
2689 /* On Ultrix, the initial portions of the .sbss and .bss segments
2690 are at the end of the data section. The bsize field in the
2691 optional header records how many bss bytes are required beyond
2692 those in the data section. The value is not rounded to a page
2694 if (bss_size
< internal_a
.dsize
- data_size
)
2697 bss_size
-= internal_a
.dsize
- data_size
;
2698 internal_a
.bsize
= bss_size
;
2699 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2701 internal_a
.entry
= bfd_get_start_address (abfd
);
2703 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2705 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2706 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2707 for (i
= 0; i
< 4; i
++)
2708 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2710 /* Let the backend adjust the headers if necessary. */
2711 if (backend
->adjust_headers
)
2713 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2717 /* Write out the file header and the optional header. */
2719 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2722 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2723 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2726 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2727 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2730 /* Build the external symbol information. This must be done before
2731 writing out the relocs so that we know the symbol indices. We
2732 don't do this if this BFD was created by the backend linker,
2733 since it will have already handled the symbols and relocs. */
2734 if (! ecoff_data (abfd
)->linker
)
2736 symhdr
->iextMax
= 0;
2737 symhdr
->issExtMax
= 0;
2738 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2739 debug
->ssext
= debug
->ssext_end
= NULL
;
2740 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2741 (((abfd
->flags
& EXEC_P
) == 0)
2743 ecoff_get_extr
, ecoff_set_index
)
2747 /* Write out the relocs. */
2748 for (current
= abfd
->sections
;
2749 current
!= (asection
*) NULL
;
2750 current
= current
->next
)
2752 arelent
**reloc_ptr_ptr
;
2753 arelent
**reloc_end
;
2756 if (current
->reloc_count
== 0)
2760 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2761 if (reloc_buff
== NULL
)
2763 bfd_set_error (bfd_error_no_memory
);
2767 reloc_ptr_ptr
= current
->orelocation
;
2768 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2769 out_ptr
= (char *) reloc_buff
;
2771 reloc_ptr_ptr
< reloc_end
;
2772 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2776 struct internal_reloc in
;
2778 memset ((PTR
) &in
, 0, sizeof in
);
2780 reloc
= *reloc_ptr_ptr
;
2781 sym
= *reloc
->sym_ptr_ptr
;
2783 in
.r_vaddr
= (reloc
->address
2784 + bfd_get_section_vma (abfd
, current
));
2785 in
.r_type
= reloc
->howto
->type
;
2787 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2789 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2796 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2797 if (strcmp (name
, ".text") == 0)
2798 in
.r_symndx
= RELOC_SECTION_TEXT
;
2799 else if (strcmp (name
, ".rdata") == 0)
2800 in
.r_symndx
= RELOC_SECTION_RDATA
;
2801 else if (strcmp (name
, ".data") == 0)
2802 in
.r_symndx
= RELOC_SECTION_DATA
;
2803 else if (strcmp (name
, ".sdata") == 0)
2804 in
.r_symndx
= RELOC_SECTION_SDATA
;
2805 else if (strcmp (name
, ".sbss") == 0)
2806 in
.r_symndx
= RELOC_SECTION_SBSS
;
2807 else if (strcmp (name
, ".bss") == 0)
2808 in
.r_symndx
= RELOC_SECTION_BSS
;
2809 else if (strcmp (name
, ".init") == 0)
2810 in
.r_symndx
= RELOC_SECTION_INIT
;
2811 else if (strcmp (name
, ".lit8") == 0)
2812 in
.r_symndx
= RELOC_SECTION_LIT8
;
2813 else if (strcmp (name
, ".lit4") == 0)
2814 in
.r_symndx
= RELOC_SECTION_LIT4
;
2815 else if (strcmp (name
, ".xdata") == 0)
2816 in
.r_symndx
= RELOC_SECTION_XDATA
;
2817 else if (strcmp (name
, ".pdata") == 0)
2818 in
.r_symndx
= RELOC_SECTION_PDATA
;
2819 else if (strcmp (name
, ".fini") == 0)
2820 in
.r_symndx
= RELOC_SECTION_FINI
;
2821 else if (strcmp (name
, ".lita") == 0)
2822 in
.r_symndx
= RELOC_SECTION_LITA
;
2823 else if (strcmp (name
, "*ABS*") == 0)
2824 in
.r_symndx
= RELOC_SECTION_ABS
;
2825 else if (strcmp (name
, ".rconst") == 0)
2826 in
.r_symndx
= RELOC_SECTION_RCONST
;
2832 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2834 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2837 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2839 if (bfd_write (reloc_buff
,
2840 external_reloc_size
, current
->reloc_count
, abfd
)
2841 != external_reloc_size
* current
->reloc_count
)
2843 bfd_release (abfd
, reloc_buff
);
2847 /* Write out the symbolic debugging information. */
2848 if (bfd_get_symcount (abfd
) > 0)
2850 /* Write out the debugging information. */
2851 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2852 ecoff_data (abfd
)->sym_filepos
)
2858 /* The .bss section of a demand paged executable must receive an
2859 entire page. If there are symbols, the symbols will start on the
2860 next page. If there are no symbols, we must fill out the page by
2862 if (bfd_get_symcount (abfd
) == 0
2863 && (abfd
->flags
& EXEC_P
) != 0
2864 && (abfd
->flags
& D_PAGED
) != 0)
2868 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2871 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2873 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2876 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2880 if (reloc_buff
!= NULL
)
2881 bfd_release (abfd
, reloc_buff
);
2886 if (reloc_buff
!= NULL
)
2887 bfd_release (abfd
, reloc_buff
);
2893 /* Archive handling. ECOFF uses what appears to be a unique type of
2894 archive header (armap). The byte ordering of the armap and the
2895 contents are encoded in the name of the armap itself. At least for
2896 now, we only support archives with the same byte ordering in the
2897 armap and the contents.
2899 The first four bytes in the armap are the number of symbol
2900 definitions. This is always a power of two.
2902 This is followed by the symbol definitions. Each symbol definition
2903 occupies 8 bytes. The first four bytes are the offset from the
2904 start of the armap strings to the null-terminated string naming
2905 this symbol. The second four bytes are the file offset to the
2906 archive member which defines this symbol. If the second four bytes
2907 are 0, then this is not actually a symbol definition, and it should
2910 The symbols are hashed into the armap with a closed hashing scheme.
2911 See the functions below for the details of the algorithm.
2913 After the symbol definitions comes four bytes holding the size of
2914 the string table, followed by the string table itself. */
2916 /* The name of an archive headers looks like this:
2917 __________E[BL]E[BL]_ (with a trailing space).
2918 The trailing space is changed to an X if the archive is changed to
2919 indicate that the armap is out of date.
2921 The Alpha seems to use ________64E[BL]E[BL]_. */
2923 #define ARMAP_BIG_ENDIAN 'B'
2924 #define ARMAP_LITTLE_ENDIAN 'L'
2925 #define ARMAP_MARKER 'E'
2926 #define ARMAP_START_LENGTH 10
2927 #define ARMAP_HEADER_MARKER_INDEX 10
2928 #define ARMAP_HEADER_ENDIAN_INDEX 11
2929 #define ARMAP_OBJECT_MARKER_INDEX 12
2930 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2931 #define ARMAP_END_INDEX 14
2932 #define ARMAP_END "_ "
2934 /* This is a magic number used in the hashing algorithm. */
2935 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2937 /* This returns the hash value to use for a string. It also sets
2938 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2939 is the number of entries in the hash table, and HLOG is the log
2943 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2945 unsigned int *rehash
;
2953 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2954 hash
*= ARMAP_HASH_MAGIC
;
2955 *rehash
= (hash
& (size
- 1)) | 1;
2956 return hash
>> (32 - hlog
);
2959 /* Read in the armap. */
2962 _bfd_ecoff_slurp_armap (abfd
)
2967 struct areltdata
*mapdata
;
2968 bfd_size_type parsed_size
;
2970 struct artdata
*ardata
;
2973 struct symdef
*symdef_ptr
;
2976 /* Get the name of the first element. */
2977 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2983 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2986 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2987 standard COFF armap. We could move the ECOFF armap stuff into
2988 bfd_slurp_armap, but that seems inappropriate since no other
2989 target uses this format. Instead, we check directly for a COFF
2991 if (strncmp (nextname
, "/ ", 16) == 0)
2992 return bfd_slurp_armap (abfd
);
2994 /* See if the first element is an armap. */
2995 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2996 ARMAP_START_LENGTH
) != 0
2997 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2998 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2999 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3000 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3001 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3002 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3003 || strncmp (nextname
+ ARMAP_END_INDEX
,
3004 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3006 bfd_has_map (abfd
) = false;
3010 /* Make sure we have the right byte ordering. */
3011 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3012 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3013 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3014 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3016 bfd_set_error (bfd_error_wrong_format
);
3020 /* Read in the armap. */
3021 ardata
= bfd_ardata (abfd
);
3022 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
3023 if (mapdata
== (struct areltdata
*) NULL
)
3025 parsed_size
= mapdata
->parsed_size
;
3026 bfd_release (abfd
, (PTR
) mapdata
);
3028 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3029 if (raw_armap
== (char *) NULL
)
3031 bfd_set_error (bfd_error_no_memory
);
3035 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3037 if (bfd_get_error () != bfd_error_system_call
)
3038 bfd_set_error (bfd_error_malformed_archive
);
3039 bfd_release (abfd
, (PTR
) raw_armap
);
3043 ardata
->tdata
= (PTR
) raw_armap
;
3045 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3047 ardata
->symdef_count
= 0;
3048 ardata
->cache
= (struct ar_cache
*) NULL
;
3050 /* This code used to overlay the symdefs over the raw archive data,
3051 but that doesn't work on a 64 bit host. */
3053 stringbase
= raw_armap
+ count
* 8 + 8;
3055 #ifdef CHECK_ARMAP_HASH
3059 /* Double check that I have the hashing algorithm right by making
3060 sure that every symbol can be looked up successfully. */
3062 for (i
= 1; i
< count
; i
<<= 1)
3064 BFD_ASSERT (i
== count
);
3066 raw_ptr
= raw_armap
+ 4;
3067 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3069 unsigned int name_offset
, file_offset
;
3070 unsigned int hash
, rehash
, srch
;
3072 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3073 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3074 if (file_offset
== 0)
3076 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3081 /* See if we can rehash to this location. */
3082 for (srch
= (hash
+ rehash
) & (count
- 1);
3083 srch
!= hash
&& srch
!= i
;
3084 srch
= (srch
+ rehash
) & (count
- 1))
3085 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3087 BFD_ASSERT (srch
== i
);
3091 #endif /* CHECK_ARMAP_HASH */
3093 raw_ptr
= raw_armap
+ 4;
3094 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3095 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3096 ++ardata
->symdef_count
;
3098 symdef_ptr
= ((struct symdef
*)
3100 ardata
->symdef_count
* sizeof (struct symdef
)));
3103 bfd_set_error (bfd_error_no_memory
);
3107 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3109 raw_ptr
= raw_armap
+ 4;
3110 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3112 unsigned int name_offset
, file_offset
;
3114 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3115 if (file_offset
== 0)
3117 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3118 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3119 symdef_ptr
->file_offset
= file_offset
;
3123 ardata
->first_file_filepos
= bfd_tell (abfd
);
3124 /* Pad to an even boundary. */
3125 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3127 bfd_has_map (abfd
) = true;
3132 /* Write out an armap. */
3135 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3137 unsigned int elength
;
3139 unsigned int orl_count
;
3142 unsigned int hashsize
, hashlog
;
3143 unsigned int symdefsize
;
3145 unsigned int stringsize
;
3146 unsigned int mapsize
;
3149 struct stat statbuf
;
3152 bfd_byte
*hashtable
;
3156 /* Ultrix appears to use as a hash table size the least power of two
3157 greater than twice the number of entries. */
3158 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3160 hashsize
= 1 << hashlog
;
3162 symdefsize
= hashsize
* 8;
3164 stringsize
= stridx
+ padit
;
3166 /* Include 8 bytes to store symdefsize and stringsize in output. */
3167 mapsize
= symdefsize
+ stringsize
+ 8;
3169 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3171 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3173 /* Work out the ECOFF armap name. */
3174 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3175 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3176 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3177 (abfd
->xvec
->header_byteorder_big_p
3179 : ARMAP_LITTLE_ENDIAN
);
3180 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3181 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3182 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3183 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3185 /* Write the timestamp of the archive header to be just a little bit
3186 later than the timestamp of the file, otherwise the linker will
3187 complain that the index is out of date. Actually, the Ultrix
3188 linker just checks the archive name; the GNU linker may check the
3190 stat (abfd
->filename
, &statbuf
);
3191 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3193 /* The DECstation uses zeroes for the uid, gid and mode of the
3195 hdr
.ar_uid
[0] = '0';
3196 hdr
.ar_gid
[0] = '0';
3197 hdr
.ar_mode
[0] = '0';
3199 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3201 hdr
.ar_fmag
[0] = '`';
3202 hdr
.ar_fmag
[1] = '\012';
3204 /* Turn all null bytes in the header into spaces. */
3205 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3206 if (((char *)(&hdr
))[i
] == '\0')
3207 (((char *)(&hdr
))[i
]) = ' ';
3209 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3210 != sizeof (struct ar_hdr
))
3213 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3214 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3217 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3220 bfd_set_error (bfd_error_no_memory
);
3224 current
= abfd
->archive_head
;
3226 for (i
= 0; i
< orl_count
; i
++)
3228 unsigned int hash
, rehash
;
3230 /* Advance firstreal to the file position of this archive
3232 if (((bfd
*) map
[i
].pos
) != last_elt
)
3236 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3237 firstreal
+= firstreal
% 2;
3238 current
= current
->next
;
3240 while (current
!= (bfd
*) map
[i
].pos
);
3245 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3246 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3250 /* The desired slot is already taken. */
3251 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3253 srch
= (srch
+ rehash
) & (hashsize
- 1))
3254 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3257 BFD_ASSERT (srch
!= hash
);
3262 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3263 (PTR
) (hashtable
+ hash
* 8));
3264 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3265 (PTR
) (hashtable
+ hash
* 8 + 4));
3268 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3271 bfd_release (abfd
, hashtable
);
3273 /* Now write the strings. */
3274 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3275 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3277 for (i
= 0; i
< orl_count
; i
++)
3281 len
= strlen (*map
[i
].name
) + 1;
3282 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3286 /* The spec sez this should be a newline. But in order to be
3287 bug-compatible for DECstation ar we use a null. */
3290 if (bfd_write ("", 1, 1, abfd
) != 1)
3297 /* See whether this BFD is an archive. If it is, read in the armap
3298 and the extended name table. */
3301 _bfd_ecoff_archive_p (abfd
)
3304 char armag
[SARMAG
+ 1];
3306 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3307 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3309 if (bfd_get_error () != bfd_error_system_call
)
3310 bfd_set_error (bfd_error_wrong_format
);
3311 return (const bfd_target
*) NULL
;
3314 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3315 involves a cast, we can't do it as the left operand of
3317 abfd
->tdata
.aout_ar_data
=
3318 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3320 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3322 bfd_set_error (bfd_error_no_memory
);
3323 return (const bfd_target
*) NULL
;
3326 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3327 bfd_ardata (abfd
)->cache
= NULL
;
3328 bfd_ardata (abfd
)->archive_head
= NULL
;
3329 bfd_ardata (abfd
)->symdefs
= NULL
;
3330 bfd_ardata (abfd
)->extended_names
= NULL
;
3331 bfd_ardata (abfd
)->tdata
= NULL
;
3333 if (_bfd_ecoff_slurp_armap (abfd
) == false
3334 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3336 bfd_release (abfd
, bfd_ardata (abfd
));
3337 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3338 return (const bfd_target
*) NULL
;
3344 /* ECOFF linker code. */
3346 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3347 PARAMS ((struct bfd_hash_entry
*entry
,
3348 struct bfd_hash_table
*table
,
3349 const char *string
));
3350 static boolean ecoff_link_add_archive_symbols
3351 PARAMS ((bfd
*, struct bfd_link_info
*));
3352 static boolean ecoff_link_check_archive_element
3353 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3354 static boolean ecoff_link_add_object_symbols
3355 PARAMS ((bfd
*, struct bfd_link_info
*));
3356 static boolean ecoff_link_add_externals
3357 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3359 /* Routine to create an entry in an ECOFF link hash table. */
3361 static struct bfd_hash_entry
*
3362 ecoff_link_hash_newfunc (entry
, table
, string
)
3363 struct bfd_hash_entry
*entry
;
3364 struct bfd_hash_table
*table
;
3367 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3369 /* Allocate the structure if it has not already been allocated by a
3371 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3372 ret
= ((struct ecoff_link_hash_entry
*)
3373 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3374 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3376 bfd_set_error (bfd_error_no_memory
);
3380 /* Call the allocation method of the superclass. */
3381 ret
= ((struct ecoff_link_hash_entry
*)
3382 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3387 /* Set local fields. */
3393 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3395 return (struct bfd_hash_entry
*) ret
;
3398 /* Create an ECOFF link hash table. */
3400 struct bfd_link_hash_table
*
3401 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3404 struct ecoff_link_hash_table
*ret
;
3406 ret
= ((struct ecoff_link_hash_table
*)
3407 bfd_alloc (abfd
, sizeof (struct ecoff_link_hash_table
)));
3410 bfd_set_error (bfd_error_no_memory
);
3413 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3414 ecoff_link_hash_newfunc
))
3417 return (struct bfd_link_hash_table
*) NULL
;
3422 /* Look up an entry in an ECOFF link hash table. */
3424 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3425 ((struct ecoff_link_hash_entry *) \
3426 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3428 /* Traverse an ECOFF link hash table. */
3430 #define ecoff_link_hash_traverse(table, func, info) \
3431 (bfd_link_hash_traverse \
3433 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3436 /* Get the ECOFF link hash table from the info structure. This is
3439 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3441 /* Given an ECOFF BFD, add symbols to the global hash table as
3445 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3447 struct bfd_link_info
*info
;
3449 switch (bfd_get_format (abfd
))
3452 return ecoff_link_add_object_symbols (abfd
, info
);
3454 return ecoff_link_add_archive_symbols (abfd
, info
);
3456 bfd_set_error (bfd_error_wrong_format
);
3461 /* Add the symbols from an archive file to the global hash table.
3462 This looks through the undefined symbols, looks each one up in the
3463 archive hash table, and adds any associated object file. We do not
3464 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3465 already have a hash table, so there is no reason to construct
3469 ecoff_link_add_archive_symbols (abfd
, info
)
3471 struct bfd_link_info
*info
;
3473 const bfd_byte
*raw_armap
;
3474 struct bfd_link_hash_entry
**pundef
;
3475 unsigned int armap_count
;
3476 unsigned int armap_log
;
3478 const bfd_byte
*hashtable
;
3479 const char *stringbase
;
3481 if (! bfd_has_map (abfd
))
3483 /* An empty archive is a special case. */
3484 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3486 bfd_set_error (bfd_error_no_armap
);
3490 /* If we don't have any raw data for this archive, as can happen on
3491 Irix 4.0.5F, we call the generic routine.
3492 FIXME: We should be more clever about this, since someday tdata
3493 may get to something for a generic archive. */
3494 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3495 if (raw_armap
== (bfd_byte
*) NULL
)
3496 return (_bfd_generic_link_add_archive_symbols
3497 (abfd
, info
, ecoff_link_check_archive_element
));
3499 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3502 for (i
= 1; i
< armap_count
; i
<<= 1)
3504 BFD_ASSERT (i
== armap_count
);
3506 hashtable
= raw_armap
+ 4;
3507 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3509 /* Look through the list of undefined symbols. */
3510 pundef
= &info
->hash
->undefs
;
3511 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3513 struct bfd_link_hash_entry
*h
;
3514 unsigned int hash
, rehash
;
3515 unsigned int file_offset
;
3521 /* When a symbol is defined, it is not necessarily removed from
3523 if (h
->type
!= bfd_link_hash_undefined
3524 && h
->type
!= bfd_link_hash_common
)
3526 /* Remove this entry from the list, for general cleanliness
3527 and because we are going to look through the list again
3528 if we search any more libraries. We can't remove the
3529 entry if it is the tail, because that would lose any
3530 entries we add to the list later on. */
3531 if (*pundef
!= info
->hash
->undefs_tail
)
3532 *pundef
= (*pundef
)->next
;
3534 pundef
= &(*pundef
)->next
;
3538 /* Native ECOFF linkers do not pull in archive elements merely
3539 to satisfy common definitions, so neither do we. We leave
3540 them on the list, though, in case we are linking against some
3541 other object format. */
3542 if (h
->type
!= bfd_link_hash_undefined
)
3544 pundef
= &(*pundef
)->next
;
3548 /* Look for this symbol in the archive hash table. */
3549 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3552 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3553 if (file_offset
== 0)
3555 /* Nothing in this slot. */
3556 pundef
= &(*pundef
)->next
;
3560 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3561 if (name
[0] != h
->root
.string
[0]
3562 || strcmp (name
, h
->root
.string
) != 0)
3567 /* That was the wrong symbol. Try rehashing. */
3569 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3571 srch
= (srch
+ rehash
) & (armap_count
- 1))
3573 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3574 if (file_offset
== 0)
3576 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3577 if (name
[0] == h
->root
.string
[0]
3578 && strcmp (name
, h
->root
.string
) == 0)
3587 pundef
= &(*pundef
)->next
;
3594 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3595 if (element
== (bfd
*) NULL
)
3598 if (! bfd_check_format (element
, bfd_object
))
3601 /* Unlike the generic linker, we know that this element provides
3602 a definition for an undefined symbol and we know that we want
3603 to include it. We don't need to check anything. */
3604 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3606 if (! ecoff_link_add_object_symbols (element
, info
))
3609 pundef
= &(*pundef
)->next
;
3615 /* This is called if we used _bfd_generic_link_add_archive_symbols
3616 because we were not dealing with an ECOFF archive. */
3619 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3621 struct bfd_link_info
*info
;
3624 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3625 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3626 = backend
->debug_swap
.swap_ext_in
;
3628 bfd_size_type external_ext_size
;
3629 PTR external_ext
= NULL
;
3637 if (! ecoff_slurp_symbolic_header (abfd
))
3640 /* If there are no symbols, we don't want it. */
3641 if (bfd_get_symcount (abfd
) == 0)
3642 goto successful_return
;
3644 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3646 /* Read in the external symbols and external strings. */
3647 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3648 esize
= symhdr
->iextMax
* external_ext_size
;
3649 external_ext
= (PTR
) malloc (esize
);
3650 if (external_ext
== NULL
&& esize
!= 0)
3652 bfd_set_error (bfd_error_no_memory
);
3656 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3657 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3660 ssext
= (char *) malloc (symhdr
->issExtMax
);
3661 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3663 bfd_set_error (bfd_error_no_memory
);
3667 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3668 || (bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) !=
3669 (bfd_size_type
) symhdr
->issExtMax
))
3672 /* Look through the external symbols to see if they define some
3673 symbol that is currently undefined. */
3674 ext_ptr
= (char *) external_ext
;
3675 ext_end
= ext_ptr
+ esize
;
3676 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3681 struct bfd_link_hash_entry
*h
;
3683 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3685 /* See if this symbol defines something. */
3686 if (esym
.asym
.st
!= stGlobal
3687 && esym
.asym
.st
!= stLabel
3688 && esym
.asym
.st
!= stProc
)
3691 switch (esym
.asym
.sc
)
3715 name
= ssext
+ esym
.asym
.iss
;
3716 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3718 /* Unlike the generic linker, we do not pull in elements because
3719 of common symbols. */
3720 if (h
== (struct bfd_link_hash_entry
*) NULL
3721 || h
->type
!= bfd_link_hash_undefined
)
3724 /* Include this element. */
3725 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3727 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3731 goto successful_return
;
3735 if (external_ext
!= NULL
)
3736 free (external_ext
);
3741 if (external_ext
!= NULL
)
3742 free (external_ext
);
3748 /* Add symbols from an ECOFF object file to the global linker hash
3752 ecoff_link_add_object_symbols (abfd
, info
)
3754 struct bfd_link_info
*info
;
3757 bfd_size_type external_ext_size
;
3758 PTR external_ext
= NULL
;
3763 if (! ecoff_slurp_symbolic_header (abfd
))
3766 /* If there are no symbols, we don't want it. */
3767 if (bfd_get_symcount (abfd
) == 0)
3770 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3772 /* Read in the external symbols and external strings. */
3773 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3774 esize
= symhdr
->iextMax
* external_ext_size
;
3775 external_ext
= (PTR
) malloc (esize
);
3776 if (external_ext
== NULL
&& esize
!= 0)
3778 bfd_set_error (bfd_error_no_memory
);
3782 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3783 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3786 ssext
= (char *) malloc (symhdr
->issExtMax
);
3787 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3789 bfd_set_error (bfd_error_no_memory
);
3793 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3794 || (bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
)
3795 != (bfd_size_type
) symhdr
->issExtMax
))
3798 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3802 if (external_ext
!= NULL
)
3803 free (external_ext
);
3809 if (external_ext
!= NULL
)
3810 free (external_ext
);
3814 /* Add the external symbols of an object file to the global linker
3815 hash table. The external symbols and strings we are passed are
3816 just allocated on the stack, and will be discarded. We must
3817 explicitly save any information we may need later on in the link.
3818 We do not want to read the external symbol information again. */
3821 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3823 struct bfd_link_info
*info
;
3827 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3828 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3829 = backend
->debug_swap
.swap_ext_in
;
3830 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3831 unsigned long ext_count
;
3832 struct ecoff_link_hash_entry
**sym_hash
;
3836 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3838 sym_hash
= ((struct ecoff_link_hash_entry
**)
3840 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3843 bfd_set_error (bfd_error_no_memory
);
3846 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3848 ext_ptr
= (char *) external_ext
;
3849 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3850 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3857 struct ecoff_link_hash_entry
*h
;
3861 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3863 /* Skip debugging symbols. */
3865 switch (esym
.asym
.st
)
3881 /* Get the information for this symbol. */
3882 value
= esym
.asym
.value
;
3883 switch (esym
.asym
.sc
)
3903 section
= bfd_make_section_old_way (abfd
, ".text");
3904 value
-= section
->vma
;
3907 section
= bfd_make_section_old_way (abfd
, ".data");
3908 value
-= section
->vma
;
3911 section
= bfd_make_section_old_way (abfd
, ".bss");
3912 value
-= section
->vma
;
3915 section
= bfd_abs_section_ptr
;
3918 section
= bfd_und_section_ptr
;
3921 section
= bfd_make_section_old_way (abfd
, ".sdata");
3922 value
-= section
->vma
;
3925 section
= bfd_make_section_old_way (abfd
, ".sbss");
3926 value
-= section
->vma
;
3929 section
= bfd_make_section_old_way (abfd
, ".rdata");
3930 value
-= section
->vma
;
3933 if (value
> ecoff_data (abfd
)->gp_size
)
3935 section
= bfd_com_section_ptr
;
3940 if (ecoff_scom_section
.name
== NULL
)
3942 /* Initialize the small common section. */
3943 ecoff_scom_section
.name
= SCOMMON
;
3944 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3945 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3946 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3947 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3948 ecoff_scom_symbol
.name
= SCOMMON
;
3949 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3950 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3951 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3953 section
= &ecoff_scom_section
;
3956 section
= bfd_und_section_ptr
;
3959 section
= bfd_make_section_old_way (abfd
, ".init");
3960 value
-= section
->vma
;
3963 section
= bfd_make_section_old_way (abfd
, ".fini");
3964 value
-= section
->vma
;
3967 section
= bfd_make_section_old_way (abfd
, ".rconst");
3968 value
-= section
->vma
;
3972 if (section
== (asection
*) NULL
)
3975 name
= ssext
+ esym
.asym
.iss
;
3978 if (! (_bfd_generic_link_add_one_symbol
3980 esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
,
3981 section
, value
, (const char *) NULL
, true, true,
3982 (struct bfd_link_hash_entry
**) &h
)))
3987 /* If we are building an ECOFF hash table, save the external
3988 symbol information. */
3989 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3991 if (h
->abfd
== (bfd
*) NULL
3992 || (! bfd_is_und_section (section
)
3993 && (! bfd_is_com_section (section
)
3994 || (h
->root
.type
!= bfd_link_hash_defined
3995 && h
->root
.type
!= bfd_link_hash_defweak
))))
4001 /* Remember whether this symbol was small undefined. */
4002 if (esym
.asym
.sc
== scSUndefined
)
4005 /* If this symbol was ever small undefined, it needs to wind
4006 up in a GP relative section. We can't control the
4007 section of a defined symbol, but we can control the
4008 section of a common symbol. This case is actually needed
4009 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4011 && h
->root
.type
== bfd_link_hash_common
4012 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
4014 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
4016 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4017 if (h
->esym
.asym
.sc
== scCommon
)
4018 h
->esym
.asym
.sc
= scSCommon
;
4026 /* ECOFF final link routines. */
4028 static boolean ecoff_final_link_debug_accumulate
4029 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4031 static boolean ecoff_link_write_external
4032 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4033 static boolean ecoff_indirect_link_order
4034 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4035 struct bfd_link_order
*));
4036 static boolean ecoff_reloc_link_order
4037 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4038 struct bfd_link_order
*));
4040 /* ECOFF final link routine. This looks through all the input BFDs
4041 and gathers together all the debugging information, and then
4042 processes all the link order information. This may cause it to
4043 close and reopen some input BFDs; I'll see how bad this is. */
4046 _bfd_ecoff_bfd_final_link (abfd
, info
)
4048 struct bfd_link_info
*info
;
4050 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4051 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4054 register bfd
*input_bfd
;
4056 struct bfd_link_order
*p
;
4058 /* We accumulate the debugging information counts in the symbolic
4060 symhdr
= &debug
->symbolic_header
;
4062 symhdr
->ilineMax
= 0;
4066 symhdr
->isymMax
= 0;
4067 symhdr
->ioptMax
= 0;
4068 symhdr
->iauxMax
= 0;
4070 symhdr
->issExtMax
= 0;
4073 symhdr
->iextMax
= 0;
4075 /* We accumulate the debugging information itself in the debug_info
4078 debug
->external_dnr
= NULL
;
4079 debug
->external_pdr
= NULL
;
4080 debug
->external_sym
= NULL
;
4081 debug
->external_opt
= NULL
;
4082 debug
->external_aux
= NULL
;
4084 debug
->ssext
= debug
->ssext_end
= NULL
;
4085 debug
->external_fdr
= NULL
;
4086 debug
->external_rfd
= NULL
;
4087 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4089 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4090 if (handle
== (PTR
) NULL
)
4093 /* Accumulate the debugging symbols from each input BFD. */
4094 for (input_bfd
= info
->input_bfds
;
4095 input_bfd
!= (bfd
*) NULL
;
4096 input_bfd
= input_bfd
->link_next
)
4100 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4102 /* Abitrarily set the symbolic header vstamp to the vstamp
4103 of the first object file in the link. */
4104 if (symhdr
->vstamp
== 0)
4106 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4107 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4111 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4112 debug
, &backend
->debug_swap
,
4117 /* Combine the register masks. */
4118 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4119 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4120 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4121 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4122 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4123 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4126 /* Write out the external symbols. */
4127 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4128 ecoff_link_write_external
,
4131 if (info
->relocateable
)
4133 /* We need to make a pass over the link_orders to count up the
4134 number of relocations we will need to output, so that we know
4135 how much space they will take up. */
4136 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4139 for (p
= o
->link_order_head
;
4140 p
!= (struct bfd_link_order
*) NULL
;
4142 if (p
->type
== bfd_indirect_link_order
)
4143 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4144 else if (p
->type
== bfd_section_reloc_link_order
4145 || p
->type
== bfd_symbol_reloc_link_order
)
4150 /* Compute the reloc and symbol file positions. */
4151 ecoff_compute_reloc_file_positions (abfd
);
4153 /* Write out the debugging information. */
4154 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4155 &backend
->debug_swap
, info
,
4156 ecoff_data (abfd
)->sym_filepos
))
4159 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4161 if (info
->relocateable
)
4163 /* Now reset the reloc_count field of the sections in the output
4164 BFD to 0, so that we can use them to keep track of how many
4165 relocs we have output thus far. */
4166 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4170 /* Get a value for the GP register. */
4171 if (ecoff_data (abfd
)->gp
== 0)
4173 struct bfd_link_hash_entry
*h
;
4175 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4176 if (h
!= (struct bfd_link_hash_entry
*) NULL
4177 && h
->type
== bfd_link_hash_defined
)
4178 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4179 + h
->u
.def
.section
->output_section
->vma
4180 + h
->u
.def
.section
->output_offset
);
4181 else if (info
->relocateable
)
4185 /* Make up a value. */
4187 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4190 && (strcmp (o
->name
, _SBSS
) == 0
4191 || strcmp (o
->name
, _SDATA
) == 0
4192 || strcmp (o
->name
, _LIT4
) == 0
4193 || strcmp (o
->name
, _LIT8
) == 0
4194 || strcmp (o
->name
, _LITA
) == 0))
4197 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4201 /* If the relocate_section function needs to do a reloc
4202 involving the GP value, it should make a reloc_dangerous
4203 callback to warn that GP is not defined. */
4207 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4209 for (p
= o
->link_order_head
;
4210 p
!= (struct bfd_link_order
*) NULL
;
4213 if (p
->type
== bfd_indirect_link_order
4214 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4215 == bfd_target_ecoff_flavour
))
4217 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4220 else if (p
->type
== bfd_section_reloc_link_order
4221 || p
->type
== bfd_symbol_reloc_link_order
)
4223 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4228 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4234 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4236 ecoff_data (abfd
)->linker
= true;
4241 /* Accumulate the debugging information for an input BFD into the
4242 output BFD. This must read in the symbolic information of the
4246 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4249 struct bfd_link_info
*info
;
4252 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4253 const struct ecoff_debug_swap
* const swap
=
4254 &ecoff_backend (input_bfd
)->debug_swap
;
4255 HDRR
*symhdr
= &debug
->symbolic_header
;
4258 #define READ(ptr, offset, count, size, type) \
4259 if (symhdr->count == 0) \
4260 debug->ptr = NULL; \
4263 debug->ptr = (type) malloc ((size_t) (size * symhdr->count)); \
4264 if (debug->ptr == NULL) \
4266 bfd_set_error (bfd_error_no_memory); \
4268 goto return_something; \
4270 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4272 || (bfd_read (debug->ptr, size, symhdr->count, \
4273 input_bfd) != size * symhdr->count)) \
4276 goto return_something; \
4280 /* If raw_syments is not NULL, then the data was already by read by
4281 _bfd_ecoff_slurp_symbolic_info. */
4282 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4284 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4286 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4287 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4288 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4289 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4290 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4292 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4293 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4294 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4298 /* We do not read the external strings or the external symbols. */
4300 ret
= (bfd_ecoff_debug_accumulate
4301 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4302 &ecoff_backend (output_bfd
)->debug_swap
,
4303 input_bfd
, debug
, swap
, info
));
4306 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4308 if (debug
->line
!= NULL
)
4310 if (debug
->external_dnr
!= NULL
)
4311 free (debug
->external_dnr
);
4312 if (debug
->external_pdr
!= NULL
)
4313 free (debug
->external_pdr
);
4314 if (debug
->external_sym
!= NULL
)
4315 free (debug
->external_sym
);
4316 if (debug
->external_opt
!= NULL
)
4317 free (debug
->external_opt
);
4318 if (debug
->external_aux
!= NULL
)
4319 free (debug
->external_aux
);
4320 if (debug
->ss
!= NULL
)
4322 if (debug
->external_fdr
!= NULL
)
4323 free (debug
->external_fdr
);
4324 if (debug
->external_rfd
!= NULL
)
4325 free (debug
->external_rfd
);
4327 /* Make sure we don't accidentally follow one of these pointers
4328 into freed memory. */
4330 debug
->external_dnr
= NULL
;
4331 debug
->external_pdr
= NULL
;
4332 debug
->external_sym
= NULL
;
4333 debug
->external_opt
= NULL
;
4334 debug
->external_aux
= NULL
;
4336 debug
->external_fdr
= NULL
;
4337 debug
->external_rfd
= NULL
;
4343 /* Put out information for an external symbol. These come only from
4347 ecoff_link_write_external (h
, data
)
4348 struct ecoff_link_hash_entry
*h
;
4351 bfd
*output_bfd
= (bfd
*) data
;
4353 /* FIXME: We should check if this symbol is being stripped. */
4358 if (h
->abfd
== (bfd
*) NULL
)
4361 h
->esym
.cobol_main
= 0;
4362 h
->esym
.weakext
= 0;
4363 h
->esym
.reserved
= 0;
4364 h
->esym
.ifd
= ifdNil
;
4365 h
->esym
.asym
.value
= 0;
4366 h
->esym
.asym
.st
= stGlobal
;
4368 if (h
->root
.type
!= bfd_link_hash_defined
4369 && h
->root
.type
!= bfd_link_hash_defweak
)
4370 h
->esym
.asym
.sc
= scAbs
;
4373 asection
*output_section
;
4376 output_section
= h
->root
.u
.def
.section
->output_section
;
4377 name
= bfd_section_name (output_section
->owner
, output_section
);
4379 if (strcmp (name
, _TEXT
) == 0)
4380 h
->esym
.asym
.sc
= scText
;
4381 else if (strcmp (name
, _DATA
) == 0)
4382 h
->esym
.asym
.sc
= scData
;
4383 else if (strcmp (name
, _SDATA
) == 0)
4384 h
->esym
.asym
.sc
= scSData
;
4385 else if (strcmp (name
, _RDATA
) == 0)
4386 h
->esym
.asym
.sc
= scRData
;
4387 else if (strcmp (name
, _BSS
) == 0)
4388 h
->esym
.asym
.sc
= scBss
;
4389 else if (strcmp (name
, _SBSS
) == 0)
4390 h
->esym
.asym
.sc
= scSBss
;
4391 else if (strcmp (name
, _INIT
) == 0)
4392 h
->esym
.asym
.sc
= scInit
;
4393 else if (strcmp (name
, _FINI
) == 0)
4394 h
->esym
.asym
.sc
= scFini
;
4395 else if (strcmp (name
, _PDATA
) == 0)
4396 h
->esym
.asym
.sc
= scPData
;
4397 else if (strcmp (name
, _XDATA
) == 0)
4398 h
->esym
.asym
.sc
= scXData
;
4399 else if (strcmp (name
, _RCONST
) == 0)
4400 h
->esym
.asym
.sc
= scRConst
;
4402 h
->esym
.asym
.sc
= scAbs
;
4405 h
->esym
.asym
.reserved
= 0;
4406 h
->esym
.asym
.index
= indexNil
;
4408 else if (h
->esym
.ifd
!= -1)
4410 struct ecoff_debug_info
*debug
;
4412 /* Adjust the FDR index for the symbol by that used for the
4414 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4415 BFD_ASSERT (h
->esym
.ifd
>= 0
4416 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4417 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4420 switch (h
->root
.type
)
4423 case bfd_link_hash_new
:
4425 case bfd_link_hash_undefined
:
4426 case bfd_link_hash_undefweak
:
4427 if (h
->esym
.asym
.sc
!= scUndefined
4428 && h
->esym
.asym
.sc
!= scSUndefined
)
4429 h
->esym
.asym
.sc
= scUndefined
;
4431 case bfd_link_hash_defined
:
4432 case bfd_link_hash_defweak
:
4433 if (h
->esym
.asym
.sc
== scUndefined
4434 || h
->esym
.asym
.sc
== scSUndefined
)
4435 h
->esym
.asym
.sc
= scAbs
;
4436 else if (h
->esym
.asym
.sc
== scCommon
)
4437 h
->esym
.asym
.sc
= scBss
;
4438 else if (h
->esym
.asym
.sc
== scSCommon
)
4439 h
->esym
.asym
.sc
= scSBss
;
4440 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4441 + h
->root
.u
.def
.section
->output_section
->vma
4442 + h
->root
.u
.def
.section
->output_offset
);
4444 case bfd_link_hash_common
:
4445 if (h
->esym
.asym
.sc
!= scCommon
4446 && h
->esym
.asym
.sc
!= scSCommon
)
4447 h
->esym
.asym
.sc
= scCommon
;
4448 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4450 case bfd_link_hash_indirect
:
4451 case bfd_link_hash_warning
:
4452 /* FIXME: Ignore these for now. The circumstances under which
4453 they should be written out are not clear to me. */
4457 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4459 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4462 return (bfd_ecoff_debug_one_external
4463 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4464 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4468 /* Relocate and write an ECOFF section into an ECOFF output file. */
4471 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4473 struct bfd_link_info
*info
;
4474 asection
*output_section
;
4475 struct bfd_link_order
*link_order
;
4477 asection
*input_section
;
4479 struct ecoff_section_tdata
*section_tdata
;
4480 bfd_size_type raw_size
;
4481 bfd_size_type cooked_size
;
4482 bfd_byte
*contents
= NULL
;
4483 bfd_size_type external_reloc_size
;
4484 bfd_size_type external_relocs_size
;
4485 PTR external_relocs
= NULL
;
4487 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4489 if (link_order
->size
== 0)
4492 input_section
= link_order
->u
.indirect
.section
;
4493 input_bfd
= input_section
->owner
;
4494 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4496 raw_size
= input_section
->_raw_size
;
4497 cooked_size
= input_section
->_cooked_size
;
4498 if (cooked_size
== 0)
4499 cooked_size
= raw_size
;
4501 BFD_ASSERT (input_section
->output_section
== output_section
);
4502 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4503 BFD_ASSERT (cooked_size
== link_order
->size
);
4505 /* Get the section contents. We allocate memory for the larger of
4506 the size before relocating and the size after relocating. */
4507 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4509 : (size_t) cooked_size
);
4510 if (contents
== NULL
&& raw_size
!= 0)
4512 bfd_set_error (bfd_error_no_memory
);
4516 /* If we are relaxing, the contents may have already been read into
4517 memory, in which case we copy them into our new buffer. We don't
4518 simply reuse the old buffer in case cooked_size > raw_size. */
4519 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4520 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4521 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4524 if (! bfd_get_section_contents (input_bfd
, input_section
,
4526 (file_ptr
) 0, raw_size
))
4530 /* Get the relocs. If we are relaxing MIPS code, they will already
4531 have been read in. Otherwise, we read them in now. */
4532 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4533 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4535 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4536 && section_tdata
->external_relocs
!= NULL
)
4537 external_relocs
= section_tdata
->external_relocs
;
4540 external_relocs
= (PTR
) malloc ((size_t) external_relocs_size
);
4541 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4543 bfd_set_error (bfd_error_no_memory
);
4547 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4548 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4549 != external_relocs_size
))
4553 /* Relocate the section contents. */
4554 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4555 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4559 /* Write out the relocated section. */
4560 if (! bfd_set_section_contents (output_bfd
,
4563 input_section
->output_offset
,
4567 /* If we are producing relocateable output, the relocs were
4568 modified, and we write them out now. We use the reloc_count
4569 field of output_section to keep track of the number of relocs we
4570 have output so far. */
4571 if (info
->relocateable
)
4573 if (bfd_seek (output_bfd
,
4574 (output_section
->rel_filepos
+
4575 output_section
->reloc_count
* external_reloc_size
),
4577 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4578 != external_relocs_size
))
4580 output_section
->reloc_count
+= input_section
->reloc_count
;
4583 if (contents
!= NULL
)
4585 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4586 free (external_relocs
);
4590 if (contents
!= NULL
)
4592 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4593 free (external_relocs
);
4597 /* Generate a reloc when linking an ECOFF file. This is a reloc
4598 requested by the linker, and does come from any input file. This
4599 is used to build constructor and destructor tables when linking
4603 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4605 struct bfd_link_info
*info
;
4606 asection
*output_section
;
4607 struct bfd_link_order
*link_order
;
4609 enum bfd_link_order_type type
;
4613 struct internal_reloc in
;
4614 bfd_size_type external_reloc_size
;
4618 type
= link_order
->type
;
4620 addend
= link_order
->u
.reloc
.p
->addend
;
4622 /* We set up an arelent to pass to the backend adjust_reloc_out
4624 rel
.address
= link_order
->offset
;
4626 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4629 bfd_set_error (bfd_error_bad_value
);
4633 if (type
== bfd_section_reloc_link_order
)
4635 section
= link_order
->u
.reloc
.p
->u
.section
;
4636 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4640 struct bfd_link_hash_entry
*h
;
4642 /* Treat a reloc against a defined symbol as though it were
4643 actually against the section. */
4644 h
= bfd_link_hash_lookup (info
->hash
, link_order
->u
.reloc
.p
->u
.name
,
4645 false, false, false);
4647 && (h
->type
== bfd_link_hash_defined
4648 || h
->type
== bfd_link_hash_defweak
))
4650 type
= bfd_section_reloc_link_order
;
4651 section
= h
->u
.def
.section
->output_section
;
4652 /* It seems that we ought to add the symbol value to the
4653 addend here, but in practice it has already been added
4654 because it was passed to constructor_callback. */
4655 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4659 /* We can't set up a reloc against a symbol correctly,
4660 because we have no asymbol structure. Currently no
4661 adjust_reloc_out routine cares. */
4662 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4666 /* All ECOFF relocs are in-place. Put the addend into the object
4669 BFD_ASSERT (rel
.howto
->partial_inplace
);
4673 bfd_reloc_status_type rstat
;
4677 size
= bfd_get_reloc_size (rel
.howto
);
4678 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4679 if (buf
== (bfd_byte
*) NULL
)
4681 bfd_set_error (bfd_error_no_memory
);
4684 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
, addend
, buf
);
4690 case bfd_reloc_outofrange
:
4692 case bfd_reloc_overflow
:
4693 if (! ((*info
->callbacks
->reloc_overflow
)
4695 (link_order
->type
== bfd_section_reloc_link_order
4696 ? bfd_section_name (output_bfd
, section
)
4697 : link_order
->u
.reloc
.p
->u
.name
),
4698 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4699 (asection
*) NULL
, (bfd_vma
) 0)))
4706 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4707 (file_ptr
) link_order
->offset
, size
);
4715 /* Move the information into a internal_reloc structure. */
4716 in
.r_vaddr
= (rel
.address
4717 + bfd_get_section_vma (output_bfd
, output_section
));
4718 in
.r_type
= rel
.howto
->type
;
4720 if (type
== bfd_symbol_reloc_link_order
)
4722 struct ecoff_link_hash_entry
*h
;
4724 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4725 link_order
->u
.reloc
.p
->u
.name
,
4726 false, false, true);
4727 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4729 in
.r_symndx
= h
->indx
;
4732 if (! ((*info
->callbacks
->unattached_reloc
)
4733 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4734 (asection
*) NULL
, (bfd_vma
) 0)))
4744 name
= bfd_get_section_name (output_bfd
, section
);
4745 if (strcmp (name
, ".text") == 0)
4746 in
.r_symndx
= RELOC_SECTION_TEXT
;
4747 else if (strcmp (name
, ".rdata") == 0)
4748 in
.r_symndx
= RELOC_SECTION_RDATA
;
4749 else if (strcmp (name
, ".data") == 0)
4750 in
.r_symndx
= RELOC_SECTION_DATA
;
4751 else if (strcmp (name
, ".sdata") == 0)
4752 in
.r_symndx
= RELOC_SECTION_SDATA
;
4753 else if (strcmp (name
, ".sbss") == 0)
4754 in
.r_symndx
= RELOC_SECTION_SBSS
;
4755 else if (strcmp (name
, ".bss") == 0)
4756 in
.r_symndx
= RELOC_SECTION_BSS
;
4757 else if (strcmp (name
, ".init") == 0)
4758 in
.r_symndx
= RELOC_SECTION_INIT
;
4759 else if (strcmp (name
, ".lit8") == 0)
4760 in
.r_symndx
= RELOC_SECTION_LIT8
;
4761 else if (strcmp (name
, ".lit4") == 0)
4762 in
.r_symndx
= RELOC_SECTION_LIT4
;
4763 else if (strcmp (name
, ".xdata") == 0)
4764 in
.r_symndx
= RELOC_SECTION_XDATA
;
4765 else if (strcmp (name
, ".pdata") == 0)
4766 in
.r_symndx
= RELOC_SECTION_PDATA
;
4767 else if (strcmp (name
, ".fini") == 0)
4768 in
.r_symndx
= RELOC_SECTION_FINI
;
4769 else if (strcmp (name
, ".lita") == 0)
4770 in
.r_symndx
= RELOC_SECTION_LITA
;
4771 else if (strcmp (name
, "*ABS*") == 0)
4772 in
.r_symndx
= RELOC_SECTION_ABS
;
4773 else if (strcmp (name
, ".rconst") == 0)
4774 in
.r_symndx
= RELOC_SECTION_RCONST
;
4780 /* Let the BFD backend adjust the reloc. */
4781 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4783 /* Get some memory and swap out the reloc. */
4784 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4785 rbuf
= (bfd_byte
*) malloc ((size_t) external_reloc_size
);
4786 if (rbuf
== (bfd_byte
*) NULL
)
4788 bfd_set_error (bfd_error_no_memory
);
4792 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4794 ok
= (bfd_seek (output_bfd
,
4795 (output_section
->rel_filepos
+
4796 output_section
->reloc_count
* external_reloc_size
),
4798 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4799 == external_reloc_size
));
4802 ++output_section
->reloc_count
;