1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
48 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
49 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
50 asymbol
*asym
, int ext
,
51 asymbol
**indirect_ptr_ptr
));
52 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
53 RNDXR
*rndx
, long isym
,
55 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
56 unsigned int indx
, int bigendian
));
57 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
59 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
60 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
61 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
62 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
63 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
68 /* This stuff is somewhat copied from coffcode.h. */
70 static asection bfd_debug_section
= { "*DEBUG*" };
72 /* Create an ECOFF object. */
78 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
79 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
80 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
82 bfd_error
= no_memory
;
89 /* This is a hook called by coff_real_object_p to create any backend
90 specific information. */
93 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
98 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
99 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
100 ecoff_data_type
*ecoff
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 /* Create the .reginfo section to give programs outside BFD a way to
111 see the information stored in the a.out header. See the comment
113 regsec
= bfd_make_section (abfd
, REGINFO
);
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 /* For the .pdata section, which has a special meaning on the Alpha,
160 we set the alignment to 8. We correct this later in
161 ecoff_compute_section_file_positions. We do this hackery because
162 we need to know the exact unaligned size of the .pdata section in
163 order to set the lnnoptr field correctly. */
164 if (strcmp (section
->name
, _PDATA
) == 0)
165 section
->alignment_power
= 3;
167 section
->alignment_power
= abfd
->xvec
->align_power_min
;
169 if (strcmp (section
->name
, _TEXT
) == 0)
170 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
171 else if (strcmp (section
->name
, _DATA
) == 0
172 || strcmp (section
->name
, _SDATA
) == 0)
173 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
174 else if (strcmp (section
->name
, _RDATA
) == 0
175 || strcmp (section
->name
, _LIT8
) == 0
176 || strcmp (section
->name
, _LIT4
) == 0)
177 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
178 else if (strcmp (section
->name
, _BSS
) == 0
179 || strcmp (section
->name
, _SBSS
) == 0)
180 section
->flags
|= SEC_ALLOC
;
181 else if (strcmp (section
->name
, REGINFO
) == 0)
183 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
184 section completely alone. */
185 section
->flags
|= (SEC_SHARED_LIBRARY
188 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
191 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
192 uncertain about .init on some systems and I don't know how shared
198 /* Determine the machine architecture and type. This is called from
199 the generic COFF routines. It is the inverse of ecoff_get_magic,
200 below. This could be an ECOFF backend routine, with one version
201 for each target, but there aren't all that many ECOFF targets. */
204 ecoff_set_arch_mach_hook (abfd
, filehdr
)
208 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
209 enum bfd_architecture arch
;
212 switch (internal_f
->f_magic
)
215 case MIPS_MAGIC_LITTLE
:
217 arch
= bfd_arch_mips
;
221 case MIPS_MAGIC_LITTLE2
:
222 case MIPS_MAGIC_BIG2
:
223 /* MIPS ISA level 2: the r6000 */
224 arch
= bfd_arch_mips
;
228 case MIPS_MAGIC_LITTLE3
:
229 case MIPS_MAGIC_BIG3
:
230 /* MIPS ISA level 3: the r4000 */
231 arch
= bfd_arch_mips
;
236 arch
= bfd_arch_alpha
;
241 arch
= bfd_arch_obscure
;
246 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
249 /* Get the magic number to use based on the architecture and machine.
250 This is the inverse of ecoff_set_arch_mach_hook, above. */
253 ecoff_get_magic (abfd
)
258 switch (bfd_get_arch (abfd
))
261 switch (bfd_get_mach (abfd
))
266 big
= MIPS_MAGIC_BIG
;
267 little
= MIPS_MAGIC_LITTLE
;
271 big
= MIPS_MAGIC_BIG2
;
272 little
= MIPS_MAGIC_LITTLE2
;
276 big
= MIPS_MAGIC_BIG3
;
277 little
= MIPS_MAGIC_LITTLE3
;
281 return abfd
->xvec
->byteorder_big_p
? big
: little
;
292 /* Get the section s_flags to use for a section. */
295 ecoff_sec_to_styp_flags (name
, flags
)
303 if (strcmp (name
, _TEXT
) == 0)
305 else if (strcmp (name
, _DATA
) == 0)
307 else if (strcmp (name
, _SDATA
) == 0)
309 else if (strcmp (name
, _RDATA
) == 0)
311 else if (strcmp (name
, _LITA
) == 0)
313 else if (strcmp (name
, _LIT8
) == 0)
315 else if (strcmp (name
, _LIT4
) == 0)
317 else if (strcmp (name
, _BSS
) == 0)
319 else if (strcmp (name
, _SBSS
) == 0)
321 else if (strcmp (name
, _INIT
) == 0)
322 styp
= STYP_ECOFF_INIT
;
323 else if (strcmp (name
, _FINI
) == 0)
324 styp
= STYP_ECOFF_FINI
;
325 else if (strcmp (name
, _PDATA
) == 0)
327 else if (strcmp (name
, _XDATA
) == 0)
329 else if (flags
& SEC_CODE
)
331 else if (flags
& SEC_DATA
)
333 else if (flags
& SEC_READONLY
)
335 else if (flags
& SEC_LOAD
)
340 if (flags
& SEC_NEVER_LOAD
)
346 /* Get the BFD flags to use for a section. */
350 ecoff_styp_to_sec_flags (abfd
, hdr
)
354 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
355 long styp_flags
= internal_s
->s_flags
;
356 flagword sec_flags
=0;
358 if (styp_flags
& STYP_NOLOAD
)
359 sec_flags
|= SEC_NEVER_LOAD
;
361 /* For 386 COFF, at least, an unloadable text or data section is
362 actually a shared library section. */
363 if ((styp_flags
& STYP_TEXT
)
364 || (styp_flags
& STYP_ECOFF_INIT
)
365 || (styp_flags
& STYP_ECOFF_FINI
))
367 if (sec_flags
& SEC_NEVER_LOAD
)
368 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
370 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
372 else if ((styp_flags
& STYP_DATA
)
373 || (styp_flags
& STYP_RDATA
)
374 || (styp_flags
& STYP_SDATA
))
376 if (sec_flags
& SEC_NEVER_LOAD
)
377 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
379 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
380 if (styp_flags
& STYP_RDATA
)
381 sec_flags
|= SEC_READONLY
;
383 else if ((styp_flags
& STYP_BSS
)
384 || (styp_flags
& STYP_SBSS
))
386 sec_flags
|= SEC_ALLOC
;
388 else if (styp_flags
& STYP_INFO
)
390 sec_flags
|= SEC_NEVER_LOAD
;
392 else if ((styp_flags
& STYP_LITA
)
393 || (styp_flags
& STYP_LIT8
)
394 || (styp_flags
& STYP_LIT4
))
396 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
400 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
406 /* Routines to swap auxiliary information in and out. I am assuming
407 that the auxiliary information format is always going to be target
410 /* Swap in a type information record.
411 BIGEND says whether AUX symbols are big-endian or little-endian; this
412 info comes from the file header record (fh-fBigendian). */
415 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
417 struct tir_ext
*ext_copy
;
420 struct tir_ext ext
[1];
422 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
424 /* now the fun stuff... */
426 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
427 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
428 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
429 >> TIR_BITS1_BT_SH_BIG
;
430 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
431 >> TIR_BITS_TQ4_SH_BIG
;
432 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
433 >> TIR_BITS_TQ5_SH_BIG
;
434 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
435 >> TIR_BITS_TQ0_SH_BIG
;
436 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
437 >> TIR_BITS_TQ1_SH_BIG
;
438 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
439 >> TIR_BITS_TQ2_SH_BIG
;
440 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
441 >> TIR_BITS_TQ3_SH_BIG
;
443 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
444 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
445 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
446 >> TIR_BITS1_BT_SH_LITTLE
;
447 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
448 >> TIR_BITS_TQ4_SH_LITTLE
;
449 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
450 >> TIR_BITS_TQ5_SH_LITTLE
;
451 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
452 >> TIR_BITS_TQ0_SH_LITTLE
;
453 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
454 >> TIR_BITS_TQ1_SH_LITTLE
;
455 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
456 >> TIR_BITS_TQ2_SH_LITTLE
;
457 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
458 >> TIR_BITS_TQ3_SH_LITTLE
;
462 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
467 /* Swap out a type information record.
468 BIGEND says whether AUX symbols are big-endian or little-endian; this
469 info comes from the file header record (fh-fBigendian). */
472 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
479 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
481 /* now the fun stuff... */
483 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
484 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
485 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
486 & TIR_BITS1_BT_BIG
));
487 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
489 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
490 & TIR_BITS_TQ5_BIG
));
491 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
493 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
494 & TIR_BITS_TQ1_BIG
));
495 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
497 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
498 & TIR_BITS_TQ3_BIG
));
500 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
501 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
502 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
503 & TIR_BITS1_BT_LITTLE
));
504 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
505 & TIR_BITS_TQ4_LITTLE
)
506 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
507 & TIR_BITS_TQ5_LITTLE
));
508 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
509 & TIR_BITS_TQ0_LITTLE
)
510 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
511 & TIR_BITS_TQ1_LITTLE
));
512 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
513 & TIR_BITS_TQ2_LITTLE
)
514 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
515 & TIR_BITS_TQ3_LITTLE
));
519 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
524 /* Swap in a relative symbol record. BIGEND says whether it is in
525 big-endian or little-endian format.*/
528 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
530 struct rndx_ext
*ext_copy
;
533 struct rndx_ext ext
[1];
535 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
537 /* now the fun stuff... */
539 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
540 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
541 >> RNDX_BITS1_RFD_SH_BIG
);
542 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
543 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
544 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
545 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
547 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
548 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
549 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
550 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
551 >> RNDX_BITS1_INDEX_SH_LITTLE
)
552 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
553 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
557 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
562 /* Swap out a relative symbol record. BIGEND says whether it is in
563 big-endian or little-endian format.*/
566 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
569 struct rndx_ext
*ext
;
573 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
575 /* now the fun stuff... */
577 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
578 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
579 & RNDX_BITS1_RFD_BIG
)
580 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
581 & RNDX_BITS1_INDEX_BIG
));
582 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
583 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
585 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
586 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
587 & RNDX_BITS1_RFD_LITTLE
)
588 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
589 & RNDX_BITS1_INDEX_LITTLE
));
590 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
591 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
595 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
600 /* Read in the symbolic header for an ECOFF object file. */
603 ecoff_slurp_symbolic_header (abfd
)
606 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
607 bfd_size_type external_hdr_size
;
609 HDRR
*internal_symhdr
;
611 /* See if we've already read it in. */
612 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
613 backend
->debug_swap
.sym_magic
)
616 /* See whether there is a symbolic header. */
617 if (ecoff_data (abfd
)->sym_filepos
== 0)
619 bfd_get_symcount (abfd
) = 0;
623 /* At this point bfd_get_symcount (abfd) holds the number of symbols
624 as read from the file header, but on ECOFF this is always the
625 size of the symbolic information header. It would be cleaner to
626 handle this when we first read the file in coffgen.c. */
627 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
628 if (bfd_get_symcount (abfd
) != external_hdr_size
)
630 bfd_error
= bad_value
;
634 /* Read the symbolic information header. */
635 raw
= (PTR
) alloca ((size_t) external_hdr_size
);
636 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
637 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
638 != external_hdr_size
))
640 bfd_error
= system_call_error
;
643 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
644 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
646 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
648 bfd_error
= bad_value
;
652 /* Now we can get the correct number of symbols. */
653 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
654 + internal_symhdr
->iextMax
);
659 /* Read in and swap the important symbolic information for an ECOFF
660 object file. This is called by gdb. */
663 ecoff_slurp_symbolic_info (abfd
)
666 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
667 HDRR
*internal_symhdr
;
668 bfd_size_type raw_base
;
669 bfd_size_type raw_size
;
671 bfd_size_type external_fdr_size
;
675 bfd_size_type raw_end
;
676 bfd_size_type cb_end
;
678 /* Check whether we've already gotten it, and whether there's any to
680 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
682 if (ecoff_data (abfd
)->sym_filepos
== 0)
684 bfd_get_symcount (abfd
) = 0;
688 if (! ecoff_slurp_symbolic_header (abfd
))
691 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
693 /* Read all the symbolic information at once. */
694 raw_base
= (ecoff_data (abfd
)->sym_filepos
695 + backend
->debug_swap
.external_hdr_size
);
697 /* Alpha ecoff makes the determination of raw_size difficult. It has
698 an undocumented debug data section between the symhdr and the first
699 documented section. And the ordering of the sections varies between
700 statically and dynamically linked executables.
701 If bfd supports SEEK_END someday, this code could be simplified. */
705 #define UPDATE_RAW_END(start, count, size) \
706 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
707 if (cb_end > raw_end) \
710 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
711 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
712 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
713 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
714 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
715 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
716 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
717 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
718 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
719 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
720 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
722 #undef UPDATE_RAW_END
724 raw_size
= raw_end
- raw_base
;
727 ecoff_data (abfd
)->sym_filepos
= 0;
730 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
733 bfd_error
= no_memory
;
737 (ecoff_data (abfd
)->sym_filepos
738 + backend
->debug_swap
.external_hdr_size
),
740 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
742 bfd_error
= system_call_error
;
743 bfd_release (abfd
, raw
);
747 ecoff_data (abfd
)->raw_syments
= raw
;
749 /* Get pointers for the numeric offsets in the HDRR structure. */
750 #define FIX(off1, off2, type) \
751 if (internal_symhdr->off1 == 0) \
752 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
754 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
755 + internal_symhdr->off1 \
757 FIX (cbLineOffset
, line
, unsigned char *);
758 FIX (cbDnOffset
, external_dnr
, PTR
);
759 FIX (cbPdOffset
, external_pdr
, PTR
);
760 FIX (cbSymOffset
, external_sym
, PTR
);
761 FIX (cbOptOffset
, external_opt
, PTR
);
762 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
763 FIX (cbSsOffset
, ss
, char *);
764 FIX (cbSsExtOffset
, ssext
, char *);
765 FIX (cbFdOffset
, external_fdr
, PTR
);
766 FIX (cbRfdOffset
, external_rfd
, PTR
);
767 FIX (cbExtOffset
, external_ext
, PTR
);
770 /* I don't want to always swap all the data, because it will just
771 waste time and most programs will never look at it. The only
772 time the linker needs most of the debugging information swapped
773 is when linking big-endian and little-endian MIPS object files
774 together, which is not a common occurrence.
776 We need to look at the fdr to deal with a lot of information in
777 the symbols, so we swap them here. */
778 ecoff_data (abfd
)->debug_info
.fdr
=
779 (struct fdr
*) bfd_alloc (abfd
,
780 (internal_symhdr
->ifdMax
*
781 sizeof (struct fdr
)));
782 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
784 bfd_error
= no_memory
;
787 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
788 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
789 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
790 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
791 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
792 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
797 /* ECOFF symbol table routines. The ECOFF symbol table is described
798 in gcc/mips-tfile.c. */
800 /* ECOFF uses two common sections. One is the usual one, and the
801 other is for small objects. All the small objects are kept
802 together, and then referenced via the gp pointer, which yields
803 faster assembler code. This is what we use for the small common
805 static asection ecoff_scom_section
;
806 static asymbol ecoff_scom_symbol
;
807 static asymbol
*ecoff_scom_symbol_ptr
;
809 /* Create an empty symbol. */
812 ecoff_make_empty_symbol (abfd
)
815 ecoff_symbol_type
*new;
817 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
818 if (new == (ecoff_symbol_type
*) NULL
)
820 bfd_error
= no_memory
;
821 return (asymbol
*) NULL
;
823 memset (new, 0, sizeof *new);
824 new->symbol
.section
= (asection
*) NULL
;
825 new->fdr
= (FDR
*) NULL
;
828 new->symbol
.the_bfd
= abfd
;
832 /* Set the BFD flags and section for an ECOFF symbol. */
835 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
840 asymbol
**indirect_ptr_ptr
;
842 asym
->the_bfd
= abfd
;
843 asym
->value
= ecoff_sym
->value
;
844 asym
->section
= &bfd_debug_section
;
847 /* An indirect symbol requires two consecutive stabs symbols. */
848 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
850 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
852 /* @@ Stuffing pointers into integers is a no-no.
853 We can usually get away with it if the integer is
854 large enough though. */
855 if (sizeof (asym
) > sizeof (bfd_vma
))
857 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
859 asym
->flags
= BSF_DEBUGGING
;
860 asym
->section
= &bfd_und_section
;
861 *indirect_ptr_ptr
= NULL
;
865 if (ECOFF_IS_STAB (ecoff_sym
)
866 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
868 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
869 asym
->section
= &bfd_ind_section
;
870 /* Pass this symbol on to the next call to this function. */
871 *indirect_ptr_ptr
= asym
;
875 /* Most symbol types are just for debugging. */
876 switch (ecoff_sym
->st
)
885 if (ECOFF_IS_STAB (ecoff_sym
))
887 asym
->flags
= BSF_DEBUGGING
;
892 asym
->flags
= BSF_DEBUGGING
;
897 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
899 asym
->flags
= BSF_LOCAL
;
900 switch (ecoff_sym
->sc
)
903 /* Used for compiler generated labels. Leave them in the
904 debugging section, and mark them as local. If BSF_DEBUGGING
905 is set, then nm does not display them for some reason. If no
906 flags are set then the linker whines about them. */
907 asym
->flags
= BSF_LOCAL
;
910 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
911 asym
->value
-= asym
->section
->vma
;
914 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
915 asym
->value
-= asym
->section
->vma
;
918 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
919 asym
->value
-= asym
->section
->vma
;
922 asym
->flags
= BSF_DEBUGGING
;
925 asym
->section
= &bfd_abs_section
;
928 asym
->section
= &bfd_und_section
;
938 asym
->flags
= BSF_DEBUGGING
;
941 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
942 asym
->value
-= asym
->section
->vma
;
945 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
946 asym
->value
-= asym
->section
->vma
;
949 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
950 asym
->value
-= asym
->section
->vma
;
953 asym
->flags
= BSF_DEBUGGING
;
956 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
958 asym
->section
= &bfd_com_section
;
964 if (ecoff_scom_section
.name
== NULL
)
966 /* Initialize the small common section. */
967 ecoff_scom_section
.name
= SCOMMON
;
968 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
969 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
970 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
971 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
972 ecoff_scom_symbol
.name
= SCOMMON
;
973 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
974 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
975 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
977 asym
->section
= &ecoff_scom_section
;
982 asym
->flags
= BSF_DEBUGGING
;
985 asym
->section
= &bfd_und_section
;
990 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
991 asym
->value
-= asym
->section
->vma
;
996 asym
->flags
= BSF_DEBUGGING
;
999 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1000 asym
->value
-= asym
->section
->vma
;
1006 /* Look for special constructors symbols and make relocation entries
1007 in a special construction section. These are produced by the
1008 -fgnu-linker argument to g++. */
1009 if (ECOFF_IS_STAB (ecoff_sym
))
1011 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1023 arelent_chain
*reloc_chain
;
1024 unsigned int bitsize
;
1026 /* Get a section with the same name as the symbol (usually
1027 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1028 name ___CTOR_LIST (three underscores). We need
1029 __CTOR_LIST (two underscores), since ECOFF doesn't use
1030 a leading underscore. This should be handled by gcc,
1031 but instead we do it here. Actually, this should all
1032 be done differently anyhow. */
1033 name
= bfd_asymbol_name (asym
);
1034 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1039 section
= bfd_get_section_by_name (abfd
, name
);
1040 if (section
== (asection
*) NULL
)
1044 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1045 strcpy (copy
, name
);
1046 section
= bfd_make_section (abfd
, copy
);
1049 /* Build a reloc pointing to this constructor. */
1051 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1052 reloc_chain
->relent
.sym_ptr_ptr
=
1053 bfd_get_section (asym
)->symbol_ptr_ptr
;
1054 reloc_chain
->relent
.address
= section
->_raw_size
;
1055 reloc_chain
->relent
.addend
= asym
->value
;
1056 reloc_chain
->relent
.howto
=
1057 ecoff_backend (abfd
)->constructor_reloc
;
1059 /* Set up the constructor section to hold the reloc. */
1060 section
->flags
= SEC_CONSTRUCTOR
;
1061 ++section
->reloc_count
;
1063 /* Constructor sections must be rounded to a boundary
1064 based on the bitsize. These are not real sections--
1065 they are handled specially by the linker--so the ECOFF
1066 16 byte alignment restriction does not apply. */
1067 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1068 section
->alignment_power
= 1;
1069 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1070 ++section
->alignment_power
;
1072 reloc_chain
->next
= section
->constructor_chain
;
1073 section
->constructor_chain
= reloc_chain
;
1074 section
->_raw_size
+= bitsize
/ 8;
1076 /* Mark the symbol as a constructor. */
1077 asym
->flags
|= BSF_CONSTRUCTOR
;
1084 /* Read an ECOFF symbol table. */
1087 ecoff_slurp_symbol_table (abfd
)
1090 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1091 const bfd_size_type external_ext_size
1092 = backend
->debug_swap
.external_ext_size
;
1093 const bfd_size_type external_sym_size
1094 = backend
->debug_swap
.external_sym_size
;
1095 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1096 = backend
->debug_swap
.swap_ext_in
;
1097 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1098 = backend
->debug_swap
.swap_sym_in
;
1099 bfd_size_type internal_size
;
1100 ecoff_symbol_type
*internal
;
1101 ecoff_symbol_type
*internal_ptr
;
1102 asymbol
*indirect_ptr
;
1108 /* If we've already read in the symbol table, do nothing. */
1109 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1112 /* Get the symbolic information. */
1113 if (ecoff_slurp_symbolic_info (abfd
) == false)
1115 if (bfd_get_symcount (abfd
) == 0)
1118 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1119 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1120 if (internal
== NULL
)
1122 bfd_error
= no_memory
;
1126 internal_ptr
= internal
;
1127 indirect_ptr
= NULL
;
1128 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1129 eraw_end
= (eraw_src
1130 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1131 * external_ext_size
));
1132 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1136 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1137 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1138 + internal_esym
.asym
.iss
);
1139 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1140 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1141 /* The alpha uses a negative ifd field for section symbols. */
1142 if (internal_esym
.ifd
>= 0)
1143 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1144 + internal_esym
.ifd
);
1146 internal_ptr
->fdr
= NULL
;
1147 internal_ptr
->local
= false;
1148 internal_ptr
->native
= (PTR
) eraw_src
;
1150 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1152 /* The local symbols must be accessed via the fdr's, because the
1153 string and aux indices are relative to the fdr information. */
1154 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1155 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1156 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1161 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1162 + fdr_ptr
->isymBase
* external_sym_size
);
1163 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1165 lraw_src
< lraw_end
;
1166 lraw_src
+= external_sym_size
, internal_ptr
++)
1170 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1171 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1173 + internal_sym
.iss
);
1174 ecoff_set_symbol_info (abfd
, &internal_sym
,
1175 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1176 internal_ptr
->fdr
= fdr_ptr
;
1177 internal_ptr
->local
= true;
1178 internal_ptr
->native
= (PTR
) lraw_src
;
1181 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1183 ecoff_data (abfd
)->canonical_symbols
= internal
;
1188 /* Return the amount of space needed for the canonical symbols. */
1191 ecoff_get_symtab_upper_bound (abfd
)
1194 if (ecoff_slurp_symbolic_info (abfd
) == false
1195 || bfd_get_symcount (abfd
) == 0)
1198 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1201 /* Get the canonical symbols. */
1204 ecoff_get_symtab (abfd
, alocation
)
1206 asymbol
**alocation
;
1208 unsigned int counter
= 0;
1209 ecoff_symbol_type
*symbase
;
1210 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1212 if (ecoff_slurp_symbol_table (abfd
) == false
1213 || bfd_get_symcount (abfd
) == 0)
1216 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1217 while (counter
< bfd_get_symcount (abfd
))
1219 *(location
++) = symbase
++;
1222 *location
++ = (ecoff_symbol_type
*) NULL
;
1223 return bfd_get_symcount (abfd
);
1226 /* Turn ECOFF type information into a printable string.
1227 ecoff_emit_aggregate and ecoff_type_to_string are from
1228 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1230 /* Write aggregate information to a string. */
1233 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1240 int ifd
= rndx
->rfd
;
1241 int indx
= rndx
->index
;
1242 int sym_base
, ss_base
;
1248 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1249 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1251 if (indx
== indexNil
)
1252 name
= "/* no name */";
1255 const struct ecoff_debug_swap
* const debug_swap
1256 = &ecoff_backend (abfd
)->debug_swap
;
1260 (*debug_swap
->swap_sym_in
)
1262 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1263 + indx
* debug_swap
->external_sym_size
),
1265 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1269 "%s %s { ifd = %d, index = %ld }",
1272 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1275 /* Convert the type information to string format. */
1278 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1280 union aux_ext
*aux_ptr
;
1292 unsigned int basic_type
;
1294 static char buffer1
[1024];
1295 static char buffer2
[1024];
1300 for (i
= 0; i
< 7; i
++)
1302 qualifiers
[i
].low_bound
= 0;
1303 qualifiers
[i
].high_bound
= 0;
1304 qualifiers
[i
].stride
= 0;
1307 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1308 return "-1 (no type)";
1309 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1311 basic_type
= u
.ti
.bt
;
1312 qualifiers
[0].type
= u
.ti
.tq0
;
1313 qualifiers
[1].type
= u
.ti
.tq1
;
1314 qualifiers
[2].type
= u
.ti
.tq2
;
1315 qualifiers
[3].type
= u
.ti
.tq3
;
1316 qualifiers
[4].type
= u
.ti
.tq4
;
1317 qualifiers
[5].type
= u
.ti
.tq5
;
1318 qualifiers
[6].type
= tqNil
;
1321 * Go get the basic type.
1325 case btNil
: /* undefined */
1329 case btAdr
: /* address - integer same size as pointer */
1330 strcpy (p1
, "address");
1333 case btChar
: /* character */
1334 strcpy (p1
, "char");
1337 case btUChar
: /* unsigned character */
1338 strcpy (p1
, "unsigned char");
1341 case btShort
: /* short */
1342 strcpy (p1
, "short");
1345 case btUShort
: /* unsigned short */
1346 strcpy (p1
, "unsigned short");
1349 case btInt
: /* int */
1353 case btUInt
: /* unsigned int */
1354 strcpy (p1
, "unsigned int");
1357 case btLong
: /* long */
1358 strcpy (p1
, "long");
1361 case btULong
: /* unsigned long */
1362 strcpy (p1
, "unsigned long");
1365 case btFloat
: /* float (real) */
1366 strcpy (p1
, "float");
1369 case btDouble
: /* Double (real) */
1370 strcpy (p1
, "double");
1373 /* Structures add 1-2 aux words:
1374 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1375 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1377 case btStruct
: /* Structure (Record) */
1378 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1379 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1380 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1382 indx
++; /* skip aux words */
1385 /* Unions add 1-2 aux words:
1386 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1387 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1389 case btUnion
: /* Union */
1390 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1391 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1392 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1394 indx
++; /* skip aux words */
1397 /* Enumerations add 1-2 aux words:
1398 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1399 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1401 case btEnum
: /* Enumeration */
1402 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1403 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1404 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1406 indx
++; /* skip aux words */
1409 case btTypedef
: /* defined via a typedef, isymRef points */
1410 strcpy (p1
, "typedef");
1413 case btRange
: /* subrange of int */
1414 strcpy (p1
, "subrange");
1417 case btSet
: /* pascal sets */
1421 case btComplex
: /* fortran complex */
1422 strcpy (p1
, "complex");
1425 case btDComplex
: /* fortran double complex */
1426 strcpy (p1
, "double complex");
1429 case btIndirect
: /* forward or unnamed typedef */
1430 strcpy (p1
, "forward/unamed typedef");
1433 case btFixedDec
: /* Fixed Decimal */
1434 strcpy (p1
, "fixed decimal");
1437 case btFloatDec
: /* Float Decimal */
1438 strcpy (p1
, "float decimal");
1441 case btString
: /* Varying Length Character String */
1442 strcpy (p1
, "string");
1445 case btBit
: /* Aligned Bit String */
1449 case btPicture
: /* Picture */
1450 strcpy (p1
, "picture");
1453 case btVoid
: /* Void */
1454 strcpy (p1
, "void");
1458 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1462 p1
+= strlen (buffer1
);
1465 * If this is a bitfield, get the bitsize.
1471 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1472 sprintf (p1
, " : %d", bitsize
);
1473 p1
+= strlen (buffer1
);
1478 * Deal with any qualifiers.
1480 if (qualifiers
[0].type
!= tqNil
)
1483 * Snarf up any array bounds in the correct order. Arrays
1484 * store 5 successive words in the aux. table:
1485 * word 0 RNDXR to type of the bounds (ie, int)
1486 * word 1 Current file descriptor index
1488 * word 3 high bound (or -1 if [])
1489 * word 4 stride size in bits
1491 for (i
= 0; i
< 7; i
++)
1493 if (qualifiers
[i
].type
== tqArray
)
1495 qualifiers
[i
].low_bound
=
1496 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1497 qualifiers
[i
].high_bound
=
1498 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1499 qualifiers
[i
].stride
=
1500 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1506 * Now print out the qualifiers.
1508 for (i
= 0; i
< 6; i
++)
1510 switch (qualifiers
[i
].type
)
1517 strcpy (p2
, "ptr to ");
1518 p2
+= sizeof ("ptr to ")-1;
1522 strcpy (p2
, "volatile ");
1523 p2
+= sizeof ("volatile ")-1;
1527 strcpy (p2
, "far ");
1528 p2
+= sizeof ("far ")-1;
1532 strcpy (p2
, "func. ret. ");
1533 p2
+= sizeof ("func. ret. ");
1538 int first_array
= i
;
1541 /* Print array bounds reversed (ie, in the order the C
1542 programmer writes them). C is such a fun language.... */
1544 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1547 for (j
= i
; j
>= first_array
; j
--)
1549 strcpy (p2
, "array [");
1550 p2
+= sizeof ("array [")-1;
1551 if (qualifiers
[j
].low_bound
!= 0)
1553 "%ld:%ld {%ld bits}",
1554 (long) qualifiers
[j
].low_bound
,
1555 (long) qualifiers
[j
].high_bound
,
1556 (long) qualifiers
[j
].stride
);
1558 else if (qualifiers
[j
].high_bound
!= -1)
1561 (long) (qualifiers
[j
].high_bound
+ 1),
1562 (long) (qualifiers
[j
].stride
));
1565 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1568 strcpy (p2
, "] of ");
1569 p2
+= sizeof ("] of ")-1;
1577 strcpy (p2
, buffer1
);
1581 /* Return information about ECOFF symbol SYMBOL in RET. */
1585 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1586 bfd
*abfd
; /* Ignored. */
1590 bfd_symbol_info (symbol
, ret
);
1593 /* Print information about an ECOFF symbol. */
1596 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1600 bfd_print_symbol_type how
;
1602 const struct ecoff_debug_swap
* const debug_swap
1603 = &ecoff_backend (abfd
)->debug_swap
;
1604 FILE *file
= (FILE *)filep
;
1608 case bfd_print_symbol_name
:
1609 fprintf (file
, "%s", symbol
->name
);
1611 case bfd_print_symbol_more
:
1612 if (ecoffsymbol (symbol
)->local
)
1616 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1618 fprintf (file
, "ecoff local ");
1619 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1620 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1621 (unsigned) ecoff_sym
.sc
);
1627 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1629 fprintf (file
, "ecoff extern ");
1630 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1631 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1632 (unsigned) ecoff_ext
.asym
.sc
);
1635 case bfd_print_symbol_all
:
1636 /* Print out the symbols in a reasonable way */
1645 if (ecoffsymbol (symbol
)->local
)
1647 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1650 pos
= ((((char *) ecoffsymbol (symbol
)->native
1651 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1652 / debug_swap
->external_sym_size
)
1653 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1660 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1663 pos
= (((char *) ecoffsymbol (symbol
)->native
1664 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1665 / debug_swap
->external_ext_size
);
1666 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1667 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1668 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1671 fprintf (file
, "[%3d] %c ",
1673 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1674 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1675 (unsigned) ecoff_ext
.asym
.st
,
1676 (unsigned) ecoff_ext
.asym
.sc
,
1677 (unsigned) ecoff_ext
.asym
.index
,
1678 jmptbl
, cobol_main
, weakext
,
1681 if (ecoffsymbol (symbol
)->fdr
!= NULL
1682 && ecoff_ext
.asym
.index
!= indexNil
)
1686 bfd_size_type sym_base
;
1687 union aux_ext
*aux_base
;
1689 indx
= ecoff_ext
.asym
.index
;
1691 /* sym_base is used to map the fdr relative indices which
1692 appear in the file to the position number which we are
1694 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1695 if (ecoffsymbol (symbol
)->local
)
1697 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1699 /* aux_base is the start of the aux entries for this file;
1700 asym.index is an offset from this. */
1701 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1702 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1704 /* The aux entries are stored in host byte order; the
1705 order is indicated by a bit in the fdr. */
1706 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1708 /* This switch is basically from gcc/mips-tdump.c */
1709 switch (ecoff_ext
.asym
.st
)
1717 fprintf (file
, "\n End+1 symbol: %ld",
1718 (long) (indx
+ sym_base
));
1722 if (ecoff_ext
.asym
.sc
== scText
1723 || ecoff_ext
.asym
.sc
== scInfo
)
1724 fprintf (file
, "\n First symbol: %ld",
1725 (long) (indx
+ sym_base
));
1727 fprintf (file
, "\n First symbol: %ld",
1728 (long) (AUX_GET_ISYM (bigendian
,
1729 &aux_base
[ecoff_ext
.asym
.index
])
1735 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1737 else if (ecoffsymbol (symbol
)->local
)
1738 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1739 (long) (AUX_GET_ISYM (bigendian
,
1740 &aux_base
[ecoff_ext
.asym
.index
])
1742 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1745 fprintf (file
, "\n Local symbol: %ld",
1748 + (ecoff_data (abfd
)
1749 ->debug_info
.symbolic_header
.iextMax
)));
1753 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1754 fprintf (file
, "\n Type: %s",
1755 ecoff_type_to_string (abfd
, aux_base
, indx
,
1765 /* Read in the relocs for a section. */
1768 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1773 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1774 arelent
*internal_relocs
;
1775 bfd_size_type external_reloc_size
;
1776 bfd_size_type external_relocs_size
;
1777 char *external_relocs
;
1781 if (section
->relocation
!= (arelent
*) NULL
1782 || section
->reloc_count
== 0
1783 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1786 if (ecoff_slurp_symbol_table (abfd
) == false)
1789 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1791 * section
->reloc_count
));
1792 external_reloc_size
= backend
->external_reloc_size
;
1793 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1794 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1795 if (internal_relocs
== (arelent
*) NULL
1796 || external_relocs
== (char *) NULL
)
1798 bfd_error
= no_memory
;
1801 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1803 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1804 != external_relocs_size
)
1806 bfd_error
= system_call_error
;
1810 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1812 struct internal_reloc intern
;
1814 (*backend
->swap_reloc_in
) (abfd
,
1815 external_relocs
+ i
* external_reloc_size
,
1818 if (intern
.r_extern
)
1820 /* r_symndx is an index into the external symbols. */
1821 BFD_ASSERT (intern
.r_symndx
>= 0
1823 < (ecoff_data (abfd
)
1824 ->debug_info
.symbolic_header
.iextMax
)));
1825 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1828 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1829 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1831 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1836 CONST
char *sec_name
;
1839 /* r_symndx is a section key. */
1840 switch (intern
.r_symndx
)
1842 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1843 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1844 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1845 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1846 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1847 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1848 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1849 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1850 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1851 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1852 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1853 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1854 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1858 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1859 if (sec
== (asection
*) NULL
)
1861 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1863 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1866 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1868 /* Let the backend select the howto field and do any other
1869 required processing. */
1870 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1873 bfd_release (abfd
, external_relocs
);
1875 section
->relocation
= internal_relocs
;
1880 /* Get a canonical list of relocs. */
1883 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1891 if (section
->flags
& SEC_CONSTRUCTOR
)
1893 arelent_chain
*chain
;
1895 /* This section has relocs made up by us, not the file, so take
1896 them out of their chain and place them into the data area
1898 for (count
= 0, chain
= section
->constructor_chain
;
1899 count
< section
->reloc_count
;
1900 count
++, chain
= chain
->next
)
1901 *relptr
++ = &chain
->relent
;
1907 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1910 tblptr
= section
->relocation
;
1911 if (tblptr
== (arelent
*) NULL
)
1914 for (count
= 0; count
< section
->reloc_count
; count
++)
1915 *relptr
++ = tblptr
++;
1918 *relptr
= (arelent
*) NULL
;
1920 return section
->reloc_count
;
1923 /* Provided a BFD, a section and an offset into the section, calculate
1924 and return the name of the source file and the line nearest to the
1929 ecoff_find_nearest_line (abfd
,
1938 asymbol
**ignore_symbols
;
1940 CONST
char **filename_ptr
;
1941 CONST
char **functionname_ptr
;
1942 unsigned int *retline_ptr
;
1944 const struct ecoff_debug_swap
* const debug_swap
1945 = &ecoff_backend (abfd
)->debug_swap
;
1950 bfd_size_type external_pdr_size
;
1954 unsigned char *line_ptr
;
1955 unsigned char *line_end
;
1958 /* If we're not in the .text section, we don't have any line
1960 if (strcmp (section
->name
, _TEXT
) != 0
1961 || offset
< ecoff_data (abfd
)->text_start
1962 || offset
>= ecoff_data (abfd
)->text_end
)
1965 /* Make sure we have the FDR's. */
1966 if (ecoff_slurp_symbolic_info (abfd
) == false
1967 || bfd_get_symcount (abfd
) == 0)
1970 /* Each file descriptor (FDR) has a memory address. Here we track
1971 down which FDR we want. The FDR's are stored in increasing
1972 memory order. If speed is ever important, this can become a
1973 binary search. We must ignore FDR's with no PDR entries; they
1974 will have the adr of the FDR before or after them. */
1975 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1976 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1977 fdr_hold
= (FDR
*) NULL
;
1978 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1980 if (fdr_ptr
->cpd
== 0)
1982 if (offset
< fdr_ptr
->adr
)
1986 if (fdr_hold
== (FDR
*) NULL
)
1990 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1991 have an address, which is relative to the FDR address, and are
1992 also stored in increasing memory order. */
1993 offset
-= fdr_ptr
->adr
;
1994 external_pdr_size
= debug_swap
->external_pdr_size
;
1995 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
1996 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1997 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1998 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2000 /* The address of the first PDR is an offset which applies to the
2001 addresses of all the PDR's. */
2004 for (pdr_ptr
+= external_pdr_size
;
2006 pdr_ptr
+= external_pdr_size
)
2008 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2009 if (offset
< pdr
.adr
)
2013 /* Now we can look for the actual line number. The line numbers are
2014 stored in a very funky format, which I won't try to describe.
2015 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2016 we want; we need this to compute line_end. */
2017 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2018 if (pdr_ptr
== pdr_end
)
2019 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2021 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2023 /* Now change pdr and pdr_ptr to the one we want. */
2024 pdr_ptr
-= external_pdr_size
;
2025 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2029 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2030 + fdr_ptr
->cbLineOffset
2031 + pdr
.cbLineOffset
);
2032 while (line_ptr
< line_end
)
2037 delta
= *line_ptr
>> 4;
2040 count
= (*line_ptr
& 0xf) + 1;
2044 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2045 if (delta
>= 0x8000)
2050 if (offset
< count
* 4)
2052 offset
-= count
* 4;
2055 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2056 at least according to gdb/mipsread.c. */
2057 if (fdr_ptr
->rss
== -1)
2059 *filename_ptr
= NULL
;
2061 *functionname_ptr
= NULL
;
2066 (*debug_swap
->swap_ext_in
)
2068 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2069 + pdr
.isym
* debug_swap
->external_ext_size
),
2071 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2072 + proc_ext
.asym
.iss
);
2079 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2082 (*debug_swap
->swap_sym_in
)
2084 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2085 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2087 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2091 if (lineno
== ilineNil
)
2093 *retline_ptr
= lineno
;
2097 /* Set the architecture. The supported architecture is stored in the
2098 backend pointer. We always set the architecture anyhow, since many
2099 callers ignore the return value. */
2102 ecoff_set_arch_mach (abfd
, arch
, machine
)
2104 enum bfd_architecture arch
;
2105 unsigned long machine
;
2107 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2108 return arch
== ecoff_backend (abfd
)->arch
;
2111 /* Get the size of the section headers. We do not output the .reginfo
2116 ecoff_sizeof_headers (abfd
, reloc
)
2124 for (current
= abfd
->sections
;
2125 current
!= (asection
*)NULL
;
2126 current
= current
->next
)
2127 if (strcmp (current
->name
, REGINFO
) != 0)
2130 return (bfd_coff_filhsz (abfd
)
2131 + bfd_coff_aoutsz (abfd
)
2132 + c
* bfd_coff_scnhsz (abfd
));
2135 /* Get the contents of a section. This is where we handle reading the
2136 .reginfo section, which implicitly holds the contents of an
2137 ecoff_reginfo structure. */
2140 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2145 bfd_size_type count
;
2147 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2148 struct ecoff_reginfo s
;
2151 if (strcmp (section
->name
, REGINFO
) != 0)
2152 return bfd_generic_get_section_contents (abfd
, section
, location
,
2155 s
.gp_value
= tdata
->gp
;
2156 s
.gprmask
= tdata
->gprmask
;
2157 for (i
= 0; i
< 4; i
++)
2158 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2159 s
.fprmask
= tdata
->fprmask
;
2161 /* bfd_get_section_contents has already checked that the offset and
2162 size is reasonable. We don't have to worry about swapping or any
2163 such thing; the .reginfo section is defined such that the
2164 contents are an ecoff_reginfo structure as seen on the host. */
2165 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2169 /* Calculate the file position for each section, and set
2173 ecoff_compute_section_file_positions (abfd
)
2181 sofar
= ecoff_sizeof_headers (abfd
, false);
2184 for (current
= abfd
->sections
;
2185 current
!= (asection
*) NULL
;
2186 current
= current
->next
)
2188 unsigned int alignment_power
;
2190 /* Only deal with sections which have contents */
2191 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2192 || strcmp (current
->name
, REGINFO
) == 0)
2195 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2196 supposed to indicate the number of .pdata entries that are
2197 really in the section. Each entry is 8 bytes. We store this
2198 away in line_filepos before increasing the section size. */
2199 if (strcmp (current
->name
, _PDATA
) != 0)
2200 alignment_power
= current
->alignment_power
;
2203 current
->line_filepos
= current
->_raw_size
/ 8;
2204 alignment_power
= 4;
2207 /* On Ultrix, the data sections in an executable file must be
2208 aligned to a page boundary within the file. This does not
2209 affect the section size, though. FIXME: Does this work for
2210 other platforms? It requires some modification for the
2211 Alpha, because .rdata on the Alpha goes with the text, not
2213 if ((abfd
->flags
& EXEC_P
) != 0
2214 && (abfd
->flags
& D_PAGED
) != 0
2215 && first_data
!= false
2216 && (current
->flags
& SEC_CODE
) == 0
2217 && (! ecoff_backend (abfd
)->rdata_in_text
2218 || strcmp (current
->name
, _RDATA
) != 0)
2219 && strcmp (current
->name
, _PDATA
) != 0)
2221 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2223 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2227 /* Align the sections in the file to the same boundary on
2228 which they are aligned in virtual memory. */
2230 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2232 current
->filepos
= sofar
;
2234 sofar
+= current
->_raw_size
;
2236 /* make sure that this section is of the right size too */
2238 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2239 current
->_raw_size
+= sofar
- old_sofar
;
2242 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2245 /* Determine the location of the relocs for all the sections in the
2246 output file, as well as the location of the symbolic debugging
2249 static bfd_size_type
2250 ecoff_compute_reloc_file_positions (abfd
)
2253 const bfd_size_type external_reloc_size
=
2254 ecoff_backend (abfd
)->external_reloc_size
;
2255 file_ptr reloc_base
;
2256 bfd_size_type reloc_size
;
2260 if (! abfd
->output_has_begun
)
2262 ecoff_compute_section_file_positions (abfd
);
2263 abfd
->output_has_begun
= true;
2266 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2269 for (current
= abfd
->sections
;
2270 current
!= (asection
*)NULL
;
2271 current
= current
->next
)
2273 if (strcmp (current
->name
, REGINFO
) == 0)
2275 if (current
->reloc_count
== 0)
2276 current
->rel_filepos
= 0;
2279 bfd_size_type relsize
;
2281 current
->rel_filepos
= reloc_base
;
2282 relsize
= current
->reloc_count
* external_reloc_size
;
2283 reloc_size
+= relsize
;
2284 reloc_base
+= relsize
;
2288 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2290 /* At least on Ultrix, the symbol table of an executable file must
2291 be aligned to a page boundary. FIXME: Is this true on other
2293 if ((abfd
->flags
& EXEC_P
) != 0
2294 && (abfd
->flags
& D_PAGED
) != 0)
2295 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2296 &~ (ecoff_backend (abfd
)->round
- 1));
2298 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2303 /* Set the contents of a section. This is where we handle setting the
2304 contents of the .reginfo section, which implicitly holds a
2305 ecoff_reginfo structure. */
2308 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2313 bfd_size_type count
;
2315 /* This must be done first, because bfd_set_section_contents is
2316 going to set output_has_begun to true. */
2317 if (abfd
->output_has_begun
== false)
2318 ecoff_compute_section_file_positions (abfd
);
2323 if (strcmp (section
->name
, REGINFO
) == 0)
2325 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2326 struct ecoff_reginfo s
;
2329 /* If the caller is only changing part of the structure, we must
2330 retrieve the current information before the memcpy. */
2331 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2333 s
.gp_value
= tdata
->gp
;
2334 s
.gprmask
= tdata
->gprmask
;
2335 for (i
= 0; i
< 4; i
++)
2336 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2337 s
.fprmask
= tdata
->fprmask
;
2340 /* bfd_set_section_contents has already checked that the offset
2341 and size is reasonable. We don't have to worry about
2342 swapping or any such thing; the .reginfo section is defined
2343 such that the contents are an ecoff_reginfo structure as seen
2345 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2347 tdata
->gp
= s
.gp_value
;
2348 tdata
->gprmask
= s
.gprmask
;
2349 for (i
= 0; i
< 4; i
++)
2350 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2351 tdata
->fprmask
= s
.fprmask
;
2356 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2357 || bfd_write (location
, 1, count
, abfd
) != count
)
2363 /* Get ECOFF EXTR information for an external symbol. This function
2364 is passed to bfd_ecoff_debug_externals. */
2367 ecoff_get_extr (sym
, esym
)
2371 ecoff_symbol_type
*ecoff_sym_ptr
;
2374 /* Don't include debugging, local or section symbols. */
2375 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2376 || (sym
->flags
& BSF_LOCAL
) != 0
2377 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2380 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2381 || ecoffsymbol (sym
)->native
== NULL
)
2384 esym
->cobol_main
= 0;
2388 /* FIXME: we can do better than this for st and sc. */
2389 esym
->asym
.st
= stGlobal
;
2390 esym
->asym
.sc
= scAbs
;
2391 esym
->asym
.reserved
= 0;
2392 esym
->asym
.index
= indexNil
;
2396 ecoff_sym_ptr
= ecoffsymbol (sym
);
2398 if (ecoff_sym_ptr
->local
)
2401 input_bfd
= bfd_asymbol_bfd (sym
);
2402 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2403 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2405 /* If the symbol was defined by the linker, then esym will be
2406 undefined but sym will not be. Get a better class for such a
2408 if ((esym
->asym
.sc
== scUndefined
2409 || esym
->asym
.sc
== scSUndefined
)
2410 && bfd_get_section (sym
) != &bfd_und_section
)
2411 esym
->asym
.sc
= scAbs
;
2413 /* Adjust the FDR index for the symbol by that used for the input
2415 if (esym
->ifd
!= -1)
2417 struct ecoff_debug_info
*input_debug
;
2419 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2420 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2421 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2422 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2428 /* Set the external symbol index. This routine is passed to
2429 bfd_ecoff_debug_externals. */
2432 ecoff_set_index (sym
, indx
)
2436 ecoff_set_sym_index (sym
, indx
);
2439 /* Write out an ECOFF file. */
2442 ecoff_write_object_contents (abfd
)
2445 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2446 const bfd_vma round
= backend
->round
;
2447 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2448 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2449 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2450 const bfd_size_type external_hdr_size
2451 = backend
->debug_swap
.external_hdr_size
;
2452 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2453 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2455 struct internal_reloc
*))
2456 = backend
->adjust_reloc_out
;
2457 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2458 const struct internal_reloc
*,
2460 = backend
->swap_reloc_out
;
2461 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2462 HDRR
* const symhdr
= &debug
->symbolic_header
;
2465 bfd_size_type reloc_size
;
2466 unsigned long text_size
;
2467 unsigned long text_start
;
2468 unsigned long data_size
;
2469 unsigned long data_start
;
2470 unsigned long bss_size
;
2472 struct internal_filehdr internal_f
;
2473 struct internal_aouthdr internal_a
;
2476 bfd_error
= system_call_error
;
2478 /* Determine where the sections and relocs will go in the output
2480 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2483 for (current
= abfd
->sections
;
2484 current
!= (asection
*)NULL
;
2485 current
= current
->next
)
2487 if (strcmp (current
->name
, REGINFO
) == 0)
2489 current
->target_index
= count
;
2493 if ((abfd
->flags
& D_PAGED
) != 0)
2494 text_size
= ecoff_sizeof_headers (abfd
, false);
2502 /* Write section headers to the file. */
2504 buff
= (PTR
) alloca (scnhsz
);
2505 internal_f
.f_nscns
= 0;
2506 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2508 for (current
= abfd
->sections
;
2509 current
!= (asection
*) NULL
;
2510 current
= current
->next
)
2512 struct internal_scnhdr section
;
2515 if (strcmp (current
->name
, REGINFO
) == 0)
2517 BFD_ASSERT (current
->reloc_count
== 0);
2521 ++internal_f
.f_nscns
;
2523 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2525 /* FIXME: is this correct for shared libraries? I think it is
2526 but I have no platform to check. Ian Lance Taylor. */
2527 vma
= bfd_get_section_vma (abfd
, current
);
2528 if (strcmp (current
->name
, _LIB
) == 0)
2529 section
.s_vaddr
= 0;
2531 section
.s_vaddr
= vma
;
2533 section
.s_paddr
= vma
;
2534 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2536 /* If this section is unloadable then the scnptr will be 0. */
2537 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2538 section
.s_scnptr
= 0;
2540 section
.s_scnptr
= current
->filepos
;
2541 section
.s_relptr
= current
->rel_filepos
;
2543 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2544 object file produced by the assembler is supposed to point to
2545 information about how much room is required by objects of
2546 various different sizes. I think this only matters if we
2547 want the linker to compute the best size to use, or
2548 something. I don't know what happens if the information is
2550 if (strcmp (current
->name
, _PDATA
) != 0)
2551 section
.s_lnnoptr
= 0;
2554 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2555 hold the number of entries in the section (each entry is
2556 8 bytes). We stored this in the line_filepos field in
2557 ecoff_compute_section_file_positions. */
2558 section
.s_lnnoptr
= current
->line_filepos
;
2561 section
.s_nreloc
= current
->reloc_count
;
2562 section
.s_nlnno
= 0;
2563 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2566 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2567 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2570 if ((section
.s_flags
& STYP_TEXT
) != 0
2571 || ((section
.s_flags
& STYP_RDATA
) != 0
2572 && backend
->rdata_in_text
)
2573 || strcmp (current
->name
, _PDATA
) == 0)
2575 text_size
+= bfd_get_section_size_before_reloc (current
);
2576 if (text_start
== 0 || text_start
> vma
)
2579 else if ((section
.s_flags
& STYP_RDATA
) != 0
2580 || (section
.s_flags
& STYP_DATA
) != 0
2581 || (section
.s_flags
& STYP_LITA
) != 0
2582 || (section
.s_flags
& STYP_LIT8
) != 0
2583 || (section
.s_flags
& STYP_LIT4
) != 0
2584 || (section
.s_flags
& STYP_SDATA
) != 0
2585 || strcmp (current
->name
, _XDATA
) == 0)
2587 data_size
+= bfd_get_section_size_before_reloc (current
);
2588 if (data_start
== 0 || data_start
> vma
)
2591 else if ((section
.s_flags
& STYP_BSS
) != 0
2592 || (section
.s_flags
& STYP_SBSS
) != 0)
2593 bss_size
+= bfd_get_section_size_before_reloc (current
);
2598 /* Set up the file header. */
2600 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2602 /* We will NOT put a fucking timestamp in the header here. Every
2603 time you put it back, I will come in and take it out again. I'm
2604 sorry. This field does not belong here. We fill it with a 0 so
2605 it compares the same but is not a reasonable time. --
2607 internal_f
.f_timdat
= 0;
2609 if (bfd_get_symcount (abfd
) != 0)
2611 /* The ECOFF f_nsyms field is not actually the number of
2612 symbols, it's the size of symbolic information header. */
2613 internal_f
.f_nsyms
= external_hdr_size
;
2614 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2618 internal_f
.f_nsyms
= 0;
2619 internal_f
.f_symptr
= 0;
2622 internal_f
.f_opthdr
= aoutsz
;
2624 internal_f
.f_flags
= F_LNNO
;
2625 if (reloc_size
== 0)
2626 internal_f
.f_flags
|= F_RELFLG
;
2627 if (bfd_get_symcount (abfd
) == 0)
2628 internal_f
.f_flags
|= F_LSYMS
;
2629 if (abfd
->flags
& EXEC_P
)
2630 internal_f
.f_flags
|= F_EXEC
;
2632 if (! abfd
->xvec
->byteorder_big_p
)
2633 internal_f
.f_flags
|= F_AR32WR
;
2635 internal_f
.f_flags
|= F_AR32W
;
2637 /* Set up the ``optional'' header. */
2638 if ((abfd
->flags
& D_PAGED
) != 0)
2639 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2641 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2643 /* FIXME: Is this really correct? */
2644 internal_a
.vstamp
= symhdr
->vstamp
;
2646 /* At least on Ultrix, these have to be rounded to page boundaries.
2647 FIXME: Is this true on other platforms? */
2648 if ((abfd
->flags
& D_PAGED
) != 0)
2650 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2651 internal_a
.text_start
= text_start
&~ (round
- 1);
2652 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2653 internal_a
.data_start
= data_start
&~ (round
- 1);
2657 internal_a
.tsize
= text_size
;
2658 internal_a
.text_start
= text_start
;
2659 internal_a
.dsize
= data_size
;
2660 internal_a
.data_start
= data_start
;
2663 /* On Ultrix, the initial portions of the .sbss and .bss segments
2664 are at the end of the data section. The bsize field in the
2665 optional header records how many bss bytes are required beyond
2666 those in the data section. The value is not rounded to a page
2668 if (bss_size
< internal_a
.dsize
- data_size
)
2671 bss_size
-= internal_a
.dsize
- data_size
;
2672 internal_a
.bsize
= bss_size
;
2673 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2675 internal_a
.entry
= bfd_get_start_address (abfd
);
2677 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2679 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2680 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2681 for (i
= 0; i
< 4; i
++)
2682 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2684 /* Write out the file header and the optional header. */
2686 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2689 buff
= (PTR
) alloca (filhsz
);
2690 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2691 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2694 buff
= (PTR
) alloca (aoutsz
);
2695 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2696 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2699 /* Build the external symbol information. This must be done before
2700 writing out the relocs so that we know the symbol indices. The
2701 condition checks makes sure this object was not created by
2702 ecoff_bfd_final_link, since if it was we do not want to tamper
2703 with the external symbols. */
2704 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2706 symhdr
->iextMax
= 0;
2707 symhdr
->issExtMax
= 0;
2708 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2709 debug
->ssext
= debug
->ssext_end
= NULL
;
2710 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2711 (((abfd
->flags
& EXEC_P
) == 0)
2713 ecoff_get_extr
, ecoff_set_index
)
2717 /* Write out the relocs. */
2718 for (current
= abfd
->sections
;
2719 current
!= (asection
*) NULL
;
2720 current
= current
->next
)
2722 arelent
**reloc_ptr_ptr
;
2723 arelent
**reloc_end
;
2726 if (current
->reloc_count
== 0)
2729 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2732 bfd_error
= no_memory
;
2736 reloc_ptr_ptr
= current
->orelocation
;
2737 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2738 out_ptr
= (char *) buff
;
2740 reloc_ptr_ptr
< reloc_end
;
2741 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2745 struct internal_reloc in
;
2747 memset (&in
, 0, sizeof in
);
2749 reloc
= *reloc_ptr_ptr
;
2750 sym
= *reloc
->sym_ptr_ptr
;
2752 in
.r_vaddr
= (reloc
->address
2753 + bfd_get_section_vma (abfd
, current
));
2754 in
.r_type
= reloc
->howto
->type
;
2756 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2758 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2765 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2766 if (strcmp (name
, ".text") == 0)
2767 in
.r_symndx
= RELOC_SECTION_TEXT
;
2768 else if (strcmp (name
, ".rdata") == 0)
2769 in
.r_symndx
= RELOC_SECTION_RDATA
;
2770 else if (strcmp (name
, ".data") == 0)
2771 in
.r_symndx
= RELOC_SECTION_DATA
;
2772 else if (strcmp (name
, ".sdata") == 0)
2773 in
.r_symndx
= RELOC_SECTION_SDATA
;
2774 else if (strcmp (name
, ".sbss") == 0)
2775 in
.r_symndx
= RELOC_SECTION_SBSS
;
2776 else if (strcmp (name
, ".bss") == 0)
2777 in
.r_symndx
= RELOC_SECTION_BSS
;
2778 else if (strcmp (name
, ".init") == 0)
2779 in
.r_symndx
= RELOC_SECTION_INIT
;
2780 else if (strcmp (name
, ".lit8") == 0)
2781 in
.r_symndx
= RELOC_SECTION_LIT8
;
2782 else if (strcmp (name
, ".lit4") == 0)
2783 in
.r_symndx
= RELOC_SECTION_LIT4
;
2784 else if (strcmp (name
, ".xdata") == 0)
2785 in
.r_symndx
= RELOC_SECTION_XDATA
;
2786 else if (strcmp (name
, ".pdata") == 0)
2787 in
.r_symndx
= RELOC_SECTION_PDATA
;
2788 else if (strcmp (name
, ".fini") == 0)
2789 in
.r_symndx
= RELOC_SECTION_FINI
;
2790 else if (strcmp (name
, ".lita") == 0)
2791 in
.r_symndx
= RELOC_SECTION_LITA
;
2792 else if (strcmp (name
, "*ABS*") == 0)
2793 in
.r_symndx
= RELOC_SECTION_ABS
;
2799 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2801 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2804 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2806 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
2807 != external_reloc_size
* current
->reloc_count
)
2809 bfd_release (abfd
, buff
);
2812 /* Write out the symbolic debugging information. */
2813 if (bfd_get_symcount (abfd
) > 0)
2815 /* Write out the debugging information. */
2816 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2817 ecoff_data (abfd
)->sym_filepos
)
2821 else if ((abfd
->flags
& EXEC_P
) != 0
2822 && (abfd
->flags
& D_PAGED
) != 0)
2826 /* A demand paged executable must occupy an even number of
2828 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2831 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2833 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2836 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2844 /* Archive handling. ECOFF uses what appears to be a unique type of
2845 archive header (armap). The byte ordering of the armap and the
2846 contents are encoded in the name of the armap itself. At least for
2847 now, we only support archives with the same byte ordering in the
2848 armap and the contents.
2850 The first four bytes in the armap are the number of symbol
2851 definitions. This is always a power of two.
2853 This is followed by the symbol definitions. Each symbol definition
2854 occupies 8 bytes. The first four bytes are the offset from the
2855 start of the armap strings to the null-terminated string naming
2856 this symbol. The second four bytes are the file offset to the
2857 archive member which defines this symbol. If the second four bytes
2858 are 0, then this is not actually a symbol definition, and it should
2861 The symbols are hashed into the armap with a closed hashing scheme.
2862 See the functions below for the details of the algorithm.
2864 After the symbol definitions comes four bytes holding the size of
2865 the string table, followed by the string table itself. */
2867 /* The name of an archive headers looks like this:
2868 __________E[BL]E[BL]_ (with a trailing space).
2869 The trailing space is changed to an X if the archive is changed to
2870 indicate that the armap is out of date.
2872 The Alpha seems to use ________64E[BL]E[BL]_. */
2874 #define ARMAP_BIG_ENDIAN 'B'
2875 #define ARMAP_LITTLE_ENDIAN 'L'
2876 #define ARMAP_MARKER 'E'
2877 #define ARMAP_START_LENGTH 10
2878 #define ARMAP_HEADER_MARKER_INDEX 10
2879 #define ARMAP_HEADER_ENDIAN_INDEX 11
2880 #define ARMAP_OBJECT_MARKER_INDEX 12
2881 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2882 #define ARMAP_END_INDEX 14
2883 #define ARMAP_END "_ "
2885 /* This is a magic number used in the hashing algorithm. */
2886 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2888 /* This returns the hash value to use for a string. It also sets
2889 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2890 is the number of entries in the hash table, and HLOG is the log
2894 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2896 unsigned int *rehash
;
2904 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2905 hash
*= ARMAP_HASH_MAGIC
;
2906 *rehash
= (hash
& (size
- 1)) | 1;
2907 return hash
>> (32 - hlog
);
2910 /* Read in the armap. */
2913 ecoff_slurp_armap (abfd
)
2918 struct areltdata
*mapdata
;
2919 bfd_size_type parsed_size
;
2921 struct artdata
*ardata
;
2924 struct symdef
*symdef_ptr
;
2927 /* Get the name of the first element. */
2928 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2934 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2936 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2937 standard COFF armap. We could move the ECOFF armap stuff into
2938 bfd_slurp_armap, but that seems inappropriate since no other
2939 target uses this format. Instead, we check directly for a COFF
2941 if (strncmp (nextname
, "/ ", 16) == 0)
2942 return bfd_slurp_armap (abfd
);
2944 /* See if the first element is an armap. */
2945 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2946 ARMAP_START_LENGTH
) != 0
2947 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2948 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2949 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2950 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2951 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2952 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2953 || strncmp (nextname
+ ARMAP_END_INDEX
,
2954 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2956 bfd_has_map (abfd
) = false;
2960 /* Make sure we have the right byte ordering. */
2961 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2962 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2963 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2964 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2966 bfd_error
= wrong_format
;
2970 /* Read in the armap. */
2971 ardata
= bfd_ardata (abfd
);
2972 mapdata
= _bfd_snarf_ar_hdr (abfd
);
2973 if (mapdata
== (struct areltdata
*) NULL
)
2975 parsed_size
= mapdata
->parsed_size
;
2976 bfd_release (abfd
, (PTR
) mapdata
);
2978 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2979 if (raw_armap
== (char *) NULL
)
2981 bfd_error
= no_memory
;
2985 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
2987 bfd_error
= malformed_archive
;
2988 bfd_release (abfd
, (PTR
) raw_armap
);
2992 ardata
->tdata
= (PTR
) raw_armap
;
2994 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
2996 ardata
->symdef_count
= 0;
2997 ardata
->cache
= (struct ar_cache
*) NULL
;
2999 /* This code used to overlay the symdefs over the raw archive data,
3000 but that doesn't work on a 64 bit host. */
3002 stringbase
= raw_armap
+ count
* 8 + 8;
3004 #ifdef CHECK_ARMAP_HASH
3008 /* Double check that I have the hashing algorithm right by making
3009 sure that every symbol can be looked up successfully. */
3011 for (i
= 1; i
< count
; i
<<= 1)
3013 BFD_ASSERT (i
== count
);
3015 raw_ptr
= raw_armap
+ 4;
3016 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3018 unsigned int name_offset
, file_offset
;
3019 unsigned int hash
, rehash
, srch
;
3021 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3022 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3023 if (file_offset
== 0)
3025 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3030 /* See if we can rehash to this location. */
3031 for (srch
= (hash
+ rehash
) & (count
- 1);
3032 srch
!= hash
&& srch
!= i
;
3033 srch
= (srch
+ rehash
) & (count
- 1))
3034 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3036 BFD_ASSERT (srch
== i
);
3040 #endif /* CHECK_ARMAP_HASH */
3042 raw_ptr
= raw_armap
+ 4;
3043 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3044 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3045 ++ardata
->symdef_count
;
3047 symdef_ptr
= ((struct symdef
*)
3049 ardata
->symdef_count
* sizeof (struct symdef
)));
3050 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3052 raw_ptr
= raw_armap
+ 4;
3053 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3055 unsigned int name_offset
, file_offset
;
3057 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3058 if (file_offset
== 0)
3060 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3061 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3062 symdef_ptr
->file_offset
= file_offset
;
3066 ardata
->first_file_filepos
= bfd_tell (abfd
);
3067 /* Pad to an even boundary. */
3068 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3070 bfd_has_map (abfd
) = true;
3075 /* Write out an armap. */
3078 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3080 unsigned int elength
;
3082 unsigned int orl_count
;
3085 unsigned int hashsize
, hashlog
;
3086 unsigned int symdefsize
;
3088 unsigned int stringsize
;
3089 unsigned int mapsize
;
3092 struct stat statbuf
;
3095 bfd_byte
*hashtable
;
3099 /* Ultrix appears to use as a hash table size the least power of two
3100 greater than twice the number of entries. */
3101 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3103 hashsize
= 1 << hashlog
;
3105 symdefsize
= hashsize
* 8;
3107 stringsize
= stridx
+ padit
;
3109 /* Include 8 bytes to store symdefsize and stringsize in output. */
3110 mapsize
= symdefsize
+ stringsize
+ 8;
3112 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3114 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3116 /* Work out the ECOFF armap name. */
3117 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3118 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3119 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3120 (abfd
->xvec
->header_byteorder_big_p
3122 : ARMAP_LITTLE_ENDIAN
);
3123 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3124 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3125 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3126 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3128 /* Write the timestamp of the archive header to be just a little bit
3129 later than the timestamp of the file, otherwise the linker will
3130 complain that the index is out of date. Actually, the Ultrix
3131 linker just checks the archive name; the GNU linker may check the
3133 stat (abfd
->filename
, &statbuf
);
3134 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3136 /* The DECstation uses zeroes for the uid, gid and mode of the
3138 hdr
.ar_uid
[0] = '0';
3139 hdr
.ar_gid
[0] = '0';
3140 hdr
.ar_mode
[0] = '0';
3142 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3144 hdr
.ar_fmag
[0] = '`';
3145 hdr
.ar_fmag
[1] = '\012';
3147 /* Turn all null bytes in the header into spaces. */
3148 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3149 if (((char *)(&hdr
))[i
] == '\0')
3150 (((char *)(&hdr
))[i
]) = ' ';
3152 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3153 != sizeof (struct ar_hdr
))
3156 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3157 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3160 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3162 current
= abfd
->archive_head
;
3164 for (i
= 0; i
< orl_count
; i
++)
3166 unsigned int hash
, rehash
;
3168 /* Advance firstreal to the file position of this archive
3170 if (((bfd
*) map
[i
].pos
) != last_elt
)
3174 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3175 firstreal
+= firstreal
% 2;
3176 current
= current
->next
;
3178 while (current
!= (bfd
*) map
[i
].pos
);
3183 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3184 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3188 /* The desired slot is already taken. */
3189 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3191 srch
= (srch
+ rehash
) & (hashsize
- 1))
3192 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3195 BFD_ASSERT (srch
!= hash
);
3200 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3201 (PTR
) (hashtable
+ hash
* 8));
3202 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3203 (PTR
) (hashtable
+ hash
* 8 + 4));
3206 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3209 bfd_release (abfd
, hashtable
);
3211 /* Now write the strings. */
3212 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3213 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3215 for (i
= 0; i
< orl_count
; i
++)
3219 len
= strlen (*map
[i
].name
) + 1;
3220 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3224 /* The spec sez this should be a newline. But in order to be
3225 bug-compatible for DECstation ar we use a null. */
3228 if (bfd_write ("", 1, 1, abfd
) != 1)
3235 /* See whether this BFD is an archive. If it is, read in the armap
3236 and the extended name table. */
3239 ecoff_archive_p (abfd
)
3242 char armag
[SARMAG
+ 1];
3244 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3245 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3247 bfd_error
= wrong_format
;
3248 return (bfd_target
*) NULL
;
3251 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3252 involves a cast, we can't do it as the left operand of
3254 abfd
->tdata
.aout_ar_data
=
3255 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3257 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3259 bfd_error
= no_memory
;
3260 return (bfd_target
*) NULL
;
3263 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3264 bfd_ardata (abfd
)->cache
= NULL
;
3265 bfd_ardata (abfd
)->archive_head
= NULL
;
3266 bfd_ardata (abfd
)->symdefs
= NULL
;
3267 bfd_ardata (abfd
)->extended_names
= NULL
;
3268 bfd_ardata (abfd
)->tdata
= NULL
;
3270 if (ecoff_slurp_armap (abfd
) == false
3271 || ecoff_slurp_extended_name_table (abfd
) == false)
3273 bfd_release (abfd
, bfd_ardata (abfd
));
3274 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3275 return (bfd_target
*) NULL
;
3281 /* ECOFF linker code. */
3283 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3284 PARAMS ((struct bfd_hash_entry
*entry
,
3285 struct bfd_hash_table
*table
,
3286 const char *string
));
3287 static boolean ecoff_link_add_archive_symbols
3288 PARAMS ((bfd
*, struct bfd_link_info
*));
3289 static boolean ecoff_link_check_archive_element
3290 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3291 static boolean ecoff_link_add_object_symbols
3292 PARAMS ((bfd
*, struct bfd_link_info
*));
3293 static boolean ecoff_link_add_externals
3294 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3296 /* Routine to create an entry in an ECOFF link hash table. */
3298 static struct bfd_hash_entry
*
3299 ecoff_link_hash_newfunc (entry
, table
, string
)
3300 struct bfd_hash_entry
*entry
;
3301 struct bfd_hash_table
*table
;
3304 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3306 /* Allocate the structure if it has not already been allocated by a
3308 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3309 ret
= ((struct ecoff_link_hash_entry
*)
3310 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3312 /* Call the allocation method of the superclass. */
3313 ret
= ((struct ecoff_link_hash_entry
*)
3314 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3317 /* Set local fields. */
3320 memset (&ret
->esym
, 0, sizeof ret
->esym
);
3322 return (struct bfd_hash_entry
*) ret
;
3325 /* Create an ECOFF link hash table. */
3327 struct bfd_link_hash_table
*
3328 ecoff_bfd_link_hash_table_create (abfd
)
3331 struct ecoff_link_hash_table
*ret
;
3333 ret
= ((struct ecoff_link_hash_table
*)
3334 malloc (sizeof (struct ecoff_link_hash_table
)));
3337 bfd_error
= no_memory
;
3340 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3341 ecoff_link_hash_newfunc
))
3344 return (struct bfd_link_hash_table
*) NULL
;
3349 /* Look up an entry in an ECOFF link hash table. */
3351 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3352 ((struct ecoff_link_hash_entry *) \
3353 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3355 /* Traverse an ECOFF link hash table. */
3357 #define ecoff_link_hash_traverse(table, func, info) \
3358 (bfd_link_hash_traverse \
3360 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3363 /* Get the ECOFF link hash table from the info structure. This is
3366 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3368 /* Given an ECOFF BFD, add symbols to the global hash table as
3372 ecoff_bfd_link_add_symbols (abfd
, info
)
3374 struct bfd_link_info
*info
;
3376 switch (bfd_get_format (abfd
))
3379 return ecoff_link_add_object_symbols (abfd
, info
);
3381 return ecoff_link_add_archive_symbols (abfd
, info
);
3383 bfd_error
= wrong_format
;
3388 /* Add the symbols from an archive file to the global hash table.
3389 This looks through the undefined symbols, looks each one up in the
3390 archive hash table, and adds any associated object file. We do not
3391 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3392 already have a hash table, so there is no reason to construct
3396 ecoff_link_add_archive_symbols (abfd
, info
)
3398 struct bfd_link_info
*info
;
3400 const bfd_byte
*raw_armap
;
3401 struct bfd_link_hash_entry
**pundef
;
3402 unsigned int armap_count
;
3403 unsigned int armap_log
;
3405 const bfd_byte
*hashtable
;
3406 const char *stringbase
;
3408 if (! bfd_has_map (abfd
))
3410 bfd_error
= no_symbols
;
3414 /* If we don't have any raw data for this archive, as can happen on
3415 Irix 4.0.5F, we call the generic routine.
3416 FIXME: We should be more clever about this, since someday tdata
3417 may get to something for a generic archive. */
3418 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3419 if (raw_armap
== (bfd_byte
*) NULL
)
3420 return (_bfd_generic_link_add_archive_symbols
3421 (abfd
, info
, ecoff_link_check_archive_element
));
3423 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3426 for (i
= 1; i
< armap_count
; i
<<= 1)
3428 BFD_ASSERT (i
== armap_count
);
3430 hashtable
= raw_armap
+ 4;
3431 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3433 /* Look through the list of undefined symbols. */
3434 pundef
= &info
->hash
->undefs
;
3435 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3437 struct bfd_link_hash_entry
*h
;
3438 unsigned int hash
, rehash
;
3439 unsigned int file_offset
;
3445 /* When a symbol is defined, it is not necessarily removed from
3447 if (h
->type
!= bfd_link_hash_undefined
3448 && h
->type
!= bfd_link_hash_common
)
3450 /* Remove this entry from the list, for general cleanliness
3451 and because we are going to look through the list again
3452 if we search any more libraries. We can't remove the
3453 entry if it is the tail, because that would lose any
3454 entries we add to the list later on. */
3455 if (*pundef
!= info
->hash
->undefs_tail
)
3456 *pundef
= (*pundef
)->next
;
3458 pundef
= &(*pundef
)->next
;
3462 /* Native ECOFF linkers do not pull in archive elements merely
3463 to satisfy common definitions, so neither do we. We leave
3464 them on the list, though, in case we are linking against some
3465 other object format. */
3466 if (h
->type
!= bfd_link_hash_undefined
)
3468 pundef
= &(*pundef
)->next
;
3472 /* Look for this symbol in the archive hash table. */
3473 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3476 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3477 if (file_offset
== 0)
3479 /* Nothing in this slot. */
3480 pundef
= &(*pundef
)->next
;
3484 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3485 if (name
[0] != h
->root
.string
[0]
3486 || strcmp (name
, h
->root
.string
) != 0)
3491 /* That was the wrong symbol. Try rehashing. */
3493 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3495 srch
= (srch
+ rehash
) & (armap_count
- 1))
3497 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3498 if (file_offset
== 0)
3500 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3501 if (name
[0] == h
->root
.string
[0]
3502 && strcmp (name
, h
->root
.string
) == 0)
3511 pundef
= &(*pundef
)->next
;
3518 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3519 if (element
== (bfd
*) NULL
)
3522 if (! bfd_check_format (element
, bfd_object
))
3525 /* Unlike the generic linker, we know that this element provides
3526 a definition for an undefined symbol and we know that we want
3527 to include it. We don't need to check anything. */
3528 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3530 if (! ecoff_link_add_object_symbols (element
, info
))
3533 pundef
= &(*pundef
)->next
;
3539 /* This is called if we used _bfd_generic_link_add_archive_symbols
3540 because we were not dealing with an ECOFF archive. */
3543 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3545 struct bfd_link_info
*info
;
3548 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3549 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3550 = backend
->debug_swap
.swap_ext_in
;
3552 bfd_size_type external_ext_size
;
3561 if (! ecoff_slurp_symbolic_header (abfd
))
3564 /* If there are no symbols, we don't want it. */
3565 if (bfd_get_symcount (abfd
) == 0)
3568 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3570 /* Read in the external symbols and external strings. */
3571 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3572 esize
= symhdr
->iextMax
* external_ext_size
;
3573 external_ext
= (PTR
) alloca (esize
);
3574 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3575 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3578 ssext
= (char *) alloca (symhdr
->issExtMax
);
3579 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3580 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3583 /* Look through the external symbols to see if they define some
3584 symbol that is currently undefined. */
3585 ext_ptr
= (char *) external_ext
;
3586 ext_end
= ext_ptr
+ esize
;
3587 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3592 struct bfd_link_hash_entry
*h
;
3594 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3596 /* See if this symbol defines something. */
3597 if (esym
.asym
.st
!= stGlobal
3598 && esym
.asym
.st
!= stLabel
3599 && esym
.asym
.st
!= stProc
)
3602 switch (esym
.asym
.sc
)
3625 name
= ssext
+ esym
.asym
.iss
;
3626 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3628 /* Unlike the generic linker, we do not pull in elements because
3629 of common symbols. */
3630 if (h
== (struct bfd_link_hash_entry
*) NULL
3631 || h
->type
!= bfd_link_hash_undefined
)
3634 /* Include this element. */
3635 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3637 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3647 /* Add symbols from an ECOFF object file to the global linker hash
3651 ecoff_link_add_object_symbols (abfd
, info
)
3653 struct bfd_link_info
*info
;
3656 bfd_size_type external_ext_size
;
3661 if (! ecoff_slurp_symbolic_header (abfd
))
3664 /* If there are no symbols, we don't want it. */
3665 if (bfd_get_symcount (abfd
) == 0)
3668 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3670 /* Read in the external symbols and external strings. */
3671 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3672 esize
= symhdr
->iextMax
* external_ext_size
;
3673 external_ext
= (PTR
) alloca (esize
);
3674 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3675 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3678 ssext
= (char *) alloca (symhdr
->issExtMax
);
3679 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3680 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3683 return ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3686 /* Add the external symbols of an object file to the global linker
3687 hash table. The external symbols and strings we are passed are
3688 just allocated on the stack, and will be discarded. We must
3689 explicitly save any information we may need later on in the link.
3690 We do not want to read the external symbol information again. */
3693 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3695 struct bfd_link_info
*info
;
3699 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3700 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3701 = backend
->debug_swap
.swap_ext_in
;
3702 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3703 unsigned long ext_count
;
3704 struct ecoff_link_hash_entry
**sym_hash
;
3708 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3710 sym_hash
= ((struct ecoff_link_hash_entry
**)
3712 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3713 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3715 ext_ptr
= (char *) external_ext
;
3716 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3717 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3724 struct ecoff_link_hash_entry
*h
;
3728 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3730 /* Skip debugging symbols. */
3732 switch (esym
.asym
.st
)
3748 /* Get the information for this symbol. */
3749 value
= esym
.asym
.value
;
3750 switch (esym
.asym
.sc
)
3770 section
= bfd_make_section_old_way (abfd
, ".text");
3771 value
-= section
->vma
;
3774 section
= bfd_make_section_old_way (abfd
, ".data");
3775 value
-= section
->vma
;
3778 section
= bfd_make_section_old_way (abfd
, ".bss");
3779 value
-= section
->vma
;
3782 section
= &bfd_abs_section
;
3785 section
= &bfd_und_section
;
3788 section
= bfd_make_section_old_way (abfd
, ".sdata");
3789 value
-= section
->vma
;
3792 section
= bfd_make_section_old_way (abfd
, ".sbss");
3793 value
-= section
->vma
;
3796 section
= bfd_make_section_old_way (abfd
, ".rdata");
3797 value
-= section
->vma
;
3800 if (value
> ecoff_data (abfd
)->gp_size
)
3802 section
= &bfd_com_section
;
3807 if (ecoff_scom_section
.name
== NULL
)
3809 /* Initialize the small common section. */
3810 ecoff_scom_section
.name
= SCOMMON
;
3811 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3812 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3813 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3814 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3815 ecoff_scom_symbol
.name
= SCOMMON
;
3816 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3817 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3818 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3820 section
= &ecoff_scom_section
;
3823 section
= &bfd_und_section
;
3826 section
= bfd_make_section_old_way (abfd
, ".init");
3827 value
-= section
->vma
;
3830 section
= bfd_make_section_old_way (abfd
, ".fini");
3831 value
-= section
->vma
;
3835 if (section
== (asection
*) NULL
)
3838 name
= ssext
+ esym
.asym
.iss
;
3840 if (! (_bfd_generic_link_add_one_symbol
3841 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3842 (const char *) NULL
, true, true, backend
->constructor_bitsize
,
3843 (struct bfd_link_hash_entry
**) &h
)))
3848 /* If we are building an ECOFF hash table, save the external
3849 symbol information. */
3850 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3852 if (h
->abfd
== (bfd
*) NULL
3853 || (section
!= &bfd_und_section
3854 && (! bfd_is_com_section (section
)
3855 || h
->root
.type
!= bfd_link_hash_defined
)))
3866 /* ECOFF final link routines. */
3868 static boolean ecoff_final_link_debug_accumulate
3869 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
3871 static boolean ecoff_link_write_external
3872 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3873 static boolean ecoff_indirect_link_order
3874 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3875 struct bfd_link_order
*));
3877 /* ECOFF final link routine. This looks through all the input BFDs
3878 and gathers together all the debugging information, and then
3879 processes all the link order information. This may cause it to
3880 close and reopen some input BFDs; I'll see how bad this is. */
3883 ecoff_bfd_final_link (abfd
, info
)
3885 struct bfd_link_info
*info
;
3887 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3888 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3891 register bfd
*input_bfd
;
3893 struct bfd_link_order
*p
;
3895 /* We accumulate the debugging information counts in the symbolic
3897 symhdr
= &debug
->symbolic_header
;
3898 symhdr
->magic
= backend
->debug_swap
.sym_magic
;
3900 symhdr
->ilineMax
= 0;
3904 symhdr
->isymMax
= 0;
3905 symhdr
->ioptMax
= 0;
3906 symhdr
->iauxMax
= 0;
3908 symhdr
->issExtMax
= 0;
3911 symhdr
->iextMax
= 0;
3913 /* We accumulate the debugging information itself in the debug_info
3916 debug
->external_dnr
= NULL
;
3917 debug
->external_pdr
= NULL
;
3918 debug
->external_sym
= NULL
;
3919 debug
->external_opt
= NULL
;
3920 debug
->external_aux
= NULL
;
3922 debug
->ssext
= debug
->ssext_end
= NULL
;
3923 debug
->external_fdr
= NULL
;
3924 debug
->external_rfd
= NULL
;
3925 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3927 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
3928 if (handle
== (PTR
) NULL
)
3931 /* Accumulate the debugging symbols from each input BFD. */
3932 for (input_bfd
= info
->input_bfds
;
3933 input_bfd
!= (bfd
*) NULL
;
3934 input_bfd
= input_bfd
->link_next
)
3938 /* If we might be using the C based alloca function, dump memory
3939 allocated by ecoff_final_link_debug_accumulate. */
3946 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
3948 /* Abitrarily set the symbolic header vstamp to the vstamp
3949 of the first object file in the link. */
3950 if (symhdr
->vstamp
== 0)
3952 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
3953 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
3957 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
3958 debug
, &backend
->debug_swap
,
3963 /* Combine the register masks. */
3964 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
3965 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
3966 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
3967 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
3968 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
3969 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
3972 /* Write out the external symbols. */
3973 ecoff_link_hash_traverse (ecoff_hash_table (info
),
3974 ecoff_link_write_external
,
3977 if (info
->relocateable
)
3979 /* We need to make a pass over the link_orders to count up the
3980 number of relocations we will need to output, so that we know
3981 how much space they will take up. */
3982 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3985 for (p
= o
->link_order_head
;
3986 p
!= (struct bfd_link_order
*) NULL
;
3988 if (p
->type
== bfd_indirect_link_order
)
3989 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
3993 /* Compute the reloc and symbol file positions. */
3994 ecoff_compute_reloc_file_positions (abfd
);
3996 /* Write out the debugging information. */
3997 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
3998 &backend
->debug_swap
, info
,
3999 ecoff_data (abfd
)->sym_filepos
))
4002 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4004 if (info
->relocateable
)
4006 /* Now reset the reloc_count field of the sections in the output
4007 BFD to 0, so that we can use them to keep track of how many
4008 relocs we have output thus far. */
4009 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4013 /* Get a value for the GP register. */
4014 if (ecoff_data (abfd
)->gp
== 0)
4016 struct bfd_link_hash_entry
*h
;
4018 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4019 if (h
!= (struct bfd_link_hash_entry
*) NULL
4020 && h
->type
== bfd_link_hash_defined
)
4021 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4022 + h
->u
.def
.section
->output_section
->vma
4023 + h
->u
.def
.section
->output_offset
);
4024 else if (info
->relocateable
)
4028 /* Make up a value. */
4030 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4033 && (strcmp (o
->name
, _SBSS
) == 0
4034 || strcmp (o
->name
, _SDATA
) == 0
4035 || strcmp (o
->name
, _LIT4
) == 0
4036 || strcmp (o
->name
, _LIT8
) == 0
4037 || strcmp (o
->name
, _LITA
) == 0))
4040 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4044 /* If the relocate_section function needs to do a reloc
4045 involving the GP value, it should make a reloc_dangerous
4046 callback to warn that GP is not defined. */
4050 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4052 /* Ignore any link_orders for the .reginfo section, which does
4053 not really exist. */
4054 if (strcmp (o
->name
, REGINFO
) == 0)
4057 for (p
= o
->link_order_head
;
4058 p
!= (struct bfd_link_order
*) NULL
;
4061 /* If we might be using the C based alloca function, we need
4062 to dump the memory allocated by the function
4063 ecoff_indirect_link_order. */
4069 if (p
->type
== bfd_indirect_link_order
4070 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4071 == bfd_target_ecoff_flavour
))
4073 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4078 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4084 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4089 /* Accumulate the debugging information for an input BFD into the
4090 output BFD. This must read in the symbolic information of the
4094 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4097 struct bfd_link_info
*info
;
4100 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4101 const struct ecoff_debug_swap
* const swap
=
4102 &ecoff_backend (input_bfd
)->debug_swap
;
4103 HDRR
*symhdr
= &debug
->symbolic_header
;
4106 #define READ(ptr, offset, count, size, type) \
4107 if (symhdr->count == 0) \
4108 debug->ptr = NULL; \
4111 debug->ptr = (type) alloca (size * symhdr->count); \
4112 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4114 || (bfd_read (debug->ptr, size, symhdr->count, \
4115 input_bfd) != size * symhdr->count)) \
4119 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4120 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4121 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4122 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4123 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4124 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4126 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4127 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4128 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4131 /* We do not read the external strings or the external symbols. */
4133 ret
= (bfd_ecoff_debug_accumulate
4134 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4135 &ecoff_backend (output_bfd
)->debug_swap
,
4136 input_bfd
, debug
, swap
, info
));
4138 /* Make sure we don't accidentally follow one of these pointers on
4141 debug
->external_dnr
= NULL
;
4142 debug
->external_pdr
= NULL
;
4143 debug
->external_sym
= NULL
;
4144 debug
->external_opt
= NULL
;
4145 debug
->external_aux
= NULL
;
4147 debug
->external_fdr
= NULL
;
4148 debug
->external_rfd
= NULL
;
4153 /* Put out information for an external symbol. These come only from
4157 ecoff_link_write_external (h
, data
)
4158 struct ecoff_link_hash_entry
*h
;
4161 bfd
*output_bfd
= (bfd
*) data
;
4163 /* FIXME: We should check if this symbol is being stripped. */
4165 if (h
->root
.written
)
4168 if (h
->abfd
== (bfd
*) NULL
)
4171 h
->esym
.cobol_main
= 0;
4172 h
->esym
.weakext
= 0;
4173 h
->esym
.reserved
= 0;
4174 h
->esym
.ifd
= ifdNil
;
4175 h
->esym
.asym
.value
= 0;
4176 /* FIXME: we can do better than this for st and sc. */
4177 h
->esym
.asym
.st
= stGlobal
;
4178 h
->esym
.asym
.sc
= scAbs
;
4179 h
->esym
.asym
.reserved
= 0;
4180 h
->esym
.asym
.index
= indexNil
;
4182 else if (h
->esym
.ifd
!= -1)
4184 struct ecoff_debug_info
*debug
;
4186 /* Adjust the FDR index for the symbol by that used for the
4188 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4189 BFD_ASSERT (h
->esym
.ifd
>= 0
4190 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4191 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4194 switch (h
->root
.type
)
4197 case bfd_link_hash_new
:
4199 case bfd_link_hash_undefined
:
4200 case bfd_link_hash_weak
:
4201 if (h
->esym
.asym
.st
!= scUndefined
4202 && h
->esym
.asym
.st
!= scSUndefined
)
4203 h
->esym
.asym
.st
= scUndefined
;
4205 case bfd_link_hash_defined
:
4206 if (h
->esym
.asym
.sc
== scUndefined
4207 || h
->esym
.asym
.sc
== scSUndefined
)
4208 h
->esym
.asym
.sc
= scAbs
;
4209 else if (h
->esym
.asym
.sc
== scCommon
)
4210 h
->esym
.asym
.sc
= scBss
;
4211 else if (h
->esym
.asym
.sc
== scSCommon
)
4212 h
->esym
.asym
.sc
= scSBss
;
4213 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4214 + h
->root
.u
.def
.section
->output_section
->vma
4215 + h
->root
.u
.def
.section
->output_offset
);
4217 case bfd_link_hash_common
:
4218 if (h
->esym
.asym
.sc
!= scCommon
4219 && h
->esym
.asym
.sc
!= scSCommon
)
4220 h
->esym
.asym
.sc
= scCommon
;
4221 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4223 case bfd_link_hash_indirect
:
4224 case bfd_link_hash_warning
:
4225 /* FIXME: Ignore these for now. The circumstances under which
4226 they should be written out are not clear to me. */
4230 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4232 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4233 h
->root
.written
= true;
4235 return (bfd_ecoff_debug_one_external
4236 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4237 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4241 /* Relocate and write an ECOFF section into an ECOFF output file. */
4244 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4246 struct bfd_link_info
*info
;
4247 asection
*output_section
;
4248 struct bfd_link_order
*link_order
;
4250 asection
*input_section
;
4252 bfd_size_type input_size
;
4254 bfd_size_type external_reloc_size
;
4255 bfd_size_type external_relocs_size
;
4256 PTR external_relocs
;
4258 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4260 if (link_order
->size
== 0)
4263 input_section
= link_order
->u
.indirect
.section
;
4264 input_bfd
= input_section
->owner
;
4266 BFD_ASSERT (input_section
->output_section
== output_section
);
4267 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4268 BFD_ASSERT (bfd_section_size (input_bfd
, input_section
) == link_order
->size
);
4270 /* Get the section contents. */
4271 input_size
= bfd_section_size (input_bfd
, input_section
);
4272 contents
= (bfd_byte
*) alloca (input_size
);
4273 if (! bfd_get_section_contents (input_bfd
, input_section
, (PTR
) contents
,
4274 (file_ptr
) 0, input_size
))
4277 /* Get the relocs. */
4278 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4279 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4280 external_relocs
= (PTR
) alloca (external_relocs_size
);
4281 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4282 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4283 != external_relocs_size
))
4286 /* Relocate the section contents. */
4287 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4288 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4292 /* Write out the relocated section. */
4293 if (! bfd_set_section_contents (output_bfd
,
4296 input_section
->output_offset
,
4300 /* If we are producing relocateable output, the relocs were
4301 modified, and we write them out now. We use the reloc_count
4302 field of output_section to keep track of the number of relocs we
4303 have output so far. */
4304 if (info
->relocateable
)
4306 if (bfd_seek (output_bfd
,
4307 (output_section
->rel_filepos
+
4308 output_section
->reloc_count
* external_reloc_size
),
4310 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4311 != external_relocs_size
))
4313 output_section
->reloc_count
+= input_section
->reloc_count
;