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 void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
49 asymbol
*asym
, int ext
,
50 asymbol
**indirect_ptr_ptr
));
51 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
52 RNDXR
*rndx
, long isym
,
54 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
55 unsigned int indx
, int bigendian
));
56 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
58 static void ecoff_clear_output_flags
PARAMS ((bfd
*abfd
));
59 static boolean ecoff_rel
PARAMS ((bfd
*output_bfd
, bfd_seclet_type
*seclet
,
60 asection
*output_section
, PTR data
,
61 boolean relocateable
));
62 static boolean ecoff_dump_seclet
PARAMS ((bfd
*abfd
, bfd_seclet_type
*seclet
,
63 asection
*section
, PTR data
,
64 boolean relocateable
));
65 static long ecoff_add_string
PARAMS ((bfd
*output_bfd
, FDR
*fdr
,
66 CONST
char *string
, boolean external
));
67 static boolean ecoff_get_debug
PARAMS ((bfd
*output_bfd
,
68 bfd_seclet_type
*seclet
,
70 boolean relocateable
));
71 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
72 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
77 /* This stuff is somewhat copied from coffcode.h. */
79 static asection bfd_debug_section
= { "*DEBUG*" };
81 /* Create an ECOFF object. */
87 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
88 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
89 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
91 bfd_error
= no_memory
;
95 /* Always create a .scommon section for every BFD. This is a hack so
96 that the linker has something to attach scSCommon symbols to. */
97 if (bfd_make_section (abfd
, SCOMMON
) == NULL
)
103 /* This is a hook called by coff_real_object_p to create any backend
104 specific information. */
107 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
112 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
113 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
114 ecoff_data_type
*ecoff
;
117 if (ecoff_mkobject (abfd
) == false)
120 ecoff
= ecoff_data (abfd
);
122 ecoff
->sym_filepos
= internal_f
->f_symptr
;
124 /* Create the .reginfo section to give programs outside BFD a way to
125 see the information stored in the a.out header. See the comment
127 regsec
= bfd_make_section (abfd
, REGINFO
);
131 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
135 ecoff
->text_start
= internal_a
->text_start
;
136 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
137 ecoff
->gp
= internal_a
->gp_value
;
138 ecoff
->gprmask
= internal_a
->gprmask
;
139 for (i
= 0; i
< 4; i
++)
140 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
141 ecoff
->fprmask
= internal_a
->fprmask
;
142 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
143 abfd
->flags
|= D_PAGED
;
146 /* It turns out that no special action is required by the MIPS or
147 Alpha ECOFF backends. They have different information in the
148 a.out header, but we just copy it all (e.g., gprmask, cprmask and
149 fprmask) and let the swapping routines ensure that only relevant
150 information is written out. */
155 /* This is a hook needed by SCO COFF, but we have nothing to do. */
158 ecoff_make_section_hook (abfd
, name
)
162 return (asection
*) NULL
;
165 /* Initialize a new section. */
168 ecoff_new_section_hook (abfd
, section
)
172 section
->alignment_power
= abfd
->xvec
->align_power_min
;
174 if (strcmp (section
->name
, _TEXT
) == 0)
175 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
176 else if (strcmp (section
->name
, _DATA
) == 0
177 || strcmp (section
->name
, _SDATA
) == 0)
178 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
179 else if (strcmp (section
->name
, _RDATA
) == 0
180 || strcmp (section
->name
, _LIT8
) == 0
181 || strcmp (section
->name
, _LIT4
) == 0)
182 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
183 else if (strcmp (section
->name
, _BSS
) == 0
184 || strcmp (section
->name
, _SBSS
) == 0)
185 section
->flags
|= SEC_ALLOC
;
186 else if (strcmp (section
->name
, REGINFO
) == 0)
188 section
->flags
|= SEC_HAS_CONTENTS
| SEC_NEVER_LOAD
;
189 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
192 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
193 uncertain about .init on some systems and I don't know how shared
199 /* Determine the machine architecture and type. This is called from
200 the generic COFF routines. It is the inverse of ecoff_get_magic,
201 below. This could be an ECOFF backend routine, with one version
202 for each target, but there aren't all that many ECOFF targets. */
205 ecoff_set_arch_mach_hook (abfd
, filehdr
)
209 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
210 enum bfd_architecture arch
;
213 switch (internal_f
->f_magic
)
216 case MIPS_MAGIC_LITTLE
:
218 arch
= bfd_arch_mips
;
222 case MIPS_MAGIC_LITTLE2
:
223 case MIPS_MAGIC_BIG2
:
224 /* MIPS ISA level 2: the r6000 */
225 arch
= bfd_arch_mips
;
229 case MIPS_MAGIC_LITTLE3
:
230 case MIPS_MAGIC_BIG3
:
231 /* MIPS ISA level 3: the r4000 */
232 arch
= bfd_arch_mips
;
237 arch
= bfd_arch_alpha
;
242 arch
= bfd_arch_obscure
;
247 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
250 /* Get the magic number to use based on the architecture and machine.
251 This is the inverse of ecoff_set_arch_mach_hook, above. */
254 ecoff_get_magic (abfd
)
259 switch (bfd_get_arch (abfd
))
262 switch (bfd_get_mach (abfd
))
267 big
= MIPS_MAGIC_BIG
;
268 little
= MIPS_MAGIC_LITTLE
;
272 big
= MIPS_MAGIC_BIG2
;
273 little
= MIPS_MAGIC_LITTLE2
;
277 big
= MIPS_MAGIC_BIG3
;
278 little
= MIPS_MAGIC_LITTLE3
;
282 return abfd
->xvec
->byteorder_big_p
? big
: little
;
293 /* Get the section s_flags to use for a section. */
296 ecoff_sec_to_styp_flags (name
, flags
)
304 if (strcmp (name
, _TEXT
) == 0)
306 else if (strcmp (name
, _DATA
) == 0)
308 else if (strcmp (name
, _SDATA
) == 0)
310 else if (strcmp (name
, _RDATA
) == 0)
312 else if (strcmp (name
, _LITA
) == 0)
314 else if (strcmp (name
, _LIT8
) == 0)
316 else if (strcmp (name
, _LIT4
) == 0)
318 else if (strcmp (name
, _BSS
) == 0)
320 else if (strcmp (name
, _SBSS
) == 0)
322 else if (strcmp (name
, _INIT
) == 0)
323 styp
= STYP_ECOFF_INIT
;
324 else if (strcmp (name
, _FINI
) == 0)
325 styp
= STYP_ECOFF_FINI
;
326 else if (flags
& SEC_CODE
)
328 else if (flags
& SEC_DATA
)
330 else if (flags
& SEC_READONLY
)
332 else if (flags
& SEC_LOAD
)
337 if (flags
& SEC_NEVER_LOAD
)
343 /* Get the BFD flags to use for a section. */
346 ecoff_styp_to_sec_flags (abfd
, hdr
)
350 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
351 long styp_flags
= internal_s
->s_flags
;
352 flagword sec_flags
=0;
354 if (styp_flags
& STYP_NOLOAD
)
355 sec_flags
|= SEC_NEVER_LOAD
;
357 /* For 386 COFF, at least, an unloadable text or data section is
358 actually a shared library section. */
359 if ((styp_flags
& STYP_TEXT
)
360 || (styp_flags
& STYP_ECOFF_INIT
)
361 || (styp_flags
& STYP_ECOFF_FINI
))
363 if (sec_flags
& SEC_NEVER_LOAD
)
364 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
366 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
368 else if ((styp_flags
& STYP_DATA
)
369 || (styp_flags
& STYP_RDATA
)
370 || (styp_flags
& STYP_SDATA
))
372 if (sec_flags
& SEC_NEVER_LOAD
)
373 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
375 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
376 if (styp_flags
& STYP_RDATA
)
377 sec_flags
|= SEC_READONLY
;
379 else if ((styp_flags
& STYP_BSS
)
380 || (styp_flags
& STYP_SBSS
))
382 sec_flags
|= SEC_ALLOC
;
384 else if (styp_flags
& STYP_INFO
)
386 sec_flags
|= SEC_NEVER_LOAD
;
388 else if ((styp_flags
& STYP_LITA
)
389 || (styp_flags
& STYP_LIT8
)
390 || (styp_flags
& STYP_LIT4
))
392 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
396 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
402 /* Routines to swap auxiliary information in and out. I am assuming
403 that the auxiliary information format is always going to be target
406 /* Swap in a type information record.
407 BIGEND says whether AUX symbols are big-endian or little-endian; this
408 info comes from the file header record (fh-fBigendian). */
411 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
413 struct tir_ext
*ext_copy
;
416 struct tir_ext ext
[1];
418 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
420 /* now the fun stuff... */
422 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
423 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
424 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
425 >> TIR_BITS1_BT_SH_BIG
;
426 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
427 >> TIR_BITS_TQ4_SH_BIG
;
428 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
429 >> TIR_BITS_TQ5_SH_BIG
;
430 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
431 >> TIR_BITS_TQ0_SH_BIG
;
432 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
433 >> TIR_BITS_TQ1_SH_BIG
;
434 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
435 >> TIR_BITS_TQ2_SH_BIG
;
436 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
437 >> TIR_BITS_TQ3_SH_BIG
;
439 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
440 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
441 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
442 >> TIR_BITS1_BT_SH_LITTLE
;
443 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
444 >> TIR_BITS_TQ4_SH_LITTLE
;
445 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
446 >> TIR_BITS_TQ5_SH_LITTLE
;
447 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
448 >> TIR_BITS_TQ0_SH_LITTLE
;
449 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
450 >> TIR_BITS_TQ1_SH_LITTLE
;
451 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
452 >> TIR_BITS_TQ2_SH_LITTLE
;
453 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
454 >> TIR_BITS_TQ3_SH_LITTLE
;
458 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
463 /* Swap out a type information record.
464 BIGEND says whether AUX symbols are big-endian or little-endian; this
465 info comes from the file header record (fh-fBigendian). */
468 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
475 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
477 /* now the fun stuff... */
479 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
480 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
481 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
482 & TIR_BITS1_BT_BIG
));
483 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
485 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
486 & TIR_BITS_TQ5_BIG
));
487 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
489 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
490 & TIR_BITS_TQ1_BIG
));
491 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
493 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
494 & TIR_BITS_TQ3_BIG
));
496 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
497 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
498 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
499 & TIR_BITS1_BT_LITTLE
));
500 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
501 & TIR_BITS_TQ4_LITTLE
)
502 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
503 & TIR_BITS_TQ5_LITTLE
));
504 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
505 & TIR_BITS_TQ0_LITTLE
)
506 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
507 & TIR_BITS_TQ1_LITTLE
));
508 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
509 & TIR_BITS_TQ2_LITTLE
)
510 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
511 & TIR_BITS_TQ3_LITTLE
));
515 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
520 /* Swap in a relative symbol record. BIGEND says whether it is in
521 big-endian or little-endian format.*/
524 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
526 struct rndx_ext
*ext_copy
;
529 struct rndx_ext ext
[1];
531 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
533 /* now the fun stuff... */
535 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
536 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
537 >> RNDX_BITS1_RFD_SH_BIG
);
538 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
539 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
540 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
541 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
543 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
544 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
545 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
546 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
547 >> RNDX_BITS1_INDEX_SH_LITTLE
)
548 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
549 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
553 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
558 /* Swap out a relative symbol record. BIGEND says whether it is in
559 big-endian or little-endian format.*/
562 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
565 struct rndx_ext
*ext
;
569 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
571 /* now the fun stuff... */
573 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
574 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
575 & RNDX_BITS1_RFD_BIG
)
576 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
577 & RNDX_BITS1_INDEX_BIG
));
578 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
579 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
581 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
582 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
583 & RNDX_BITS1_RFD_LITTLE
)
584 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
585 & RNDX_BITS1_INDEX_LITTLE
));
586 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
587 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
591 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
596 /* Read in and swap the important symbolic information for an ECOFF
597 object file. This is called by gdb. */
600 ecoff_slurp_symbolic_info (abfd
)
603 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
604 bfd_size_type external_hdr_size
;
605 HDRR
*internal_symhdr
;
606 bfd_size_type raw_base
;
607 bfd_size_type raw_size
;
609 bfd_size_type external_fdr_size
;
613 bfd_size_type raw_end
;
614 bfd_size_type cb_end
;
616 /* Check whether we've already gotten it, and whether there's any to
618 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
620 if (ecoff_data (abfd
)->sym_filepos
== 0)
622 bfd_get_symcount (abfd
) = 0;
626 /* At this point bfd_get_symcount (abfd) holds the number of symbols
627 as read from the file header, but on ECOFF this is always the
628 size of the symbolic information header. It would be cleaner to
629 handle this when we first read the file in coffgen.c. */
630 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
631 if (bfd_get_symcount (abfd
) != external_hdr_size
)
633 bfd_error
= bad_value
;
637 /* Read the symbolic information header. */
638 raw
= (PTR
) alloca (external_hdr_size
);
639 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
640 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
641 != external_hdr_size
))
643 bfd_error
= system_call_error
;
646 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
647 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
649 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
651 bfd_error
= bad_value
;
655 /* Now we can get the correct number of symbols. */
656 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
657 + internal_symhdr
->iextMax
);
659 /* Read all the symbolic information at once. */
660 raw_base
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
662 /* Alpha ecoff makes the determination of raw_size difficult. It has
663 an undocumented debug data section between the symhdr and the first
664 documented section. And the ordering of the sections varies between
665 statically and dynamically linked executables.
666 If bfd supports SEEK_END someday, this code could be simplified. */
670 #define UPDATE_RAW_END(start, count, size) \
671 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
672 if (cb_end > raw_end) \
675 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
676 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
677 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
678 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
679 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
680 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
681 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
682 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
683 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
684 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
685 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
687 #undef UPDATE_RAW_END
689 raw_size
= raw_end
- raw_base
;
692 ecoff_data (abfd
)->sym_filepos
= 0;
695 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
698 bfd_error
= no_memory
;
701 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
703 bfd_error
= system_call_error
;
704 bfd_release (abfd
, raw
);
708 ecoff_data (abfd
)->raw_size
= raw_size
;
709 ecoff_data (abfd
)->raw_syments
= raw
;
711 /* Get pointers for the numeric offsets in the HDRR structure. */
712 #define FIX(off1, off2, type) \
713 if (internal_symhdr->off1 == 0) \
714 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
716 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
717 + internal_symhdr->off1 \
719 FIX (cbLineOffset
, line
, unsigned char *);
720 FIX (cbDnOffset
, external_dnr
, PTR
);
721 FIX (cbPdOffset
, external_pdr
, PTR
);
722 FIX (cbSymOffset
, external_sym
, PTR
);
723 FIX (cbOptOffset
, external_opt
, PTR
);
724 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
725 FIX (cbSsOffset
, ss
, char *);
726 FIX (cbSsExtOffset
, ssext
, char *);
727 FIX (cbFdOffset
, external_fdr
, PTR
);
728 FIX (cbRfdOffset
, external_rfd
, PTR
);
729 FIX (cbExtOffset
, external_ext
, PTR
);
732 /* I don't want to always swap all the data, because it will just
733 waste time and most programs will never look at it. The only
734 time the linker needs most of the debugging information swapped
735 is when linking big-endian and little-endian MIPS object files
736 together, which is not a common occurrence.
738 We need to look at the fdr to deal with a lot of information in
739 the symbols, so we swap them here. */
740 ecoff_data (abfd
)->debug_info
.fdr
=
741 (struct fdr
*) bfd_alloc (abfd
,
742 (internal_symhdr
->ifdMax
*
743 sizeof (struct fdr
)));
744 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
746 bfd_error
= no_memory
;
749 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
750 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
751 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
752 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
753 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
754 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
759 /* ECOFF symbol table routines. The ECOFF symbol table is described
760 in gcc/mips-tfile.c. */
762 /* ECOFF uses two common sections. One is the usual one, and the
763 other is for small objects. All the small objects are kept
764 together, and then referenced via the gp pointer, which yields
765 faster assembler code. This is what we use for the small common
767 static asection ecoff_scom_section
;
768 static asymbol ecoff_scom_symbol
;
769 static asymbol
*ecoff_scom_symbol_ptr
;
771 /* Create an empty symbol. */
774 ecoff_make_empty_symbol (abfd
)
777 ecoff_symbol_type
*new;
779 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
780 if (new == (ecoff_symbol_type
*) NULL
)
782 bfd_error
= no_memory
;
783 return (asymbol
*) NULL
;
785 memset (new, 0, sizeof *new);
786 new->symbol
.section
= (asection
*) NULL
;
787 new->fdr
= (FDR
*) NULL
;
790 new->symbol
.the_bfd
= abfd
;
794 /* Set the BFD flags and section for an ECOFF symbol. */
797 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
802 asymbol
**indirect_ptr_ptr
;
804 asym
->the_bfd
= abfd
;
805 asym
->value
= ecoff_sym
->value
;
806 asym
->section
= &bfd_debug_section
;
809 /* An indirect symbol requires two consecutive stabs symbols. */
810 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
812 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
814 /* @@ Stuffing pointers into integers is a no-no.
815 We can usually get away with it if the integer is
816 large enough though. */
817 if (sizeof (asym
) > sizeof (bfd_vma
))
819 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
821 asym
->flags
= BSF_DEBUGGING
;
822 asym
->section
= &bfd_und_section
;
823 *indirect_ptr_ptr
= NULL
;
827 if (ECOFF_IS_STAB (ecoff_sym
)
828 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
830 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
831 asym
->section
= &bfd_ind_section
;
832 /* Pass this symbol on to the next call to this function. */
833 *indirect_ptr_ptr
= asym
;
837 /* Most symbol types are just for debugging. */
838 switch (ecoff_sym
->st
)
847 if (ECOFF_IS_STAB (ecoff_sym
))
849 asym
->flags
= BSF_DEBUGGING
;
854 asym
->flags
= BSF_DEBUGGING
;
859 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
861 asym
->flags
= BSF_LOCAL
;
862 switch (ecoff_sym
->sc
)
865 /* Used for compiler generated labels. Leave them in the
866 debugging section, and mark them as local. If BSF_DEBUGGING
867 is set, then nm does not display them for some reason. If no
868 flags are set then the linker whines about them. */
869 asym
->flags
= BSF_LOCAL
;
872 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
873 asym
->value
-= asym
->section
->vma
;
876 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
877 asym
->value
-= asym
->section
->vma
;
880 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
881 asym
->value
-= asym
->section
->vma
;
884 asym
->flags
= BSF_DEBUGGING
;
887 asym
->section
= &bfd_abs_section
;
890 asym
->section
= &bfd_und_section
;
900 asym
->flags
= BSF_DEBUGGING
;
903 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
904 asym
->value
-= asym
->section
->vma
;
907 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
908 asym
->value
-= asym
->section
->vma
;
911 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
912 asym
->value
-= asym
->section
->vma
;
915 asym
->flags
= BSF_DEBUGGING
;
918 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
920 asym
->section
= &bfd_com_section
;
926 if (ecoff_scom_section
.name
== NULL
)
928 /* Initialize the small common section. */
929 ecoff_scom_section
.name
= SCOMMON
;
930 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
931 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
932 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
933 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
934 ecoff_scom_symbol
.name
= SCOMMON
;
935 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
936 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
937 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
939 asym
->section
= &ecoff_scom_section
;
944 asym
->flags
= BSF_DEBUGGING
;
947 asym
->section
= &bfd_und_section
;
952 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
953 asym
->value
-= asym
->section
->vma
;
958 asym
->flags
= BSF_DEBUGGING
;
961 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
962 asym
->value
-= asym
->section
->vma
;
968 /* Look for special constructors symbols and make relocation entries
969 in a special construction section. These are produced by the
970 -fgnu-linker argument to g++. */
971 if (ECOFF_IS_STAB (ecoff_sym
))
973 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
985 arelent_chain
*reloc_chain
;
986 unsigned int bitsize
;
988 /* Get a section with the same name as the symbol (usually
989 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
990 name ___CTOR_LIST (three underscores). We need
991 __CTOR_LIST (two underscores), since ECOFF doesn't use
992 a leading underscore. This should be handled by gcc,
993 but instead we do it here. Actually, this should all
994 be done differently anyhow. */
995 name
= bfd_asymbol_name (asym
);
996 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1001 section
= bfd_get_section_by_name (abfd
, name
);
1002 if (section
== (asection
*) NULL
)
1006 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1007 strcpy (copy
, name
);
1008 section
= bfd_make_section (abfd
, copy
);
1011 /* Build a reloc pointing to this constructor. */
1013 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1014 reloc_chain
->relent
.sym_ptr_ptr
=
1015 bfd_get_section (asym
)->symbol_ptr_ptr
;
1016 reloc_chain
->relent
.address
= section
->_raw_size
;
1017 reloc_chain
->relent
.addend
= asym
->value
;
1018 reloc_chain
->relent
.howto
=
1019 ecoff_backend (abfd
)->constructor_reloc
;
1021 /* Set up the constructor section to hold the reloc. */
1022 section
->flags
= SEC_CONSTRUCTOR
;
1023 ++section
->reloc_count
;
1025 /* Constructor sections must be rounded to a boundary
1026 based on the bitsize. These are not real sections--
1027 they are handled specially by the linker--so the ECOFF
1028 16 byte alignment restriction does not apply. */
1029 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1030 section
->alignment_power
= 1;
1031 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1032 ++section
->alignment_power
;
1034 reloc_chain
->next
= section
->constructor_chain
;
1035 section
->constructor_chain
= reloc_chain
;
1036 section
->_raw_size
+= bitsize
/ 8;
1038 /* Mark the symbol as a constructor. */
1039 asym
->flags
|= BSF_CONSTRUCTOR
;
1046 /* Read an ECOFF symbol table. */
1049 ecoff_slurp_symbol_table (abfd
)
1052 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1053 const bfd_size_type external_ext_size
1054 = backend
->debug_swap
.external_ext_size
;
1055 const bfd_size_type external_sym_size
1056 = backend
->debug_swap
.external_sym_size
;
1057 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1058 = backend
->debug_swap
.swap_ext_in
;
1059 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1060 = backend
->debug_swap
.swap_sym_in
;
1061 bfd_size_type internal_size
;
1062 ecoff_symbol_type
*internal
;
1063 ecoff_symbol_type
*internal_ptr
;
1064 asymbol
*indirect_ptr
;
1070 /* If we've already read in the symbol table, do nothing. */
1071 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1074 /* Get the symbolic information. */
1075 if (ecoff_slurp_symbolic_info (abfd
) == false)
1077 if (bfd_get_symcount (abfd
) == 0)
1080 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1081 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1082 if (internal
== NULL
)
1084 bfd_error
= no_memory
;
1088 internal_ptr
= internal
;
1089 indirect_ptr
= NULL
;
1090 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1091 eraw_end
= (eraw_src
1092 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1093 * external_ext_size
));
1094 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1098 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1099 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1100 + internal_esym
.asym
.iss
);
1101 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1102 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1103 /* The alpha uses a negative ifd field for section symbols. */
1104 if (internal_esym
.ifd
>= 0)
1105 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1106 + internal_esym
.ifd
);
1108 internal_ptr
->fdr
= NULL
;
1109 internal_ptr
->local
= false;
1110 internal_ptr
->native
= (PTR
) eraw_src
;
1112 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1114 /* The local symbols must be accessed via the fdr's, because the
1115 string and aux indices are relative to the fdr information. */
1116 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1117 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1118 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1123 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1124 + fdr_ptr
->isymBase
* external_sym_size
);
1125 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1127 lraw_src
< lraw_end
;
1128 lraw_src
+= external_sym_size
, internal_ptr
++)
1132 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1133 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1135 + internal_sym
.iss
);
1136 ecoff_set_symbol_info (abfd
, &internal_sym
,
1137 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1138 internal_ptr
->fdr
= fdr_ptr
;
1139 internal_ptr
->local
= true;
1140 internal_ptr
->native
= (PTR
) lraw_src
;
1143 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1145 ecoff_data (abfd
)->canonical_symbols
= internal
;
1150 /* Return the amount of space needed for the canonical symbols. */
1153 ecoff_get_symtab_upper_bound (abfd
)
1156 if (ecoff_slurp_symbolic_info (abfd
) == false
1157 || bfd_get_symcount (abfd
) == 0)
1160 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1163 /* Get the canonicals symbols. */
1166 ecoff_get_symtab (abfd
, alocation
)
1168 asymbol
**alocation
;
1170 unsigned int counter
= 0;
1171 ecoff_symbol_type
*symbase
;
1172 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1174 if (ecoff_slurp_symbol_table (abfd
) == false
1175 || bfd_get_symcount (abfd
) == 0)
1178 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1179 while (counter
< bfd_get_symcount (abfd
))
1181 *(location
++) = symbase
++;
1184 *location
++ = (ecoff_symbol_type
*) NULL
;
1185 return bfd_get_symcount (abfd
);
1188 /* Turn ECOFF type information into a printable string.
1189 ecoff_emit_aggregate and ecoff_type_to_string are from
1190 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1192 /* Write aggregate information to a string. */
1195 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1202 int ifd
= rndx
->rfd
;
1203 int indx
= rndx
->index
;
1204 int sym_base
, ss_base
;
1210 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1211 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1213 if (indx
== indexNil
)
1214 name
= "/* no name */";
1217 const struct ecoff_debug_swap
* const debug_swap
1218 = &ecoff_backend (abfd
)->debug_swap
;
1222 (*debug_swap
->swap_sym_in
)
1224 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1225 + indx
* debug_swap
->external_sym_size
),
1227 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1231 "%s %s { ifd = %d, index = %ld }",
1234 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1237 /* Convert the type information to string format. */
1240 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1242 union aux_ext
*aux_ptr
;
1254 unsigned int basic_type
;
1256 static char buffer1
[1024];
1257 static char buffer2
[1024];
1262 for (i
= 0; i
< 7; i
++)
1264 qualifiers
[i
].low_bound
= 0;
1265 qualifiers
[i
].high_bound
= 0;
1266 qualifiers
[i
].stride
= 0;
1269 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1270 return "-1 (no type)";
1271 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1273 basic_type
= u
.ti
.bt
;
1274 qualifiers
[0].type
= u
.ti
.tq0
;
1275 qualifiers
[1].type
= u
.ti
.tq1
;
1276 qualifiers
[2].type
= u
.ti
.tq2
;
1277 qualifiers
[3].type
= u
.ti
.tq3
;
1278 qualifiers
[4].type
= u
.ti
.tq4
;
1279 qualifiers
[5].type
= u
.ti
.tq5
;
1280 qualifiers
[6].type
= tqNil
;
1283 * Go get the basic type.
1287 case btNil
: /* undefined */
1291 case btAdr
: /* address - integer same size as pointer */
1292 strcpy (p1
, "address");
1295 case btChar
: /* character */
1296 strcpy (p1
, "char");
1299 case btUChar
: /* unsigned character */
1300 strcpy (p1
, "unsigned char");
1303 case btShort
: /* short */
1304 strcpy (p1
, "short");
1307 case btUShort
: /* unsigned short */
1308 strcpy (p1
, "unsigned short");
1311 case btInt
: /* int */
1315 case btUInt
: /* unsigned int */
1316 strcpy (p1
, "unsigned int");
1319 case btLong
: /* long */
1320 strcpy (p1
, "long");
1323 case btULong
: /* unsigned long */
1324 strcpy (p1
, "unsigned long");
1327 case btFloat
: /* float (real) */
1328 strcpy (p1
, "float");
1331 case btDouble
: /* Double (real) */
1332 strcpy (p1
, "double");
1335 /* Structures add 1-2 aux words:
1336 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1337 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1339 case btStruct
: /* Structure (Record) */
1340 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1341 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1342 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1344 indx
++; /* skip aux words */
1347 /* Unions add 1-2 aux words:
1348 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1349 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1351 case btUnion
: /* Union */
1352 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1353 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1354 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1356 indx
++; /* skip aux words */
1359 /* Enumerations add 1-2 aux words:
1360 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1361 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1363 case btEnum
: /* Enumeration */
1364 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1365 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1366 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1368 indx
++; /* skip aux words */
1371 case btTypedef
: /* defined via a typedef, isymRef points */
1372 strcpy (p1
, "typedef");
1375 case btRange
: /* subrange of int */
1376 strcpy (p1
, "subrange");
1379 case btSet
: /* pascal sets */
1383 case btComplex
: /* fortran complex */
1384 strcpy (p1
, "complex");
1387 case btDComplex
: /* fortran double complex */
1388 strcpy (p1
, "double complex");
1391 case btIndirect
: /* forward or unnamed typedef */
1392 strcpy (p1
, "forward/unamed typedef");
1395 case btFixedDec
: /* Fixed Decimal */
1396 strcpy (p1
, "fixed decimal");
1399 case btFloatDec
: /* Float Decimal */
1400 strcpy (p1
, "float decimal");
1403 case btString
: /* Varying Length Character String */
1404 strcpy (p1
, "string");
1407 case btBit
: /* Aligned Bit String */
1411 case btPicture
: /* Picture */
1412 strcpy (p1
, "picture");
1415 case btVoid
: /* Void */
1416 strcpy (p1
, "void");
1420 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1424 p1
+= strlen (buffer1
);
1427 * If this is a bitfield, get the bitsize.
1433 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1434 sprintf (p1
, " : %d", bitsize
);
1435 p1
+= strlen (buffer1
);
1440 * Deal with any qualifiers.
1442 if (qualifiers
[0].type
!= tqNil
)
1445 * Snarf up any array bounds in the correct order. Arrays
1446 * store 5 successive words in the aux. table:
1447 * word 0 RNDXR to type of the bounds (ie, int)
1448 * word 1 Current file descriptor index
1450 * word 3 high bound (or -1 if [])
1451 * word 4 stride size in bits
1453 for (i
= 0; i
< 7; i
++)
1455 if (qualifiers
[i
].type
== tqArray
)
1457 qualifiers
[i
].low_bound
=
1458 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1459 qualifiers
[i
].high_bound
=
1460 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1461 qualifiers
[i
].stride
=
1462 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1468 * Now print out the qualifiers.
1470 for (i
= 0; i
< 6; i
++)
1472 switch (qualifiers
[i
].type
)
1479 strcpy (p2
, "ptr to ");
1480 p2
+= sizeof ("ptr to ")-1;
1484 strcpy (p2
, "volatile ");
1485 p2
+= sizeof ("volatile ")-1;
1489 strcpy (p2
, "far ");
1490 p2
+= sizeof ("far ")-1;
1494 strcpy (p2
, "func. ret. ");
1495 p2
+= sizeof ("func. ret. ");
1500 int first_array
= i
;
1503 /* Print array bounds reversed (ie, in the order the C
1504 programmer writes them). C is such a fun language.... */
1506 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1509 for (j
= i
; j
>= first_array
; j
--)
1511 strcpy (p2
, "array [");
1512 p2
+= sizeof ("array [")-1;
1513 if (qualifiers
[j
].low_bound
!= 0)
1515 "%ld:%ld {%ld bits}",
1516 (long) qualifiers
[j
].low_bound
,
1517 (long) qualifiers
[j
].high_bound
,
1518 (long) qualifiers
[j
].stride
);
1520 else if (qualifiers
[j
].high_bound
!= -1)
1523 (long) (qualifiers
[j
].high_bound
+ 1),
1524 (long) (qualifiers
[j
].stride
));
1527 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1530 strcpy (p2
, "] of ");
1531 p2
+= sizeof ("] of ")-1;
1539 strcpy (p2
, buffer1
);
1543 /* Return information about ECOFF symbol SYMBOL in RET. */
1546 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1547 bfd
*abfd
; /* Ignored. */
1551 bfd_symbol_info (symbol
, ret
);
1554 /* Print information about an ECOFF symbol. */
1557 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1561 bfd_print_symbol_type how
;
1563 const struct ecoff_debug_swap
* const debug_swap
1564 = &ecoff_backend (abfd
)->debug_swap
;
1565 FILE *file
= (FILE *)filep
;
1569 case bfd_print_symbol_name
:
1570 fprintf (file
, "%s", symbol
->name
);
1572 case bfd_print_symbol_more
:
1573 if (ecoffsymbol (symbol
)->local
)
1577 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1579 fprintf (file
, "ecoff local ");
1580 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1581 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1582 (unsigned) ecoff_sym
.sc
);
1588 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1590 fprintf (file
, "ecoff extern ");
1591 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1592 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1593 (unsigned) ecoff_ext
.asym
.sc
);
1596 case bfd_print_symbol_all
:
1597 /* Print out the symbols in a reasonable way */
1606 if (ecoffsymbol (symbol
)->local
)
1608 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1611 pos
= ((((char *) ecoffsymbol (symbol
)->native
1612 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1613 / debug_swap
->external_sym_size
)
1614 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1621 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1624 pos
= (((char *) ecoffsymbol (symbol
)->native
1625 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1626 / debug_swap
->external_ext_size
);
1627 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1628 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1629 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1632 fprintf (file
, "[%3d] %c ",
1634 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1635 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1636 (unsigned) ecoff_ext
.asym
.st
,
1637 (unsigned) ecoff_ext
.asym
.sc
,
1638 (unsigned) ecoff_ext
.asym
.index
,
1639 jmptbl
, cobol_main
, weakext
,
1642 if (ecoffsymbol (symbol
)->fdr
!= NULL
1643 && ecoff_ext
.asym
.index
!= indexNil
)
1647 bfd_size_type sym_base
;
1648 union aux_ext
*aux_base
;
1650 indx
= ecoff_ext
.asym
.index
;
1652 /* sym_base is used to map the fdr relative indices which
1653 appear in the file to the position number which we are
1655 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1656 if (ecoffsymbol (symbol
)->local
)
1658 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1660 /* aux_base is the start of the aux entries for this file;
1661 asym.index is an offset from this. */
1662 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1663 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1665 /* The aux entries are stored in host byte order; the
1666 order is indicated by a bit in the fdr. */
1667 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1669 /* This switch is basically from gcc/mips-tdump.c */
1670 switch (ecoff_ext
.asym
.st
)
1678 fprintf (file
, "\n End+1 symbol: %ld",
1679 (long) (indx
+ sym_base
));
1683 if (ecoff_ext
.asym
.sc
== scText
1684 || ecoff_ext
.asym
.sc
== scInfo
)
1685 fprintf (file
, "\n First symbol: %ld",
1686 (long) (indx
+ sym_base
));
1688 fprintf (file
, "\n First symbol: %ld",
1689 (long) (AUX_GET_ISYM (bigendian
,
1690 &aux_base
[ecoff_ext
.asym
.index
])
1696 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1698 else if (ecoffsymbol (symbol
)->local
)
1699 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1700 (long) (AUX_GET_ISYM (bigendian
,
1701 &aux_base
[ecoff_ext
.asym
.index
])
1703 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1706 fprintf (file
, "\n Local symbol: %ld",
1709 + (ecoff_data (abfd
)
1710 ->debug_info
.symbolic_header
.iextMax
)));
1714 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1715 fprintf (file
, "\n Type: %s",
1716 ecoff_type_to_string (abfd
, aux_base
, indx
,
1726 /* Read in the relocs for a section. */
1729 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1734 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1735 arelent
*internal_relocs
;
1736 bfd_size_type external_reloc_size
;
1737 bfd_size_type external_relocs_size
;
1738 char *external_relocs
;
1742 if (section
->relocation
!= (arelent
*) NULL
1743 || section
->reloc_count
== 0
1744 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1747 if (ecoff_slurp_symbol_table (abfd
) == false)
1750 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1752 * section
->reloc_count
));
1753 external_reloc_size
= backend
->external_reloc_size
;
1754 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1755 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1756 if (internal_relocs
== (arelent
*) NULL
1757 || external_relocs
== (char *) NULL
)
1759 bfd_error
= no_memory
;
1762 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1764 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1765 != external_relocs_size
)
1767 bfd_error
= system_call_error
;
1771 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1773 struct internal_reloc intern
;
1775 (*backend
->swap_reloc_in
) (abfd
,
1776 external_relocs
+ i
* external_reloc_size
,
1779 if (intern
.r_extern
)
1781 /* r_symndx is an index into the external symbols. */
1782 BFD_ASSERT (intern
.r_symndx
>= 0
1784 < (ecoff_data (abfd
)
1785 ->debug_info
.symbolic_header
.iextMax
)));
1786 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1789 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1790 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1792 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1797 CONST
char *sec_name
;
1800 /* r_symndx is a section key. */
1801 switch (intern
.r_symndx
)
1803 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1804 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1805 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1806 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1807 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1808 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1809 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1810 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1811 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1812 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1813 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1814 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1815 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1819 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1820 if (sec
== (asection
*) NULL
)
1822 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1824 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1827 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1829 /* Let the backend select the howto field and do any other
1830 required processing. */
1831 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1834 bfd_release (abfd
, external_relocs
);
1836 section
->relocation
= internal_relocs
;
1841 /* Get a canonical list of relocs. */
1844 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1852 if (section
->flags
& SEC_CONSTRUCTOR
)
1854 arelent_chain
*chain
;
1856 /* This section has relocs made up by us, not the file, so take
1857 them out of their chain and place them into the data area
1859 for (count
= 0, chain
= section
->constructor_chain
;
1860 count
< section
->reloc_count
;
1861 count
++, chain
= chain
->next
)
1862 *relptr
++ = &chain
->relent
;
1868 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1871 tblptr
= section
->relocation
;
1872 if (tblptr
== (arelent
*) NULL
)
1875 for (count
= 0; count
< section
->reloc_count
; count
++)
1876 *relptr
++ = tblptr
++;
1879 *relptr
= (arelent
*) NULL
;
1881 return section
->reloc_count
;
1884 /* Provided a BFD, a section and an offset into the section, calculate
1885 and return the name of the source file and the line nearest to the
1889 ecoff_find_nearest_line (abfd
,
1898 asymbol
**ignore_symbols
;
1900 CONST
char **filename_ptr
;
1901 CONST
char **functionname_ptr
;
1902 unsigned int *retline_ptr
;
1904 const struct ecoff_debug_swap
* const debug_swap
1905 = &ecoff_backend (abfd
)->debug_swap
;
1910 bfd_size_type external_pdr_size
;
1914 unsigned char *line_ptr
;
1915 unsigned char *line_end
;
1918 /* If we're not in the .text section, we don't have any line
1920 if (strcmp (section
->name
, _TEXT
) != 0
1921 || offset
< ecoff_data (abfd
)->text_start
1922 || offset
>= ecoff_data (abfd
)->text_end
)
1925 /* Make sure we have the FDR's. */
1926 if (ecoff_slurp_symbolic_info (abfd
) == false
1927 || bfd_get_symcount (abfd
) == 0)
1930 /* Each file descriptor (FDR) has a memory address. Here we track
1931 down which FDR we want. The FDR's are stored in increasing
1932 memory order. If speed is ever important, this can become a
1933 binary search. We must ignore FDR's with no PDR entries; they
1934 will have the adr of the FDR before or after them. */
1935 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1936 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1937 fdr_hold
= (FDR
*) NULL
;
1938 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1940 if (fdr_ptr
->cpd
== 0)
1942 if (offset
< fdr_ptr
->adr
)
1946 if (fdr_hold
== (FDR
*) NULL
)
1950 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1951 have an address, which is relative to the FDR address, and are
1952 also stored in increasing memory order. */
1953 offset
-= fdr_ptr
->adr
;
1954 external_pdr_size
= debug_swap
->external_pdr_size
;
1955 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
1956 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1957 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1958 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1960 /* The address of the first PDR is an offset which applies to the
1961 addresses of all the PDR's. */
1964 for (pdr_ptr
+= external_pdr_size
;
1966 pdr_ptr
+= external_pdr_size
)
1968 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1969 if (offset
< pdr
.adr
)
1973 /* Now we can look for the actual line number. The line numbers are
1974 stored in a very funky format, which I won't try to describe.
1975 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1976 we want; we need this to compute line_end. */
1977 line_end
= ecoff_data (abfd
)->debug_info
.line
;
1978 if (pdr_ptr
== pdr_end
)
1979 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1981 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1983 /* Now change pdr and pdr_ptr to the one we want. */
1984 pdr_ptr
-= external_pdr_size
;
1985 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1989 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
1990 + fdr_ptr
->cbLineOffset
1991 + pdr
.cbLineOffset
);
1992 while (line_ptr
< line_end
)
1997 delta
= *line_ptr
>> 4;
2000 count
= (*line_ptr
& 0xf) + 1;
2004 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2005 if (delta
>= 0x8000)
2010 if (offset
< count
* 4)
2012 offset
-= count
* 4;
2015 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2016 at least according to gdb/mipsread.c. */
2017 if (fdr_ptr
->rss
== -1)
2019 *filename_ptr
= NULL
;
2021 *functionname_ptr
= NULL
;
2026 (*debug_swap
->swap_ext_in
)
2028 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2029 + pdr
.isym
* debug_swap
->external_ext_size
),
2031 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2032 + proc_ext
.asym
.iss
);
2039 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2042 (*debug_swap
->swap_sym_in
)
2044 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2045 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2047 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2051 if (lineno
== ilineNil
)
2053 *retline_ptr
= lineno
;
2057 /* We can't use the generic linking routines for ECOFF, because we
2058 have to handle all the debugging information. The generic link
2059 routine just works out the section contents and attaches a list of
2062 We link by looping over all the seclets. We make two passes. On
2063 the first we set the actual section contents and determine the size
2064 of the debugging information. On the second we accumulate the
2065 debugging information and write it out.
2067 This currently always accumulates the debugging information, which
2068 is incorrect, because it ignores the -s and -S options of the
2069 linker. The linker needs to be modified to give us that
2070 information in a more useful format (currently it just provides a
2071 list of symbols which should appear in the output file). */
2073 /* Clear the output_has_begun flag for all the input BFD's. We use it
2074 to avoid linking in the debugging information for a BFD more than
2078 ecoff_clear_output_flags (abfd
)
2081 register asection
*o
;
2082 register bfd_seclet_type
*p
;
2084 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2085 for (p
= o
->seclets_head
;
2086 p
!= (bfd_seclet_type
*) NULL
;
2088 if (p
->type
== bfd_indirect_seclet
)
2089 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2092 /* Handle an indirect seclet on the first pass. Set the contents of
2093 the output section, and accumulate the debugging information if
2097 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
2099 bfd_seclet_type
*seclet
;
2100 asection
*output_section
;
2102 boolean relocateable
;
2105 HDRR
*output_symhdr
;
2108 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2109 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2110 && (output_section
->flags
& SEC_LOAD
)
2113 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2117 if (bfd_set_section_contents (output_bfd
,
2128 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2130 /* We want to figure out how much space will be required to
2131 incorporate all the debugging information from input_bfd. We use
2132 the output_has_begun field to avoid adding it in more than once.
2133 The actual incorporation is done in the second pass, in
2134 ecoff_get_debug. The code has to parallel that code in its
2135 manipulations of output_symhdr. */
2137 if (input_bfd
->output_has_begun
)
2139 input_bfd
->output_has_begun
= true;
2141 output_symhdr
= &ecoff_data (output_bfd
)->debug_info
.symbolic_header
;
2143 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2149 /* We just accumulate local symbols from a non-ECOFF BFD. The
2150 external symbols are handled separately. */
2152 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2153 get_symtab_upper_bound (input_bfd
));
2154 if (symbols
== (asymbol
**) NULL
)
2156 bfd_error
= no_memory
;
2159 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2161 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2165 len
= strlen ((*sym_ptr
)->name
);
2166 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2168 ++output_symhdr
->isymMax
;
2169 output_symhdr
->issMax
+= len
+ 1;
2173 bfd_release (output_bfd
, (PTR
) symbols
);
2175 ++output_symhdr
->ifdMax
;
2180 /* We simply add in the information from another ECOFF BFD. First
2181 we make sure we have the symbolic information. */
2182 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2184 if (bfd_get_symcount (input_bfd
) == 0)
2187 input_symhdr
= &ecoff_data (input_bfd
)->debug_info
.symbolic_header
;
2189 /* Figure out how much information we are going to be putting in.
2190 The external symbols are handled separately. */
2191 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2192 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2193 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2194 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2195 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2196 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2197 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2198 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2199 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2201 /* The RFD's are special, since we create them if needed. */
2202 if (input_symhdr
->crfd
> 0)
2203 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2205 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2210 /* Handle an arbitrary seclet on the first pass. */
2213 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2215 bfd_seclet_type
*seclet
;
2218 boolean relocateable
;
2220 switch (seclet
->type
)
2222 case bfd_indirect_seclet
:
2223 /* The contents of this section come from another one somewhere
2225 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2227 case bfd_fill_seclet
:
2228 /* Fill in the section with fill.value. This is used to pad out
2229 sections, but we must avoid padding the .bss section. */
2230 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2232 if (seclet
->u
.fill
.value
!= 0)
2237 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2241 for (i
= 0; i
< seclet
->size
; i
+=2)
2242 d
[i
] = seclet
->u
.fill
.value
>> 8;
2243 for (i
= 1; i
< seclet
->size
; i
+=2)
2244 d
[i
] = seclet
->u
.fill
.value
;
2245 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2247 bfd_release (abfd
, (PTR
) d
);
2259 /* Add a string to the debugging information we are accumulating for a
2260 file. Return the offset from the fdr string base or from the
2261 external string base. */
2264 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2274 symhdr
= &ecoff_data (output_bfd
)->debug_info
.symbolic_header
;
2275 len
= strlen (string
);
2278 strcpy (ecoff_data (output_bfd
)->debug_info
.ssext
+ symhdr
->issExtMax
,
2280 ret
= symhdr
->issExtMax
;
2281 symhdr
->issExtMax
+= len
+ 1;
2285 strcpy (ecoff_data (output_bfd
)->debug_info
.ss
+ symhdr
->issMax
, string
);
2287 symhdr
->issMax
+= len
+ 1;
2288 fdr
->cbSs
+= len
+ 1;
2293 /* Accumulate the debugging information from an input section. */
2296 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2298 bfd_seclet_type
*seclet
;
2300 boolean relocateable
;
2302 const struct ecoff_debug_swap
* const debug_swap
2303 = &ecoff_backend (output_bfd
)->debug_swap
;
2304 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
2305 const bfd_size_type external_pdr_size
= debug_swap
->external_pdr_size
;
2306 const bfd_size_type external_fdr_size
= debug_swap
->external_fdr_size
;
2307 const bfd_size_type external_rfd_size
= debug_swap
->external_rfd_size
;
2308 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2309 = debug_swap
->swap_sym_in
;
2310 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2311 = debug_swap
->swap_sym_out
;
2312 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2313 = debug_swap
->swap_pdr_in
;
2314 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
2315 = debug_swap
->swap_fdr_out
;
2316 void (* const swap_rfd_out
) PARAMS ((bfd
*, const RFDT
*, PTR
))
2317 = debug_swap
->swap_rfd_out
;
2319 HDRR
*output_symhdr
;
2321 ecoff_data_type
*output_ecoff
;
2322 ecoff_data_type
*input_ecoff
;
2325 ecoff_symbol_type
*esym_ptr
;
2326 ecoff_symbol_type
*esym_end
;
2331 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2333 /* Don't get the information more than once. */
2334 if (input_bfd
->output_has_begun
)
2336 input_bfd
->output_has_begun
= true;
2338 output_ecoff
= ecoff_data (output_bfd
);
2339 output_symhdr
= &output_ecoff
->debug_info
.symbolic_header
;
2341 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2348 /* This is not an ECOFF BFD. Just gather the symbols. */
2350 memset (&fdr
, 0, sizeof fdr
);
2352 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2353 fdr
.issBase
= output_symhdr
->issMax
;
2355 fdr
.rss
= ecoff_add_string (output_bfd
,
2357 bfd_get_filename (input_bfd
),
2359 fdr
.isymBase
= output_symhdr
->isymMax
;
2361 /* Get the local symbols from the input BFD. */
2362 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2363 get_symtab_upper_bound (input_bfd
));
2364 if (symbols
== (asymbol
**) NULL
)
2366 bfd_error
= no_memory
;
2369 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2371 /* Handle the local symbols. Any external symbols are handled
2374 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2378 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2380 memset (&internal_sym
, 0, sizeof internal_sym
);
2381 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2386 if (bfd_is_com_section ((*sym_ptr
)->section
)
2387 || (*sym_ptr
)->section
== &bfd_und_section
)
2388 internal_sym
.value
= (*sym_ptr
)->value
;
2390 internal_sym
.value
= ((*sym_ptr
)->value
2391 + (*sym_ptr
)->section
->output_offset
2392 + (*sym_ptr
)->section
->output_section
->vma
);
2393 internal_sym
.st
= stNil
;
2394 internal_sym
.sc
= scUndefined
;
2395 internal_sym
.index
= indexNil
;
2396 (*swap_sym_out
) (output_bfd
, &internal_sym
,
2397 ((char *) output_ecoff
->debug_info
.external_sym
2398 + output_symhdr
->isymMax
* external_sym_size
));
2400 ++output_symhdr
->isymMax
;
2403 bfd_release (output_bfd
, (PTR
) symbols
);
2405 /* Leave everything else in the FDR zeroed out. This will cause
2406 the lang field to be langC. The fBigendian field will
2407 indicate little endian format, but it doesn't matter because
2408 it only applies to aux fields and there are none. */
2410 (*swap_fdr_out
) (output_bfd
, &fdr
,
2411 ((char *) output_ecoff
->debug_info
.external_fdr
2412 + output_symhdr
->ifdMax
* external_fdr_size
));
2413 ++output_symhdr
->ifdMax
;
2417 /* This is an ECOFF BFD. We want to grab the information from
2418 input_bfd and attach it to output_bfd. */
2419 count
= bfd_get_symcount (input_bfd
);
2422 input_ecoff
= ecoff_data (input_bfd
);
2423 input_symhdr
= &input_ecoff
->debug_info
.symbolic_header
;
2425 /* I think that it is more efficient to simply copy the debugging
2426 information from the input BFD to the output BFD. Because ECOFF
2427 uses relative pointers for most of the debugging information,
2428 only a little of it has to be changed at all. */
2430 /* Swap in the local symbols, adjust their values, and swap them out
2431 again. The external symbols are handled separately. */
2432 sym_out
= ((char *) output_ecoff
->debug_info
.external_sym
2433 + output_symhdr
->isymMax
* external_sym_size
);
2435 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2436 esym_end
= esym_ptr
+ count
;
2437 for (; esym_ptr
< esym_end
; esym_ptr
++)
2439 if (esym_ptr
->local
)
2443 (*swap_sym_in
) (input_bfd
, esym_ptr
->native
, &sym
);
2445 /* If we're producing an executable, move common symbols
2447 if (relocateable
== false)
2449 if (sym
.sc
== scCommon
)
2451 else if (sym
.sc
== scSCommon
)
2455 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2456 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2457 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2458 sym
.value
= (esym_ptr
->symbol
.value
2459 + esym_ptr
->symbol
.section
->output_offset
2460 + esym_ptr
->symbol
.section
->output_section
->vma
);
2461 (*swap_sym_out
) (output_bfd
, &sym
, sym_out
);
2462 sym_out
+= external_sym_size
;
2466 /* That should have accounted for all the local symbols in
2469 /* Copy the information that does not need swapping. */
2470 memcpy (output_ecoff
->debug_info
.line
+ output_symhdr
->cbLine
,
2471 input_ecoff
->debug_info
.line
,
2472 input_symhdr
->cbLine
* sizeof (unsigned char));
2473 memcpy (output_ecoff
->debug_info
.external_aux
+ output_symhdr
->iauxMax
,
2474 input_ecoff
->debug_info
.external_aux
,
2475 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2476 memcpy (output_ecoff
->debug_info
.ss
+ output_symhdr
->issMax
,
2477 input_ecoff
->debug_info
.ss
,
2478 input_symhdr
->issMax
* sizeof (char));
2480 /* Some of the information may need to be swapped. */
2481 if (output_bfd
->xvec
->header_byteorder_big_p
2482 == input_bfd
->xvec
->header_byteorder_big_p
)
2484 /* The two BFD's have the same endianness, so memcpy will
2486 if (input_symhdr
->idnMax
> 0)
2487 memcpy (((char *) output_ecoff
->debug_info
.external_dnr
2488 + output_symhdr
->idnMax
* debug_swap
->external_dnr_size
),
2489 input_ecoff
->debug_info
.external_dnr
,
2490 input_symhdr
->idnMax
* debug_swap
->external_dnr_size
);
2491 if (input_symhdr
->ipdMax
> 0)
2492 memcpy (((char *) output_ecoff
->debug_info
.external_pdr
2493 + output_symhdr
->ipdMax
* external_pdr_size
),
2494 input_ecoff
->debug_info
.external_pdr
,
2495 input_symhdr
->ipdMax
* external_pdr_size
);
2496 if (input_symhdr
->ioptMax
> 0)
2497 memcpy (((char *) output_ecoff
->debug_info
.external_opt
2498 + output_symhdr
->ioptMax
* debug_swap
->external_opt_size
),
2499 input_ecoff
->debug_info
.external_opt
,
2500 input_symhdr
->ioptMax
* debug_swap
->external_opt_size
);
2509 /* The two BFD's have different endianness, so we must swap
2510 everything in and out. This code would always work, but it
2511 would be slow in the normal case. */
2512 sz
= debug_swap
->external_dnr_size
;
2513 in
= (char *) input_ecoff
->debug_info
.external_dnr
;
2514 end
= in
+ input_symhdr
->idnMax
* sz
;
2515 out
= ((char *) output_ecoff
->debug_info
.external_dnr
2516 + output_symhdr
->idnMax
* sz
);
2517 for (; in
< end
; in
+= sz
, out
+= sz
)
2521 (*debug_swap
->swap_dnr_in
) (input_bfd
, in
, &dnr
);
2522 (*debug_swap
->swap_dnr_out
) (output_bfd
, &dnr
, out
);
2525 sz
= external_pdr_size
;
2526 in
= (char *) input_ecoff
->debug_info
.external_pdr
;
2527 end
= in
+ input_symhdr
->ipdMax
* sz
;
2528 out
= ((char *) output_ecoff
->debug_info
.external_pdr
2529 + output_symhdr
->ipdMax
* sz
);
2530 for (; in
< end
; in
+= sz
, out
+= sz
)
2534 (*swap_pdr_in
) (input_bfd
, in
, &pdr
);
2535 (*debug_swap
->swap_pdr_out
) (output_bfd
, &pdr
, out
);
2538 sz
= debug_swap
->external_opt_size
;
2539 in
= (char *) input_ecoff
->debug_info
.external_opt
;
2540 end
= in
+ input_symhdr
->ioptMax
* sz
;
2541 out
= ((char *) output_ecoff
->debug_info
.external_opt
2542 + output_symhdr
->ioptMax
* sz
);
2543 for (; in
< end
; in
+= sz
, out
+= sz
)
2547 (*debug_swap
->swap_opt_in
) (input_bfd
, in
, &opt
);
2548 (*debug_swap
->swap_opt_out
) (output_bfd
, &opt
, out
);
2552 /* Set ifdbase so that the external symbols know how to adjust their
2554 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2556 fdr_ptr
= input_ecoff
->debug_info
.fdr
;
2557 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2558 fdr_out
= ((char *) output_ecoff
->debug_info
.external_fdr
2559 + output_symhdr
->ifdMax
* external_fdr_size
);
2560 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
+= external_fdr_size
)
2563 unsigned long pdr_off
;
2567 /* The memory address for this fdr is the address for the seclet
2568 plus the offset to this fdr within input_bfd. For some
2569 reason the offset of the first procedure pointer is also
2577 (*swap_pdr_in
) (input_bfd
,
2578 ((char *) input_ecoff
->debug_info
.external_pdr
2579 + fdr
.ipdFirst
* external_pdr_size
),
2583 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2585 + (fdr_ptr
->adr
- input_ecoff
->debug_info
.fdr
->adr
)
2588 fdr
.issBase
+= output_symhdr
->issMax
;
2589 fdr
.isymBase
+= output_symhdr
->isymMax
;
2590 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2591 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2592 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2593 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2594 fdr
.rfdBase
+= output_symhdr
->crfd
;
2596 /* If there are no RFD's, we are going to add some. We don't
2597 want to adjust irfd for this, so that all the FDR's can share
2599 if (input_symhdr
->crfd
== 0)
2600 fdr
.crfd
= input_symhdr
->ifdMax
;
2602 if (fdr
.cbLine
!= 0)
2603 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2605 (*swap_fdr_out
) (output_bfd
, &fdr
, fdr_out
);
2608 if (input_symhdr
->crfd
> 0)
2610 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2611 = debug_swap
->swap_rfd_in
;
2616 /* Swap and adjust the RFD's. RFD's are only created by the
2617 linker, so this will only be necessary if one of the input
2618 files is the result of a partial link. Presumably all
2619 necessary RFD's are present. */
2620 rfd_in
= (char *) input_ecoff
->debug_info
.external_rfd
;
2621 rfd_end
= rfd_in
+ input_symhdr
->crfd
* external_rfd_size
;
2622 rfd_out
= ((char *) output_ecoff
->debug_info
.external_rfd
2623 + output_symhdr
->crfd
* external_rfd_size
);
2626 rfd_in
+= external_rfd_size
, rfd_out
+= external_rfd_size
)
2630 (*swap_rfd_in
) (input_bfd
, rfd_in
, &rfd
);
2631 rfd
+= output_symhdr
->ifdMax
;
2632 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2634 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2642 /* Create RFD's. Some of the debugging information includes
2643 relative file indices. These indices are taken as indices to
2644 the RFD table if there is one, or to the global table if
2645 there is not. If we did not create RFD's, we would have to
2646 parse and adjust all the debugging information which contains
2648 rfd
= output_symhdr
->ifdMax
;
2649 rfd_out
= ((char *) output_ecoff
->debug_info
.external_rfd
2650 + output_symhdr
->crfd
* external_rfd_size
);
2651 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
* external_rfd_size
;
2652 for (; rfd_out
< rfd_end
; rfd_out
+= external_rfd_size
, rfd
++)
2653 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2654 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2657 /* Combine the register masks. Not all of these are used on all
2658 targets, but that's OK because only the relevant ones will be
2659 swapped in and out. */
2663 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2664 output_ecoff
->fprmask
|= input_ecoff
->fprmask
;
2665 for (i
= 0; i
< 4; i
++)
2666 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2669 /* Update the counts. */
2670 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2671 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2672 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2673 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2674 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2675 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2676 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2677 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2678 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2683 /* This is the actual link routine. It makes two passes over all the
2687 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2690 boolean relocateable
;
2692 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2695 register asection
*o
;
2696 register bfd_seclet_type
*p
;
2697 asymbol
**sym_ptr_ptr
;
2698 bfd_size_type debug_align
, aux_align
;
2702 /* We accumulate the debugging information counts in the symbolic
2704 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
2705 symhdr
->magic
= backend
->debug_swap
.sym_magic
;
2706 /* FIXME: What should the version stamp be? */
2708 symhdr
->ilineMax
= 0;
2712 symhdr
->isymMax
= 0;
2713 symhdr
->ioptMax
= 0;
2714 symhdr
->iauxMax
= 0;
2716 symhdr
->issExtMax
= 0;
2719 symhdr
->iextMax
= 0;
2721 /* We need to copy over the debugging symbols from each input BFD.
2722 When we do this copying, we have to adjust the text address in
2723 the FDR structures, so we have to know the text address used for
2724 the input BFD. Since we only want to copy the symbols once per
2725 input BFD, but we are going to look at each input BFD multiple
2726 times (once for each section it provides), we arrange to always
2727 look at the text section first. That means that when we copy the
2728 debugging information, we always know the text address. So we
2729 actually do each pass in two sub passes; first the text sections,
2730 then the non-text sections. We use the output_has_begun flag to
2731 determine whether we have copied over the debugging information
2734 /* Do the first pass: set the output section contents and count the
2735 debugging information. */
2736 ecoff_clear_output_flags (abfd
);
2737 for (ipass
= 0; ipass
< 2; ipass
++)
2739 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2741 /* If this is a fake section, just forget it. The register
2742 information is handled in another way. */
2743 if (strcmp (o
->name
, SCOMMON
) == 0
2744 || strcmp (o
->name
, REGINFO
) == 0)
2747 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2748 so they are done on pass 0. For other sections the
2749 expression is true, so they are done on pass 1. */
2750 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2753 for (p
= o
->seclets_head
;
2754 p
!= (bfd_seclet_type
*) NULL
;
2757 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2764 /* We handle the external symbols differently. We use the ones
2765 attached to the output_bfd. The linker will have already
2766 determined which symbols are to be attached. Here we just
2767 determine how much space we will need for them. */
2768 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2769 if (sym_ptr_ptr
!= NULL
)
2773 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2774 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2776 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2777 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2780 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2785 /* Adjust the counts so that structures are aligned. */
2786 debug_align
= backend
->debug_swap
.debug_align
;
2787 aux_align
= debug_align
/ sizeof (union aux_ext
);
2790 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2791 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2792 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2793 symhdr
->iauxMax
= (symhdr
->iauxMax
+ aux_align
) &~ aux_align
;
2795 /* Now the counts in symhdr are the correct size for the debugging
2796 information. We allocate the right amount of space, and reset
2797 the counts so that the second pass can use them as indices. It
2798 would be possible to output the debugging information directly to
2799 the file in pass 2, rather than to build it in memory and then
2800 write it out. Outputting to the file would require a lot of
2801 seeks and small writes, though, and I think this approach is
2803 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2804 + symhdr
->idnMax
* backend
->debug_swap
.external_dnr_size
2805 + symhdr
->ipdMax
* backend
->debug_swap
.external_pdr_size
2806 + symhdr
->isymMax
* backend
->debug_swap
.external_sym_size
2807 + symhdr
->ioptMax
* backend
->debug_swap
.external_opt_size
2808 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2809 + symhdr
->issMax
* sizeof (char)
2810 + symhdr
->issExtMax
* sizeof (char)
2811 + symhdr
->ifdMax
* backend
->debug_swap
.external_fdr_size
2812 + symhdr
->crfd
* backend
->debug_swap
.external_rfd_size
2813 + symhdr
->iextMax
* backend
->debug_swap
.external_ext_size
);
2814 raw
= (char *) bfd_alloc (abfd
, size
);
2815 if (raw
== (char *) NULL
)
2817 bfd_error
= no_memory
;
2820 ecoff_data (abfd
)->raw_size
= size
;
2821 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2823 /* Initialize the raw pointers. */
2824 #define SET(field, count, type, size) \
2825 ecoff_data (abfd)->debug_info.field = (type) raw; \
2826 raw += symhdr->count * size
2828 SET (line
, cbLine
, unsigned char *, sizeof (unsigned char));
2829 SET (external_dnr
, idnMax
, PTR
, backend
->debug_swap
.external_dnr_size
);
2830 SET (external_pdr
, ipdMax
, PTR
, backend
->debug_swap
.external_pdr_size
);
2831 SET (external_sym
, isymMax
, PTR
, backend
->debug_swap
.external_sym_size
);
2832 SET (external_opt
, ioptMax
, PTR
, backend
->debug_swap
.external_opt_size
);
2833 SET (external_aux
, iauxMax
, union aux_ext
*, sizeof (union aux_ext
));
2834 SET (ss
, issMax
, char *, sizeof (char));
2835 SET (ssext
, issExtMax
, char *, sizeof (char));
2836 SET (external_fdr
, ifdMax
, PTR
, backend
->debug_swap
.external_fdr_size
);
2837 SET (external_rfd
, crfd
, PTR
, backend
->debug_swap
.external_rfd_size
);
2838 SET (external_ext
, iextMax
, PTR
, backend
->debug_swap
.external_ext_size
);
2841 /* Reset the counts so the second pass can use them to know how far
2843 symhdr
->ilineMax
= 0;
2847 symhdr
->isymMax
= 0;
2848 symhdr
->ioptMax
= 0;
2849 symhdr
->iauxMax
= 0;
2851 symhdr
->issExtMax
= 0;
2854 symhdr
->iextMax
= 0;
2856 /* Do the second pass: accumulate the debugging information. */
2857 ecoff_clear_output_flags (abfd
);
2858 for (ipass
= 0; ipass
< 2; ipass
++)
2860 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2862 if (strcmp (o
->name
, SCOMMON
) == 0
2863 || strcmp (o
->name
, REGINFO
) == 0)
2865 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2867 for (p
= o
->seclets_head
;
2868 p
!= (bfd_seclet_type
*) NULL
;
2871 if (p
->type
== bfd_indirect_seclet
)
2873 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
2880 /* Put in the external symbols. */
2881 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2882 if (sym_ptr_ptr
!= NULL
)
2884 const bfd_size_type external_ext_size
2885 = backend
->debug_swap
.external_ext_size
;
2886 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
2887 = backend
->debug_swap
.swap_ext_in
;
2888 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
2889 = backend
->debug_swap
.swap_ext_out
;
2893 ssext
= ecoff_data (abfd
)->debug_info
.ssext
;
2894 external_ext
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
2895 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2900 sym_ptr
= *sym_ptr_ptr
;
2902 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2903 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2906 /* The native pointer can be NULL for a symbol created by
2907 the linker via ecoff_make_empty_symbol. */
2908 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2909 || ecoffsymbol (sym_ptr
)->native
== NULL
)
2912 esym
.cobol_main
= 0;
2916 /* FIXME: we can do better than this for st and sc. */
2917 esym
.asym
.st
= stGlobal
;
2918 esym
.asym
.sc
= scAbs
;
2919 esym
.asym
.reserved
= 0;
2920 esym
.asym
.index
= indexNil
;
2924 ecoff_symbol_type
*ecoff_sym_ptr
;
2926 ecoff_sym_ptr
= ecoffsymbol (sym_ptr
);
2927 if (ecoff_sym_ptr
->local
)
2929 (*swap_ext_in
) (abfd
, ecoff_sym_ptr
->native
, &esym
);
2931 /* If we're producing an executable, move common symbols
2933 if (relocateable
== false)
2935 if (esym
.asym
.sc
== scCommon
)
2936 esym
.asym
.sc
= scBss
;
2937 else if (esym
.asym
.sc
== scSCommon
)
2938 esym
.asym
.sc
= scSBss
;
2941 /* Adjust the FDR index for the symbol by that used for
2943 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2946 esym
.asym
.iss
= symhdr
->issExtMax
;
2948 if (bfd_is_com_section (sym_ptr
->section
)
2949 || sym_ptr
->section
== &bfd_und_section
)
2950 esym
.asym
.value
= sym_ptr
->value
;
2952 esym
.asym
.value
= (sym_ptr
->value
2953 + sym_ptr
->section
->output_offset
2954 + sym_ptr
->section
->output_section
->vma
);
2956 (*swap_ext_out
) (abfd
, &esym
, external_ext
);
2958 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2960 external_ext
+= external_ext_size
;
2963 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2964 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2968 /* Adjust the counts so that structures are aligned. */
2969 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2970 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2971 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2972 symhdr
->iauxMax
= (symhdr
->iauxMax
+ aux_align
) &~ aux_align
;
2977 /* Set the architecture. The supported architecture is stored in the
2978 backend pointer. We always set the architecture anyhow, since many
2979 callers ignore the return value. */
2982 ecoff_set_arch_mach (abfd
, arch
, machine
)
2984 enum bfd_architecture arch
;
2985 unsigned long machine
;
2987 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2988 return arch
== ecoff_backend (abfd
)->arch
;
2991 /* Get the size of the section headers. We do not output the .scommon
2992 section which we created in ecoff_mkobject, nor do we output any
2993 .reginfo section. */
2996 ecoff_sizeof_headers (abfd
, reloc
)
3004 for (current
= abfd
->sections
;
3005 current
!= (asection
*)NULL
;
3006 current
= current
->next
)
3007 if (strcmp (current
->name
, SCOMMON
) != 0
3008 && strcmp (current
->name
, REGINFO
) != 0)
3011 return (bfd_coff_filhsz (abfd
)
3012 + bfd_coff_aoutsz (abfd
)
3013 + c
* bfd_coff_scnhsz (abfd
));
3016 /* Get the contents of a section. This is where we handle reading the
3017 .reginfo section, which implicitly holds the contents of an
3018 ecoff_reginfo structure. */
3021 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
3026 bfd_size_type count
;
3028 ecoff_data_type
*tdata
= ecoff_data (abfd
);
3029 struct ecoff_reginfo s
;
3032 if (strcmp (section
->name
, REGINFO
) != 0)
3033 return bfd_generic_get_section_contents (abfd
, section
, location
,
3036 s
.gp_value
= tdata
->gp
;
3037 s
.gprmask
= tdata
->gprmask
;
3038 for (i
= 0; i
< 4; i
++)
3039 s
.cprmask
[i
] = tdata
->cprmask
[i
];
3040 s
.fprmask
= tdata
->fprmask
;
3042 /* bfd_get_section_contents has already checked that the offset and
3043 size is reasonable. We don't have to worry about swapping or any
3044 such thing; the .reginfo section is defined such that the
3045 contents are an ecoff_reginfo structure as seen on the host. */
3046 memcpy (location
, ((char *) &s
) + offset
, count
);
3050 /* Calculate the file position for each section, and set
3054 ecoff_compute_section_file_positions (abfd
)
3062 if (bfd_get_start_address (abfd
))
3063 abfd
->flags
|= EXEC_P
;
3065 sofar
= ecoff_sizeof_headers (abfd
, false);
3068 for (current
= abfd
->sections
;
3069 current
!= (asection
*) NULL
;
3070 current
= current
->next
)
3072 /* Only deal with sections which have contents */
3073 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
3074 || strcmp (current
->name
, SCOMMON
) == 0
3075 || strcmp (current
->name
, REGINFO
) == 0)
3078 /* On Ultrix, the data sections in an executable file must be
3079 aligned to a page boundary within the file. This does not
3080 affect the section size, though. FIXME: Does this work for
3081 other platforms? It requires some modification for the
3082 Alpha, because .rdata on the Alpha goes with the text, not
3084 if ((abfd
->flags
& EXEC_P
) != 0
3085 && (abfd
->flags
& D_PAGED
) != 0
3086 && first_data
!= false
3087 && (current
->flags
& SEC_CODE
) == 0
3088 && (! ecoff_backend (abfd
)->rdata_in_text
3089 || strcmp (current
->name
, _RDATA
) != 0)
3090 && strcmp (current
->name
, _PDATA
) != 0)
3092 const bfd_vma round
= ecoff_backend (abfd
)->round
;
3094 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
3098 /* Align the sections in the file to the same boundary on
3099 which they are aligned in virtual memory. */
3101 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3103 current
->filepos
= sofar
;
3105 sofar
+= current
->_raw_size
;
3107 /* make sure that this section is of the right size too */
3109 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3110 current
->_raw_size
+= sofar
- old_sofar
;
3113 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3116 /* Set the contents of a section. This is where we handle setting the
3117 contents of the .reginfo section, which implicitly holds a
3118 ecoff_reginfo structure. */
3121 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
3126 bfd_size_type count
;
3128 if (abfd
->output_has_begun
== false)
3129 ecoff_compute_section_file_positions (abfd
);
3131 if (strcmp (section
->name
, REGINFO
) == 0)
3133 ecoff_data_type
*tdata
= ecoff_data (abfd
);
3134 struct ecoff_reginfo s
;
3137 /* If the caller is only changing part of the structure, we must
3138 retrieve the current information before the memcpy. */
3139 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
3141 s
.gp_value
= tdata
->gp
;
3142 s
.gprmask
= tdata
->gprmask
;
3143 for (i
= 0; i
< 4; i
++)
3144 s
.cprmask
[i
] = tdata
->cprmask
[i
];
3145 s
.fprmask
= tdata
->fprmask
;
3148 /* bfd_set_section_contents has already checked that the offset
3149 and size is reasonable. We don't have to worry about
3150 swapping or any such thing; the .reginfo section is defined
3151 such that the contents are an ecoff_reginfo structure as seen
3153 memcpy (((char *) &s
) + offset
, location
, count
);
3155 tdata
->gp
= s
.gp_value
;
3156 tdata
->gprmask
= s
.gprmask
;
3157 for (i
= 0; i
< 4; i
++)
3158 tdata
->cprmask
[i
] = s
.cprmask
[i
];
3159 tdata
->fprmask
= s
.fprmask
;
3165 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3168 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3173 /* Write out an ECOFF file. */
3176 ecoff_write_object_contents (abfd
)
3179 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3180 const bfd_vma round
= backend
->round
;
3181 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
3182 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
3183 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
3184 const bfd_size_type external_hdr_size
3185 = backend
->debug_swap
.external_hdr_size
;
3186 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
3187 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
3189 struct internal_reloc
*))
3190 = backend
->adjust_reloc_out
;
3191 void (* const swap_reloc_out
) PARAMS ((bfd
*,
3192 const struct internal_reloc
*,
3194 = backend
->swap_reloc_out
;
3198 file_ptr reloc_base
;
3200 unsigned long reloc_size
;
3201 unsigned long text_size
;
3202 unsigned long text_start
;
3203 unsigned long data_size
;
3204 unsigned long data_start
;
3205 unsigned long bss_size
;
3207 struct internal_filehdr internal_f
;
3208 struct internal_aouthdr internal_a
;
3211 bfd_error
= system_call_error
;
3213 if(abfd
->output_has_begun
== false)
3214 ecoff_compute_section_file_positions(abfd
);
3216 if (abfd
->sections
!= (asection
*) NULL
)
3217 scn_base
= abfd
->sections
->filepos
;
3220 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3224 for (current
= abfd
->sections
;
3225 current
!= (asection
*)NULL
;
3226 current
= current
->next
)
3228 if (strcmp (current
->name
, SCOMMON
) == 0
3229 || strcmp (current
->name
, REGINFO
) == 0)
3231 current
->target_index
= count
;
3233 if (current
->reloc_count
!= 0)
3235 bfd_size_type relsize
;
3237 current
->rel_filepos
= reloc_base
;
3238 relsize
= current
->reloc_count
* external_reloc_size
;
3239 reloc_size
+= relsize
;
3240 reloc_base
+= relsize
;
3243 current
->rel_filepos
= 0;
3246 sym_base
= reloc_base
+ reloc_size
;
3248 /* At least on Ultrix, the symbol table of an executable file must
3249 be aligned to a page boundary. FIXME: Is this true on other
3251 if ((abfd
->flags
& EXEC_P
) != 0
3252 && (abfd
->flags
& D_PAGED
) != 0)
3253 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
3255 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3257 if ((abfd
->flags
& D_PAGED
) != 0)
3258 text_size
= ecoff_sizeof_headers (abfd
, false);
3266 /* Write section headers to the file. */
3268 buff
= (PTR
) alloca (scnhsz
);
3269 internal_f
.f_nscns
= 0;
3270 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
3272 for (current
= abfd
->sections
;
3273 current
!= (asection
*) NULL
;
3274 current
= current
->next
)
3276 struct internal_scnhdr section
;
3279 if (strcmp (current
->name
, SCOMMON
) == 0)
3281 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3282 && current
->reloc_count
== 0);
3285 if (strcmp (current
->name
, REGINFO
) == 0)
3287 BFD_ASSERT (current
->reloc_count
== 0);
3291 ++internal_f
.f_nscns
;
3293 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3295 /* FIXME: is this correct for shared libraries? I think it is
3296 but I have no platform to check. Ian Lance Taylor. */
3297 vma
= bfd_get_section_vma (abfd
, current
);
3298 if (strcmp (current
->name
, _LIB
) == 0)
3299 section
.s_vaddr
= 0;
3301 section
.s_vaddr
= vma
;
3303 section
.s_paddr
= vma
;
3304 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3306 /* If this section is unloadable then the scnptr will be 0. */
3307 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3308 section
.s_scnptr
= 0;
3310 section
.s_scnptr
= current
->filepos
;
3311 section
.s_relptr
= current
->rel_filepos
;
3313 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3314 object file produced by the assembler is supposed to point to
3315 information about how much room is required by objects of
3316 various different sizes. I think this only matters if we
3317 want the linker to compute the best size to use, or
3318 something. I don't know what happens if the information is
3320 section
.s_lnnoptr
= 0;
3322 section
.s_nreloc
= current
->reloc_count
;
3323 section
.s_nlnno
= 0;
3324 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3327 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
3328 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
3331 /* FIXME: On the Alpha .rdata is in the text segment. For MIPS
3332 it is in the .data segment. We guess here as to where it
3333 should go based on the vma, but the choice should be made
3334 more systematically. */
3335 if ((section
.s_flags
& STYP_TEXT
) != 0
3336 || ((section
.s_flags
& STYP_RDATA
) != 0
3337 && backend
->rdata_in_text
)
3338 || strcmp (current
->name
, _PDATA
) == 0)
3340 text_size
+= bfd_get_section_size_before_reloc (current
);
3341 if (text_start
== 0 || text_start
> vma
)
3344 else if ((section
.s_flags
& STYP_RDATA
) != 0
3345 || (section
.s_flags
& STYP_DATA
) != 0
3346 || (section
.s_flags
& STYP_LITA
) != 0
3347 || (section
.s_flags
& STYP_LIT8
) != 0
3348 || (section
.s_flags
& STYP_LIT4
) != 0
3349 || (section
.s_flags
& STYP_SDATA
) != 0)
3351 data_size
+= bfd_get_section_size_before_reloc (current
);
3352 if (data_start
== 0 || data_start
> vma
)
3355 else if ((section
.s_flags
& STYP_BSS
) != 0
3356 || (section
.s_flags
& STYP_SBSS
) != 0)
3357 bss_size
+= bfd_get_section_size_before_reloc (current
);
3360 /* Set up the file header. */
3362 internal_f
.f_magic
= ecoff_get_magic (abfd
);
3364 /* We will NOT put a fucking timestamp in the header here. Every
3365 time you put it back, I will come in and take it out again. I'm
3366 sorry. This field does not belong here. We fill it with a 0 so
3367 it compares the same but is not a reasonable time. --
3369 internal_f
.f_timdat
= 0;
3371 if (bfd_get_symcount (abfd
) != 0)
3373 /* The ECOFF f_nsyms field is not actually the number of
3374 symbols, it's the size of symbolic information header. */
3375 internal_f
.f_nsyms
= external_hdr_size
;
3376 internal_f
.f_symptr
= sym_base
;
3380 internal_f
.f_nsyms
= 0;
3381 internal_f
.f_symptr
= 0;
3384 internal_f
.f_opthdr
= aoutsz
;
3386 internal_f
.f_flags
= F_LNNO
;
3387 if (reloc_size
== 0)
3388 internal_f
.f_flags
|= F_RELFLG
;
3389 if (bfd_get_symcount (abfd
) == 0)
3390 internal_f
.f_flags
|= F_LSYMS
;
3391 if (abfd
->flags
& EXEC_P
)
3392 internal_f
.f_flags
|= F_EXEC
;
3394 if (! abfd
->xvec
->byteorder_big_p
)
3395 internal_f
.f_flags
|= F_AR32WR
;
3397 internal_f
.f_flags
|= F_AR32W
;
3399 /* Set up the ``optional'' header. */
3400 if ((abfd
->flags
& D_PAGED
) != 0)
3401 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
3403 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
3405 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3406 linker happy. But, is it right? */
3407 internal_a
.vstamp
= 0x20a;
3409 /* At least on Ultrix, these have to be rounded to page boundaries.
3410 FIXME: Is this true on other platforms? */
3411 if ((abfd
->flags
& D_PAGED
) != 0)
3413 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
3414 internal_a
.text_start
= text_start
&~ (round
- 1);
3415 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
3416 internal_a
.data_start
= data_start
&~ (round
- 1);
3420 internal_a
.tsize
= text_size
;
3421 internal_a
.text_start
= text_start
;
3422 internal_a
.dsize
= data_size
;
3423 internal_a
.data_start
= data_start
;
3426 /* On Ultrix, the initial portions of the .sbss and .bss segments
3427 are at the end of the data section. The bsize field in the
3428 optional header records how many bss bytes are required beyond
3429 those in the data section. The value is not rounded to a page
3431 if (bss_size
< internal_a
.dsize
- data_size
)
3434 bss_size
-= internal_a
.dsize
- data_size
;
3435 internal_a
.bsize
= bss_size
;
3436 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3438 internal_a
.entry
= bfd_get_start_address (abfd
);
3440 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3442 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3443 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
3444 for (i
= 0; i
< 4; i
++)
3445 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3447 /* Write out the file header and the optional header. */
3449 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3452 buff
= (PTR
) alloca (filhsz
);
3453 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
3454 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
3457 buff
= (PTR
) alloca (aoutsz
);
3458 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
3459 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
3462 /* Write out the relocs. */
3463 for (current
= abfd
->sections
;
3464 current
!= (asection
*) NULL
;
3465 current
= current
->next
)
3467 arelent
**reloc_ptr_ptr
;
3468 arelent
**reloc_end
;
3471 if (current
->reloc_count
== 0)
3474 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
3477 bfd_error
= no_memory
;
3481 reloc_ptr_ptr
= current
->orelocation
;
3482 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3483 out_ptr
= (char *) buff
;
3485 reloc_ptr_ptr
< reloc_end
;
3486 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
3490 struct internal_reloc in
;
3492 memset (&in
, 0, sizeof in
);
3494 reloc
= *reloc_ptr_ptr
;
3495 sym
= *reloc
->sym_ptr_ptr
;
3497 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3498 in
.r_type
= reloc
->howto
->type
;
3500 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3502 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3509 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3510 if (strcmp (name
, ".text") == 0)
3511 in
.r_symndx
= RELOC_SECTION_TEXT
;
3512 else if (strcmp (name
, ".rdata") == 0)
3513 in
.r_symndx
= RELOC_SECTION_RDATA
;
3514 else if (strcmp (name
, ".data") == 0)
3515 in
.r_symndx
= RELOC_SECTION_DATA
;
3516 else if (strcmp (name
, ".sdata") == 0)
3517 in
.r_symndx
= RELOC_SECTION_SDATA
;
3518 else if (strcmp (name
, ".sbss") == 0)
3519 in
.r_symndx
= RELOC_SECTION_SBSS
;
3520 else if (strcmp (name
, ".bss") == 0)
3521 in
.r_symndx
= RELOC_SECTION_BSS
;
3522 else if (strcmp (name
, ".init") == 0)
3523 in
.r_symndx
= RELOC_SECTION_INIT
;
3524 else if (strcmp (name
, ".lit8") == 0)
3525 in
.r_symndx
= RELOC_SECTION_LIT8
;
3526 else if (strcmp (name
, ".lit4") == 0)
3527 in
.r_symndx
= RELOC_SECTION_LIT4
;
3528 else if (strcmp (name
, ".xdata") == 0)
3529 in
.r_symndx
= RELOC_SECTION_XDATA
;
3530 else if (strcmp (name
, ".pdata") == 0)
3531 in
.r_symndx
= RELOC_SECTION_PDATA
;
3532 else if (strcmp (name
, ".fini") == 0)
3533 in
.r_symndx
= RELOC_SECTION_FINI
;
3534 else if (strcmp (name
, ".lita") == 0)
3535 in
.r_symndx
= RELOC_SECTION_LITA
;
3536 else if (strcmp (name
, "*ABS*") == 0)
3537 in
.r_symndx
= RELOC_SECTION_ABS
;
3543 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
3545 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3548 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3550 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
3551 != external_reloc_size
* current
->reloc_count
)
3553 bfd_release (abfd
, buff
);
3556 /* Write out the symbolic debugging information. */
3557 if (bfd_get_symcount (abfd
) > 0)
3560 unsigned long sym_offset
;
3562 /* Set up the offsets in the symbolic header. */
3563 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3564 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
3566 #define SET(offset, size, ptr) \
3567 if (symhdr->size == 0) \
3568 symhdr->offset = 0; \
3570 symhdr->offset = (((char *) ecoff_data (abfd)->debug_info.ptr \
3571 - (char *) ecoff_data (abfd)->raw_syments) \
3574 SET (cbLineOffset
, cbLine
, line
);
3575 SET (cbDnOffset
, idnMax
, external_dnr
);
3576 SET (cbPdOffset
, ipdMax
, external_pdr
);
3577 SET (cbSymOffset
, isymMax
, external_sym
);
3578 SET (cbOptOffset
, ioptMax
, external_opt
);
3579 SET (cbAuxOffset
, iauxMax
, external_aux
);
3580 SET (cbSsOffset
, issMax
, ss
);
3581 SET (cbSsExtOffset
, issExtMax
, ssext
);
3582 SET (cbFdOffset
, ifdMax
, external_fdr
);
3583 SET (cbRfdOffset
, crfd
, external_rfd
);
3584 SET (cbExtOffset
, iextMax
, external_ext
);
3587 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3590 buff
= (PTR
) alloca (external_hdr_size
);
3591 (*backend
->debug_swap
.swap_hdr_out
)
3592 (abfd
, &ecoff_data (abfd
)->debug_info
.symbolic_header
, buff
);
3593 if (bfd_write (buff
, 1, external_hdr_size
, abfd
) != external_hdr_size
)
3595 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3596 ecoff_data (abfd
)->raw_size
, abfd
)
3597 != ecoff_data (abfd
)->raw_size
)
3600 else if ((abfd
->flags
& EXEC_P
) != 0
3601 && (abfd
->flags
& D_PAGED
) != 0)
3605 /* A demand paged executable must occupy an even number of
3607 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3610 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3612 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3615 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3622 /* Archive handling. ECOFF uses what appears to be a unique type of
3623 archive header (which I call an armap). The byte ordering of the
3624 armap and the contents are encoded in the name of the armap itself.
3625 At least for now, we only support archives with the same byte
3626 ordering in the armap and the contents.
3628 The first four bytes in the armap are the number of symbol
3629 definitions. This is always a power of two.
3631 This is followed by the symbol definitions. Each symbol definition
3632 occupies 8 bytes. The first four bytes are the offset from the
3633 start of the armap strings to the null-terminated string naming
3634 this symbol. The second four bytes are the file offset to the
3635 archive member which defines this symbol. If the second four bytes
3636 are 0, then this is not actually a symbol definition, and it should
3639 The symbols are hashed into the armap with a closed hashing scheme.
3640 See the functions below for the details of the algorithm.
3642 We could use the hash table when looking up symbols in a library.
3643 This would require a new BFD target entry point to replace the
3644 bfd_get_next_mapent function used by the linker.
3646 After the symbol definitions comes four bytes holding the size of
3647 the string table, followed by the string table itself. */
3649 /* The name of an archive headers looks like this:
3650 __________E[BL]E[BL]_ (with a trailing space).
3651 The trailing space is changed to an X if the archive is changed to
3652 indicate that the armap is out of date.
3654 The Alpha seems to use ________64E[BL]E[BL]_. */
3656 #define ARMAP_BIG_ENDIAN 'B'
3657 #define ARMAP_LITTLE_ENDIAN 'L'
3658 #define ARMAP_MARKER 'E'
3659 #define ARMAP_START_LENGTH 10
3660 #define ARMAP_HEADER_MARKER_INDEX 10
3661 #define ARMAP_HEADER_ENDIAN_INDEX 11
3662 #define ARMAP_OBJECT_MARKER_INDEX 12
3663 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3664 #define ARMAP_END_INDEX 14
3665 #define ARMAP_END "_ "
3667 /* This is a magic number used in the hashing algorithm. */
3668 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3670 /* This returns the hash value to use for a string. It also sets
3671 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3672 is the number of entries in the hash table, and HLOG is the log
3676 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3678 unsigned int *rehash
;
3686 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3687 hash
*= ARMAP_HASH_MAGIC
;
3688 *rehash
= (hash
& (size
- 1)) | 1;
3689 return hash
>> (32 - hlog
);
3692 /* Read in the armap. */
3695 ecoff_slurp_armap (abfd
)
3700 struct areltdata
*mapdata
;
3701 bfd_size_type parsed_size
;
3703 struct artdata
*ardata
;
3706 struct symdef
*symdef_ptr
;
3709 /* Get the name of the first element. */
3710 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3716 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3718 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3719 standard COFF armap. We could move the ECOFF armap stuff into
3720 bfd_slurp_armap, but that seems inappropriate since no other
3721 target uses this format. Instead, we check directly for a COFF
3723 if (strncmp (nextname
, "/ ", 16) == 0)
3724 return bfd_slurp_armap (abfd
);
3726 /* See if the first element is an armap. */
3727 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3728 ARMAP_START_LENGTH
) != 0
3729 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3730 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3731 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3732 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3733 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3734 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3735 || strncmp (nextname
+ ARMAP_END_INDEX
,
3736 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3738 bfd_has_map (abfd
) = false;
3742 /* Make sure we have the right byte ordering. */
3743 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3744 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3745 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3746 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3748 bfd_error
= wrong_format
;
3752 /* Read in the armap. */
3753 ardata
= bfd_ardata (abfd
);
3754 mapdata
= snarf_ar_hdr (abfd
);
3755 if (mapdata
== (struct areltdata
*) NULL
)
3757 parsed_size
= mapdata
->parsed_size
;
3758 bfd_release (abfd
, (PTR
) mapdata
);
3760 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3761 if (raw_armap
== (char *) NULL
)
3763 bfd_error
= no_memory
;
3767 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3769 bfd_error
= malformed_archive
;
3770 bfd_release (abfd
, (PTR
) raw_armap
);
3774 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3776 ardata
->symdef_count
= 0;
3777 ardata
->cache
= (struct ar_cache
*) NULL
;
3779 /* This code used to overlay the symdefs over the raw archive data,
3780 but that doesn't work on a 64 bit host. */
3782 stringbase
= raw_armap
+ count
* 8 + 8;
3784 #ifdef CHECK_ARMAP_HASH
3788 /* Double check that I have the hashing algorithm right by making
3789 sure that every symbol can be looked up successfully. */
3791 for (i
= 1; i
< count
; i
<<= 1)
3793 BFD_ASSERT (i
== count
);
3795 raw_ptr
= raw_armap
+ 4;
3796 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3798 unsigned int name_offset
, file_offset
;
3799 unsigned int hash
, rehash
, srch
;
3801 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3802 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3803 if (file_offset
== 0)
3805 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3810 /* See if we can rehash to this location. */
3811 for (srch
= (hash
+ rehash
) & (count
- 1);
3812 srch
!= hash
&& srch
!= i
;
3813 srch
= (srch
+ rehash
) & (count
- 1))
3814 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3816 BFD_ASSERT (srch
== i
);
3820 #endif /* CHECK_ARMAP_HASH */
3822 raw_ptr
= raw_armap
+ 4;
3823 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3824 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3825 ++ardata
->symdef_count
;
3827 symdef_ptr
= ((struct symdef
*)
3829 ardata
->symdef_count
* sizeof (struct symdef
)));
3830 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3832 raw_ptr
= raw_armap
+ 4;
3833 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3835 unsigned int name_offset
, file_offset
;
3837 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3838 if (file_offset
== 0)
3840 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3841 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3842 symdef_ptr
->file_offset
= file_offset
;
3846 ardata
->first_file_filepos
= bfd_tell (abfd
);
3847 /* Pad to an even boundary. */
3848 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3850 bfd_has_map (abfd
) = true;
3855 /* Write out an armap. */
3858 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3860 unsigned int elength
;
3862 unsigned int orl_count
;
3865 unsigned int hashsize
, hashlog
;
3866 unsigned int symdefsize
;
3868 unsigned int stringsize
;
3869 unsigned int mapsize
;
3872 struct stat statbuf
;
3875 bfd_byte
*hashtable
;
3879 /* Ultrix appears to use as a hash table size the least power of two
3880 greater than twice the number of entries. */
3881 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3883 hashsize
= 1 << hashlog
;
3885 symdefsize
= hashsize
* 8;
3887 stringsize
= stridx
+ padit
;
3889 /* Include 8 bytes to store symdefsize and stringsize in output. */
3890 mapsize
= symdefsize
+ stringsize
+ 8;
3892 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3894 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3896 /* Work out the ECOFF armap name. */
3897 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3898 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3899 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3900 (abfd
->xvec
->header_byteorder_big_p
3902 : ARMAP_LITTLE_ENDIAN
);
3903 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3904 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3905 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3906 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3908 /* Write the timestamp of the archive header to be just a little bit
3909 later than the timestamp of the file, otherwise the linker will
3910 complain that the index is out of date. Actually, the Ultrix
3911 linker just checks the archive name; the GNU linker may check the
3913 stat (abfd
->filename
, &statbuf
);
3914 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3916 /* The DECstation uses zeroes for the uid, gid and mode of the
3918 hdr
.ar_uid
[0] = '0';
3919 hdr
.ar_gid
[0] = '0';
3920 hdr
.ar_mode
[0] = '0';
3922 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3924 hdr
.ar_fmag
[0] = '`';
3925 hdr
.ar_fmag
[1] = '\n';
3927 /* Turn all null bytes in the header into spaces. */
3928 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3929 if (((char *)(&hdr
))[i
] == '\0')
3930 (((char *)(&hdr
))[i
]) = ' ';
3932 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3933 != sizeof (struct ar_hdr
))
3936 bfd_h_put_32 (abfd
, hashsize
, temp
);
3937 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3940 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3942 current
= abfd
->archive_head
;
3944 for (i
= 0; i
< orl_count
; i
++)
3946 unsigned int hash
, rehash
;
3948 /* Advance firstreal to the file position of this archive
3950 if (((bfd
*) map
[i
].pos
) != last_elt
)
3954 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3955 firstreal
+= firstreal
% 2;
3956 current
= current
->next
;
3958 while (current
!= (bfd
*) map
[i
].pos
);
3963 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3964 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3968 /* The desired slot is already taken. */
3969 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3971 srch
= (srch
+ rehash
) & (hashsize
- 1))
3972 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3975 BFD_ASSERT (srch
!= hash
);
3980 bfd_h_put_32 (abfd
, map
[i
].namidx
, (PTR
) (hashtable
+ hash
* 8));
3981 bfd_h_put_32 (abfd
, firstreal
, (PTR
) (hashtable
+ hash
* 8 + 4));
3984 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3987 bfd_release (abfd
, hashtable
);
3989 /* Now write the strings. */
3990 bfd_h_put_32 (abfd
, stringsize
, temp
);
3991 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3993 for (i
= 0; i
< orl_count
; i
++)
3997 len
= strlen (*map
[i
].name
) + 1;
3998 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
4002 /* The spec sez this should be a newline. But in order to be
4003 bug-compatible for DECstation ar we use a null. */
4006 if (bfd_write ("\0", 1, 1, abfd
) != 1)
4013 /* See whether this BFD is an archive. If it is, read in the armap
4014 and the extended name table. */
4017 ecoff_archive_p (abfd
)
4020 char armag
[SARMAG
+ 1];
4022 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
4023 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
4025 bfd_error
= wrong_format
;
4026 return (bfd_target
*) NULL
;
4029 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
4030 involves a cast, we can't do it as the left operand of
4032 abfd
->tdata
.aout_ar_data
=
4033 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
4035 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
4037 bfd_error
= no_memory
;
4038 return (bfd_target
*) NULL
;
4041 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
4043 if (ecoff_slurp_armap (abfd
) == false
4044 || ecoff_slurp_extended_name_table (abfd
) == false)
4046 bfd_release (abfd
, bfd_ardata (abfd
));
4047 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
4048 return (bfd_target
*) NULL
;