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_compute_section_file_positions
PARAMS ((bfd
*abfd
));
59 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
60 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
61 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
66 /* This stuff is somewhat copied from coffcode.h. */
68 static asection bfd_debug_section
= { "*DEBUG*" };
70 /* Create an ECOFF object. */
76 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
77 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
78 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
80 bfd_error
= no_memory
;
87 /* This is a hook called by coff_real_object_p to create any backend
88 specific information. */
91 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
96 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
97 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
98 ecoff_data_type
*ecoff
;
101 if (ecoff_mkobject (abfd
) == false)
104 ecoff
= ecoff_data (abfd
);
106 ecoff
->sym_filepos
= internal_f
->f_symptr
;
108 /* Create the .reginfo section to give programs outside BFD a way to
109 see the information stored in the a.out header. See the comment
111 regsec
= bfd_make_section (abfd
, REGINFO
);
114 /* Tell the linker to leave this section completely alone. */
115 regsec
->flags
= SEC_SHARED_LIBRARY
;
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 section
->alignment_power
= abfd
->xvec
->align_power_min
;
161 if (strcmp (section
->name
, _TEXT
) == 0)
162 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
163 else if (strcmp (section
->name
, _DATA
) == 0
164 || strcmp (section
->name
, _SDATA
) == 0)
165 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
166 else if (strcmp (section
->name
, _RDATA
) == 0
167 || strcmp (section
->name
, _LIT8
) == 0
168 || strcmp (section
->name
, _LIT4
) == 0)
169 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
170 else if (strcmp (section
->name
, _BSS
) == 0
171 || strcmp (section
->name
, _SBSS
) == 0)
172 section
->flags
|= SEC_ALLOC
;
173 else if (strcmp (section
->name
, REGINFO
) == 0)
175 section
->flags
|= SEC_HAS_CONTENTS
| SEC_NEVER_LOAD
;
176 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
179 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
180 uncertain about .init on some systems and I don't know how shared
186 /* Determine the machine architecture and type. This is called from
187 the generic COFF routines. It is the inverse of ecoff_get_magic,
188 below. This could be an ECOFF backend routine, with one version
189 for each target, but there aren't all that many ECOFF targets. */
192 ecoff_set_arch_mach_hook (abfd
, filehdr
)
196 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
197 enum bfd_architecture arch
;
200 switch (internal_f
->f_magic
)
203 case MIPS_MAGIC_LITTLE
:
205 arch
= bfd_arch_mips
;
209 case MIPS_MAGIC_LITTLE2
:
210 case MIPS_MAGIC_BIG2
:
211 /* MIPS ISA level 2: the r6000 */
212 arch
= bfd_arch_mips
;
216 case MIPS_MAGIC_LITTLE3
:
217 case MIPS_MAGIC_BIG3
:
218 /* MIPS ISA level 3: the r4000 */
219 arch
= bfd_arch_mips
;
224 arch
= bfd_arch_alpha
;
229 arch
= bfd_arch_obscure
;
234 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
237 /* Get the magic number to use based on the architecture and machine.
238 This is the inverse of ecoff_set_arch_mach_hook, above. */
241 ecoff_get_magic (abfd
)
246 switch (bfd_get_arch (abfd
))
249 switch (bfd_get_mach (abfd
))
254 big
= MIPS_MAGIC_BIG
;
255 little
= MIPS_MAGIC_LITTLE
;
259 big
= MIPS_MAGIC_BIG2
;
260 little
= MIPS_MAGIC_LITTLE2
;
264 big
= MIPS_MAGIC_BIG3
;
265 little
= MIPS_MAGIC_LITTLE3
;
269 return abfd
->xvec
->byteorder_big_p
? big
: little
;
280 /* Get the section s_flags to use for a section. */
283 ecoff_sec_to_styp_flags (name
, flags
)
291 if (strcmp (name
, _TEXT
) == 0)
293 else if (strcmp (name
, _DATA
) == 0)
295 else if (strcmp (name
, _SDATA
) == 0)
297 else if (strcmp (name
, _RDATA
) == 0)
299 else if (strcmp (name
, _LITA
) == 0)
301 else if (strcmp (name
, _LIT8
) == 0)
303 else if (strcmp (name
, _LIT4
) == 0)
305 else if (strcmp (name
, _BSS
) == 0)
307 else if (strcmp (name
, _SBSS
) == 0)
309 else if (strcmp (name
, _INIT
) == 0)
310 styp
= STYP_ECOFF_INIT
;
311 else if (strcmp (name
, _FINI
) == 0)
312 styp
= STYP_ECOFF_FINI
;
313 else if (flags
& SEC_CODE
)
315 else if (flags
& SEC_DATA
)
317 else if (flags
& SEC_READONLY
)
319 else if (flags
& SEC_LOAD
)
324 if (flags
& SEC_NEVER_LOAD
)
330 /* Get the BFD flags to use for a section. */
334 ecoff_styp_to_sec_flags (abfd
, hdr
)
338 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
339 long styp_flags
= internal_s
->s_flags
;
340 flagword sec_flags
=0;
342 if (styp_flags
& STYP_NOLOAD
)
343 sec_flags
|= SEC_NEVER_LOAD
;
345 /* For 386 COFF, at least, an unloadable text or data section is
346 actually a shared library section. */
347 if ((styp_flags
& STYP_TEXT
)
348 || (styp_flags
& STYP_ECOFF_INIT
)
349 || (styp_flags
& STYP_ECOFF_FINI
))
351 if (sec_flags
& SEC_NEVER_LOAD
)
352 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
354 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
356 else if ((styp_flags
& STYP_DATA
)
357 || (styp_flags
& STYP_RDATA
)
358 || (styp_flags
& STYP_SDATA
))
360 if (sec_flags
& SEC_NEVER_LOAD
)
361 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
363 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
364 if (styp_flags
& STYP_RDATA
)
365 sec_flags
|= SEC_READONLY
;
367 else if ((styp_flags
& STYP_BSS
)
368 || (styp_flags
& STYP_SBSS
))
370 sec_flags
|= SEC_ALLOC
;
372 else if (styp_flags
& STYP_INFO
)
374 sec_flags
|= SEC_NEVER_LOAD
;
376 else if ((styp_flags
& STYP_LITA
)
377 || (styp_flags
& STYP_LIT8
)
378 || (styp_flags
& STYP_LIT4
))
380 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
384 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
390 /* Routines to swap auxiliary information in and out. I am assuming
391 that the auxiliary information format is always going to be target
394 /* Swap in a type information record.
395 BIGEND says whether AUX symbols are big-endian or little-endian; this
396 info comes from the file header record (fh-fBigendian). */
399 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
401 struct tir_ext
*ext_copy
;
404 struct tir_ext ext
[1];
406 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
408 /* now the fun stuff... */
410 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
411 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
412 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
413 >> TIR_BITS1_BT_SH_BIG
;
414 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
415 >> TIR_BITS_TQ4_SH_BIG
;
416 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
417 >> TIR_BITS_TQ5_SH_BIG
;
418 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
419 >> TIR_BITS_TQ0_SH_BIG
;
420 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
421 >> TIR_BITS_TQ1_SH_BIG
;
422 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
423 >> TIR_BITS_TQ2_SH_BIG
;
424 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
425 >> TIR_BITS_TQ3_SH_BIG
;
427 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
428 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
429 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
430 >> TIR_BITS1_BT_SH_LITTLE
;
431 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
432 >> TIR_BITS_TQ4_SH_LITTLE
;
433 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
434 >> TIR_BITS_TQ5_SH_LITTLE
;
435 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
436 >> TIR_BITS_TQ0_SH_LITTLE
;
437 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
438 >> TIR_BITS_TQ1_SH_LITTLE
;
439 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
440 >> TIR_BITS_TQ2_SH_LITTLE
;
441 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
442 >> TIR_BITS_TQ3_SH_LITTLE
;
446 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
451 /* Swap out a type information record.
452 BIGEND says whether AUX symbols are big-endian or little-endian; this
453 info comes from the file header record (fh-fBigendian). */
456 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
463 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
465 /* now the fun stuff... */
467 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
468 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
469 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
470 & TIR_BITS1_BT_BIG
));
471 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
473 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
474 & TIR_BITS_TQ5_BIG
));
475 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
477 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
478 & TIR_BITS_TQ1_BIG
));
479 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
481 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
482 & TIR_BITS_TQ3_BIG
));
484 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
485 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
486 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
487 & TIR_BITS1_BT_LITTLE
));
488 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
489 & TIR_BITS_TQ4_LITTLE
)
490 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
491 & TIR_BITS_TQ5_LITTLE
));
492 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
493 & TIR_BITS_TQ0_LITTLE
)
494 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
495 & TIR_BITS_TQ1_LITTLE
));
496 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
497 & TIR_BITS_TQ2_LITTLE
)
498 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
499 & TIR_BITS_TQ3_LITTLE
));
503 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
508 /* Swap in a relative symbol record. BIGEND says whether it is in
509 big-endian or little-endian format.*/
512 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
514 struct rndx_ext
*ext_copy
;
517 struct rndx_ext ext
[1];
519 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
521 /* now the fun stuff... */
523 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
524 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
525 >> RNDX_BITS1_RFD_SH_BIG
);
526 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
527 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
528 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
529 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
531 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
532 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
533 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
534 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
535 >> RNDX_BITS1_INDEX_SH_LITTLE
)
536 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
537 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
541 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
546 /* Swap out a relative symbol record. BIGEND says whether it is in
547 big-endian or little-endian format.*/
550 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
553 struct rndx_ext
*ext
;
557 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
559 /* now the fun stuff... */
561 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
562 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
563 & RNDX_BITS1_RFD_BIG
)
564 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
565 & RNDX_BITS1_INDEX_BIG
));
566 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
567 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
569 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
570 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
571 & RNDX_BITS1_RFD_LITTLE
)
572 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
573 & RNDX_BITS1_INDEX_LITTLE
));
574 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
575 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
579 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
584 /* Read in and swap the important symbolic information for an ECOFF
585 object file. This is called by gdb. */
588 ecoff_slurp_symbolic_info (abfd
)
591 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
592 bfd_size_type external_hdr_size
;
593 HDRR
*internal_symhdr
;
594 bfd_size_type raw_base
;
595 bfd_size_type raw_size
;
597 bfd_size_type external_fdr_size
;
601 bfd_size_type raw_end
;
602 bfd_size_type cb_end
;
604 /* Check whether we've already gotten it, and whether there's any to
606 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
608 if (ecoff_data (abfd
)->sym_filepos
== 0)
610 bfd_get_symcount (abfd
) = 0;
614 /* At this point bfd_get_symcount (abfd) holds the number of symbols
615 as read from the file header, but on ECOFF this is always the
616 size of the symbolic information header. It would be cleaner to
617 handle this when we first read the file in coffgen.c. */
618 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
619 if (bfd_get_symcount (abfd
) != external_hdr_size
)
621 bfd_error
= bad_value
;
625 /* Read the symbolic information header. */
626 raw
= (PTR
) alloca (external_hdr_size
);
627 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
628 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
629 != external_hdr_size
))
631 bfd_error
= system_call_error
;
634 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
635 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
637 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
639 bfd_error
= bad_value
;
643 /* Now we can get the correct number of symbols. */
644 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
645 + internal_symhdr
->iextMax
);
647 /* Read all the symbolic information at once. */
648 raw_base
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
650 /* Alpha ecoff makes the determination of raw_size difficult. It has
651 an undocumented debug data section between the symhdr and the first
652 documented section. And the ordering of the sections varies between
653 statically and dynamically linked executables.
654 If bfd supports SEEK_END someday, this code could be simplified. */
658 #define UPDATE_RAW_END(start, count, size) \
659 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
660 if (cb_end > raw_end) \
663 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
664 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
665 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
666 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
667 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
668 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
669 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
670 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
671 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
672 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
673 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
675 #undef UPDATE_RAW_END
677 raw_size
= raw_end
- raw_base
;
680 ecoff_data (abfd
)->sym_filepos
= 0;
683 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
686 bfd_error
= no_memory
;
689 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
691 bfd_error
= system_call_error
;
692 bfd_release (abfd
, raw
);
696 ecoff_data (abfd
)->raw_syments
= raw
;
698 /* Get pointers for the numeric offsets in the HDRR structure. */
699 #define FIX(off1, off2, type) \
700 if (internal_symhdr->off1 == 0) \
701 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
703 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
704 + internal_symhdr->off1 \
706 FIX (cbLineOffset
, line
, unsigned char *);
707 FIX (cbDnOffset
, external_dnr
, PTR
);
708 FIX (cbPdOffset
, external_pdr
, PTR
);
709 FIX (cbSymOffset
, external_sym
, PTR
);
710 FIX (cbOptOffset
, external_opt
, PTR
);
711 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
712 FIX (cbSsOffset
, ss
, char *);
713 FIX (cbSsExtOffset
, ssext
, char *);
714 FIX (cbFdOffset
, external_fdr
, PTR
);
715 FIX (cbRfdOffset
, external_rfd
, PTR
);
716 FIX (cbExtOffset
, external_ext
, PTR
);
719 /* I don't want to always swap all the data, because it will just
720 waste time and most programs will never look at it. The only
721 time the linker needs most of the debugging information swapped
722 is when linking big-endian and little-endian MIPS object files
723 together, which is not a common occurrence.
725 We need to look at the fdr to deal with a lot of information in
726 the symbols, so we swap them here. */
727 ecoff_data (abfd
)->debug_info
.fdr
=
728 (struct fdr
*) bfd_alloc (abfd
,
729 (internal_symhdr
->ifdMax
*
730 sizeof (struct fdr
)));
731 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
733 bfd_error
= no_memory
;
736 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
737 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
738 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
739 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
740 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
741 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
746 /* ECOFF symbol table routines. The ECOFF symbol table is described
747 in gcc/mips-tfile.c. */
749 /* ECOFF uses two common sections. One is the usual one, and the
750 other is for small objects. All the small objects are kept
751 together, and then referenced via the gp pointer, which yields
752 faster assembler code. This is what we use for the small common
754 static asection ecoff_scom_section
;
755 static asymbol ecoff_scom_symbol
;
756 static asymbol
*ecoff_scom_symbol_ptr
;
758 /* Create an empty symbol. */
761 ecoff_make_empty_symbol (abfd
)
764 ecoff_symbol_type
*new;
766 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
767 if (new == (ecoff_symbol_type
*) NULL
)
769 bfd_error
= no_memory
;
770 return (asymbol
*) NULL
;
772 memset (new, 0, sizeof *new);
773 new->symbol
.section
= (asection
*) NULL
;
774 new->fdr
= (FDR
*) NULL
;
777 new->symbol
.the_bfd
= abfd
;
781 /* Set the BFD flags and section for an ECOFF symbol. */
784 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
789 asymbol
**indirect_ptr_ptr
;
791 asym
->the_bfd
= abfd
;
792 asym
->value
= ecoff_sym
->value
;
793 asym
->section
= &bfd_debug_section
;
796 /* An indirect symbol requires two consecutive stabs symbols. */
797 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
799 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
801 /* @@ Stuffing pointers into integers is a no-no.
802 We can usually get away with it if the integer is
803 large enough though. */
804 if (sizeof (asym
) > sizeof (bfd_vma
))
806 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
808 asym
->flags
= BSF_DEBUGGING
;
809 asym
->section
= &bfd_und_section
;
810 *indirect_ptr_ptr
= NULL
;
814 if (ECOFF_IS_STAB (ecoff_sym
)
815 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
817 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
818 asym
->section
= &bfd_ind_section
;
819 /* Pass this symbol on to the next call to this function. */
820 *indirect_ptr_ptr
= asym
;
824 /* Most symbol types are just for debugging. */
825 switch (ecoff_sym
->st
)
834 if (ECOFF_IS_STAB (ecoff_sym
))
836 asym
->flags
= BSF_DEBUGGING
;
841 asym
->flags
= BSF_DEBUGGING
;
846 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
848 asym
->flags
= BSF_LOCAL
;
849 switch (ecoff_sym
->sc
)
852 /* Used for compiler generated labels. Leave them in the
853 debugging section, and mark them as local. If BSF_DEBUGGING
854 is set, then nm does not display them for some reason. If no
855 flags are set then the linker whines about them. */
856 asym
->flags
= BSF_LOCAL
;
859 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
860 asym
->value
-= asym
->section
->vma
;
863 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
864 asym
->value
-= asym
->section
->vma
;
867 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
868 asym
->value
-= asym
->section
->vma
;
871 asym
->flags
= BSF_DEBUGGING
;
874 asym
->section
= &bfd_abs_section
;
877 asym
->section
= &bfd_und_section
;
887 asym
->flags
= BSF_DEBUGGING
;
890 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
891 asym
->value
-= asym
->section
->vma
;
894 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
895 asym
->value
-= asym
->section
->vma
;
898 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
899 asym
->value
-= asym
->section
->vma
;
902 asym
->flags
= BSF_DEBUGGING
;
905 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
907 asym
->section
= &bfd_com_section
;
913 if (ecoff_scom_section
.name
== NULL
)
915 /* Initialize the small common section. */
916 ecoff_scom_section
.name
= SCOMMON
;
917 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
918 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
919 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
920 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
921 ecoff_scom_symbol
.name
= SCOMMON
;
922 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
923 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
924 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
926 asym
->section
= &ecoff_scom_section
;
931 asym
->flags
= BSF_DEBUGGING
;
934 asym
->section
= &bfd_und_section
;
939 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
940 asym
->value
-= asym
->section
->vma
;
945 asym
->flags
= BSF_DEBUGGING
;
948 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
949 asym
->value
-= asym
->section
->vma
;
955 /* Look for special constructors symbols and make relocation entries
956 in a special construction section. These are produced by the
957 -fgnu-linker argument to g++. */
958 if (ECOFF_IS_STAB (ecoff_sym
))
960 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
972 arelent_chain
*reloc_chain
;
973 unsigned int bitsize
;
975 /* Get a section with the same name as the symbol (usually
976 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
977 name ___CTOR_LIST (three underscores). We need
978 __CTOR_LIST (two underscores), since ECOFF doesn't use
979 a leading underscore. This should be handled by gcc,
980 but instead we do it here. Actually, this should all
981 be done differently anyhow. */
982 name
= bfd_asymbol_name (asym
);
983 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
988 section
= bfd_get_section_by_name (abfd
, name
);
989 if (section
== (asection
*) NULL
)
993 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
995 section
= bfd_make_section (abfd
, copy
);
998 /* Build a reloc pointing to this constructor. */
1000 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1001 reloc_chain
->relent
.sym_ptr_ptr
=
1002 bfd_get_section (asym
)->symbol_ptr_ptr
;
1003 reloc_chain
->relent
.address
= section
->_raw_size
;
1004 reloc_chain
->relent
.addend
= asym
->value
;
1005 reloc_chain
->relent
.howto
=
1006 ecoff_backend (abfd
)->constructor_reloc
;
1008 /* Set up the constructor section to hold the reloc. */
1009 section
->flags
= SEC_CONSTRUCTOR
;
1010 ++section
->reloc_count
;
1012 /* Constructor sections must be rounded to a boundary
1013 based on the bitsize. These are not real sections--
1014 they are handled specially by the linker--so the ECOFF
1015 16 byte alignment restriction does not apply. */
1016 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1017 section
->alignment_power
= 1;
1018 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1019 ++section
->alignment_power
;
1021 reloc_chain
->next
= section
->constructor_chain
;
1022 section
->constructor_chain
= reloc_chain
;
1023 section
->_raw_size
+= bitsize
/ 8;
1025 /* Mark the symbol as a constructor. */
1026 asym
->flags
|= BSF_CONSTRUCTOR
;
1033 /* Read an ECOFF symbol table. */
1036 ecoff_slurp_symbol_table (abfd
)
1039 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1040 const bfd_size_type external_ext_size
1041 = backend
->debug_swap
.external_ext_size
;
1042 const bfd_size_type external_sym_size
1043 = backend
->debug_swap
.external_sym_size
;
1044 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1045 = backend
->debug_swap
.swap_ext_in
;
1046 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1047 = backend
->debug_swap
.swap_sym_in
;
1048 bfd_size_type internal_size
;
1049 ecoff_symbol_type
*internal
;
1050 ecoff_symbol_type
*internal_ptr
;
1051 asymbol
*indirect_ptr
;
1057 /* If we've already read in the symbol table, do nothing. */
1058 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1061 /* Get the symbolic information. */
1062 if (ecoff_slurp_symbolic_info (abfd
) == false)
1064 if (bfd_get_symcount (abfd
) == 0)
1067 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1068 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1069 if (internal
== NULL
)
1071 bfd_error
= no_memory
;
1075 internal_ptr
= internal
;
1076 indirect_ptr
= NULL
;
1077 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1078 eraw_end
= (eraw_src
1079 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1080 * external_ext_size
));
1081 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1085 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1086 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1087 + internal_esym
.asym
.iss
);
1088 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1089 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1090 /* The alpha uses a negative ifd field for section symbols. */
1091 if (internal_esym
.ifd
>= 0)
1092 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1093 + internal_esym
.ifd
);
1095 internal_ptr
->fdr
= NULL
;
1096 internal_ptr
->local
= false;
1097 internal_ptr
->native
= (PTR
) eraw_src
;
1099 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1101 /* The local symbols must be accessed via the fdr's, because the
1102 string and aux indices are relative to the fdr information. */
1103 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1104 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1105 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1110 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1111 + fdr_ptr
->isymBase
* external_sym_size
);
1112 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1114 lraw_src
< lraw_end
;
1115 lraw_src
+= external_sym_size
, internal_ptr
++)
1119 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1120 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1122 + internal_sym
.iss
);
1123 ecoff_set_symbol_info (abfd
, &internal_sym
,
1124 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1125 internal_ptr
->fdr
= fdr_ptr
;
1126 internal_ptr
->local
= true;
1127 internal_ptr
->native
= (PTR
) lraw_src
;
1130 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1132 ecoff_data (abfd
)->canonical_symbols
= internal
;
1137 /* Return the amount of space needed for the canonical symbols. */
1140 ecoff_get_symtab_upper_bound (abfd
)
1143 if (ecoff_slurp_symbolic_info (abfd
) == false
1144 || bfd_get_symcount (abfd
) == 0)
1147 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1150 /* Get the canonicals symbols. */
1153 ecoff_get_symtab (abfd
, alocation
)
1155 asymbol
**alocation
;
1157 unsigned int counter
= 0;
1158 ecoff_symbol_type
*symbase
;
1159 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1161 if (ecoff_slurp_symbol_table (abfd
) == false
1162 || bfd_get_symcount (abfd
) == 0)
1165 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1166 while (counter
< bfd_get_symcount (abfd
))
1168 *(location
++) = symbase
++;
1171 *location
++ = (ecoff_symbol_type
*) NULL
;
1172 return bfd_get_symcount (abfd
);
1175 /* Turn ECOFF type information into a printable string.
1176 ecoff_emit_aggregate and ecoff_type_to_string are from
1177 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1179 /* Write aggregate information to a string. */
1182 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1189 int ifd
= rndx
->rfd
;
1190 int indx
= rndx
->index
;
1191 int sym_base
, ss_base
;
1197 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1198 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1200 if (indx
== indexNil
)
1201 name
= "/* no name */";
1204 const struct ecoff_debug_swap
* const debug_swap
1205 = &ecoff_backend (abfd
)->debug_swap
;
1209 (*debug_swap
->swap_sym_in
)
1211 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1212 + indx
* debug_swap
->external_sym_size
),
1214 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1218 "%s %s { ifd = %d, index = %ld }",
1221 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1224 /* Convert the type information to string format. */
1227 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1229 union aux_ext
*aux_ptr
;
1241 unsigned int basic_type
;
1243 static char buffer1
[1024];
1244 static char buffer2
[1024];
1249 for (i
= 0; i
< 7; i
++)
1251 qualifiers
[i
].low_bound
= 0;
1252 qualifiers
[i
].high_bound
= 0;
1253 qualifiers
[i
].stride
= 0;
1256 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1257 return "-1 (no type)";
1258 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1260 basic_type
= u
.ti
.bt
;
1261 qualifiers
[0].type
= u
.ti
.tq0
;
1262 qualifiers
[1].type
= u
.ti
.tq1
;
1263 qualifiers
[2].type
= u
.ti
.tq2
;
1264 qualifiers
[3].type
= u
.ti
.tq3
;
1265 qualifiers
[4].type
= u
.ti
.tq4
;
1266 qualifiers
[5].type
= u
.ti
.tq5
;
1267 qualifiers
[6].type
= tqNil
;
1270 * Go get the basic type.
1274 case btNil
: /* undefined */
1278 case btAdr
: /* address - integer same size as pointer */
1279 strcpy (p1
, "address");
1282 case btChar
: /* character */
1283 strcpy (p1
, "char");
1286 case btUChar
: /* unsigned character */
1287 strcpy (p1
, "unsigned char");
1290 case btShort
: /* short */
1291 strcpy (p1
, "short");
1294 case btUShort
: /* unsigned short */
1295 strcpy (p1
, "unsigned short");
1298 case btInt
: /* int */
1302 case btUInt
: /* unsigned int */
1303 strcpy (p1
, "unsigned int");
1306 case btLong
: /* long */
1307 strcpy (p1
, "long");
1310 case btULong
: /* unsigned long */
1311 strcpy (p1
, "unsigned long");
1314 case btFloat
: /* float (real) */
1315 strcpy (p1
, "float");
1318 case btDouble
: /* Double (real) */
1319 strcpy (p1
, "double");
1322 /* Structures add 1-2 aux words:
1323 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1324 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1326 case btStruct
: /* Structure (Record) */
1327 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1328 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1329 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1331 indx
++; /* skip aux words */
1334 /* Unions add 1-2 aux words:
1335 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1336 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1338 case btUnion
: /* Union */
1339 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1340 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1341 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1343 indx
++; /* skip aux words */
1346 /* Enumerations add 1-2 aux words:
1347 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1348 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1350 case btEnum
: /* Enumeration */
1351 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1352 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1353 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1355 indx
++; /* skip aux words */
1358 case btTypedef
: /* defined via a typedef, isymRef points */
1359 strcpy (p1
, "typedef");
1362 case btRange
: /* subrange of int */
1363 strcpy (p1
, "subrange");
1366 case btSet
: /* pascal sets */
1370 case btComplex
: /* fortran complex */
1371 strcpy (p1
, "complex");
1374 case btDComplex
: /* fortran double complex */
1375 strcpy (p1
, "double complex");
1378 case btIndirect
: /* forward or unnamed typedef */
1379 strcpy (p1
, "forward/unamed typedef");
1382 case btFixedDec
: /* Fixed Decimal */
1383 strcpy (p1
, "fixed decimal");
1386 case btFloatDec
: /* Float Decimal */
1387 strcpy (p1
, "float decimal");
1390 case btString
: /* Varying Length Character String */
1391 strcpy (p1
, "string");
1394 case btBit
: /* Aligned Bit String */
1398 case btPicture
: /* Picture */
1399 strcpy (p1
, "picture");
1402 case btVoid
: /* Void */
1403 strcpy (p1
, "void");
1407 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1411 p1
+= strlen (buffer1
);
1414 * If this is a bitfield, get the bitsize.
1420 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1421 sprintf (p1
, " : %d", bitsize
);
1422 p1
+= strlen (buffer1
);
1427 * Deal with any qualifiers.
1429 if (qualifiers
[0].type
!= tqNil
)
1432 * Snarf up any array bounds in the correct order. Arrays
1433 * store 5 successive words in the aux. table:
1434 * word 0 RNDXR to type of the bounds (ie, int)
1435 * word 1 Current file descriptor index
1437 * word 3 high bound (or -1 if [])
1438 * word 4 stride size in bits
1440 for (i
= 0; i
< 7; i
++)
1442 if (qualifiers
[i
].type
== tqArray
)
1444 qualifiers
[i
].low_bound
=
1445 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1446 qualifiers
[i
].high_bound
=
1447 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1448 qualifiers
[i
].stride
=
1449 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1455 * Now print out the qualifiers.
1457 for (i
= 0; i
< 6; i
++)
1459 switch (qualifiers
[i
].type
)
1466 strcpy (p2
, "ptr to ");
1467 p2
+= sizeof ("ptr to ")-1;
1471 strcpy (p2
, "volatile ");
1472 p2
+= sizeof ("volatile ")-1;
1476 strcpy (p2
, "far ");
1477 p2
+= sizeof ("far ")-1;
1481 strcpy (p2
, "func. ret. ");
1482 p2
+= sizeof ("func. ret. ");
1487 int first_array
= i
;
1490 /* Print array bounds reversed (ie, in the order the C
1491 programmer writes them). C is such a fun language.... */
1493 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1496 for (j
= i
; j
>= first_array
; j
--)
1498 strcpy (p2
, "array [");
1499 p2
+= sizeof ("array [")-1;
1500 if (qualifiers
[j
].low_bound
!= 0)
1502 "%ld:%ld {%ld bits}",
1503 (long) qualifiers
[j
].low_bound
,
1504 (long) qualifiers
[j
].high_bound
,
1505 (long) qualifiers
[j
].stride
);
1507 else if (qualifiers
[j
].high_bound
!= -1)
1510 (long) (qualifiers
[j
].high_bound
+ 1),
1511 (long) (qualifiers
[j
].stride
));
1514 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1517 strcpy (p2
, "] of ");
1518 p2
+= sizeof ("] of ")-1;
1526 strcpy (p2
, buffer1
);
1530 /* Return information about ECOFF symbol SYMBOL in RET. */
1534 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1535 bfd
*abfd
; /* Ignored. */
1539 bfd_symbol_info (symbol
, ret
);
1542 /* Print information about an ECOFF symbol. */
1545 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1549 bfd_print_symbol_type how
;
1551 const struct ecoff_debug_swap
* const debug_swap
1552 = &ecoff_backend (abfd
)->debug_swap
;
1553 FILE *file
= (FILE *)filep
;
1557 case bfd_print_symbol_name
:
1558 fprintf (file
, "%s", symbol
->name
);
1560 case bfd_print_symbol_more
:
1561 if (ecoffsymbol (symbol
)->local
)
1565 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1567 fprintf (file
, "ecoff local ");
1568 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1569 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1570 (unsigned) ecoff_sym
.sc
);
1576 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1578 fprintf (file
, "ecoff extern ");
1579 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1580 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1581 (unsigned) ecoff_ext
.asym
.sc
);
1584 case bfd_print_symbol_all
:
1585 /* Print out the symbols in a reasonable way */
1594 if (ecoffsymbol (symbol
)->local
)
1596 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1599 pos
= ((((char *) ecoffsymbol (symbol
)->native
1600 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1601 / debug_swap
->external_sym_size
)
1602 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1609 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1612 pos
= (((char *) ecoffsymbol (symbol
)->native
1613 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1614 / debug_swap
->external_ext_size
);
1615 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1616 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1617 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1620 fprintf (file
, "[%3d] %c ",
1622 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1623 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1624 (unsigned) ecoff_ext
.asym
.st
,
1625 (unsigned) ecoff_ext
.asym
.sc
,
1626 (unsigned) ecoff_ext
.asym
.index
,
1627 jmptbl
, cobol_main
, weakext
,
1630 if (ecoffsymbol (symbol
)->fdr
!= NULL
1631 && ecoff_ext
.asym
.index
!= indexNil
)
1635 bfd_size_type sym_base
;
1636 union aux_ext
*aux_base
;
1638 indx
= ecoff_ext
.asym
.index
;
1640 /* sym_base is used to map the fdr relative indices which
1641 appear in the file to the position number which we are
1643 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1644 if (ecoffsymbol (symbol
)->local
)
1646 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1648 /* aux_base is the start of the aux entries for this file;
1649 asym.index is an offset from this. */
1650 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1651 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1653 /* The aux entries are stored in host byte order; the
1654 order is indicated by a bit in the fdr. */
1655 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1657 /* This switch is basically from gcc/mips-tdump.c */
1658 switch (ecoff_ext
.asym
.st
)
1666 fprintf (file
, "\n End+1 symbol: %ld",
1667 (long) (indx
+ sym_base
));
1671 if (ecoff_ext
.asym
.sc
== scText
1672 || ecoff_ext
.asym
.sc
== scInfo
)
1673 fprintf (file
, "\n First symbol: %ld",
1674 (long) (indx
+ sym_base
));
1676 fprintf (file
, "\n First symbol: %ld",
1677 (long) (AUX_GET_ISYM (bigendian
,
1678 &aux_base
[ecoff_ext
.asym
.index
])
1684 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1686 else if (ecoffsymbol (symbol
)->local
)
1687 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1688 (long) (AUX_GET_ISYM (bigendian
,
1689 &aux_base
[ecoff_ext
.asym
.index
])
1691 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1694 fprintf (file
, "\n Local symbol: %ld",
1697 + (ecoff_data (abfd
)
1698 ->debug_info
.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
)
1773 ->debug_info
.symbolic_header
.iextMax
)));
1774 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1777 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1778 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1780 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1785 CONST
char *sec_name
;
1788 /* r_symndx is a section key. */
1789 switch (intern
.r_symndx
)
1791 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1792 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1793 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1794 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1795 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1796 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1797 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1798 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1799 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1800 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1801 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1802 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1803 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1807 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1808 if (sec
== (asection
*) NULL
)
1810 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1812 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1815 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1817 /* Let the backend select the howto field and do any other
1818 required processing. */
1819 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1822 bfd_release (abfd
, external_relocs
);
1824 section
->relocation
= internal_relocs
;
1829 /* Get a canonical list of relocs. */
1832 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1840 if (section
->flags
& SEC_CONSTRUCTOR
)
1842 arelent_chain
*chain
;
1844 /* This section has relocs made up by us, not the file, so take
1845 them out of their chain and place them into the data area
1847 for (count
= 0, chain
= section
->constructor_chain
;
1848 count
< section
->reloc_count
;
1849 count
++, chain
= chain
->next
)
1850 *relptr
++ = &chain
->relent
;
1856 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1859 tblptr
= section
->relocation
;
1860 if (tblptr
== (arelent
*) NULL
)
1863 for (count
= 0; count
< section
->reloc_count
; count
++)
1864 *relptr
++ = tblptr
++;
1867 *relptr
= (arelent
*) NULL
;
1869 return section
->reloc_count
;
1872 /* Provided a BFD, a section and an offset into the section, calculate
1873 and return the name of the source file and the line nearest to the
1878 ecoff_find_nearest_line (abfd
,
1887 asymbol
**ignore_symbols
;
1889 CONST
char **filename_ptr
;
1890 CONST
char **functionname_ptr
;
1891 unsigned int *retline_ptr
;
1893 const struct ecoff_debug_swap
* const debug_swap
1894 = &ecoff_backend (abfd
)->debug_swap
;
1899 bfd_size_type external_pdr_size
;
1903 unsigned char *line_ptr
;
1904 unsigned char *line_end
;
1907 /* If we're not in the .text section, we don't have any line
1909 if (strcmp (section
->name
, _TEXT
) != 0
1910 || offset
< ecoff_data (abfd
)->text_start
1911 || offset
>= ecoff_data (abfd
)->text_end
)
1914 /* Make sure we have the FDR's. */
1915 if (ecoff_slurp_symbolic_info (abfd
) == false
1916 || bfd_get_symcount (abfd
) == 0)
1919 /* Each file descriptor (FDR) has a memory address. Here we track
1920 down which FDR we want. The FDR's are stored in increasing
1921 memory order. If speed is ever important, this can become a
1922 binary search. We must ignore FDR's with no PDR entries; they
1923 will have the adr of the FDR before or after them. */
1924 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1925 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1926 fdr_hold
= (FDR
*) NULL
;
1927 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1929 if (fdr_ptr
->cpd
== 0)
1931 if (offset
< fdr_ptr
->adr
)
1935 if (fdr_hold
== (FDR
*) NULL
)
1939 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1940 have an address, which is relative to the FDR address, and are
1941 also stored in increasing memory order. */
1942 offset
-= fdr_ptr
->adr
;
1943 external_pdr_size
= debug_swap
->external_pdr_size
;
1944 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
1945 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1946 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1947 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1949 /* The address of the first PDR is an offset which applies to the
1950 addresses of all the PDR's. */
1953 for (pdr_ptr
+= external_pdr_size
;
1955 pdr_ptr
+= external_pdr_size
)
1957 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1958 if (offset
< pdr
.adr
)
1962 /* Now we can look for the actual line number. The line numbers are
1963 stored in a very funky format, which I won't try to describe.
1964 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1965 we want; we need this to compute line_end. */
1966 line_end
= ecoff_data (abfd
)->debug_info
.line
;
1967 if (pdr_ptr
== pdr_end
)
1968 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1970 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1972 /* Now change pdr and pdr_ptr to the one we want. */
1973 pdr_ptr
-= external_pdr_size
;
1974 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1978 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
1979 + fdr_ptr
->cbLineOffset
1980 + pdr
.cbLineOffset
);
1981 while (line_ptr
< line_end
)
1986 delta
= *line_ptr
>> 4;
1989 count
= (*line_ptr
& 0xf) + 1;
1993 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
1994 if (delta
>= 0x8000)
1999 if (offset
< count
* 4)
2001 offset
-= count
* 4;
2004 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2005 at least according to gdb/mipsread.c. */
2006 if (fdr_ptr
->rss
== -1)
2008 *filename_ptr
= NULL
;
2010 *functionname_ptr
= NULL
;
2015 (*debug_swap
->swap_ext_in
)
2017 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2018 + pdr
.isym
* debug_swap
->external_ext_size
),
2020 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2021 + proc_ext
.asym
.iss
);
2028 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2031 (*debug_swap
->swap_sym_in
)
2033 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2034 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2036 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2040 if (lineno
== ilineNil
)
2042 *retline_ptr
= lineno
;
2046 /* We can't use the generic linking routines for ECOFF, because we
2047 have to handle all the debugging information. The generic link
2048 routine just works out the section contents and attaches a list of
2049 symbols. We find each input BFD by looping over all the link_order
2050 information. We accumulate the debugging information for each
2053 /* Get ECOFF EXTR information for an external symbol. This function
2054 is passed to bfd_ecoff_debug_externals. */
2057 ecoff_get_extr (sym
, esym
)
2061 ecoff_symbol_type
*ecoff_sym_ptr
;
2064 /* Don't include debugging or local symbols. */
2065 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2066 || (sym
->flags
& BSF_LOCAL
) != 0)
2069 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2070 || ecoffsymbol (sym
)->native
== NULL
)
2073 esym
->cobol_main
= 0;
2077 /* FIXME: we can do better than this for st and sc. */
2078 esym
->asym
.st
= stGlobal
;
2079 esym
->asym
.sc
= scAbs
;
2080 esym
->asym
.reserved
= 0;
2081 esym
->asym
.index
= indexNil
;
2085 ecoff_sym_ptr
= ecoffsymbol (sym
);
2087 if (ecoff_sym_ptr
->local
)
2090 input_bfd
= bfd_asymbol_bfd (sym
);
2091 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2092 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2094 /* If the symbol was defined by the linker, then esym will be
2095 undefined but sym will not be. Get a better class for such a
2097 if ((esym
->asym
.sc
== scUndefined
2098 || esym
->asym
.sc
== scSUndefined
)
2099 && bfd_get_section (sym
) != &bfd_und_section
)
2100 esym
->asym
.sc
= scAbs
;
2102 /* Adjust the FDR index for the symbol by that used for the input
2104 esym
->ifd
+= ecoff_data (input_bfd
)->debug_info
.ifdbase
;
2109 /* Set the external symbol index. This routine is passed to
2110 bfd_ecoff_debug_externals. */
2113 ecoff_set_index (sym
, indx
)
2117 ecoff_set_sym_index (sym
, indx
);
2120 /* This is the actual link routine. It builds the debugging
2121 information, and then lets the generic linking routine complete the
2125 ecoff_bfd_final_link (abfd
, info
)
2127 struct bfd_link_info
*info
;
2129 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2130 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2132 register bfd
*input_bfd
;
2135 /* We accumulate the debugging information counts in the symbolic
2137 symhdr
= &debug
->symbolic_header
;
2138 symhdr
->magic
= backend
->debug_swap
.sym_magic
;
2139 /* FIXME: What should the version stamp be? */
2141 symhdr
->ilineMax
= 0;
2145 symhdr
->isymMax
= 0;
2146 symhdr
->ioptMax
= 0;
2147 symhdr
->iauxMax
= 0;
2152 /* We accumulate the debugging information itself in the debug_info
2154 debug
->line
= debug
->line_end
= NULL
;
2155 debug
->external_dnr
= debug
->external_dnr_end
= NULL
;
2156 debug
->external_pdr
= debug
->external_pdr_end
= NULL
;
2157 debug
->external_sym
= debug
->external_sym_end
= NULL
;
2158 debug
->external_opt
= debug
->external_opt_end
= NULL
;
2159 debug
->external_aux
= debug
->external_aux_end
= NULL
;
2160 debug
->ss
= debug
->ss_end
= NULL
;
2161 debug
->external_fdr
= debug
->external_fdr_end
= NULL
;
2162 debug
->external_rfd
= debug
->external_rfd_end
= NULL
;
2164 /* We accumulate the debugging symbols from each input BFD. */
2165 for (input_bfd
= info
->input_bfds
;
2166 input_bfd
!= (bfd
*) NULL
;
2167 input_bfd
= input_bfd
->link_next
)
2171 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
2172 ret
= (bfd_ecoff_debug_accumulate
2173 (abfd
, debug
, &backend
->debug_swap
,
2174 input_bfd
, &ecoff_data (input_bfd
)->debug_info
,
2175 &ecoff_backend (input_bfd
)->debug_swap
, info
->relocateable
));
2177 ret
= bfd_ecoff_debug_link_other (abfd
,
2179 &backend
->debug_swap
,
2185 /* Combine the register masks. */
2186 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
2187 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
2188 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
2189 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
2190 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
2191 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
2194 /* Don't let the generic routine link the .reginfo sections. */
2195 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2197 if (strcmp (o
->name
, REGINFO
) == 0)
2199 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
2204 /* Let the generic link routine handle writing out the section
2206 return _bfd_generic_final_link (abfd
, info
);
2209 /* Set the architecture. The supported architecture is stored in the
2210 backend pointer. We always set the architecture anyhow, since many
2211 callers ignore the return value. */
2214 ecoff_set_arch_mach (abfd
, arch
, machine
)
2216 enum bfd_architecture arch
;
2217 unsigned long machine
;
2219 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2220 return arch
== ecoff_backend (abfd
)->arch
;
2223 /* Get the size of the section headers. We do not output the .reginfo
2228 ecoff_sizeof_headers (abfd
, reloc
)
2236 for (current
= abfd
->sections
;
2237 current
!= (asection
*)NULL
;
2238 current
= current
->next
)
2239 if (strcmp (current
->name
, REGINFO
) != 0)
2242 return (bfd_coff_filhsz (abfd
)
2243 + bfd_coff_aoutsz (abfd
)
2244 + c
* bfd_coff_scnhsz (abfd
));
2247 /* Get the contents of a section. This is where we handle reading the
2248 .reginfo section, which implicitly holds the contents of an
2249 ecoff_reginfo structure. */
2252 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2257 bfd_size_type count
;
2259 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2260 struct ecoff_reginfo s
;
2263 if (strcmp (section
->name
, REGINFO
) != 0)
2264 return bfd_generic_get_section_contents (abfd
, section
, location
,
2267 s
.gp_value
= tdata
->gp
;
2268 s
.gprmask
= tdata
->gprmask
;
2269 for (i
= 0; i
< 4; i
++)
2270 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2271 s
.fprmask
= tdata
->fprmask
;
2273 /* bfd_get_section_contents has already checked that the offset and
2274 size is reasonable. We don't have to worry about swapping or any
2275 such thing; the .reginfo section is defined such that the
2276 contents are an ecoff_reginfo structure as seen on the host. */
2277 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2281 /* Calculate the file position for each section, and set
2285 ecoff_compute_section_file_positions (abfd
)
2293 sofar
= ecoff_sizeof_headers (abfd
, false);
2296 for (current
= abfd
->sections
;
2297 current
!= (asection
*) NULL
;
2298 current
= current
->next
)
2300 /* Only deal with sections which have contents */
2301 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2302 || strcmp (current
->name
, REGINFO
) == 0)
2305 /* On Ultrix, the data sections in an executable file must be
2306 aligned to a page boundary within the file. This does not
2307 affect the section size, though. FIXME: Does this work for
2308 other platforms? It requires some modification for the
2309 Alpha, because .rdata on the Alpha goes with the text, not
2311 if ((abfd
->flags
& EXEC_P
) != 0
2312 && (abfd
->flags
& D_PAGED
) != 0
2313 && first_data
!= false
2314 && (current
->flags
& SEC_CODE
) == 0
2315 && (! ecoff_backend (abfd
)->rdata_in_text
2316 || strcmp (current
->name
, _RDATA
) != 0)
2317 && strcmp (current
->name
, _PDATA
) != 0)
2319 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2321 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2325 /* Align the sections in the file to the same boundary on
2326 which they are aligned in virtual memory. */
2328 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2330 current
->filepos
= sofar
;
2332 sofar
+= current
->_raw_size
;
2334 /* make sure that this section is of the right size too */
2336 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2337 current
->_raw_size
+= sofar
- old_sofar
;
2340 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2343 /* Set the contents of a section. This is where we handle setting the
2344 contents of the .reginfo section, which implicitly holds a
2345 ecoff_reginfo structure. */
2348 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2353 bfd_size_type count
;
2355 if (abfd
->output_has_begun
== false)
2356 ecoff_compute_section_file_positions (abfd
);
2358 if (strcmp (section
->name
, REGINFO
) == 0)
2360 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2361 struct ecoff_reginfo s
;
2364 /* If the caller is only changing part of the structure, we must
2365 retrieve the current information before the memcpy. */
2366 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2368 s
.gp_value
= tdata
->gp
;
2369 s
.gprmask
= tdata
->gprmask
;
2370 for (i
= 0; i
< 4; i
++)
2371 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2372 s
.fprmask
= tdata
->fprmask
;
2375 /* bfd_set_section_contents has already checked that the offset
2376 and size is reasonable. We don't have to worry about
2377 swapping or any such thing; the .reginfo section is defined
2378 such that the contents are an ecoff_reginfo structure as seen
2380 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2382 tdata
->gp
= s
.gp_value
;
2383 tdata
->gprmask
= s
.gprmask
;
2384 for (i
= 0; i
< 4; i
++)
2385 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2386 tdata
->fprmask
= s
.fprmask
;
2392 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
2395 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
2400 /* Write out an ECOFF file. */
2403 ecoff_write_object_contents (abfd
)
2406 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2407 const bfd_vma round
= backend
->round
;
2408 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2409 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2410 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2411 const bfd_size_type external_hdr_size
2412 = backend
->debug_swap
.external_hdr_size
;
2413 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2414 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2416 struct internal_reloc
*))
2417 = backend
->adjust_reloc_out
;
2418 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2419 const struct internal_reloc
*,
2421 = backend
->swap_reloc_out
;
2422 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2423 HDRR
* const symhdr
= &debug
->symbolic_header
;
2426 file_ptr reloc_base
;
2428 unsigned long reloc_size
;
2429 unsigned long text_size
;
2430 unsigned long text_start
;
2431 unsigned long data_size
;
2432 unsigned long data_start
;
2433 unsigned long bss_size
;
2435 struct internal_filehdr internal_f
;
2436 struct internal_aouthdr internal_a
;
2439 bfd_error
= system_call_error
;
2441 if(abfd
->output_has_begun
== false)
2442 ecoff_compute_section_file_positions(abfd
);
2444 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2448 for (current
= abfd
->sections
;
2449 current
!= (asection
*)NULL
;
2450 current
= current
->next
)
2452 if (strcmp (current
->name
, REGINFO
) == 0)
2454 current
->target_index
= count
;
2456 if (current
->reloc_count
!= 0)
2458 bfd_size_type relsize
;
2460 current
->rel_filepos
= reloc_base
;
2461 relsize
= current
->reloc_count
* external_reloc_size
;
2462 reloc_size
+= relsize
;
2463 reloc_base
+= relsize
;
2466 current
->rel_filepos
= 0;
2469 sym_base
= reloc_base
+ reloc_size
;
2471 /* At least on Ultrix, the symbol table of an executable file must
2472 be aligned to a page boundary. FIXME: Is this true on other
2474 if ((abfd
->flags
& EXEC_P
) != 0
2475 && (abfd
->flags
& D_PAGED
) != 0)
2476 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
2478 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2480 if ((abfd
->flags
& D_PAGED
) != 0)
2481 text_size
= ecoff_sizeof_headers (abfd
, false);
2489 /* Write section headers to the file. */
2491 buff
= (PTR
) alloca (scnhsz
);
2492 internal_f
.f_nscns
= 0;
2493 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2495 for (current
= abfd
->sections
;
2496 current
!= (asection
*) NULL
;
2497 current
= current
->next
)
2499 struct internal_scnhdr section
;
2502 if (strcmp (current
->name
, REGINFO
) == 0)
2504 BFD_ASSERT (current
->reloc_count
== 0);
2508 ++internal_f
.f_nscns
;
2510 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2512 /* FIXME: is this correct for shared libraries? I think it is
2513 but I have no platform to check. Ian Lance Taylor. */
2514 vma
= bfd_get_section_vma (abfd
, current
);
2515 if (strcmp (current
->name
, _LIB
) == 0)
2516 section
.s_vaddr
= 0;
2518 section
.s_vaddr
= vma
;
2520 section
.s_paddr
= vma
;
2521 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2523 /* If this section is unloadable then the scnptr will be 0. */
2524 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2525 section
.s_scnptr
= 0;
2527 section
.s_scnptr
= current
->filepos
;
2528 section
.s_relptr
= current
->rel_filepos
;
2530 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2531 object file produced by the assembler is supposed to point to
2532 information about how much room is required by objects of
2533 various different sizes. I think this only matters if we
2534 want the linker to compute the best size to use, or
2535 something. I don't know what happens if the information is
2537 section
.s_lnnoptr
= 0;
2539 section
.s_nreloc
= current
->reloc_count
;
2540 section
.s_nlnno
= 0;
2541 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2544 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2545 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2548 if ((section
.s_flags
& STYP_TEXT
) != 0
2549 || ((section
.s_flags
& STYP_RDATA
) != 0
2550 && backend
->rdata_in_text
)
2551 || strcmp (current
->name
, _PDATA
) == 0)
2553 text_size
+= bfd_get_section_size_before_reloc (current
);
2554 if (text_start
== 0 || text_start
> vma
)
2557 else if ((section
.s_flags
& STYP_RDATA
) != 0
2558 || (section
.s_flags
& STYP_DATA
) != 0
2559 || (section
.s_flags
& STYP_LITA
) != 0
2560 || (section
.s_flags
& STYP_LIT8
) != 0
2561 || (section
.s_flags
& STYP_LIT4
) != 0
2562 || (section
.s_flags
& STYP_SDATA
) != 0)
2564 data_size
+= bfd_get_section_size_before_reloc (current
);
2565 if (data_start
== 0 || data_start
> vma
)
2568 else if ((section
.s_flags
& STYP_BSS
) != 0
2569 || (section
.s_flags
& STYP_SBSS
) != 0)
2570 bss_size
+= bfd_get_section_size_before_reloc (current
);
2573 /* Set up the file header. */
2575 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2577 /* We will NOT put a fucking timestamp in the header here. Every
2578 time you put it back, I will come in and take it out again. I'm
2579 sorry. This field does not belong here. We fill it with a 0 so
2580 it compares the same but is not a reasonable time. --
2582 internal_f
.f_timdat
= 0;
2584 if (bfd_get_symcount (abfd
) != 0)
2586 /* The ECOFF f_nsyms field is not actually the number of
2587 symbols, it's the size of symbolic information header. */
2588 internal_f
.f_nsyms
= external_hdr_size
;
2589 internal_f
.f_symptr
= sym_base
;
2593 internal_f
.f_nsyms
= 0;
2594 internal_f
.f_symptr
= 0;
2597 internal_f
.f_opthdr
= aoutsz
;
2599 internal_f
.f_flags
= F_LNNO
;
2600 if (reloc_size
== 0)
2601 internal_f
.f_flags
|= F_RELFLG
;
2602 if (bfd_get_symcount (abfd
) == 0)
2603 internal_f
.f_flags
|= F_LSYMS
;
2604 if (abfd
->flags
& EXEC_P
)
2605 internal_f
.f_flags
|= F_EXEC
;
2607 if (! abfd
->xvec
->byteorder_big_p
)
2608 internal_f
.f_flags
|= F_AR32WR
;
2610 internal_f
.f_flags
|= F_AR32W
;
2612 /* Set up the ``optional'' header. */
2613 if ((abfd
->flags
& D_PAGED
) != 0)
2614 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2616 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2618 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
2619 linker happy. But, is it right? */
2620 internal_a
.vstamp
= 0x20a;
2622 /* At least on Ultrix, these have to be rounded to page boundaries.
2623 FIXME: Is this true on other platforms? */
2624 if ((abfd
->flags
& D_PAGED
) != 0)
2626 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2627 internal_a
.text_start
= text_start
&~ (round
- 1);
2628 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2629 internal_a
.data_start
= data_start
&~ (round
- 1);
2633 internal_a
.tsize
= text_size
;
2634 internal_a
.text_start
= text_start
;
2635 internal_a
.dsize
= data_size
;
2636 internal_a
.data_start
= data_start
;
2639 /* On Ultrix, the initial portions of the .sbss and .bss segments
2640 are at the end of the data section. The bsize field in the
2641 optional header records how many bss bytes are required beyond
2642 those in the data section. The value is not rounded to a page
2644 if (bss_size
< internal_a
.dsize
- data_size
)
2647 bss_size
-= internal_a
.dsize
- data_size
;
2648 internal_a
.bsize
= bss_size
;
2649 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2651 internal_a
.entry
= bfd_get_start_address (abfd
);
2653 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2655 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2656 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2657 for (i
= 0; i
< 4; i
++)
2658 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2660 /* Write out the file header and the optional header. */
2662 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2665 buff
= (PTR
) alloca (filhsz
);
2666 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2667 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2670 buff
= (PTR
) alloca (aoutsz
);
2671 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2672 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2675 /* Build the external symbol information. This must be done before
2676 writing out the relocs so that we know the symbol indices. */
2677 symhdr
->iextMax
= 0;
2678 symhdr
->issExtMax
= 0;
2679 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2680 debug
->ssext
= debug
->ssext_end
= NULL
;
2681 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2682 (((abfd
->flags
& EXEC_P
) == 0)
2684 ecoff_get_extr
, ecoff_set_index
)
2688 /* Write out the relocs. */
2689 for (current
= abfd
->sections
;
2690 current
!= (asection
*) NULL
;
2691 current
= current
->next
)
2693 arelent
**reloc_ptr_ptr
;
2694 arelent
**reloc_end
;
2697 if (current
->reloc_count
== 0)
2700 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2703 bfd_error
= no_memory
;
2707 reloc_ptr_ptr
= current
->orelocation
;
2708 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2709 out_ptr
= (char *) buff
;
2711 reloc_ptr_ptr
< reloc_end
;
2712 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2716 struct internal_reloc in
;
2718 memset (&in
, 0, sizeof in
);
2720 reloc
= *reloc_ptr_ptr
;
2721 sym
= *reloc
->sym_ptr_ptr
;
2723 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
2724 in
.r_type
= reloc
->howto
->type
;
2726 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2728 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2735 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2736 if (strcmp (name
, ".text") == 0)
2737 in
.r_symndx
= RELOC_SECTION_TEXT
;
2738 else if (strcmp (name
, ".rdata") == 0)
2739 in
.r_symndx
= RELOC_SECTION_RDATA
;
2740 else if (strcmp (name
, ".data") == 0)
2741 in
.r_symndx
= RELOC_SECTION_DATA
;
2742 else if (strcmp (name
, ".sdata") == 0)
2743 in
.r_symndx
= RELOC_SECTION_SDATA
;
2744 else if (strcmp (name
, ".sbss") == 0)
2745 in
.r_symndx
= RELOC_SECTION_SBSS
;
2746 else if (strcmp (name
, ".bss") == 0)
2747 in
.r_symndx
= RELOC_SECTION_BSS
;
2748 else if (strcmp (name
, ".init") == 0)
2749 in
.r_symndx
= RELOC_SECTION_INIT
;
2750 else if (strcmp (name
, ".lit8") == 0)
2751 in
.r_symndx
= RELOC_SECTION_LIT8
;
2752 else if (strcmp (name
, ".lit4") == 0)
2753 in
.r_symndx
= RELOC_SECTION_LIT4
;
2754 else if (strcmp (name
, ".xdata") == 0)
2755 in
.r_symndx
= RELOC_SECTION_XDATA
;
2756 else if (strcmp (name
, ".pdata") == 0)
2757 in
.r_symndx
= RELOC_SECTION_PDATA
;
2758 else if (strcmp (name
, ".fini") == 0)
2759 in
.r_symndx
= RELOC_SECTION_FINI
;
2760 else if (strcmp (name
, ".lita") == 0)
2761 in
.r_symndx
= RELOC_SECTION_LITA
;
2762 else if (strcmp (name
, "*ABS*") == 0)
2763 in
.r_symndx
= RELOC_SECTION_ABS
;
2769 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2771 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2774 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2776 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
2777 != external_reloc_size
* current
->reloc_count
)
2779 bfd_release (abfd
, buff
);
2782 /* Write out the symbolic debugging information. */
2783 if (bfd_get_symcount (abfd
) > 0)
2785 /* Write out the debugging information. */
2786 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2787 ecoff_data (abfd
)->sym_filepos
)
2791 else if ((abfd
->flags
& EXEC_P
) != 0
2792 && (abfd
->flags
& D_PAGED
) != 0)
2796 /* A demand paged executable must occupy an even number of
2798 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2801 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2803 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2806 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2813 /* Archive handling. ECOFF uses what appears to be a unique type of
2814 archive header (which I call an armap). The byte ordering of the
2815 armap and the contents are encoded in the name of the armap itself.
2816 At least for now, we only support archives with the same byte
2817 ordering in the armap and the contents.
2819 The first four bytes in the armap are the number of symbol
2820 definitions. This is always a power of two.
2822 This is followed by the symbol definitions. Each symbol definition
2823 occupies 8 bytes. The first four bytes are the offset from the
2824 start of the armap strings to the null-terminated string naming
2825 this symbol. The second four bytes are the file offset to the
2826 archive member which defines this symbol. If the second four bytes
2827 are 0, then this is not actually a symbol definition, and it should
2830 The symbols are hashed into the armap with a closed hashing scheme.
2831 See the functions below for the details of the algorithm.
2833 We could use the hash table when looking up symbols in a library.
2834 This would require a new BFD target entry point to replace the
2835 bfd_get_next_mapent function used by the linker.
2837 After the symbol definitions comes four bytes holding the size of
2838 the string table, followed by the string table itself. */
2840 /* The name of an archive headers looks like this:
2841 __________E[BL]E[BL]_ (with a trailing space).
2842 The trailing space is changed to an X if the archive is changed to
2843 indicate that the armap is out of date.
2845 The Alpha seems to use ________64E[BL]E[BL]_. */
2847 #define ARMAP_BIG_ENDIAN 'B'
2848 #define ARMAP_LITTLE_ENDIAN 'L'
2849 #define ARMAP_MARKER 'E'
2850 #define ARMAP_START_LENGTH 10
2851 #define ARMAP_HEADER_MARKER_INDEX 10
2852 #define ARMAP_HEADER_ENDIAN_INDEX 11
2853 #define ARMAP_OBJECT_MARKER_INDEX 12
2854 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2855 #define ARMAP_END_INDEX 14
2856 #define ARMAP_END "_ "
2858 /* This is a magic number used in the hashing algorithm. */
2859 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2861 /* This returns the hash value to use for a string. It also sets
2862 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2863 is the number of entries in the hash table, and HLOG is the log
2867 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2869 unsigned int *rehash
;
2877 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2878 hash
*= ARMAP_HASH_MAGIC
;
2879 *rehash
= (hash
& (size
- 1)) | 1;
2880 return hash
>> (32 - hlog
);
2883 /* Read in the armap. */
2886 ecoff_slurp_armap (abfd
)
2891 struct areltdata
*mapdata
;
2892 bfd_size_type parsed_size
;
2894 struct artdata
*ardata
;
2897 struct symdef
*symdef_ptr
;
2900 /* Get the name of the first element. */
2901 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2907 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2909 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2910 standard COFF armap. We could move the ECOFF armap stuff into
2911 bfd_slurp_armap, but that seems inappropriate since no other
2912 target uses this format. Instead, we check directly for a COFF
2914 if (strncmp (nextname
, "/ ", 16) == 0)
2915 return bfd_slurp_armap (abfd
);
2917 /* See if the first element is an armap. */
2918 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2919 ARMAP_START_LENGTH
) != 0
2920 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2921 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2922 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2923 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2924 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2925 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2926 || strncmp (nextname
+ ARMAP_END_INDEX
,
2927 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2929 bfd_has_map (abfd
) = false;
2933 /* Make sure we have the right byte ordering. */
2934 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2935 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2936 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2937 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2939 bfd_error
= wrong_format
;
2943 /* Read in the armap. */
2944 ardata
= bfd_ardata (abfd
);
2945 mapdata
= snarf_ar_hdr (abfd
);
2946 if (mapdata
== (struct areltdata
*) NULL
)
2948 parsed_size
= mapdata
->parsed_size
;
2949 bfd_release (abfd
, (PTR
) mapdata
);
2951 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2952 if (raw_armap
== (char *) NULL
)
2954 bfd_error
= no_memory
;
2958 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
2960 bfd_error
= malformed_archive
;
2961 bfd_release (abfd
, (PTR
) raw_armap
);
2965 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
2967 ardata
->symdef_count
= 0;
2968 ardata
->cache
= (struct ar_cache
*) NULL
;
2970 /* This code used to overlay the symdefs over the raw archive data,
2971 but that doesn't work on a 64 bit host. */
2973 stringbase
= raw_armap
+ count
* 8 + 8;
2975 #ifdef CHECK_ARMAP_HASH
2979 /* Double check that I have the hashing algorithm right by making
2980 sure that every symbol can be looked up successfully. */
2982 for (i
= 1; i
< count
; i
<<= 1)
2984 BFD_ASSERT (i
== count
);
2986 raw_ptr
= raw_armap
+ 4;
2987 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2989 unsigned int name_offset
, file_offset
;
2990 unsigned int hash
, rehash
, srch
;
2992 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
2993 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
2994 if (file_offset
== 0)
2996 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3001 /* See if we can rehash to this location. */
3002 for (srch
= (hash
+ rehash
) & (count
- 1);
3003 srch
!= hash
&& srch
!= i
;
3004 srch
= (srch
+ rehash
) & (count
- 1))
3005 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3007 BFD_ASSERT (srch
== i
);
3011 #endif /* CHECK_ARMAP_HASH */
3013 raw_ptr
= raw_armap
+ 4;
3014 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3015 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3016 ++ardata
->symdef_count
;
3018 symdef_ptr
= ((struct symdef
*)
3020 ardata
->symdef_count
* sizeof (struct symdef
)));
3021 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3023 raw_ptr
= raw_armap
+ 4;
3024 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3026 unsigned int name_offset
, file_offset
;
3028 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3029 if (file_offset
== 0)
3031 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3032 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3033 symdef_ptr
->file_offset
= file_offset
;
3037 ardata
->first_file_filepos
= bfd_tell (abfd
);
3038 /* Pad to an even boundary. */
3039 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3041 bfd_has_map (abfd
) = true;
3046 /* Write out an armap. */
3049 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3051 unsigned int elength
;
3053 unsigned int orl_count
;
3056 unsigned int hashsize
, hashlog
;
3057 unsigned int symdefsize
;
3059 unsigned int stringsize
;
3060 unsigned int mapsize
;
3063 struct stat statbuf
;
3066 bfd_byte
*hashtable
;
3070 /* Ultrix appears to use as a hash table size the least power of two
3071 greater than twice the number of entries. */
3072 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3074 hashsize
= 1 << hashlog
;
3076 symdefsize
= hashsize
* 8;
3078 stringsize
= stridx
+ padit
;
3080 /* Include 8 bytes to store symdefsize and stringsize in output. */
3081 mapsize
= symdefsize
+ stringsize
+ 8;
3083 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3085 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3087 /* Work out the ECOFF armap name. */
3088 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3089 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3090 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3091 (abfd
->xvec
->header_byteorder_big_p
3093 : ARMAP_LITTLE_ENDIAN
);
3094 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3095 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3096 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3097 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3099 /* Write the timestamp of the archive header to be just a little bit
3100 later than the timestamp of the file, otherwise the linker will
3101 complain that the index is out of date. Actually, the Ultrix
3102 linker just checks the archive name; the GNU linker may check the
3104 stat (abfd
->filename
, &statbuf
);
3105 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3107 /* The DECstation uses zeroes for the uid, gid and mode of the
3109 hdr
.ar_uid
[0] = '0';
3110 hdr
.ar_gid
[0] = '0';
3111 hdr
.ar_mode
[0] = '0';
3113 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3115 hdr
.ar_fmag
[0] = '`';
3116 hdr
.ar_fmag
[1] = '\n';
3118 /* Turn all null bytes in the header into spaces. */
3119 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3120 if (((char *)(&hdr
))[i
] == '\0')
3121 (((char *)(&hdr
))[i
]) = ' ';
3123 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3124 != sizeof (struct ar_hdr
))
3127 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3128 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3131 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3133 current
= abfd
->archive_head
;
3135 for (i
= 0; i
< orl_count
; i
++)
3137 unsigned int hash
, rehash
;
3139 /* Advance firstreal to the file position of this archive
3141 if (((bfd
*) map
[i
].pos
) != last_elt
)
3145 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3146 firstreal
+= firstreal
% 2;
3147 current
= current
->next
;
3149 while (current
!= (bfd
*) map
[i
].pos
);
3154 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3155 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3159 /* The desired slot is already taken. */
3160 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3162 srch
= (srch
+ rehash
) & (hashsize
- 1))
3163 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3166 BFD_ASSERT (srch
!= hash
);
3171 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3172 (PTR
) (hashtable
+ hash
* 8));
3173 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3174 (PTR
) (hashtable
+ hash
* 8 + 4));
3177 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3180 bfd_release (abfd
, hashtable
);
3182 /* Now write the strings. */
3183 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3184 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3186 for (i
= 0; i
< orl_count
; i
++)
3190 len
= strlen (*map
[i
].name
) + 1;
3191 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3195 /* The spec sez this should be a newline. But in order to be
3196 bug-compatible for DECstation ar we use a null. */
3199 if (bfd_write ("", 1, 1, abfd
) != 1)
3206 /* See whether this BFD is an archive. If it is, read in the armap
3207 and the extended name table. */
3210 ecoff_archive_p (abfd
)
3213 char armag
[SARMAG
+ 1];
3215 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3216 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3218 bfd_error
= wrong_format
;
3219 return (bfd_target
*) NULL
;
3222 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3223 involves a cast, we can't do it as the left operand of
3225 abfd
->tdata
.aout_ar_data
=
3226 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3228 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3230 bfd_error
= no_memory
;
3231 return (bfd_target
*) NULL
;
3234 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3236 if (ecoff_slurp_armap (abfd
) == false
3237 || ecoff_slurp_extended_name_table (abfd
) == false)
3239 bfd_release (abfd
, bfd_ardata (abfd
));
3240 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3241 return (bfd_target
*) NULL
;