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
)
90 /* This is a hook called by coff_real_object_p to create any backend
91 specific information. */
94 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
99 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
100 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
101 ecoff_data_type
*ecoff
;
103 if (_bfd_ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
114 ecoff
->text_start
= internal_a
->text_start
;
115 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
116 ecoff
->gp
= internal_a
->gp_value
;
117 ecoff
->gprmask
= internal_a
->gprmask
;
118 for (i
= 0; i
< 4; i
++)
119 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
120 ecoff
->fprmask
= internal_a
->fprmask
;
121 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
122 abfd
->flags
|= D_PAGED
;
124 abfd
->flags
&=~ D_PAGED
;
127 /* It turns out that no special action is required by the MIPS or
128 Alpha ECOFF backends. They have different information in the
129 a.out header, but we just copy it all (e.g., gprmask, cprmask and
130 fprmask) and let the swapping routines ensure that only relevant
131 information is written out. */
136 /* Initialize a new section. */
139 _bfd_ecoff_new_section_hook (abfd
, section
)
143 /* For the .pdata section, which has a special meaning on the Alpha,
144 we set the alignment power to 3. We correct this later in
145 ecoff_compute_section_file_positions. We do this hackery because
146 we need to know the exact unaligned size of the .pdata section in
147 order to set the lnnoptr field correctly. For every other
148 section we use an alignment power of 4; this could be made target
149 dependent by adding a field to ecoff_backend_data, but 4 appears
150 to be correct for both the MIPS and the Alpha. */
151 if (strcmp (section
->name
, _PDATA
) == 0)
152 section
->alignment_power
= 3;
154 section
->alignment_power
= 4;
156 if (strcmp (section
->name
, _TEXT
) == 0)
157 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
158 else if (strcmp (section
->name
, _DATA
) == 0
159 || strcmp (section
->name
, _SDATA
) == 0)
160 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
161 else if (strcmp (section
->name
, _RDATA
) == 0
162 || strcmp (section
->name
, _LIT8
) == 0
163 || strcmp (section
->name
, _LIT4
) == 0
164 || strcmp (section
->name
, _RCONST
) == 0)
165 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
166 else if (strcmp (section
->name
, _BSS
) == 0
167 || strcmp (section
->name
, _SBSS
) == 0)
168 section
->flags
|= SEC_ALLOC
;
169 else if (strcmp (section
->name
, _LIB
) == 0)
171 /* An Irix 4 shared libary. */
172 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
175 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
176 uncertain about .init on some systems and I don't know how shared
182 /* Determine the machine architecture and type. This is called from
183 the generic COFF routines. It is the inverse of ecoff_get_magic,
184 below. This could be an ECOFF backend routine, with one version
185 for each target, but there aren't all that many ECOFF targets. */
188 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
192 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
193 enum bfd_architecture arch
;
196 switch (internal_f
->f_magic
)
199 case MIPS_MAGIC_LITTLE
:
201 arch
= bfd_arch_mips
;
205 case MIPS_MAGIC_LITTLE2
:
206 case MIPS_MAGIC_BIG2
:
207 /* MIPS ISA level 2: the r6000 */
208 arch
= bfd_arch_mips
;
212 case MIPS_MAGIC_LITTLE3
:
213 case MIPS_MAGIC_BIG3
:
214 /* MIPS ISA level 3: the r4000 */
215 arch
= bfd_arch_mips
;
220 arch
= bfd_arch_alpha
;
225 arch
= bfd_arch_obscure
;
230 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
233 /* Get the magic number to use based on the architecture and machine.
234 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
237 ecoff_get_magic (abfd
)
242 switch (bfd_get_arch (abfd
))
245 switch (bfd_get_mach (abfd
))
250 big
= MIPS_MAGIC_BIG
;
251 little
= MIPS_MAGIC_LITTLE
;
255 big
= MIPS_MAGIC_BIG2
;
256 little
= MIPS_MAGIC_LITTLE2
;
260 big
= MIPS_MAGIC_BIG3
;
261 little
= MIPS_MAGIC_LITTLE3
;
265 return abfd
->xvec
->byteorder_big_p
? big
: little
;
276 /* Get the section s_flags to use for a section. */
279 ecoff_sec_to_styp_flags (name
, flags
)
287 if (strcmp (name
, _TEXT
) == 0)
289 else if (strcmp (name
, _DATA
) == 0)
291 else if (strcmp (name
, _SDATA
) == 0)
293 else if (strcmp (name
, _RDATA
) == 0)
295 else if (strcmp (name
, _LITA
) == 0)
297 else if (strcmp (name
, _LIT8
) == 0)
299 else if (strcmp (name
, _LIT4
) == 0)
301 else if (strcmp (name
, _BSS
) == 0)
303 else if (strcmp (name
, _SBSS
) == 0)
305 else if (strcmp (name
, _INIT
) == 0)
306 styp
= STYP_ECOFF_INIT
;
307 else if (strcmp (name
, _FINI
) == 0)
308 styp
= STYP_ECOFF_FINI
;
309 else if (strcmp (name
, _PDATA
) == 0)
311 else if (strcmp (name
, _XDATA
) == 0)
313 else if (strcmp (name
, _LIB
) == 0)
314 styp
= STYP_ECOFF_LIB
;
315 else if (strcmp (name
, _GOT
) == 0)
317 else if (strcmp (name
, _HASH
) == 0)
319 else if (strcmp (name
, _DYNAMIC
) == 0)
321 else if (strcmp (name
, _LIBLIST
) == 0)
323 else if (strcmp (name
, _RELDYN
) == 0)
325 else if (strcmp (name
, _CONFLIC
) == 0)
327 else if (strcmp (name
, _DYNSTR
) == 0)
329 else if (strcmp (name
, _DYNSYM
) == 0)
331 else if (strcmp (name
, _COMMENT
) == 0)
334 flags
&=~ SEC_NEVER_LOAD
;
336 else if (strcmp (name
, _RCONST
) == 0)
338 else if (flags
& SEC_CODE
)
340 else if (flags
& SEC_DATA
)
342 else if (flags
& SEC_READONLY
)
344 else if (flags
& SEC_LOAD
)
349 if (flags
& SEC_NEVER_LOAD
)
355 /* Get the BFD flags to use for a section. */
359 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
)
364 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
365 long styp_flags
= internal_s
->s_flags
;
366 flagword sec_flags
=0;
368 if (styp_flags
& STYP_NOLOAD
)
369 sec_flags
|= SEC_NEVER_LOAD
;
371 /* For 386 COFF, at least, an unloadable text or data section is
372 actually a shared library section. */
373 if ((styp_flags
& STYP_TEXT
)
374 || (styp_flags
& STYP_ECOFF_INIT
)
375 || (styp_flags
& STYP_ECOFF_FINI
)
376 || (styp_flags
& STYP_DYNAMIC
)
377 || (styp_flags
& STYP_LIBLIST
)
378 || (styp_flags
& STYP_RELDYN
)
379 || styp_flags
== STYP_CONFLIC
380 || (styp_flags
& STYP_DYNSTR
)
381 || (styp_flags
& STYP_DYNSYM
)
382 || (styp_flags
& STYP_HASH
))
384 if (sec_flags
& SEC_NEVER_LOAD
)
385 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
387 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
389 else if ((styp_flags
& STYP_DATA
)
390 || (styp_flags
& STYP_RDATA
)
391 || (styp_flags
& STYP_SDATA
)
392 || styp_flags
== STYP_PDATA
393 || styp_flags
== STYP_XDATA
394 || (styp_flags
& STYP_GOT
)
395 || styp_flags
== STYP_RCONST
)
397 if (sec_flags
& SEC_NEVER_LOAD
)
398 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
400 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
401 if ((styp_flags
& STYP_RDATA
)
402 || styp_flags
== STYP_PDATA
403 || styp_flags
== STYP_RCONST
)
404 sec_flags
|= SEC_READONLY
;
406 else if ((styp_flags
& STYP_BSS
)
407 || (styp_flags
& STYP_SBSS
))
409 sec_flags
|= SEC_ALLOC
;
411 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
413 sec_flags
|= SEC_NEVER_LOAD
;
415 else if ((styp_flags
& STYP_LITA
)
416 || (styp_flags
& STYP_LIT8
)
417 || (styp_flags
& STYP_LIT4
))
419 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
421 else if (styp_flags
& STYP_ECOFF_LIB
)
423 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
427 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
433 /* Read in the symbolic header for an ECOFF object file. */
436 ecoff_slurp_symbolic_header (abfd
)
439 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
440 bfd_size_type external_hdr_size
;
442 HDRR
*internal_symhdr
;
444 /* See if we've already read it in. */
445 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
446 backend
->debug_swap
.sym_magic
)
449 /* See whether there is a symbolic header. */
450 if (ecoff_data (abfd
)->sym_filepos
== 0)
452 bfd_get_symcount (abfd
) = 0;
456 /* At this point bfd_get_symcount (abfd) holds the number of symbols
457 as read from the file header, but on ECOFF this is always the
458 size of the symbolic information header. It would be cleaner to
459 handle this when we first read the file in coffgen.c. */
460 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
461 if (bfd_get_symcount (abfd
) != external_hdr_size
)
463 bfd_set_error (bfd_error_bad_value
);
467 /* Read the symbolic information header. */
468 raw
= (PTR
) bfd_malloc ((size_t) external_hdr_size
);
472 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
473 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
474 != external_hdr_size
))
476 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
477 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
479 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
481 bfd_set_error (bfd_error_bad_value
);
485 /* Now we can get the correct number of symbols. */
486 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
487 + internal_symhdr
->iextMax
);
498 /* Read in and swap the important symbolic information for an ECOFF
499 object file. This is called by gdb via the read_debug_info entry
500 point in the backend structure. */
504 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
507 struct ecoff_debug_info
*debug
;
509 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
510 HDRR
*internal_symhdr
;
511 bfd_size_type raw_base
;
512 bfd_size_type raw_size
;
514 bfd_size_type external_fdr_size
;
518 bfd_size_type raw_end
;
519 bfd_size_type cb_end
;
521 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
523 /* Check whether we've already gotten it, and whether there's any to
525 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
527 if (ecoff_data (abfd
)->sym_filepos
== 0)
529 bfd_get_symcount (abfd
) = 0;
533 if (! ecoff_slurp_symbolic_header (abfd
))
536 internal_symhdr
= &debug
->symbolic_header
;
538 /* Read all the symbolic information at once. */
539 raw_base
= (ecoff_data (abfd
)->sym_filepos
540 + backend
->debug_swap
.external_hdr_size
);
542 /* Alpha ecoff makes the determination of raw_size difficult. It has
543 an undocumented debug data section between the symhdr and the first
544 documented section. And the ordering of the sections varies between
545 statically and dynamically linked executables.
546 If bfd supports SEEK_END someday, this code could be simplified. */
550 #define UPDATE_RAW_END(start, count, size) \
551 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
552 if (cb_end > raw_end) \
555 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
556 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
557 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
558 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
559 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
560 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
561 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
562 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
563 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
564 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
565 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
567 #undef UPDATE_RAW_END
569 raw_size
= raw_end
- raw_base
;
572 ecoff_data (abfd
)->sym_filepos
= 0;
575 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
579 (ecoff_data (abfd
)->sym_filepos
580 + backend
->debug_swap
.external_hdr_size
),
582 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
584 bfd_release (abfd
, raw
);
588 ecoff_data (abfd
)->raw_syments
= raw
;
590 /* Get pointers for the numeric offsets in the HDRR structure. */
591 #define FIX(off1, off2, type) \
592 if (internal_symhdr->off1 == 0) \
593 debug->off2 = (type) NULL; \
595 debug->off2 = (type) ((char *) raw \
596 + (internal_symhdr->off1 \
598 FIX (cbLineOffset
, line
, unsigned char *);
599 FIX (cbDnOffset
, external_dnr
, PTR
);
600 FIX (cbPdOffset
, external_pdr
, PTR
);
601 FIX (cbSymOffset
, external_sym
, PTR
);
602 FIX (cbOptOffset
, external_opt
, PTR
);
603 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
604 FIX (cbSsOffset
, ss
, char *);
605 FIX (cbSsExtOffset
, ssext
, char *);
606 FIX (cbFdOffset
, external_fdr
, PTR
);
607 FIX (cbRfdOffset
, external_rfd
, PTR
);
608 FIX (cbExtOffset
, external_ext
, PTR
);
611 /* I don't want to always swap all the data, because it will just
612 waste time and most programs will never look at it. The only
613 time the linker needs most of the debugging information swapped
614 is when linking big-endian and little-endian MIPS object files
615 together, which is not a common occurrence.
617 We need to look at the fdr to deal with a lot of information in
618 the symbols, so we swap them here. */
619 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
,
620 (internal_symhdr
->ifdMax
*
621 sizeof (struct fdr
)));
622 if (debug
->fdr
== NULL
)
624 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
625 fdr_ptr
= debug
->fdr
;
626 fraw_src
= (char *) debug
->external_fdr
;
627 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
628 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
629 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
634 /* ECOFF symbol table routines. The ECOFF symbol table is described
635 in gcc/mips-tfile.c. */
637 /* ECOFF uses two common sections. One is the usual one, and the
638 other is for small objects. All the small objects are kept
639 together, and then referenced via the gp pointer, which yields
640 faster assembler code. This is what we use for the small common
642 static asection ecoff_scom_section
;
643 static asymbol ecoff_scom_symbol
;
644 static asymbol
*ecoff_scom_symbol_ptr
;
646 /* Create an empty symbol. */
649 _bfd_ecoff_make_empty_symbol (abfd
)
652 ecoff_symbol_type
*new;
654 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
655 if (new == (ecoff_symbol_type
*) NULL
)
656 return (asymbol
*) NULL
;
657 memset ((PTR
) new, 0, sizeof *new);
658 new->symbol
.section
= (asection
*) NULL
;
659 new->fdr
= (FDR
*) NULL
;
662 new->symbol
.the_bfd
= abfd
;
666 /* Set the BFD flags and section for an ECOFF symbol. */
669 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
676 asym
->the_bfd
= abfd
;
677 asym
->value
= ecoff_sym
->value
;
678 asym
->section
= &bfd_debug_section
;
681 /* Most symbol types are just for debugging. */
682 switch (ecoff_sym
->st
)
691 if (ECOFF_IS_STAB (ecoff_sym
))
693 asym
->flags
= BSF_DEBUGGING
;
698 asym
->flags
= BSF_DEBUGGING
;
703 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
705 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
708 asym
->flags
= BSF_LOCAL
;
709 /* Normally, a local stProc symbol will have a corresponding
710 external symbol. We mark the local symbol as a debugging
711 symbol, in order to prevent nm from printing both out.
712 Similarly, we mark stLabel and stabs symbols as debugging
713 symbols. In both cases, we do want to set the value
714 correctly based on the symbol class. */
715 if (ecoff_sym
->st
== stProc
716 || ecoff_sym
->st
== stLabel
717 || ECOFF_IS_STAB (ecoff_sym
))
718 asym
->flags
|= BSF_DEBUGGING
;
720 switch (ecoff_sym
->sc
)
723 /* Used for compiler generated labels. Leave them in the
724 debugging section, and mark them as local. If BSF_DEBUGGING
725 is set, then nm does not display them for some reason. If no
726 flags are set then the linker whines about them. */
727 asym
->flags
= BSF_LOCAL
;
730 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
731 asym
->value
-= asym
->section
->vma
;
734 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
735 asym
->value
-= asym
->section
->vma
;
738 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
739 asym
->value
-= asym
->section
->vma
;
742 asym
->flags
= BSF_DEBUGGING
;
745 asym
->section
= bfd_abs_section_ptr
;
748 asym
->section
= bfd_und_section_ptr
;
758 asym
->flags
= BSF_DEBUGGING
;
761 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
762 asym
->value
-= asym
->section
->vma
;
765 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
766 asym
->value
-= asym
->section
->vma
;
769 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
770 asym
->value
-= asym
->section
->vma
;
773 asym
->flags
= BSF_DEBUGGING
;
776 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
778 asym
->section
= bfd_com_section_ptr
;
784 if (ecoff_scom_section
.name
== NULL
)
786 /* Initialize the small common section. */
787 ecoff_scom_section
.name
= SCOMMON
;
788 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
789 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
790 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
791 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
792 ecoff_scom_symbol
.name
= SCOMMON
;
793 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
794 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
795 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
797 asym
->section
= &ecoff_scom_section
;
802 asym
->flags
= BSF_DEBUGGING
;
805 asym
->section
= bfd_und_section_ptr
;
810 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
811 asym
->value
-= asym
->section
->vma
;
816 asym
->flags
= BSF_DEBUGGING
;
819 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
820 asym
->value
-= asym
->section
->vma
;
823 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
824 asym
->value
-= asym
->section
->vma
;
830 /* Look for special constructors symbols and make relocation entries
831 in a special construction section. These are produced by the
832 -fgnu-linker argument to g++. */
833 if (ECOFF_IS_STAB (ecoff_sym
))
835 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
847 arelent_chain
*reloc_chain
;
848 unsigned int bitsize
;
850 /* Get a section with the same name as the symbol (usually
851 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
852 name ___CTOR_LIST (three underscores). We need
853 __CTOR_LIST (two underscores), since ECOFF doesn't use
854 a leading underscore. This should be handled by gcc,
855 but instead we do it here. Actually, this should all
856 be done differently anyhow. */
857 name
= bfd_asymbol_name (asym
);
858 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
863 section
= bfd_get_section_by_name (abfd
, name
);
864 if (section
== (asection
*) NULL
)
868 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
872 section
= bfd_make_section (abfd
, copy
);
875 /* Build a reloc pointing to this constructor. */
877 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
880 reloc_chain
->relent
.sym_ptr_ptr
=
881 bfd_get_section (asym
)->symbol_ptr_ptr
;
882 reloc_chain
->relent
.address
= section
->_raw_size
;
883 reloc_chain
->relent
.addend
= asym
->value
;
884 reloc_chain
->relent
.howto
=
885 ecoff_backend (abfd
)->constructor_reloc
;
887 /* Set up the constructor section to hold the reloc. */
888 section
->flags
= SEC_CONSTRUCTOR
;
889 ++section
->reloc_count
;
891 /* Constructor sections must be rounded to a boundary
892 based on the bitsize. These are not real sections--
893 they are handled specially by the linker--so the ECOFF
894 16 byte alignment restriction does not apply. */
895 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
896 section
->alignment_power
= 1;
897 while ((1 << section
->alignment_power
) < bitsize
/ 8)
898 ++section
->alignment_power
;
900 reloc_chain
->next
= section
->constructor_chain
;
901 section
->constructor_chain
= reloc_chain
;
902 section
->_raw_size
+= bitsize
/ 8;
904 /* Mark the symbol as a constructor. */
905 asym
->flags
|= BSF_CONSTRUCTOR
;
913 /* Read an ECOFF symbol table. */
916 _bfd_ecoff_slurp_symbol_table (abfd
)
919 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
920 const bfd_size_type external_ext_size
921 = backend
->debug_swap
.external_ext_size
;
922 const bfd_size_type external_sym_size
923 = backend
->debug_swap
.external_sym_size
;
924 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
925 = backend
->debug_swap
.swap_ext_in
;
926 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
927 = backend
->debug_swap
.swap_sym_in
;
928 bfd_size_type internal_size
;
929 ecoff_symbol_type
*internal
;
930 ecoff_symbol_type
*internal_ptr
;
936 /* If we've already read in the symbol table, do nothing. */
937 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
940 /* Get the symbolic information. */
941 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
942 &ecoff_data (abfd
)->debug_info
))
944 if (bfd_get_symcount (abfd
) == 0)
947 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
948 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
949 if (internal
== NULL
)
952 internal_ptr
= internal
;
953 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
955 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
956 * external_ext_size
));
957 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
961 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
962 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
963 + internal_esym
.asym
.iss
);
964 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
965 &internal_ptr
->symbol
, 1,
966 internal_esym
.weakext
))
968 /* The alpha uses a negative ifd field for section symbols. */
969 if (internal_esym
.ifd
>= 0)
970 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
971 + internal_esym
.ifd
);
973 internal_ptr
->fdr
= NULL
;
974 internal_ptr
->local
= false;
975 internal_ptr
->native
= (PTR
) eraw_src
;
978 /* The local symbols must be accessed via the fdr's, because the
979 string and aux indices are relative to the fdr information. */
980 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
981 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
982 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
987 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
988 + fdr_ptr
->isymBase
* external_sym_size
);
989 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
992 lraw_src
+= external_sym_size
, internal_ptr
++)
996 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
997 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1000 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1001 &internal_ptr
->symbol
, 0, 0))
1003 internal_ptr
->fdr
= fdr_ptr
;
1004 internal_ptr
->local
= true;
1005 internal_ptr
->native
= (PTR
) lraw_src
;
1009 ecoff_data (abfd
)->canonical_symbols
= internal
;
1014 /* Return the amount of space needed for the canonical symbols. */
1017 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1020 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1021 &ecoff_data (abfd
)->debug_info
))
1024 if (bfd_get_symcount (abfd
) == 0)
1027 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1030 /* Get the canonical symbols. */
1033 _bfd_ecoff_get_symtab (abfd
, alocation
)
1035 asymbol
**alocation
;
1037 unsigned int counter
= 0;
1038 ecoff_symbol_type
*symbase
;
1039 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1041 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1043 if (bfd_get_symcount (abfd
) == 0)
1046 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1047 while (counter
< bfd_get_symcount (abfd
))
1049 *(location
++) = symbase
++;
1052 *location
++ = (ecoff_symbol_type
*) NULL
;
1053 return bfd_get_symcount (abfd
);
1056 /* Turn ECOFF type information into a printable string.
1057 ecoff_emit_aggregate and ecoff_type_to_string are from
1058 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1060 /* Write aggregate information to a string. */
1063 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1071 const struct ecoff_debug_swap
* const debug_swap
=
1072 &ecoff_backend (abfd
)->debug_swap
;
1073 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1074 unsigned int ifd
= rndx
->rfd
;
1075 unsigned int indx
= rndx
->index
;
1081 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1082 struct return type of a procedure compiled without -g. */
1083 if (ifd
== 0xffffffff
1084 || (rndx
->rfd
== 0xfff && indx
== 0))
1085 name
= "<undefined>";
1086 else if (indx
== indexNil
)
1092 if (debug_info
->external_rfd
== NULL
)
1093 fdr
= debug_info
->fdr
+ ifd
;
1098 (*debug_swap
->swap_rfd_in
) (abfd
,
1099 ((char *) debug_info
->external_rfd
1100 + ((fdr
->rfdBase
+ ifd
)
1101 * debug_swap
->external_rfd_size
)),
1103 fdr
= debug_info
->fdr
+ rfd
;
1106 indx
+= fdr
->isymBase
;
1108 (*debug_swap
->swap_sym_in
) (abfd
,
1109 ((char *) debug_info
->external_sym
1110 + indx
* debug_swap
->external_sym_size
),
1113 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1117 "%s %s { ifd = %u, index = %lu }",
1120 + debug_info
->symbolic_header
.iextMax
));
1123 /* Convert the type information to string format. */
1126 ecoff_type_to_string (abfd
, fdr
, indx
)
1131 union aux_ext
*aux_ptr
;
1140 unsigned int basic_type
;
1143 static char buffer2
[1024];
1148 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1149 bigendian
= fdr
->fBigendian
;
1151 for (i
= 0; i
< 7; i
++)
1153 qualifiers
[i
].low_bound
= 0;
1154 qualifiers
[i
].high_bound
= 0;
1155 qualifiers
[i
].stride
= 0;
1158 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1159 return "-1 (no type)";
1160 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1162 basic_type
= u
.ti
.bt
;
1163 qualifiers
[0].type
= u
.ti
.tq0
;
1164 qualifiers
[1].type
= u
.ti
.tq1
;
1165 qualifiers
[2].type
= u
.ti
.tq2
;
1166 qualifiers
[3].type
= u
.ti
.tq3
;
1167 qualifiers
[4].type
= u
.ti
.tq4
;
1168 qualifiers
[5].type
= u
.ti
.tq5
;
1169 qualifiers
[6].type
= tqNil
;
1172 * Go get the basic type.
1176 case btNil
: /* undefined */
1180 case btAdr
: /* address - integer same size as pointer */
1181 strcpy (p1
, "address");
1184 case btChar
: /* character */
1185 strcpy (p1
, "char");
1188 case btUChar
: /* unsigned character */
1189 strcpy (p1
, "unsigned char");
1192 case btShort
: /* short */
1193 strcpy (p1
, "short");
1196 case btUShort
: /* unsigned short */
1197 strcpy (p1
, "unsigned short");
1200 case btInt
: /* int */
1204 case btUInt
: /* unsigned int */
1205 strcpy (p1
, "unsigned int");
1208 case btLong
: /* long */
1209 strcpy (p1
, "long");
1212 case btULong
: /* unsigned long */
1213 strcpy (p1
, "unsigned long");
1216 case btFloat
: /* float (real) */
1217 strcpy (p1
, "float");
1220 case btDouble
: /* Double (real) */
1221 strcpy (p1
, "double");
1224 /* Structures add 1-2 aux words:
1225 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1226 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1228 case btStruct
: /* Structure (Record) */
1229 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1230 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1231 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1233 indx
++; /* skip aux words */
1236 /* Unions add 1-2 aux words:
1237 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1238 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1240 case btUnion
: /* Union */
1241 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1242 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1243 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1245 indx
++; /* skip aux words */
1248 /* Enumerations add 1-2 aux words:
1249 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1250 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1252 case btEnum
: /* Enumeration */
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 case btTypedef
: /* defined via a typedef, isymRef points */
1261 strcpy (p1
, "typedef");
1264 case btRange
: /* subrange of int */
1265 strcpy (p1
, "subrange");
1268 case btSet
: /* pascal sets */
1272 case btComplex
: /* fortran complex */
1273 strcpy (p1
, "complex");
1276 case btDComplex
: /* fortran double complex */
1277 strcpy (p1
, "double complex");
1280 case btIndirect
: /* forward or unnamed typedef */
1281 strcpy (p1
, "forward/unamed typedef");
1284 case btFixedDec
: /* Fixed Decimal */
1285 strcpy (p1
, "fixed decimal");
1288 case btFloatDec
: /* Float Decimal */
1289 strcpy (p1
, "float decimal");
1292 case btString
: /* Varying Length Character String */
1293 strcpy (p1
, "string");
1296 case btBit
: /* Aligned Bit String */
1300 case btPicture
: /* Picture */
1301 strcpy (p1
, "picture");
1304 case btVoid
: /* Void */
1305 strcpy (p1
, "void");
1309 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1313 p1
+= strlen (buffer1
);
1316 * If this is a bitfield, get the bitsize.
1322 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1323 sprintf (p1
, " : %d", bitsize
);
1324 p1
+= strlen (buffer1
);
1329 * Deal with any qualifiers.
1331 if (qualifiers
[0].type
!= tqNil
)
1334 * Snarf up any array bounds in the correct order. Arrays
1335 * store 5 successive words in the aux. table:
1336 * word 0 RNDXR to type of the bounds (ie, int)
1337 * word 1 Current file descriptor index
1339 * word 3 high bound (or -1 if [])
1340 * word 4 stride size in bits
1342 for (i
= 0; i
< 7; i
++)
1344 if (qualifiers
[i
].type
== tqArray
)
1346 qualifiers
[i
].low_bound
=
1347 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1348 qualifiers
[i
].high_bound
=
1349 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1350 qualifiers
[i
].stride
=
1351 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1357 * Now print out the qualifiers.
1359 for (i
= 0; i
< 6; i
++)
1361 switch (qualifiers
[i
].type
)
1368 strcpy (p2
, "ptr to ");
1369 p2
+= sizeof ("ptr to ")-1;
1373 strcpy (p2
, "volatile ");
1374 p2
+= sizeof ("volatile ")-1;
1378 strcpy (p2
, "far ");
1379 p2
+= sizeof ("far ")-1;
1383 strcpy (p2
, "func. ret. ");
1384 p2
+= sizeof ("func. ret. ");
1389 int first_array
= i
;
1392 /* Print array bounds reversed (ie, in the order the C
1393 programmer writes them). C is such a fun language.... */
1395 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1398 for (j
= i
; j
>= first_array
; j
--)
1400 strcpy (p2
, "array [");
1401 p2
+= sizeof ("array [")-1;
1402 if (qualifiers
[j
].low_bound
!= 0)
1404 "%ld:%ld {%ld bits}",
1405 (long) qualifiers
[j
].low_bound
,
1406 (long) qualifiers
[j
].high_bound
,
1407 (long) qualifiers
[j
].stride
);
1409 else if (qualifiers
[j
].high_bound
!= -1)
1412 (long) (qualifiers
[j
].high_bound
+ 1),
1413 (long) (qualifiers
[j
].stride
));
1416 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1419 strcpy (p2
, "] of ");
1420 p2
+= sizeof ("] of ")-1;
1428 strcpy (p2
, buffer1
);
1432 /* Return information about ECOFF symbol SYMBOL in RET. */
1436 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1437 bfd
*abfd
; /* Ignored. */
1441 bfd_symbol_info (symbol
, ret
);
1444 /* Return whether this is a local label. */
1448 _bfd_ecoff_bfd_is_local_label (abfd
, symbol
)
1452 return symbol
->name
[0] == '$';
1455 /* Print information about an ECOFF symbol. */
1458 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1462 bfd_print_symbol_type how
;
1464 const struct ecoff_debug_swap
* const debug_swap
1465 = &ecoff_backend (abfd
)->debug_swap
;
1466 FILE *file
= (FILE *)filep
;
1470 case bfd_print_symbol_name
:
1471 fprintf (file
, "%s", symbol
->name
);
1473 case bfd_print_symbol_more
:
1474 if (ecoffsymbol (symbol
)->local
)
1478 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1480 fprintf (file
, "ecoff local ");
1481 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1482 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1483 (unsigned) ecoff_sym
.sc
);
1489 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1491 fprintf (file
, "ecoff extern ");
1492 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1493 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1494 (unsigned) ecoff_ext
.asym
.sc
);
1497 case bfd_print_symbol_all
:
1498 /* Print out the symbols in a reasonable way */
1507 if (ecoffsymbol (symbol
)->local
)
1509 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1512 pos
= ((((char *) ecoffsymbol (symbol
)->native
1513 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1514 / debug_swap
->external_sym_size
)
1515 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1522 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1525 pos
= (((char *) ecoffsymbol (symbol
)->native
1526 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1527 / debug_swap
->external_ext_size
);
1528 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1529 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1530 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1533 fprintf (file
, "[%3d] %c ",
1535 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1536 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1537 (unsigned) ecoff_ext
.asym
.st
,
1538 (unsigned) ecoff_ext
.asym
.sc
,
1539 (unsigned) ecoff_ext
.asym
.index
,
1540 jmptbl
, cobol_main
, weakext
,
1543 if (ecoffsymbol (symbol
)->fdr
!= NULL
1544 && ecoff_ext
.asym
.index
!= indexNil
)
1549 bfd_size_type sym_base
;
1550 union aux_ext
*aux_base
;
1552 fdr
= ecoffsymbol (symbol
)->fdr
;
1553 indx
= ecoff_ext
.asym
.index
;
1555 /* sym_base is used to map the fdr relative indices which
1556 appear in the file to the position number which we are
1558 sym_base
= fdr
->isymBase
;
1559 if (ecoffsymbol (symbol
)->local
)
1561 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1563 /* aux_base is the start of the aux entries for this file;
1564 asym.index is an offset from this. */
1565 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1568 /* The aux entries are stored in host byte order; the
1569 order is indicated by a bit in the fdr. */
1570 bigendian
= fdr
->fBigendian
;
1572 /* This switch is basically from gcc/mips-tdump.c */
1573 switch (ecoff_ext
.asym
.st
)
1581 fprintf (file
, "\n End+1 symbol: %ld",
1582 (long) (indx
+ sym_base
));
1586 if (ecoff_ext
.asym
.sc
== scText
1587 || ecoff_ext
.asym
.sc
== scInfo
)
1588 fprintf (file
, "\n First symbol: %ld",
1589 (long) (indx
+ sym_base
));
1591 fprintf (file
, "\n First symbol: %ld",
1593 (AUX_GET_ISYM (bigendian
,
1594 &aux_base
[ecoff_ext
.asym
.index
])
1600 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1602 else if (ecoffsymbol (symbol
)->local
)
1603 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1605 (AUX_GET_ISYM (bigendian
,
1606 &aux_base
[ecoff_ext
.asym
.index
])
1608 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1610 fprintf (file
, "\n Local symbol: %ld",
1613 + (ecoff_data (abfd
)
1614 ->debug_info
.symbolic_header
.iextMax
)));
1618 fprintf (file
, "\n struct; End+1 symbol: %ld",
1619 (long) (indx
+ sym_base
));
1623 fprintf (file
, "\n union; End+1 symbol: %ld",
1624 (long) (indx
+ sym_base
));
1628 fprintf (file
, "\n enum; End+1 symbol: %ld",
1629 (long) (indx
+ sym_base
));
1633 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1634 fprintf (file
, "\n Type: %s",
1635 ecoff_type_to_string (abfd
, fdr
, indx
));
1644 /* Read in the relocs for a section. */
1647 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1652 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1653 arelent
*internal_relocs
;
1654 bfd_size_type external_reloc_size
;
1655 bfd_size_type external_relocs_size
;
1656 char *external_relocs
;
1660 if (section
->relocation
!= (arelent
*) NULL
1661 || section
->reloc_count
== 0
1662 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1665 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1668 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1670 * section
->reloc_count
));
1671 external_reloc_size
= backend
->external_reloc_size
;
1672 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1673 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1674 if (internal_relocs
== (arelent
*) NULL
1675 || external_relocs
== (char *) NULL
)
1677 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1679 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1680 != external_relocs_size
)
1683 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1685 struct internal_reloc intern
;
1687 (*backend
->swap_reloc_in
) (abfd
,
1688 external_relocs
+ i
* external_reloc_size
,
1691 if (intern
.r_extern
)
1693 /* r_symndx is an index into the external symbols. */
1694 BFD_ASSERT (intern
.r_symndx
>= 0
1696 < (ecoff_data (abfd
)
1697 ->debug_info
.symbolic_header
.iextMax
)));
1698 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1701 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1702 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1704 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1709 CONST
char *sec_name
;
1712 /* r_symndx is a section key. */
1713 switch (intern
.r_symndx
)
1715 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1716 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1717 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1718 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1719 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1720 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1721 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1722 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1723 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1724 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1725 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1726 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1727 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1728 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1732 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1733 if (sec
== (asection
*) NULL
)
1735 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1737 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1740 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1742 /* Let the backend select the howto field and do any other
1743 required processing. */
1744 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1747 bfd_release (abfd
, external_relocs
);
1749 section
->relocation
= internal_relocs
;
1754 /* Get a canonical list of relocs. */
1757 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1765 if (section
->flags
& SEC_CONSTRUCTOR
)
1767 arelent_chain
*chain
;
1769 /* This section has relocs made up by us, not the file, so take
1770 them out of their chain and place them into the data area
1772 for (count
= 0, chain
= section
->constructor_chain
;
1773 count
< section
->reloc_count
;
1774 count
++, chain
= chain
->next
)
1775 *relptr
++ = &chain
->relent
;
1781 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1784 tblptr
= section
->relocation
;
1786 for (count
= 0; count
< section
->reloc_count
; count
++)
1787 *relptr
++ = tblptr
++;
1790 *relptr
= (arelent
*) NULL
;
1792 return section
->reloc_count
;
1795 /* Provided a BFD, a section and an offset into the section, calculate
1796 and return the name of the source file and the line nearest to the
1801 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1802 filename_ptr
, functionname_ptr
, retline_ptr
)
1805 asymbol
**ignore_symbols
;
1807 CONST
char **filename_ptr
;
1808 CONST
char **functionname_ptr
;
1809 unsigned int *retline_ptr
;
1811 const struct ecoff_debug_swap
* const debug_swap
1812 = &ecoff_backend (abfd
)->debug_swap
;
1813 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1814 struct ecoff_find_line
*line_info
;
1816 /* If we're not in the .text section, we don't have any line
1818 if (strcmp (section
->name
, _TEXT
) != 0
1819 || offset
>= bfd_section_size (abfd
, section
))
1822 /* Make sure we have the FDR's. */
1823 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1824 || bfd_get_symcount (abfd
) == 0)
1827 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1829 ecoff_data (abfd
)->find_line_info
=
1830 ((struct ecoff_find_line
*)
1831 bfd_alloc (abfd
, sizeof (struct ecoff_find_line
)));
1832 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1834 ecoff_data (abfd
)->find_line_info
->find_buffer
= NULL
;
1835 ecoff_data (abfd
)->find_line_info
->fdrtab_len
= 0;
1836 ecoff_data (abfd
)->find_line_info
->fdrtab
= NULL
;
1838 line_info
= ecoff_data (abfd
)->find_line_info
;
1840 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1841 debug_swap
, line_info
, filename_ptr
,
1842 functionname_ptr
, retline_ptr
);
1845 /* Copy private BFD data. This is called by objcopy and strip. We
1846 use it to copy the ECOFF debugging information from one BFD to the
1847 other. It would be theoretically possible to represent the ECOFF
1848 debugging information in the symbol table. However, it would be a
1849 lot of work, and there would be little gain (gas, gdb, and ld
1850 already access the ECOFF debugging information via the
1851 ecoff_debug_info structure, and that structure would have to be
1852 retained in order to support ECOFF debugging in MIPS ELF).
1854 The debugging information for the ECOFF external symbols comes from
1855 the symbol table, so this function only handles the other debugging
1859 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1863 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1864 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1866 asymbol
**sym_ptr_ptr
;
1870 /* This function is selected based on the input vector. We only
1871 want to copy information over if the output BFD also uses ECOFF
1873 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1876 /* Copy the GP value and the register masks. */
1877 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1878 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1879 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1880 for (i
= 0; i
< 3; i
++)
1881 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1883 /* Copy the version stamp. */
1884 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1886 /* If there are no symbols, don't copy any debugging information. */
1887 c
= bfd_get_symcount (obfd
);
1888 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1889 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1892 /* See if there are any local symbols. */
1894 for (; c
> 0; c
--, sym_ptr_ptr
++)
1896 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1905 /* There are some local symbols. We just bring over all the
1906 debugging information. FIXME: This is not quite the right
1907 thing to do. If the user has asked us to discard all
1908 debugging information, then we are probably going to wind up
1909 keeping it because there will probably be some local symbol
1910 which objcopy did not discard. We should actually break
1911 apart the debugging information and only keep that which
1912 applies to the symbols we want to keep. */
1913 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1914 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1915 oinfo
->line
= iinfo
->line
;
1917 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1918 oinfo
->external_dnr
= iinfo
->external_dnr
;
1920 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1921 oinfo
->external_pdr
= iinfo
->external_pdr
;
1923 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1924 oinfo
->external_sym
= iinfo
->external_sym
;
1926 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1927 oinfo
->external_opt
= iinfo
->external_opt
;
1929 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1930 oinfo
->external_aux
= iinfo
->external_aux
;
1932 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1933 oinfo
->ss
= iinfo
->ss
;
1935 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1936 oinfo
->external_fdr
= iinfo
->external_fdr
;
1938 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1939 oinfo
->external_rfd
= iinfo
->external_rfd
;
1943 /* We are discarding all the local symbol information. Look
1944 through the external symbols and remove all references to FDR
1945 or aux information. */
1946 c
= bfd_get_symcount (obfd
);
1947 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1948 for (; c
> 0; c
--, sym_ptr_ptr
++)
1952 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1953 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1955 esym
.asym
.index
= indexNil
;
1956 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1957 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1964 /* Set the architecture. The supported architecture is stored in the
1965 backend pointer. We always set the architecture anyhow, since many
1966 callers ignore the return value. */
1969 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1971 enum bfd_architecture arch
;
1972 unsigned long machine
;
1974 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1975 return arch
== ecoff_backend (abfd
)->arch
;
1978 /* Get the size of the section headers. */
1982 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
1991 for (current
= abfd
->sections
;
1992 current
!= (asection
*)NULL
;
1993 current
= current
->next
)
1996 ret
= (bfd_coff_filhsz (abfd
)
1997 + bfd_coff_aoutsz (abfd
)
1998 + c
* bfd_coff_scnhsz (abfd
));
1999 return BFD_ALIGN (ret
, 16);
2002 /* Get the contents of a section. */
2005 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2010 bfd_size_type count
;
2012 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2016 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2017 called via qsort. */
2020 ecoff_sort_hdrs (arg1
, arg2
)
2024 const asection
*hdr1
= *(const asection
**) arg1
;
2025 const asection
*hdr2
= *(const asection
**) arg2
;
2027 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2029 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2034 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2037 if (hdr1
->vma
< hdr2
->vma
)
2039 else if (hdr1
->vma
> hdr2
->vma
)
2045 /* Calculate the file position for each section, and set
2049 ecoff_compute_section_file_positions (abfd
)
2053 asection
**sorted_hdrs
;
2057 boolean first_data
, first_nonalloc
;
2058 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2060 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2062 /* Sort the sections by VMA. */
2063 sorted_hdrs
= (asection
**) bfd_malloc (abfd
->section_count
2064 * sizeof (asection
*));
2065 if (sorted_hdrs
== NULL
)
2067 for (current
= abfd
->sections
, i
= 0;
2069 current
= current
->next
, i
++)
2070 sorted_hdrs
[i
] = current
;
2071 BFD_ASSERT (i
== abfd
->section_count
);
2073 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2077 first_nonalloc
= true;
2078 for (i
= 0; i
< abfd
->section_count
; i
++)
2080 unsigned int alignment_power
;
2082 current
= sorted_hdrs
[i
];
2084 /* Only deal with sections which have contents */
2085 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2088 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2089 supposed to indicate the number of .pdata entries that are
2090 really in the section. Each entry is 8 bytes. We store this
2091 away in line_filepos before increasing the section size. */
2092 if (strcmp (current
->name
, _PDATA
) != 0)
2093 alignment_power
= current
->alignment_power
;
2096 current
->line_filepos
= current
->_raw_size
/ 8;
2097 alignment_power
= 4;
2100 /* On Ultrix, the data sections in an executable file must be
2101 aligned to a page boundary within the file. This does not
2102 affect the section size, though. FIXME: Does this work for
2103 other platforms? It requires some modification for the
2104 Alpha, because .rdata on the Alpha goes with the text, not
2106 if ((abfd
->flags
& EXEC_P
) != 0
2107 && (abfd
->flags
& D_PAGED
) != 0
2109 && (current
->flags
& SEC_CODE
) == 0
2110 && (! ecoff_backend (abfd
)->rdata_in_text
2111 || strcmp (current
->name
, _RDATA
) != 0)
2112 && strcmp (current
->name
, _PDATA
) != 0
2113 && strcmp (current
->name
, _RCONST
) != 0)
2115 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2118 else if (strcmp (current
->name
, _LIB
) == 0)
2120 /* On Irix 4, the location of contents of the .lib section
2121 from a shared library section is also rounded up to a
2124 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2126 else if (first_nonalloc
2127 && (current
->flags
& SEC_ALLOC
) == 0
2128 && (abfd
->flags
& D_PAGED
) != 0)
2130 /* Skip up to the next page for an unallocated section, such
2131 as the .comment section on the Alpha. This leaves room
2132 for the .bss section. */
2133 first_nonalloc
= false;
2134 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2137 /* Align the sections in the file to the same boundary on
2138 which they are aligned in virtual memory. */
2140 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2142 if ((abfd
->flags
& D_PAGED
) != 0
2143 && (current
->flags
& SEC_ALLOC
) != 0)
2144 sofar
+= (current
->vma
- sofar
) % round
;
2146 current
->filepos
= sofar
;
2148 sofar
+= current
->_raw_size
;
2150 /* make sure that this section is of the right size too */
2152 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2153 current
->_raw_size
+= sofar
- old_sofar
;
2159 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2164 /* Determine the location of the relocs for all the sections in the
2165 output file, as well as the location of the symbolic debugging
2168 static bfd_size_type
2169 ecoff_compute_reloc_file_positions (abfd
)
2172 const bfd_size_type external_reloc_size
=
2173 ecoff_backend (abfd
)->external_reloc_size
;
2174 file_ptr reloc_base
;
2175 bfd_size_type reloc_size
;
2179 if (! abfd
->output_has_begun
)
2181 if (! ecoff_compute_section_file_positions (abfd
))
2183 abfd
->output_has_begun
= true;
2186 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2189 for (current
= abfd
->sections
;
2190 current
!= (asection
*)NULL
;
2191 current
= current
->next
)
2193 if (current
->reloc_count
== 0)
2194 current
->rel_filepos
= 0;
2197 bfd_size_type relsize
;
2199 current
->rel_filepos
= reloc_base
;
2200 relsize
= current
->reloc_count
* external_reloc_size
;
2201 reloc_size
+= relsize
;
2202 reloc_base
+= relsize
;
2206 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2208 /* At least on Ultrix, the symbol table of an executable file must
2209 be aligned to a page boundary. FIXME: Is this true on other
2211 if ((abfd
->flags
& EXEC_P
) != 0
2212 && (abfd
->flags
& D_PAGED
) != 0)
2213 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2214 &~ (ecoff_backend (abfd
)->round
- 1));
2216 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2221 /* Set the contents of a section. */
2224 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2229 bfd_size_type count
;
2231 /* This must be done first, because bfd_set_section_contents is
2232 going to set output_has_begun to true. */
2233 if (abfd
->output_has_begun
== false)
2235 if (! ecoff_compute_section_file_positions (abfd
))
2239 /* If this is a .lib section, bump the vma address so that it winds
2240 up being the number of .lib sections output. This is right for
2241 Irix 4. Ian Taylor <ian@cygnus.com>. */
2242 if (strcmp (section
->name
, _LIB
) == 0)
2248 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2249 || bfd_write (location
, 1, count
, abfd
) != count
)
2255 /* Get the GP value for an ECOFF file. This is a hook used by
2259 bfd_ecoff_get_gp_value (abfd
)
2262 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2263 || bfd_get_format (abfd
) != bfd_object
)
2265 bfd_set_error (bfd_error_invalid_operation
);
2269 return ecoff_data (abfd
)->gp
;
2272 /* Set the GP value for an ECOFF file. This is a hook used by the
2276 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2280 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2281 || bfd_get_format (abfd
) != bfd_object
)
2283 bfd_set_error (bfd_error_invalid_operation
);
2287 ecoff_data (abfd
)->gp
= gp_value
;
2292 /* Set the register masks for an ECOFF file. This is a hook used by
2296 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2298 unsigned long gprmask
;
2299 unsigned long fprmask
;
2300 unsigned long *cprmask
;
2302 ecoff_data_type
*tdata
;
2304 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2305 || bfd_get_format (abfd
) != bfd_object
)
2307 bfd_set_error (bfd_error_invalid_operation
);
2311 tdata
= ecoff_data (abfd
);
2312 tdata
->gprmask
= gprmask
;
2313 tdata
->fprmask
= fprmask
;
2314 if (cprmask
!= (unsigned long *) NULL
)
2318 for (i
= 0; i
< 3; i
++)
2319 tdata
->cprmask
[i
] = cprmask
[i
];
2325 /* Get ECOFF EXTR information for an external symbol. This function
2326 is passed to bfd_ecoff_debug_externals. */
2329 ecoff_get_extr (sym
, esym
)
2333 ecoff_symbol_type
*ecoff_sym_ptr
;
2336 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2337 || ecoffsymbol (sym
)->native
== NULL
)
2339 /* Don't include debugging, local, or section symbols. */
2340 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2341 || (sym
->flags
& BSF_LOCAL
) != 0
2342 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2346 esym
->cobol_main
= 0;
2347 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2350 /* FIXME: we can do better than this for st and sc. */
2351 esym
->asym
.st
= stGlobal
;
2352 esym
->asym
.sc
= scAbs
;
2353 esym
->asym
.reserved
= 0;
2354 esym
->asym
.index
= indexNil
;
2358 ecoff_sym_ptr
= ecoffsymbol (sym
);
2360 if (ecoff_sym_ptr
->local
)
2363 input_bfd
= bfd_asymbol_bfd (sym
);
2364 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2365 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2367 /* If the symbol was defined by the linker, then esym will be
2368 undefined but sym will not be. Get a better class for such a
2370 if ((esym
->asym
.sc
== scUndefined
2371 || esym
->asym
.sc
== scSUndefined
)
2372 && ! bfd_is_und_section (bfd_get_section (sym
)))
2373 esym
->asym
.sc
= scAbs
;
2375 /* Adjust the FDR index for the symbol by that used for the input
2377 if (esym
->ifd
!= -1)
2379 struct ecoff_debug_info
*input_debug
;
2381 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2382 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2383 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2384 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2390 /* Set the external symbol index. This routine is passed to
2391 bfd_ecoff_debug_externals. */
2394 ecoff_set_index (sym
, indx
)
2398 ecoff_set_sym_index (sym
, indx
);
2401 /* Write out an ECOFF file. */
2404 _bfd_ecoff_write_object_contents (abfd
)
2407 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2408 const bfd_vma round
= backend
->round
;
2409 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2410 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2411 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2412 const bfd_size_type external_hdr_size
2413 = backend
->debug_swap
.external_hdr_size
;
2414 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2415 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2417 struct internal_reloc
*))
2418 = backend
->adjust_reloc_out
;
2419 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2420 const struct internal_reloc
*,
2422 = backend
->swap_reloc_out
;
2423 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2424 HDRR
* const symhdr
= &debug
->symbolic_header
;
2427 bfd_size_type reloc_size
;
2428 bfd_size_type text_size
;
2430 boolean set_text_start
;
2431 bfd_size_type data_size
;
2433 boolean set_data_start
;
2434 bfd_size_type bss_size
;
2436 PTR reloc_buff
= NULL
;
2437 struct internal_filehdr internal_f
;
2438 struct internal_aouthdr internal_a
;
2441 /* Determine where the sections and relocs will go in the output
2443 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2446 for (current
= abfd
->sections
;
2447 current
!= (asection
*)NULL
;
2448 current
= current
->next
)
2450 current
->target_index
= count
;
2454 if ((abfd
->flags
& D_PAGED
) != 0)
2455 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2459 set_text_start
= false;
2462 set_data_start
= false;
2465 /* Write section headers to the file. */
2467 /* Allocate buff big enough to hold a section header,
2468 file header, or a.out header. */
2476 buff
= (PTR
) bfd_malloc ((size_t) siz
);
2481 internal_f
.f_nscns
= 0;
2482 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2484 for (current
= abfd
->sections
;
2485 current
!= (asection
*) NULL
;
2486 current
= current
->next
)
2488 struct internal_scnhdr section
;
2491 ++internal_f
.f_nscns
;
2493 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2495 /* This seems to be correct for Irix 4 shared libraries. */
2496 vma
= bfd_get_section_vma (abfd
, current
);
2497 if (strcmp (current
->name
, _LIB
) == 0)
2498 section
.s_vaddr
= 0;
2500 section
.s_vaddr
= vma
;
2502 section
.s_paddr
= vma
;
2503 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2505 /* If this section is unloadable then the scnptr will be 0. */
2506 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2507 section
.s_scnptr
= 0;
2509 section
.s_scnptr
= current
->filepos
;
2510 section
.s_relptr
= current
->rel_filepos
;
2512 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2513 object file produced by the assembler is supposed to point to
2514 information about how much room is required by objects of
2515 various different sizes. I think this only matters if we
2516 want the linker to compute the best size to use, or
2517 something. I don't know what happens if the information is
2519 if (strcmp (current
->name
, _PDATA
) != 0)
2520 section
.s_lnnoptr
= 0;
2523 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2524 hold the number of entries in the section (each entry is
2525 8 bytes). We stored this in the line_filepos field in
2526 ecoff_compute_section_file_positions. */
2527 section
.s_lnnoptr
= current
->line_filepos
;
2530 section
.s_nreloc
= current
->reloc_count
;
2531 section
.s_nlnno
= 0;
2532 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2535 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2536 || bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2539 if ((section
.s_flags
& STYP_TEXT
) != 0
2540 || ((section
.s_flags
& STYP_RDATA
) != 0
2541 && backend
->rdata_in_text
)
2542 || section
.s_flags
== STYP_PDATA
2543 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2544 || (section
.s_flags
& STYP_LIBLIST
) != 0
2545 || (section
.s_flags
& STYP_RELDYN
) != 0
2546 || section
.s_flags
== STYP_CONFLIC
2547 || (section
.s_flags
& STYP_DYNSTR
) != 0
2548 || (section
.s_flags
& STYP_DYNSYM
) != 0
2549 || (section
.s_flags
& STYP_HASH
) != 0
2550 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2551 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2552 || section
.s_flags
== STYP_RCONST
)
2554 text_size
+= bfd_get_section_size_before_reloc (current
);
2555 if (! set_text_start
|| text_start
> vma
)
2558 set_text_start
= true;
2561 else if ((section
.s_flags
& STYP_RDATA
) != 0
2562 || (section
.s_flags
& STYP_DATA
) != 0
2563 || (section
.s_flags
& STYP_LITA
) != 0
2564 || (section
.s_flags
& STYP_LIT8
) != 0
2565 || (section
.s_flags
& STYP_LIT4
) != 0
2566 || (section
.s_flags
& STYP_SDATA
) != 0
2567 || section
.s_flags
== STYP_XDATA
2568 || (section
.s_flags
& STYP_GOT
) != 0)
2570 data_size
+= bfd_get_section_size_before_reloc (current
);
2571 if (! set_data_start
|| data_start
> vma
)
2574 set_data_start
= true;
2577 else if ((section
.s_flags
& STYP_BSS
) != 0
2578 || (section
.s_flags
& STYP_SBSS
) != 0)
2579 bss_size
+= bfd_get_section_size_before_reloc (current
);
2580 else if (section
.s_flags
== 0
2581 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2582 || section
.s_flags
== STYP_COMMENT
)
2588 /* Set up the file header. */
2590 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2592 /* We will NOT put a fucking timestamp in the header here. Every
2593 time you put it back, I will come in and take it out again. I'm
2594 sorry. This field does not belong here. We fill it with a 0 so
2595 it compares the same but is not a reasonable time. --
2597 internal_f
.f_timdat
= 0;
2599 if (bfd_get_symcount (abfd
) != 0)
2601 /* The ECOFF f_nsyms field is not actually the number of
2602 symbols, it's the size of symbolic information header. */
2603 internal_f
.f_nsyms
= external_hdr_size
;
2604 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2608 internal_f
.f_nsyms
= 0;
2609 internal_f
.f_symptr
= 0;
2612 internal_f
.f_opthdr
= aoutsz
;
2614 internal_f
.f_flags
= F_LNNO
;
2615 if (reloc_size
== 0)
2616 internal_f
.f_flags
|= F_RELFLG
;
2617 if (bfd_get_symcount (abfd
) == 0)
2618 internal_f
.f_flags
|= F_LSYMS
;
2619 if (abfd
->flags
& EXEC_P
)
2620 internal_f
.f_flags
|= F_EXEC
;
2622 if (! abfd
->xvec
->byteorder_big_p
)
2623 internal_f
.f_flags
|= F_AR32WR
;
2625 internal_f
.f_flags
|= F_AR32W
;
2627 /* Set up the ``optional'' header. */
2628 if ((abfd
->flags
& D_PAGED
) != 0)
2629 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2631 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2633 /* FIXME: Is this really correct? */
2634 internal_a
.vstamp
= symhdr
->vstamp
;
2636 /* At least on Ultrix, these have to be rounded to page boundaries.
2637 FIXME: Is this true on other platforms? */
2638 if ((abfd
->flags
& D_PAGED
) != 0)
2640 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2641 internal_a
.text_start
= text_start
&~ (round
- 1);
2642 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2643 internal_a
.data_start
= data_start
&~ (round
- 1);
2647 internal_a
.tsize
= text_size
;
2648 internal_a
.text_start
= text_start
;
2649 internal_a
.dsize
= data_size
;
2650 internal_a
.data_start
= data_start
;
2653 /* On Ultrix, the initial portions of the .sbss and .bss segments
2654 are at the end of the data section. The bsize field in the
2655 optional header records how many bss bytes are required beyond
2656 those in the data section. The value is not rounded to a page
2658 if (bss_size
< internal_a
.dsize
- data_size
)
2661 bss_size
-= internal_a
.dsize
- data_size
;
2662 internal_a
.bsize
= bss_size
;
2663 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2665 internal_a
.entry
= bfd_get_start_address (abfd
);
2667 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2669 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2670 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2671 for (i
= 0; i
< 4; i
++)
2672 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2674 /* Let the backend adjust the headers if necessary. */
2675 if (backend
->adjust_headers
)
2677 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2681 /* Write out the file header and the optional header. */
2683 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2686 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2687 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2690 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2691 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2694 /* Build the external symbol information. This must be done before
2695 writing out the relocs so that we know the symbol indices. We
2696 don't do this if this BFD was created by the backend linker,
2697 since it will have already handled the symbols and relocs. */
2698 if (! ecoff_data (abfd
)->linker
)
2700 symhdr
->iextMax
= 0;
2701 symhdr
->issExtMax
= 0;
2702 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2703 debug
->ssext
= debug
->ssext_end
= NULL
;
2704 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2705 (((abfd
->flags
& EXEC_P
) == 0)
2707 ecoff_get_extr
, ecoff_set_index
)
2711 /* Write out the relocs. */
2712 for (current
= abfd
->sections
;
2713 current
!= (asection
*) NULL
;
2714 current
= current
->next
)
2716 arelent
**reloc_ptr_ptr
;
2717 arelent
**reloc_end
;
2720 if (current
->reloc_count
== 0)
2724 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2725 if (reloc_buff
== NULL
)
2728 reloc_ptr_ptr
= current
->orelocation
;
2729 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2730 out_ptr
= (char *) reloc_buff
;
2732 reloc_ptr_ptr
< reloc_end
;
2733 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2737 struct internal_reloc in
;
2739 memset ((PTR
) &in
, 0, sizeof in
);
2741 reloc
= *reloc_ptr_ptr
;
2742 sym
= *reloc
->sym_ptr_ptr
;
2744 in
.r_vaddr
= (reloc
->address
2745 + bfd_get_section_vma (abfd
, current
));
2746 in
.r_type
= reloc
->howto
->type
;
2748 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2750 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2757 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2758 if (strcmp (name
, ".text") == 0)
2759 in
.r_symndx
= RELOC_SECTION_TEXT
;
2760 else if (strcmp (name
, ".rdata") == 0)
2761 in
.r_symndx
= RELOC_SECTION_RDATA
;
2762 else if (strcmp (name
, ".data") == 0)
2763 in
.r_symndx
= RELOC_SECTION_DATA
;
2764 else if (strcmp (name
, ".sdata") == 0)
2765 in
.r_symndx
= RELOC_SECTION_SDATA
;
2766 else if (strcmp (name
, ".sbss") == 0)
2767 in
.r_symndx
= RELOC_SECTION_SBSS
;
2768 else if (strcmp (name
, ".bss") == 0)
2769 in
.r_symndx
= RELOC_SECTION_BSS
;
2770 else if (strcmp (name
, ".init") == 0)
2771 in
.r_symndx
= RELOC_SECTION_INIT
;
2772 else if (strcmp (name
, ".lit8") == 0)
2773 in
.r_symndx
= RELOC_SECTION_LIT8
;
2774 else if (strcmp (name
, ".lit4") == 0)
2775 in
.r_symndx
= RELOC_SECTION_LIT4
;
2776 else if (strcmp (name
, ".xdata") == 0)
2777 in
.r_symndx
= RELOC_SECTION_XDATA
;
2778 else if (strcmp (name
, ".pdata") == 0)
2779 in
.r_symndx
= RELOC_SECTION_PDATA
;
2780 else if (strcmp (name
, ".fini") == 0)
2781 in
.r_symndx
= RELOC_SECTION_FINI
;
2782 else if (strcmp (name
, ".lita") == 0)
2783 in
.r_symndx
= RELOC_SECTION_LITA
;
2784 else if (strcmp (name
, "*ABS*") == 0)
2785 in
.r_symndx
= RELOC_SECTION_ABS
;
2786 else if (strcmp (name
, ".rconst") == 0)
2787 in
.r_symndx
= RELOC_SECTION_RCONST
;
2793 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2795 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2798 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2800 if (bfd_write (reloc_buff
,
2801 external_reloc_size
, current
->reloc_count
, abfd
)
2802 != external_reloc_size
* current
->reloc_count
)
2804 bfd_release (abfd
, reloc_buff
);
2808 /* Write out the symbolic debugging information. */
2809 if (bfd_get_symcount (abfd
) > 0)
2811 /* Write out the debugging information. */
2812 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2813 ecoff_data (abfd
)->sym_filepos
)
2819 /* The .bss section of a demand paged executable must receive an
2820 entire page. If there are symbols, the symbols will start on the
2821 next page. If there are no symbols, we must fill out the page by
2823 if (bfd_get_symcount (abfd
) == 0
2824 && (abfd
->flags
& EXEC_P
) != 0
2825 && (abfd
->flags
& D_PAGED
) != 0)
2829 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2832 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2834 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2837 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2841 if (reloc_buff
!= NULL
)
2842 bfd_release (abfd
, reloc_buff
);
2847 if (reloc_buff
!= NULL
)
2848 bfd_release (abfd
, reloc_buff
);
2854 /* Archive handling. ECOFF uses what appears to be a unique type of
2855 archive header (armap). The byte ordering of the armap and the
2856 contents are encoded in the name of the armap itself. At least for
2857 now, we only support archives with the same byte ordering in the
2858 armap and the contents.
2860 The first four bytes in the armap are the number of symbol
2861 definitions. This is always a power of two.
2863 This is followed by the symbol definitions. Each symbol definition
2864 occupies 8 bytes. The first four bytes are the offset from the
2865 start of the armap strings to the null-terminated string naming
2866 this symbol. The second four bytes are the file offset to the
2867 archive member which defines this symbol. If the second four bytes
2868 are 0, then this is not actually a symbol definition, and it should
2871 The symbols are hashed into the armap with a closed hashing scheme.
2872 See the functions below for the details of the algorithm.
2874 After the symbol definitions comes four bytes holding the size of
2875 the string table, followed by the string table itself. */
2877 /* The name of an archive headers looks like this:
2878 __________E[BL]E[BL]_ (with a trailing space).
2879 The trailing space is changed to an X if the archive is changed to
2880 indicate that the armap is out of date.
2882 The Alpha seems to use ________64E[BL]E[BL]_. */
2884 #define ARMAP_BIG_ENDIAN 'B'
2885 #define ARMAP_LITTLE_ENDIAN 'L'
2886 #define ARMAP_MARKER 'E'
2887 #define ARMAP_START_LENGTH 10
2888 #define ARMAP_HEADER_MARKER_INDEX 10
2889 #define ARMAP_HEADER_ENDIAN_INDEX 11
2890 #define ARMAP_OBJECT_MARKER_INDEX 12
2891 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2892 #define ARMAP_END_INDEX 14
2893 #define ARMAP_END "_ "
2895 /* This is a magic number used in the hashing algorithm. */
2896 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2898 /* This returns the hash value to use for a string. It also sets
2899 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2900 is the number of entries in the hash table, and HLOG is the log
2904 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2906 unsigned int *rehash
;
2914 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2915 hash
*= ARMAP_HASH_MAGIC
;
2916 *rehash
= (hash
& (size
- 1)) | 1;
2917 return hash
>> (32 - hlog
);
2920 /* Read in the armap. */
2923 _bfd_ecoff_slurp_armap (abfd
)
2928 struct areltdata
*mapdata
;
2929 bfd_size_type parsed_size
;
2931 struct artdata
*ardata
;
2934 struct symdef
*symdef_ptr
;
2937 /* Get the name of the first element. */
2938 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2944 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2947 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2948 standard COFF armap. We could move the ECOFF armap stuff into
2949 bfd_slurp_armap, but that seems inappropriate since no other
2950 target uses this format. Instead, we check directly for a COFF
2952 if (strncmp (nextname
, "/ ", 16) == 0)
2953 return bfd_slurp_armap (abfd
);
2955 /* See if the first element is an armap. */
2956 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2957 ARMAP_START_LENGTH
) != 0
2958 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2959 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2960 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2961 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2962 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2963 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2964 || strncmp (nextname
+ ARMAP_END_INDEX
,
2965 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2967 bfd_has_map (abfd
) = false;
2971 /* Make sure we have the right byte ordering. */
2972 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2973 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2974 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2975 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2977 bfd_set_error (bfd_error_wrong_format
);
2981 /* Read in the armap. */
2982 ardata
= bfd_ardata (abfd
);
2983 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
2984 if (mapdata
== (struct areltdata
*) NULL
)
2986 parsed_size
= mapdata
->parsed_size
;
2987 bfd_release (abfd
, (PTR
) mapdata
);
2989 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2990 if (raw_armap
== (char *) NULL
)
2993 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
2995 if (bfd_get_error () != bfd_error_system_call
)
2996 bfd_set_error (bfd_error_malformed_archive
);
2997 bfd_release (abfd
, (PTR
) raw_armap
);
3001 ardata
->tdata
= (PTR
) raw_armap
;
3003 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3005 ardata
->symdef_count
= 0;
3006 ardata
->cache
= (struct ar_cache
*) NULL
;
3008 /* This code used to overlay the symdefs over the raw archive data,
3009 but that doesn't work on a 64 bit host. */
3011 stringbase
= raw_armap
+ count
* 8 + 8;
3013 #ifdef CHECK_ARMAP_HASH
3017 /* Double check that I have the hashing algorithm right by making
3018 sure that every symbol can be looked up successfully. */
3020 for (i
= 1; i
< count
; i
<<= 1)
3022 BFD_ASSERT (i
== count
);
3024 raw_ptr
= raw_armap
+ 4;
3025 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3027 unsigned int name_offset
, file_offset
;
3028 unsigned int hash
, rehash
, srch
;
3030 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3031 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3032 if (file_offset
== 0)
3034 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3039 /* See if we can rehash to this location. */
3040 for (srch
= (hash
+ rehash
) & (count
- 1);
3041 srch
!= hash
&& srch
!= i
;
3042 srch
= (srch
+ rehash
) & (count
- 1))
3043 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3045 BFD_ASSERT (srch
== i
);
3049 #endif /* CHECK_ARMAP_HASH */
3051 raw_ptr
= raw_armap
+ 4;
3052 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3053 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3054 ++ardata
->symdef_count
;
3056 symdef_ptr
= ((struct symdef
*)
3058 ardata
->symdef_count
* sizeof (struct symdef
)));
3062 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3064 raw_ptr
= raw_armap
+ 4;
3065 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3067 unsigned int name_offset
, file_offset
;
3069 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3070 if (file_offset
== 0)
3072 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3073 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3074 symdef_ptr
->file_offset
= file_offset
;
3078 ardata
->first_file_filepos
= bfd_tell (abfd
);
3079 /* Pad to an even boundary. */
3080 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3082 bfd_has_map (abfd
) = true;
3087 /* Write out an armap. */
3090 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3092 unsigned int elength
;
3094 unsigned int orl_count
;
3097 unsigned int hashsize
, hashlog
;
3098 unsigned int symdefsize
;
3100 unsigned int stringsize
;
3101 unsigned int mapsize
;
3104 struct stat statbuf
;
3107 bfd_byte
*hashtable
;
3111 /* Ultrix appears to use as a hash table size the least power of two
3112 greater than twice the number of entries. */
3113 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3115 hashsize
= 1 << hashlog
;
3117 symdefsize
= hashsize
* 8;
3119 stringsize
= stridx
+ padit
;
3121 /* Include 8 bytes to store symdefsize and stringsize in output. */
3122 mapsize
= symdefsize
+ stringsize
+ 8;
3124 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3126 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3128 /* Work out the ECOFF armap name. */
3129 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3130 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3131 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3132 (abfd
->xvec
->header_byteorder_big_p
3134 : ARMAP_LITTLE_ENDIAN
);
3135 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3136 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3137 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3138 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3140 /* Write the timestamp of the archive header to be just a little bit
3141 later than the timestamp of the file, otherwise the linker will
3142 complain that the index is out of date. Actually, the Ultrix
3143 linker just checks the archive name; the GNU linker may check the
3145 stat (abfd
->filename
, &statbuf
);
3146 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3148 /* The DECstation uses zeroes for the uid, gid and mode of the
3150 hdr
.ar_uid
[0] = '0';
3151 hdr
.ar_gid
[0] = '0';
3152 hdr
.ar_mode
[0] = '0';
3154 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3156 hdr
.ar_fmag
[0] = '`';
3157 hdr
.ar_fmag
[1] = '\012';
3159 /* Turn all null bytes in the header into spaces. */
3160 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3161 if (((char *)(&hdr
))[i
] == '\0')
3162 (((char *)(&hdr
))[i
]) = ' ';
3164 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3165 != sizeof (struct ar_hdr
))
3168 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3169 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3172 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3176 current
= abfd
->archive_head
;
3178 for (i
= 0; i
< orl_count
; i
++)
3180 unsigned int hash
, rehash
;
3182 /* Advance firstreal to the file position of this archive
3184 if (((bfd
*) map
[i
].pos
) != last_elt
)
3188 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3189 firstreal
+= firstreal
% 2;
3190 current
= current
->next
;
3192 while (current
!= (bfd
*) map
[i
].pos
);
3197 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3198 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3202 /* The desired slot is already taken. */
3203 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3205 srch
= (srch
+ rehash
) & (hashsize
- 1))
3206 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3209 BFD_ASSERT (srch
!= hash
);
3214 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3215 (PTR
) (hashtable
+ hash
* 8));
3216 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3217 (PTR
) (hashtable
+ hash
* 8 + 4));
3220 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3223 bfd_release (abfd
, hashtable
);
3225 /* Now write the strings. */
3226 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3227 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3229 for (i
= 0; i
< orl_count
; i
++)
3233 len
= strlen (*map
[i
].name
) + 1;
3234 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3238 /* The spec sez this should be a newline. But in order to be
3239 bug-compatible for DECstation ar we use a null. */
3242 if (bfd_write ("", 1, 1, abfd
) != 1)
3249 /* See whether this BFD is an archive. If it is, read in the armap
3250 and the extended name table. */
3253 _bfd_ecoff_archive_p (abfd
)
3256 char armag
[SARMAG
+ 1];
3258 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3259 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3261 if (bfd_get_error () != bfd_error_system_call
)
3262 bfd_set_error (bfd_error_wrong_format
);
3263 return (const bfd_target
*) NULL
;
3266 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3267 involves a cast, we can't do it as the left operand of
3269 abfd
->tdata
.aout_ar_data
=
3270 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3272 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3273 return (const bfd_target
*) NULL
;
3275 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3276 bfd_ardata (abfd
)->cache
= NULL
;
3277 bfd_ardata (abfd
)->archive_head
= NULL
;
3278 bfd_ardata (abfd
)->symdefs
= NULL
;
3279 bfd_ardata (abfd
)->extended_names
= NULL
;
3280 bfd_ardata (abfd
)->tdata
= NULL
;
3282 if (_bfd_ecoff_slurp_armap (abfd
) == false
3283 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3285 bfd_release (abfd
, bfd_ardata (abfd
));
3286 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3287 return (const bfd_target
*) NULL
;
3293 /* ECOFF linker code. */
3295 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3296 PARAMS ((struct bfd_hash_entry
*entry
,
3297 struct bfd_hash_table
*table
,
3298 const char *string
));
3299 static boolean ecoff_link_add_archive_symbols
3300 PARAMS ((bfd
*, struct bfd_link_info
*));
3301 static boolean ecoff_link_check_archive_element
3302 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3303 static boolean ecoff_link_add_object_symbols
3304 PARAMS ((bfd
*, struct bfd_link_info
*));
3305 static boolean ecoff_link_add_externals
3306 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3308 /* Routine to create an entry in an ECOFF link hash table. */
3310 static struct bfd_hash_entry
*
3311 ecoff_link_hash_newfunc (entry
, table
, string
)
3312 struct bfd_hash_entry
*entry
;
3313 struct bfd_hash_table
*table
;
3316 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3318 /* Allocate the structure if it has not already been allocated by a
3320 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3321 ret
= ((struct ecoff_link_hash_entry
*)
3322 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3323 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3326 /* Call the allocation method of the superclass. */
3327 ret
= ((struct ecoff_link_hash_entry
*)
3328 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3333 /* Set local fields. */
3339 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3341 return (struct bfd_hash_entry
*) ret
;
3344 /* Create an ECOFF link hash table. */
3346 struct bfd_link_hash_table
*
3347 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3350 struct ecoff_link_hash_table
*ret
;
3352 ret
= ((struct ecoff_link_hash_table
*)
3353 bfd_alloc (abfd
, sizeof (struct ecoff_link_hash_table
)));
3356 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3357 ecoff_link_hash_newfunc
))
3360 return (struct bfd_link_hash_table
*) NULL
;
3365 /* Look up an entry in an ECOFF link hash table. */
3367 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3368 ((struct ecoff_link_hash_entry *) \
3369 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3371 /* Traverse an ECOFF link hash table. */
3373 #define ecoff_link_hash_traverse(table, func, info) \
3374 (bfd_link_hash_traverse \
3376 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3379 /* Get the ECOFF link hash table from the info structure. This is
3382 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3384 /* Given an ECOFF BFD, add symbols to the global hash table as
3388 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3390 struct bfd_link_info
*info
;
3392 switch (bfd_get_format (abfd
))
3395 return ecoff_link_add_object_symbols (abfd
, info
);
3397 return ecoff_link_add_archive_symbols (abfd
, info
);
3399 bfd_set_error (bfd_error_wrong_format
);
3404 /* Add the symbols from an archive file to the global hash table.
3405 This looks through the undefined symbols, looks each one up in the
3406 archive hash table, and adds any associated object file. We do not
3407 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3408 already have a hash table, so there is no reason to construct
3412 ecoff_link_add_archive_symbols (abfd
, info
)
3414 struct bfd_link_info
*info
;
3416 const bfd_byte
*raw_armap
;
3417 struct bfd_link_hash_entry
**pundef
;
3418 unsigned int armap_count
;
3419 unsigned int armap_log
;
3421 const bfd_byte
*hashtable
;
3422 const char *stringbase
;
3424 if (! bfd_has_map (abfd
))
3426 /* An empty archive is a special case. */
3427 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3429 bfd_set_error (bfd_error_no_armap
);
3433 /* If we don't have any raw data for this archive, as can happen on
3434 Irix 4.0.5F, we call the generic routine.
3435 FIXME: We should be more clever about this, since someday tdata
3436 may get to something for a generic archive. */
3437 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3438 if (raw_armap
== (bfd_byte
*) NULL
)
3439 return (_bfd_generic_link_add_archive_symbols
3440 (abfd
, info
, ecoff_link_check_archive_element
));
3442 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3445 for (i
= 1; i
< armap_count
; i
<<= 1)
3447 BFD_ASSERT (i
== armap_count
);
3449 hashtable
= raw_armap
+ 4;
3450 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3452 /* Look through the list of undefined symbols. */
3453 pundef
= &info
->hash
->undefs
;
3454 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3456 struct bfd_link_hash_entry
*h
;
3457 unsigned int hash
, rehash
;
3458 unsigned int file_offset
;
3464 /* When a symbol is defined, it is not necessarily removed from
3466 if (h
->type
!= bfd_link_hash_undefined
3467 && h
->type
!= bfd_link_hash_common
)
3469 /* Remove this entry from the list, for general cleanliness
3470 and because we are going to look through the list again
3471 if we search any more libraries. We can't remove the
3472 entry if it is the tail, because that would lose any
3473 entries we add to the list later on. */
3474 if (*pundef
!= info
->hash
->undefs_tail
)
3475 *pundef
= (*pundef
)->next
;
3477 pundef
= &(*pundef
)->next
;
3481 /* Native ECOFF linkers do not pull in archive elements merely
3482 to satisfy common definitions, so neither do we. We leave
3483 them on the list, though, in case we are linking against some
3484 other object format. */
3485 if (h
->type
!= bfd_link_hash_undefined
)
3487 pundef
= &(*pundef
)->next
;
3491 /* Look for this symbol in the archive hash table. */
3492 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3495 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3496 if (file_offset
== 0)
3498 /* Nothing in this slot. */
3499 pundef
= &(*pundef
)->next
;
3503 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3504 if (name
[0] != h
->root
.string
[0]
3505 || strcmp (name
, h
->root
.string
) != 0)
3510 /* That was the wrong symbol. Try rehashing. */
3512 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3514 srch
= (srch
+ rehash
) & (armap_count
- 1))
3516 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3517 if (file_offset
== 0)
3519 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3520 if (name
[0] == h
->root
.string
[0]
3521 && strcmp (name
, h
->root
.string
) == 0)
3530 pundef
= &(*pundef
)->next
;
3537 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3538 if (element
== (bfd
*) NULL
)
3541 if (! bfd_check_format (element
, bfd_object
))
3544 /* Unlike the generic linker, we know that this element provides
3545 a definition for an undefined symbol and we know that we want
3546 to include it. We don't need to check anything. */
3547 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3549 if (! ecoff_link_add_object_symbols (element
, info
))
3552 pundef
= &(*pundef
)->next
;
3558 /* This is called if we used _bfd_generic_link_add_archive_symbols
3559 because we were not dealing with an ECOFF archive. */
3562 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3564 struct bfd_link_info
*info
;
3567 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3568 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3569 = backend
->debug_swap
.swap_ext_in
;
3571 bfd_size_type external_ext_size
;
3572 PTR external_ext
= NULL
;
3580 if (! ecoff_slurp_symbolic_header (abfd
))
3583 /* If there are no symbols, we don't want it. */
3584 if (bfd_get_symcount (abfd
) == 0)
3585 goto successful_return
;
3587 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3589 /* Read in the external symbols and external strings. */
3590 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3591 esize
= symhdr
->iextMax
* external_ext_size
;
3592 external_ext
= (PTR
) bfd_malloc (esize
);
3593 if (external_ext
== NULL
&& esize
!= 0)
3596 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3597 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3600 ssext
= (char *) bfd_malloc (symhdr
->issExtMax
);
3601 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3604 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3605 || (bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) !=
3606 (bfd_size_type
) symhdr
->issExtMax
))
3609 /* Look through the external symbols to see if they define some
3610 symbol that is currently undefined. */
3611 ext_ptr
= (char *) external_ext
;
3612 ext_end
= ext_ptr
+ esize
;
3613 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3618 struct bfd_link_hash_entry
*h
;
3620 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3622 /* See if this symbol defines something. */
3623 if (esym
.asym
.st
!= stGlobal
3624 && esym
.asym
.st
!= stLabel
3625 && esym
.asym
.st
!= stProc
)
3628 switch (esym
.asym
.sc
)
3652 name
= ssext
+ esym
.asym
.iss
;
3653 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3655 /* Unlike the generic linker, we do not pull in elements because
3656 of common symbols. */
3657 if (h
== (struct bfd_link_hash_entry
*) NULL
3658 || h
->type
!= bfd_link_hash_undefined
)
3661 /* Include this element. */
3662 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3664 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3668 goto successful_return
;
3672 if (external_ext
!= NULL
)
3673 free (external_ext
);
3678 if (external_ext
!= NULL
)
3679 free (external_ext
);
3685 /* Add symbols from an ECOFF object file to the global linker hash
3689 ecoff_link_add_object_symbols (abfd
, info
)
3691 struct bfd_link_info
*info
;
3694 bfd_size_type external_ext_size
;
3695 PTR external_ext
= NULL
;
3700 if (! ecoff_slurp_symbolic_header (abfd
))
3703 /* If there are no symbols, we don't want it. */
3704 if (bfd_get_symcount (abfd
) == 0)
3707 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3709 /* Read in the external symbols and external strings. */
3710 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3711 esize
= symhdr
->iextMax
* external_ext_size
;
3712 external_ext
= (PTR
) bfd_malloc (esize
);
3713 if (external_ext
== NULL
&& esize
!= 0)
3716 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3717 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3720 ssext
= (char *) bfd_malloc (symhdr
->issExtMax
);
3721 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3724 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3725 || (bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
)
3726 != (bfd_size_type
) symhdr
->issExtMax
))
3729 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3733 if (external_ext
!= NULL
)
3734 free (external_ext
);
3740 if (external_ext
!= NULL
)
3741 free (external_ext
);
3745 /* Add the external symbols of an object file to the global linker
3746 hash table. The external symbols and strings we are passed are
3747 just allocated on the stack, and will be discarded. We must
3748 explicitly save any information we may need later on in the link.
3749 We do not want to read the external symbol information again. */
3752 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3754 struct bfd_link_info
*info
;
3758 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3759 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3760 = backend
->debug_swap
.swap_ext_in
;
3761 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3762 unsigned long ext_count
;
3763 struct ecoff_link_hash_entry
**sym_hash
;
3767 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3769 sym_hash
= ((struct ecoff_link_hash_entry
**)
3771 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3774 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3776 ext_ptr
= (char *) external_ext
;
3777 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3778 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3785 struct ecoff_link_hash_entry
*h
;
3789 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3791 /* Skip debugging symbols. */
3793 switch (esym
.asym
.st
)
3809 /* Get the information for this symbol. */
3810 value
= esym
.asym
.value
;
3811 switch (esym
.asym
.sc
)
3831 section
= bfd_make_section_old_way (abfd
, ".text");
3832 value
-= section
->vma
;
3835 section
= bfd_make_section_old_way (abfd
, ".data");
3836 value
-= section
->vma
;
3839 section
= bfd_make_section_old_way (abfd
, ".bss");
3840 value
-= section
->vma
;
3843 section
= bfd_abs_section_ptr
;
3846 section
= bfd_und_section_ptr
;
3849 section
= bfd_make_section_old_way (abfd
, ".sdata");
3850 value
-= section
->vma
;
3853 section
= bfd_make_section_old_way (abfd
, ".sbss");
3854 value
-= section
->vma
;
3857 section
= bfd_make_section_old_way (abfd
, ".rdata");
3858 value
-= section
->vma
;
3861 if (value
> ecoff_data (abfd
)->gp_size
)
3863 section
= bfd_com_section_ptr
;
3868 if (ecoff_scom_section
.name
== NULL
)
3870 /* Initialize the small common section. */
3871 ecoff_scom_section
.name
= SCOMMON
;
3872 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3873 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3874 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3875 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3876 ecoff_scom_symbol
.name
= SCOMMON
;
3877 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3878 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3879 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3881 section
= &ecoff_scom_section
;
3884 section
= bfd_und_section_ptr
;
3887 section
= bfd_make_section_old_way (abfd
, ".init");
3888 value
-= section
->vma
;
3891 section
= bfd_make_section_old_way (abfd
, ".fini");
3892 value
-= section
->vma
;
3895 section
= bfd_make_section_old_way (abfd
, ".rconst");
3896 value
-= section
->vma
;
3900 if (section
== (asection
*) NULL
)
3903 name
= ssext
+ esym
.asym
.iss
;
3906 if (! (_bfd_generic_link_add_one_symbol
3908 esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
,
3909 section
, value
, (const char *) NULL
, true, true,
3910 (struct bfd_link_hash_entry
**) &h
)))
3915 /* If we are building an ECOFF hash table, save the external
3916 symbol information. */
3917 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3919 if (h
->abfd
== (bfd
*) NULL
3920 || (! bfd_is_und_section (section
)
3921 && (! bfd_is_com_section (section
)
3922 || (h
->root
.type
!= bfd_link_hash_defined
3923 && h
->root
.type
!= bfd_link_hash_defweak
))))
3929 /* Remember whether this symbol was small undefined. */
3930 if (esym
.asym
.sc
== scSUndefined
)
3933 /* If this symbol was ever small undefined, it needs to wind
3934 up in a GP relative section. We can't control the
3935 section of a defined symbol, but we can control the
3936 section of a common symbol. This case is actually needed
3937 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
3939 && h
->root
.type
== bfd_link_hash_common
3940 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
3942 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
3944 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
3945 if (h
->esym
.asym
.sc
== scCommon
)
3946 h
->esym
.asym
.sc
= scSCommon
;
3954 /* ECOFF final link routines. */
3956 static boolean ecoff_final_link_debug_accumulate
3957 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
3959 static boolean ecoff_link_write_external
3960 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3961 static boolean ecoff_indirect_link_order
3962 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3963 struct bfd_link_order
*));
3964 static boolean ecoff_reloc_link_order
3965 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3966 struct bfd_link_order
*));
3968 /* ECOFF final link routine. This looks through all the input BFDs
3969 and gathers together all the debugging information, and then
3970 processes all the link order information. This may cause it to
3971 close and reopen some input BFDs; I'll see how bad this is. */
3974 _bfd_ecoff_bfd_final_link (abfd
, info
)
3976 struct bfd_link_info
*info
;
3978 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3979 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3982 register bfd
*input_bfd
;
3984 struct bfd_link_order
*p
;
3986 /* We accumulate the debugging information counts in the symbolic
3988 symhdr
= &debug
->symbolic_header
;
3990 symhdr
->ilineMax
= 0;
3994 symhdr
->isymMax
= 0;
3995 symhdr
->ioptMax
= 0;
3996 symhdr
->iauxMax
= 0;
3998 symhdr
->issExtMax
= 0;
4001 symhdr
->iextMax
= 0;
4003 /* We accumulate the debugging information itself in the debug_info
4006 debug
->external_dnr
= NULL
;
4007 debug
->external_pdr
= NULL
;
4008 debug
->external_sym
= NULL
;
4009 debug
->external_opt
= NULL
;
4010 debug
->external_aux
= NULL
;
4012 debug
->ssext
= debug
->ssext_end
= NULL
;
4013 debug
->external_fdr
= NULL
;
4014 debug
->external_rfd
= NULL
;
4015 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4017 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4018 if (handle
== (PTR
) NULL
)
4021 /* Accumulate the debugging symbols from each input BFD. */
4022 for (input_bfd
= info
->input_bfds
;
4023 input_bfd
!= (bfd
*) NULL
;
4024 input_bfd
= input_bfd
->link_next
)
4028 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4030 /* Abitrarily set the symbolic header vstamp to the vstamp
4031 of the first object file in the link. */
4032 if (symhdr
->vstamp
== 0)
4034 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4035 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4039 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4040 debug
, &backend
->debug_swap
,
4045 /* Combine the register masks. */
4046 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4047 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4048 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4049 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4050 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4051 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4054 /* Write out the external symbols. */
4055 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4056 ecoff_link_write_external
,
4059 if (info
->relocateable
)
4061 /* We need to make a pass over the link_orders to count up the
4062 number of relocations we will need to output, so that we know
4063 how much space they will take up. */
4064 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4067 for (p
= o
->link_order_head
;
4068 p
!= (struct bfd_link_order
*) NULL
;
4070 if (p
->type
== bfd_indirect_link_order
)
4071 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4072 else if (p
->type
== bfd_section_reloc_link_order
4073 || p
->type
== bfd_symbol_reloc_link_order
)
4078 /* Compute the reloc and symbol file positions. */
4079 ecoff_compute_reloc_file_positions (abfd
);
4081 /* Write out the debugging information. */
4082 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4083 &backend
->debug_swap
, info
,
4084 ecoff_data (abfd
)->sym_filepos
))
4087 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4089 if (info
->relocateable
)
4091 /* Now reset the reloc_count field of the sections in the output
4092 BFD to 0, so that we can use them to keep track of how many
4093 relocs we have output thus far. */
4094 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4098 /* Get a value for the GP register. */
4099 if (ecoff_data (abfd
)->gp
== 0)
4101 struct bfd_link_hash_entry
*h
;
4103 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4104 if (h
!= (struct bfd_link_hash_entry
*) NULL
4105 && h
->type
== bfd_link_hash_defined
)
4106 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4107 + h
->u
.def
.section
->output_section
->vma
4108 + h
->u
.def
.section
->output_offset
);
4109 else if (info
->relocateable
)
4113 /* Make up a value. */
4115 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4118 && (strcmp (o
->name
, _SBSS
) == 0
4119 || strcmp (o
->name
, _SDATA
) == 0
4120 || strcmp (o
->name
, _LIT4
) == 0
4121 || strcmp (o
->name
, _LIT8
) == 0
4122 || strcmp (o
->name
, _LITA
) == 0))
4125 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4129 /* If the relocate_section function needs to do a reloc
4130 involving the GP value, it should make a reloc_dangerous
4131 callback to warn that GP is not defined. */
4135 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4137 for (p
= o
->link_order_head
;
4138 p
!= (struct bfd_link_order
*) NULL
;
4141 if (p
->type
== bfd_indirect_link_order
4142 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4143 == bfd_target_ecoff_flavour
))
4145 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4148 else if (p
->type
== bfd_section_reloc_link_order
4149 || p
->type
== bfd_symbol_reloc_link_order
)
4151 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4156 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4162 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4164 ecoff_data (abfd
)->linker
= true;
4169 /* Accumulate the debugging information for an input BFD into the
4170 output BFD. This must read in the symbolic information of the
4174 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4177 struct bfd_link_info
*info
;
4180 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4181 const struct ecoff_debug_swap
* const swap
=
4182 &ecoff_backend (input_bfd
)->debug_swap
;
4183 HDRR
*symhdr
= &debug
->symbolic_header
;
4186 #define READ(ptr, offset, count, size, type) \
4187 if (symhdr->count == 0) \
4188 debug->ptr = NULL; \
4191 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
4192 if (debug->ptr == NULL) \
4195 goto return_something; \
4197 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4199 || (bfd_read (debug->ptr, size, symhdr->count, \
4200 input_bfd) != size * symhdr->count)) \
4203 goto return_something; \
4207 /* If raw_syments is not NULL, then the data was already by read by
4208 _bfd_ecoff_slurp_symbolic_info. */
4209 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4211 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4213 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4214 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4215 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4216 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4217 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4219 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4220 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4221 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4225 /* We do not read the external strings or the external symbols. */
4227 ret
= (bfd_ecoff_debug_accumulate
4228 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4229 &ecoff_backend (output_bfd
)->debug_swap
,
4230 input_bfd
, debug
, swap
, info
));
4233 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4235 if (debug
->line
!= NULL
)
4237 if (debug
->external_dnr
!= NULL
)
4238 free (debug
->external_dnr
);
4239 if (debug
->external_pdr
!= NULL
)
4240 free (debug
->external_pdr
);
4241 if (debug
->external_sym
!= NULL
)
4242 free (debug
->external_sym
);
4243 if (debug
->external_opt
!= NULL
)
4244 free (debug
->external_opt
);
4245 if (debug
->external_aux
!= NULL
)
4246 free (debug
->external_aux
);
4247 if (debug
->ss
!= NULL
)
4249 if (debug
->external_fdr
!= NULL
)
4250 free (debug
->external_fdr
);
4251 if (debug
->external_rfd
!= NULL
)
4252 free (debug
->external_rfd
);
4254 /* Make sure we don't accidentally follow one of these pointers
4255 into freed memory. */
4257 debug
->external_dnr
= NULL
;
4258 debug
->external_pdr
= NULL
;
4259 debug
->external_sym
= NULL
;
4260 debug
->external_opt
= NULL
;
4261 debug
->external_aux
= NULL
;
4263 debug
->external_fdr
= NULL
;
4264 debug
->external_rfd
= NULL
;
4270 /* Put out information for an external symbol. These come only from
4274 ecoff_link_write_external (h
, data
)
4275 struct ecoff_link_hash_entry
*h
;
4278 bfd
*output_bfd
= (bfd
*) data
;
4280 /* FIXME: We should check if this symbol is being stripped. */
4285 if (h
->abfd
== (bfd
*) NULL
)
4288 h
->esym
.cobol_main
= 0;
4289 h
->esym
.weakext
= 0;
4290 h
->esym
.reserved
= 0;
4291 h
->esym
.ifd
= ifdNil
;
4292 h
->esym
.asym
.value
= 0;
4293 h
->esym
.asym
.st
= stGlobal
;
4295 if (h
->root
.type
!= bfd_link_hash_defined
4296 && h
->root
.type
!= bfd_link_hash_defweak
)
4297 h
->esym
.asym
.sc
= scAbs
;
4300 asection
*output_section
;
4303 output_section
= h
->root
.u
.def
.section
->output_section
;
4304 name
= bfd_section_name (output_section
->owner
, output_section
);
4306 if (strcmp (name
, _TEXT
) == 0)
4307 h
->esym
.asym
.sc
= scText
;
4308 else if (strcmp (name
, _DATA
) == 0)
4309 h
->esym
.asym
.sc
= scData
;
4310 else if (strcmp (name
, _SDATA
) == 0)
4311 h
->esym
.asym
.sc
= scSData
;
4312 else if (strcmp (name
, _RDATA
) == 0)
4313 h
->esym
.asym
.sc
= scRData
;
4314 else if (strcmp (name
, _BSS
) == 0)
4315 h
->esym
.asym
.sc
= scBss
;
4316 else if (strcmp (name
, _SBSS
) == 0)
4317 h
->esym
.asym
.sc
= scSBss
;
4318 else if (strcmp (name
, _INIT
) == 0)
4319 h
->esym
.asym
.sc
= scInit
;
4320 else if (strcmp (name
, _FINI
) == 0)
4321 h
->esym
.asym
.sc
= scFini
;
4322 else if (strcmp (name
, _PDATA
) == 0)
4323 h
->esym
.asym
.sc
= scPData
;
4324 else if (strcmp (name
, _XDATA
) == 0)
4325 h
->esym
.asym
.sc
= scXData
;
4326 else if (strcmp (name
, _RCONST
) == 0)
4327 h
->esym
.asym
.sc
= scRConst
;
4329 h
->esym
.asym
.sc
= scAbs
;
4332 h
->esym
.asym
.reserved
= 0;
4333 h
->esym
.asym
.index
= indexNil
;
4335 else if (h
->esym
.ifd
!= -1)
4337 struct ecoff_debug_info
*debug
;
4339 /* Adjust the FDR index for the symbol by that used for the
4341 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4342 BFD_ASSERT (h
->esym
.ifd
>= 0
4343 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4344 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4347 switch (h
->root
.type
)
4350 case bfd_link_hash_new
:
4352 case bfd_link_hash_undefined
:
4353 case bfd_link_hash_undefweak
:
4354 if (h
->esym
.asym
.sc
!= scUndefined
4355 && h
->esym
.asym
.sc
!= scSUndefined
)
4356 h
->esym
.asym
.sc
= scUndefined
;
4358 case bfd_link_hash_defined
:
4359 case bfd_link_hash_defweak
:
4360 if (h
->esym
.asym
.sc
== scUndefined
4361 || h
->esym
.asym
.sc
== scSUndefined
)
4362 h
->esym
.asym
.sc
= scAbs
;
4363 else if (h
->esym
.asym
.sc
== scCommon
)
4364 h
->esym
.asym
.sc
= scBss
;
4365 else if (h
->esym
.asym
.sc
== scSCommon
)
4366 h
->esym
.asym
.sc
= scSBss
;
4367 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4368 + h
->root
.u
.def
.section
->output_section
->vma
4369 + h
->root
.u
.def
.section
->output_offset
);
4371 case bfd_link_hash_common
:
4372 if (h
->esym
.asym
.sc
!= scCommon
4373 && h
->esym
.asym
.sc
!= scSCommon
)
4374 h
->esym
.asym
.sc
= scCommon
;
4375 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4377 case bfd_link_hash_indirect
:
4378 case bfd_link_hash_warning
:
4379 /* FIXME: Ignore these for now. The circumstances under which
4380 they should be written out are not clear to me. */
4384 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4386 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4389 return (bfd_ecoff_debug_one_external
4390 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4391 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4395 /* Relocate and write an ECOFF section into an ECOFF output file. */
4398 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4400 struct bfd_link_info
*info
;
4401 asection
*output_section
;
4402 struct bfd_link_order
*link_order
;
4404 asection
*input_section
;
4406 struct ecoff_section_tdata
*section_tdata
;
4407 bfd_size_type raw_size
;
4408 bfd_size_type cooked_size
;
4409 bfd_byte
*contents
= NULL
;
4410 bfd_size_type external_reloc_size
;
4411 bfd_size_type external_relocs_size
;
4412 PTR external_relocs
= NULL
;
4414 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4416 if (link_order
->size
== 0)
4419 input_section
= link_order
->u
.indirect
.section
;
4420 input_bfd
= input_section
->owner
;
4421 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4423 raw_size
= input_section
->_raw_size
;
4424 cooked_size
= input_section
->_cooked_size
;
4425 if (cooked_size
== 0)
4426 cooked_size
= raw_size
;
4428 BFD_ASSERT (input_section
->output_section
== output_section
);
4429 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4430 BFD_ASSERT (cooked_size
== link_order
->size
);
4432 /* Get the section contents. We allocate memory for the larger of
4433 the size before relocating and the size after relocating. */
4434 contents
= (bfd_byte
*) bfd_malloc (raw_size
>= cooked_size
4436 : (size_t) cooked_size
);
4437 if (contents
== NULL
&& raw_size
!= 0)
4440 /* If we are relaxing, the contents may have already been read into
4441 memory, in which case we copy them into our new buffer. We don't
4442 simply reuse the old buffer in case cooked_size > raw_size. */
4443 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4444 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4445 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4448 if (! bfd_get_section_contents (input_bfd
, input_section
,
4450 (file_ptr
) 0, raw_size
))
4454 /* Get the relocs. If we are relaxing MIPS code, they will already
4455 have been read in. Otherwise, we read them in now. */
4456 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4457 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4459 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4460 && section_tdata
->external_relocs
!= NULL
)
4461 external_relocs
= section_tdata
->external_relocs
;
4464 external_relocs
= (PTR
) bfd_malloc ((size_t) external_relocs_size
);
4465 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4468 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4469 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4470 != external_relocs_size
))
4474 /* Relocate the section contents. */
4475 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4476 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4480 /* Write out the relocated section. */
4481 if (! bfd_set_section_contents (output_bfd
,
4484 input_section
->output_offset
,
4488 /* If we are producing relocateable output, the relocs were
4489 modified, and we write them out now. We use the reloc_count
4490 field of output_section to keep track of the number of relocs we
4491 have output so far. */
4492 if (info
->relocateable
)
4494 if (bfd_seek (output_bfd
,
4495 (output_section
->rel_filepos
+
4496 output_section
->reloc_count
* external_reloc_size
),
4498 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4499 != external_relocs_size
))
4501 output_section
->reloc_count
+= input_section
->reloc_count
;
4504 if (contents
!= NULL
)
4506 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4507 free (external_relocs
);
4511 if (contents
!= NULL
)
4513 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4514 free (external_relocs
);
4518 /* Generate a reloc when linking an ECOFF file. This is a reloc
4519 requested by the linker, and does come from any input file. This
4520 is used to build constructor and destructor tables when linking
4524 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4526 struct bfd_link_info
*info
;
4527 asection
*output_section
;
4528 struct bfd_link_order
*link_order
;
4530 enum bfd_link_order_type type
;
4534 struct internal_reloc in
;
4535 bfd_size_type external_reloc_size
;
4539 type
= link_order
->type
;
4541 addend
= link_order
->u
.reloc
.p
->addend
;
4543 /* We set up an arelent to pass to the backend adjust_reloc_out
4545 rel
.address
= link_order
->offset
;
4547 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4550 bfd_set_error (bfd_error_bad_value
);
4554 if (type
== bfd_section_reloc_link_order
)
4556 section
= link_order
->u
.reloc
.p
->u
.section
;
4557 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4561 struct bfd_link_hash_entry
*h
;
4563 /* Treat a reloc against a defined symbol as though it were
4564 actually against the section. */
4565 h
= bfd_link_hash_lookup (info
->hash
, link_order
->u
.reloc
.p
->u
.name
,
4566 false, false, false);
4568 && (h
->type
== bfd_link_hash_defined
4569 || h
->type
== bfd_link_hash_defweak
))
4571 type
= bfd_section_reloc_link_order
;
4572 section
= h
->u
.def
.section
->output_section
;
4573 /* It seems that we ought to add the symbol value to the
4574 addend here, but in practice it has already been added
4575 because it was passed to constructor_callback. */
4576 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4580 /* We can't set up a reloc against a symbol correctly,
4581 because we have no asymbol structure. Currently no
4582 adjust_reloc_out routine cares. */
4583 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4587 /* All ECOFF relocs are in-place. Put the addend into the object
4590 BFD_ASSERT (rel
.howto
->partial_inplace
);
4594 bfd_reloc_status_type rstat
;
4598 size
= bfd_get_reloc_size (rel
.howto
);
4599 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4600 if (buf
== (bfd_byte
*) NULL
)
4602 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
, addend
, buf
);
4608 case bfd_reloc_outofrange
:
4610 case bfd_reloc_overflow
:
4611 if (! ((*info
->callbacks
->reloc_overflow
)
4613 (link_order
->type
== bfd_section_reloc_link_order
4614 ? bfd_section_name (output_bfd
, section
)
4615 : link_order
->u
.reloc
.p
->u
.name
),
4616 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4617 (asection
*) NULL
, (bfd_vma
) 0)))
4624 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4625 (file_ptr
) link_order
->offset
, size
);
4633 /* Move the information into a internal_reloc structure. */
4634 in
.r_vaddr
= (rel
.address
4635 + bfd_get_section_vma (output_bfd
, output_section
));
4636 in
.r_type
= rel
.howto
->type
;
4638 if (type
== bfd_symbol_reloc_link_order
)
4640 struct ecoff_link_hash_entry
*h
;
4642 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4643 link_order
->u
.reloc
.p
->u
.name
,
4644 false, false, true);
4645 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4647 in
.r_symndx
= h
->indx
;
4650 if (! ((*info
->callbacks
->unattached_reloc
)
4651 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4652 (asection
*) NULL
, (bfd_vma
) 0)))
4662 name
= bfd_get_section_name (output_bfd
, section
);
4663 if (strcmp (name
, ".text") == 0)
4664 in
.r_symndx
= RELOC_SECTION_TEXT
;
4665 else if (strcmp (name
, ".rdata") == 0)
4666 in
.r_symndx
= RELOC_SECTION_RDATA
;
4667 else if (strcmp (name
, ".data") == 0)
4668 in
.r_symndx
= RELOC_SECTION_DATA
;
4669 else if (strcmp (name
, ".sdata") == 0)
4670 in
.r_symndx
= RELOC_SECTION_SDATA
;
4671 else if (strcmp (name
, ".sbss") == 0)
4672 in
.r_symndx
= RELOC_SECTION_SBSS
;
4673 else if (strcmp (name
, ".bss") == 0)
4674 in
.r_symndx
= RELOC_SECTION_BSS
;
4675 else if (strcmp (name
, ".init") == 0)
4676 in
.r_symndx
= RELOC_SECTION_INIT
;
4677 else if (strcmp (name
, ".lit8") == 0)
4678 in
.r_symndx
= RELOC_SECTION_LIT8
;
4679 else if (strcmp (name
, ".lit4") == 0)
4680 in
.r_symndx
= RELOC_SECTION_LIT4
;
4681 else if (strcmp (name
, ".xdata") == 0)
4682 in
.r_symndx
= RELOC_SECTION_XDATA
;
4683 else if (strcmp (name
, ".pdata") == 0)
4684 in
.r_symndx
= RELOC_SECTION_PDATA
;
4685 else if (strcmp (name
, ".fini") == 0)
4686 in
.r_symndx
= RELOC_SECTION_FINI
;
4687 else if (strcmp (name
, ".lita") == 0)
4688 in
.r_symndx
= RELOC_SECTION_LITA
;
4689 else if (strcmp (name
, "*ABS*") == 0)
4690 in
.r_symndx
= RELOC_SECTION_ABS
;
4691 else if (strcmp (name
, ".rconst") == 0)
4692 in
.r_symndx
= RELOC_SECTION_RCONST
;
4698 /* Let the BFD backend adjust the reloc. */
4699 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4701 /* Get some memory and swap out the reloc. */
4702 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4703 rbuf
= (bfd_byte
*) bfd_malloc ((size_t) external_reloc_size
);
4704 if (rbuf
== (bfd_byte
*) NULL
)
4707 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4709 ok
= (bfd_seek (output_bfd
,
4710 (output_section
->rel_filepos
+
4711 output_section
->reloc_count
* external_reloc_size
),
4713 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4714 == external_reloc_size
));
4717 ++output_section
->reloc_count
;