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
, _LIT8
) == 0)
314 else if (strcmp (name
, _LIT4
) == 0)
316 else if (strcmp (name
, _BSS
) == 0)
318 else if (strcmp (name
, _SBSS
) == 0)
320 else if (strcmp (name
, _INIT
) == 0)
321 styp
= STYP_ECOFF_INIT
;
322 else if (strcmp (name
, _FINI
) == 0)
323 styp
= STYP_ECOFF_FINI
;
324 else if (flags
& SEC_CODE
)
326 else if (flags
& SEC_DATA
)
328 else if (flags
& SEC_READONLY
)
330 else if (flags
& SEC_LOAD
)
335 if (flags
& SEC_NEVER_LOAD
)
341 /* Get the BFD flags to use for a section. */
344 ecoff_styp_to_sec_flags (abfd
, hdr
)
348 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
349 long styp_flags
= internal_s
->s_flags
;
350 flagword sec_flags
=0;
352 if (styp_flags
& STYP_NOLOAD
)
353 sec_flags
|= SEC_NEVER_LOAD
;
355 /* For 386 COFF, at least, an unloadable text or data section is
356 actually a shared library section. */
357 if ((styp_flags
& STYP_TEXT
)
358 || (styp_flags
& STYP_ECOFF_INIT
)
359 || (styp_flags
& STYP_ECOFF_FINI
))
361 if (sec_flags
& SEC_NEVER_LOAD
)
362 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
364 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
366 else if ((styp_flags
& STYP_DATA
)
367 || (styp_flags
& STYP_RDATA
)
368 || (styp_flags
& STYP_SDATA
))
370 if (sec_flags
& SEC_NEVER_LOAD
)
371 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
373 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
374 if (styp_flags
& STYP_RDATA
)
375 sec_flags
|= SEC_READONLY
;
377 else if ((styp_flags
& STYP_BSS
)
378 || (styp_flags
& STYP_SBSS
))
380 sec_flags
|= SEC_ALLOC
;
382 else if (styp_flags
& STYP_INFO
)
384 sec_flags
|= SEC_NEVER_LOAD
;
386 else if ((styp_flags
& STYP_LIT8
)
387 || (styp_flags
& STYP_LIT4
))
389 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
393 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
399 /* Routines to swap auxiliary information in and out. I am assuming
400 that the auxiliary information format is always going to be target
403 /* Swap in a type information record.
404 BIGEND says whether AUX symbols are big-endian or little-endian; this
405 info comes from the file header record (fh-fBigendian). */
408 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
410 struct tir_ext
*ext_copy
;
413 struct tir_ext ext
[1];
415 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
417 /* now the fun stuff... */
419 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
420 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
421 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
422 >> TIR_BITS1_BT_SH_BIG
;
423 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
424 >> TIR_BITS_TQ4_SH_BIG
;
425 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
426 >> TIR_BITS_TQ5_SH_BIG
;
427 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
428 >> TIR_BITS_TQ0_SH_BIG
;
429 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
430 >> TIR_BITS_TQ1_SH_BIG
;
431 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
432 >> TIR_BITS_TQ2_SH_BIG
;
433 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
434 >> TIR_BITS_TQ3_SH_BIG
;
436 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
437 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
438 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
439 >> TIR_BITS1_BT_SH_LITTLE
;
440 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
441 >> TIR_BITS_TQ4_SH_LITTLE
;
442 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
443 >> TIR_BITS_TQ5_SH_LITTLE
;
444 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
445 >> TIR_BITS_TQ0_SH_LITTLE
;
446 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
447 >> TIR_BITS_TQ1_SH_LITTLE
;
448 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
449 >> TIR_BITS_TQ2_SH_LITTLE
;
450 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
451 >> TIR_BITS_TQ3_SH_LITTLE
;
455 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
460 /* Swap out a type information record.
461 BIGEND says whether AUX symbols are big-endian or little-endian; this
462 info comes from the file header record (fh-fBigendian). */
465 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
472 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
474 /* now the fun stuff... */
476 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
477 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
478 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
479 & TIR_BITS1_BT_BIG
));
480 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
482 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
483 & TIR_BITS_TQ5_BIG
));
484 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
486 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
487 & TIR_BITS_TQ1_BIG
));
488 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
490 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
491 & TIR_BITS_TQ3_BIG
));
493 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
494 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
495 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
496 & TIR_BITS1_BT_LITTLE
));
497 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
498 & TIR_BITS_TQ4_LITTLE
)
499 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
500 & TIR_BITS_TQ5_LITTLE
));
501 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
502 & TIR_BITS_TQ0_LITTLE
)
503 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
504 & TIR_BITS_TQ1_LITTLE
));
505 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
506 & TIR_BITS_TQ2_LITTLE
)
507 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
508 & TIR_BITS_TQ3_LITTLE
));
512 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
517 /* Swap in a relative symbol record. BIGEND says whether it is in
518 big-endian or little-endian format.*/
521 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
523 struct rndx_ext
*ext_copy
;
526 struct rndx_ext ext
[1];
528 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
530 /* now the fun stuff... */
532 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
533 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
534 >> RNDX_BITS1_RFD_SH_BIG
);
535 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
536 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
537 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
538 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
540 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
541 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
542 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
543 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
544 >> RNDX_BITS1_INDEX_SH_LITTLE
)
545 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
546 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
550 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
555 /* Swap out a relative symbol record. BIGEND says whether it is in
556 big-endian or little-endian format.*/
559 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
562 struct rndx_ext
*ext
;
566 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
568 /* now the fun stuff... */
570 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
571 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
572 & RNDX_BITS1_RFD_BIG
)
573 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
574 & RNDX_BITS1_INDEX_BIG
));
575 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
576 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
578 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
579 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
580 & RNDX_BITS1_RFD_LITTLE
)
581 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
582 & RNDX_BITS1_INDEX_LITTLE
));
583 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
584 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
588 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
593 /* Read in and swap the important symbolic information for an ECOFF
594 object file. This is called by gdb. */
597 ecoff_slurp_symbolic_info (abfd
)
600 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
601 bfd_size_type external_hdr_size
;
602 HDRR
*internal_symhdr
;
603 bfd_size_type raw_base
;
604 bfd_size_type raw_size
;
606 bfd_size_type external_fdr_size
;
610 bfd_size_type raw_end
;
611 bfd_size_type cb_end
;
613 /* Check whether we've already gotten it, and whether there's any to
615 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
617 if (ecoff_data (abfd
)->sym_filepos
== 0)
619 bfd_get_symcount (abfd
) = 0;
623 /* At this point bfd_get_symcount (abfd) holds the number of symbols
624 as read from the file header, but on ECOFF this is always the
625 size of the symbolic information header. It would be cleaner to
626 handle this when we first read the file in coffgen.c. */
627 external_hdr_size
= backend
->external_hdr_size
;
628 if (bfd_get_symcount (abfd
) != external_hdr_size
)
630 bfd_error
= bad_value
;
634 /* Read the symbolic information header. */
635 raw
= (PTR
) alloca (external_hdr_size
);
636 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
637 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
638 != external_hdr_size
))
640 bfd_error
= system_call_error
;
643 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
644 (*backend
->swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
646 if (internal_symhdr
->magic
!= backend
->sym_magic
)
648 bfd_error
= bad_value
;
652 /* Now we can get the correct number of symbols. */
653 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
654 + internal_symhdr
->iextMax
);
656 /* Read all the symbolic information at once. */
657 raw_base
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
659 /* Alpha ecoff makes the determination of raw_size difficult. It has
660 an undocumented debug data section between the symhdr and the first
661 documented section. And the ordering of the sections varies between
662 statically and dynamically linked executables.
663 If bfd supports SEEK_END someday, this code could be simplified. */
667 #define UPDATE_RAW_END(start, count, size) \
668 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
669 if (cb_end > raw_end) \
672 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
673 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->external_dnr_size
);
674 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->external_pdr_size
);
675 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->external_sym_size
);
676 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->external_opt_size
);
677 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
678 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
679 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
680 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->external_fdr_size
);
681 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->external_rfd_size
);
682 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->external_ext_size
);
684 #undef UPDATE_RAW_END
686 raw_size
= raw_end
- raw_base
;
689 ecoff_data (abfd
)->sym_filepos
= 0;
692 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
695 bfd_error
= no_memory
;
698 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
700 bfd_error
= system_call_error
;
701 bfd_release (abfd
, raw
);
705 ecoff_data (abfd
)->raw_size
= raw_size
;
706 ecoff_data (abfd
)->raw_syments
= raw
;
708 /* Get pointers for the numeric offsets in the HDRR structure. */
709 #define FIX(off1, off2, type) \
710 if (internal_symhdr->off1 == 0) \
711 ecoff_data (abfd)->off2 = (type) NULL; \
713 ecoff_data (abfd)->off2 = (type) ((char *) raw \
714 + internal_symhdr->off1 \
716 FIX (cbLineOffset
, line
, unsigned char *);
717 FIX (cbDnOffset
, external_dnr
, PTR
);
718 FIX (cbPdOffset
, external_pdr
, PTR
);
719 FIX (cbSymOffset
, external_sym
, PTR
);
720 FIX (cbOptOffset
, external_opt
, PTR
);
721 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
722 FIX (cbSsOffset
, ss
, char *);
723 FIX (cbSsExtOffset
, ssext
, char *);
724 FIX (cbFdOffset
, external_fdr
, PTR
);
725 FIX (cbRfdOffset
, external_rfd
, PTR
);
726 FIX (cbExtOffset
, external_ext
, PTR
);
729 /* I don't want to always swap all the data, because it will just
730 waste time and most programs will never look at it. The only
731 time the linker needs most of the debugging information swapped
732 is when linking big-endian and little-endian MIPS object files
733 together, which is not a common occurrence.
735 We need to look at the fdr to deal with a lot of information in
736 the symbols, so we swap them here. */
737 ecoff_data (abfd
)->fdr
=
738 (struct fdr
*) bfd_alloc (abfd
,
739 (internal_symhdr
->ifdMax
*
740 sizeof (struct fdr
)));
741 if (ecoff_data (abfd
)->fdr
== NULL
)
743 bfd_error
= no_memory
;
746 external_fdr_size
= backend
->external_fdr_size
;
747 fdr_ptr
= ecoff_data (abfd
)->fdr
;
748 fraw_src
= (char *) ecoff_data (abfd
)->external_fdr
;
749 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
750 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
751 (*backend
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
756 /* ECOFF symbol table routines. The ECOFF symbol table is described
757 in gcc/mips-tfile.c. */
759 /* ECOFF uses two common sections. One is the usual one, and the
760 other is for small objects. All the small objects are kept
761 together, and then referenced via the gp pointer, which yields
762 faster assembler code. This is what we use for the small common
764 static asection ecoff_scom_section
;
765 static asymbol ecoff_scom_symbol
;
766 static asymbol
*ecoff_scom_symbol_ptr
;
768 /* Create an empty symbol. */
771 ecoff_make_empty_symbol (abfd
)
774 ecoff_symbol_type
*new;
776 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
777 if (new == (ecoff_symbol_type
*) NULL
)
779 bfd_error
= no_memory
;
780 return (asymbol
*) NULL
;
782 memset (new, 0, sizeof *new);
783 new->symbol
.section
= (asection
*) NULL
;
784 new->fdr
= (FDR
*) NULL
;
787 new->symbol
.the_bfd
= abfd
;
791 /* Set the BFD flags and section for an ECOFF symbol. */
794 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
799 asymbol
**indirect_ptr_ptr
;
801 asym
->the_bfd
= abfd
;
802 asym
->value
= ecoff_sym
->value
;
803 asym
->section
= &bfd_debug_section
;
806 /* An indirect symbol requires two consecutive stabs symbols. */
807 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
809 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
811 /* @@ Stuffing pointers into integers is a no-no.
812 We can usually get away with it if the integer is
813 large enough though. */
814 if (sizeof (asym
) > sizeof (bfd_vma
))
816 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
818 asym
->flags
= BSF_DEBUGGING
;
819 asym
->section
= &bfd_und_section
;
820 *indirect_ptr_ptr
= NULL
;
824 if (ECOFF_IS_STAB (ecoff_sym
)
825 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
827 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
828 asym
->section
= &bfd_ind_section
;
829 /* Pass this symbol on to the next call to this function. */
830 *indirect_ptr_ptr
= asym
;
834 /* Most symbol types are just for debugging. */
835 switch (ecoff_sym
->st
)
844 if (ECOFF_IS_STAB (ecoff_sym
))
846 asym
->flags
= BSF_DEBUGGING
;
851 asym
->flags
= BSF_DEBUGGING
;
856 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
858 asym
->flags
= BSF_LOCAL
;
859 switch (ecoff_sym
->sc
)
862 /* Used for compiler generated labels. Leave them in the
863 debugging section, and mark them as local. If BSF_DEBUGGING
864 is set, then nm does not display them for some reason. If no
865 flags are set then the linker whines about them. */
866 asym
->flags
= BSF_LOCAL
;
869 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
870 asym
->value
-= asym
->section
->vma
;
873 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
874 asym
->value
-= asym
->section
->vma
;
877 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
878 asym
->value
-= asym
->section
->vma
;
881 asym
->flags
= BSF_DEBUGGING
;
884 asym
->section
= &bfd_abs_section
;
887 asym
->section
= &bfd_und_section
;
897 asym
->flags
= BSF_DEBUGGING
;
900 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
901 asym
->value
-= asym
->section
->vma
;
904 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
905 asym
->value
-= asym
->section
->vma
;
908 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
909 asym
->value
-= asym
->section
->vma
;
912 asym
->flags
= BSF_DEBUGGING
;
915 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
917 asym
->section
= &bfd_com_section
;
923 if (ecoff_scom_section
.name
== NULL
)
925 /* Initialize the small common section. */
926 ecoff_scom_section
.name
= SCOMMON
;
927 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
928 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
929 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
930 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
931 ecoff_scom_symbol
.name
= SCOMMON
;
932 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
933 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
934 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
936 asym
->section
= &ecoff_scom_section
;
941 asym
->flags
= BSF_DEBUGGING
;
944 asym
->section
= &bfd_und_section
;
949 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
950 asym
->value
-= asym
->section
->vma
;
955 asym
->flags
= BSF_DEBUGGING
;
958 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
959 asym
->value
-= asym
->section
->vma
;
965 /* Look for special constructors symbols and make relocation entries
966 in a special construction section. These are produced by the
967 -fgnu-linker argument to g++. */
968 if (ECOFF_IS_STAB (ecoff_sym
))
970 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
982 arelent_chain
*reloc_chain
;
983 unsigned int bitsize
;
985 /* Get a section with the same name as the symbol (usually
986 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
987 name ___CTOR_LIST (three underscores). We need
988 __CTOR_LIST (two underscores), since ECOFF doesn't use
989 a leading underscore. This should be handled by gcc,
990 but instead we do it here. Actually, this should all
991 be done differently anyhow. */
992 name
= bfd_asymbol_name (asym
);
993 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
998 section
= bfd_get_section_by_name (abfd
, name
);
999 if (section
== (asection
*) NULL
)
1003 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1004 strcpy (copy
, name
);
1005 section
= bfd_make_section (abfd
, copy
);
1008 /* Build a reloc pointing to this constructor. */
1010 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1011 reloc_chain
->relent
.sym_ptr_ptr
=
1012 bfd_get_section (asym
)->symbol_ptr_ptr
;
1013 reloc_chain
->relent
.address
= section
->_raw_size
;
1014 reloc_chain
->relent
.addend
= asym
->value
;
1015 reloc_chain
->relent
.howto
=
1016 ecoff_backend (abfd
)->constructor_reloc
;
1018 /* Set up the constructor section to hold the reloc. */
1019 section
->flags
= SEC_CONSTRUCTOR
;
1020 ++section
->reloc_count
;
1022 /* Constructor sections must be rounded to a boundary
1023 based on the bitsize. These are not real sections--
1024 they are handled specially by the linker--so the ECOFF
1025 16 byte alignment restriction does not apply. */
1026 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1027 section
->alignment_power
= 1;
1028 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1029 ++section
->alignment_power
;
1031 reloc_chain
->next
= section
->constructor_chain
;
1032 section
->constructor_chain
= reloc_chain
;
1033 section
->_raw_size
+= bitsize
/ 8;
1035 /* Mark the symbol as a constructor. */
1036 asym
->flags
|= BSF_CONSTRUCTOR
;
1043 /* Read an ECOFF symbol table. */
1046 ecoff_slurp_symbol_table (abfd
)
1049 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1050 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
1051 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
1052 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1053 = backend
->swap_ext_in
;
1054 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1055 = backend
->swap_sym_in
;
1056 bfd_size_type internal_size
;
1057 ecoff_symbol_type
*internal
;
1058 ecoff_symbol_type
*internal_ptr
;
1059 asymbol
*indirect_ptr
;
1065 /* If we've already read in the symbol table, do nothing. */
1066 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1069 /* Get the symbolic information. */
1070 if (ecoff_slurp_symbolic_info (abfd
) == false)
1072 if (bfd_get_symcount (abfd
) == 0)
1075 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1076 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1077 if (internal
== NULL
)
1079 bfd_error
= no_memory
;
1083 internal_ptr
= internal
;
1084 indirect_ptr
= NULL
;
1085 eraw_src
= (char *) ecoff_data (abfd
)->external_ext
;
1086 eraw_end
= (eraw_src
1087 + (ecoff_data (abfd
)->symbolic_header
.iextMax
1088 * external_ext_size
));
1089 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1093 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1094 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
1095 + internal_esym
.asym
.iss
);
1096 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1097 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1098 /* The alpha uses a negative ifd field for section symbols. */
1099 if (internal_esym
.ifd
>= 0)
1100 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
1102 internal_ptr
->fdr
= NULL
;
1103 internal_ptr
->local
= false;
1104 internal_ptr
->native
= (PTR
) eraw_src
;
1106 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1108 /* The local symbols must be accessed via the fdr's, because the
1109 string and aux indices are relative to the fdr information. */
1110 fdr_ptr
= ecoff_data (abfd
)->fdr
;
1111 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1112 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1117 lraw_src
= ((char *) ecoff_data (abfd
)->external_sym
1118 + fdr_ptr
->isymBase
* external_sym_size
);
1119 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1121 lraw_src
< lraw_end
;
1122 lraw_src
+= external_sym_size
, internal_ptr
++)
1126 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1127 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
1129 + internal_sym
.iss
);
1130 ecoff_set_symbol_info (abfd
, &internal_sym
,
1131 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1132 internal_ptr
->fdr
= fdr_ptr
;
1133 internal_ptr
->local
= true;
1134 internal_ptr
->native
= (PTR
) lraw_src
;
1137 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1139 ecoff_data (abfd
)->canonical_symbols
= internal
;
1144 /* Return the amount of space needed for the canonical symbols. */
1147 ecoff_get_symtab_upper_bound (abfd
)
1150 if (ecoff_slurp_symbolic_info (abfd
) == false
1151 || bfd_get_symcount (abfd
) == 0)
1154 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1157 /* Get the canonicals symbols. */
1160 ecoff_get_symtab (abfd
, alocation
)
1162 asymbol
**alocation
;
1164 unsigned int counter
= 0;
1165 ecoff_symbol_type
*symbase
;
1166 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1168 if (ecoff_slurp_symbol_table (abfd
) == false
1169 || bfd_get_symcount (abfd
) == 0)
1172 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1173 while (counter
< bfd_get_symcount (abfd
))
1175 *(location
++) = symbase
++;
1178 *location
++ = (ecoff_symbol_type
*) NULL
;
1179 return bfd_get_symcount (abfd
);
1182 /* Turn ECOFF type information into a printable string.
1183 ecoff_emit_aggregate and ecoff_type_to_string are from
1184 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1186 /* Write aggregate information to a string. */
1189 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1196 int ifd
= rndx
->rfd
;
1197 int indx
= rndx
->index
;
1198 int sym_base
, ss_base
;
1204 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
1205 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
1207 if (indx
== indexNil
)
1208 name
= "/* no name */";
1211 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1215 (*backend
->swap_sym_in
) (abfd
,
1216 ((char *) ecoff_data (abfd
)->external_sym
1217 + indx
* backend
->external_sym_size
),
1219 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
1223 "%s %s { ifd = %d, index = %d }",
1225 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
1228 /* Convert the type information to string format. */
1231 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1233 union aux_ext
*aux_ptr
;
1245 unsigned int basic_type
;
1247 static char buffer1
[1024];
1248 static char buffer2
[1024];
1253 for (i
= 0; i
< 7; i
++)
1255 qualifiers
[i
].low_bound
= 0;
1256 qualifiers
[i
].high_bound
= 0;
1257 qualifiers
[i
].stride
= 0;
1260 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1261 return "-1 (no type)";
1262 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1264 basic_type
= u
.ti
.bt
;
1265 qualifiers
[0].type
= u
.ti
.tq0
;
1266 qualifiers
[1].type
= u
.ti
.tq1
;
1267 qualifiers
[2].type
= u
.ti
.tq2
;
1268 qualifiers
[3].type
= u
.ti
.tq3
;
1269 qualifiers
[4].type
= u
.ti
.tq4
;
1270 qualifiers
[5].type
= u
.ti
.tq5
;
1271 qualifiers
[6].type
= tqNil
;
1274 * Go get the basic type.
1278 case btNil
: /* undefined */
1282 case btAdr
: /* address - integer same size as pointer */
1283 strcpy (p1
, "address");
1286 case btChar
: /* character */
1287 strcpy (p1
, "char");
1290 case btUChar
: /* unsigned character */
1291 strcpy (p1
, "unsigned char");
1294 case btShort
: /* short */
1295 strcpy (p1
, "short");
1298 case btUShort
: /* unsigned short */
1299 strcpy (p1
, "unsigned short");
1302 case btInt
: /* int */
1306 case btUInt
: /* unsigned int */
1307 strcpy (p1
, "unsigned int");
1310 case btLong
: /* long */
1311 strcpy (p1
, "long");
1314 case btULong
: /* unsigned long */
1315 strcpy (p1
, "unsigned long");
1318 case btFloat
: /* float (real) */
1319 strcpy (p1
, "float");
1322 case btDouble
: /* Double (real) */
1323 strcpy (p1
, "double");
1326 /* Structures add 1-2 aux words:
1327 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1328 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1330 case btStruct
: /* Structure (Record) */
1331 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1332 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1333 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1335 indx
++; /* skip aux words */
1338 /* Unions add 1-2 aux words:
1339 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1340 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1342 case btUnion
: /* Union */
1343 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1344 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1345 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1347 indx
++; /* skip aux words */
1350 /* Enumerations add 1-2 aux words:
1351 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1352 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1354 case btEnum
: /* Enumeration */
1355 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1356 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1357 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1359 indx
++; /* skip aux words */
1362 case btTypedef
: /* defined via a typedef, isymRef points */
1363 strcpy (p1
, "typedef");
1366 case btRange
: /* subrange of int */
1367 strcpy (p1
, "subrange");
1370 case btSet
: /* pascal sets */
1374 case btComplex
: /* fortran complex */
1375 strcpy (p1
, "complex");
1378 case btDComplex
: /* fortran double complex */
1379 strcpy (p1
, "double complex");
1382 case btIndirect
: /* forward or unnamed typedef */
1383 strcpy (p1
, "forward/unamed typedef");
1386 case btFixedDec
: /* Fixed Decimal */
1387 strcpy (p1
, "fixed decimal");
1390 case btFloatDec
: /* Float Decimal */
1391 strcpy (p1
, "float decimal");
1394 case btString
: /* Varying Length Character String */
1395 strcpy (p1
, "string");
1398 case btBit
: /* Aligned Bit String */
1402 case btPicture
: /* Picture */
1403 strcpy (p1
, "picture");
1406 case btVoid
: /* Void */
1407 strcpy (p1
, "void");
1411 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1415 p1
+= strlen (buffer1
);
1418 * If this is a bitfield, get the bitsize.
1424 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1425 sprintf (p1
, " : %d", bitsize
);
1426 p1
+= strlen (buffer1
);
1431 * Deal with any qualifiers.
1433 if (qualifiers
[0].type
!= tqNil
)
1436 * Snarf up any array bounds in the correct order. Arrays
1437 * store 5 successive words in the aux. table:
1438 * word 0 RNDXR to type of the bounds (ie, int)
1439 * word 1 Current file descriptor index
1441 * word 3 high bound (or -1 if [])
1442 * word 4 stride size in bits
1444 for (i
= 0; i
< 7; i
++)
1446 if (qualifiers
[i
].type
== tqArray
)
1448 qualifiers
[i
].low_bound
=
1449 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1450 qualifiers
[i
].high_bound
=
1451 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1452 qualifiers
[i
].stride
=
1453 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1459 * Now print out the qualifiers.
1461 for (i
= 0; i
< 6; i
++)
1463 switch (qualifiers
[i
].type
)
1470 strcpy (p2
, "ptr to ");
1471 p2
+= sizeof ("ptr to ")-1;
1475 strcpy (p2
, "volatile ");
1476 p2
+= sizeof ("volatile ")-1;
1480 strcpy (p2
, "far ");
1481 p2
+= sizeof ("far ")-1;
1485 strcpy (p2
, "func. ret. ");
1486 p2
+= sizeof ("func. ret. ");
1491 int first_array
= i
;
1494 /* Print array bounds reversed (ie, in the order the C
1495 programmer writes them). C is such a fun language.... */
1497 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1500 for (j
= i
; j
>= first_array
; j
--)
1502 strcpy (p2
, "array [");
1503 p2
+= sizeof ("array [")-1;
1504 if (qualifiers
[j
].low_bound
!= 0)
1506 "%ld:%ld {%ld bits}",
1507 (long) qualifiers
[j
].low_bound
,
1508 (long) qualifiers
[j
].high_bound
,
1509 (long) qualifiers
[j
].stride
);
1511 else if (qualifiers
[j
].high_bound
!= -1)
1514 (long) (qualifiers
[j
].high_bound
+ 1),
1515 (long) (qualifiers
[j
].stride
));
1518 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1521 strcpy (p2
, "] of ");
1522 p2
+= sizeof ("] of ")-1;
1530 strcpy (p2
, buffer1
);
1534 /* Return information about ECOFF symbol SYMBOL in RET. */
1537 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1538 bfd
*abfd
; /* Ignored. */
1542 bfd_symbol_info (symbol
, ret
);
1545 /* Print information about an ECOFF symbol. */
1548 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1552 bfd_print_symbol_type how
;
1554 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1555 FILE *file
= (FILE *)filep
;
1559 case bfd_print_symbol_name
:
1560 fprintf (file
, "%s", symbol
->name
);
1562 case bfd_print_symbol_more
:
1563 if (ecoffsymbol (symbol
)->local
)
1567 (*backend
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1569 fprintf (file
, "ecoff local ");
1570 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1571 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1572 (unsigned) ecoff_sym
.sc
);
1578 (*backend
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1580 fprintf (file
, "ecoff extern ");
1581 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1582 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1583 (unsigned) ecoff_ext
.asym
.sc
);
1586 case bfd_print_symbol_all
:
1587 /* Print out the symbols in a reasonable way */
1596 if (ecoffsymbol (symbol
)->local
)
1598 (*backend
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1601 pos
= ((((char *) ecoffsymbol (symbol
)->native
1602 - (char *) ecoff_data (abfd
)->external_sym
)
1603 / backend
->external_sym_size
)
1604 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1611 (*backend
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1614 pos
= (((char *) ecoffsymbol (symbol
)->native
1615 - (char *) ecoff_data (abfd
)->external_ext
)
1616 / backend
->external_ext_size
);
1617 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1618 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1619 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1622 fprintf (file
, "[%3d] %c ",
1624 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1625 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1626 (unsigned) ecoff_ext
.asym
.st
,
1627 (unsigned) ecoff_ext
.asym
.sc
,
1628 (unsigned) ecoff_ext
.asym
.index
,
1629 jmptbl
, cobol_main
, weakext
,
1632 if (ecoffsymbol (symbol
)->fdr
!= NULL
1633 && ecoff_ext
.asym
.index
!= indexNil
)
1637 bfd_size_type sym_base
;
1638 union aux_ext
*aux_base
;
1640 indx
= ecoff_ext
.asym
.index
;
1642 /* sym_base is used to map the fdr relative indices which
1643 appear in the file to the position number which we are
1645 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1646 if (ecoffsymbol (symbol
)->local
)
1647 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1649 /* aux_base is the start of the aux entries for this file;
1650 asym.index is an offset from this. */
1651 aux_base
= (ecoff_data (abfd
)->external_aux
1652 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1654 /* The aux entries are stored in host byte order; the
1655 order is indicated by a bit in the fdr. */
1656 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1658 /* This switch is basically from gcc/mips-tdump.c */
1659 switch (ecoff_ext
.asym
.st
)
1667 fprintf (file
, "\n End+1 symbol: %ld",
1668 (long) (indx
+ sym_base
));
1672 if (ecoff_ext
.asym
.sc
== scText
1673 || ecoff_ext
.asym
.sc
== scInfo
)
1674 fprintf (file
, "\n First symbol: %ld",
1675 (long) (indx
+ sym_base
));
1677 fprintf (file
, "\n First symbol: %ld",
1678 (long) (AUX_GET_ISYM (bigendian
,
1679 &aux_base
[ecoff_ext
.asym
.index
])
1685 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1687 else if (ecoffsymbol (symbol
)->local
)
1688 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1689 (long) (AUX_GET_ISYM (bigendian
,
1690 &aux_base
[ecoff_ext
.asym
.index
])
1692 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1695 fprintf (file
, "\n Local symbol: %d",
1698 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1702 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1703 fprintf (file
, "\n Type: %s",
1704 ecoff_type_to_string (abfd
, aux_base
, indx
,
1714 /* Read in the relocs for a section. */
1717 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1722 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1723 arelent
*internal_relocs
;
1724 bfd_size_type external_reloc_size
;
1725 bfd_size_type external_relocs_size
;
1726 char *external_relocs
;
1730 if (section
->relocation
!= (arelent
*) NULL
1731 || section
->reloc_count
== 0
1732 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1735 if (ecoff_slurp_symbol_table (abfd
) == false)
1738 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1740 * section
->reloc_count
));
1741 external_reloc_size
= backend
->external_reloc_size
;
1742 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1743 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1744 if (internal_relocs
== (arelent
*) NULL
1745 || external_relocs
== (char *) NULL
)
1747 bfd_error
= no_memory
;
1750 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1752 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1753 != external_relocs_size
)
1755 bfd_error
= system_call_error
;
1759 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1761 struct internal_reloc intern
;
1763 (*backend
->swap_reloc_in
) (abfd
,
1764 external_relocs
+ i
* external_reloc_size
,
1767 if (intern
.r_extern
)
1769 /* r_symndx is an index into the external symbols. */
1770 BFD_ASSERT (intern
.r_symndx
>= 0
1772 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1773 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1776 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1777 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1779 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1784 CONST
char *sec_name
;
1787 /* r_symndx is a section key. */
1788 switch (intern
.r_symndx
)
1790 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1791 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1792 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1793 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1794 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1795 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1796 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1797 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1798 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1799 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1800 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1801 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1805 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1806 if (sec
== (asection
*) NULL
)
1808 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1810 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1813 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1815 /* Let the backend select the howto field and do any other
1816 required processing. */
1817 (*backend
->finish_reloc
) (abfd
, &intern
, rptr
);
1820 bfd_release (abfd
, external_relocs
);
1822 section
->relocation
= internal_relocs
;
1827 /* Get a canonical list of relocs. */
1830 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1838 if (section
->flags
& SEC_CONSTRUCTOR
)
1840 arelent_chain
*chain
;
1842 /* This section has relocs made up by us, not the file, so take
1843 them out of their chain and place them into the data area
1845 for (count
= 0, chain
= section
->constructor_chain
;
1846 count
< section
->reloc_count
;
1847 count
++, chain
= chain
->next
)
1848 *relptr
++ = &chain
->relent
;
1854 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1857 tblptr
= section
->relocation
;
1858 if (tblptr
== (arelent
*) NULL
)
1861 for (count
= 0; count
< section
->reloc_count
; count
++)
1862 *relptr
++ = tblptr
++;
1865 *relptr
= (arelent
*) NULL
;
1867 return section
->reloc_count
;
1870 /* Provided a BFD, a section and an offset into the section, calculate
1871 and return the name of the source file and the line nearest to the
1875 ecoff_find_nearest_line (abfd
,
1884 asymbol
**ignore_symbols
;
1886 CONST
char **filename_ptr
;
1887 CONST
char **functionname_ptr
;
1888 unsigned int *retline_ptr
;
1890 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1895 bfd_size_type external_pdr_size
;
1899 unsigned char *line_ptr
;
1900 unsigned char *line_end
;
1903 /* If we're not in the .text section, we don't have any line
1905 if (strcmp (section
->name
, _TEXT
) != 0
1906 || offset
< ecoff_data (abfd
)->text_start
1907 || offset
>= ecoff_data (abfd
)->text_end
)
1910 /* Make sure we have the FDR's. */
1911 if (ecoff_slurp_symbolic_info (abfd
) == false
1912 || bfd_get_symcount (abfd
) == 0)
1915 /* Each file descriptor (FDR) has a memory address. Here we track
1916 down which FDR we want. The FDR's are stored in increasing
1917 memory order. If speed is ever important, this can become a
1918 binary search. We must ignore FDR's with no PDR entries; they
1919 will have the adr of the FDR before or after them. */
1920 fdr_start
= ecoff_data (abfd
)->fdr
;
1921 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1922 fdr_hold
= (FDR
*) NULL
;
1923 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1925 if (fdr_ptr
->cpd
== 0)
1927 if (offset
< fdr_ptr
->adr
)
1931 if (fdr_hold
== (FDR
*) NULL
)
1935 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1936 have an address, which is relative to the FDR address, and are
1937 also stored in increasing memory order. */
1938 offset
-= fdr_ptr
->adr
;
1939 external_pdr_size
= backend
->external_pdr_size
;
1940 pdr_ptr
= ((char *) ecoff_data (abfd
)->external_pdr
1941 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1942 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1943 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1945 /* The address of the first PDR is an offset which applies to the
1946 addresses of all the PDR's. */
1949 for (pdr_ptr
+= external_pdr_size
;
1951 pdr_ptr
+= external_pdr_size
)
1953 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1954 if (offset
< pdr
.adr
)
1958 /* Now we can look for the actual line number. The line numbers are
1959 stored in a very funky format, which I won't try to describe.
1960 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1961 we want; we need this to compute line_end. */
1962 line_end
= ecoff_data (abfd
)->line
;
1963 if (pdr_ptr
== pdr_end
)
1964 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1966 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1968 /* Now change pdr and pdr_ptr to the one we want. */
1969 pdr_ptr
-= external_pdr_size
;
1970 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1974 line_ptr
= (ecoff_data (abfd
)->line
1975 + fdr_ptr
->cbLineOffset
1976 + pdr
.cbLineOffset
);
1977 while (line_ptr
< line_end
)
1982 delta
= *line_ptr
>> 4;
1985 count
= (*line_ptr
& 0xf) + 1;
1989 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
1990 if (delta
>= 0x8000)
1995 if (offset
< count
* 4)
1997 offset
-= count
* 4;
2000 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2001 at least according to gdb/mipsread.c. */
2002 if (fdr_ptr
->rss
== -1)
2004 *filename_ptr
= NULL
;
2006 *functionname_ptr
= NULL
;
2011 (*backend
->swap_ext_in
) (abfd
,
2012 ((char *) ecoff_data (abfd
)->external_ext
2013 + pdr
.isym
* backend
->external_ext_size
),
2015 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2022 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2023 (*backend
->swap_sym_in
) (abfd
,
2024 ((char *) ecoff_data (abfd
)->external_sym
2025 + ((fdr_ptr
->isymBase
+ pdr
.isym
)
2026 * backend
->external_sym_size
)),
2028 *functionname_ptr
= (ecoff_data (abfd
)->ss
2032 if (lineno
== ilineNil
)
2034 *retline_ptr
= lineno
;
2038 /* We can't use the generic linking routines for ECOFF, because we
2039 have to handle all the debugging information. The generic link
2040 routine just works out the section contents and attaches a list of
2043 We link by looping over all the seclets. We make two passes. On
2044 the first we set the actual section contents and determine the size
2045 of the debugging information. On the second we accumulate the
2046 debugging information and write it out.
2048 This currently always accumulates the debugging information, which
2049 is incorrect, because it ignores the -s and -S options of the
2050 linker. The linker needs to be modified to give us that
2051 information in a more useful format (currently it just provides a
2052 list of symbols which should appear in the output file). */
2054 /* Clear the output_has_begun flag for all the input BFD's. We use it
2055 to avoid linking in the debugging information for a BFD more than
2059 ecoff_clear_output_flags (abfd
)
2062 register asection
*o
;
2063 register bfd_seclet_type
*p
;
2065 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2066 for (p
= o
->seclets_head
;
2067 p
!= (bfd_seclet_type
*) NULL
;
2069 if (p
->type
== bfd_indirect_seclet
)
2070 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2073 /* Handle an indirect seclet on the first pass. Set the contents of
2074 the output section, and accumulate the debugging information if
2078 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
2080 bfd_seclet_type
*seclet
;
2081 asection
*output_section
;
2083 boolean relocateable
;
2086 HDRR
*output_symhdr
;
2089 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2090 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2091 && (output_section
->flags
& SEC_LOAD
)
2094 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2098 if (bfd_set_section_contents (output_bfd
,
2109 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2111 /* We want to figure out how much space will be required to
2112 incorporate all the debugging information from input_bfd. We use
2113 the output_has_begun field to avoid adding it in more than once.
2114 The actual incorporation is done in the second pass, in
2115 ecoff_get_debug. The code has to parallel that code in its
2116 manipulations of output_symhdr. */
2118 if (input_bfd
->output_has_begun
)
2120 input_bfd
->output_has_begun
= true;
2122 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2124 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2130 /* We just accumulate local symbols from a non-ECOFF BFD. The
2131 external symbols are handled separately. */
2133 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2134 get_symtab_upper_bound (input_bfd
));
2135 if (symbols
== (asymbol
**) NULL
)
2137 bfd_error
= no_memory
;
2140 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2142 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2146 len
= strlen ((*sym_ptr
)->name
);
2147 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2149 ++output_symhdr
->isymMax
;
2150 output_symhdr
->issMax
+= len
+ 1;
2154 bfd_release (output_bfd
, (PTR
) symbols
);
2156 ++output_symhdr
->ifdMax
;
2161 /* We simply add in the information from another ECOFF BFD. First
2162 we make sure we have the symbolic information. */
2163 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2165 if (bfd_get_symcount (input_bfd
) == 0)
2168 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2170 /* Figure out how much information we are going to be putting in.
2171 The external symbols are handled separately. */
2172 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2173 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2174 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2175 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2176 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2177 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2178 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2179 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2180 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2182 /* The RFD's are special, since we create them if needed. */
2183 if (input_symhdr
->crfd
> 0)
2184 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2186 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2191 /* Handle an arbitrary seclet on the first pass. */
2194 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2196 bfd_seclet_type
*seclet
;
2199 boolean relocateable
;
2201 switch (seclet
->type
)
2203 case bfd_indirect_seclet
:
2204 /* The contents of this section come from another one somewhere
2206 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2208 case bfd_fill_seclet
:
2209 /* Fill in the section with fill.value. This is used to pad out
2210 sections, but we must avoid padding the .bss section. */
2211 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2213 if (seclet
->u
.fill
.value
!= 0)
2218 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2222 for (i
= 0; i
< seclet
->size
; i
+=2)
2223 d
[i
] = seclet
->u
.fill
.value
>> 8;
2224 for (i
= 1; i
< seclet
->size
; i
+=2)
2225 d
[i
] = seclet
->u
.fill
.value
;
2226 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2228 bfd_release (abfd
, (PTR
) d
);
2240 /* Add a string to the debugging information we are accumulating for a
2241 file. Return the offset from the fdr string base or from the
2242 external string base. */
2245 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2255 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2256 len
= strlen (string
);
2259 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2260 ret
= symhdr
->issExtMax
;
2261 symhdr
->issExtMax
+= len
+ 1;
2265 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2267 symhdr
->issMax
+= len
+ 1;
2268 fdr
->cbSs
+= len
+ 1;
2273 /* Accumulate the debugging information from an input section. */
2276 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2278 bfd_seclet_type
*seclet
;
2280 boolean relocateable
;
2282 const struct ecoff_backend_data
* const backend
= ecoff_backend (output_bfd
);
2283 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
2284 const bfd_size_type external_pdr_size
= backend
->external_pdr_size
;
2285 const bfd_size_type external_fdr_size
= backend
->external_fdr_size
;
2286 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
2287 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2288 = backend
->swap_sym_in
;
2289 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2290 = backend
->swap_sym_out
;
2291 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2292 = backend
->swap_pdr_in
;
2293 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
2294 = backend
->swap_fdr_out
;
2295 void (* const swap_rfd_out
) PARAMS ((bfd
*, const RFDT
*, PTR
))
2296 = backend
->swap_rfd_out
;
2298 HDRR
*output_symhdr
;
2300 ecoff_data_type
*output_ecoff
;
2301 ecoff_data_type
*input_ecoff
;
2304 ecoff_symbol_type
*esym_ptr
;
2305 ecoff_symbol_type
*esym_end
;
2310 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2312 /* Don't get the information more than once. */
2313 if (input_bfd
->output_has_begun
)
2315 input_bfd
->output_has_begun
= true;
2317 output_ecoff
= ecoff_data (output_bfd
);
2318 output_symhdr
= &output_ecoff
->symbolic_header
;
2320 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2327 /* This is not an ECOFF BFD. Just gather the symbols. */
2329 memset (&fdr
, 0, sizeof fdr
);
2331 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2332 fdr
.issBase
= output_symhdr
->issMax
;
2334 fdr
.rss
= ecoff_add_string (output_bfd
,
2336 bfd_get_filename (input_bfd
),
2338 fdr
.isymBase
= output_symhdr
->isymMax
;
2340 /* Get the local symbols from the input BFD. */
2341 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2342 get_symtab_upper_bound (input_bfd
));
2343 if (symbols
== (asymbol
**) NULL
)
2345 bfd_error
= no_memory
;
2348 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2350 /* Handle the local symbols. Any external symbols are handled
2353 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2357 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2359 memset (&internal_sym
, 0, sizeof internal_sym
);
2360 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2365 if (bfd_is_com_section ((*sym_ptr
)->section
)
2366 || (*sym_ptr
)->section
== &bfd_und_section
)
2367 internal_sym
.value
= (*sym_ptr
)->value
;
2369 internal_sym
.value
= ((*sym_ptr
)->value
2370 + (*sym_ptr
)->section
->output_offset
2371 + (*sym_ptr
)->section
->output_section
->vma
);
2372 internal_sym
.st
= stNil
;
2373 internal_sym
.sc
= scUndefined
;
2374 internal_sym
.index
= indexNil
;
2375 (*swap_sym_out
) (output_bfd
, &internal_sym
,
2376 ((char *) output_ecoff
->external_sym
2377 + output_symhdr
->isymMax
* external_sym_size
));
2379 ++output_symhdr
->isymMax
;
2382 bfd_release (output_bfd
, (PTR
) symbols
);
2384 /* Leave everything else in the FDR zeroed out. This will cause
2385 the lang field to be langC. The fBigendian field will
2386 indicate little endian format, but it doesn't matter because
2387 it only applies to aux fields and there are none. */
2389 (*swap_fdr_out
) (output_bfd
, &fdr
,
2390 ((char *) output_ecoff
->external_fdr
2391 + output_symhdr
->ifdMax
* external_fdr_size
));
2392 ++output_symhdr
->ifdMax
;
2396 /* This is an ECOFF BFD. We want to grab the information from
2397 input_bfd and attach it to output_bfd. */
2398 count
= bfd_get_symcount (input_bfd
);
2401 input_ecoff
= ecoff_data (input_bfd
);
2402 input_symhdr
= &input_ecoff
->symbolic_header
;
2404 /* I think that it is more efficient to simply copy the debugging
2405 information from the input BFD to the output BFD. Because ECOFF
2406 uses relative pointers for most of the debugging information,
2407 only a little of it has to be changed at all. */
2409 /* Swap in the local symbols, adjust their values, and swap them out
2410 again. The external symbols are handled separately. */
2411 sym_out
= ((char *) output_ecoff
->external_sym
2412 + output_symhdr
->isymMax
* external_sym_size
);
2414 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2415 esym_end
= esym_ptr
+ count
;
2416 for (; esym_ptr
< esym_end
; esym_ptr
++)
2418 if (esym_ptr
->local
)
2422 (*swap_sym_in
) (input_bfd
, esym_ptr
->native
, &sym
);
2424 /* If we're producing an executable, move common symbols
2426 if (relocateable
== false)
2428 if (sym
.sc
== scCommon
)
2430 else if (sym
.sc
== scSCommon
)
2434 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2435 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2436 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2437 sym
.value
= (esym_ptr
->symbol
.value
2438 + esym_ptr
->symbol
.section
->output_offset
2439 + esym_ptr
->symbol
.section
->output_section
->vma
);
2440 (*swap_sym_out
) (output_bfd
, &sym
, sym_out
);
2441 sym_out
+= external_sym_size
;
2445 /* That should have accounted for all the local symbols in
2448 /* Copy the information that does not need swapping. */
2449 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2451 input_symhdr
->cbLine
* sizeof (unsigned char));
2452 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2453 input_ecoff
->external_aux
,
2454 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2455 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2457 input_symhdr
->issMax
* sizeof (char));
2459 /* Some of the information may need to be swapped. */
2460 if (output_bfd
->xvec
->header_byteorder_big_p
2461 == input_bfd
->xvec
->header_byteorder_big_p
)
2463 /* The two BFD's have the same endianness, so memcpy will
2465 if (input_symhdr
->idnMax
> 0)
2466 memcpy (((char *) output_ecoff
->external_dnr
2467 + output_symhdr
->idnMax
* backend
->external_dnr_size
),
2468 input_ecoff
->external_dnr
,
2469 input_symhdr
->idnMax
* backend
->external_dnr_size
);
2470 if (input_symhdr
->ipdMax
> 0)
2471 memcpy (((char *) output_ecoff
->external_pdr
2472 + output_symhdr
->ipdMax
* external_pdr_size
),
2473 input_ecoff
->external_pdr
,
2474 input_symhdr
->ipdMax
* external_pdr_size
);
2475 if (input_symhdr
->ioptMax
> 0)
2476 memcpy (((char *) output_ecoff
->external_opt
2477 + output_symhdr
->ioptMax
* backend
->external_opt_size
),
2478 input_ecoff
->external_opt
,
2479 input_symhdr
->ioptMax
* backend
->external_opt_size
);
2488 /* The two BFD's have different endianness, so we must swap
2489 everything in and out. This code would always work, but it
2490 would be slow in the normal case. */
2491 sz
= backend
->external_dnr_size
;
2492 in
= (char *) input_ecoff
->external_dnr
;
2493 end
= in
+ input_symhdr
->idnMax
* sz
;
2494 out
= (char *) output_ecoff
->external_dnr
+ output_symhdr
->idnMax
* sz
;
2495 for (; in
< end
; in
+= sz
, out
+= sz
)
2499 (*backend
->swap_dnr_in
) (input_bfd
, in
, &dnr
);
2500 (*backend
->swap_dnr_out
) (output_bfd
, &dnr
, out
);
2503 sz
= external_pdr_size
;
2504 in
= (char *) input_ecoff
->external_pdr
;
2505 end
= in
+ input_symhdr
->ipdMax
* sz
;
2506 out
= (char *) output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
* sz
;
2507 for (; in
< end
; in
+= sz
, out
+= sz
)
2511 (*swap_pdr_in
) (input_bfd
, in
, &pdr
);
2512 (*backend
->swap_pdr_out
) (output_bfd
, &pdr
, out
);
2515 sz
= backend
->external_opt_size
;
2516 in
= (char *) input_ecoff
->external_opt
;
2517 end
= in
+ input_symhdr
->ioptMax
* sz
;
2518 out
= (char *) output_ecoff
->external_opt
+ output_symhdr
->ioptMax
* sz
;
2519 for (; in
< end
; in
+= sz
, out
+= sz
)
2523 (*backend
->swap_opt_in
) (input_bfd
, in
, &opt
);
2524 (*backend
->swap_opt_out
) (output_bfd
, &opt
, out
);
2528 /* Set ifdbase so that the external symbols know how to adjust their
2530 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2532 fdr_ptr
= input_ecoff
->fdr
;
2533 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2534 fdr_out
= ((char *) output_ecoff
->external_fdr
2535 + output_symhdr
->ifdMax
* external_fdr_size
);
2536 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
+= external_fdr_size
)
2539 unsigned long pdr_off
;
2543 /* The memory address for this fdr is the address for the seclet
2544 plus the offset to this fdr within input_bfd. For some
2545 reason the offset of the first procedure pointer is also
2553 (*swap_pdr_in
) (input_bfd
,
2554 ((char *) input_ecoff
->external_pdr
2555 + fdr
.ipdFirst
* external_pdr_size
),
2559 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2561 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2564 fdr
.issBase
+= output_symhdr
->issMax
;
2565 fdr
.isymBase
+= output_symhdr
->isymMax
;
2566 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2567 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2568 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2569 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2570 fdr
.rfdBase
+= output_symhdr
->crfd
;
2572 /* If there are no RFD's, we are going to add some. We don't
2573 want to adjust irfd for this, so that all the FDR's can share
2575 if (input_symhdr
->crfd
== 0)
2576 fdr
.crfd
= input_symhdr
->ifdMax
;
2578 if (fdr
.cbLine
!= 0)
2579 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2581 (*swap_fdr_out
) (output_bfd
, &fdr
, fdr_out
);
2584 if (input_symhdr
->crfd
> 0)
2586 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2587 = backend
->swap_rfd_in
;
2592 /* Swap and adjust the RFD's. RFD's are only created by the
2593 linker, so this will only be necessary if one of the input
2594 files is the result of a partial link. Presumably all
2595 necessary RFD's are present. */
2596 rfd_in
= (char *) input_ecoff
->external_rfd
;
2597 rfd_end
= rfd_in
+ input_symhdr
->crfd
* external_rfd_size
;
2598 rfd_out
= ((char *) output_ecoff
->external_rfd
2599 + output_symhdr
->crfd
* external_rfd_size
);
2602 rfd_in
+= external_rfd_size
, rfd_out
+= external_rfd_size
)
2606 (*swap_rfd_in
) (input_bfd
, rfd_in
, &rfd
);
2607 rfd
+= output_symhdr
->ifdMax
;
2608 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2610 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2618 /* Create RFD's. Some of the debugging information includes
2619 relative file indices. These indices are taken as indices to
2620 the RFD table if there is one, or to the global table if
2621 there is not. If we did not create RFD's, we would have to
2622 parse and adjust all the debugging information which contains
2624 rfd
= output_symhdr
->ifdMax
;
2625 rfd_out
= ((char *) output_ecoff
->external_rfd
2626 + output_symhdr
->crfd
* external_rfd_size
);
2627 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
* external_rfd_size
;
2628 for (; rfd_out
< rfd_end
; rfd_out
+= external_rfd_size
, rfd
++)
2629 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2630 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2633 /* Combine the register masks. Not all of these are used on all
2634 targets, but that's OK because only the relevant ones will be
2635 swapped in and out. */
2639 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2640 output_ecoff
->fprmask
|= input_ecoff
->fprmask
;
2641 for (i
= 0; i
< 4; i
++)
2642 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2645 /* Update the counts. */
2646 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2647 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2648 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2649 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2650 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2651 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2652 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2653 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2654 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2659 /* This is the actual link routine. It makes two passes over all the
2663 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2666 boolean relocateable
;
2668 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2671 register asection
*o
;
2672 register bfd_seclet_type
*p
;
2673 asymbol
**sym_ptr_ptr
;
2674 bfd_size_type debug_align
;
2678 /* We accumulate the debugging information counts in the symbolic
2680 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2681 symhdr
->magic
= backend
->sym_magic
;
2682 /* FIXME: What should the version stamp be? */
2684 symhdr
->ilineMax
= 0;
2688 symhdr
->isymMax
= 0;
2689 symhdr
->ioptMax
= 0;
2690 symhdr
->iauxMax
= 0;
2692 symhdr
->issExtMax
= 0;
2695 symhdr
->iextMax
= 0;
2697 /* We need to copy over the debugging symbols from each input BFD.
2698 When we do this copying, we have to adjust the text address in
2699 the FDR structures, so we have to know the text address used for
2700 the input BFD. Since we only want to copy the symbols once per
2701 input BFD, but we are going to look at each input BFD multiple
2702 times (once for each section it provides), we arrange to always
2703 look at the text section first. That means that when we copy the
2704 debugging information, we always know the text address. So we
2705 actually do each pass in two sub passes; first the text sections,
2706 then the non-text sections. We use the output_has_begun flag to
2707 determine whether we have copied over the debugging information
2710 /* Do the first pass: set the output section contents and count the
2711 debugging information. */
2712 ecoff_clear_output_flags (abfd
);
2713 for (ipass
= 0; ipass
< 2; ipass
++)
2715 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2717 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2718 so they are done on pass 0. For other sections the
2719 expression is true, so they are done on pass 1. */
2720 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2723 for (p
= o
->seclets_head
;
2724 p
!= (bfd_seclet_type
*) NULL
;
2727 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2734 /* We handle the external symbols differently. We use the ones
2735 attached to the output_bfd. The linker will have already
2736 determined which symbols are to be attached. Here we just
2737 determine how much space we will need for them. */
2738 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2739 if (sym_ptr_ptr
!= NULL
)
2743 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2744 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2746 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2747 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2750 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2755 /* Adjust the counts so that structures are longword aligned. */
2756 debug_align
= backend
->debug_align
;
2758 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2759 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2760 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2762 /* Now the counts in symhdr are the correct size for the debugging
2763 information. We allocate the right amount of space, and reset
2764 the counts so that the second pass can use them as indices. It
2765 would be possible to output the debugging information directly to
2766 the file in pass 2, rather than to build it in memory and then
2767 write it out. Outputting to the file would require a lot of
2768 seeks and small writes, though, and I think this approach is
2770 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2771 + symhdr
->idnMax
* backend
->external_dnr_size
2772 + symhdr
->ipdMax
* backend
->external_pdr_size
2773 + symhdr
->isymMax
* backend
->external_sym_size
2774 + symhdr
->ioptMax
* backend
->external_opt_size
2775 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2776 + symhdr
->issMax
* sizeof (char)
2777 + symhdr
->issExtMax
* sizeof (char)
2778 + symhdr
->ifdMax
* backend
->external_fdr_size
2779 + symhdr
->crfd
* backend
->external_rfd_size
2780 + symhdr
->iextMax
* backend
->external_ext_size
);
2781 raw
= (char *) bfd_alloc (abfd
, size
);
2782 if (raw
== (char *) NULL
)
2784 bfd_error
= no_memory
;
2787 ecoff_data (abfd
)->raw_size
= size
;
2788 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2790 /* Initialize the raw pointers. */
2791 #define SET(field, count, type, size) \
2792 ecoff_data (abfd)->field = (type) raw; \
2793 raw += symhdr->count * size
2795 SET (line
, cbLine
, unsigned char *, sizeof (unsigned char));
2796 SET (external_dnr
, idnMax
, PTR
, backend
->external_dnr_size
);
2797 SET (external_pdr
, ipdMax
, PTR
, backend
->external_pdr_size
);
2798 SET (external_sym
, isymMax
, PTR
, backend
->external_sym_size
);
2799 SET (external_opt
, ioptMax
, PTR
, backend
->external_opt_size
);
2800 SET (external_aux
, iauxMax
, union aux_ext
*, sizeof (union aux_ext
));
2801 SET (ss
, issMax
, char *, sizeof (char));
2802 SET (ssext
, issExtMax
, char *, sizeof (char));
2803 SET (external_fdr
, ifdMax
, PTR
, backend
->external_fdr_size
);
2804 SET (external_rfd
, crfd
, PTR
, backend
->external_rfd_size
);
2805 SET (external_ext
, iextMax
, PTR
, backend
->external_ext_size
);
2808 /* Reset the counts so the second pass can use them to know how far
2810 symhdr
->ilineMax
= 0;
2814 symhdr
->isymMax
= 0;
2815 symhdr
->ioptMax
= 0;
2816 symhdr
->iauxMax
= 0;
2818 symhdr
->issExtMax
= 0;
2821 symhdr
->iextMax
= 0;
2823 /* Do the second pass: accumulate the debugging information. */
2824 ecoff_clear_output_flags (abfd
);
2825 for (ipass
= 0; ipass
< 2; ipass
++)
2827 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2829 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2831 for (p
= o
->seclets_head
;
2832 p
!= (bfd_seclet_type
*) NULL
;
2835 if (p
->type
== bfd_indirect_seclet
)
2837 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
2844 /* Put in the external symbols. */
2845 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2846 if (sym_ptr_ptr
!= NULL
)
2848 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
2849 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
2850 = backend
->swap_ext_in
;
2851 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
2852 = backend
->swap_ext_out
;
2856 ssext
= ecoff_data (abfd
)->ssext
;
2857 external_ext
= (char *) ecoff_data (abfd
)->external_ext
;
2858 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2863 sym_ptr
= *sym_ptr_ptr
;
2865 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2866 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2869 /* The native pointer can be NULL for a symbol created by
2870 the linker via ecoff_make_empty_symbol. */
2871 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2872 || ecoffsymbol (sym_ptr
)->native
== NULL
)
2875 esym
.cobol_main
= 0;
2879 /* FIXME: we can do better than this for st and sc. */
2880 esym
.asym
.st
= stGlobal
;
2881 esym
.asym
.sc
= scAbs
;
2882 esym
.asym
.reserved
= 0;
2883 esym
.asym
.index
= indexNil
;
2887 ecoff_symbol_type
*ecoff_sym_ptr
;
2889 ecoff_sym_ptr
= ecoffsymbol (sym_ptr
);
2890 if (ecoff_sym_ptr
->local
)
2892 (*swap_ext_in
) (abfd
, ecoff_sym_ptr
->native
, &esym
);
2894 /* If we're producing an executable, move common symbols
2896 if (relocateable
== false)
2898 if (esym
.asym
.sc
== scCommon
)
2899 esym
.asym
.sc
= scBss
;
2900 else if (esym
.asym
.sc
== scSCommon
)
2901 esym
.asym
.sc
= scSBss
;
2904 /* Adjust the FDR index for the symbol by that used for
2906 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2909 esym
.asym
.iss
= symhdr
->issExtMax
;
2911 if (bfd_is_com_section (sym_ptr
->section
)
2912 || sym_ptr
->section
== &bfd_und_section
)
2913 esym
.asym
.value
= sym_ptr
->value
;
2915 esym
.asym
.value
= (sym_ptr
->value
2916 + sym_ptr
->section
->output_offset
2917 + sym_ptr
->section
->output_section
->vma
);
2919 (*swap_ext_out
) (abfd
, &esym
, external_ext
);
2921 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2923 external_ext
+= external_ext_size
;
2926 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2927 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2931 /* Adjust the counts so that structures are longword aligned. */
2932 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2933 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2934 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2939 /* Set the architecture. The supported architecture is stored in the
2940 backend pointer. We always set the architecture anyhow, since many
2941 callers ignore the return value. */
2944 ecoff_set_arch_mach (abfd
, arch
, machine
)
2946 enum bfd_architecture arch
;
2947 unsigned long machine
;
2949 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2950 return arch
== ecoff_backend (abfd
)->arch
;
2953 /* Get the size of the section headers. We do not output the .scommon
2954 section which we created in ecoff_mkobject, nor do we output any
2955 .reginfo section. */
2958 ecoff_sizeof_headers (abfd
, reloc
)
2966 for (current
= abfd
->sections
;
2967 current
!= (asection
*)NULL
;
2968 current
= current
->next
)
2969 if (strcmp (current
->name
, SCOMMON
) != 0
2970 && strcmp (current
->name
, REGINFO
) != 0)
2973 return (bfd_coff_filhsz (abfd
)
2974 + bfd_coff_aoutsz (abfd
)
2975 + c
* bfd_coff_scnhsz (abfd
));
2979 /* Get the contents of a section. This is where we handle reading the
2980 .reginfo section, which implicitly holds the contents of an
2981 ecoff_reginfo structure. */
2984 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2989 bfd_size_type count
;
2991 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2992 struct ecoff_reginfo s
;
2995 if (strcmp (section
->name
, REGINFO
) != 0)
2996 return bfd_generic_get_section_contents (abfd
, section
, location
,
2999 s
.gp_value
= tdata
->gp
;
3000 s
.gprmask
= tdata
->gprmask
;
3001 for (i
= 0; i
< 4; i
++)
3002 s
.cprmask
[i
] = tdata
->cprmask
[i
];
3003 s
.fprmask
= tdata
->fprmask
;
3005 /* bfd_get_section_contents has already checked that the offset and
3006 size is reasonable. We don't have to worry about swapping or any
3007 such thing; the .reginfo section is defined such that the
3008 contents are an ecoff_reginfo structure as seen on the host. */
3009 memcpy (location
, ((char *) &s
) + offset
, count
);
3013 /* Calculate the file position for each section, and set
3017 ecoff_compute_section_file_positions (abfd
)
3025 if (bfd_get_start_address (abfd
))
3026 abfd
->flags
|= EXEC_P
;
3028 sofar
= ecoff_sizeof_headers (abfd
, false);
3031 for (current
= abfd
->sections
;
3032 current
!= (asection
*) NULL
;
3033 current
= current
->next
)
3035 /* Only deal with sections which have contents */
3036 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
3037 || strcmp (current
->name
, SCOMMON
) == 0
3038 || strcmp (current
->name
, REGINFO
) == 0)
3041 /* On Ultrix, the data sections in an executable file must be
3042 aligned to a page boundary within the file. This does not
3043 affect the section size, though. FIXME: Does this work for
3045 if ((abfd
->flags
& EXEC_P
) != 0
3046 && (abfd
->flags
& D_PAGED
) != 0
3047 && first_data
!= false
3048 && (current
->flags
& SEC_CODE
) == 0)
3050 const bfd_vma round
= ecoff_backend (abfd
)->round
;
3052 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
3056 /* Align the sections in the file to the same boundary on
3057 which they are aligned in virtual memory. */
3059 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3061 current
->filepos
= sofar
;
3063 sofar
+= current
->_raw_size
;
3065 /* make sure that this section is of the right size too */
3067 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3068 current
->_raw_size
+= sofar
- old_sofar
;
3071 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3074 /* Set the contents of a section. This is where we handle setting the
3075 contents of the .reginfo section, which implicitly holds a
3076 ecoff_reginfo structure. */
3079 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
3084 bfd_size_type count
;
3086 if (abfd
->output_has_begun
== false)
3087 ecoff_compute_section_file_positions (abfd
);
3089 if (strcmp (section
->name
, REGINFO
) == 0)
3091 ecoff_data_type
*tdata
= ecoff_data (abfd
);
3092 struct ecoff_reginfo s
;
3095 /* If the caller is only changing part of the structure, we must
3096 retrieve the current information before the memcpy. */
3097 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
3099 s
.gp_value
= tdata
->gp
;
3100 s
.gprmask
= tdata
->gprmask
;
3101 for (i
= 0; i
< 4; i
++)
3102 s
.cprmask
[i
] = tdata
->cprmask
[i
];
3103 s
.fprmask
= tdata
->fprmask
;
3106 /* bfd_set_section_contents has already checked that the offset
3107 and size is reasonable. We don't have to worry about
3108 swapping or any such thing; the .reginfo section is defined
3109 such that the contents are an ecoff_reginfo structure as seen
3111 memcpy (((char *) &s
) + offset
, location
, count
);
3113 tdata
->gp
= s
.gp_value
;
3114 tdata
->gprmask
= s
.gprmask
;
3115 for (i
= 0; i
< 4; i
++)
3116 tdata
->cprmask
[i
] = s
.cprmask
[i
];
3117 tdata
->fprmask
= s
.fprmask
;
3123 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3126 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3131 /* Write out an ECOFF file. */
3134 ecoff_write_object_contents (abfd
)
3137 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3138 const bfd_vma round
= backend
->round
;
3139 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
3140 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
3141 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
3142 const bfd_size_type external_hdr_size
= backend
->external_hdr_size
;
3143 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
3144 void (* const swap_reloc_out
) PARAMS ((bfd
*,
3145 const struct internal_reloc
*,
3147 = backend
->swap_reloc_out
;
3151 file_ptr reloc_base
;
3153 unsigned long reloc_size
;
3154 unsigned long text_size
;
3155 unsigned long text_start
;
3156 unsigned long data_size
;
3157 unsigned long data_start
;
3158 unsigned long bss_size
;
3160 struct internal_filehdr internal_f
;
3161 struct internal_aouthdr internal_a
;
3164 bfd_error
= system_call_error
;
3166 if(abfd
->output_has_begun
== false)
3167 ecoff_compute_section_file_positions(abfd
);
3169 if (abfd
->sections
!= (asection
*) NULL
)
3170 scn_base
= abfd
->sections
->filepos
;
3173 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3177 for (current
= abfd
->sections
;
3178 current
!= (asection
*)NULL
;
3179 current
= current
->next
)
3181 if (strcmp (current
->name
, SCOMMON
) == 0
3182 || strcmp (current
->name
, REGINFO
) == 0)
3184 current
->target_index
= count
;
3186 if (current
->reloc_count
!= 0)
3188 bfd_size_type relsize
;
3190 current
->rel_filepos
= reloc_base
;
3191 relsize
= current
->reloc_count
* external_reloc_size
;
3192 reloc_size
+= relsize
;
3193 reloc_base
+= relsize
;
3196 current
->rel_filepos
= 0;
3199 sym_base
= reloc_base
+ reloc_size
;
3201 /* At least on Ultrix, the symbol table of an executable file must
3202 be aligned to a page boundary. FIXME: Is this true on other
3204 if ((abfd
->flags
& EXEC_P
) != 0
3205 && (abfd
->flags
& D_PAGED
) != 0)
3206 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
3208 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3210 if ((abfd
->flags
& D_PAGED
) != 0)
3211 text_size
= ecoff_sizeof_headers (abfd
, false);
3219 /* Write section headers to the file. */
3221 buff
= (PTR
) alloca (scnhsz
);
3222 internal_f
.f_nscns
= 0;
3223 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
3225 for (current
= abfd
->sections
;
3226 current
!= (asection
*) NULL
;
3227 current
= current
->next
)
3229 struct internal_scnhdr section
;
3232 if (strcmp (current
->name
, SCOMMON
) == 0)
3234 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3235 && current
->reloc_count
== 0);
3238 if (strcmp (current
->name
, REGINFO
) == 0)
3240 BFD_ASSERT ((bfd_get_section_size_before_reloc (current
)
3241 == sizeof (struct ecoff_reginfo
))
3242 && current
->reloc_count
== 0);
3246 ++internal_f
.f_nscns
;
3248 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3250 /* FIXME: is this correct for shared libraries? I think it is
3251 but I have no platform to check. Ian Lance Taylor. */
3252 vma
= bfd_get_section_vma (abfd
, current
);
3253 if (strcmp (current
->name
, _LIB
) == 0)
3254 section
.s_vaddr
= 0;
3256 section
.s_vaddr
= vma
;
3258 section
.s_paddr
= vma
;
3259 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3261 /* If this section is unloadable then the scnptr will be 0. */
3262 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3263 section
.s_scnptr
= 0;
3265 section
.s_scnptr
= current
->filepos
;
3266 section
.s_relptr
= current
->rel_filepos
;
3268 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3269 object file produced by the assembler is supposed to point to
3270 information about how much room is required by objects of
3271 various different sizes. I think this only matters if we
3272 want the linker to compute the best size to use, or
3273 something. I don't know what happens if the information is
3275 section
.s_lnnoptr
= 0;
3277 section
.s_nreloc
= current
->reloc_count
;
3278 section
.s_nlnno
= 0;
3279 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3282 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
3283 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
3286 if ((section
.s_flags
& STYP_TEXT
) != 0)
3288 text_size
+= bfd_get_section_size_before_reloc (current
);
3289 if (text_start
== 0 || text_start
> vma
)
3292 else if ((section
.s_flags
& STYP_RDATA
) != 0
3293 || (section
.s_flags
& STYP_DATA
) != 0
3294 || (section
.s_flags
& STYP_LIT8
) != 0
3295 || (section
.s_flags
& STYP_LIT4
) != 0
3296 || (section
.s_flags
& STYP_SDATA
) != 0)
3298 data_size
+= bfd_get_section_size_before_reloc (current
);
3299 if (data_start
== 0 || data_start
> vma
)
3302 else if ((section
.s_flags
& STYP_BSS
) != 0
3303 || (section
.s_flags
& STYP_SBSS
) != 0)
3304 bss_size
+= bfd_get_section_size_before_reloc (current
);
3307 /* Set up the file header. */
3309 internal_f
.f_magic
= ecoff_get_magic (abfd
);
3311 /* We will NOT put a fucking timestamp in the header here. Every
3312 time you put it back, I will come in and take it out again. I'm
3313 sorry. This field does not belong here. We fill it with a 0 so
3314 it compares the same but is not a reasonable time. --
3316 internal_f
.f_timdat
= 0;
3318 if (bfd_get_symcount (abfd
) != 0)
3320 /* The ECOFF f_nsyms field is not actually the number of
3321 symbols, it's the size of symbolic information header. */
3322 internal_f
.f_nsyms
= external_hdr_size
;
3323 internal_f
.f_symptr
= sym_base
;
3327 internal_f
.f_nsyms
= 0;
3328 internal_f
.f_symptr
= 0;
3331 internal_f
.f_opthdr
= aoutsz
;
3333 internal_f
.f_flags
= F_LNNO
;
3334 if (reloc_size
== 0)
3335 internal_f
.f_flags
|= F_RELFLG
;
3336 if (bfd_get_symcount (abfd
) == 0)
3337 internal_f
.f_flags
|= F_LSYMS
;
3338 if (abfd
->flags
& EXEC_P
)
3339 internal_f
.f_flags
|= F_EXEC
;
3341 if (! abfd
->xvec
->byteorder_big_p
)
3342 internal_f
.f_flags
|= F_AR32WR
;
3344 internal_f
.f_flags
|= F_AR32W
;
3346 /* Set up the ``optional'' header. */
3347 if ((abfd
->flags
& D_PAGED
) != 0)
3348 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
3350 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
3352 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3353 linker happy. But, is it right? */
3354 internal_a
.vstamp
= 0x20a;
3356 /* At least on Ultrix, these have to be rounded to page boundaries.
3357 FIXME: Is this true on other platforms? */
3358 if ((abfd
->flags
& D_PAGED
) != 0)
3360 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
3361 internal_a
.text_start
= text_start
&~ (round
- 1);
3362 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
3363 internal_a
.data_start
= data_start
&~ (round
- 1);
3367 internal_a
.tsize
= text_size
;
3368 internal_a
.text_start
= text_start
;
3369 internal_a
.dsize
= data_size
;
3370 internal_a
.data_start
= data_start
;
3373 /* On Ultrix, the initial portions of the .sbss and .bss segments
3374 are at the end of the data section. The bsize field in the
3375 optional header records how many bss bytes are required beyond
3376 those in the data section. The value is not rounded to a page
3378 if (bss_size
< internal_a
.dsize
- data_size
)
3381 bss_size
-= internal_a
.dsize
- data_size
;
3382 internal_a
.bsize
= bss_size
;
3383 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3385 internal_a
.entry
= bfd_get_start_address (abfd
);
3387 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3389 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3390 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
3391 for (i
= 0; i
< 4; i
++)
3392 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3394 /* Write out the file header and the optional header. */
3396 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3399 buff
= (PTR
) alloca (filhsz
);
3400 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
3401 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
3404 buff
= (PTR
) alloca (aoutsz
);
3405 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
3406 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
3409 /* Write out the relocs. */
3410 for (current
= abfd
->sections
;
3411 current
!= (asection
*) NULL
;
3412 current
= current
->next
)
3414 arelent
**reloc_ptr_ptr
;
3415 arelent
**reloc_end
;
3418 if (current
->reloc_count
== 0)
3421 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
3424 bfd_error
= no_memory
;
3428 reloc_ptr_ptr
= current
->orelocation
;
3429 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3430 out_ptr
= (char *) buff
;
3432 reloc_ptr_ptr
< reloc_end
;
3433 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
3437 struct internal_reloc in
;
3439 memset (&in
, 0, sizeof in
);
3441 reloc
= *reloc_ptr_ptr
;
3442 sym
= *reloc
->sym_ptr_ptr
;
3444 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3445 in
.r_type
= reloc
->howto
->type
;
3447 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3449 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3456 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3457 if (strcmp (name
, ".text") == 0)
3458 in
.r_symndx
= RELOC_SECTION_TEXT
;
3459 else if (strcmp (name
, ".rdata") == 0)
3460 in
.r_symndx
= RELOC_SECTION_RDATA
;
3461 else if (strcmp (name
, ".data") == 0)
3462 in
.r_symndx
= RELOC_SECTION_DATA
;
3463 else if (strcmp (name
, ".sdata") == 0)
3464 in
.r_symndx
= RELOC_SECTION_SDATA
;
3465 else if (strcmp (name
, ".sbss") == 0)
3466 in
.r_symndx
= RELOC_SECTION_SBSS
;
3467 else if (strcmp (name
, ".bss") == 0)
3468 in
.r_symndx
= RELOC_SECTION_BSS
;
3469 else if (strcmp (name
, ".init") == 0)
3470 in
.r_symndx
= RELOC_SECTION_INIT
;
3471 else if (strcmp (name
, ".lit8") == 0)
3472 in
.r_symndx
= RELOC_SECTION_LIT8
;
3473 else if (strcmp (name
, ".lit4") == 0)
3474 in
.r_symndx
= RELOC_SECTION_LIT4
;
3480 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3483 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3485 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
3486 != external_reloc_size
* current
->reloc_count
)
3488 bfd_release (abfd
, buff
);
3491 /* Write out the symbolic debugging information. */
3492 if (bfd_get_symcount (abfd
) > 0)
3495 unsigned long sym_offset
;
3497 /* Set up the offsets in the symbolic header. */
3498 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3499 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
3501 #define SET(offset, size, ptr) \
3502 if (symhdr->size == 0) \
3503 symhdr->offset = 0; \
3505 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3506 - (char *) ecoff_data (abfd)->raw_syments) \
3509 SET (cbLineOffset
, cbLine
, line
);
3510 SET (cbDnOffset
, idnMax
, external_dnr
);
3511 SET (cbPdOffset
, ipdMax
, external_pdr
);
3512 SET (cbSymOffset
, isymMax
, external_sym
);
3513 SET (cbOptOffset
, ioptMax
, external_opt
);
3514 SET (cbAuxOffset
, iauxMax
, external_aux
);
3515 SET (cbSsOffset
, issMax
, ss
);
3516 SET (cbSsExtOffset
, issExtMax
, ssext
);
3517 SET (cbFdOffset
, ifdMax
, external_fdr
);
3518 SET (cbRfdOffset
, crfd
, external_rfd
);
3519 SET (cbExtOffset
, iextMax
, external_ext
);
3522 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3525 buff
= (PTR
) alloca (external_hdr_size
);
3526 (*backend
->swap_hdr_out
) (abfd
, &ecoff_data (abfd
)->symbolic_header
,
3528 if (bfd_write (buff
, 1, external_hdr_size
, abfd
) != external_hdr_size
)
3530 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3531 ecoff_data (abfd
)->raw_size
, abfd
)
3532 != ecoff_data (abfd
)->raw_size
)
3535 else if ((abfd
->flags
& EXEC_P
) != 0
3536 && (abfd
->flags
& D_PAGED
) != 0)
3540 /* A demand paged executable must occupy an even number of
3542 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3545 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3547 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3550 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3557 /* Archive handling. ECOFF uses what appears to be a unique type of
3558 archive header (which I call an armap). The byte ordering of the
3559 armap and the contents are encoded in the name of the armap itself.
3560 At least for now, we only support archives with the same byte
3561 ordering in the armap and the contents.
3563 The first four bytes in the armap are the number of symbol
3564 definitions. This is always a power of two.
3566 This is followed by the symbol definitions. Each symbol definition
3567 occupies 8 bytes. The first four bytes are the offset from the
3568 start of the armap strings to the null-terminated string naming
3569 this symbol. The second four bytes are the file offset to the
3570 archive member which defines this symbol. If the second four bytes
3571 are 0, then this is not actually a symbol definition, and it should
3574 The symbols are hashed into the armap with a closed hashing scheme.
3575 See the functions below for the details of the algorithm.
3577 We could use the hash table when looking up symbols in a library.
3578 This would require a new BFD target entry point to replace the
3579 bfd_get_next_mapent function used by the linker.
3581 After the symbol definitions comes four bytes holding the size of
3582 the string table, followed by the string table itself. */
3584 /* The name of an archive headers looks like this:
3585 __________E[BL]E[BL]_ (with a trailing space).
3586 The trailing space is changed to an X if the archive is changed to
3587 indicate that the armap is out of date.
3589 The Alpha seems to use ________64E[BL]E[BL]_. */
3591 #define ARMAP_BIG_ENDIAN 'B'
3592 #define ARMAP_LITTLE_ENDIAN 'L'
3593 #define ARMAP_MARKER 'E'
3594 #define ARMAP_START_LENGTH 10
3595 #define ARMAP_HEADER_MARKER_INDEX 10
3596 #define ARMAP_HEADER_ENDIAN_INDEX 11
3597 #define ARMAP_OBJECT_MARKER_INDEX 12
3598 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3599 #define ARMAP_END_INDEX 14
3600 #define ARMAP_END "_ "
3602 /* This is a magic number used in the hashing algorithm. */
3603 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3605 /* This returns the hash value to use for a string. It also sets
3606 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3607 is the number of entries in the hash table, and HLOG is the log
3611 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3613 unsigned int *rehash
;
3621 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3622 hash
*= ARMAP_HASH_MAGIC
;
3623 *rehash
= (hash
& (size
- 1)) | 1;
3624 return hash
>> (32 - hlog
);
3627 /* Read in the armap. */
3630 ecoff_slurp_armap (abfd
)
3635 struct areltdata
*mapdata
;
3636 bfd_size_type parsed_size
;
3638 struct artdata
*ardata
;
3641 struct symdef
*symdef_ptr
;
3644 /* Get the name of the first element. */
3645 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3651 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3653 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3654 standard COFF armap. We could move the ECOFF armap stuff into
3655 bfd_slurp_armap, but that seems inappropriate since no other
3656 target uses this format. Instead, we check directly for a COFF
3658 if (strncmp (nextname
, "/ ", 16) == 0)
3659 return bfd_slurp_armap (abfd
);
3661 /* See if the first element is an armap. */
3662 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3663 ARMAP_START_LENGTH
) != 0
3664 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3665 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3666 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3667 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3668 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3669 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3670 || strncmp (nextname
+ ARMAP_END_INDEX
,
3671 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3673 bfd_has_map (abfd
) = false;
3677 /* Make sure we have the right byte ordering. */
3678 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3679 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3680 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3681 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3683 bfd_error
= wrong_format
;
3687 /* Read in the armap. */
3688 ardata
= bfd_ardata (abfd
);
3689 mapdata
= snarf_ar_hdr (abfd
);
3690 if (mapdata
== (struct areltdata
*) NULL
)
3692 parsed_size
= mapdata
->parsed_size
;
3693 bfd_release (abfd
, (PTR
) mapdata
);
3695 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3696 if (raw_armap
== (char *) NULL
)
3698 bfd_error
= no_memory
;
3702 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3704 bfd_error
= malformed_archive
;
3705 bfd_release (abfd
, (PTR
) raw_armap
);
3709 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3711 ardata
->symdef_count
= 0;
3712 ardata
->cache
= (struct ar_cache
*) NULL
;
3714 /* This code used to overlay the symdefs over the raw archive data,
3715 but that doesn't work on a 64 bit host. */
3717 stringbase
= raw_armap
+ count
* 8 + 8;
3719 #ifdef CHECK_ARMAP_HASH
3723 /* Double check that I have the hashing algorithm right by making
3724 sure that every symbol can be looked up successfully. */
3726 for (i
= 1; i
< count
; i
<<= 1)
3728 BFD_ASSERT (i
== count
);
3730 raw_ptr
= raw_armap
+ 4;
3731 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3733 unsigned int name_offset
, file_offset
;
3734 unsigned int hash
, rehash
, srch
;
3736 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3737 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3738 if (file_offset
== 0)
3740 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3745 /* See if we can rehash to this location. */
3746 for (srch
= (hash
+ rehash
) & (count
- 1);
3747 srch
!= hash
&& srch
!= i
;
3748 srch
= (srch
+ rehash
) & (count
- 1))
3749 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3751 BFD_ASSERT (srch
== i
);
3755 #endif /* CHECK_ARMAP_HASH */
3757 raw_ptr
= raw_armap
+ 4;
3758 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3759 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3760 ++ardata
->symdef_count
;
3762 symdef_ptr
= ((struct symdef
*)
3764 ardata
->symdef_count
* sizeof (struct symdef
)));
3765 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3767 raw_ptr
= raw_armap
+ 4;
3768 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3770 unsigned int name_offset
, file_offset
;
3772 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3773 if (file_offset
== 0)
3775 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3776 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3777 symdef_ptr
->file_offset
= file_offset
;
3781 ardata
->first_file_filepos
= bfd_tell (abfd
);
3782 /* Pad to an even boundary. */
3783 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3785 bfd_has_map (abfd
) = true;
3790 /* Write out an armap. */
3793 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3795 unsigned int elength
;
3797 unsigned int orl_count
;
3800 unsigned int hashsize
, hashlog
;
3801 unsigned int symdefsize
;
3803 unsigned int stringsize
;
3804 unsigned int mapsize
;
3807 struct stat statbuf
;
3810 bfd_byte
*hashtable
;
3814 /* Ultrix appears to use as a hash table size the least power of two
3815 greater than twice the number of entries. */
3816 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3818 hashsize
= 1 << hashlog
;
3820 symdefsize
= hashsize
* 8;
3822 stringsize
= stridx
+ padit
;
3824 /* Include 8 bytes to store symdefsize and stringsize in output. */
3825 mapsize
= symdefsize
+ stringsize
+ 8;
3827 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3829 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3831 /* Work out the ECOFF armap name. */
3832 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3833 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3834 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3835 (abfd
->xvec
->header_byteorder_big_p
3837 : ARMAP_LITTLE_ENDIAN
);
3838 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3839 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3840 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3841 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3843 /* Write the timestamp of the archive header to be just a little bit
3844 later than the timestamp of the file, otherwise the linker will
3845 complain that the index is out of date. Actually, the Ultrix
3846 linker just checks the archive name; the GNU linker may check the
3848 stat (abfd
->filename
, &statbuf
);
3849 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3851 /* The DECstation uses zeroes for the uid, gid and mode of the
3853 hdr
.ar_uid
[0] = '0';
3854 hdr
.ar_gid
[0] = '0';
3855 hdr
.ar_mode
[0] = '0';
3857 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3859 hdr
.ar_fmag
[0] = '`';
3860 hdr
.ar_fmag
[1] = '\n';
3862 /* Turn all null bytes in the header into spaces. */
3863 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3864 if (((char *)(&hdr
))[i
] == '\0')
3865 (((char *)(&hdr
))[i
]) = ' ';
3867 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3868 != sizeof (struct ar_hdr
))
3871 bfd_h_put_32 (abfd
, hashsize
, temp
);
3872 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3875 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3877 current
= abfd
->archive_head
;
3879 for (i
= 0; i
< orl_count
; i
++)
3881 unsigned int hash
, rehash
;
3883 /* Advance firstreal to the file position of this archive
3885 if (((bfd
*) map
[i
].pos
) != last_elt
)
3889 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3890 firstreal
+= firstreal
% 2;
3891 current
= current
->next
;
3893 while (current
!= (bfd
*) map
[i
].pos
);
3898 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3899 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3903 /* The desired slot is already taken. */
3904 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3906 srch
= (srch
+ rehash
) & (hashsize
- 1))
3907 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3910 BFD_ASSERT (srch
!= hash
);
3915 bfd_h_put_32 (abfd
, map
[i
].namidx
, (PTR
) (hashtable
+ hash
* 8));
3916 bfd_h_put_32 (abfd
, firstreal
, (PTR
) (hashtable
+ hash
* 8 + 4));
3919 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3922 bfd_release (abfd
, hashtable
);
3924 /* Now write the strings. */
3925 bfd_h_put_32 (abfd
, stringsize
, temp
);
3926 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3928 for (i
= 0; i
< orl_count
; i
++)
3932 len
= strlen (*map
[i
].name
) + 1;
3933 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3937 /* The spec sez this should be a newline. But in order to be
3938 bug-compatible for DECstation ar we use a null. */
3941 if (bfd_write ("\0", 1, 1, abfd
) != 1)
3948 /* See whether this BFD is an archive. If it is, read in the armap
3949 and the extended name table. */
3952 ecoff_archive_p (abfd
)
3955 char armag
[SARMAG
+ 1];
3957 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3958 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3960 bfd_error
= wrong_format
;
3961 return (bfd_target
*) NULL
;
3964 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3965 involves a cast, we can't do it as the left operand of
3967 abfd
->tdata
.aout_ar_data
=
3968 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3970 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3972 bfd_error
= no_memory
;
3973 return (bfd_target
*) NULL
;
3976 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3978 if (ecoff_slurp_armap (abfd
) == false
3979 || ecoff_slurp_extended_name_table (abfd
) == false)
3981 bfd_release (abfd
, bfd_ardata (abfd
));
3982 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3983 return (bfd_target
*) NULL
;