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_error
= no_memory
;
89 /* This is a hook called by coff_real_object_p to create any backend
90 specific information. */
93 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
98 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
99 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
100 ecoff_data_type
*ecoff
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 /* Create the .reginfo section to give programs outside BFD a way to
111 see the information stored in the a.out header. See the comment
113 regsec
= bfd_make_section (abfd
, REGINFO
);
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 /* For the .pdata section, which has a special meaning on the Alpha,
160 we set the alignment to 8. We correct this later in
161 ecoff_compute_section_file_positions. We do this hackery because
162 we need to know the exact unaligned size of the .pdata section in
163 order to set the lnnoptr field correctly. */
164 if (strcmp (section
->name
, _PDATA
) == 0)
165 section
->alignment_power
= 3;
167 section
->alignment_power
= abfd
->xvec
->align_power_min
;
169 if (strcmp (section
->name
, _TEXT
) == 0)
170 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
171 else if (strcmp (section
->name
, _DATA
) == 0
172 || strcmp (section
->name
, _SDATA
) == 0)
173 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
174 else if (strcmp (section
->name
, _RDATA
) == 0
175 || strcmp (section
->name
, _LIT8
) == 0
176 || strcmp (section
->name
, _LIT4
) == 0)
177 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
178 else if (strcmp (section
->name
, _BSS
) == 0
179 || strcmp (section
->name
, _SBSS
) == 0)
180 section
->flags
|= SEC_ALLOC
;
181 else if (strcmp (section
->name
, REGINFO
) == 0)
183 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
184 section completely alone. */
185 section
->flags
|= (SEC_SHARED_LIBRARY
188 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
191 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
192 uncertain about .init on some systems and I don't know how shared
198 /* Determine the machine architecture and type. This is called from
199 the generic COFF routines. It is the inverse of ecoff_get_magic,
200 below. This could be an ECOFF backend routine, with one version
201 for each target, but there aren't all that many ECOFF targets. */
204 ecoff_set_arch_mach_hook (abfd
, filehdr
)
208 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
209 enum bfd_architecture arch
;
212 switch (internal_f
->f_magic
)
215 case MIPS_MAGIC_LITTLE
:
217 arch
= bfd_arch_mips
;
221 case MIPS_MAGIC_LITTLE2
:
222 case MIPS_MAGIC_BIG2
:
223 /* MIPS ISA level 2: the r6000 */
224 arch
= bfd_arch_mips
;
228 case MIPS_MAGIC_LITTLE3
:
229 case MIPS_MAGIC_BIG3
:
230 /* MIPS ISA level 3: the r4000 */
231 arch
= bfd_arch_mips
;
236 arch
= bfd_arch_alpha
;
241 arch
= bfd_arch_obscure
;
246 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
249 /* Get the magic number to use based on the architecture and machine.
250 This is the inverse of ecoff_set_arch_mach_hook, above. */
253 ecoff_get_magic (abfd
)
258 switch (bfd_get_arch (abfd
))
261 switch (bfd_get_mach (abfd
))
266 big
= MIPS_MAGIC_BIG
;
267 little
= MIPS_MAGIC_LITTLE
;
271 big
= MIPS_MAGIC_BIG2
;
272 little
= MIPS_MAGIC_LITTLE2
;
276 big
= MIPS_MAGIC_BIG3
;
277 little
= MIPS_MAGIC_LITTLE3
;
281 return abfd
->xvec
->byteorder_big_p
? big
: little
;
292 /* Get the section s_flags to use for a section. */
295 ecoff_sec_to_styp_flags (name
, flags
)
303 if (strcmp (name
, _TEXT
) == 0)
305 else if (strcmp (name
, _DATA
) == 0)
307 else if (strcmp (name
, _SDATA
) == 0)
309 else if (strcmp (name
, _RDATA
) == 0)
311 else if (strcmp (name
, _LITA
) == 0)
313 else if (strcmp (name
, _LIT8
) == 0)
315 else if (strcmp (name
, _LIT4
) == 0)
317 else if (strcmp (name
, _BSS
) == 0)
319 else if (strcmp (name
, _SBSS
) == 0)
321 else if (strcmp (name
, _INIT
) == 0)
322 styp
= STYP_ECOFF_INIT
;
323 else if (strcmp (name
, _FINI
) == 0)
324 styp
= STYP_ECOFF_FINI
;
325 else if (strcmp (name
, _PDATA
) == 0)
327 else if (strcmp (name
, _XDATA
) == 0)
329 else if (flags
& SEC_CODE
)
331 else if (flags
& SEC_DATA
)
333 else if (flags
& SEC_READONLY
)
335 else if (flags
& SEC_LOAD
)
340 if (flags
& SEC_NEVER_LOAD
)
346 /* Get the BFD flags to use for a section. */
350 ecoff_styp_to_sec_flags (abfd
, hdr
)
354 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
355 long styp_flags
= internal_s
->s_flags
;
356 flagword sec_flags
=0;
358 if (styp_flags
& STYP_NOLOAD
)
359 sec_flags
|= SEC_NEVER_LOAD
;
361 /* For 386 COFF, at least, an unloadable text or data section is
362 actually a shared library section. */
363 if ((styp_flags
& STYP_TEXT
)
364 || (styp_flags
& STYP_ECOFF_INIT
)
365 || (styp_flags
& STYP_ECOFF_FINI
))
367 if (sec_flags
& SEC_NEVER_LOAD
)
368 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
370 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
372 else if ((styp_flags
& STYP_DATA
)
373 || (styp_flags
& STYP_RDATA
)
374 || (styp_flags
& STYP_SDATA
))
376 if (sec_flags
& SEC_NEVER_LOAD
)
377 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
379 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
380 if (styp_flags
& STYP_RDATA
)
381 sec_flags
|= SEC_READONLY
;
383 else if ((styp_flags
& STYP_BSS
)
384 || (styp_flags
& STYP_SBSS
))
386 sec_flags
|= SEC_ALLOC
;
388 else if (styp_flags
& STYP_INFO
)
390 sec_flags
|= SEC_NEVER_LOAD
;
392 else if ((styp_flags
& STYP_LITA
)
393 || (styp_flags
& STYP_LIT8
)
394 || (styp_flags
& STYP_LIT4
))
396 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
400 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
406 /* Routines to swap auxiliary information in and out. I am assuming
407 that the auxiliary information format is always going to be target
410 /* Swap in a type information record.
411 BIGEND says whether AUX symbols are big-endian or little-endian; this
412 info comes from the file header record (fh-fBigendian). */
415 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
417 struct tir_ext
*ext_copy
;
420 struct tir_ext ext
[1];
422 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
424 /* now the fun stuff... */
426 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
427 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
428 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
429 >> TIR_BITS1_BT_SH_BIG
;
430 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
431 >> TIR_BITS_TQ4_SH_BIG
;
432 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
433 >> TIR_BITS_TQ5_SH_BIG
;
434 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
435 >> TIR_BITS_TQ0_SH_BIG
;
436 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
437 >> TIR_BITS_TQ1_SH_BIG
;
438 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
439 >> TIR_BITS_TQ2_SH_BIG
;
440 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
441 >> TIR_BITS_TQ3_SH_BIG
;
443 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
444 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
445 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
446 >> TIR_BITS1_BT_SH_LITTLE
;
447 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
448 >> TIR_BITS_TQ4_SH_LITTLE
;
449 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
450 >> TIR_BITS_TQ5_SH_LITTLE
;
451 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
452 >> TIR_BITS_TQ0_SH_LITTLE
;
453 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
454 >> TIR_BITS_TQ1_SH_LITTLE
;
455 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
456 >> TIR_BITS_TQ2_SH_LITTLE
;
457 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
458 >> TIR_BITS_TQ3_SH_LITTLE
;
462 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
467 /* Swap out a type information record.
468 BIGEND says whether AUX symbols are big-endian or little-endian; this
469 info comes from the file header record (fh-fBigendian). */
472 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
479 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
481 /* now the fun stuff... */
483 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
484 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
485 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
486 & TIR_BITS1_BT_BIG
));
487 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
489 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
490 & TIR_BITS_TQ5_BIG
));
491 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
493 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
494 & TIR_BITS_TQ1_BIG
));
495 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
497 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
498 & TIR_BITS_TQ3_BIG
));
500 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
501 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
502 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
503 & TIR_BITS1_BT_LITTLE
));
504 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
505 & TIR_BITS_TQ4_LITTLE
)
506 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
507 & TIR_BITS_TQ5_LITTLE
));
508 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
509 & TIR_BITS_TQ0_LITTLE
)
510 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
511 & TIR_BITS_TQ1_LITTLE
));
512 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
513 & TIR_BITS_TQ2_LITTLE
)
514 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
515 & TIR_BITS_TQ3_LITTLE
));
519 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
524 /* Swap in a relative symbol record. BIGEND says whether it is in
525 big-endian or little-endian format.*/
528 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
530 struct rndx_ext
*ext_copy
;
533 struct rndx_ext ext
[1];
535 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
537 /* now the fun stuff... */
539 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
540 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
541 >> RNDX_BITS1_RFD_SH_BIG
);
542 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
543 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
544 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
545 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
547 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
548 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
549 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
550 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
551 >> RNDX_BITS1_INDEX_SH_LITTLE
)
552 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
553 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
557 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
562 /* Swap out a relative symbol record. BIGEND says whether it is in
563 big-endian or little-endian format.*/
566 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
569 struct rndx_ext
*ext
;
573 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
575 /* now the fun stuff... */
577 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
578 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
579 & RNDX_BITS1_RFD_BIG
)
580 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
581 & RNDX_BITS1_INDEX_BIG
));
582 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
583 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
585 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
586 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
587 & RNDX_BITS1_RFD_LITTLE
)
588 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
589 & RNDX_BITS1_INDEX_LITTLE
));
590 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
591 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
595 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
600 /* Read in the symbolic header for an ECOFF object file. */
603 ecoff_slurp_symbolic_header (abfd
)
606 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
607 bfd_size_type external_hdr_size
;
609 HDRR
*internal_symhdr
;
611 /* See if we've already read it in. */
612 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
613 backend
->debug_swap
.sym_magic
)
616 /* See whether there is a symbolic header. */
617 if (ecoff_data (abfd
)->sym_filepos
== 0)
619 bfd_get_symcount (abfd
) = 0;
623 /* At this point bfd_get_symcount (abfd) holds the number of symbols
624 as read from the file header, but on ECOFF this is always the
625 size of the symbolic information header. It would be cleaner to
626 handle this when we first read the file in coffgen.c. */
627 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
628 if (bfd_get_symcount (abfd
) != external_hdr_size
)
630 bfd_error
= bad_value
;
634 /* Read the symbolic information header. */
635 raw
= (PTR
) alloca ((size_t) external_hdr_size
);
636 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
637 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
638 != external_hdr_size
))
640 bfd_error
= system_call_error
;
643 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
644 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
646 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
648 bfd_error
= bad_value
;
652 /* Now we can get the correct number of symbols. */
653 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
654 + internal_symhdr
->iextMax
);
659 /* Read in and swap the important symbolic information for an ECOFF
660 object file. This is called by gdb. */
663 ecoff_slurp_symbolic_info (abfd
)
666 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
667 HDRR
*internal_symhdr
;
668 bfd_size_type raw_base
;
669 bfd_size_type raw_size
;
671 bfd_size_type external_fdr_size
;
675 bfd_size_type raw_end
;
676 bfd_size_type cb_end
;
678 /* Check whether we've already gotten it, and whether there's any to
680 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
682 if (ecoff_data (abfd
)->sym_filepos
== 0)
684 bfd_get_symcount (abfd
) = 0;
688 if (! ecoff_slurp_symbolic_header (abfd
))
691 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
693 /* Read all the symbolic information at once. */
694 raw_base
= (ecoff_data (abfd
)->sym_filepos
695 + backend
->debug_swap
.external_hdr_size
);
697 /* Alpha ecoff makes the determination of raw_size difficult. It has
698 an undocumented debug data section between the symhdr and the first
699 documented section. And the ordering of the sections varies between
700 statically and dynamically linked executables.
701 If bfd supports SEEK_END someday, this code could be simplified. */
705 #define UPDATE_RAW_END(start, count, size) \
706 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
707 if (cb_end > raw_end) \
710 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
711 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
712 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
713 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
714 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
715 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
716 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
717 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
718 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
719 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
720 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
722 #undef UPDATE_RAW_END
724 raw_size
= raw_end
- raw_base
;
727 ecoff_data (abfd
)->sym_filepos
= 0;
730 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
733 bfd_error
= no_memory
;
737 (ecoff_data (abfd
)->sym_filepos
738 + backend
->debug_swap
.external_hdr_size
),
740 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
742 bfd_error
= system_call_error
;
743 bfd_release (abfd
, raw
);
747 ecoff_data (abfd
)->raw_syments
= raw
;
749 /* Get pointers for the numeric offsets in the HDRR structure. */
750 #define FIX(off1, off2, type) \
751 if (internal_symhdr->off1 == 0) \
752 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
754 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
755 + internal_symhdr->off1 \
757 FIX (cbLineOffset
, line
, unsigned char *);
758 FIX (cbDnOffset
, external_dnr
, PTR
);
759 FIX (cbPdOffset
, external_pdr
, PTR
);
760 FIX (cbSymOffset
, external_sym
, PTR
);
761 FIX (cbOptOffset
, external_opt
, PTR
);
762 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
763 FIX (cbSsOffset
, ss
, char *);
764 FIX (cbSsExtOffset
, ssext
, char *);
765 FIX (cbFdOffset
, external_fdr
, PTR
);
766 FIX (cbRfdOffset
, external_rfd
, PTR
);
767 FIX (cbExtOffset
, external_ext
, PTR
);
770 /* I don't want to always swap all the data, because it will just
771 waste time and most programs will never look at it. The only
772 time the linker needs most of the debugging information swapped
773 is when linking big-endian and little-endian MIPS object files
774 together, which is not a common occurrence.
776 We need to look at the fdr to deal with a lot of information in
777 the symbols, so we swap them here. */
778 ecoff_data (abfd
)->debug_info
.fdr
=
779 (struct fdr
*) bfd_alloc (abfd
,
780 (internal_symhdr
->ifdMax
*
781 sizeof (struct fdr
)));
782 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
784 bfd_error
= no_memory
;
787 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
788 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
789 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
790 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
791 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
792 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
797 /* ECOFF symbol table routines. The ECOFF symbol table is described
798 in gcc/mips-tfile.c. */
800 /* ECOFF uses two common sections. One is the usual one, and the
801 other is for small objects. All the small objects are kept
802 together, and then referenced via the gp pointer, which yields
803 faster assembler code. This is what we use for the small common
805 static asection ecoff_scom_section
;
806 static asymbol ecoff_scom_symbol
;
807 static asymbol
*ecoff_scom_symbol_ptr
;
809 /* Create an empty symbol. */
812 ecoff_make_empty_symbol (abfd
)
815 ecoff_symbol_type
*new;
817 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
818 if (new == (ecoff_symbol_type
*) NULL
)
820 bfd_error
= no_memory
;
821 return (asymbol
*) NULL
;
823 memset (new, 0, sizeof *new);
824 new->symbol
.section
= (asection
*) NULL
;
825 new->fdr
= (FDR
*) NULL
;
828 new->symbol
.the_bfd
= abfd
;
832 /* Set the BFD flags and section for an ECOFF symbol. */
835 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
840 asymbol
**indirect_ptr_ptr
;
842 asym
->the_bfd
= abfd
;
843 asym
->value
= ecoff_sym
->value
;
844 asym
->section
= &bfd_debug_section
;
847 /* An indirect symbol requires two consecutive stabs symbols. */
848 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
850 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
852 /* @@ Stuffing pointers into integers is a no-no.
853 We can usually get away with it if the integer is
854 large enough though. */
855 if (sizeof (asym
) > sizeof (bfd_vma
))
857 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
859 asym
->flags
= BSF_DEBUGGING
;
860 asym
->section
= &bfd_und_section
;
861 *indirect_ptr_ptr
= NULL
;
865 if (ECOFF_IS_STAB (ecoff_sym
)
866 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
868 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
869 asym
->section
= &bfd_ind_section
;
870 /* Pass this symbol on to the next call to this function. */
871 *indirect_ptr_ptr
= asym
;
875 /* Most symbol types are just for debugging. */
876 switch (ecoff_sym
->st
)
885 if (ECOFF_IS_STAB (ecoff_sym
))
887 asym
->flags
= BSF_DEBUGGING
;
892 asym
->flags
= BSF_DEBUGGING
;
897 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
899 asym
->flags
= BSF_LOCAL
;
900 switch (ecoff_sym
->sc
)
903 /* Used for compiler generated labels. Leave them in the
904 debugging section, and mark them as local. If BSF_DEBUGGING
905 is set, then nm does not display them for some reason. If no
906 flags are set then the linker whines about them. */
907 asym
->flags
= BSF_LOCAL
;
910 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
911 asym
->value
-= asym
->section
->vma
;
914 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
915 asym
->value
-= asym
->section
->vma
;
918 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
919 asym
->value
-= asym
->section
->vma
;
922 asym
->flags
= BSF_DEBUGGING
;
925 asym
->section
= &bfd_abs_section
;
928 asym
->section
= &bfd_und_section
;
938 asym
->flags
= BSF_DEBUGGING
;
941 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
942 asym
->value
-= asym
->section
->vma
;
945 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
946 asym
->value
-= asym
->section
->vma
;
949 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
950 asym
->value
-= asym
->section
->vma
;
953 asym
->flags
= BSF_DEBUGGING
;
956 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
958 asym
->section
= &bfd_com_section
;
964 if (ecoff_scom_section
.name
== NULL
)
966 /* Initialize the small common section. */
967 ecoff_scom_section
.name
= SCOMMON
;
968 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
969 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
970 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
971 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
972 ecoff_scom_symbol
.name
= SCOMMON
;
973 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
974 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
975 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
977 asym
->section
= &ecoff_scom_section
;
982 asym
->flags
= BSF_DEBUGGING
;
985 asym
->section
= &bfd_und_section
;
990 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
991 asym
->value
-= asym
->section
->vma
;
996 asym
->flags
= BSF_DEBUGGING
;
999 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1000 asym
->value
-= asym
->section
->vma
;
1006 /* Look for special constructors symbols and make relocation entries
1007 in a special construction section. These are produced by the
1008 -fgnu-linker argument to g++. */
1009 if (ECOFF_IS_STAB (ecoff_sym
))
1011 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1023 arelent_chain
*reloc_chain
;
1024 unsigned int bitsize
;
1026 /* Get a section with the same name as the symbol (usually
1027 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1028 name ___CTOR_LIST (three underscores). We need
1029 __CTOR_LIST (two underscores), since ECOFF doesn't use
1030 a leading underscore. This should be handled by gcc,
1031 but instead we do it here. Actually, this should all
1032 be done differently anyhow. */
1033 name
= bfd_asymbol_name (asym
);
1034 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1039 section
= bfd_get_section_by_name (abfd
, name
);
1040 if (section
== (asection
*) NULL
)
1044 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1047 bfd_error
= no_memory
;
1050 strcpy (copy
, name
);
1051 section
= bfd_make_section (abfd
, copy
);
1054 /* Build a reloc pointing to this constructor. */
1056 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1059 bfd_error
= no_memory
;
1062 reloc_chain
->relent
.sym_ptr_ptr
=
1063 bfd_get_section (asym
)->symbol_ptr_ptr
;
1064 reloc_chain
->relent
.address
= section
->_raw_size
;
1065 reloc_chain
->relent
.addend
= asym
->value
;
1066 reloc_chain
->relent
.howto
=
1067 ecoff_backend (abfd
)->constructor_reloc
;
1069 /* Set up the constructor section to hold the reloc. */
1070 section
->flags
= SEC_CONSTRUCTOR
;
1071 ++section
->reloc_count
;
1073 /* Constructor sections must be rounded to a boundary
1074 based on the bitsize. These are not real sections--
1075 they are handled specially by the linker--so the ECOFF
1076 16 byte alignment restriction does not apply. */
1077 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1078 section
->alignment_power
= 1;
1079 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1080 ++section
->alignment_power
;
1082 reloc_chain
->next
= section
->constructor_chain
;
1083 section
->constructor_chain
= reloc_chain
;
1084 section
->_raw_size
+= bitsize
/ 8;
1086 /* Mark the symbol as a constructor. */
1087 asym
->flags
|= BSF_CONSTRUCTOR
;
1095 /* Read an ECOFF symbol table. */
1098 ecoff_slurp_symbol_table (abfd
)
1101 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1102 const bfd_size_type external_ext_size
1103 = backend
->debug_swap
.external_ext_size
;
1104 const bfd_size_type external_sym_size
1105 = backend
->debug_swap
.external_sym_size
;
1106 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1107 = backend
->debug_swap
.swap_ext_in
;
1108 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1109 = backend
->debug_swap
.swap_sym_in
;
1110 bfd_size_type internal_size
;
1111 ecoff_symbol_type
*internal
;
1112 ecoff_symbol_type
*internal_ptr
;
1113 asymbol
*indirect_ptr
;
1119 /* If we've already read in the symbol table, do nothing. */
1120 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1123 /* Get the symbolic information. */
1124 if (ecoff_slurp_symbolic_info (abfd
) == false)
1126 if (bfd_get_symcount (abfd
) == 0)
1129 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1130 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1131 if (internal
== NULL
)
1133 bfd_error
= no_memory
;
1137 internal_ptr
= internal
;
1138 indirect_ptr
= NULL
;
1139 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1140 eraw_end
= (eraw_src
1141 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1142 * external_ext_size
));
1143 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1147 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1148 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1149 + internal_esym
.asym
.iss
);
1150 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1151 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1153 /* The alpha uses a negative ifd field for section symbols. */
1154 if (internal_esym
.ifd
>= 0)
1155 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1156 + internal_esym
.ifd
);
1158 internal_ptr
->fdr
= NULL
;
1159 internal_ptr
->local
= false;
1160 internal_ptr
->native
= (PTR
) eraw_src
;
1162 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1164 /* The local symbols must be accessed via the fdr's, because the
1165 string and aux indices are relative to the fdr information. */
1166 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1167 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1168 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1173 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1174 + fdr_ptr
->isymBase
* external_sym_size
);
1175 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1177 lraw_src
< lraw_end
;
1178 lraw_src
+= external_sym_size
, internal_ptr
++)
1182 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1183 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1185 + internal_sym
.iss
);
1186 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1187 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1189 internal_ptr
->fdr
= fdr_ptr
;
1190 internal_ptr
->local
= true;
1191 internal_ptr
->native
= (PTR
) lraw_src
;
1194 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1196 ecoff_data (abfd
)->canonical_symbols
= internal
;
1201 /* Return the amount of space needed for the canonical symbols. */
1204 ecoff_get_symtab_upper_bound (abfd
)
1207 if (ecoff_slurp_symbolic_info (abfd
) == false
1208 || bfd_get_symcount (abfd
) == 0)
1211 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1214 /* Get the canonical symbols. */
1217 ecoff_get_symtab (abfd
, alocation
)
1219 asymbol
**alocation
;
1221 unsigned int counter
= 0;
1222 ecoff_symbol_type
*symbase
;
1223 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1225 if (ecoff_slurp_symbol_table (abfd
) == false
1226 || bfd_get_symcount (abfd
) == 0)
1229 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1230 while (counter
< bfd_get_symcount (abfd
))
1232 *(location
++) = symbase
++;
1235 *location
++ = (ecoff_symbol_type
*) NULL
;
1236 return bfd_get_symcount (abfd
);
1239 /* Turn ECOFF type information into a printable string.
1240 ecoff_emit_aggregate and ecoff_type_to_string are from
1241 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1243 /* Write aggregate information to a string. */
1246 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1253 int ifd
= rndx
->rfd
;
1254 int indx
= rndx
->index
;
1255 int sym_base
, ss_base
;
1261 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1262 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1264 if (indx
== indexNil
)
1265 name
= "/* no name */";
1268 const struct ecoff_debug_swap
* const debug_swap
1269 = &ecoff_backend (abfd
)->debug_swap
;
1273 (*debug_swap
->swap_sym_in
)
1275 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1276 + indx
* debug_swap
->external_sym_size
),
1278 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1282 "%s %s { ifd = %d, index = %ld }",
1285 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1288 /* Convert the type information to string format. */
1291 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1293 union aux_ext
*aux_ptr
;
1305 unsigned int basic_type
;
1307 static char buffer1
[1024];
1308 static char buffer2
[1024];
1313 for (i
= 0; i
< 7; i
++)
1315 qualifiers
[i
].low_bound
= 0;
1316 qualifiers
[i
].high_bound
= 0;
1317 qualifiers
[i
].stride
= 0;
1320 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1321 return "-1 (no type)";
1322 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1324 basic_type
= u
.ti
.bt
;
1325 qualifiers
[0].type
= u
.ti
.tq0
;
1326 qualifiers
[1].type
= u
.ti
.tq1
;
1327 qualifiers
[2].type
= u
.ti
.tq2
;
1328 qualifiers
[3].type
= u
.ti
.tq3
;
1329 qualifiers
[4].type
= u
.ti
.tq4
;
1330 qualifiers
[5].type
= u
.ti
.tq5
;
1331 qualifiers
[6].type
= tqNil
;
1334 * Go get the basic type.
1338 case btNil
: /* undefined */
1342 case btAdr
: /* address - integer same size as pointer */
1343 strcpy (p1
, "address");
1346 case btChar
: /* character */
1347 strcpy (p1
, "char");
1350 case btUChar
: /* unsigned character */
1351 strcpy (p1
, "unsigned char");
1354 case btShort
: /* short */
1355 strcpy (p1
, "short");
1358 case btUShort
: /* unsigned short */
1359 strcpy (p1
, "unsigned short");
1362 case btInt
: /* int */
1366 case btUInt
: /* unsigned int */
1367 strcpy (p1
, "unsigned int");
1370 case btLong
: /* long */
1371 strcpy (p1
, "long");
1374 case btULong
: /* unsigned long */
1375 strcpy (p1
, "unsigned long");
1378 case btFloat
: /* float (real) */
1379 strcpy (p1
, "float");
1382 case btDouble
: /* Double (real) */
1383 strcpy (p1
, "double");
1386 /* Structures add 1-2 aux words:
1387 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1388 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1390 case btStruct
: /* Structure (Record) */
1391 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1392 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1393 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1395 indx
++; /* skip aux words */
1398 /* Unions add 1-2 aux words:
1399 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1400 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1402 case btUnion
: /* Union */
1403 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1404 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1405 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1407 indx
++; /* skip aux words */
1410 /* Enumerations add 1-2 aux words:
1411 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1412 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1414 case btEnum
: /* Enumeration */
1415 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1416 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1417 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1419 indx
++; /* skip aux words */
1422 case btTypedef
: /* defined via a typedef, isymRef points */
1423 strcpy (p1
, "typedef");
1426 case btRange
: /* subrange of int */
1427 strcpy (p1
, "subrange");
1430 case btSet
: /* pascal sets */
1434 case btComplex
: /* fortran complex */
1435 strcpy (p1
, "complex");
1438 case btDComplex
: /* fortran double complex */
1439 strcpy (p1
, "double complex");
1442 case btIndirect
: /* forward or unnamed typedef */
1443 strcpy (p1
, "forward/unamed typedef");
1446 case btFixedDec
: /* Fixed Decimal */
1447 strcpy (p1
, "fixed decimal");
1450 case btFloatDec
: /* Float Decimal */
1451 strcpy (p1
, "float decimal");
1454 case btString
: /* Varying Length Character String */
1455 strcpy (p1
, "string");
1458 case btBit
: /* Aligned Bit String */
1462 case btPicture
: /* Picture */
1463 strcpy (p1
, "picture");
1466 case btVoid
: /* Void */
1467 strcpy (p1
, "void");
1471 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1475 p1
+= strlen (buffer1
);
1478 * If this is a bitfield, get the bitsize.
1484 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1485 sprintf (p1
, " : %d", bitsize
);
1486 p1
+= strlen (buffer1
);
1491 * Deal with any qualifiers.
1493 if (qualifiers
[0].type
!= tqNil
)
1496 * Snarf up any array bounds in the correct order. Arrays
1497 * store 5 successive words in the aux. table:
1498 * word 0 RNDXR to type of the bounds (ie, int)
1499 * word 1 Current file descriptor index
1501 * word 3 high bound (or -1 if [])
1502 * word 4 stride size in bits
1504 for (i
= 0; i
< 7; i
++)
1506 if (qualifiers
[i
].type
== tqArray
)
1508 qualifiers
[i
].low_bound
=
1509 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1510 qualifiers
[i
].high_bound
=
1511 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1512 qualifiers
[i
].stride
=
1513 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1519 * Now print out the qualifiers.
1521 for (i
= 0; i
< 6; i
++)
1523 switch (qualifiers
[i
].type
)
1530 strcpy (p2
, "ptr to ");
1531 p2
+= sizeof ("ptr to ")-1;
1535 strcpy (p2
, "volatile ");
1536 p2
+= sizeof ("volatile ")-1;
1540 strcpy (p2
, "far ");
1541 p2
+= sizeof ("far ")-1;
1545 strcpy (p2
, "func. ret. ");
1546 p2
+= sizeof ("func. ret. ");
1551 int first_array
= i
;
1554 /* Print array bounds reversed (ie, in the order the C
1555 programmer writes them). C is such a fun language.... */
1557 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1560 for (j
= i
; j
>= first_array
; j
--)
1562 strcpy (p2
, "array [");
1563 p2
+= sizeof ("array [")-1;
1564 if (qualifiers
[j
].low_bound
!= 0)
1566 "%ld:%ld {%ld bits}",
1567 (long) qualifiers
[j
].low_bound
,
1568 (long) qualifiers
[j
].high_bound
,
1569 (long) qualifiers
[j
].stride
);
1571 else if (qualifiers
[j
].high_bound
!= -1)
1574 (long) (qualifiers
[j
].high_bound
+ 1),
1575 (long) (qualifiers
[j
].stride
));
1578 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1581 strcpy (p2
, "] of ");
1582 p2
+= sizeof ("] of ")-1;
1590 strcpy (p2
, buffer1
);
1594 /* Return information about ECOFF symbol SYMBOL in RET. */
1598 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1599 bfd
*abfd
; /* Ignored. */
1603 bfd_symbol_info (symbol
, ret
);
1606 /* Print information about an ECOFF symbol. */
1609 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1613 bfd_print_symbol_type how
;
1615 const struct ecoff_debug_swap
* const debug_swap
1616 = &ecoff_backend (abfd
)->debug_swap
;
1617 FILE *file
= (FILE *)filep
;
1621 case bfd_print_symbol_name
:
1622 fprintf (file
, "%s", symbol
->name
);
1624 case bfd_print_symbol_more
:
1625 if (ecoffsymbol (symbol
)->local
)
1629 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1631 fprintf (file
, "ecoff local ");
1632 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1633 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1634 (unsigned) ecoff_sym
.sc
);
1640 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1642 fprintf (file
, "ecoff extern ");
1643 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1644 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1645 (unsigned) ecoff_ext
.asym
.sc
);
1648 case bfd_print_symbol_all
:
1649 /* Print out the symbols in a reasonable way */
1658 if (ecoffsymbol (symbol
)->local
)
1660 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1663 pos
= ((((char *) ecoffsymbol (symbol
)->native
1664 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1665 / debug_swap
->external_sym_size
)
1666 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1673 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1676 pos
= (((char *) ecoffsymbol (symbol
)->native
1677 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1678 / debug_swap
->external_ext_size
);
1679 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1680 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1681 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1684 fprintf (file
, "[%3d] %c ",
1686 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1687 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1688 (unsigned) ecoff_ext
.asym
.st
,
1689 (unsigned) ecoff_ext
.asym
.sc
,
1690 (unsigned) ecoff_ext
.asym
.index
,
1691 jmptbl
, cobol_main
, weakext
,
1694 if (ecoffsymbol (symbol
)->fdr
!= NULL
1695 && ecoff_ext
.asym
.index
!= indexNil
)
1699 bfd_size_type sym_base
;
1700 union aux_ext
*aux_base
;
1702 indx
= ecoff_ext
.asym
.index
;
1704 /* sym_base is used to map the fdr relative indices which
1705 appear in the file to the position number which we are
1707 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1708 if (ecoffsymbol (symbol
)->local
)
1710 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1712 /* aux_base is the start of the aux entries for this file;
1713 asym.index is an offset from this. */
1714 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1715 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1717 /* The aux entries are stored in host byte order; the
1718 order is indicated by a bit in the fdr. */
1719 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1721 /* This switch is basically from gcc/mips-tdump.c */
1722 switch (ecoff_ext
.asym
.st
)
1730 fprintf (file
, "\n End+1 symbol: %ld",
1731 (long) (indx
+ sym_base
));
1735 if (ecoff_ext
.asym
.sc
== scText
1736 || ecoff_ext
.asym
.sc
== scInfo
)
1737 fprintf (file
, "\n First symbol: %ld",
1738 (long) (indx
+ sym_base
));
1740 fprintf (file
, "\n First symbol: %ld",
1741 (long) (AUX_GET_ISYM (bigendian
,
1742 &aux_base
[ecoff_ext
.asym
.index
])
1748 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1750 else if (ecoffsymbol (symbol
)->local
)
1751 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1752 (long) (AUX_GET_ISYM (bigendian
,
1753 &aux_base
[ecoff_ext
.asym
.index
])
1755 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1758 fprintf (file
, "\n Local symbol: %ld",
1761 + (ecoff_data (abfd
)
1762 ->debug_info
.symbolic_header
.iextMax
)));
1766 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1767 fprintf (file
, "\n Type: %s",
1768 ecoff_type_to_string (abfd
, aux_base
, indx
,
1778 /* Read in the relocs for a section. */
1781 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1786 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1787 arelent
*internal_relocs
;
1788 bfd_size_type external_reloc_size
;
1789 bfd_size_type external_relocs_size
;
1790 char *external_relocs
;
1794 if (section
->relocation
!= (arelent
*) NULL
1795 || section
->reloc_count
== 0
1796 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1799 if (ecoff_slurp_symbol_table (abfd
) == false)
1802 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1804 * section
->reloc_count
));
1805 external_reloc_size
= backend
->external_reloc_size
;
1806 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1807 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1808 if (internal_relocs
== (arelent
*) NULL
1809 || external_relocs
== (char *) NULL
)
1811 bfd_error
= no_memory
;
1814 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1816 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1817 != external_relocs_size
)
1819 bfd_error
= system_call_error
;
1823 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1825 struct internal_reloc intern
;
1827 (*backend
->swap_reloc_in
) (abfd
,
1828 external_relocs
+ i
* external_reloc_size
,
1831 if (intern
.r_extern
)
1833 /* r_symndx is an index into the external symbols. */
1834 BFD_ASSERT (intern
.r_symndx
>= 0
1836 < (ecoff_data (abfd
)
1837 ->debug_info
.symbolic_header
.iextMax
)));
1838 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1841 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1842 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1844 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1849 CONST
char *sec_name
;
1852 /* r_symndx is a section key. */
1853 switch (intern
.r_symndx
)
1855 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1856 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1857 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1858 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1859 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1860 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1861 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1862 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1863 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1864 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1865 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1866 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1867 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1871 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1872 if (sec
== (asection
*) NULL
)
1874 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1876 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1879 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1881 /* Let the backend select the howto field and do any other
1882 required processing. */
1883 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1886 bfd_release (abfd
, external_relocs
);
1888 section
->relocation
= internal_relocs
;
1893 /* Get a canonical list of relocs. */
1896 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1904 if (section
->flags
& SEC_CONSTRUCTOR
)
1906 arelent_chain
*chain
;
1908 /* This section has relocs made up by us, not the file, so take
1909 them out of their chain and place them into the data area
1911 for (count
= 0, chain
= section
->constructor_chain
;
1912 count
< section
->reloc_count
;
1913 count
++, chain
= chain
->next
)
1914 *relptr
++ = &chain
->relent
;
1920 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1923 tblptr
= section
->relocation
;
1924 if (tblptr
== (arelent
*) NULL
)
1927 for (count
= 0; count
< section
->reloc_count
; count
++)
1928 *relptr
++ = tblptr
++;
1931 *relptr
= (arelent
*) NULL
;
1933 return section
->reloc_count
;
1936 /* Provided a BFD, a section and an offset into the section, calculate
1937 and return the name of the source file and the line nearest to the
1942 ecoff_find_nearest_line (abfd
,
1951 asymbol
**ignore_symbols
;
1953 CONST
char **filename_ptr
;
1954 CONST
char **functionname_ptr
;
1955 unsigned int *retline_ptr
;
1957 const struct ecoff_debug_swap
* const debug_swap
1958 = &ecoff_backend (abfd
)->debug_swap
;
1963 bfd_size_type external_pdr_size
;
1967 unsigned char *line_ptr
;
1968 unsigned char *line_end
;
1971 /* If we're not in the .text section, we don't have any line
1973 if (strcmp (section
->name
, _TEXT
) != 0
1974 || offset
< ecoff_data (abfd
)->text_start
1975 || offset
>= ecoff_data (abfd
)->text_end
)
1978 /* Make sure we have the FDR's. */
1979 if (ecoff_slurp_symbolic_info (abfd
) == false
1980 || bfd_get_symcount (abfd
) == 0)
1983 /* Each file descriptor (FDR) has a memory address. Here we track
1984 down which FDR we want. The FDR's are stored in increasing
1985 memory order. If speed is ever important, this can become a
1986 binary search. We must ignore FDR's with no PDR entries; they
1987 will have the adr of the FDR before or after them. */
1988 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1989 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1990 fdr_hold
= (FDR
*) NULL
;
1991 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1993 if (fdr_ptr
->cpd
== 0)
1995 if (offset
< fdr_ptr
->adr
)
1999 if (fdr_hold
== (FDR
*) NULL
)
2003 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2004 have an address, which is relative to the FDR address, and are
2005 also stored in increasing memory order. */
2006 offset
-= fdr_ptr
->adr
;
2007 external_pdr_size
= debug_swap
->external_pdr_size
;
2008 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2009 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2010 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2011 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2013 /* The address of the first PDR is an offset which applies to the
2014 addresses of all the PDR's. */
2017 for (pdr_ptr
+= external_pdr_size
;
2019 pdr_ptr
+= external_pdr_size
)
2021 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2022 if (offset
< pdr
.adr
)
2026 /* Now we can look for the actual line number. The line numbers are
2027 stored in a very funky format, which I won't try to describe.
2028 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2029 we want; we need this to compute line_end. */
2030 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2031 if (pdr_ptr
== pdr_end
)
2032 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2034 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2036 /* Now change pdr and pdr_ptr to the one we want. */
2037 pdr_ptr
-= external_pdr_size
;
2038 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2042 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2043 + fdr_ptr
->cbLineOffset
2044 + pdr
.cbLineOffset
);
2045 while (line_ptr
< line_end
)
2050 delta
= *line_ptr
>> 4;
2053 count
= (*line_ptr
& 0xf) + 1;
2057 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2058 if (delta
>= 0x8000)
2063 if (offset
< count
* 4)
2065 offset
-= count
* 4;
2068 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2069 at least according to gdb/mipsread.c. */
2070 if (fdr_ptr
->rss
== -1)
2072 *filename_ptr
= NULL
;
2074 *functionname_ptr
= NULL
;
2079 (*debug_swap
->swap_ext_in
)
2081 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2082 + pdr
.isym
* debug_swap
->external_ext_size
),
2084 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2085 + proc_ext
.asym
.iss
);
2092 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2095 (*debug_swap
->swap_sym_in
)
2097 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2098 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2100 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2104 if (lineno
== ilineNil
)
2106 *retline_ptr
= lineno
;
2110 /* Set the architecture. The supported architecture is stored in the
2111 backend pointer. We always set the architecture anyhow, since many
2112 callers ignore the return value. */
2115 ecoff_set_arch_mach (abfd
, arch
, machine
)
2117 enum bfd_architecture arch
;
2118 unsigned long machine
;
2120 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2121 return arch
== ecoff_backend (abfd
)->arch
;
2124 /* Get the size of the section headers. We do not output the .reginfo
2129 ecoff_sizeof_headers (abfd
, reloc
)
2137 for (current
= abfd
->sections
;
2138 current
!= (asection
*)NULL
;
2139 current
= current
->next
)
2140 if (strcmp (current
->name
, REGINFO
) != 0)
2143 return (bfd_coff_filhsz (abfd
)
2144 + bfd_coff_aoutsz (abfd
)
2145 + c
* bfd_coff_scnhsz (abfd
));
2148 /* Get the contents of a section. This is where we handle reading the
2149 .reginfo section, which implicitly holds the contents of an
2150 ecoff_reginfo structure. */
2153 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2158 bfd_size_type count
;
2160 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2161 struct ecoff_reginfo s
;
2164 if (strcmp (section
->name
, REGINFO
) != 0)
2165 return bfd_generic_get_section_contents (abfd
, section
, location
,
2168 s
.gp_value
= tdata
->gp
;
2169 s
.gprmask
= tdata
->gprmask
;
2170 for (i
= 0; i
< 4; i
++)
2171 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2172 s
.fprmask
= tdata
->fprmask
;
2174 /* bfd_get_section_contents has already checked that the offset and
2175 size is reasonable. We don't have to worry about swapping or any
2176 such thing; the .reginfo section is defined such that the
2177 contents are an ecoff_reginfo structure as seen on the host. */
2178 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2182 /* Calculate the file position for each section, and set
2186 ecoff_compute_section_file_positions (abfd
)
2194 sofar
= ecoff_sizeof_headers (abfd
, false);
2197 for (current
= abfd
->sections
;
2198 current
!= (asection
*) NULL
;
2199 current
= current
->next
)
2201 unsigned int alignment_power
;
2203 /* Only deal with sections which have contents */
2204 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2205 || strcmp (current
->name
, REGINFO
) == 0)
2208 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2209 supposed to indicate the number of .pdata entries that are
2210 really in the section. Each entry is 8 bytes. We store this
2211 away in line_filepos before increasing the section size. */
2212 if (strcmp (current
->name
, _PDATA
) != 0)
2213 alignment_power
= current
->alignment_power
;
2216 current
->line_filepos
= current
->_raw_size
/ 8;
2217 alignment_power
= 4;
2220 /* On Ultrix, the data sections in an executable file must be
2221 aligned to a page boundary within the file. This does not
2222 affect the section size, though. FIXME: Does this work for
2223 other platforms? It requires some modification for the
2224 Alpha, because .rdata on the Alpha goes with the text, not
2226 if ((abfd
->flags
& EXEC_P
) != 0
2227 && (abfd
->flags
& D_PAGED
) != 0
2228 && first_data
!= false
2229 && (current
->flags
& SEC_CODE
) == 0
2230 && (! ecoff_backend (abfd
)->rdata_in_text
2231 || strcmp (current
->name
, _RDATA
) != 0)
2232 && strcmp (current
->name
, _PDATA
) != 0)
2234 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2236 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2240 /* Align the sections in the file to the same boundary on
2241 which they are aligned in virtual memory. */
2243 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2245 current
->filepos
= sofar
;
2247 sofar
+= current
->_raw_size
;
2249 /* make sure that this section is of the right size too */
2251 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2252 current
->_raw_size
+= sofar
- old_sofar
;
2255 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2258 /* Determine the location of the relocs for all the sections in the
2259 output file, as well as the location of the symbolic debugging
2262 static bfd_size_type
2263 ecoff_compute_reloc_file_positions (abfd
)
2266 const bfd_size_type external_reloc_size
=
2267 ecoff_backend (abfd
)->external_reloc_size
;
2268 file_ptr reloc_base
;
2269 bfd_size_type reloc_size
;
2273 if (! abfd
->output_has_begun
)
2275 ecoff_compute_section_file_positions (abfd
);
2276 abfd
->output_has_begun
= true;
2279 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2282 for (current
= abfd
->sections
;
2283 current
!= (asection
*)NULL
;
2284 current
= current
->next
)
2286 if (strcmp (current
->name
, REGINFO
) == 0)
2288 if (current
->reloc_count
== 0)
2289 current
->rel_filepos
= 0;
2292 bfd_size_type relsize
;
2294 current
->rel_filepos
= reloc_base
;
2295 relsize
= current
->reloc_count
* external_reloc_size
;
2296 reloc_size
+= relsize
;
2297 reloc_base
+= relsize
;
2301 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2303 /* At least on Ultrix, the symbol table of an executable file must
2304 be aligned to a page boundary. FIXME: Is this true on other
2306 if ((abfd
->flags
& EXEC_P
) != 0
2307 && (abfd
->flags
& D_PAGED
) != 0)
2308 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2309 &~ (ecoff_backend (abfd
)->round
- 1));
2311 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2316 /* Set the contents of a section. This is where we handle setting the
2317 contents of the .reginfo section, which implicitly holds a
2318 ecoff_reginfo structure. */
2321 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2326 bfd_size_type count
;
2328 /* This must be done first, because bfd_set_section_contents is
2329 going to set output_has_begun to true. */
2330 if (abfd
->output_has_begun
== false)
2331 ecoff_compute_section_file_positions (abfd
);
2336 if (strcmp (section
->name
, REGINFO
) == 0)
2338 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2339 struct ecoff_reginfo s
;
2342 /* If the caller is only changing part of the structure, we must
2343 retrieve the current information before the memcpy. */
2344 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2346 s
.gp_value
= tdata
->gp
;
2347 s
.gprmask
= tdata
->gprmask
;
2348 for (i
= 0; i
< 4; i
++)
2349 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2350 s
.fprmask
= tdata
->fprmask
;
2353 /* bfd_set_section_contents has already checked that the offset
2354 and size is reasonable. We don't have to worry about
2355 swapping or any such thing; the .reginfo section is defined
2356 such that the contents are an ecoff_reginfo structure as seen
2358 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2360 tdata
->gp
= s
.gp_value
;
2361 tdata
->gprmask
= s
.gprmask
;
2362 for (i
= 0; i
< 4; i
++)
2363 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2364 tdata
->fprmask
= s
.fprmask
;
2369 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2370 || bfd_write (location
, 1, count
, abfd
) != count
)
2376 /* Get ECOFF EXTR information for an external symbol. This function
2377 is passed to bfd_ecoff_debug_externals. */
2380 ecoff_get_extr (sym
, esym
)
2384 ecoff_symbol_type
*ecoff_sym_ptr
;
2387 /* Don't include debugging, local or section symbols. */
2388 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2389 || (sym
->flags
& BSF_LOCAL
) != 0
2390 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2393 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2394 || ecoffsymbol (sym
)->native
== NULL
)
2397 esym
->cobol_main
= 0;
2401 /* FIXME: we can do better than this for st and sc. */
2402 esym
->asym
.st
= stGlobal
;
2403 esym
->asym
.sc
= scAbs
;
2404 esym
->asym
.reserved
= 0;
2405 esym
->asym
.index
= indexNil
;
2409 ecoff_sym_ptr
= ecoffsymbol (sym
);
2411 if (ecoff_sym_ptr
->local
)
2414 input_bfd
= bfd_asymbol_bfd (sym
);
2415 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2416 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2418 /* If the symbol was defined by the linker, then esym will be
2419 undefined but sym will not be. Get a better class for such a
2421 if ((esym
->asym
.sc
== scUndefined
2422 || esym
->asym
.sc
== scSUndefined
)
2423 && bfd_get_section (sym
) != &bfd_und_section
)
2424 esym
->asym
.sc
= scAbs
;
2426 /* Adjust the FDR index for the symbol by that used for the input
2428 if (esym
->ifd
!= -1)
2430 struct ecoff_debug_info
*input_debug
;
2432 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2433 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2434 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2435 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2441 /* Set the external symbol index. This routine is passed to
2442 bfd_ecoff_debug_externals. */
2445 ecoff_set_index (sym
, indx
)
2449 ecoff_set_sym_index (sym
, indx
);
2452 /* Write out an ECOFF file. */
2455 ecoff_write_object_contents (abfd
)
2458 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2459 const bfd_vma round
= backend
->round
;
2460 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2461 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2462 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2463 const bfd_size_type external_hdr_size
2464 = backend
->debug_swap
.external_hdr_size
;
2465 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2466 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2468 struct internal_reloc
*))
2469 = backend
->adjust_reloc_out
;
2470 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2471 const struct internal_reloc
*,
2473 = backend
->swap_reloc_out
;
2474 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2475 HDRR
* const symhdr
= &debug
->symbolic_header
;
2478 bfd_size_type reloc_size
;
2479 unsigned long text_size
;
2480 unsigned long text_start
;
2481 unsigned long data_size
;
2482 unsigned long data_start
;
2483 unsigned long bss_size
;
2485 struct internal_filehdr internal_f
;
2486 struct internal_aouthdr internal_a
;
2489 bfd_error
= system_call_error
;
2491 /* Determine where the sections and relocs will go in the output
2493 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2496 for (current
= abfd
->sections
;
2497 current
!= (asection
*)NULL
;
2498 current
= current
->next
)
2500 if (strcmp (current
->name
, REGINFO
) == 0)
2502 current
->target_index
= count
;
2506 if ((abfd
->flags
& D_PAGED
) != 0)
2507 text_size
= ecoff_sizeof_headers (abfd
, false);
2515 /* Write section headers to the file. */
2517 buff
= (PTR
) alloca (scnhsz
);
2518 internal_f
.f_nscns
= 0;
2519 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2521 for (current
= abfd
->sections
;
2522 current
!= (asection
*) NULL
;
2523 current
= current
->next
)
2525 struct internal_scnhdr section
;
2528 if (strcmp (current
->name
, REGINFO
) == 0)
2530 BFD_ASSERT (current
->reloc_count
== 0);
2534 ++internal_f
.f_nscns
;
2536 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2538 /* FIXME: is this correct for shared libraries? I think it is
2539 but I have no platform to check. Ian Lance Taylor. */
2540 vma
= bfd_get_section_vma (abfd
, current
);
2541 if (strcmp (current
->name
, _LIB
) == 0)
2542 section
.s_vaddr
= 0;
2544 section
.s_vaddr
= vma
;
2546 section
.s_paddr
= vma
;
2547 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2549 /* If this section is unloadable then the scnptr will be 0. */
2550 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2551 section
.s_scnptr
= 0;
2553 section
.s_scnptr
= current
->filepos
;
2554 section
.s_relptr
= current
->rel_filepos
;
2556 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2557 object file produced by the assembler is supposed to point to
2558 information about how much room is required by objects of
2559 various different sizes. I think this only matters if we
2560 want the linker to compute the best size to use, or
2561 something. I don't know what happens if the information is
2563 if (strcmp (current
->name
, _PDATA
) != 0)
2564 section
.s_lnnoptr
= 0;
2567 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2568 hold the number of entries in the section (each entry is
2569 8 bytes). We stored this in the line_filepos field in
2570 ecoff_compute_section_file_positions. */
2571 section
.s_lnnoptr
= current
->line_filepos
;
2574 section
.s_nreloc
= current
->reloc_count
;
2575 section
.s_nlnno
= 0;
2576 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2579 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2580 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2583 if ((section
.s_flags
& STYP_TEXT
) != 0
2584 || ((section
.s_flags
& STYP_RDATA
) != 0
2585 && backend
->rdata_in_text
)
2586 || strcmp (current
->name
, _PDATA
) == 0)
2588 text_size
+= bfd_get_section_size_before_reloc (current
);
2589 if (text_start
== 0 || text_start
> vma
)
2592 else if ((section
.s_flags
& STYP_RDATA
) != 0
2593 || (section
.s_flags
& STYP_DATA
) != 0
2594 || (section
.s_flags
& STYP_LITA
) != 0
2595 || (section
.s_flags
& STYP_LIT8
) != 0
2596 || (section
.s_flags
& STYP_LIT4
) != 0
2597 || (section
.s_flags
& STYP_SDATA
) != 0
2598 || strcmp (current
->name
, _XDATA
) == 0)
2600 data_size
+= bfd_get_section_size_before_reloc (current
);
2601 if (data_start
== 0 || data_start
> vma
)
2604 else if ((section
.s_flags
& STYP_BSS
) != 0
2605 || (section
.s_flags
& STYP_SBSS
) != 0)
2606 bss_size
+= bfd_get_section_size_before_reloc (current
);
2611 /* Set up the file header. */
2613 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2615 /* We will NOT put a fucking timestamp in the header here. Every
2616 time you put it back, I will come in and take it out again. I'm
2617 sorry. This field does not belong here. We fill it with a 0 so
2618 it compares the same but is not a reasonable time. --
2620 internal_f
.f_timdat
= 0;
2622 if (bfd_get_symcount (abfd
) != 0)
2624 /* The ECOFF f_nsyms field is not actually the number of
2625 symbols, it's the size of symbolic information header. */
2626 internal_f
.f_nsyms
= external_hdr_size
;
2627 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2631 internal_f
.f_nsyms
= 0;
2632 internal_f
.f_symptr
= 0;
2635 internal_f
.f_opthdr
= aoutsz
;
2637 internal_f
.f_flags
= F_LNNO
;
2638 if (reloc_size
== 0)
2639 internal_f
.f_flags
|= F_RELFLG
;
2640 if (bfd_get_symcount (abfd
) == 0)
2641 internal_f
.f_flags
|= F_LSYMS
;
2642 if (abfd
->flags
& EXEC_P
)
2643 internal_f
.f_flags
|= F_EXEC
;
2645 if (! abfd
->xvec
->byteorder_big_p
)
2646 internal_f
.f_flags
|= F_AR32WR
;
2648 internal_f
.f_flags
|= F_AR32W
;
2650 /* Set up the ``optional'' header. */
2651 if ((abfd
->flags
& D_PAGED
) != 0)
2652 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2654 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2656 /* FIXME: Is this really correct? */
2657 internal_a
.vstamp
= symhdr
->vstamp
;
2659 /* At least on Ultrix, these have to be rounded to page boundaries.
2660 FIXME: Is this true on other platforms? */
2661 if ((abfd
->flags
& D_PAGED
) != 0)
2663 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2664 internal_a
.text_start
= text_start
&~ (round
- 1);
2665 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2666 internal_a
.data_start
= data_start
&~ (round
- 1);
2670 internal_a
.tsize
= text_size
;
2671 internal_a
.text_start
= text_start
;
2672 internal_a
.dsize
= data_size
;
2673 internal_a
.data_start
= data_start
;
2676 /* On Ultrix, the initial portions of the .sbss and .bss segments
2677 are at the end of the data section. The bsize field in the
2678 optional header records how many bss bytes are required beyond
2679 those in the data section. The value is not rounded to a page
2681 if (bss_size
< internal_a
.dsize
- data_size
)
2684 bss_size
-= internal_a
.dsize
- data_size
;
2685 internal_a
.bsize
= bss_size
;
2686 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2688 internal_a
.entry
= bfd_get_start_address (abfd
);
2690 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2692 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2693 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2694 for (i
= 0; i
< 4; i
++)
2695 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2697 /* Write out the file header and the optional header. */
2699 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2702 buff
= (PTR
) alloca (filhsz
);
2703 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2704 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2707 buff
= (PTR
) alloca (aoutsz
);
2708 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2709 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2712 /* Build the external symbol information. This must be done before
2713 writing out the relocs so that we know the symbol indices. The
2714 condition checks makes sure this object was not created by
2715 ecoff_bfd_final_link, since if it was we do not want to tamper
2716 with the external symbols. */
2717 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2719 symhdr
->iextMax
= 0;
2720 symhdr
->issExtMax
= 0;
2721 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2722 debug
->ssext
= debug
->ssext_end
= NULL
;
2723 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2724 (((abfd
->flags
& EXEC_P
) == 0)
2726 ecoff_get_extr
, ecoff_set_index
)
2730 /* Write out the relocs. */
2731 for (current
= abfd
->sections
;
2732 current
!= (asection
*) NULL
;
2733 current
= current
->next
)
2735 arelent
**reloc_ptr_ptr
;
2736 arelent
**reloc_end
;
2739 if (current
->reloc_count
== 0)
2742 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2745 bfd_error
= no_memory
;
2749 reloc_ptr_ptr
= current
->orelocation
;
2750 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2751 out_ptr
= (char *) buff
;
2753 reloc_ptr_ptr
< reloc_end
;
2754 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2758 struct internal_reloc in
;
2760 memset (&in
, 0, sizeof in
);
2762 reloc
= *reloc_ptr_ptr
;
2763 sym
= *reloc
->sym_ptr_ptr
;
2765 in
.r_vaddr
= (reloc
->address
2766 + bfd_get_section_vma (abfd
, current
));
2767 in
.r_type
= reloc
->howto
->type
;
2769 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2771 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2778 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2779 if (strcmp (name
, ".text") == 0)
2780 in
.r_symndx
= RELOC_SECTION_TEXT
;
2781 else if (strcmp (name
, ".rdata") == 0)
2782 in
.r_symndx
= RELOC_SECTION_RDATA
;
2783 else if (strcmp (name
, ".data") == 0)
2784 in
.r_symndx
= RELOC_SECTION_DATA
;
2785 else if (strcmp (name
, ".sdata") == 0)
2786 in
.r_symndx
= RELOC_SECTION_SDATA
;
2787 else if (strcmp (name
, ".sbss") == 0)
2788 in
.r_symndx
= RELOC_SECTION_SBSS
;
2789 else if (strcmp (name
, ".bss") == 0)
2790 in
.r_symndx
= RELOC_SECTION_BSS
;
2791 else if (strcmp (name
, ".init") == 0)
2792 in
.r_symndx
= RELOC_SECTION_INIT
;
2793 else if (strcmp (name
, ".lit8") == 0)
2794 in
.r_symndx
= RELOC_SECTION_LIT8
;
2795 else if (strcmp (name
, ".lit4") == 0)
2796 in
.r_symndx
= RELOC_SECTION_LIT4
;
2797 else if (strcmp (name
, ".xdata") == 0)
2798 in
.r_symndx
= RELOC_SECTION_XDATA
;
2799 else if (strcmp (name
, ".pdata") == 0)
2800 in
.r_symndx
= RELOC_SECTION_PDATA
;
2801 else if (strcmp (name
, ".fini") == 0)
2802 in
.r_symndx
= RELOC_SECTION_FINI
;
2803 else if (strcmp (name
, ".lita") == 0)
2804 in
.r_symndx
= RELOC_SECTION_LITA
;
2805 else if (strcmp (name
, "*ABS*") == 0)
2806 in
.r_symndx
= RELOC_SECTION_ABS
;
2812 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2814 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2817 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2819 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
2820 != external_reloc_size
* current
->reloc_count
)
2822 bfd_release (abfd
, buff
);
2825 /* Write out the symbolic debugging information. */
2826 if (bfd_get_symcount (abfd
) > 0)
2828 /* Write out the debugging information. */
2829 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2830 ecoff_data (abfd
)->sym_filepos
)
2834 else if ((abfd
->flags
& EXEC_P
) != 0
2835 && (abfd
->flags
& D_PAGED
) != 0)
2839 /* A demand paged executable must occupy an even number of
2841 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2844 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2846 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2849 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2857 /* Archive handling. ECOFF uses what appears to be a unique type of
2858 archive header (armap). The byte ordering of the armap and the
2859 contents are encoded in the name of the armap itself. At least for
2860 now, we only support archives with the same byte ordering in the
2861 armap and the contents.
2863 The first four bytes in the armap are the number of symbol
2864 definitions. This is always a power of two.
2866 This is followed by the symbol definitions. Each symbol definition
2867 occupies 8 bytes. The first four bytes are the offset from the
2868 start of the armap strings to the null-terminated string naming
2869 this symbol. The second four bytes are the file offset to the
2870 archive member which defines this symbol. If the second four bytes
2871 are 0, then this is not actually a symbol definition, and it should
2874 The symbols are hashed into the armap with a closed hashing scheme.
2875 See the functions below for the details of the algorithm.
2877 After the symbol definitions comes four bytes holding the size of
2878 the string table, followed by the string table itself. */
2880 /* The name of an archive headers looks like this:
2881 __________E[BL]E[BL]_ (with a trailing space).
2882 The trailing space is changed to an X if the archive is changed to
2883 indicate that the armap is out of date.
2885 The Alpha seems to use ________64E[BL]E[BL]_. */
2887 #define ARMAP_BIG_ENDIAN 'B'
2888 #define ARMAP_LITTLE_ENDIAN 'L'
2889 #define ARMAP_MARKER 'E'
2890 #define ARMAP_START_LENGTH 10
2891 #define ARMAP_HEADER_MARKER_INDEX 10
2892 #define ARMAP_HEADER_ENDIAN_INDEX 11
2893 #define ARMAP_OBJECT_MARKER_INDEX 12
2894 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2895 #define ARMAP_END_INDEX 14
2896 #define ARMAP_END "_ "
2898 /* This is a magic number used in the hashing algorithm. */
2899 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2901 /* This returns the hash value to use for a string. It also sets
2902 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2903 is the number of entries in the hash table, and HLOG is the log
2907 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2909 unsigned int *rehash
;
2917 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2918 hash
*= ARMAP_HASH_MAGIC
;
2919 *rehash
= (hash
& (size
- 1)) | 1;
2920 return hash
>> (32 - hlog
);
2923 /* Read in the armap. */
2926 ecoff_slurp_armap (abfd
)
2931 struct areltdata
*mapdata
;
2932 bfd_size_type parsed_size
;
2934 struct artdata
*ardata
;
2937 struct symdef
*symdef_ptr
;
2940 /* Get the name of the first element. */
2941 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2947 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2949 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2950 standard COFF armap. We could move the ECOFF armap stuff into
2951 bfd_slurp_armap, but that seems inappropriate since no other
2952 target uses this format. Instead, we check directly for a COFF
2954 if (strncmp (nextname
, "/ ", 16) == 0)
2955 return bfd_slurp_armap (abfd
);
2957 /* See if the first element is an armap. */
2958 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2959 ARMAP_START_LENGTH
) != 0
2960 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2961 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2962 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2963 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2964 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2965 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2966 || strncmp (nextname
+ ARMAP_END_INDEX
,
2967 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2969 bfd_has_map (abfd
) = false;
2973 /* Make sure we have the right byte ordering. */
2974 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2975 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2976 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2977 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2979 bfd_error
= wrong_format
;
2983 /* Read in the armap. */
2984 ardata
= bfd_ardata (abfd
);
2985 mapdata
= _bfd_snarf_ar_hdr (abfd
);
2986 if (mapdata
== (struct areltdata
*) NULL
)
2988 parsed_size
= mapdata
->parsed_size
;
2989 bfd_release (abfd
, (PTR
) mapdata
);
2991 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2992 if (raw_armap
== (char *) NULL
)
2994 bfd_error
= no_memory
;
2998 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3000 bfd_error
= malformed_archive
;
3001 bfd_release (abfd
, (PTR
) raw_armap
);
3005 ardata
->tdata
= (PTR
) raw_armap
;
3007 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3009 ardata
->symdef_count
= 0;
3010 ardata
->cache
= (struct ar_cache
*) NULL
;
3012 /* This code used to overlay the symdefs over the raw archive data,
3013 but that doesn't work on a 64 bit host. */
3015 stringbase
= raw_armap
+ count
* 8 + 8;
3017 #ifdef CHECK_ARMAP_HASH
3021 /* Double check that I have the hashing algorithm right by making
3022 sure that every symbol can be looked up successfully. */
3024 for (i
= 1; i
< count
; i
<<= 1)
3026 BFD_ASSERT (i
== count
);
3028 raw_ptr
= raw_armap
+ 4;
3029 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3031 unsigned int name_offset
, file_offset
;
3032 unsigned int hash
, rehash
, srch
;
3034 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3035 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3036 if (file_offset
== 0)
3038 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3043 /* See if we can rehash to this location. */
3044 for (srch
= (hash
+ rehash
) & (count
- 1);
3045 srch
!= hash
&& srch
!= i
;
3046 srch
= (srch
+ rehash
) & (count
- 1))
3047 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3049 BFD_ASSERT (srch
== i
);
3053 #endif /* CHECK_ARMAP_HASH */
3055 raw_ptr
= raw_armap
+ 4;
3056 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3057 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3058 ++ardata
->symdef_count
;
3060 symdef_ptr
= ((struct symdef
*)
3062 ardata
->symdef_count
* sizeof (struct symdef
)));
3065 bfd_error
= no_memory
;
3069 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3071 raw_ptr
= raw_armap
+ 4;
3072 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3074 unsigned int name_offset
, file_offset
;
3076 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3077 if (file_offset
== 0)
3079 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3080 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3081 symdef_ptr
->file_offset
= file_offset
;
3085 ardata
->first_file_filepos
= bfd_tell (abfd
);
3086 /* Pad to an even boundary. */
3087 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3089 bfd_has_map (abfd
) = true;
3094 /* Write out an armap. */
3097 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3099 unsigned int elength
;
3101 unsigned int orl_count
;
3104 unsigned int hashsize
, hashlog
;
3105 unsigned int symdefsize
;
3107 unsigned int stringsize
;
3108 unsigned int mapsize
;
3111 struct stat statbuf
;
3114 bfd_byte
*hashtable
;
3118 /* Ultrix appears to use as a hash table size the least power of two
3119 greater than twice the number of entries. */
3120 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3122 hashsize
= 1 << hashlog
;
3124 symdefsize
= hashsize
* 8;
3126 stringsize
= stridx
+ padit
;
3128 /* Include 8 bytes to store symdefsize and stringsize in output. */
3129 mapsize
= symdefsize
+ stringsize
+ 8;
3131 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3133 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3135 /* Work out the ECOFF armap name. */
3136 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3137 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3138 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3139 (abfd
->xvec
->header_byteorder_big_p
3141 : ARMAP_LITTLE_ENDIAN
);
3142 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3143 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3144 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3145 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3147 /* Write the timestamp of the archive header to be just a little bit
3148 later than the timestamp of the file, otherwise the linker will
3149 complain that the index is out of date. Actually, the Ultrix
3150 linker just checks the archive name; the GNU linker may check the
3152 stat (abfd
->filename
, &statbuf
);
3153 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3155 /* The DECstation uses zeroes for the uid, gid and mode of the
3157 hdr
.ar_uid
[0] = '0';
3158 hdr
.ar_gid
[0] = '0';
3159 hdr
.ar_mode
[0] = '0';
3161 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3163 hdr
.ar_fmag
[0] = '`';
3164 hdr
.ar_fmag
[1] = '\012';
3166 /* Turn all null bytes in the header into spaces. */
3167 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3168 if (((char *)(&hdr
))[i
] == '\0')
3169 (((char *)(&hdr
))[i
]) = ' ';
3171 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3172 != sizeof (struct ar_hdr
))
3175 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3176 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3179 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3182 bfd_error
= no_memory
;
3186 current
= abfd
->archive_head
;
3188 for (i
= 0; i
< orl_count
; i
++)
3190 unsigned int hash
, rehash
;
3192 /* Advance firstreal to the file position of this archive
3194 if (((bfd
*) map
[i
].pos
) != last_elt
)
3198 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3199 firstreal
+= firstreal
% 2;
3200 current
= current
->next
;
3202 while (current
!= (bfd
*) map
[i
].pos
);
3207 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3208 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3212 /* The desired slot is already taken. */
3213 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3215 srch
= (srch
+ rehash
) & (hashsize
- 1))
3216 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3219 BFD_ASSERT (srch
!= hash
);
3224 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3225 (PTR
) (hashtable
+ hash
* 8));
3226 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3227 (PTR
) (hashtable
+ hash
* 8 + 4));
3230 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3233 bfd_release (abfd
, hashtable
);
3235 /* Now write the strings. */
3236 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3237 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3239 for (i
= 0; i
< orl_count
; i
++)
3243 len
= strlen (*map
[i
].name
) + 1;
3244 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3248 /* The spec sez this should be a newline. But in order to be
3249 bug-compatible for DECstation ar we use a null. */
3252 if (bfd_write ("", 1, 1, abfd
) != 1)
3259 /* See whether this BFD is an archive. If it is, read in the armap
3260 and the extended name table. */
3263 ecoff_archive_p (abfd
)
3266 char armag
[SARMAG
+ 1];
3268 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3269 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3271 bfd_error
= wrong_format
;
3272 return (bfd_target
*) NULL
;
3275 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3276 involves a cast, we can't do it as the left operand of
3278 abfd
->tdata
.aout_ar_data
=
3279 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3281 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3283 bfd_error
= no_memory
;
3284 return (bfd_target
*) NULL
;
3287 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3288 bfd_ardata (abfd
)->cache
= NULL
;
3289 bfd_ardata (abfd
)->archive_head
= NULL
;
3290 bfd_ardata (abfd
)->symdefs
= NULL
;
3291 bfd_ardata (abfd
)->extended_names
= NULL
;
3292 bfd_ardata (abfd
)->tdata
= NULL
;
3294 if (ecoff_slurp_armap (abfd
) == false
3295 || ecoff_slurp_extended_name_table (abfd
) == false)
3297 bfd_release (abfd
, bfd_ardata (abfd
));
3298 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3299 return (bfd_target
*) NULL
;
3305 /* ECOFF linker code. */
3307 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3308 PARAMS ((struct bfd_hash_entry
*entry
,
3309 struct bfd_hash_table
*table
,
3310 const char *string
));
3311 static boolean ecoff_link_add_archive_symbols
3312 PARAMS ((bfd
*, struct bfd_link_info
*));
3313 static boolean ecoff_link_check_archive_element
3314 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3315 static boolean ecoff_link_add_object_symbols
3316 PARAMS ((bfd
*, struct bfd_link_info
*));
3317 static boolean ecoff_link_add_externals
3318 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3320 /* Routine to create an entry in an ECOFF link hash table. */
3322 static struct bfd_hash_entry
*
3323 ecoff_link_hash_newfunc (entry
, table
, string
)
3324 struct bfd_hash_entry
*entry
;
3325 struct bfd_hash_table
*table
;
3328 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3330 /* Allocate the structure if it has not already been allocated by a
3332 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3333 ret
= ((struct ecoff_link_hash_entry
*)
3334 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3335 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3337 bfd_error
= no_memory
;
3341 /* Call the allocation method of the superclass. */
3342 ret
= ((struct ecoff_link_hash_entry
*)
3343 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3348 /* Set local fields. */
3352 memset (&ret
->esym
, 0, sizeof ret
->esym
);
3354 return (struct bfd_hash_entry
*) ret
;
3357 /* Create an ECOFF link hash table. */
3359 struct bfd_link_hash_table
*
3360 ecoff_bfd_link_hash_table_create (abfd
)
3363 struct ecoff_link_hash_table
*ret
;
3365 ret
= ((struct ecoff_link_hash_table
*)
3366 malloc (sizeof (struct ecoff_link_hash_table
)));
3369 bfd_error
= no_memory
;
3372 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3373 ecoff_link_hash_newfunc
))
3376 return (struct bfd_link_hash_table
*) NULL
;
3381 /* Look up an entry in an ECOFF link hash table. */
3383 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3384 ((struct ecoff_link_hash_entry *) \
3385 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3387 /* Traverse an ECOFF link hash table. */
3389 #define ecoff_link_hash_traverse(table, func, info) \
3390 (bfd_link_hash_traverse \
3392 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3395 /* Get the ECOFF link hash table from the info structure. This is
3398 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3400 /* Given an ECOFF BFD, add symbols to the global hash table as
3404 ecoff_bfd_link_add_symbols (abfd
, info
)
3406 struct bfd_link_info
*info
;
3408 switch (bfd_get_format (abfd
))
3411 return ecoff_link_add_object_symbols (abfd
, info
);
3413 return ecoff_link_add_archive_symbols (abfd
, info
);
3415 bfd_error
= wrong_format
;
3420 /* Add the symbols from an archive file to the global hash table.
3421 This looks through the undefined symbols, looks each one up in the
3422 archive hash table, and adds any associated object file. We do not
3423 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3424 already have a hash table, so there is no reason to construct
3428 ecoff_link_add_archive_symbols (abfd
, info
)
3430 struct bfd_link_info
*info
;
3432 const bfd_byte
*raw_armap
;
3433 struct bfd_link_hash_entry
**pundef
;
3434 unsigned int armap_count
;
3435 unsigned int armap_log
;
3437 const bfd_byte
*hashtable
;
3438 const char *stringbase
;
3440 if (! bfd_has_map (abfd
))
3442 bfd_error
= no_symbols
;
3446 /* If we don't have any raw data for this archive, as can happen on
3447 Irix 4.0.5F, we call the generic routine.
3448 FIXME: We should be more clever about this, since someday tdata
3449 may get to something for a generic archive. */
3450 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3451 if (raw_armap
== (bfd_byte
*) NULL
)
3452 return (_bfd_generic_link_add_archive_symbols
3453 (abfd
, info
, ecoff_link_check_archive_element
));
3455 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3458 for (i
= 1; i
< armap_count
; i
<<= 1)
3460 BFD_ASSERT (i
== armap_count
);
3462 hashtable
= raw_armap
+ 4;
3463 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3465 /* Look through the list of undefined symbols. */
3466 pundef
= &info
->hash
->undefs
;
3467 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3469 struct bfd_link_hash_entry
*h
;
3470 unsigned int hash
, rehash
;
3471 unsigned int file_offset
;
3477 /* When a symbol is defined, it is not necessarily removed from
3479 if (h
->type
!= bfd_link_hash_undefined
3480 && h
->type
!= bfd_link_hash_common
)
3482 /* Remove this entry from the list, for general cleanliness
3483 and because we are going to look through the list again
3484 if we search any more libraries. We can't remove the
3485 entry if it is the tail, because that would lose any
3486 entries we add to the list later on. */
3487 if (*pundef
!= info
->hash
->undefs_tail
)
3488 *pundef
= (*pundef
)->next
;
3490 pundef
= &(*pundef
)->next
;
3494 /* Native ECOFF linkers do not pull in archive elements merely
3495 to satisfy common definitions, so neither do we. We leave
3496 them on the list, though, in case we are linking against some
3497 other object format. */
3498 if (h
->type
!= bfd_link_hash_undefined
)
3500 pundef
= &(*pundef
)->next
;
3504 /* Look for this symbol in the archive hash table. */
3505 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3508 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3509 if (file_offset
== 0)
3511 /* Nothing in this slot. */
3512 pundef
= &(*pundef
)->next
;
3516 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3517 if (name
[0] != h
->root
.string
[0]
3518 || strcmp (name
, h
->root
.string
) != 0)
3523 /* That was the wrong symbol. Try rehashing. */
3525 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3527 srch
= (srch
+ rehash
) & (armap_count
- 1))
3529 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3530 if (file_offset
== 0)
3532 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3533 if (name
[0] == h
->root
.string
[0]
3534 && strcmp (name
, h
->root
.string
) == 0)
3543 pundef
= &(*pundef
)->next
;
3550 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3551 if (element
== (bfd
*) NULL
)
3554 if (! bfd_check_format (element
, bfd_object
))
3557 /* Unlike the generic linker, we know that this element provides
3558 a definition for an undefined symbol and we know that we want
3559 to include it. We don't need to check anything. */
3560 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3562 if (! ecoff_link_add_object_symbols (element
, info
))
3565 pundef
= &(*pundef
)->next
;
3571 /* This is called if we used _bfd_generic_link_add_archive_symbols
3572 because we were not dealing with an ECOFF archive. */
3575 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3577 struct bfd_link_info
*info
;
3580 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3581 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3582 = backend
->debug_swap
.swap_ext_in
;
3584 bfd_size_type external_ext_size
;
3593 if (! ecoff_slurp_symbolic_header (abfd
))
3596 /* If there are no symbols, we don't want it. */
3597 if (bfd_get_symcount (abfd
) == 0)
3600 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3602 /* Read in the external symbols and external strings. */
3603 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3604 esize
= symhdr
->iextMax
* external_ext_size
;
3605 external_ext
= (PTR
) alloca (esize
);
3606 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3607 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3610 ssext
= (char *) alloca (symhdr
->issExtMax
);
3611 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3612 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3615 /* Look through the external symbols to see if they define some
3616 symbol that is currently undefined. */
3617 ext_ptr
= (char *) external_ext
;
3618 ext_end
= ext_ptr
+ esize
;
3619 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3624 struct bfd_link_hash_entry
*h
;
3626 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3628 /* See if this symbol defines something. */
3629 if (esym
.asym
.st
!= stGlobal
3630 && esym
.asym
.st
!= stLabel
3631 && esym
.asym
.st
!= stProc
)
3634 switch (esym
.asym
.sc
)
3657 name
= ssext
+ esym
.asym
.iss
;
3658 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3660 /* Unlike the generic linker, we do not pull in elements because
3661 of common symbols. */
3662 if (h
== (struct bfd_link_hash_entry
*) NULL
3663 || h
->type
!= bfd_link_hash_undefined
)
3666 /* Include this element. */
3667 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3669 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3679 /* Add symbols from an ECOFF object file to the global linker hash
3683 ecoff_link_add_object_symbols (abfd
, info
)
3685 struct bfd_link_info
*info
;
3688 bfd_size_type external_ext_size
;
3693 if (! ecoff_slurp_symbolic_header (abfd
))
3696 /* If there are no symbols, we don't want it. */
3697 if (bfd_get_symcount (abfd
) == 0)
3700 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3702 /* Read in the external symbols and external strings. */
3703 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3704 esize
= symhdr
->iextMax
* external_ext_size
;
3705 external_ext
= (PTR
) alloca (esize
);
3706 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3707 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3710 ssext
= (char *) alloca (symhdr
->issExtMax
);
3711 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3712 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3715 return ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3718 /* Add the external symbols of an object file to the global linker
3719 hash table. The external symbols and strings we are passed are
3720 just allocated on the stack, and will be discarded. We must
3721 explicitly save any information we may need later on in the link.
3722 We do not want to read the external symbol information again. */
3725 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3727 struct bfd_link_info
*info
;
3731 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3732 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3733 = backend
->debug_swap
.swap_ext_in
;
3734 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3735 unsigned long ext_count
;
3736 struct ecoff_link_hash_entry
**sym_hash
;
3740 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3742 sym_hash
= ((struct ecoff_link_hash_entry
**)
3744 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3747 bfd_error
= no_memory
;
3750 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3752 ext_ptr
= (char *) external_ext
;
3753 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3754 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3761 struct ecoff_link_hash_entry
*h
;
3765 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3767 /* Skip debugging symbols. */
3769 switch (esym
.asym
.st
)
3785 /* Get the information for this symbol. */
3786 value
= esym
.asym
.value
;
3787 switch (esym
.asym
.sc
)
3807 section
= bfd_make_section_old_way (abfd
, ".text");
3808 value
-= section
->vma
;
3811 section
= bfd_make_section_old_way (abfd
, ".data");
3812 value
-= section
->vma
;
3815 section
= bfd_make_section_old_way (abfd
, ".bss");
3816 value
-= section
->vma
;
3819 section
= &bfd_abs_section
;
3822 section
= &bfd_und_section
;
3825 section
= bfd_make_section_old_way (abfd
, ".sdata");
3826 value
-= section
->vma
;
3829 section
= bfd_make_section_old_way (abfd
, ".sbss");
3830 value
-= section
->vma
;
3833 section
= bfd_make_section_old_way (abfd
, ".rdata");
3834 value
-= section
->vma
;
3837 if (value
> ecoff_data (abfd
)->gp_size
)
3839 section
= &bfd_com_section
;
3844 if (ecoff_scom_section
.name
== NULL
)
3846 /* Initialize the small common section. */
3847 ecoff_scom_section
.name
= SCOMMON
;
3848 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3849 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3850 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3851 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3852 ecoff_scom_symbol
.name
= SCOMMON
;
3853 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3854 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3855 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3857 section
= &ecoff_scom_section
;
3860 section
= &bfd_und_section
;
3863 section
= bfd_make_section_old_way (abfd
, ".init");
3864 value
-= section
->vma
;
3867 section
= bfd_make_section_old_way (abfd
, ".fini");
3868 value
-= section
->vma
;
3872 if (section
== (asection
*) NULL
)
3875 name
= ssext
+ esym
.asym
.iss
;
3877 if (! (_bfd_generic_link_add_one_symbol
3878 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3879 (const char *) NULL
, true, true, backend
->constructor_bitsize
,
3880 (struct bfd_link_hash_entry
**) &h
)))
3885 /* If we are building an ECOFF hash table, save the external
3886 symbol information. */
3887 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3889 if (h
->abfd
== (bfd
*) NULL
3890 || (section
!= &bfd_und_section
3891 && (! bfd_is_com_section (section
)
3892 || h
->root
.type
!= bfd_link_hash_defined
)))
3903 /* ECOFF final link routines. */
3905 static boolean ecoff_final_link_debug_accumulate
3906 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
3908 static boolean ecoff_link_write_external
3909 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3910 static boolean ecoff_indirect_link_order
3911 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3912 struct bfd_link_order
*));
3914 /* ECOFF final link routine. This looks through all the input BFDs
3915 and gathers together all the debugging information, and then
3916 processes all the link order information. This may cause it to
3917 close and reopen some input BFDs; I'll see how bad this is. */
3920 ecoff_bfd_final_link (abfd
, info
)
3922 struct bfd_link_info
*info
;
3924 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3925 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3928 register bfd
*input_bfd
;
3930 struct bfd_link_order
*p
;
3932 /* We accumulate the debugging information counts in the symbolic
3934 symhdr
= &debug
->symbolic_header
;
3935 symhdr
->magic
= backend
->debug_swap
.sym_magic
;
3937 symhdr
->ilineMax
= 0;
3941 symhdr
->isymMax
= 0;
3942 symhdr
->ioptMax
= 0;
3943 symhdr
->iauxMax
= 0;
3945 symhdr
->issExtMax
= 0;
3948 symhdr
->iextMax
= 0;
3950 /* We accumulate the debugging information itself in the debug_info
3953 debug
->external_dnr
= NULL
;
3954 debug
->external_pdr
= NULL
;
3955 debug
->external_sym
= NULL
;
3956 debug
->external_opt
= NULL
;
3957 debug
->external_aux
= NULL
;
3959 debug
->ssext
= debug
->ssext_end
= NULL
;
3960 debug
->external_fdr
= NULL
;
3961 debug
->external_rfd
= NULL
;
3962 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3964 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
3965 if (handle
== (PTR
) NULL
)
3968 /* Accumulate the debugging symbols from each input BFD. */
3969 for (input_bfd
= info
->input_bfds
;
3970 input_bfd
!= (bfd
*) NULL
;
3971 input_bfd
= input_bfd
->link_next
)
3975 /* If we might be using the C based alloca function, dump memory
3976 allocated by ecoff_final_link_debug_accumulate. */
3983 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
3985 /* Abitrarily set the symbolic header vstamp to the vstamp
3986 of the first object file in the link. */
3987 if (symhdr
->vstamp
== 0)
3989 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
3990 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
3994 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
3995 debug
, &backend
->debug_swap
,
4000 /* Combine the register masks. */
4001 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4002 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4003 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4004 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4005 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4006 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4009 /* Write out the external symbols. */
4010 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4011 ecoff_link_write_external
,
4014 if (info
->relocateable
)
4016 /* We need to make a pass over the link_orders to count up the
4017 number of relocations we will need to output, so that we know
4018 how much space they will take up. */
4019 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4022 for (p
= o
->link_order_head
;
4023 p
!= (struct bfd_link_order
*) NULL
;
4025 if (p
->type
== bfd_indirect_link_order
)
4026 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4030 /* Compute the reloc and symbol file positions. */
4031 ecoff_compute_reloc_file_positions (abfd
);
4033 /* Write out the debugging information. */
4034 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4035 &backend
->debug_swap
, info
,
4036 ecoff_data (abfd
)->sym_filepos
))
4039 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4041 if (info
->relocateable
)
4043 /* Now reset the reloc_count field of the sections in the output
4044 BFD to 0, so that we can use them to keep track of how many
4045 relocs we have output thus far. */
4046 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4050 /* Get a value for the GP register. */
4051 if (ecoff_data (abfd
)->gp
== 0)
4053 struct bfd_link_hash_entry
*h
;
4055 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4056 if (h
!= (struct bfd_link_hash_entry
*) NULL
4057 && h
->type
== bfd_link_hash_defined
)
4058 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4059 + h
->u
.def
.section
->output_section
->vma
4060 + h
->u
.def
.section
->output_offset
);
4061 else if (info
->relocateable
)
4065 /* Make up a value. */
4067 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4070 && (strcmp (o
->name
, _SBSS
) == 0
4071 || strcmp (o
->name
, _SDATA
) == 0
4072 || strcmp (o
->name
, _LIT4
) == 0
4073 || strcmp (o
->name
, _LIT8
) == 0
4074 || strcmp (o
->name
, _LITA
) == 0))
4077 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4081 /* If the relocate_section function needs to do a reloc
4082 involving the GP value, it should make a reloc_dangerous
4083 callback to warn that GP is not defined. */
4087 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4089 /* Ignore any link_orders for the .reginfo section, which does
4090 not really exist. */
4091 if (strcmp (o
->name
, REGINFO
) == 0)
4094 for (p
= o
->link_order_head
;
4095 p
!= (struct bfd_link_order
*) NULL
;
4098 /* If we might be using the C based alloca function, we need
4099 to dump the memory allocated by the function
4100 ecoff_indirect_link_order. */
4106 if (p
->type
== bfd_indirect_link_order
4107 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4108 == bfd_target_ecoff_flavour
))
4110 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4115 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4121 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4126 /* Accumulate the debugging information for an input BFD into the
4127 output BFD. This must read in the symbolic information of the
4131 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4134 struct bfd_link_info
*info
;
4137 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4138 const struct ecoff_debug_swap
* const swap
=
4139 &ecoff_backend (input_bfd
)->debug_swap
;
4140 HDRR
*symhdr
= &debug
->symbolic_header
;
4143 #define READ(ptr, offset, count, size, type) \
4144 if (symhdr->count == 0) \
4145 debug->ptr = NULL; \
4148 debug->ptr = (type) alloca (size * symhdr->count); \
4149 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4151 || (bfd_read (debug->ptr, size, symhdr->count, \
4152 input_bfd) != size * symhdr->count)) \
4156 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4157 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4158 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4159 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4160 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4161 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4163 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4164 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4165 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4168 /* We do not read the external strings or the external symbols. */
4170 ret
= (bfd_ecoff_debug_accumulate
4171 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4172 &ecoff_backend (output_bfd
)->debug_swap
,
4173 input_bfd
, debug
, swap
, info
));
4175 /* Make sure we don't accidentally follow one of these pointers on
4178 debug
->external_dnr
= NULL
;
4179 debug
->external_pdr
= NULL
;
4180 debug
->external_sym
= NULL
;
4181 debug
->external_opt
= NULL
;
4182 debug
->external_aux
= NULL
;
4184 debug
->external_fdr
= NULL
;
4185 debug
->external_rfd
= NULL
;
4190 /* Put out information for an external symbol. These come only from
4194 ecoff_link_write_external (h
, data
)
4195 struct ecoff_link_hash_entry
*h
;
4198 bfd
*output_bfd
= (bfd
*) data
;
4200 /* FIXME: We should check if this symbol is being stripped. */
4202 if (h
->root
.written
)
4205 if (h
->abfd
== (bfd
*) NULL
)
4208 h
->esym
.cobol_main
= 0;
4209 h
->esym
.weakext
= 0;
4210 h
->esym
.reserved
= 0;
4211 h
->esym
.ifd
= ifdNil
;
4212 h
->esym
.asym
.value
= 0;
4213 /* FIXME: we can do better than this for st and sc. */
4214 h
->esym
.asym
.st
= stGlobal
;
4215 h
->esym
.asym
.sc
= scAbs
;
4216 h
->esym
.asym
.reserved
= 0;
4217 h
->esym
.asym
.index
= indexNil
;
4219 else if (h
->esym
.ifd
!= -1)
4221 struct ecoff_debug_info
*debug
;
4223 /* Adjust the FDR index for the symbol by that used for the
4225 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4226 BFD_ASSERT (h
->esym
.ifd
>= 0
4227 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4228 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4231 switch (h
->root
.type
)
4234 case bfd_link_hash_new
:
4236 case bfd_link_hash_undefined
:
4237 case bfd_link_hash_weak
:
4238 if (h
->esym
.asym
.st
!= scUndefined
4239 && h
->esym
.asym
.st
!= scSUndefined
)
4240 h
->esym
.asym
.st
= scUndefined
;
4242 case bfd_link_hash_defined
:
4243 if (h
->esym
.asym
.sc
== scUndefined
4244 || h
->esym
.asym
.sc
== scSUndefined
)
4245 h
->esym
.asym
.sc
= scAbs
;
4246 else if (h
->esym
.asym
.sc
== scCommon
)
4247 h
->esym
.asym
.sc
= scBss
;
4248 else if (h
->esym
.asym
.sc
== scSCommon
)
4249 h
->esym
.asym
.sc
= scSBss
;
4250 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4251 + h
->root
.u
.def
.section
->output_section
->vma
4252 + h
->root
.u
.def
.section
->output_offset
);
4254 case bfd_link_hash_common
:
4255 if (h
->esym
.asym
.sc
!= scCommon
4256 && h
->esym
.asym
.sc
!= scSCommon
)
4257 h
->esym
.asym
.sc
= scCommon
;
4258 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4260 case bfd_link_hash_indirect
:
4261 case bfd_link_hash_warning
:
4262 /* FIXME: Ignore these for now. The circumstances under which
4263 they should be written out are not clear to me. */
4267 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4269 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4270 h
->root
.written
= true;
4272 return (bfd_ecoff_debug_one_external
4273 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4274 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4278 /* Relocate and write an ECOFF section into an ECOFF output file. */
4281 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4283 struct bfd_link_info
*info
;
4284 asection
*output_section
;
4285 struct bfd_link_order
*link_order
;
4287 asection
*input_section
;
4289 bfd_size_type input_size
;
4291 bfd_size_type external_reloc_size
;
4292 bfd_size_type external_relocs_size
;
4293 PTR external_relocs
;
4295 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4297 if (link_order
->size
== 0)
4300 input_section
= link_order
->u
.indirect
.section
;
4301 input_bfd
= input_section
->owner
;
4303 BFD_ASSERT (input_section
->output_section
== output_section
);
4304 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4305 BFD_ASSERT (bfd_section_size (input_bfd
, input_section
) == link_order
->size
);
4307 /* Get the section contents. */
4308 input_size
= bfd_section_size (input_bfd
, input_section
);
4309 contents
= (bfd_byte
*) alloca (input_size
);
4310 if (! bfd_get_section_contents (input_bfd
, input_section
, (PTR
) contents
,
4311 (file_ptr
) 0, input_size
))
4314 /* Get the relocs. */
4315 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4316 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4317 external_relocs
= (PTR
) alloca (external_relocs_size
);
4318 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4319 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4320 != external_relocs_size
))
4323 /* Relocate the section contents. */
4324 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4325 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4329 /* Write out the relocated section. */
4330 if (! bfd_set_section_contents (output_bfd
,
4333 input_section
->output_offset
,
4337 /* If we are producing relocateable output, the relocs were
4338 modified, and we write them out now. We use the reloc_count
4339 field of output_section to keep track of the number of relocs we
4340 have output so far. */
4341 if (info
->relocateable
)
4343 if (bfd_seek (output_bfd
,
4344 (output_section
->rel_filepos
+
4345 output_section
->reloc_count
* external_reloc_size
),
4347 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4348 != external_relocs_size
))
4350 output_section
->reloc_count
+= input_section
->reloc_count
;