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 boolean 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_set_error (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 | ((unsigned int) ext
->r_bits
[3]
554 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
558 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
563 /* Swap out a relative symbol record. BIGEND says whether it is in
564 big-endian or little-endian format.*/
567 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
570 struct rndx_ext
*ext
;
574 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
576 /* now the fun stuff... */
578 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
579 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
580 & RNDX_BITS1_RFD_BIG
)
581 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
582 & RNDX_BITS1_INDEX_BIG
));
583 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
584 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
586 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
587 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
588 & RNDX_BITS1_RFD_LITTLE
)
589 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
590 & RNDX_BITS1_INDEX_LITTLE
));
591 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
592 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
596 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
601 /* Read in the symbolic header for an ECOFF object file. */
604 ecoff_slurp_symbolic_header (abfd
)
607 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
608 bfd_size_type external_hdr_size
;
610 HDRR
*internal_symhdr
;
612 /* See if we've already read it in. */
613 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
614 backend
->debug_swap
.sym_magic
)
617 /* See whether there is a symbolic header. */
618 if (ecoff_data (abfd
)->sym_filepos
== 0)
620 bfd_get_symcount (abfd
) = 0;
624 /* At this point bfd_get_symcount (abfd) holds the number of symbols
625 as read from the file header, but on ECOFF this is always the
626 size of the symbolic information header. It would be cleaner to
627 handle this when we first read the file in coffgen.c. */
628 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
629 if (bfd_get_symcount (abfd
) != external_hdr_size
)
631 bfd_set_error (bfd_error_bad_value
);
635 /* Read the symbolic information header. */
636 raw
= (PTR
) alloca ((size_t) external_hdr_size
);
637 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
638 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
639 != external_hdr_size
))
641 bfd_set_error (bfd_error_system_call
);
644 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
645 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
647 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
649 bfd_set_error (bfd_error_bad_value
);
653 /* Now we can get the correct number of symbols. */
654 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
655 + internal_symhdr
->iextMax
);
660 /* Read in and swap the important symbolic information for an ECOFF
661 object file. This is called by gdb. */
664 ecoff_slurp_symbolic_info (abfd
)
667 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
668 HDRR
*internal_symhdr
;
669 bfd_size_type raw_base
;
670 bfd_size_type raw_size
;
672 bfd_size_type external_fdr_size
;
676 bfd_size_type raw_end
;
677 bfd_size_type cb_end
;
679 /* Check whether we've already gotten it, and whether there's any to
681 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
683 if (ecoff_data (abfd
)->sym_filepos
== 0)
685 bfd_get_symcount (abfd
) = 0;
689 if (! ecoff_slurp_symbolic_header (abfd
))
692 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
694 /* Read all the symbolic information at once. */
695 raw_base
= (ecoff_data (abfd
)->sym_filepos
696 + backend
->debug_swap
.external_hdr_size
);
698 /* Alpha ecoff makes the determination of raw_size difficult. It has
699 an undocumented debug data section between the symhdr and the first
700 documented section. And the ordering of the sections varies between
701 statically and dynamically linked executables.
702 If bfd supports SEEK_END someday, this code could be simplified. */
706 #define UPDATE_RAW_END(start, count, size) \
707 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
708 if (cb_end > raw_end) \
711 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
712 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
713 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
714 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
715 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
716 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
717 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
718 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
719 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
720 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
721 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
723 #undef UPDATE_RAW_END
725 raw_size
= raw_end
- raw_base
;
728 ecoff_data (abfd
)->sym_filepos
= 0;
731 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
734 bfd_set_error (bfd_error_no_memory
);
738 (ecoff_data (abfd
)->sym_filepos
739 + backend
->debug_swap
.external_hdr_size
),
741 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
743 bfd_set_error (bfd_error_system_call
);
744 bfd_release (abfd
, raw
);
748 ecoff_data (abfd
)->raw_syments
= raw
;
750 /* Get pointers for the numeric offsets in the HDRR structure. */
751 #define FIX(off1, off2, type) \
752 if (internal_symhdr->off1 == 0) \
753 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
755 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
756 + internal_symhdr->off1 \
758 FIX (cbLineOffset
, line
, unsigned char *);
759 FIX (cbDnOffset
, external_dnr
, PTR
);
760 FIX (cbPdOffset
, external_pdr
, PTR
);
761 FIX (cbSymOffset
, external_sym
, PTR
);
762 FIX (cbOptOffset
, external_opt
, PTR
);
763 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
764 FIX (cbSsOffset
, ss
, char *);
765 FIX (cbSsExtOffset
, ssext
, char *);
766 FIX (cbFdOffset
, external_fdr
, PTR
);
767 FIX (cbRfdOffset
, external_rfd
, PTR
);
768 FIX (cbExtOffset
, external_ext
, PTR
);
771 /* I don't want to always swap all the data, because it will just
772 waste time and most programs will never look at it. The only
773 time the linker needs most of the debugging information swapped
774 is when linking big-endian and little-endian MIPS object files
775 together, which is not a common occurrence.
777 We need to look at the fdr to deal with a lot of information in
778 the symbols, so we swap them here. */
779 ecoff_data (abfd
)->debug_info
.fdr
=
780 (struct fdr
*) bfd_alloc (abfd
,
781 (internal_symhdr
->ifdMax
*
782 sizeof (struct fdr
)));
783 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
785 bfd_set_error (bfd_error_no_memory
);
788 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
789 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
790 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
791 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
792 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
793 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
798 /* ECOFF symbol table routines. The ECOFF symbol table is described
799 in gcc/mips-tfile.c. */
801 /* ECOFF uses two common sections. One is the usual one, and the
802 other is for small objects. All the small objects are kept
803 together, and then referenced via the gp pointer, which yields
804 faster assembler code. This is what we use for the small common
806 static asection ecoff_scom_section
;
807 static asymbol ecoff_scom_symbol
;
808 static asymbol
*ecoff_scom_symbol_ptr
;
810 /* Create an empty symbol. */
813 ecoff_make_empty_symbol (abfd
)
816 ecoff_symbol_type
*new;
818 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
819 if (new == (ecoff_symbol_type
*) NULL
)
821 bfd_set_error (bfd_error_no_memory
);
822 return (asymbol
*) NULL
;
824 memset ((PTR
) new, 0, sizeof *new);
825 new->symbol
.section
= (asection
*) NULL
;
826 new->fdr
= (FDR
*) NULL
;
829 new->symbol
.the_bfd
= abfd
;
833 /* Set the BFD flags and section for an ECOFF symbol. */
836 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
841 asymbol
**indirect_ptr_ptr
;
843 asym
->the_bfd
= abfd
;
844 asym
->value
= ecoff_sym
->value
;
845 asym
->section
= &bfd_debug_section
;
848 /* An indirect symbol requires two consecutive stabs symbols. */
849 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
851 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
853 /* @@ Stuffing pointers into integers is a no-no.
854 We can usually get away with it if the integer is
855 large enough though. */
856 if (sizeof (asym
) > sizeof (bfd_vma
))
858 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
860 asym
->flags
= BSF_DEBUGGING
;
861 asym
->section
= &bfd_und_section
;
862 *indirect_ptr_ptr
= NULL
;
866 if (ECOFF_IS_STAB (ecoff_sym
)
867 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
869 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
870 asym
->section
= &bfd_ind_section
;
871 /* Pass this symbol on to the next call to this function. */
872 *indirect_ptr_ptr
= asym
;
876 /* Most symbol types are just for debugging. */
877 switch (ecoff_sym
->st
)
886 if (ECOFF_IS_STAB (ecoff_sym
))
888 asym
->flags
= BSF_DEBUGGING
;
893 asym
->flags
= BSF_DEBUGGING
;
898 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
900 asym
->flags
= BSF_LOCAL
;
901 switch (ecoff_sym
->sc
)
904 /* Used for compiler generated labels. Leave them in the
905 debugging section, and mark them as local. If BSF_DEBUGGING
906 is set, then nm does not display them for some reason. If no
907 flags are set then the linker whines about them. */
908 asym
->flags
= BSF_LOCAL
;
911 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
912 asym
->value
-= asym
->section
->vma
;
915 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
916 asym
->value
-= asym
->section
->vma
;
919 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
920 asym
->value
-= asym
->section
->vma
;
923 asym
->flags
= BSF_DEBUGGING
;
926 asym
->section
= &bfd_abs_section
;
929 asym
->section
= &bfd_und_section
;
939 asym
->flags
= BSF_DEBUGGING
;
942 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
943 asym
->value
-= asym
->section
->vma
;
946 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
947 asym
->value
-= asym
->section
->vma
;
950 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
951 asym
->value
-= asym
->section
->vma
;
954 asym
->flags
= BSF_DEBUGGING
;
957 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
959 asym
->section
= &bfd_com_section
;
965 if (ecoff_scom_section
.name
== NULL
)
967 /* Initialize the small common section. */
968 ecoff_scom_section
.name
= SCOMMON
;
969 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
970 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
971 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
972 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
973 ecoff_scom_symbol
.name
= SCOMMON
;
974 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
975 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
976 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
978 asym
->section
= &ecoff_scom_section
;
983 asym
->flags
= BSF_DEBUGGING
;
986 asym
->section
= &bfd_und_section
;
991 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
992 asym
->value
-= asym
->section
->vma
;
997 asym
->flags
= BSF_DEBUGGING
;
1000 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1001 asym
->value
-= asym
->section
->vma
;
1007 /* Look for special constructors symbols and make relocation entries
1008 in a special construction section. These are produced by the
1009 -fgnu-linker argument to g++. */
1010 if (ECOFF_IS_STAB (ecoff_sym
))
1012 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1024 arelent_chain
*reloc_chain
;
1025 unsigned int bitsize
;
1027 /* Get a section with the same name as the symbol (usually
1028 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1029 name ___CTOR_LIST (three underscores). We need
1030 __CTOR_LIST (two underscores), since ECOFF doesn't use
1031 a leading underscore. This should be handled by gcc,
1032 but instead we do it here. Actually, this should all
1033 be done differently anyhow. */
1034 name
= bfd_asymbol_name (asym
);
1035 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1040 section
= bfd_get_section_by_name (abfd
, name
);
1041 if (section
== (asection
*) NULL
)
1045 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1048 bfd_set_error (bfd_error_no_memory
);
1051 strcpy (copy
, name
);
1052 section
= bfd_make_section (abfd
, copy
);
1055 /* Build a reloc pointing to this constructor. */
1057 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1060 bfd_set_error (bfd_error_no_memory
);
1063 reloc_chain
->relent
.sym_ptr_ptr
=
1064 bfd_get_section (asym
)->symbol_ptr_ptr
;
1065 reloc_chain
->relent
.address
= section
->_raw_size
;
1066 reloc_chain
->relent
.addend
= asym
->value
;
1067 reloc_chain
->relent
.howto
=
1068 ecoff_backend (abfd
)->constructor_reloc
;
1070 /* Set up the constructor section to hold the reloc. */
1071 section
->flags
= SEC_CONSTRUCTOR
;
1072 ++section
->reloc_count
;
1074 /* Constructor sections must be rounded to a boundary
1075 based on the bitsize. These are not real sections--
1076 they are handled specially by the linker--so the ECOFF
1077 16 byte alignment restriction does not apply. */
1078 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1079 section
->alignment_power
= 1;
1080 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1081 ++section
->alignment_power
;
1083 reloc_chain
->next
= section
->constructor_chain
;
1084 section
->constructor_chain
= reloc_chain
;
1085 section
->_raw_size
+= bitsize
/ 8;
1087 /* Mark the symbol as a constructor. */
1088 asym
->flags
|= BSF_CONSTRUCTOR
;
1096 /* Read an ECOFF symbol table. */
1099 ecoff_slurp_symbol_table (abfd
)
1102 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1103 const bfd_size_type external_ext_size
1104 = backend
->debug_swap
.external_ext_size
;
1105 const bfd_size_type external_sym_size
1106 = backend
->debug_swap
.external_sym_size
;
1107 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1108 = backend
->debug_swap
.swap_ext_in
;
1109 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1110 = backend
->debug_swap
.swap_sym_in
;
1111 bfd_size_type internal_size
;
1112 ecoff_symbol_type
*internal
;
1113 ecoff_symbol_type
*internal_ptr
;
1114 asymbol
*indirect_ptr
;
1120 /* If we've already read in the symbol table, do nothing. */
1121 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1124 /* Get the symbolic information. */
1125 if (ecoff_slurp_symbolic_info (abfd
) == false)
1127 if (bfd_get_symcount (abfd
) == 0)
1130 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1131 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1132 if (internal
== NULL
)
1134 bfd_set_error (bfd_error_no_memory
);
1138 internal_ptr
= internal
;
1139 indirect_ptr
= NULL
;
1140 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1141 eraw_end
= (eraw_src
1142 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1143 * external_ext_size
));
1144 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1148 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1149 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1150 + internal_esym
.asym
.iss
);
1151 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1152 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1154 /* The alpha uses a negative ifd field for section symbols. */
1155 if (internal_esym
.ifd
>= 0)
1156 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1157 + internal_esym
.ifd
);
1159 internal_ptr
->fdr
= NULL
;
1160 internal_ptr
->local
= false;
1161 internal_ptr
->native
= (PTR
) eraw_src
;
1163 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1165 /* The local symbols must be accessed via the fdr's, because the
1166 string and aux indices are relative to the fdr information. */
1167 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1168 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1169 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1174 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1175 + fdr_ptr
->isymBase
* external_sym_size
);
1176 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1178 lraw_src
< lraw_end
;
1179 lraw_src
+= external_sym_size
, internal_ptr
++)
1183 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1184 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1186 + internal_sym
.iss
);
1187 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1188 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1190 internal_ptr
->fdr
= fdr_ptr
;
1191 internal_ptr
->local
= true;
1192 internal_ptr
->native
= (PTR
) lraw_src
;
1195 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1197 ecoff_data (abfd
)->canonical_symbols
= internal
;
1202 /* Return the amount of space needed for the canonical symbols. */
1205 ecoff_get_symtab_upper_bound (abfd
)
1208 if (ecoff_slurp_symbolic_info (abfd
) == false
1209 || bfd_get_symcount (abfd
) == 0)
1212 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1215 /* Get the canonical symbols. */
1218 ecoff_get_symtab (abfd
, alocation
)
1220 asymbol
**alocation
;
1222 unsigned int counter
= 0;
1223 ecoff_symbol_type
*symbase
;
1224 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1226 if (ecoff_slurp_symbol_table (abfd
) == false
1227 || bfd_get_symcount (abfd
) == 0)
1230 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1231 while (counter
< bfd_get_symcount (abfd
))
1233 *(location
++) = symbase
++;
1236 *location
++ = (ecoff_symbol_type
*) NULL
;
1237 return bfd_get_symcount (abfd
);
1240 /* Turn ECOFF type information into a printable string.
1241 ecoff_emit_aggregate and ecoff_type_to_string are from
1242 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1244 /* Write aggregate information to a string. */
1247 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1254 int ifd
= rndx
->rfd
;
1255 int indx
= rndx
->index
;
1256 int sym_base
, ss_base
;
1262 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1263 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1265 if (indx
== indexNil
)
1266 name
= "/* no name */";
1269 const struct ecoff_debug_swap
* const debug_swap
1270 = &ecoff_backend (abfd
)->debug_swap
;
1274 (*debug_swap
->swap_sym_in
)
1276 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1277 + indx
* debug_swap
->external_sym_size
),
1279 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1283 "%s %s { ifd = %d, index = %ld }",
1286 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1289 /* Convert the type information to string format. */
1292 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1294 union aux_ext
*aux_ptr
;
1306 unsigned int basic_type
;
1308 static char buffer1
[1024];
1309 static char buffer2
[1024];
1314 for (i
= 0; i
< 7; i
++)
1316 qualifiers
[i
].low_bound
= 0;
1317 qualifiers
[i
].high_bound
= 0;
1318 qualifiers
[i
].stride
= 0;
1321 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1322 return "-1 (no type)";
1323 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1325 basic_type
= u
.ti
.bt
;
1326 qualifiers
[0].type
= u
.ti
.tq0
;
1327 qualifiers
[1].type
= u
.ti
.tq1
;
1328 qualifiers
[2].type
= u
.ti
.tq2
;
1329 qualifiers
[3].type
= u
.ti
.tq3
;
1330 qualifiers
[4].type
= u
.ti
.tq4
;
1331 qualifiers
[5].type
= u
.ti
.tq5
;
1332 qualifiers
[6].type
= tqNil
;
1335 * Go get the basic type.
1339 case btNil
: /* undefined */
1343 case btAdr
: /* address - integer same size as pointer */
1344 strcpy (p1
, "address");
1347 case btChar
: /* character */
1348 strcpy (p1
, "char");
1351 case btUChar
: /* unsigned character */
1352 strcpy (p1
, "unsigned char");
1355 case btShort
: /* short */
1356 strcpy (p1
, "short");
1359 case btUShort
: /* unsigned short */
1360 strcpy (p1
, "unsigned short");
1363 case btInt
: /* int */
1367 case btUInt
: /* unsigned int */
1368 strcpy (p1
, "unsigned int");
1371 case btLong
: /* long */
1372 strcpy (p1
, "long");
1375 case btULong
: /* unsigned long */
1376 strcpy (p1
, "unsigned long");
1379 case btFloat
: /* float (real) */
1380 strcpy (p1
, "float");
1383 case btDouble
: /* Double (real) */
1384 strcpy (p1
, "double");
1387 /* Structures add 1-2 aux words:
1388 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1389 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1391 case btStruct
: /* Structure (Record) */
1392 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1393 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1394 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1396 indx
++; /* skip aux words */
1399 /* Unions add 1-2 aux words:
1400 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1401 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1403 case btUnion
: /* Union */
1404 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1405 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1406 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1408 indx
++; /* skip aux words */
1411 /* Enumerations add 1-2 aux words:
1412 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1413 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1415 case btEnum
: /* Enumeration */
1416 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1417 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1418 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1420 indx
++; /* skip aux words */
1423 case btTypedef
: /* defined via a typedef, isymRef points */
1424 strcpy (p1
, "typedef");
1427 case btRange
: /* subrange of int */
1428 strcpy (p1
, "subrange");
1431 case btSet
: /* pascal sets */
1435 case btComplex
: /* fortran complex */
1436 strcpy (p1
, "complex");
1439 case btDComplex
: /* fortran double complex */
1440 strcpy (p1
, "double complex");
1443 case btIndirect
: /* forward or unnamed typedef */
1444 strcpy (p1
, "forward/unamed typedef");
1447 case btFixedDec
: /* Fixed Decimal */
1448 strcpy (p1
, "fixed decimal");
1451 case btFloatDec
: /* Float Decimal */
1452 strcpy (p1
, "float decimal");
1455 case btString
: /* Varying Length Character String */
1456 strcpy (p1
, "string");
1459 case btBit
: /* Aligned Bit String */
1463 case btPicture
: /* Picture */
1464 strcpy (p1
, "picture");
1467 case btVoid
: /* Void */
1468 strcpy (p1
, "void");
1472 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1476 p1
+= strlen (buffer1
);
1479 * If this is a bitfield, get the bitsize.
1485 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1486 sprintf (p1
, " : %d", bitsize
);
1487 p1
+= strlen (buffer1
);
1492 * Deal with any qualifiers.
1494 if (qualifiers
[0].type
!= tqNil
)
1497 * Snarf up any array bounds in the correct order. Arrays
1498 * store 5 successive words in the aux. table:
1499 * word 0 RNDXR to type of the bounds (ie, int)
1500 * word 1 Current file descriptor index
1502 * word 3 high bound (or -1 if [])
1503 * word 4 stride size in bits
1505 for (i
= 0; i
< 7; i
++)
1507 if (qualifiers
[i
].type
== tqArray
)
1509 qualifiers
[i
].low_bound
=
1510 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1511 qualifiers
[i
].high_bound
=
1512 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1513 qualifiers
[i
].stride
=
1514 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1520 * Now print out the qualifiers.
1522 for (i
= 0; i
< 6; i
++)
1524 switch (qualifiers
[i
].type
)
1531 strcpy (p2
, "ptr to ");
1532 p2
+= sizeof ("ptr to ")-1;
1536 strcpy (p2
, "volatile ");
1537 p2
+= sizeof ("volatile ")-1;
1541 strcpy (p2
, "far ");
1542 p2
+= sizeof ("far ")-1;
1546 strcpy (p2
, "func. ret. ");
1547 p2
+= sizeof ("func. ret. ");
1552 int first_array
= i
;
1555 /* Print array bounds reversed (ie, in the order the C
1556 programmer writes them). C is such a fun language.... */
1558 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1561 for (j
= i
; j
>= first_array
; j
--)
1563 strcpy (p2
, "array [");
1564 p2
+= sizeof ("array [")-1;
1565 if (qualifiers
[j
].low_bound
!= 0)
1567 "%ld:%ld {%ld bits}",
1568 (long) qualifiers
[j
].low_bound
,
1569 (long) qualifiers
[j
].high_bound
,
1570 (long) qualifiers
[j
].stride
);
1572 else if (qualifiers
[j
].high_bound
!= -1)
1575 (long) (qualifiers
[j
].high_bound
+ 1),
1576 (long) (qualifiers
[j
].stride
));
1579 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1582 strcpy (p2
, "] of ");
1583 p2
+= sizeof ("] of ")-1;
1591 strcpy (p2
, buffer1
);
1595 /* Return information about ECOFF symbol SYMBOL in RET. */
1599 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1600 bfd
*abfd
; /* Ignored. */
1604 bfd_symbol_info (symbol
, ret
);
1607 /* Print information about an ECOFF symbol. */
1610 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1614 bfd_print_symbol_type how
;
1616 const struct ecoff_debug_swap
* const debug_swap
1617 = &ecoff_backend (abfd
)->debug_swap
;
1618 FILE *file
= (FILE *)filep
;
1622 case bfd_print_symbol_name
:
1623 fprintf (file
, "%s", symbol
->name
);
1625 case bfd_print_symbol_more
:
1626 if (ecoffsymbol (symbol
)->local
)
1630 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1632 fprintf (file
, "ecoff local ");
1633 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1634 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1635 (unsigned) ecoff_sym
.sc
);
1641 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1643 fprintf (file
, "ecoff extern ");
1644 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1645 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1646 (unsigned) ecoff_ext
.asym
.sc
);
1649 case bfd_print_symbol_all
:
1650 /* Print out the symbols in a reasonable way */
1659 if (ecoffsymbol (symbol
)->local
)
1661 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1664 pos
= ((((char *) ecoffsymbol (symbol
)->native
1665 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1666 / debug_swap
->external_sym_size
)
1667 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1674 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1677 pos
= (((char *) ecoffsymbol (symbol
)->native
1678 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1679 / debug_swap
->external_ext_size
);
1680 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1681 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1682 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1685 fprintf (file
, "[%3d] %c ",
1687 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1688 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1689 (unsigned) ecoff_ext
.asym
.st
,
1690 (unsigned) ecoff_ext
.asym
.sc
,
1691 (unsigned) ecoff_ext
.asym
.index
,
1692 jmptbl
, cobol_main
, weakext
,
1695 if (ecoffsymbol (symbol
)->fdr
!= NULL
1696 && ecoff_ext
.asym
.index
!= indexNil
)
1700 bfd_size_type sym_base
;
1701 union aux_ext
*aux_base
;
1703 indx
= ecoff_ext
.asym
.index
;
1705 /* sym_base is used to map the fdr relative indices which
1706 appear in the file to the position number which we are
1708 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1709 if (ecoffsymbol (symbol
)->local
)
1711 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1713 /* aux_base is the start of the aux entries for this file;
1714 asym.index is an offset from this. */
1715 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1716 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1718 /* The aux entries are stored in host byte order; the
1719 order is indicated by a bit in the fdr. */
1720 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1722 /* This switch is basically from gcc/mips-tdump.c */
1723 switch (ecoff_ext
.asym
.st
)
1731 fprintf (file
, "\n End+1 symbol: %ld",
1732 (long) (indx
+ sym_base
));
1736 if (ecoff_ext
.asym
.sc
== scText
1737 || ecoff_ext
.asym
.sc
== scInfo
)
1738 fprintf (file
, "\n First symbol: %ld",
1739 (long) (indx
+ sym_base
));
1741 fprintf (file
, "\n First symbol: %ld",
1742 (long) (AUX_GET_ISYM (bigendian
,
1743 &aux_base
[ecoff_ext
.asym
.index
])
1749 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1751 else if (ecoffsymbol (symbol
)->local
)
1752 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1753 (long) (AUX_GET_ISYM (bigendian
,
1754 &aux_base
[ecoff_ext
.asym
.index
])
1756 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1759 fprintf (file
, "\n Local symbol: %ld",
1762 + (ecoff_data (abfd
)
1763 ->debug_info
.symbolic_header
.iextMax
)));
1767 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1768 fprintf (file
, "\n Type: %s",
1769 ecoff_type_to_string (abfd
, aux_base
, indx
,
1779 /* Read in the relocs for a section. */
1782 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1787 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1788 arelent
*internal_relocs
;
1789 bfd_size_type external_reloc_size
;
1790 bfd_size_type external_relocs_size
;
1791 char *external_relocs
;
1795 if (section
->relocation
!= (arelent
*) NULL
1796 || section
->reloc_count
== 0
1797 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1800 if (ecoff_slurp_symbol_table (abfd
) == false)
1803 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1805 * section
->reloc_count
));
1806 external_reloc_size
= backend
->external_reloc_size
;
1807 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1808 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1809 if (internal_relocs
== (arelent
*) NULL
1810 || external_relocs
== (char *) NULL
)
1812 bfd_set_error (bfd_error_no_memory
);
1815 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1817 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1818 != external_relocs_size
)
1820 bfd_set_error (bfd_error_system_call
);
1824 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1826 struct internal_reloc intern
;
1828 (*backend
->swap_reloc_in
) (abfd
,
1829 external_relocs
+ i
* external_reloc_size
,
1832 if (intern
.r_extern
)
1834 /* r_symndx is an index into the external symbols. */
1835 BFD_ASSERT (intern
.r_symndx
>= 0
1837 < (ecoff_data (abfd
)
1838 ->debug_info
.symbolic_header
.iextMax
)));
1839 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1842 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1843 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1845 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1850 CONST
char *sec_name
;
1853 /* r_symndx is a section key. */
1854 switch (intern
.r_symndx
)
1856 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1857 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1858 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1859 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1860 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1861 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1862 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1863 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1864 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1865 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1866 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1867 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1868 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1872 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1873 if (sec
== (asection
*) NULL
)
1875 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1877 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1880 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1882 /* Let the backend select the howto field and do any other
1883 required processing. */
1884 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1887 bfd_release (abfd
, external_relocs
);
1889 section
->relocation
= internal_relocs
;
1894 /* Get a canonical list of relocs. */
1897 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1905 if (section
->flags
& SEC_CONSTRUCTOR
)
1907 arelent_chain
*chain
;
1909 /* This section has relocs made up by us, not the file, so take
1910 them out of their chain and place them into the data area
1912 for (count
= 0, chain
= section
->constructor_chain
;
1913 count
< section
->reloc_count
;
1914 count
++, chain
= chain
->next
)
1915 *relptr
++ = &chain
->relent
;
1921 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1924 tblptr
= section
->relocation
;
1925 if (tblptr
== (arelent
*) NULL
)
1928 for (count
= 0; count
< section
->reloc_count
; count
++)
1929 *relptr
++ = tblptr
++;
1932 *relptr
= (arelent
*) NULL
;
1934 return section
->reloc_count
;
1937 /* Provided a BFD, a section and an offset into the section, calculate
1938 and return the name of the source file and the line nearest to the
1943 ecoff_find_nearest_line (abfd
,
1952 asymbol
**ignore_symbols
;
1954 CONST
char **filename_ptr
;
1955 CONST
char **functionname_ptr
;
1956 unsigned int *retline_ptr
;
1958 const struct ecoff_debug_swap
* const debug_swap
1959 = &ecoff_backend (abfd
)->debug_swap
;
1964 bfd_size_type external_pdr_size
;
1968 unsigned char *line_ptr
;
1969 unsigned char *line_end
;
1972 /* If we're not in the .text section, we don't have any line
1974 if (strcmp (section
->name
, _TEXT
) != 0
1975 || offset
< ecoff_data (abfd
)->text_start
1976 || offset
>= ecoff_data (abfd
)->text_end
)
1979 /* Make sure we have the FDR's. */
1980 if (ecoff_slurp_symbolic_info (abfd
) == false
1981 || bfd_get_symcount (abfd
) == 0)
1984 /* Each file descriptor (FDR) has a memory address. Here we track
1985 down which FDR we want. The FDR's are stored in increasing
1986 memory order. If speed is ever important, this can become a
1987 binary search. We must ignore FDR's with no PDR entries; they
1988 will have the adr of the FDR before or after them. */
1989 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1990 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1991 fdr_hold
= (FDR
*) NULL
;
1992 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1994 if (fdr_ptr
->cpd
== 0)
1996 if (offset
< fdr_ptr
->adr
)
2000 if (fdr_hold
== (FDR
*) NULL
)
2004 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2005 have an address, which is relative to the FDR address, and are
2006 also stored in increasing memory order. */
2007 offset
-= fdr_ptr
->adr
;
2008 external_pdr_size
= debug_swap
->external_pdr_size
;
2009 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2010 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2011 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2012 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2014 /* The address of the first PDR is an offset which applies to the
2015 addresses of all the PDR's. */
2018 for (pdr_ptr
+= external_pdr_size
;
2020 pdr_ptr
+= external_pdr_size
)
2022 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2023 if (offset
< pdr
.adr
)
2027 /* Now we can look for the actual line number. The line numbers are
2028 stored in a very funky format, which I won't try to describe.
2029 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2030 we want; we need this to compute line_end. */
2031 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2032 if (pdr_ptr
== pdr_end
)
2033 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2035 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2037 /* Now change pdr and pdr_ptr to the one we want. */
2038 pdr_ptr
-= external_pdr_size
;
2039 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2043 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2044 + fdr_ptr
->cbLineOffset
2045 + pdr
.cbLineOffset
);
2046 while (line_ptr
< line_end
)
2051 delta
= *line_ptr
>> 4;
2054 count
= (*line_ptr
& 0xf) + 1;
2058 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2059 if (delta
>= 0x8000)
2064 if (offset
< count
* 4)
2066 offset
-= count
* 4;
2069 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2070 at least according to gdb/mipsread.c. */
2071 if (fdr_ptr
->rss
== -1)
2073 *filename_ptr
= NULL
;
2075 *functionname_ptr
= NULL
;
2080 (*debug_swap
->swap_ext_in
)
2082 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2083 + pdr
.isym
* debug_swap
->external_ext_size
),
2085 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2086 + proc_ext
.asym
.iss
);
2093 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2096 (*debug_swap
->swap_sym_in
)
2098 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2099 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2101 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2105 if (lineno
== ilineNil
)
2107 *retline_ptr
= lineno
;
2111 /* Set the architecture. The supported architecture is stored in the
2112 backend pointer. We always set the architecture anyhow, since many
2113 callers ignore the return value. */
2116 ecoff_set_arch_mach (abfd
, arch
, machine
)
2118 enum bfd_architecture arch
;
2119 unsigned long machine
;
2121 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2122 return arch
== ecoff_backend (abfd
)->arch
;
2125 /* Get the size of the section headers. We do not output the .reginfo
2130 ecoff_sizeof_headers (abfd
, reloc
)
2139 for (current
= abfd
->sections
;
2140 current
!= (asection
*)NULL
;
2141 current
= current
->next
)
2142 if (strcmp (current
->name
, REGINFO
) != 0)
2145 ret
= (bfd_coff_filhsz (abfd
)
2146 + bfd_coff_aoutsz (abfd
)
2147 + c
* bfd_coff_scnhsz (abfd
));
2148 return BFD_ALIGN (ret
, 16);
2151 /* Get the contents of a section. This is where we handle reading the
2152 .reginfo section, which implicitly holds the contents of an
2153 ecoff_reginfo structure. */
2156 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2161 bfd_size_type count
;
2163 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2164 struct ecoff_reginfo s
;
2167 if (strcmp (section
->name
, REGINFO
) != 0)
2168 return bfd_generic_get_section_contents (abfd
, section
, location
,
2171 s
.gp_value
= tdata
->gp
;
2172 s
.gprmask
= tdata
->gprmask
;
2173 for (i
= 0; i
< 4; i
++)
2174 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2175 s
.fprmask
= tdata
->fprmask
;
2177 /* bfd_get_section_contents has already checked that the offset and
2178 size is reasonable. We don't have to worry about swapping or any
2179 such thing; the .reginfo section is defined such that the
2180 contents are an ecoff_reginfo structure as seen on the host. */
2181 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2185 /* Calculate the file position for each section, and set
2189 ecoff_compute_section_file_positions (abfd
)
2197 sofar
= ecoff_sizeof_headers (abfd
, false);
2200 for (current
= abfd
->sections
;
2201 current
!= (asection
*) NULL
;
2202 current
= current
->next
)
2204 unsigned int alignment_power
;
2206 /* Only deal with sections which have contents */
2207 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2208 || strcmp (current
->name
, REGINFO
) == 0)
2211 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2212 supposed to indicate the number of .pdata entries that are
2213 really in the section. Each entry is 8 bytes. We store this
2214 away in line_filepos before increasing the section size. */
2215 if (strcmp (current
->name
, _PDATA
) != 0)
2216 alignment_power
= current
->alignment_power
;
2219 current
->line_filepos
= current
->_raw_size
/ 8;
2220 alignment_power
= 4;
2223 /* On Ultrix, the data sections in an executable file must be
2224 aligned to a page boundary within the file. This does not
2225 affect the section size, though. FIXME: Does this work for
2226 other platforms? It requires some modification for the
2227 Alpha, because .rdata on the Alpha goes with the text, not
2229 if ((abfd
->flags
& EXEC_P
) != 0
2230 && (abfd
->flags
& D_PAGED
) != 0
2231 && first_data
!= false
2232 && (current
->flags
& SEC_CODE
) == 0
2233 && (! ecoff_backend (abfd
)->rdata_in_text
2234 || strcmp (current
->name
, _RDATA
) != 0)
2235 && strcmp (current
->name
, _PDATA
) != 0)
2237 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2239 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2243 /* Align the sections in the file to the same boundary on
2244 which they are aligned in virtual memory. */
2246 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2248 current
->filepos
= sofar
;
2250 sofar
+= current
->_raw_size
;
2252 /* make sure that this section is of the right size too */
2254 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2255 current
->_raw_size
+= sofar
- old_sofar
;
2258 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2261 /* Determine the location of the relocs for all the sections in the
2262 output file, as well as the location of the symbolic debugging
2265 static bfd_size_type
2266 ecoff_compute_reloc_file_positions (abfd
)
2269 const bfd_size_type external_reloc_size
=
2270 ecoff_backend (abfd
)->external_reloc_size
;
2271 file_ptr reloc_base
;
2272 bfd_size_type reloc_size
;
2276 if (! abfd
->output_has_begun
)
2278 ecoff_compute_section_file_positions (abfd
);
2279 abfd
->output_has_begun
= true;
2282 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2285 for (current
= abfd
->sections
;
2286 current
!= (asection
*)NULL
;
2287 current
= current
->next
)
2289 if (strcmp (current
->name
, REGINFO
) == 0)
2291 if (current
->reloc_count
== 0)
2292 current
->rel_filepos
= 0;
2295 bfd_size_type relsize
;
2297 current
->rel_filepos
= reloc_base
;
2298 relsize
= current
->reloc_count
* external_reloc_size
;
2299 reloc_size
+= relsize
;
2300 reloc_base
+= relsize
;
2304 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2306 /* At least on Ultrix, the symbol table of an executable file must
2307 be aligned to a page boundary. FIXME: Is this true on other
2309 if ((abfd
->flags
& EXEC_P
) != 0
2310 && (abfd
->flags
& D_PAGED
) != 0)
2311 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2312 &~ (ecoff_backend (abfd
)->round
- 1));
2314 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2319 /* Set the contents of a section. This is where we handle setting the
2320 contents of the .reginfo section, which implicitly holds a
2321 ecoff_reginfo structure. */
2324 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2329 bfd_size_type count
;
2331 /* This must be done first, because bfd_set_section_contents is
2332 going to set output_has_begun to true. */
2333 if (abfd
->output_has_begun
== false)
2334 ecoff_compute_section_file_positions (abfd
);
2339 if (strcmp (section
->name
, REGINFO
) == 0)
2341 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2342 struct ecoff_reginfo s
;
2345 /* If the caller is only changing part of the structure, we must
2346 retrieve the current information before the memcpy. */
2347 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2349 s
.gp_value
= tdata
->gp
;
2350 s
.gprmask
= tdata
->gprmask
;
2351 for (i
= 0; i
< 4; i
++)
2352 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2353 s
.fprmask
= tdata
->fprmask
;
2356 /* bfd_set_section_contents has already checked that the offset
2357 and size is reasonable. We don't have to worry about
2358 swapping or any such thing; the .reginfo section is defined
2359 such that the contents are an ecoff_reginfo structure as seen
2361 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2363 tdata
->gp
= s
.gp_value
;
2364 tdata
->gprmask
= s
.gprmask
;
2365 for (i
= 0; i
< 4; i
++)
2366 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2367 tdata
->fprmask
= s
.fprmask
;
2372 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2373 || bfd_write (location
, 1, count
, abfd
) != count
)
2379 /* Get ECOFF EXTR information for an external symbol. This function
2380 is passed to bfd_ecoff_debug_externals. */
2383 ecoff_get_extr (sym
, esym
)
2387 ecoff_symbol_type
*ecoff_sym_ptr
;
2390 /* Don't include debugging, local or section symbols. */
2391 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2392 || (sym
->flags
& BSF_LOCAL
) != 0
2393 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2396 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2397 || ecoffsymbol (sym
)->native
== NULL
)
2400 esym
->cobol_main
= 0;
2404 /* FIXME: we can do better than this for st and sc. */
2405 esym
->asym
.st
= stGlobal
;
2406 esym
->asym
.sc
= scAbs
;
2407 esym
->asym
.reserved
= 0;
2408 esym
->asym
.index
= indexNil
;
2412 ecoff_sym_ptr
= ecoffsymbol (sym
);
2414 if (ecoff_sym_ptr
->local
)
2417 input_bfd
= bfd_asymbol_bfd (sym
);
2418 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2419 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2421 /* If the symbol was defined by the linker, then esym will be
2422 undefined but sym will not be. Get a better class for such a
2424 if ((esym
->asym
.sc
== scUndefined
2425 || esym
->asym
.sc
== scSUndefined
)
2426 && bfd_get_section (sym
) != &bfd_und_section
)
2427 esym
->asym
.sc
= scAbs
;
2429 /* Adjust the FDR index for the symbol by that used for the input
2431 if (esym
->ifd
!= -1)
2433 struct ecoff_debug_info
*input_debug
;
2435 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2436 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2437 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2438 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2444 /* Set the external symbol index. This routine is passed to
2445 bfd_ecoff_debug_externals. */
2448 ecoff_set_index (sym
, indx
)
2452 ecoff_set_sym_index (sym
, indx
);
2455 /* Write out an ECOFF file. */
2458 ecoff_write_object_contents (abfd
)
2461 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2462 const bfd_vma round
= backend
->round
;
2463 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2464 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2465 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2466 const bfd_size_type external_hdr_size
2467 = backend
->debug_swap
.external_hdr_size
;
2468 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2469 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2471 struct internal_reloc
*))
2472 = backend
->adjust_reloc_out
;
2473 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2474 const struct internal_reloc
*,
2476 = backend
->swap_reloc_out
;
2477 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2478 HDRR
* const symhdr
= &debug
->symbolic_header
;
2481 bfd_size_type reloc_size
;
2482 bfd_size_type text_size
;
2484 bfd_size_type data_size
;
2486 bfd_size_type bss_size
;
2488 struct internal_filehdr internal_f
;
2489 struct internal_aouthdr internal_a
;
2492 bfd_set_error (bfd_error_system_call
);
2494 /* Determine where the sections and relocs will go in the output
2496 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2499 for (current
= abfd
->sections
;
2500 current
!= (asection
*)NULL
;
2501 current
= current
->next
)
2503 if (strcmp (current
->name
, REGINFO
) == 0)
2505 current
->target_index
= count
;
2509 if ((abfd
->flags
& D_PAGED
) != 0)
2510 text_size
= ecoff_sizeof_headers (abfd
, false);
2518 /* Write section headers to the file. */
2520 buff
= (PTR
) alloca (scnhsz
);
2521 internal_f
.f_nscns
= 0;
2522 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2524 for (current
= abfd
->sections
;
2525 current
!= (asection
*) NULL
;
2526 current
= current
->next
)
2528 struct internal_scnhdr section
;
2531 if (strcmp (current
->name
, REGINFO
) == 0)
2533 BFD_ASSERT (current
->reloc_count
== 0);
2537 ++internal_f
.f_nscns
;
2539 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2541 /* FIXME: is this correct for shared libraries? I think it is
2542 but I have no platform to check. Ian Lance Taylor. */
2543 vma
= bfd_get_section_vma (abfd
, current
);
2544 if (strcmp (current
->name
, _LIB
) == 0)
2545 section
.s_vaddr
= 0;
2547 section
.s_vaddr
= vma
;
2549 section
.s_paddr
= vma
;
2550 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2552 /* If this section is unloadable then the scnptr will be 0. */
2553 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2554 section
.s_scnptr
= 0;
2556 section
.s_scnptr
= current
->filepos
;
2557 section
.s_relptr
= current
->rel_filepos
;
2559 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2560 object file produced by the assembler is supposed to point to
2561 information about how much room is required by objects of
2562 various different sizes. I think this only matters if we
2563 want the linker to compute the best size to use, or
2564 something. I don't know what happens if the information is
2566 if (strcmp (current
->name
, _PDATA
) != 0)
2567 section
.s_lnnoptr
= 0;
2570 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2571 hold the number of entries in the section (each entry is
2572 8 bytes). We stored this in the line_filepos field in
2573 ecoff_compute_section_file_positions. */
2574 section
.s_lnnoptr
= current
->line_filepos
;
2577 section
.s_nreloc
= current
->reloc_count
;
2578 section
.s_nlnno
= 0;
2579 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2582 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2583 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2586 if ((section
.s_flags
& STYP_TEXT
) != 0
2587 || ((section
.s_flags
& STYP_RDATA
) != 0
2588 && backend
->rdata_in_text
)
2589 || strcmp (current
->name
, _PDATA
) == 0)
2591 text_size
+= bfd_get_section_size_before_reloc (current
);
2592 if (text_start
== 0 || text_start
> vma
)
2595 else if ((section
.s_flags
& STYP_RDATA
) != 0
2596 || (section
.s_flags
& STYP_DATA
) != 0
2597 || (section
.s_flags
& STYP_LITA
) != 0
2598 || (section
.s_flags
& STYP_LIT8
) != 0
2599 || (section
.s_flags
& STYP_LIT4
) != 0
2600 || (section
.s_flags
& STYP_SDATA
) != 0
2601 || strcmp (current
->name
, _XDATA
) == 0)
2603 data_size
+= bfd_get_section_size_before_reloc (current
);
2604 if (data_start
== 0 || data_start
> vma
)
2607 else if ((section
.s_flags
& STYP_BSS
) != 0
2608 || (section
.s_flags
& STYP_SBSS
) != 0)
2609 bss_size
+= bfd_get_section_size_before_reloc (current
);
2614 /* Set up the file header. */
2616 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2618 /* We will NOT put a fucking timestamp in the header here. Every
2619 time you put it back, I will come in and take it out again. I'm
2620 sorry. This field does not belong here. We fill it with a 0 so
2621 it compares the same but is not a reasonable time. --
2623 internal_f
.f_timdat
= 0;
2625 if (bfd_get_symcount (abfd
) != 0)
2627 /* The ECOFF f_nsyms field is not actually the number of
2628 symbols, it's the size of symbolic information header. */
2629 internal_f
.f_nsyms
= external_hdr_size
;
2630 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2634 internal_f
.f_nsyms
= 0;
2635 internal_f
.f_symptr
= 0;
2638 internal_f
.f_opthdr
= aoutsz
;
2640 internal_f
.f_flags
= F_LNNO
;
2641 if (reloc_size
== 0)
2642 internal_f
.f_flags
|= F_RELFLG
;
2643 if (bfd_get_symcount (abfd
) == 0)
2644 internal_f
.f_flags
|= F_LSYMS
;
2645 if (abfd
->flags
& EXEC_P
)
2646 internal_f
.f_flags
|= F_EXEC
;
2648 if (! abfd
->xvec
->byteorder_big_p
)
2649 internal_f
.f_flags
|= F_AR32WR
;
2651 internal_f
.f_flags
|= F_AR32W
;
2653 /* Set up the ``optional'' header. */
2654 if ((abfd
->flags
& D_PAGED
) != 0)
2655 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2657 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2659 /* FIXME: Is this really correct? */
2660 internal_a
.vstamp
= symhdr
->vstamp
;
2662 /* At least on Ultrix, these have to be rounded to page boundaries.
2663 FIXME: Is this true on other platforms? */
2664 if ((abfd
->flags
& D_PAGED
) != 0)
2666 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2667 internal_a
.text_start
= text_start
&~ (round
- 1);
2668 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2669 internal_a
.data_start
= data_start
&~ (round
- 1);
2673 internal_a
.tsize
= text_size
;
2674 internal_a
.text_start
= text_start
;
2675 internal_a
.dsize
= data_size
;
2676 internal_a
.data_start
= data_start
;
2679 /* On Ultrix, the initial portions of the .sbss and .bss segments
2680 are at the end of the data section. The bsize field in the
2681 optional header records how many bss bytes are required beyond
2682 those in the data section. The value is not rounded to a page
2684 if (bss_size
< internal_a
.dsize
- data_size
)
2687 bss_size
-= internal_a
.dsize
- data_size
;
2688 internal_a
.bsize
= bss_size
;
2689 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2691 internal_a
.entry
= bfd_get_start_address (abfd
);
2693 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2695 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2696 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2697 for (i
= 0; i
< 4; i
++)
2698 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2700 /* Write out the file header and the optional header. */
2702 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2705 buff
= (PTR
) alloca (filhsz
);
2706 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2707 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2710 buff
= (PTR
) alloca (aoutsz
);
2711 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2712 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2715 /* Build the external symbol information. This must be done before
2716 writing out the relocs so that we know the symbol indices. The
2717 condition checks makes sure this object was not created by
2718 ecoff_bfd_final_link, since if it was we do not want to tamper
2719 with the external symbols. */
2720 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2722 symhdr
->iextMax
= 0;
2723 symhdr
->issExtMax
= 0;
2724 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2725 debug
->ssext
= debug
->ssext_end
= NULL
;
2726 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2727 (((abfd
->flags
& EXEC_P
) == 0)
2729 ecoff_get_extr
, ecoff_set_index
)
2733 /* Write out the relocs. */
2734 for (current
= abfd
->sections
;
2735 current
!= (asection
*) NULL
;
2736 current
= current
->next
)
2738 arelent
**reloc_ptr_ptr
;
2739 arelent
**reloc_end
;
2742 if (current
->reloc_count
== 0)
2745 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2748 bfd_set_error (bfd_error_no_memory
);
2752 reloc_ptr_ptr
= current
->orelocation
;
2753 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2754 out_ptr
= (char *) buff
;
2756 reloc_ptr_ptr
< reloc_end
;
2757 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2761 struct internal_reloc in
;
2763 memset ((PTR
) &in
, 0, sizeof in
);
2765 reloc
= *reloc_ptr_ptr
;
2766 sym
= *reloc
->sym_ptr_ptr
;
2768 in
.r_vaddr
= (reloc
->address
2769 + bfd_get_section_vma (abfd
, current
));
2770 in
.r_type
= reloc
->howto
->type
;
2772 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2774 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2781 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2782 if (strcmp (name
, ".text") == 0)
2783 in
.r_symndx
= RELOC_SECTION_TEXT
;
2784 else if (strcmp (name
, ".rdata") == 0)
2785 in
.r_symndx
= RELOC_SECTION_RDATA
;
2786 else if (strcmp (name
, ".data") == 0)
2787 in
.r_symndx
= RELOC_SECTION_DATA
;
2788 else if (strcmp (name
, ".sdata") == 0)
2789 in
.r_symndx
= RELOC_SECTION_SDATA
;
2790 else if (strcmp (name
, ".sbss") == 0)
2791 in
.r_symndx
= RELOC_SECTION_SBSS
;
2792 else if (strcmp (name
, ".bss") == 0)
2793 in
.r_symndx
= RELOC_SECTION_BSS
;
2794 else if (strcmp (name
, ".init") == 0)
2795 in
.r_symndx
= RELOC_SECTION_INIT
;
2796 else if (strcmp (name
, ".lit8") == 0)
2797 in
.r_symndx
= RELOC_SECTION_LIT8
;
2798 else if (strcmp (name
, ".lit4") == 0)
2799 in
.r_symndx
= RELOC_SECTION_LIT4
;
2800 else if (strcmp (name
, ".xdata") == 0)
2801 in
.r_symndx
= RELOC_SECTION_XDATA
;
2802 else if (strcmp (name
, ".pdata") == 0)
2803 in
.r_symndx
= RELOC_SECTION_PDATA
;
2804 else if (strcmp (name
, ".fini") == 0)
2805 in
.r_symndx
= RELOC_SECTION_FINI
;
2806 else if (strcmp (name
, ".lita") == 0)
2807 in
.r_symndx
= RELOC_SECTION_LITA
;
2808 else if (strcmp (name
, "*ABS*") == 0)
2809 in
.r_symndx
= RELOC_SECTION_ABS
;
2815 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2817 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2820 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2822 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
2823 != external_reloc_size
* current
->reloc_count
)
2825 bfd_release (abfd
, buff
);
2828 /* Write out the symbolic debugging information. */
2829 if (bfd_get_symcount (abfd
) > 0)
2831 /* Write out the debugging information. */
2832 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2833 ecoff_data (abfd
)->sym_filepos
)
2839 /* The .bss section of a demand paged executable must receive an
2840 entire page. If there are symbols, the symbols will start on the
2841 next page. If there are no symbols, we must fill out the page by
2843 if (bfd_get_symcount (abfd
) == 0
2844 && (abfd
->flags
& EXEC_P
) != 0
2845 && (abfd
->flags
& D_PAGED
) != 0)
2849 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2852 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2854 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2857 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2864 /* Archive handling. ECOFF uses what appears to be a unique type of
2865 archive header (armap). The byte ordering of the armap and the
2866 contents are encoded in the name of the armap itself. At least for
2867 now, we only support archives with the same byte ordering in the
2868 armap and the contents.
2870 The first four bytes in the armap are the number of symbol
2871 definitions. This is always a power of two.
2873 This is followed by the symbol definitions. Each symbol definition
2874 occupies 8 bytes. The first four bytes are the offset from the
2875 start of the armap strings to the null-terminated string naming
2876 this symbol. The second four bytes are the file offset to the
2877 archive member which defines this symbol. If the second four bytes
2878 are 0, then this is not actually a symbol definition, and it should
2881 The symbols are hashed into the armap with a closed hashing scheme.
2882 See the functions below for the details of the algorithm.
2884 After the symbol definitions comes four bytes holding the size of
2885 the string table, followed by the string table itself. */
2887 /* The name of an archive headers looks like this:
2888 __________E[BL]E[BL]_ (with a trailing space).
2889 The trailing space is changed to an X if the archive is changed to
2890 indicate that the armap is out of date.
2892 The Alpha seems to use ________64E[BL]E[BL]_. */
2894 #define ARMAP_BIG_ENDIAN 'B'
2895 #define ARMAP_LITTLE_ENDIAN 'L'
2896 #define ARMAP_MARKER 'E'
2897 #define ARMAP_START_LENGTH 10
2898 #define ARMAP_HEADER_MARKER_INDEX 10
2899 #define ARMAP_HEADER_ENDIAN_INDEX 11
2900 #define ARMAP_OBJECT_MARKER_INDEX 12
2901 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2902 #define ARMAP_END_INDEX 14
2903 #define ARMAP_END "_ "
2905 /* This is a magic number used in the hashing algorithm. */
2906 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2908 /* This returns the hash value to use for a string. It also sets
2909 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2910 is the number of entries in the hash table, and HLOG is the log
2914 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2916 unsigned int *rehash
;
2924 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2925 hash
*= ARMAP_HASH_MAGIC
;
2926 *rehash
= (hash
& (size
- 1)) | 1;
2927 return hash
>> (32 - hlog
);
2930 /* Read in the armap. */
2933 ecoff_slurp_armap (abfd
)
2938 struct areltdata
*mapdata
;
2939 bfd_size_type parsed_size
;
2941 struct artdata
*ardata
;
2944 struct symdef
*symdef_ptr
;
2947 /* Get the name of the first element. */
2948 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2954 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2956 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2957 standard COFF armap. We could move the ECOFF armap stuff into
2958 bfd_slurp_armap, but that seems inappropriate since no other
2959 target uses this format. Instead, we check directly for a COFF
2961 if (strncmp (nextname
, "/ ", 16) == 0)
2962 return bfd_slurp_armap (abfd
);
2964 /* See if the first element is an armap. */
2965 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2966 ARMAP_START_LENGTH
) != 0
2967 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2968 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2969 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2970 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2971 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2972 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2973 || strncmp (nextname
+ ARMAP_END_INDEX
,
2974 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2976 bfd_has_map (abfd
) = false;
2980 /* Make sure we have the right byte ordering. */
2981 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2982 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2983 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2984 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2986 bfd_set_error (bfd_error_wrong_format
);
2990 /* Read in the armap. */
2991 ardata
= bfd_ardata (abfd
);
2992 mapdata
= _bfd_snarf_ar_hdr (abfd
);
2993 if (mapdata
== (struct areltdata
*) NULL
)
2995 parsed_size
= mapdata
->parsed_size
;
2996 bfd_release (abfd
, (PTR
) mapdata
);
2998 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2999 if (raw_armap
== (char *) NULL
)
3001 bfd_set_error (bfd_error_no_memory
);
3005 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3007 bfd_set_error (bfd_error_malformed_archive
);
3008 bfd_release (abfd
, (PTR
) raw_armap
);
3012 ardata
->tdata
= (PTR
) raw_armap
;
3014 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3016 ardata
->symdef_count
= 0;
3017 ardata
->cache
= (struct ar_cache
*) NULL
;
3019 /* This code used to overlay the symdefs over the raw archive data,
3020 but that doesn't work on a 64 bit host. */
3022 stringbase
= raw_armap
+ count
* 8 + 8;
3024 #ifdef CHECK_ARMAP_HASH
3028 /* Double check that I have the hashing algorithm right by making
3029 sure that every symbol can be looked up successfully. */
3031 for (i
= 1; i
< count
; i
<<= 1)
3033 BFD_ASSERT (i
== count
);
3035 raw_ptr
= raw_armap
+ 4;
3036 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3038 unsigned int name_offset
, file_offset
;
3039 unsigned int hash
, rehash
, srch
;
3041 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3042 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3043 if (file_offset
== 0)
3045 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3050 /* See if we can rehash to this location. */
3051 for (srch
= (hash
+ rehash
) & (count
- 1);
3052 srch
!= hash
&& srch
!= i
;
3053 srch
= (srch
+ rehash
) & (count
- 1))
3054 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3056 BFD_ASSERT (srch
== i
);
3060 #endif /* CHECK_ARMAP_HASH */
3062 raw_ptr
= raw_armap
+ 4;
3063 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3064 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3065 ++ardata
->symdef_count
;
3067 symdef_ptr
= ((struct symdef
*)
3069 ardata
->symdef_count
* sizeof (struct symdef
)));
3072 bfd_set_error (bfd_error_no_memory
);
3076 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3078 raw_ptr
= raw_armap
+ 4;
3079 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3081 unsigned int name_offset
, file_offset
;
3083 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3084 if (file_offset
== 0)
3086 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3087 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3088 symdef_ptr
->file_offset
= file_offset
;
3092 ardata
->first_file_filepos
= bfd_tell (abfd
);
3093 /* Pad to an even boundary. */
3094 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3096 bfd_has_map (abfd
) = true;
3101 /* Write out an armap. */
3104 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3106 unsigned int elength
;
3108 unsigned int orl_count
;
3111 unsigned int hashsize
, hashlog
;
3112 unsigned int symdefsize
;
3114 unsigned int stringsize
;
3115 unsigned int mapsize
;
3118 struct stat statbuf
;
3121 bfd_byte
*hashtable
;
3125 /* Ultrix appears to use as a hash table size the least power of two
3126 greater than twice the number of entries. */
3127 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3129 hashsize
= 1 << hashlog
;
3131 symdefsize
= hashsize
* 8;
3133 stringsize
= stridx
+ padit
;
3135 /* Include 8 bytes to store symdefsize and stringsize in output. */
3136 mapsize
= symdefsize
+ stringsize
+ 8;
3138 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3140 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3142 /* Work out the ECOFF armap name. */
3143 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3144 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3145 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3146 (abfd
->xvec
->header_byteorder_big_p
3148 : ARMAP_LITTLE_ENDIAN
);
3149 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3150 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3151 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3152 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3154 /* Write the timestamp of the archive header to be just a little bit
3155 later than the timestamp of the file, otherwise the linker will
3156 complain that the index is out of date. Actually, the Ultrix
3157 linker just checks the archive name; the GNU linker may check the
3159 stat (abfd
->filename
, &statbuf
);
3160 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3162 /* The DECstation uses zeroes for the uid, gid and mode of the
3164 hdr
.ar_uid
[0] = '0';
3165 hdr
.ar_gid
[0] = '0';
3166 hdr
.ar_mode
[0] = '0';
3168 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3170 hdr
.ar_fmag
[0] = '`';
3171 hdr
.ar_fmag
[1] = '\012';
3173 /* Turn all null bytes in the header into spaces. */
3174 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3175 if (((char *)(&hdr
))[i
] == '\0')
3176 (((char *)(&hdr
))[i
]) = ' ';
3178 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3179 != sizeof (struct ar_hdr
))
3182 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3183 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3186 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3189 bfd_set_error (bfd_error_no_memory
);
3193 current
= abfd
->archive_head
;
3195 for (i
= 0; i
< orl_count
; i
++)
3197 unsigned int hash
, rehash
;
3199 /* Advance firstreal to the file position of this archive
3201 if (((bfd
*) map
[i
].pos
) != last_elt
)
3205 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3206 firstreal
+= firstreal
% 2;
3207 current
= current
->next
;
3209 while (current
!= (bfd
*) map
[i
].pos
);
3214 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3215 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3219 /* The desired slot is already taken. */
3220 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3222 srch
= (srch
+ rehash
) & (hashsize
- 1))
3223 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3226 BFD_ASSERT (srch
!= hash
);
3231 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3232 (PTR
) (hashtable
+ hash
* 8));
3233 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3234 (PTR
) (hashtable
+ hash
* 8 + 4));
3237 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3240 bfd_release (abfd
, hashtable
);
3242 /* Now write the strings. */
3243 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3244 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3246 for (i
= 0; i
< orl_count
; i
++)
3250 len
= strlen (*map
[i
].name
) + 1;
3251 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3255 /* The spec sez this should be a newline. But in order to be
3256 bug-compatible for DECstation ar we use a null. */
3259 if (bfd_write ("", 1, 1, abfd
) != 1)
3266 /* See whether this BFD is an archive. If it is, read in the armap
3267 and the extended name table. */
3270 ecoff_archive_p (abfd
)
3273 char armag
[SARMAG
+ 1];
3275 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3276 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3278 bfd_set_error (bfd_error_wrong_format
);
3279 return (bfd_target
*) NULL
;
3282 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3283 involves a cast, we can't do it as the left operand of
3285 abfd
->tdata
.aout_ar_data
=
3286 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3288 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3290 bfd_set_error (bfd_error_no_memory
);
3291 return (bfd_target
*) NULL
;
3294 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3295 bfd_ardata (abfd
)->cache
= NULL
;
3296 bfd_ardata (abfd
)->archive_head
= NULL
;
3297 bfd_ardata (abfd
)->symdefs
= NULL
;
3298 bfd_ardata (abfd
)->extended_names
= NULL
;
3299 bfd_ardata (abfd
)->tdata
= NULL
;
3301 if (ecoff_slurp_armap (abfd
) == false
3302 || ecoff_slurp_extended_name_table (abfd
) == false)
3304 bfd_release (abfd
, bfd_ardata (abfd
));
3305 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3306 return (bfd_target
*) NULL
;
3312 /* ECOFF linker code. */
3314 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3315 PARAMS ((struct bfd_hash_entry
*entry
,
3316 struct bfd_hash_table
*table
,
3317 const char *string
));
3318 static boolean ecoff_link_add_archive_symbols
3319 PARAMS ((bfd
*, struct bfd_link_info
*));
3320 static boolean ecoff_link_check_archive_element
3321 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3322 static boolean ecoff_link_add_object_symbols
3323 PARAMS ((bfd
*, struct bfd_link_info
*));
3324 static boolean ecoff_link_add_externals
3325 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3327 /* Routine to create an entry in an ECOFF link hash table. */
3329 static struct bfd_hash_entry
*
3330 ecoff_link_hash_newfunc (entry
, table
, string
)
3331 struct bfd_hash_entry
*entry
;
3332 struct bfd_hash_table
*table
;
3335 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3337 /* Allocate the structure if it has not already been allocated by a
3339 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3340 ret
= ((struct ecoff_link_hash_entry
*)
3341 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3342 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3344 bfd_set_error (bfd_error_no_memory
);
3348 /* Call the allocation method of the superclass. */
3349 ret
= ((struct ecoff_link_hash_entry
*)
3350 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3355 /* Set local fields. */
3359 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3361 return (struct bfd_hash_entry
*) ret
;
3364 /* Create an ECOFF link hash table. */
3366 struct bfd_link_hash_table
*
3367 ecoff_bfd_link_hash_table_create (abfd
)
3370 struct ecoff_link_hash_table
*ret
;
3372 ret
= ((struct ecoff_link_hash_table
*)
3373 malloc (sizeof (struct ecoff_link_hash_table
)));
3376 bfd_set_error (bfd_error_no_memory
);
3379 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3380 ecoff_link_hash_newfunc
))
3383 return (struct bfd_link_hash_table
*) NULL
;
3388 /* Look up an entry in an ECOFF link hash table. */
3390 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3391 ((struct ecoff_link_hash_entry *) \
3392 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3394 /* Traverse an ECOFF link hash table. */
3396 #define ecoff_link_hash_traverse(table, func, info) \
3397 (bfd_link_hash_traverse \
3399 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3402 /* Get the ECOFF link hash table from the info structure. This is
3405 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3407 /* Given an ECOFF BFD, add symbols to the global hash table as
3411 ecoff_bfd_link_add_symbols (abfd
, info
)
3413 struct bfd_link_info
*info
;
3415 switch (bfd_get_format (abfd
))
3418 return ecoff_link_add_object_symbols (abfd
, info
);
3420 return ecoff_link_add_archive_symbols (abfd
, info
);
3422 bfd_set_error (bfd_error_wrong_format
);
3427 /* Add the symbols from an archive file to the global hash table.
3428 This looks through the undefined symbols, looks each one up in the
3429 archive hash table, and adds any associated object file. We do not
3430 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3431 already have a hash table, so there is no reason to construct
3435 ecoff_link_add_archive_symbols (abfd
, info
)
3437 struct bfd_link_info
*info
;
3439 const bfd_byte
*raw_armap
;
3440 struct bfd_link_hash_entry
**pundef
;
3441 unsigned int armap_count
;
3442 unsigned int armap_log
;
3444 const bfd_byte
*hashtable
;
3445 const char *stringbase
;
3447 if (! bfd_has_map (abfd
))
3449 bfd_set_error (bfd_error_no_symbols
);
3453 /* If we don't have any raw data for this archive, as can happen on
3454 Irix 4.0.5F, we call the generic routine.
3455 FIXME: We should be more clever about this, since someday tdata
3456 may get to something for a generic archive. */
3457 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3458 if (raw_armap
== (bfd_byte
*) NULL
)
3459 return (_bfd_generic_link_add_archive_symbols
3460 (abfd
, info
, ecoff_link_check_archive_element
));
3462 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3465 for (i
= 1; i
< armap_count
; i
<<= 1)
3467 BFD_ASSERT (i
== armap_count
);
3469 hashtable
= raw_armap
+ 4;
3470 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3472 /* Look through the list of undefined symbols. */
3473 pundef
= &info
->hash
->undefs
;
3474 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3476 struct bfd_link_hash_entry
*h
;
3477 unsigned int hash
, rehash
;
3478 unsigned int file_offset
;
3484 /* When a symbol is defined, it is not necessarily removed from
3486 if (h
->type
!= bfd_link_hash_undefined
3487 && h
->type
!= bfd_link_hash_common
)
3489 /* Remove this entry from the list, for general cleanliness
3490 and because we are going to look through the list again
3491 if we search any more libraries. We can't remove the
3492 entry if it is the tail, because that would lose any
3493 entries we add to the list later on. */
3494 if (*pundef
!= info
->hash
->undefs_tail
)
3495 *pundef
= (*pundef
)->next
;
3497 pundef
= &(*pundef
)->next
;
3501 /* Native ECOFF linkers do not pull in archive elements merely
3502 to satisfy common definitions, so neither do we. We leave
3503 them on the list, though, in case we are linking against some
3504 other object format. */
3505 if (h
->type
!= bfd_link_hash_undefined
)
3507 pundef
= &(*pundef
)->next
;
3511 /* Look for this symbol in the archive hash table. */
3512 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3515 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3516 if (file_offset
== 0)
3518 /* Nothing in this slot. */
3519 pundef
= &(*pundef
)->next
;
3523 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3524 if (name
[0] != h
->root
.string
[0]
3525 || strcmp (name
, h
->root
.string
) != 0)
3530 /* That was the wrong symbol. Try rehashing. */
3532 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3534 srch
= (srch
+ rehash
) & (armap_count
- 1))
3536 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3537 if (file_offset
== 0)
3539 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3540 if (name
[0] == h
->root
.string
[0]
3541 && strcmp (name
, h
->root
.string
) == 0)
3550 pundef
= &(*pundef
)->next
;
3557 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3558 if (element
== (bfd
*) NULL
)
3561 if (! bfd_check_format (element
, bfd_object
))
3564 /* Unlike the generic linker, we know that this element provides
3565 a definition for an undefined symbol and we know that we want
3566 to include it. We don't need to check anything. */
3567 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3569 if (! ecoff_link_add_object_symbols (element
, info
))
3572 pundef
= &(*pundef
)->next
;
3578 /* This is called if we used _bfd_generic_link_add_archive_symbols
3579 because we were not dealing with an ECOFF archive. */
3582 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3584 struct bfd_link_info
*info
;
3587 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3588 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3589 = backend
->debug_swap
.swap_ext_in
;
3591 bfd_size_type external_ext_size
;
3600 if (! ecoff_slurp_symbolic_header (abfd
))
3603 /* If there are no symbols, we don't want it. */
3604 if (bfd_get_symcount (abfd
) == 0)
3607 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3609 /* Read in the external symbols and external strings. */
3610 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3611 esize
= symhdr
->iextMax
* external_ext_size
;
3612 external_ext
= (PTR
) alloca (esize
);
3613 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3614 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3617 ssext
= (char *) alloca (symhdr
->issExtMax
);
3618 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3619 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3622 /* Look through the external symbols to see if they define some
3623 symbol that is currently undefined. */
3624 ext_ptr
= (char *) external_ext
;
3625 ext_end
= ext_ptr
+ esize
;
3626 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3631 struct bfd_link_hash_entry
*h
;
3633 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3635 /* See if this symbol defines something. */
3636 if (esym
.asym
.st
!= stGlobal
3637 && esym
.asym
.st
!= stLabel
3638 && esym
.asym
.st
!= stProc
)
3641 switch (esym
.asym
.sc
)
3664 name
= ssext
+ esym
.asym
.iss
;
3665 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3667 /* Unlike the generic linker, we do not pull in elements because
3668 of common symbols. */
3669 if (h
== (struct bfd_link_hash_entry
*) NULL
3670 || h
->type
!= bfd_link_hash_undefined
)
3673 /* Include this element. */
3674 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3676 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3686 /* Add symbols from an ECOFF object file to the global linker hash
3690 ecoff_link_add_object_symbols (abfd
, info
)
3692 struct bfd_link_info
*info
;
3695 bfd_size_type external_ext_size
;
3700 if (! ecoff_slurp_symbolic_header (abfd
))
3703 /* If there are no symbols, we don't want it. */
3704 if (bfd_get_symcount (abfd
) == 0)
3707 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3709 /* Read in the external symbols and external strings. */
3710 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3711 esize
= symhdr
->iextMax
* external_ext_size
;
3712 external_ext
= (PTR
) alloca (esize
);
3713 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3714 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3717 ssext
= (char *) alloca (symhdr
->issExtMax
);
3718 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3719 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3722 return ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3725 /* Add the external symbols of an object file to the global linker
3726 hash table. The external symbols and strings we are passed are
3727 just allocated on the stack, and will be discarded. We must
3728 explicitly save any information we may need later on in the link.
3729 We do not want to read the external symbol information again. */
3732 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3734 struct bfd_link_info
*info
;
3738 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3739 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3740 = backend
->debug_swap
.swap_ext_in
;
3741 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3742 unsigned long ext_count
;
3743 struct ecoff_link_hash_entry
**sym_hash
;
3747 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3749 sym_hash
= ((struct ecoff_link_hash_entry
**)
3751 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3754 bfd_set_error (bfd_error_no_memory
);
3757 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3759 ext_ptr
= (char *) external_ext
;
3760 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3761 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3768 struct ecoff_link_hash_entry
*h
;
3772 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3774 /* Skip debugging symbols. */
3776 switch (esym
.asym
.st
)
3792 /* Get the information for this symbol. */
3793 value
= esym
.asym
.value
;
3794 switch (esym
.asym
.sc
)
3814 section
= bfd_make_section_old_way (abfd
, ".text");
3815 value
-= section
->vma
;
3818 section
= bfd_make_section_old_way (abfd
, ".data");
3819 value
-= section
->vma
;
3822 section
= bfd_make_section_old_way (abfd
, ".bss");
3823 value
-= section
->vma
;
3826 section
= &bfd_abs_section
;
3829 section
= &bfd_und_section
;
3832 section
= bfd_make_section_old_way (abfd
, ".sdata");
3833 value
-= section
->vma
;
3836 section
= bfd_make_section_old_way (abfd
, ".sbss");
3837 value
-= section
->vma
;
3840 section
= bfd_make_section_old_way (abfd
, ".rdata");
3841 value
-= section
->vma
;
3844 if (value
> ecoff_data (abfd
)->gp_size
)
3846 section
= &bfd_com_section
;
3851 if (ecoff_scom_section
.name
== NULL
)
3853 /* Initialize the small common section. */
3854 ecoff_scom_section
.name
= SCOMMON
;
3855 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3856 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3857 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3858 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3859 ecoff_scom_symbol
.name
= SCOMMON
;
3860 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3861 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3862 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3864 section
= &ecoff_scom_section
;
3867 section
= &bfd_und_section
;
3870 section
= bfd_make_section_old_way (abfd
, ".init");
3871 value
-= section
->vma
;
3874 section
= bfd_make_section_old_way (abfd
, ".fini");
3875 value
-= section
->vma
;
3879 if (section
== (asection
*) NULL
)
3882 name
= ssext
+ esym
.asym
.iss
;
3884 if (! (_bfd_generic_link_add_one_symbol
3885 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3886 (const char *) NULL
, true, true, backend
->constructor_bitsize
,
3887 (struct bfd_link_hash_entry
**) &h
)))
3892 /* If we are building an ECOFF hash table, save the external
3893 symbol information. */
3894 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3896 if (h
->abfd
== (bfd
*) NULL
3897 || (section
!= &bfd_und_section
3898 && (! bfd_is_com_section (section
)
3899 || h
->root
.type
!= bfd_link_hash_defined
)))
3910 /* ECOFF final link routines. */
3912 static boolean ecoff_final_link_debug_accumulate
3913 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
3915 static boolean ecoff_link_write_external
3916 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3917 static boolean ecoff_indirect_link_order
3918 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3919 struct bfd_link_order
*));
3921 /* ECOFF final link routine. This looks through all the input BFDs
3922 and gathers together all the debugging information, and then
3923 processes all the link order information. This may cause it to
3924 close and reopen some input BFDs; I'll see how bad this is. */
3927 ecoff_bfd_final_link (abfd
, info
)
3929 struct bfd_link_info
*info
;
3931 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3932 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3935 register bfd
*input_bfd
;
3937 struct bfd_link_order
*p
;
3939 /* We accumulate the debugging information counts in the symbolic
3941 symhdr
= &debug
->symbolic_header
;
3943 symhdr
->ilineMax
= 0;
3947 symhdr
->isymMax
= 0;
3948 symhdr
->ioptMax
= 0;
3949 symhdr
->iauxMax
= 0;
3951 symhdr
->issExtMax
= 0;
3954 symhdr
->iextMax
= 0;
3956 /* We accumulate the debugging information itself in the debug_info
3959 debug
->external_dnr
= NULL
;
3960 debug
->external_pdr
= NULL
;
3961 debug
->external_sym
= NULL
;
3962 debug
->external_opt
= NULL
;
3963 debug
->external_aux
= NULL
;
3965 debug
->ssext
= debug
->ssext_end
= NULL
;
3966 debug
->external_fdr
= NULL
;
3967 debug
->external_rfd
= NULL
;
3968 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3970 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
3971 if (handle
== (PTR
) NULL
)
3974 /* Accumulate the debugging symbols from each input BFD. */
3975 for (input_bfd
= info
->input_bfds
;
3976 input_bfd
!= (bfd
*) NULL
;
3977 input_bfd
= input_bfd
->link_next
)
3981 /* If we might be using the C based alloca function, dump memory
3982 allocated by ecoff_final_link_debug_accumulate. */
3989 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
3991 /* Abitrarily set the symbolic header vstamp to the vstamp
3992 of the first object file in the link. */
3993 if (symhdr
->vstamp
== 0)
3995 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
3996 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4000 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4001 debug
, &backend
->debug_swap
,
4006 /* Combine the register masks. */
4007 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4008 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4009 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4010 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4011 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4012 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4015 /* Write out the external symbols. */
4016 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4017 ecoff_link_write_external
,
4020 if (info
->relocateable
)
4022 /* We need to make a pass over the link_orders to count up the
4023 number of relocations we will need to output, so that we know
4024 how much space they will take up. */
4025 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4028 for (p
= o
->link_order_head
;
4029 p
!= (struct bfd_link_order
*) NULL
;
4031 if (p
->type
== bfd_indirect_link_order
)
4032 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4036 /* Compute the reloc and symbol file positions. */
4037 ecoff_compute_reloc_file_positions (abfd
);
4039 /* Write out the debugging information. */
4040 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4041 &backend
->debug_swap
, info
,
4042 ecoff_data (abfd
)->sym_filepos
))
4045 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4047 if (info
->relocateable
)
4049 /* Now reset the reloc_count field of the sections in the output
4050 BFD to 0, so that we can use them to keep track of how many
4051 relocs we have output thus far. */
4052 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4056 /* Get a value for the GP register. */
4057 if (ecoff_data (abfd
)->gp
== 0)
4059 struct bfd_link_hash_entry
*h
;
4061 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4062 if (h
!= (struct bfd_link_hash_entry
*) NULL
4063 && h
->type
== bfd_link_hash_defined
)
4064 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4065 + h
->u
.def
.section
->output_section
->vma
4066 + h
->u
.def
.section
->output_offset
);
4067 else if (info
->relocateable
)
4071 /* Make up a value. */
4073 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4076 && (strcmp (o
->name
, _SBSS
) == 0
4077 || strcmp (o
->name
, _SDATA
) == 0
4078 || strcmp (o
->name
, _LIT4
) == 0
4079 || strcmp (o
->name
, _LIT8
) == 0
4080 || strcmp (o
->name
, _LITA
) == 0))
4083 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4087 /* If the relocate_section function needs to do a reloc
4088 involving the GP value, it should make a reloc_dangerous
4089 callback to warn that GP is not defined. */
4093 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4095 /* Ignore any link_orders for the .reginfo section, which does
4096 not really exist. */
4097 if (strcmp (o
->name
, REGINFO
) == 0)
4100 for (p
= o
->link_order_head
;
4101 p
!= (struct bfd_link_order
*) NULL
;
4104 /* If we might be using the C based alloca function, we need
4105 to dump the memory allocated by the function
4106 ecoff_indirect_link_order. */
4112 if (p
->type
== bfd_indirect_link_order
4113 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4114 == bfd_target_ecoff_flavour
))
4116 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4121 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4127 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4132 /* Accumulate the debugging information for an input BFD into the
4133 output BFD. This must read in the symbolic information of the
4137 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4140 struct bfd_link_info
*info
;
4143 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4144 const struct ecoff_debug_swap
* const swap
=
4145 &ecoff_backend (input_bfd
)->debug_swap
;
4146 HDRR
*symhdr
= &debug
->symbolic_header
;
4149 #define READ(ptr, offset, count, size, type) \
4150 if (symhdr->count == 0) \
4151 debug->ptr = NULL; \
4154 debug->ptr = (type) alloca (size * symhdr->count); \
4155 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4157 || (bfd_read (debug->ptr, size, symhdr->count, \
4158 input_bfd) != size * symhdr->count)) \
4162 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4163 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4164 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4165 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4166 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4167 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4169 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4170 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4171 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4174 /* We do not read the external strings or the external symbols. */
4176 ret
= (bfd_ecoff_debug_accumulate
4177 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4178 &ecoff_backend (output_bfd
)->debug_swap
,
4179 input_bfd
, debug
, swap
, info
));
4181 /* Make sure we don't accidentally follow one of these pointers on
4184 debug
->external_dnr
= NULL
;
4185 debug
->external_pdr
= NULL
;
4186 debug
->external_sym
= NULL
;
4187 debug
->external_opt
= NULL
;
4188 debug
->external_aux
= NULL
;
4190 debug
->external_fdr
= NULL
;
4191 debug
->external_rfd
= NULL
;
4196 /* Put out information for an external symbol. These come only from
4200 ecoff_link_write_external (h
, data
)
4201 struct ecoff_link_hash_entry
*h
;
4204 bfd
*output_bfd
= (bfd
*) data
;
4206 /* FIXME: We should check if this symbol is being stripped. */
4208 if (h
->root
.written
)
4211 if (h
->abfd
== (bfd
*) NULL
)
4214 h
->esym
.cobol_main
= 0;
4215 h
->esym
.weakext
= 0;
4216 h
->esym
.reserved
= 0;
4217 h
->esym
.ifd
= ifdNil
;
4218 h
->esym
.asym
.value
= 0;
4219 /* FIXME: we can do better than this for st and sc. */
4220 h
->esym
.asym
.st
= stGlobal
;
4221 h
->esym
.asym
.sc
= scAbs
;
4222 h
->esym
.asym
.reserved
= 0;
4223 h
->esym
.asym
.index
= indexNil
;
4225 else if (h
->esym
.ifd
!= -1)
4227 struct ecoff_debug_info
*debug
;
4229 /* Adjust the FDR index for the symbol by that used for the
4231 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4232 BFD_ASSERT (h
->esym
.ifd
>= 0
4233 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4234 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4237 switch (h
->root
.type
)
4240 case bfd_link_hash_new
:
4242 case bfd_link_hash_undefined
:
4243 case bfd_link_hash_weak
:
4244 if (h
->esym
.asym
.st
!= scUndefined
4245 && h
->esym
.asym
.st
!= scSUndefined
)
4246 h
->esym
.asym
.st
= scUndefined
;
4248 case bfd_link_hash_defined
:
4249 if (h
->esym
.asym
.sc
== scUndefined
4250 || h
->esym
.asym
.sc
== scSUndefined
)
4251 h
->esym
.asym
.sc
= scAbs
;
4252 else if (h
->esym
.asym
.sc
== scCommon
)
4253 h
->esym
.asym
.sc
= scBss
;
4254 else if (h
->esym
.asym
.sc
== scSCommon
)
4255 h
->esym
.asym
.sc
= scSBss
;
4256 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4257 + h
->root
.u
.def
.section
->output_section
->vma
4258 + h
->root
.u
.def
.section
->output_offset
);
4260 case bfd_link_hash_common
:
4261 if (h
->esym
.asym
.sc
!= scCommon
4262 && h
->esym
.asym
.sc
!= scSCommon
)
4263 h
->esym
.asym
.sc
= scCommon
;
4264 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4266 case bfd_link_hash_indirect
:
4267 case bfd_link_hash_warning
:
4268 /* FIXME: Ignore these for now. The circumstances under which
4269 they should be written out are not clear to me. */
4273 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4275 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4276 h
->root
.written
= true;
4278 return (bfd_ecoff_debug_one_external
4279 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4280 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4284 /* Relocate and write an ECOFF section into an ECOFF output file. */
4287 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4289 struct bfd_link_info
*info
;
4290 asection
*output_section
;
4291 struct bfd_link_order
*link_order
;
4293 asection
*input_section
;
4295 bfd_size_type input_size
;
4297 bfd_size_type external_reloc_size
;
4298 bfd_size_type external_relocs_size
;
4299 PTR external_relocs
;
4301 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4303 if (link_order
->size
== 0)
4306 input_section
= link_order
->u
.indirect
.section
;
4307 input_bfd
= input_section
->owner
;
4309 BFD_ASSERT (input_section
->output_section
== output_section
);
4310 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4311 BFD_ASSERT (bfd_section_size (input_bfd
, input_section
) == link_order
->size
);
4313 /* Get the section contents. */
4314 input_size
= bfd_section_size (input_bfd
, input_section
);
4315 contents
= (bfd_byte
*) alloca (input_size
);
4316 if (! bfd_get_section_contents (input_bfd
, input_section
, (PTR
) contents
,
4317 (file_ptr
) 0, input_size
))
4320 /* Get the relocs. */
4321 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4322 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4323 external_relocs
= (PTR
) alloca (external_relocs_size
);
4324 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4325 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4326 != external_relocs_size
))
4329 /* Relocate the section contents. */
4330 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4331 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4335 /* Write out the relocated section. */
4336 if (! bfd_set_section_contents (output_bfd
,
4339 input_section
->output_offset
,
4343 /* If we are producing relocateable output, the relocs were
4344 modified, and we write them out now. We use the reloc_count
4345 field of output_section to keep track of the number of relocs we
4346 have output so far. */
4347 if (info
->relocateable
)
4349 if (bfd_seek (output_bfd
,
4350 (output_section
->rel_filepos
+
4351 output_section
->reloc_count
* external_reloc_size
),
4353 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4354 != external_relocs_size
))
4356 output_section
->reloc_count
+= input_section
->reloc_count
;