1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
48 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
49 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
50 asymbol
*asym
, int ext
,
51 asymbol
**indirect_ptr_ptr
));
52 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
54 RNDXR
*rndx
, long isym
,
56 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
58 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
60 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
61 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
62 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
63 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
64 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
69 /* This stuff is somewhat copied from coffcode.h. */
71 static asection bfd_debug_section
= { "*DEBUG*" };
73 /* Create an ECOFF object. */
79 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
80 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
81 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
83 bfd_set_error (bfd_error_no_memory
);
90 /* This is a hook called by coff_real_object_p to create any backend
91 specific information. */
94 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
99 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
100 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
101 ecoff_data_type
*ecoff
;
104 if (ecoff_mkobject (abfd
) == false)
107 ecoff
= ecoff_data (abfd
);
109 ecoff
->sym_filepos
= internal_f
->f_symptr
;
111 /* Create the .reginfo section to give programs outside BFD a way to
112 see the information stored in the a.out header. See the comment
114 regsec
= bfd_make_section (abfd
, REGINFO
);
118 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
122 ecoff
->text_start
= internal_a
->text_start
;
123 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
124 ecoff
->gp
= internal_a
->gp_value
;
125 ecoff
->gprmask
= internal_a
->gprmask
;
126 for (i
= 0; i
< 4; i
++)
127 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
128 ecoff
->fprmask
= internal_a
->fprmask
;
129 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
130 abfd
->flags
|= D_PAGED
;
133 /* It turns out that no special action is required by the MIPS or
134 Alpha ECOFF backends. They have different information in the
135 a.out header, but we just copy it all (e.g., gprmask, cprmask and
136 fprmask) and let the swapping routines ensure that only relevant
137 information is written out. */
142 /* This is a hook needed by SCO COFF, but we have nothing to do. */
146 ecoff_make_section_hook (abfd
, name
)
150 return (asection
*) NULL
;
153 /* Initialize a new section. */
156 ecoff_new_section_hook (abfd
, section
)
160 /* For the .pdata section, which has a special meaning on the Alpha,
161 we set the alignment to 8. We correct this later in
162 ecoff_compute_section_file_positions. We do this hackery because
163 we need to know the exact unaligned size of the .pdata section in
164 order to set the lnnoptr field correctly. */
165 if (strcmp (section
->name
, _PDATA
) == 0)
166 section
->alignment_power
= 3;
168 section
->alignment_power
= abfd
->xvec
->align_power_min
;
170 if (strcmp (section
->name
, _TEXT
) == 0)
171 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
172 else if (strcmp (section
->name
, _DATA
) == 0
173 || strcmp (section
->name
, _SDATA
) == 0)
174 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
175 else if (strcmp (section
->name
, _RDATA
) == 0
176 || strcmp (section
->name
, _LIT8
) == 0
177 || strcmp (section
->name
, _LIT4
) == 0)
178 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
179 else if (strcmp (section
->name
, _BSS
) == 0
180 || strcmp (section
->name
, _SBSS
) == 0)
181 section
->flags
|= SEC_ALLOC
;
182 else if (strcmp (section
->name
, _LIB
) == 0)
184 /* An Irix 4 shared libary. */
185 section
->flags
|= SEC_SHARED_LIBRARY
;
187 else if (strcmp (section
->name
, REGINFO
) == 0)
189 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
190 section completely alone. */
191 section
->flags
|= (SEC_SHARED_LIBRARY
194 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
197 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
198 uncertain about .init on some systems and I don't know how shared
204 /* Determine the machine architecture and type. This is called from
205 the generic COFF routines. It is the inverse of ecoff_get_magic,
206 below. This could be an ECOFF backend routine, with one version
207 for each target, but there aren't all that many ECOFF targets. */
210 ecoff_set_arch_mach_hook (abfd
, filehdr
)
214 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
215 enum bfd_architecture arch
;
218 switch (internal_f
->f_magic
)
221 case MIPS_MAGIC_LITTLE
:
223 arch
= bfd_arch_mips
;
227 case MIPS_MAGIC_LITTLE2
:
228 case MIPS_MAGIC_BIG2
:
229 /* MIPS ISA level 2: the r6000 */
230 arch
= bfd_arch_mips
;
234 case MIPS_MAGIC_LITTLE3
:
235 case MIPS_MAGIC_BIG3
:
236 /* MIPS ISA level 3: the r4000 */
237 arch
= bfd_arch_mips
;
242 arch
= bfd_arch_alpha
;
247 arch
= bfd_arch_obscure
;
252 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
255 /* Get the magic number to use based on the architecture and machine.
256 This is the inverse of ecoff_set_arch_mach_hook, above. */
259 ecoff_get_magic (abfd
)
264 switch (bfd_get_arch (abfd
))
267 switch (bfd_get_mach (abfd
))
272 big
= MIPS_MAGIC_BIG
;
273 little
= MIPS_MAGIC_LITTLE
;
277 big
= MIPS_MAGIC_BIG2
;
278 little
= MIPS_MAGIC_LITTLE2
;
282 big
= MIPS_MAGIC_BIG3
;
283 little
= MIPS_MAGIC_LITTLE3
;
287 return abfd
->xvec
->byteorder_big_p
? big
: little
;
298 /* Get the section s_flags to use for a section. */
301 ecoff_sec_to_styp_flags (name
, flags
)
309 if (strcmp (name
, _TEXT
) == 0)
311 else if (strcmp (name
, _DATA
) == 0)
313 else if (strcmp (name
, _SDATA
) == 0)
315 else if (strcmp (name
, _RDATA
) == 0)
317 else if (strcmp (name
, _LITA
) == 0)
319 else if (strcmp (name
, _LIT8
) == 0)
321 else if (strcmp (name
, _LIT4
) == 0)
323 else if (strcmp (name
, _BSS
) == 0)
325 else if (strcmp (name
, _SBSS
) == 0)
327 else if (strcmp (name
, _INIT
) == 0)
328 styp
= STYP_ECOFF_INIT
;
329 else if (strcmp (name
, _FINI
) == 0)
330 styp
= STYP_ECOFF_FINI
;
331 else if (strcmp (name
, _PDATA
) == 0)
333 else if (strcmp (name
, _XDATA
) == 0)
335 else if (strcmp (name
, _LIB
) == 0)
336 styp
= STYP_ECOFF_LIB
;
337 else if (flags
& SEC_CODE
)
339 else if (flags
& SEC_DATA
)
341 else if (flags
& SEC_READONLY
)
343 else if (flags
& SEC_LOAD
)
348 if (flags
& SEC_NEVER_LOAD
)
354 /* Get the BFD flags to use for a section. */
358 ecoff_styp_to_sec_flags (abfd
, hdr
)
362 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
363 long styp_flags
= internal_s
->s_flags
;
364 flagword sec_flags
=0;
366 if (styp_flags
& STYP_NOLOAD
)
367 sec_flags
|= SEC_NEVER_LOAD
;
369 /* For 386 COFF, at least, an unloadable text or data section is
370 actually a shared library section. */
371 if ((styp_flags
& STYP_TEXT
)
372 || (styp_flags
& STYP_ECOFF_INIT
)
373 || (styp_flags
& STYP_ECOFF_FINI
))
375 if (sec_flags
& SEC_NEVER_LOAD
)
376 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
378 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
380 else if ((styp_flags
& STYP_DATA
)
381 || (styp_flags
& STYP_RDATA
)
382 || (styp_flags
& STYP_SDATA
)
383 || styp_flags
== STYP_PDATA
384 || styp_flags
== STYP_XDATA
)
386 if (sec_flags
& SEC_NEVER_LOAD
)
387 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
389 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
390 if ((styp_flags
& STYP_RDATA
)
391 || styp_flags
== STYP_PDATA
)
392 sec_flags
|= SEC_READONLY
;
394 else if ((styp_flags
& STYP_BSS
)
395 || (styp_flags
& STYP_SBSS
))
397 sec_flags
|= SEC_ALLOC
;
399 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
401 sec_flags
|= SEC_NEVER_LOAD
;
403 else if ((styp_flags
& STYP_LITA
)
404 || (styp_flags
& STYP_LIT8
)
405 || (styp_flags
& STYP_LIT4
))
407 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
409 else if (styp_flags
& STYP_ECOFF_LIB
)
411 sec_flags
|= SEC_SHARED_LIBRARY
;
415 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
421 /* Routines to swap auxiliary information in and out. I am assuming
422 that the auxiliary information format is always going to be target
425 /* Swap in a type information record.
426 BIGEND says whether AUX symbols are big-endian or little-endian; this
427 info comes from the file header record (fh-fBigendian). */
430 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
432 struct tir_ext
*ext_copy
;
435 struct tir_ext ext
[1];
437 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
439 /* now the fun stuff... */
441 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
442 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
443 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
444 >> TIR_BITS1_BT_SH_BIG
;
445 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
446 >> TIR_BITS_TQ4_SH_BIG
;
447 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
448 >> TIR_BITS_TQ5_SH_BIG
;
449 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
450 >> TIR_BITS_TQ0_SH_BIG
;
451 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
452 >> TIR_BITS_TQ1_SH_BIG
;
453 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
454 >> TIR_BITS_TQ2_SH_BIG
;
455 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
456 >> TIR_BITS_TQ3_SH_BIG
;
458 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
459 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
460 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
461 >> TIR_BITS1_BT_SH_LITTLE
;
462 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
463 >> TIR_BITS_TQ4_SH_LITTLE
;
464 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
465 >> TIR_BITS_TQ5_SH_LITTLE
;
466 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
467 >> TIR_BITS_TQ0_SH_LITTLE
;
468 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
469 >> TIR_BITS_TQ1_SH_LITTLE
;
470 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
471 >> TIR_BITS_TQ2_SH_LITTLE
;
472 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
473 >> TIR_BITS_TQ3_SH_LITTLE
;
477 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
482 /* Swap out a type information record.
483 BIGEND says whether AUX symbols are big-endian or little-endian; this
484 info comes from the file header record (fh-fBigendian). */
487 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
494 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
496 /* now the fun stuff... */
498 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
499 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
500 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
501 & TIR_BITS1_BT_BIG
));
502 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
504 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
505 & TIR_BITS_TQ5_BIG
));
506 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
508 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
509 & TIR_BITS_TQ1_BIG
));
510 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
512 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
513 & TIR_BITS_TQ3_BIG
));
515 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
516 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
517 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
518 & TIR_BITS1_BT_LITTLE
));
519 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
520 & TIR_BITS_TQ4_LITTLE
)
521 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
522 & TIR_BITS_TQ5_LITTLE
));
523 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
524 & TIR_BITS_TQ0_LITTLE
)
525 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
526 & TIR_BITS_TQ1_LITTLE
));
527 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
528 & TIR_BITS_TQ2_LITTLE
)
529 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
530 & TIR_BITS_TQ3_LITTLE
));
534 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
539 /* Swap in a relative symbol record. BIGEND says whether it is in
540 big-endian or little-endian format.*/
543 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
545 struct rndx_ext
*ext_copy
;
548 struct rndx_ext ext
[1];
550 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
552 /* now the fun stuff... */
554 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
555 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
556 >> RNDX_BITS1_RFD_SH_BIG
);
557 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
558 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
559 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
560 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
562 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
563 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
564 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
565 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
566 >> RNDX_BITS1_INDEX_SH_LITTLE
)
567 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
568 | ((unsigned int) ext
->r_bits
[3]
569 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
573 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
578 /* Swap out a relative symbol record. BIGEND says whether it is in
579 big-endian or little-endian format.*/
582 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
585 struct rndx_ext
*ext
;
589 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
591 /* now the fun stuff... */
593 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
594 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
595 & RNDX_BITS1_RFD_BIG
)
596 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
597 & RNDX_BITS1_INDEX_BIG
));
598 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
599 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
601 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
602 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
603 & RNDX_BITS1_RFD_LITTLE
)
604 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
605 & RNDX_BITS1_INDEX_LITTLE
));
606 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
607 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
611 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
616 /* Read in the symbolic header for an ECOFF object file. */
619 ecoff_slurp_symbolic_header (abfd
)
622 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
623 bfd_size_type external_hdr_size
;
625 HDRR
*internal_symhdr
;
627 /* See if we've already read it in. */
628 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
629 backend
->debug_swap
.sym_magic
)
632 /* See whether there is a symbolic header. */
633 if (ecoff_data (abfd
)->sym_filepos
== 0)
635 bfd_get_symcount (abfd
) = 0;
639 /* At this point bfd_get_symcount (abfd) holds the number of symbols
640 as read from the file header, but on ECOFF this is always the
641 size of the symbolic information header. It would be cleaner to
642 handle this when we first read the file in coffgen.c. */
643 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
644 if (bfd_get_symcount (abfd
) != external_hdr_size
)
646 bfd_set_error (bfd_error_bad_value
);
650 /* Read the symbolic information header. */
651 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
654 bfd_set_error (bfd_error_no_memory
);
658 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
659 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
660 != external_hdr_size
))
662 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
663 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
665 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
667 bfd_set_error (bfd_error_bad_value
);
671 /* Now we can get the correct number of symbols. */
672 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
673 + internal_symhdr
->iextMax
);
684 /* Read in and swap the important symbolic information for an ECOFF
685 object file. This is called by gdb. */
688 ecoff_slurp_symbolic_info (abfd
)
691 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
692 HDRR
*internal_symhdr
;
693 bfd_size_type raw_base
;
694 bfd_size_type raw_size
;
696 bfd_size_type external_fdr_size
;
700 bfd_size_type raw_end
;
701 bfd_size_type cb_end
;
703 /* Check whether we've already gotten it, and whether there's any to
705 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
707 if (ecoff_data (abfd
)->sym_filepos
== 0)
709 bfd_get_symcount (abfd
) = 0;
713 if (! ecoff_slurp_symbolic_header (abfd
))
716 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
718 /* Read all the symbolic information at once. */
719 raw_base
= (ecoff_data (abfd
)->sym_filepos
720 + backend
->debug_swap
.external_hdr_size
);
722 /* Alpha ecoff makes the determination of raw_size difficult. It has
723 an undocumented debug data section between the symhdr and the first
724 documented section. And the ordering of the sections varies between
725 statically and dynamically linked executables.
726 If bfd supports SEEK_END someday, this code could be simplified. */
730 #define UPDATE_RAW_END(start, count, size) \
731 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
732 if (cb_end > raw_end) \
735 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
736 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
737 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
738 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
739 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
740 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
741 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
742 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
743 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
744 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
745 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
747 #undef UPDATE_RAW_END
749 raw_size
= raw_end
- raw_base
;
752 ecoff_data (abfd
)->sym_filepos
= 0;
755 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
758 bfd_set_error (bfd_error_no_memory
);
762 (ecoff_data (abfd
)->sym_filepos
763 + backend
->debug_swap
.external_hdr_size
),
765 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
767 bfd_release (abfd
, raw
);
771 ecoff_data (abfd
)->raw_syments
= raw
;
773 /* Get pointers for the numeric offsets in the HDRR structure. */
774 #define FIX(off1, off2, type) \
775 if (internal_symhdr->off1 == 0) \
776 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
778 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
779 + internal_symhdr->off1 \
781 FIX (cbLineOffset
, line
, unsigned char *);
782 FIX (cbDnOffset
, external_dnr
, PTR
);
783 FIX (cbPdOffset
, external_pdr
, PTR
);
784 FIX (cbSymOffset
, external_sym
, PTR
);
785 FIX (cbOptOffset
, external_opt
, PTR
);
786 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
787 FIX (cbSsOffset
, ss
, char *);
788 FIX (cbSsExtOffset
, ssext
, char *);
789 FIX (cbFdOffset
, external_fdr
, PTR
);
790 FIX (cbRfdOffset
, external_rfd
, PTR
);
791 FIX (cbExtOffset
, external_ext
, PTR
);
794 /* I don't want to always swap all the data, because it will just
795 waste time and most programs will never look at it. The only
796 time the linker needs most of the debugging information swapped
797 is when linking big-endian and little-endian MIPS object files
798 together, which is not a common occurrence.
800 We need to look at the fdr to deal with a lot of information in
801 the symbols, so we swap them here. */
802 ecoff_data (abfd
)->debug_info
.fdr
=
803 (struct fdr
*) bfd_alloc (abfd
,
804 (internal_symhdr
->ifdMax
*
805 sizeof (struct fdr
)));
806 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
808 bfd_set_error (bfd_error_no_memory
);
811 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
812 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
813 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
814 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
815 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
816 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
821 /* ECOFF symbol table routines. The ECOFF symbol table is described
822 in gcc/mips-tfile.c. */
824 /* ECOFF uses two common sections. One is the usual one, and the
825 other is for small objects. All the small objects are kept
826 together, and then referenced via the gp pointer, which yields
827 faster assembler code. This is what we use for the small common
829 static asection ecoff_scom_section
;
830 static asymbol ecoff_scom_symbol
;
831 static asymbol
*ecoff_scom_symbol_ptr
;
833 /* Create an empty symbol. */
836 ecoff_make_empty_symbol (abfd
)
839 ecoff_symbol_type
*new;
841 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
842 if (new == (ecoff_symbol_type
*) NULL
)
844 bfd_set_error (bfd_error_no_memory
);
845 return (asymbol
*) NULL
;
847 memset ((PTR
) new, 0, sizeof *new);
848 new->symbol
.section
= (asection
*) NULL
;
849 new->fdr
= (FDR
*) NULL
;
852 new->symbol
.the_bfd
= abfd
;
856 /* Set the BFD flags and section for an ECOFF symbol. */
859 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
864 asymbol
**indirect_ptr_ptr
;
866 asym
->the_bfd
= abfd
;
867 asym
->value
= ecoff_sym
->value
;
868 asym
->section
= &bfd_debug_section
;
871 /* An indirect symbol requires two consecutive stabs symbols. */
872 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
874 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
876 /* @@ Stuffing pointers into integers is a no-no.
877 We can usually get away with it if the integer is
878 large enough though. */
879 if (sizeof (asym
) > sizeof (bfd_vma
))
881 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
883 asym
->flags
= BSF_DEBUGGING
;
884 asym
->section
= &bfd_und_section
;
885 *indirect_ptr_ptr
= NULL
;
889 if (ECOFF_IS_STAB (ecoff_sym
)
890 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
892 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
893 asym
->section
= &bfd_ind_section
;
894 /* Pass this symbol on to the next call to this function. */
895 *indirect_ptr_ptr
= asym
;
899 /* Most symbol types are just for debugging. */
900 switch (ecoff_sym
->st
)
909 if (ECOFF_IS_STAB (ecoff_sym
))
911 asym
->flags
= BSF_DEBUGGING
;
916 asym
->flags
= BSF_DEBUGGING
;
921 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
923 asym
->flags
= BSF_LOCAL
;
924 switch (ecoff_sym
->sc
)
927 /* Used for compiler generated labels. Leave them in the
928 debugging section, and mark them as local. If BSF_DEBUGGING
929 is set, then nm does not display them for some reason. If no
930 flags are set then the linker whines about them. */
931 asym
->flags
= BSF_LOCAL
;
934 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
935 asym
->value
-= asym
->section
->vma
;
938 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
939 asym
->value
-= asym
->section
->vma
;
942 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
943 asym
->value
-= asym
->section
->vma
;
946 asym
->flags
= BSF_DEBUGGING
;
949 asym
->section
= &bfd_abs_section
;
952 asym
->section
= &bfd_und_section
;
962 asym
->flags
= BSF_DEBUGGING
;
965 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
966 asym
->value
-= asym
->section
->vma
;
969 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
970 asym
->value
-= asym
->section
->vma
;
973 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
974 asym
->value
-= asym
->section
->vma
;
977 asym
->flags
= BSF_DEBUGGING
;
980 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
982 asym
->section
= &bfd_com_section
;
988 if (ecoff_scom_section
.name
== NULL
)
990 /* Initialize the small common section. */
991 ecoff_scom_section
.name
= SCOMMON
;
992 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
993 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
994 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
995 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
996 ecoff_scom_symbol
.name
= SCOMMON
;
997 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
998 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
999 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
1001 asym
->section
= &ecoff_scom_section
;
1006 asym
->flags
= BSF_DEBUGGING
;
1009 asym
->section
= &bfd_und_section
;
1014 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1015 asym
->value
-= asym
->section
->vma
;
1020 asym
->flags
= BSF_DEBUGGING
;
1023 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1024 asym
->value
-= asym
->section
->vma
;
1030 /* Look for special constructors symbols and make relocation entries
1031 in a special construction section. These are produced by the
1032 -fgnu-linker argument to g++. */
1033 if (ECOFF_IS_STAB (ecoff_sym
))
1035 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1047 arelent_chain
*reloc_chain
;
1048 unsigned int bitsize
;
1050 /* Get a section with the same name as the symbol (usually
1051 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1052 name ___CTOR_LIST (three underscores). We need
1053 __CTOR_LIST (two underscores), since ECOFF doesn't use
1054 a leading underscore. This should be handled by gcc,
1055 but instead we do it here. Actually, this should all
1056 be done differently anyhow. */
1057 name
= bfd_asymbol_name (asym
);
1058 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1063 section
= bfd_get_section_by_name (abfd
, name
);
1064 if (section
== (asection
*) NULL
)
1068 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1071 bfd_set_error (bfd_error_no_memory
);
1074 strcpy (copy
, name
);
1075 section
= bfd_make_section (abfd
, copy
);
1078 /* Build a reloc pointing to this constructor. */
1080 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1083 bfd_set_error (bfd_error_no_memory
);
1086 reloc_chain
->relent
.sym_ptr_ptr
=
1087 bfd_get_section (asym
)->symbol_ptr_ptr
;
1088 reloc_chain
->relent
.address
= section
->_raw_size
;
1089 reloc_chain
->relent
.addend
= asym
->value
;
1090 reloc_chain
->relent
.howto
=
1091 ecoff_backend (abfd
)->constructor_reloc
;
1093 /* Set up the constructor section to hold the reloc. */
1094 section
->flags
= SEC_CONSTRUCTOR
;
1095 ++section
->reloc_count
;
1097 /* Constructor sections must be rounded to a boundary
1098 based on the bitsize. These are not real sections--
1099 they are handled specially by the linker--so the ECOFF
1100 16 byte alignment restriction does not apply. */
1101 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1102 section
->alignment_power
= 1;
1103 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1104 ++section
->alignment_power
;
1106 reloc_chain
->next
= section
->constructor_chain
;
1107 section
->constructor_chain
= reloc_chain
;
1108 section
->_raw_size
+= bitsize
/ 8;
1110 /* Mark the symbol as a constructor. */
1111 asym
->flags
|= BSF_CONSTRUCTOR
;
1119 /* Read an ECOFF symbol table. */
1122 ecoff_slurp_symbol_table (abfd
)
1125 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1126 const bfd_size_type external_ext_size
1127 = backend
->debug_swap
.external_ext_size
;
1128 const bfd_size_type external_sym_size
1129 = backend
->debug_swap
.external_sym_size
;
1130 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1131 = backend
->debug_swap
.swap_ext_in
;
1132 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1133 = backend
->debug_swap
.swap_sym_in
;
1134 bfd_size_type internal_size
;
1135 ecoff_symbol_type
*internal
;
1136 ecoff_symbol_type
*internal_ptr
;
1137 asymbol
*indirect_ptr
;
1143 /* If we've already read in the symbol table, do nothing. */
1144 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1147 /* Get the symbolic information. */
1148 if (ecoff_slurp_symbolic_info (abfd
) == false)
1150 if (bfd_get_symcount (abfd
) == 0)
1153 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1154 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1155 if (internal
== NULL
)
1157 bfd_set_error (bfd_error_no_memory
);
1161 internal_ptr
= internal
;
1162 indirect_ptr
= NULL
;
1163 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1164 eraw_end
= (eraw_src
1165 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1166 * external_ext_size
));
1167 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1171 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1172 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1173 + internal_esym
.asym
.iss
);
1174 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1175 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1177 /* The alpha uses a negative ifd field for section symbols. */
1178 if (internal_esym
.ifd
>= 0)
1179 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1180 + internal_esym
.ifd
);
1182 internal_ptr
->fdr
= NULL
;
1183 internal_ptr
->local
= false;
1184 internal_ptr
->native
= (PTR
) eraw_src
;
1186 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1188 /* The local symbols must be accessed via the fdr's, because the
1189 string and aux indices are relative to the fdr information. */
1190 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1191 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1192 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1197 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1198 + fdr_ptr
->isymBase
* external_sym_size
);
1199 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1201 lraw_src
< lraw_end
;
1202 lraw_src
+= external_sym_size
, internal_ptr
++)
1206 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1207 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1209 + internal_sym
.iss
);
1210 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1211 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1213 internal_ptr
->fdr
= fdr_ptr
;
1214 internal_ptr
->local
= true;
1215 internal_ptr
->native
= (PTR
) lraw_src
;
1218 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1220 ecoff_data (abfd
)->canonical_symbols
= internal
;
1225 /* Return the amount of space needed for the canonical symbols. */
1228 ecoff_get_symtab_upper_bound (abfd
)
1231 if (! ecoff_slurp_symbolic_info (abfd
))
1234 if (bfd_get_symcount (abfd
) == 0)
1237 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1240 /* Get the canonical symbols. */
1243 ecoff_get_symtab (abfd
, alocation
)
1245 asymbol
**alocation
;
1247 unsigned int counter
= 0;
1248 ecoff_symbol_type
*symbase
;
1249 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1251 if (ecoff_slurp_symbol_table (abfd
) == false)
1253 if (bfd_get_symcount (abfd
) == 0)
1256 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1257 while (counter
< bfd_get_symcount (abfd
))
1259 *(location
++) = symbase
++;
1262 *location
++ = (ecoff_symbol_type
*) NULL
;
1263 return bfd_get_symcount (abfd
);
1266 /* Turn ECOFF type information into a printable string.
1267 ecoff_emit_aggregate and ecoff_type_to_string are from
1268 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1270 /* Write aggregate information to a string. */
1273 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1281 const struct ecoff_debug_swap
* const debug_swap
=
1282 &ecoff_backend (abfd
)->debug_swap
;
1283 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1284 unsigned int ifd
= rndx
->rfd
;
1285 unsigned int indx
= rndx
->index
;
1291 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1292 struct return type of a procedure compiled without -g. */
1293 if (ifd
== 0xffffffff
1294 || (rndx
->rfd
== 0xfff && indx
== 0))
1295 name
= "<undefined>";
1296 else if (indx
== indexNil
)
1302 if (debug_info
->external_rfd
== NULL
)
1303 fdr
= debug_info
->fdr
+ ifd
;
1308 (*debug_swap
->swap_rfd_in
) (abfd
,
1309 ((char *) debug_info
->external_rfd
1310 + ((fdr
->rfdBase
+ ifd
)
1311 * debug_swap
->external_rfd_size
)),
1313 fdr
= debug_info
->fdr
+ rfd
;
1316 indx
+= fdr
->isymBase
;
1318 (*debug_swap
->swap_sym_in
) (abfd
,
1319 ((char *) debug_info
->external_sym
1320 + indx
* debug_swap
->external_sym_size
),
1323 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1327 "%s %s { ifd = %u, index = %lu }",
1330 + debug_info
->symbolic_header
.iextMax
));
1333 /* Convert the type information to string format. */
1336 ecoff_type_to_string (abfd
, fdr
, indx
)
1341 union aux_ext
*aux_ptr
;
1350 unsigned int basic_type
;
1352 static char buffer1
[1024];
1353 static char buffer2
[1024];
1358 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1359 bigendian
= fdr
->fBigendian
;
1361 for (i
= 0; i
< 7; i
++)
1363 qualifiers
[i
].low_bound
= 0;
1364 qualifiers
[i
].high_bound
= 0;
1365 qualifiers
[i
].stride
= 0;
1368 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1369 return "-1 (no type)";
1370 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1372 basic_type
= u
.ti
.bt
;
1373 qualifiers
[0].type
= u
.ti
.tq0
;
1374 qualifiers
[1].type
= u
.ti
.tq1
;
1375 qualifiers
[2].type
= u
.ti
.tq2
;
1376 qualifiers
[3].type
= u
.ti
.tq3
;
1377 qualifiers
[4].type
= u
.ti
.tq4
;
1378 qualifiers
[5].type
= u
.ti
.tq5
;
1379 qualifiers
[6].type
= tqNil
;
1382 * Go get the basic type.
1386 case btNil
: /* undefined */
1390 case btAdr
: /* address - integer same size as pointer */
1391 strcpy (p1
, "address");
1394 case btChar
: /* character */
1395 strcpy (p1
, "char");
1398 case btUChar
: /* unsigned character */
1399 strcpy (p1
, "unsigned char");
1402 case btShort
: /* short */
1403 strcpy (p1
, "short");
1406 case btUShort
: /* unsigned short */
1407 strcpy (p1
, "unsigned short");
1410 case btInt
: /* int */
1414 case btUInt
: /* unsigned int */
1415 strcpy (p1
, "unsigned int");
1418 case btLong
: /* long */
1419 strcpy (p1
, "long");
1422 case btULong
: /* unsigned long */
1423 strcpy (p1
, "unsigned long");
1426 case btFloat
: /* float (real) */
1427 strcpy (p1
, "float");
1430 case btDouble
: /* Double (real) */
1431 strcpy (p1
, "double");
1434 /* Structures add 1-2 aux words:
1435 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1436 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1438 case btStruct
: /* Structure (Record) */
1439 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1440 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1441 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1443 indx
++; /* skip aux words */
1446 /* Unions add 1-2 aux words:
1447 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1448 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1450 case btUnion
: /* Union */
1451 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1452 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1453 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1455 indx
++; /* skip aux words */
1458 /* Enumerations add 1-2 aux words:
1459 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1460 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1462 case btEnum
: /* Enumeration */
1463 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1464 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1465 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1467 indx
++; /* skip aux words */
1470 case btTypedef
: /* defined via a typedef, isymRef points */
1471 strcpy (p1
, "typedef");
1474 case btRange
: /* subrange of int */
1475 strcpy (p1
, "subrange");
1478 case btSet
: /* pascal sets */
1482 case btComplex
: /* fortran complex */
1483 strcpy (p1
, "complex");
1486 case btDComplex
: /* fortran double complex */
1487 strcpy (p1
, "double complex");
1490 case btIndirect
: /* forward or unnamed typedef */
1491 strcpy (p1
, "forward/unamed typedef");
1494 case btFixedDec
: /* Fixed Decimal */
1495 strcpy (p1
, "fixed decimal");
1498 case btFloatDec
: /* Float Decimal */
1499 strcpy (p1
, "float decimal");
1502 case btString
: /* Varying Length Character String */
1503 strcpy (p1
, "string");
1506 case btBit
: /* Aligned Bit String */
1510 case btPicture
: /* Picture */
1511 strcpy (p1
, "picture");
1514 case btVoid
: /* Void */
1515 strcpy (p1
, "void");
1519 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1523 p1
+= strlen (buffer1
);
1526 * If this is a bitfield, get the bitsize.
1532 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1533 sprintf (p1
, " : %d", bitsize
);
1534 p1
+= strlen (buffer1
);
1539 * Deal with any qualifiers.
1541 if (qualifiers
[0].type
!= tqNil
)
1544 * Snarf up any array bounds in the correct order. Arrays
1545 * store 5 successive words in the aux. table:
1546 * word 0 RNDXR to type of the bounds (ie, int)
1547 * word 1 Current file descriptor index
1549 * word 3 high bound (or -1 if [])
1550 * word 4 stride size in bits
1552 for (i
= 0; i
< 7; i
++)
1554 if (qualifiers
[i
].type
== tqArray
)
1556 qualifiers
[i
].low_bound
=
1557 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1558 qualifiers
[i
].high_bound
=
1559 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1560 qualifiers
[i
].stride
=
1561 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1567 * Now print out the qualifiers.
1569 for (i
= 0; i
< 6; i
++)
1571 switch (qualifiers
[i
].type
)
1578 strcpy (p2
, "ptr to ");
1579 p2
+= sizeof ("ptr to ")-1;
1583 strcpy (p2
, "volatile ");
1584 p2
+= sizeof ("volatile ")-1;
1588 strcpy (p2
, "far ");
1589 p2
+= sizeof ("far ")-1;
1593 strcpy (p2
, "func. ret. ");
1594 p2
+= sizeof ("func. ret. ");
1599 int first_array
= i
;
1602 /* Print array bounds reversed (ie, in the order the C
1603 programmer writes them). C is such a fun language.... */
1605 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1608 for (j
= i
; j
>= first_array
; j
--)
1610 strcpy (p2
, "array [");
1611 p2
+= sizeof ("array [")-1;
1612 if (qualifiers
[j
].low_bound
!= 0)
1614 "%ld:%ld {%ld bits}",
1615 (long) qualifiers
[j
].low_bound
,
1616 (long) qualifiers
[j
].high_bound
,
1617 (long) qualifiers
[j
].stride
);
1619 else if (qualifiers
[j
].high_bound
!= -1)
1622 (long) (qualifiers
[j
].high_bound
+ 1),
1623 (long) (qualifiers
[j
].stride
));
1626 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1629 strcpy (p2
, "] of ");
1630 p2
+= sizeof ("] of ")-1;
1638 strcpy (p2
, buffer1
);
1642 /* Return information about ECOFF symbol SYMBOL in RET. */
1646 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1647 bfd
*abfd
; /* Ignored. */
1651 bfd_symbol_info (symbol
, ret
);
1654 /* Print information about an ECOFF symbol. */
1657 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1661 bfd_print_symbol_type how
;
1663 const struct ecoff_debug_swap
* const debug_swap
1664 = &ecoff_backend (abfd
)->debug_swap
;
1665 FILE *file
= (FILE *)filep
;
1669 case bfd_print_symbol_name
:
1670 fprintf (file
, "%s", symbol
->name
);
1672 case bfd_print_symbol_more
:
1673 if (ecoffsymbol (symbol
)->local
)
1677 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1679 fprintf (file
, "ecoff local ");
1680 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1681 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1682 (unsigned) ecoff_sym
.sc
);
1688 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1690 fprintf (file
, "ecoff extern ");
1691 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1692 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1693 (unsigned) ecoff_ext
.asym
.sc
);
1696 case bfd_print_symbol_all
:
1697 /* Print out the symbols in a reasonable way */
1706 if (ecoffsymbol (symbol
)->local
)
1708 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1711 pos
= ((((char *) ecoffsymbol (symbol
)->native
1712 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1713 / debug_swap
->external_sym_size
)
1714 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1721 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1724 pos
= (((char *) ecoffsymbol (symbol
)->native
1725 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1726 / debug_swap
->external_ext_size
);
1727 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1728 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1729 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1732 fprintf (file
, "[%3d] %c ",
1734 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1735 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1736 (unsigned) ecoff_ext
.asym
.st
,
1737 (unsigned) ecoff_ext
.asym
.sc
,
1738 (unsigned) ecoff_ext
.asym
.index
,
1739 jmptbl
, cobol_main
, weakext
,
1742 if (ecoffsymbol (symbol
)->fdr
!= NULL
1743 && ecoff_ext
.asym
.index
!= indexNil
)
1748 bfd_size_type sym_base
;
1749 union aux_ext
*aux_base
;
1751 fdr
= ecoffsymbol (symbol
)->fdr
;
1752 indx
= ecoff_ext
.asym
.index
;
1754 /* sym_base is used to map the fdr relative indices which
1755 appear in the file to the position number which we are
1757 sym_base
= fdr
->isymBase
;
1758 if (ecoffsymbol (symbol
)->local
)
1760 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1762 /* aux_base is the start of the aux entries for this file;
1763 asym.index is an offset from this. */
1764 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1767 /* The aux entries are stored in host byte order; the
1768 order is indicated by a bit in the fdr. */
1769 bigendian
= fdr
->fBigendian
;
1771 /* This switch is basically from gcc/mips-tdump.c */
1772 switch (ecoff_ext
.asym
.st
)
1780 fprintf (file
, "\n End+1 symbol: %ld",
1781 (long) (indx
+ sym_base
));
1785 if (ecoff_ext
.asym
.sc
== scText
1786 || ecoff_ext
.asym
.sc
== scInfo
)
1787 fprintf (file
, "\n First symbol: %ld",
1788 (long) (indx
+ sym_base
));
1790 fprintf (file
, "\n First symbol: %ld",
1792 (AUX_GET_ISYM (bigendian
,
1793 &aux_base
[ecoff_ext
.asym
.index
])
1799 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1801 else if (ecoffsymbol (symbol
)->local
)
1802 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1804 (AUX_GET_ISYM (bigendian
,
1805 &aux_base
[ecoff_ext
.asym
.index
])
1807 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1809 fprintf (file
, "\n Local symbol: %ld",
1812 + (ecoff_data (abfd
)
1813 ->debug_info
.symbolic_header
.iextMax
)));
1817 fprintf (file
, "\n struct; End+1 symbol: %ld",
1818 (long) (indx
+ sym_base
));
1822 fprintf (file
, "\n union; End+1 symbol: %ld",
1823 (long) (indx
+ sym_base
));
1827 fprintf (file
, "\n enum; End+1 symbol: %ld",
1828 (long) (indx
+ sym_base
));
1832 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1833 fprintf (file
, "\n Type: %s",
1834 ecoff_type_to_string (abfd
, fdr
, indx
));
1843 /* Read in the relocs for a section. */
1846 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1851 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1852 arelent
*internal_relocs
;
1853 bfd_size_type external_reloc_size
;
1854 bfd_size_type external_relocs_size
;
1855 char *external_relocs
;
1859 if (section
->relocation
!= (arelent
*) NULL
1860 || section
->reloc_count
== 0
1861 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1864 if (ecoff_slurp_symbol_table (abfd
) == false)
1867 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1869 * section
->reloc_count
));
1870 external_reloc_size
= backend
->external_reloc_size
;
1871 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1872 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1873 if (internal_relocs
== (arelent
*) NULL
1874 || external_relocs
== (char *) NULL
)
1876 bfd_set_error (bfd_error_no_memory
);
1879 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1881 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1882 != external_relocs_size
)
1885 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1887 struct internal_reloc intern
;
1889 (*backend
->swap_reloc_in
) (abfd
,
1890 external_relocs
+ i
* external_reloc_size
,
1893 if (intern
.r_extern
)
1895 /* r_symndx is an index into the external symbols. */
1896 BFD_ASSERT (intern
.r_symndx
>= 0
1898 < (ecoff_data (abfd
)
1899 ->debug_info
.symbolic_header
.iextMax
)));
1900 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1903 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1904 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1906 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1911 CONST
char *sec_name
;
1914 /* r_symndx is a section key. */
1915 switch (intern
.r_symndx
)
1917 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1918 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1919 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1920 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1921 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1922 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1923 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1924 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1925 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1926 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1927 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1928 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1929 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1933 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1934 if (sec
== (asection
*) NULL
)
1936 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1938 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1941 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1943 /* Let the backend select the howto field and do any other
1944 required processing. */
1945 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1948 bfd_release (abfd
, external_relocs
);
1950 section
->relocation
= internal_relocs
;
1955 /* Get a canonical list of relocs. */
1958 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1966 if (section
->flags
& SEC_CONSTRUCTOR
)
1968 arelent_chain
*chain
;
1970 /* This section has relocs made up by us, not the file, so take
1971 them out of their chain and place them into the data area
1973 for (count
= 0, chain
= section
->constructor_chain
;
1974 count
< section
->reloc_count
;
1975 count
++, chain
= chain
->next
)
1976 *relptr
++ = &chain
->relent
;
1982 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1985 tblptr
= section
->relocation
;
1987 for (count
= 0; count
< section
->reloc_count
; count
++)
1988 *relptr
++ = tblptr
++;
1991 *relptr
= (arelent
*) NULL
;
1993 return section
->reloc_count
;
1996 /* Provided a BFD, a section and an offset into the section, calculate
1997 and return the name of the source file and the line nearest to the
2002 ecoff_find_nearest_line (abfd
,
2011 asymbol
**ignore_symbols
;
2013 CONST
char **filename_ptr
;
2014 CONST
char **functionname_ptr
;
2015 unsigned int *retline_ptr
;
2017 const struct ecoff_debug_swap
* const debug_swap
2018 = &ecoff_backend (abfd
)->debug_swap
;
2023 bfd_size_type external_pdr_size
;
2027 unsigned char *line_ptr
;
2028 unsigned char *line_end
;
2031 /* If we're not in the .text section, we don't have any line
2033 if (strcmp (section
->name
, _TEXT
) != 0
2034 || offset
< ecoff_data (abfd
)->text_start
2035 || offset
>= ecoff_data (abfd
)->text_end
)
2038 /* Make sure we have the FDR's. */
2039 if (ecoff_slurp_symbolic_info (abfd
) == false
2040 || bfd_get_symcount (abfd
) == 0)
2043 /* Each file descriptor (FDR) has a memory address. Here we track
2044 down which FDR we want. The FDR's are stored in increasing
2045 memory order. If speed is ever important, this can become a
2046 binary search. We must ignore FDR's with no PDR entries; they
2047 will have the adr of the FDR before or after them. */
2048 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2049 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2050 fdr_hold
= (FDR
*) NULL
;
2051 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2053 if (fdr_ptr
->cpd
== 0)
2055 if (offset
< fdr_ptr
->adr
)
2059 if (fdr_hold
== (FDR
*) NULL
)
2063 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2064 have an address, which is relative to the FDR address, and are
2065 also stored in increasing memory order. */
2066 offset
-= fdr_ptr
->adr
;
2067 external_pdr_size
= debug_swap
->external_pdr_size
;
2068 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2069 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2070 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2071 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2073 /* The address of the first PDR is an offset which applies to the
2074 addresses of all the PDR's. */
2077 for (pdr_ptr
+= external_pdr_size
;
2079 pdr_ptr
+= external_pdr_size
)
2081 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2082 if (offset
< pdr
.adr
)
2086 /* Now we can look for the actual line number. The line numbers are
2087 stored in a very funky format, which I won't try to describe.
2088 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2089 we want; we need this to compute line_end. */
2090 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2091 if (pdr_ptr
== pdr_end
)
2092 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2094 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2096 /* Now change pdr and pdr_ptr to the one we want. */
2097 pdr_ptr
-= external_pdr_size
;
2098 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2102 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2103 + fdr_ptr
->cbLineOffset
2104 + pdr
.cbLineOffset
);
2105 while (line_ptr
< line_end
)
2110 delta
= *line_ptr
>> 4;
2113 count
= (*line_ptr
& 0xf) + 1;
2117 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2118 if (delta
>= 0x8000)
2123 if (offset
< count
* 4)
2125 offset
-= count
* 4;
2128 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2129 at least according to gdb/mipsread.c. */
2130 if (fdr_ptr
->rss
== -1)
2132 *filename_ptr
= NULL
;
2134 *functionname_ptr
= NULL
;
2139 (*debug_swap
->swap_ext_in
)
2141 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2142 + pdr
.isym
* debug_swap
->external_ext_size
),
2144 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2145 + proc_ext
.asym
.iss
);
2152 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2155 (*debug_swap
->swap_sym_in
)
2157 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2158 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2160 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2164 if (lineno
== ilineNil
)
2166 *retline_ptr
= lineno
;
2170 /* Copy private BFD data. This is called by objcopy and strip. We
2171 use it to copy the ECOFF debugging information from one BFD to the
2172 other. It would be theoretically possible to represent the ECOFF
2173 debugging information in the symbol table. However, it would be a
2174 lot of work, and there would be little gain (gas, gdb, and ld
2175 already access the ECOFF debugging information via the
2176 ecoff_debug_info structure, and that structure would have to be
2177 retained in order to support ECOFF debugging in MIPS ELF).
2179 The debugging information for the ECOFF external symbols comes from
2180 the symbol table, so this function only handles the other debugging
2184 ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
2188 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
2189 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
2190 asymbol
**sym_ptr_ptr
;
2194 BFD_ASSERT (ibfd
->xvec
== obfd
->xvec
);
2196 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
2198 /* If there are no symbols, don't copy any debugging information. */
2199 c
= bfd_get_symcount (obfd
);
2200 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2201 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
2204 /* See if there are any local symbols. */
2206 for (; c
> 0; c
--, sym_ptr_ptr
++)
2208 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
2217 /* There are some local symbols. We just bring over all the
2218 debugging information. FIXME: This is not quite the right
2219 thing to do. If the user has asked us to discard all
2220 debugging information, then we are probably going to wind up
2221 keeping it because there will probably be some local symbol
2222 which objcopy did not discard. We should actually break
2223 apart the debugging information and only keep that which
2224 applies to the symbols we want to keep. */
2225 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
2226 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
2227 oinfo
->line
= iinfo
->line
;
2229 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
2230 oinfo
->external_dnr
= iinfo
->external_dnr
;
2232 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
2233 oinfo
->external_pdr
= iinfo
->external_pdr
;
2235 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
2236 oinfo
->external_sym
= iinfo
->external_sym
;
2238 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
2239 oinfo
->external_opt
= iinfo
->external_opt
;
2241 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
2242 oinfo
->external_aux
= iinfo
->external_aux
;
2244 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
2245 oinfo
->ss
= iinfo
->ss
;
2247 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
2248 oinfo
->external_fdr
= iinfo
->external_fdr
;
2250 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
2251 oinfo
->external_rfd
= iinfo
->external_rfd
;
2255 /* We are discarding all the local symbol information. Look
2256 through the external symbols and remove all references to FDR
2257 or aux information. */
2258 c
= bfd_get_symcount (obfd
);
2259 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2260 for (; c
> 0; c
--, sym_ptr_ptr
++)
2264 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
2265 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
2267 esym
.asym
.index
= indexNil
;
2268 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
2269 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
2276 /* Set the architecture. The supported architecture is stored in the
2277 backend pointer. We always set the architecture anyhow, since many
2278 callers ignore the return value. */
2281 ecoff_set_arch_mach (abfd
, arch
, machine
)
2283 enum bfd_architecture arch
;
2284 unsigned long machine
;
2286 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2287 return arch
== ecoff_backend (abfd
)->arch
;
2290 /* Get the size of the section headers. We do not output the .reginfo
2295 ecoff_sizeof_headers (abfd
, reloc
)
2304 for (current
= abfd
->sections
;
2305 current
!= (asection
*)NULL
;
2306 current
= current
->next
)
2307 if (strcmp (current
->name
, REGINFO
) != 0)
2310 ret
= (bfd_coff_filhsz (abfd
)
2311 + bfd_coff_aoutsz (abfd
)
2312 + c
* bfd_coff_scnhsz (abfd
));
2313 return BFD_ALIGN (ret
, 16);
2316 /* Get the contents of a section. This is where we handle reading the
2317 .reginfo section, which implicitly holds the contents of an
2318 ecoff_reginfo structure. */
2321 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2326 bfd_size_type count
;
2328 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2329 struct ecoff_reginfo s
;
2332 if (strcmp (section
->name
, REGINFO
) != 0)
2333 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2336 s
.gp_value
= tdata
->gp
;
2337 s
.gprmask
= tdata
->gprmask
;
2338 for (i
= 0; i
< 4; i
++)
2339 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2340 s
.fprmask
= tdata
->fprmask
;
2342 /* bfd_get_section_contents has already checked that the offset and
2343 size is reasonable. We don't have to worry about swapping or any
2344 such thing; the .reginfo section is defined such that the
2345 contents are an ecoff_reginfo structure as seen on the host. */
2346 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2350 /* Calculate the file position for each section, and set
2354 ecoff_compute_section_file_positions (abfd
)
2362 sofar
= ecoff_sizeof_headers (abfd
, false);
2365 for (current
= abfd
->sections
;
2366 current
!= (asection
*) NULL
;
2367 current
= current
->next
)
2369 unsigned int alignment_power
;
2371 /* Only deal with sections which have contents */
2372 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2373 || strcmp (current
->name
, REGINFO
) == 0)
2376 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2377 supposed to indicate the number of .pdata entries that are
2378 really in the section. Each entry is 8 bytes. We store this
2379 away in line_filepos before increasing the section size. */
2380 if (strcmp (current
->name
, _PDATA
) != 0)
2381 alignment_power
= current
->alignment_power
;
2384 current
->line_filepos
= current
->_raw_size
/ 8;
2385 alignment_power
= 4;
2388 /* On Ultrix, the data sections in an executable file must be
2389 aligned to a page boundary within the file. This does not
2390 affect the section size, though. FIXME: Does this work for
2391 other platforms? It requires some modification for the
2392 Alpha, because .rdata on the Alpha goes with the text, not
2394 if ((abfd
->flags
& EXEC_P
) != 0
2395 && (abfd
->flags
& D_PAGED
) != 0
2396 && first_data
!= false
2397 && (current
->flags
& SEC_CODE
) == 0
2398 && (! ecoff_backend (abfd
)->rdata_in_text
2399 || strcmp (current
->name
, _RDATA
) != 0)
2400 && strcmp (current
->name
, _PDATA
) != 0)
2402 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2404 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2407 else if (strcmp (current
->name
, _LIB
) == 0)
2409 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2410 /* On Irix 4, the location of contents of the .lib section
2411 from a shared library section is also rounded up to a
2414 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2417 /* Align the sections in the file to the same boundary on
2418 which they are aligned in virtual memory. */
2420 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2422 current
->filepos
= sofar
;
2424 sofar
+= current
->_raw_size
;
2426 /* make sure that this section is of the right size too */
2428 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2429 current
->_raw_size
+= sofar
- old_sofar
;
2432 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2435 /* Determine the location of the relocs for all the sections in the
2436 output file, as well as the location of the symbolic debugging
2439 static bfd_size_type
2440 ecoff_compute_reloc_file_positions (abfd
)
2443 const bfd_size_type external_reloc_size
=
2444 ecoff_backend (abfd
)->external_reloc_size
;
2445 file_ptr reloc_base
;
2446 bfd_size_type reloc_size
;
2450 if (! abfd
->output_has_begun
)
2452 ecoff_compute_section_file_positions (abfd
);
2453 abfd
->output_has_begun
= true;
2456 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2459 for (current
= abfd
->sections
;
2460 current
!= (asection
*)NULL
;
2461 current
= current
->next
)
2463 if (strcmp (current
->name
, REGINFO
) == 0)
2465 if (current
->reloc_count
== 0)
2466 current
->rel_filepos
= 0;
2469 bfd_size_type relsize
;
2471 current
->rel_filepos
= reloc_base
;
2472 relsize
= current
->reloc_count
* external_reloc_size
;
2473 reloc_size
+= relsize
;
2474 reloc_base
+= relsize
;
2478 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2480 /* At least on Ultrix, the symbol table of an executable file must
2481 be aligned to a page boundary. FIXME: Is this true on other
2483 if ((abfd
->flags
& EXEC_P
) != 0
2484 && (abfd
->flags
& D_PAGED
) != 0)
2485 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2486 &~ (ecoff_backend (abfd
)->round
- 1));
2488 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2493 /* Set the contents of a section. This is where we handle setting the
2494 contents of the .reginfo section, which implicitly holds a
2495 ecoff_reginfo structure. */
2498 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2503 bfd_size_type count
;
2505 /* This must be done first, because bfd_set_section_contents is
2506 going to set output_has_begun to true. */
2507 if (abfd
->output_has_begun
== false)
2508 ecoff_compute_section_file_positions (abfd
);
2510 /* If this is a .lib section, bump the vma address so that it winds
2511 up being the number of .lib sections output. This is right for
2512 Irix 4. Ian Taylor <ian@cygnus.com>. */
2513 if (strcmp (section
->name
, _LIB
) == 0)
2519 if (strcmp (section
->name
, REGINFO
) == 0)
2521 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2522 struct ecoff_reginfo s
;
2525 /* If the caller is only changing part of the structure, we must
2526 retrieve the current information before the memcpy. */
2527 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2529 s
.gp_value
= tdata
->gp
;
2530 s
.gprmask
= tdata
->gprmask
;
2531 for (i
= 0; i
< 4; i
++)
2532 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2533 s
.fprmask
= tdata
->fprmask
;
2536 /* bfd_set_section_contents has already checked that the offset
2537 and size is reasonable. We don't have to worry about
2538 swapping or any such thing; the .reginfo section is defined
2539 such that the contents are an ecoff_reginfo structure as seen
2541 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2543 tdata
->gp
= s
.gp_value
;
2544 tdata
->gprmask
= s
.gprmask
;
2545 for (i
= 0; i
< 4; i
++)
2546 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2547 tdata
->fprmask
= s
.fprmask
;
2552 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2553 || bfd_write (location
, 1, count
, abfd
) != count
)
2559 /* Get ECOFF EXTR information for an external symbol. This function
2560 is passed to bfd_ecoff_debug_externals. */
2563 ecoff_get_extr (sym
, esym
)
2567 ecoff_symbol_type
*ecoff_sym_ptr
;
2570 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2571 || ecoffsymbol (sym
)->native
== NULL
)
2573 /* Don't include debugging, local, or section symbols. */
2574 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2575 || (sym
->flags
& BSF_LOCAL
) != 0
2576 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2580 esym
->cobol_main
= 0;
2584 /* FIXME: we can do better than this for st and sc. */
2585 esym
->asym
.st
= stGlobal
;
2586 esym
->asym
.sc
= scAbs
;
2587 esym
->asym
.reserved
= 0;
2588 esym
->asym
.index
= indexNil
;
2592 ecoff_sym_ptr
= ecoffsymbol (sym
);
2594 if (ecoff_sym_ptr
->local
)
2597 input_bfd
= bfd_asymbol_bfd (sym
);
2598 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2599 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2601 /* If the symbol was defined by the linker, then esym will be
2602 undefined but sym will not be. Get a better class for such a
2604 if ((esym
->asym
.sc
== scUndefined
2605 || esym
->asym
.sc
== scSUndefined
)
2606 && bfd_get_section (sym
) != &bfd_und_section
)
2607 esym
->asym
.sc
= scAbs
;
2609 /* Adjust the FDR index for the symbol by that used for the input
2611 if (esym
->ifd
!= -1)
2613 struct ecoff_debug_info
*input_debug
;
2615 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2616 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2617 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2618 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2624 /* Set the external symbol index. This routine is passed to
2625 bfd_ecoff_debug_externals. */
2628 ecoff_set_index (sym
, indx
)
2632 ecoff_set_sym_index (sym
, indx
);
2635 /* Write out an ECOFF file. */
2638 ecoff_write_object_contents (abfd
)
2641 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2642 const bfd_vma round
= backend
->round
;
2643 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2644 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2645 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2646 const bfd_size_type external_hdr_size
2647 = backend
->debug_swap
.external_hdr_size
;
2648 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2649 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2651 struct internal_reloc
*))
2652 = backend
->adjust_reloc_out
;
2653 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2654 const struct internal_reloc
*,
2656 = backend
->swap_reloc_out
;
2657 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2658 HDRR
* const symhdr
= &debug
->symbolic_header
;
2661 bfd_size_type reloc_size
;
2662 bfd_size_type text_size
;
2664 boolean set_text_start
;
2665 bfd_size_type data_size
;
2667 boolean set_data_start
;
2668 bfd_size_type bss_size
;
2670 PTR reloc_buff
= NULL
;
2671 struct internal_filehdr internal_f
;
2672 struct internal_aouthdr internal_a
;
2675 /* Determine where the sections and relocs will go in the output
2677 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2680 for (current
= abfd
->sections
;
2681 current
!= (asection
*)NULL
;
2682 current
= current
->next
)
2684 if (strcmp (current
->name
, REGINFO
) == 0)
2686 current
->target_index
= count
;
2690 if ((abfd
->flags
& D_PAGED
) != 0)
2691 text_size
= ecoff_sizeof_headers (abfd
, false);
2695 set_text_start
= false;
2698 set_data_start
= false;
2701 /* Write section headers to the file. */
2703 /* Allocate buff big enough to hold a section header,
2704 file header, or a.out header. */
2712 buff
= (PTR
) malloc (siz
);
2715 bfd_set_error (bfd_error_no_memory
);
2720 internal_f
.f_nscns
= 0;
2721 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2723 for (current
= abfd
->sections
;
2724 current
!= (asection
*) NULL
;
2725 current
= current
->next
)
2727 struct internal_scnhdr section
;
2730 if (strcmp (current
->name
, REGINFO
) == 0)
2732 BFD_ASSERT (current
->reloc_count
== 0);
2736 ++internal_f
.f_nscns
;
2738 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2740 /* This seems to be correct for Irix 4 shared libraries. */
2741 vma
= bfd_get_section_vma (abfd
, current
);
2742 if (strcmp (current
->name
, _LIB
) == 0)
2743 section
.s_vaddr
= 0;
2745 section
.s_vaddr
= vma
;
2747 section
.s_paddr
= vma
;
2748 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2750 /* If this section is unloadable then the scnptr will be 0. */
2751 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2752 section
.s_scnptr
= 0;
2754 section
.s_scnptr
= current
->filepos
;
2755 section
.s_relptr
= current
->rel_filepos
;
2757 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2758 object file produced by the assembler is supposed to point to
2759 information about how much room is required by objects of
2760 various different sizes. I think this only matters if we
2761 want the linker to compute the best size to use, or
2762 something. I don't know what happens if the information is
2764 if (strcmp (current
->name
, _PDATA
) != 0)
2765 section
.s_lnnoptr
= 0;
2768 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2769 hold the number of entries in the section (each entry is
2770 8 bytes). We stored this in the line_filepos field in
2771 ecoff_compute_section_file_positions. */
2772 section
.s_lnnoptr
= current
->line_filepos
;
2775 section
.s_nreloc
= current
->reloc_count
;
2776 section
.s_nlnno
= 0;
2777 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2780 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2781 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2784 if ((section
.s_flags
& STYP_TEXT
) != 0
2785 || ((section
.s_flags
& STYP_RDATA
) != 0
2786 && backend
->rdata_in_text
)
2787 || strcmp (current
->name
, _PDATA
) == 0)
2789 text_size
+= bfd_get_section_size_before_reloc (current
);
2790 if (! set_text_start
|| text_start
> vma
)
2793 set_text_start
= true;
2796 else if ((section
.s_flags
& STYP_RDATA
) != 0
2797 || (section
.s_flags
& STYP_DATA
) != 0
2798 || (section
.s_flags
& STYP_LITA
) != 0
2799 || (section
.s_flags
& STYP_LIT8
) != 0
2800 || (section
.s_flags
& STYP_LIT4
) != 0
2801 || (section
.s_flags
& STYP_SDATA
) != 0
2802 || strcmp (current
->name
, _XDATA
) == 0)
2804 data_size
+= bfd_get_section_size_before_reloc (current
);
2805 if (! set_data_start
|| data_start
> vma
)
2808 set_data_start
= true;
2811 else if ((section
.s_flags
& STYP_BSS
) != 0
2812 || (section
.s_flags
& STYP_SBSS
) != 0)
2813 bss_size
+= bfd_get_section_size_before_reloc (current
);
2814 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
2820 /* Set up the file header. */
2822 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2824 /* We will NOT put a fucking timestamp in the header here. Every
2825 time you put it back, I will come in and take it out again. I'm
2826 sorry. This field does not belong here. We fill it with a 0 so
2827 it compares the same but is not a reasonable time. --
2829 internal_f
.f_timdat
= 0;
2831 if (bfd_get_symcount (abfd
) != 0)
2833 /* The ECOFF f_nsyms field is not actually the number of
2834 symbols, it's the size of symbolic information header. */
2835 internal_f
.f_nsyms
= external_hdr_size
;
2836 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2840 internal_f
.f_nsyms
= 0;
2841 internal_f
.f_symptr
= 0;
2844 internal_f
.f_opthdr
= aoutsz
;
2846 internal_f
.f_flags
= F_LNNO
;
2847 if (reloc_size
== 0)
2848 internal_f
.f_flags
|= F_RELFLG
;
2849 if (bfd_get_symcount (abfd
) == 0)
2850 internal_f
.f_flags
|= F_LSYMS
;
2851 if (abfd
->flags
& EXEC_P
)
2852 internal_f
.f_flags
|= F_EXEC
;
2854 if (! abfd
->xvec
->byteorder_big_p
)
2855 internal_f
.f_flags
|= F_AR32WR
;
2857 internal_f
.f_flags
|= F_AR32W
;
2859 /* Set up the ``optional'' header. */
2860 if ((abfd
->flags
& D_PAGED
) != 0)
2861 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2863 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2865 /* FIXME: Is this really correct? */
2866 internal_a
.vstamp
= symhdr
->vstamp
;
2868 /* At least on Ultrix, these have to be rounded to page boundaries.
2869 FIXME: Is this true on other platforms? */
2870 if ((abfd
->flags
& D_PAGED
) != 0)
2872 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2873 internal_a
.text_start
= text_start
&~ (round
- 1);
2874 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2875 internal_a
.data_start
= data_start
&~ (round
- 1);
2879 internal_a
.tsize
= text_size
;
2880 internal_a
.text_start
= text_start
;
2881 internal_a
.dsize
= data_size
;
2882 internal_a
.data_start
= data_start
;
2885 /* On Ultrix, the initial portions of the .sbss and .bss segments
2886 are at the end of the data section. The bsize field in the
2887 optional header records how many bss bytes are required beyond
2888 those in the data section. The value is not rounded to a page
2890 if (bss_size
< internal_a
.dsize
- data_size
)
2893 bss_size
-= internal_a
.dsize
- data_size
;
2894 internal_a
.bsize
= bss_size
;
2895 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2897 internal_a
.entry
= bfd_get_start_address (abfd
);
2899 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2901 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2902 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2903 for (i
= 0; i
< 4; i
++)
2904 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2906 /* Write out the file header and the optional header. */
2908 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2911 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2912 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2915 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2916 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2919 /* Build the external symbol information. This must be done before
2920 writing out the relocs so that we know the symbol indices. The
2921 condition checks makes sure this object was not created by
2922 ecoff_bfd_final_link, since if it was we do not want to tamper
2923 with the external symbols. */
2924 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2926 symhdr
->iextMax
= 0;
2927 symhdr
->issExtMax
= 0;
2928 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2929 debug
->ssext
= debug
->ssext_end
= NULL
;
2930 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2931 (((abfd
->flags
& EXEC_P
) == 0)
2933 ecoff_get_extr
, ecoff_set_index
)
2937 /* Write out the relocs. */
2938 for (current
= abfd
->sections
;
2939 current
!= (asection
*) NULL
;
2940 current
= current
->next
)
2942 arelent
**reloc_ptr_ptr
;
2943 arelent
**reloc_end
;
2946 if (current
->reloc_count
== 0)
2950 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2951 if (reloc_buff
== NULL
)
2953 bfd_set_error (bfd_error_no_memory
);
2957 reloc_ptr_ptr
= current
->orelocation
;
2958 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2959 out_ptr
= (char *) reloc_buff
;
2961 reloc_ptr_ptr
< reloc_end
;
2962 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2966 struct internal_reloc in
;
2968 memset ((PTR
) &in
, 0, sizeof in
);
2970 reloc
= *reloc_ptr_ptr
;
2971 sym
= *reloc
->sym_ptr_ptr
;
2973 in
.r_vaddr
= (reloc
->address
2974 + bfd_get_section_vma (abfd
, current
));
2975 in
.r_type
= reloc
->howto
->type
;
2977 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2979 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2986 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2987 if (strcmp (name
, ".text") == 0)
2988 in
.r_symndx
= RELOC_SECTION_TEXT
;
2989 else if (strcmp (name
, ".rdata") == 0)
2990 in
.r_symndx
= RELOC_SECTION_RDATA
;
2991 else if (strcmp (name
, ".data") == 0)
2992 in
.r_symndx
= RELOC_SECTION_DATA
;
2993 else if (strcmp (name
, ".sdata") == 0)
2994 in
.r_symndx
= RELOC_SECTION_SDATA
;
2995 else if (strcmp (name
, ".sbss") == 0)
2996 in
.r_symndx
= RELOC_SECTION_SBSS
;
2997 else if (strcmp (name
, ".bss") == 0)
2998 in
.r_symndx
= RELOC_SECTION_BSS
;
2999 else if (strcmp (name
, ".init") == 0)
3000 in
.r_symndx
= RELOC_SECTION_INIT
;
3001 else if (strcmp (name
, ".lit8") == 0)
3002 in
.r_symndx
= RELOC_SECTION_LIT8
;
3003 else if (strcmp (name
, ".lit4") == 0)
3004 in
.r_symndx
= RELOC_SECTION_LIT4
;
3005 else if (strcmp (name
, ".xdata") == 0)
3006 in
.r_symndx
= RELOC_SECTION_XDATA
;
3007 else if (strcmp (name
, ".pdata") == 0)
3008 in
.r_symndx
= RELOC_SECTION_PDATA
;
3009 else if (strcmp (name
, ".fini") == 0)
3010 in
.r_symndx
= RELOC_SECTION_FINI
;
3011 else if (strcmp (name
, ".lita") == 0)
3012 in
.r_symndx
= RELOC_SECTION_LITA
;
3013 else if (strcmp (name
, "*ABS*") == 0)
3014 in
.r_symndx
= RELOC_SECTION_ABS
;
3020 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
3022 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3025 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3027 if (bfd_write (reloc_buff
,
3028 external_reloc_size
, current
->reloc_count
, abfd
)
3029 != external_reloc_size
* current
->reloc_count
)
3031 bfd_release (abfd
, reloc_buff
);
3035 /* Write out the symbolic debugging information. */
3036 if (bfd_get_symcount (abfd
) > 0)
3038 /* Write out the debugging information. */
3039 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
3040 ecoff_data (abfd
)->sym_filepos
)
3046 /* The .bss section of a demand paged executable must receive an
3047 entire page. If there are symbols, the symbols will start on the
3048 next page. If there are no symbols, we must fill out the page by
3050 if (bfd_get_symcount (abfd
) == 0
3051 && (abfd
->flags
& EXEC_P
) != 0
3052 && (abfd
->flags
& D_PAGED
) != 0)
3056 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3059 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3061 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3064 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3068 if (reloc_buff
!= NULL
)
3069 bfd_release (abfd
, reloc_buff
);
3074 if (reloc_buff
!= NULL
)
3075 bfd_release (abfd
, reloc_buff
);
3081 /* Archive handling. ECOFF uses what appears to be a unique type of
3082 archive header (armap). The byte ordering of the armap and the
3083 contents are encoded in the name of the armap itself. At least for
3084 now, we only support archives with the same byte ordering in the
3085 armap and the contents.
3087 The first four bytes in the armap are the number of symbol
3088 definitions. This is always a power of two.
3090 This is followed by the symbol definitions. Each symbol definition
3091 occupies 8 bytes. The first four bytes are the offset from the
3092 start of the armap strings to the null-terminated string naming
3093 this symbol. The second four bytes are the file offset to the
3094 archive member which defines this symbol. If the second four bytes
3095 are 0, then this is not actually a symbol definition, and it should
3098 The symbols are hashed into the armap with a closed hashing scheme.
3099 See the functions below for the details of the algorithm.
3101 After the symbol definitions comes four bytes holding the size of
3102 the string table, followed by the string table itself. */
3104 /* The name of an archive headers looks like this:
3105 __________E[BL]E[BL]_ (with a trailing space).
3106 The trailing space is changed to an X if the archive is changed to
3107 indicate that the armap is out of date.
3109 The Alpha seems to use ________64E[BL]E[BL]_. */
3111 #define ARMAP_BIG_ENDIAN 'B'
3112 #define ARMAP_LITTLE_ENDIAN 'L'
3113 #define ARMAP_MARKER 'E'
3114 #define ARMAP_START_LENGTH 10
3115 #define ARMAP_HEADER_MARKER_INDEX 10
3116 #define ARMAP_HEADER_ENDIAN_INDEX 11
3117 #define ARMAP_OBJECT_MARKER_INDEX 12
3118 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3119 #define ARMAP_END_INDEX 14
3120 #define ARMAP_END "_ "
3122 /* This is a magic number used in the hashing algorithm. */
3123 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3125 /* This returns the hash value to use for a string. It also sets
3126 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3127 is the number of entries in the hash table, and HLOG is the log
3131 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3133 unsigned int *rehash
;
3141 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3142 hash
*= ARMAP_HASH_MAGIC
;
3143 *rehash
= (hash
& (size
- 1)) | 1;
3144 return hash
>> (32 - hlog
);
3147 /* Read in the armap. */
3150 ecoff_slurp_armap (abfd
)
3155 struct areltdata
*mapdata
;
3156 bfd_size_type parsed_size
;
3158 struct artdata
*ardata
;
3161 struct symdef
*symdef_ptr
;
3164 /* Get the name of the first element. */
3165 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3171 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
3174 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3175 standard COFF armap. We could move the ECOFF armap stuff into
3176 bfd_slurp_armap, but that seems inappropriate since no other
3177 target uses this format. Instead, we check directly for a COFF
3179 if (strncmp (nextname
, "/ ", 16) == 0)
3180 return bfd_slurp_armap (abfd
);
3182 /* See if the first element is an armap. */
3183 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3184 ARMAP_START_LENGTH
) != 0
3185 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3186 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3187 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3188 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3189 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3190 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3191 || strncmp (nextname
+ ARMAP_END_INDEX
,
3192 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3194 bfd_has_map (abfd
) = false;
3198 /* Make sure we have the right byte ordering. */
3199 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3200 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3201 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3202 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3204 bfd_set_error (bfd_error_wrong_format
);
3208 /* Read in the armap. */
3209 ardata
= bfd_ardata (abfd
);
3210 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3211 if (mapdata
== (struct areltdata
*) NULL
)
3213 parsed_size
= mapdata
->parsed_size
;
3214 bfd_release (abfd
, (PTR
) mapdata
);
3216 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3217 if (raw_armap
== (char *) NULL
)
3219 bfd_set_error (bfd_error_no_memory
);
3223 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3225 if (bfd_get_error () != bfd_error_system_call
)
3226 bfd_set_error (bfd_error_malformed_archive
);
3227 bfd_release (abfd
, (PTR
) raw_armap
);
3231 ardata
->tdata
= (PTR
) raw_armap
;
3233 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3235 ardata
->symdef_count
= 0;
3236 ardata
->cache
= (struct ar_cache
*) NULL
;
3238 /* This code used to overlay the symdefs over the raw archive data,
3239 but that doesn't work on a 64 bit host. */
3241 stringbase
= raw_armap
+ count
* 8 + 8;
3243 #ifdef CHECK_ARMAP_HASH
3247 /* Double check that I have the hashing algorithm right by making
3248 sure that every symbol can be looked up successfully. */
3250 for (i
= 1; i
< count
; i
<<= 1)
3252 BFD_ASSERT (i
== count
);
3254 raw_ptr
= raw_armap
+ 4;
3255 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3257 unsigned int name_offset
, file_offset
;
3258 unsigned int hash
, rehash
, srch
;
3260 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3261 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3262 if (file_offset
== 0)
3264 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3269 /* See if we can rehash to this location. */
3270 for (srch
= (hash
+ rehash
) & (count
- 1);
3271 srch
!= hash
&& srch
!= i
;
3272 srch
= (srch
+ rehash
) & (count
- 1))
3273 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3275 BFD_ASSERT (srch
== i
);
3279 #endif /* CHECK_ARMAP_HASH */
3281 raw_ptr
= raw_armap
+ 4;
3282 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3283 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3284 ++ardata
->symdef_count
;
3286 symdef_ptr
= ((struct symdef
*)
3288 ardata
->symdef_count
* sizeof (struct symdef
)));
3291 bfd_set_error (bfd_error_no_memory
);
3295 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3297 raw_ptr
= raw_armap
+ 4;
3298 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3300 unsigned int name_offset
, file_offset
;
3302 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3303 if (file_offset
== 0)
3305 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3306 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3307 symdef_ptr
->file_offset
= file_offset
;
3311 ardata
->first_file_filepos
= bfd_tell (abfd
);
3312 /* Pad to an even boundary. */
3313 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3315 bfd_has_map (abfd
) = true;
3320 /* Write out an armap. */
3323 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3325 unsigned int elength
;
3327 unsigned int orl_count
;
3330 unsigned int hashsize
, hashlog
;
3331 unsigned int symdefsize
;
3333 unsigned int stringsize
;
3334 unsigned int mapsize
;
3337 struct stat statbuf
;
3340 bfd_byte
*hashtable
;
3344 /* Ultrix appears to use as a hash table size the least power of two
3345 greater than twice the number of entries. */
3346 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3348 hashsize
= 1 << hashlog
;
3350 symdefsize
= hashsize
* 8;
3352 stringsize
= stridx
+ padit
;
3354 /* Include 8 bytes to store symdefsize and stringsize in output. */
3355 mapsize
= symdefsize
+ stringsize
+ 8;
3357 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3359 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3361 /* Work out the ECOFF armap name. */
3362 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3363 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3364 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3365 (abfd
->xvec
->header_byteorder_big_p
3367 : ARMAP_LITTLE_ENDIAN
);
3368 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3369 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3370 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3371 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3373 /* Write the timestamp of the archive header to be just a little bit
3374 later than the timestamp of the file, otherwise the linker will
3375 complain that the index is out of date. Actually, the Ultrix
3376 linker just checks the archive name; the GNU linker may check the
3378 stat (abfd
->filename
, &statbuf
);
3379 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3381 /* The DECstation uses zeroes for the uid, gid and mode of the
3383 hdr
.ar_uid
[0] = '0';
3384 hdr
.ar_gid
[0] = '0';
3385 hdr
.ar_mode
[0] = '0';
3387 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3389 hdr
.ar_fmag
[0] = '`';
3390 hdr
.ar_fmag
[1] = '\012';
3392 /* Turn all null bytes in the header into spaces. */
3393 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3394 if (((char *)(&hdr
))[i
] == '\0')
3395 (((char *)(&hdr
))[i
]) = ' ';
3397 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3398 != sizeof (struct ar_hdr
))
3401 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3402 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3405 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3408 bfd_set_error (bfd_error_no_memory
);
3412 current
= abfd
->archive_head
;
3414 for (i
= 0; i
< orl_count
; i
++)
3416 unsigned int hash
, rehash
;
3418 /* Advance firstreal to the file position of this archive
3420 if (((bfd
*) map
[i
].pos
) != last_elt
)
3424 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3425 firstreal
+= firstreal
% 2;
3426 current
= current
->next
;
3428 while (current
!= (bfd
*) map
[i
].pos
);
3433 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3434 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3438 /* The desired slot is already taken. */
3439 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3441 srch
= (srch
+ rehash
) & (hashsize
- 1))
3442 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3445 BFD_ASSERT (srch
!= hash
);
3450 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3451 (PTR
) (hashtable
+ hash
* 8));
3452 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3453 (PTR
) (hashtable
+ hash
* 8 + 4));
3456 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3459 bfd_release (abfd
, hashtable
);
3461 /* Now write the strings. */
3462 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3463 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3465 for (i
= 0; i
< orl_count
; i
++)
3469 len
= strlen (*map
[i
].name
) + 1;
3470 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3474 /* The spec sez this should be a newline. But in order to be
3475 bug-compatible for DECstation ar we use a null. */
3478 if (bfd_write ("", 1, 1, abfd
) != 1)
3485 /* See whether this BFD is an archive. If it is, read in the armap
3486 and the extended name table. */
3489 ecoff_archive_p (abfd
)
3492 char armag
[SARMAG
+ 1];
3494 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3495 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3497 if (bfd_get_error () != bfd_error_system_call
)
3498 bfd_set_error (bfd_error_wrong_format
);
3499 return (bfd_target
*) NULL
;
3502 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3503 involves a cast, we can't do it as the left operand of
3505 abfd
->tdata
.aout_ar_data
=
3506 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3508 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3510 bfd_set_error (bfd_error_no_memory
);
3511 return (bfd_target
*) NULL
;
3514 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3515 bfd_ardata (abfd
)->cache
= NULL
;
3516 bfd_ardata (abfd
)->archive_head
= NULL
;
3517 bfd_ardata (abfd
)->symdefs
= NULL
;
3518 bfd_ardata (abfd
)->extended_names
= NULL
;
3519 bfd_ardata (abfd
)->tdata
= NULL
;
3521 if (ecoff_slurp_armap (abfd
) == false
3522 || ecoff_slurp_extended_name_table (abfd
) == false)
3524 bfd_release (abfd
, bfd_ardata (abfd
));
3525 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3526 return (bfd_target
*) NULL
;
3532 /* ECOFF linker code. */
3534 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3535 PARAMS ((struct bfd_hash_entry
*entry
,
3536 struct bfd_hash_table
*table
,
3537 const char *string
));
3538 static boolean ecoff_link_add_archive_symbols
3539 PARAMS ((bfd
*, struct bfd_link_info
*));
3540 static boolean ecoff_link_check_archive_element
3541 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3542 static boolean ecoff_link_add_object_symbols
3543 PARAMS ((bfd
*, struct bfd_link_info
*));
3544 static boolean ecoff_link_add_externals
3545 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3547 /* Routine to create an entry in an ECOFF link hash table. */
3549 static struct bfd_hash_entry
*
3550 ecoff_link_hash_newfunc (entry
, table
, string
)
3551 struct bfd_hash_entry
*entry
;
3552 struct bfd_hash_table
*table
;
3555 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3557 /* Allocate the structure if it has not already been allocated by a
3559 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3560 ret
= ((struct ecoff_link_hash_entry
*)
3561 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3562 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3564 bfd_set_error (bfd_error_no_memory
);
3568 /* Call the allocation method of the superclass. */
3569 ret
= ((struct ecoff_link_hash_entry
*)
3570 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3575 /* Set local fields. */
3579 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3581 return (struct bfd_hash_entry
*) ret
;
3584 /* Create an ECOFF link hash table. */
3586 struct bfd_link_hash_table
*
3587 ecoff_bfd_link_hash_table_create (abfd
)
3590 struct ecoff_link_hash_table
*ret
;
3592 ret
= ((struct ecoff_link_hash_table
*)
3593 malloc (sizeof (struct ecoff_link_hash_table
)));
3596 bfd_set_error (bfd_error_no_memory
);
3599 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3600 ecoff_link_hash_newfunc
))
3603 return (struct bfd_link_hash_table
*) NULL
;
3608 /* Look up an entry in an ECOFF link hash table. */
3610 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3611 ((struct ecoff_link_hash_entry *) \
3612 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3614 /* Traverse an ECOFF link hash table. */
3616 #define ecoff_link_hash_traverse(table, func, info) \
3617 (bfd_link_hash_traverse \
3619 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3622 /* Get the ECOFF link hash table from the info structure. This is
3625 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3627 /* Given an ECOFF BFD, add symbols to the global hash table as
3631 ecoff_bfd_link_add_symbols (abfd
, info
)
3633 struct bfd_link_info
*info
;
3635 switch (bfd_get_format (abfd
))
3638 return ecoff_link_add_object_symbols (abfd
, info
);
3640 return ecoff_link_add_archive_symbols (abfd
, info
);
3642 bfd_set_error (bfd_error_wrong_format
);
3647 /* Add the symbols from an archive file to the global hash table.
3648 This looks through the undefined symbols, looks each one up in the
3649 archive hash table, and adds any associated object file. We do not
3650 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3651 already have a hash table, so there is no reason to construct
3655 ecoff_link_add_archive_symbols (abfd
, info
)
3657 struct bfd_link_info
*info
;
3659 const bfd_byte
*raw_armap
;
3660 struct bfd_link_hash_entry
**pundef
;
3661 unsigned int armap_count
;
3662 unsigned int armap_log
;
3664 const bfd_byte
*hashtable
;
3665 const char *stringbase
;
3667 if (! bfd_has_map (abfd
))
3669 bfd_set_error (bfd_error_no_symbols
);
3673 /* If we don't have any raw data for this archive, as can happen on
3674 Irix 4.0.5F, we call the generic routine.
3675 FIXME: We should be more clever about this, since someday tdata
3676 may get to something for a generic archive. */
3677 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3678 if (raw_armap
== (bfd_byte
*) NULL
)
3679 return (_bfd_generic_link_add_archive_symbols
3680 (abfd
, info
, ecoff_link_check_archive_element
));
3682 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3685 for (i
= 1; i
< armap_count
; i
<<= 1)
3687 BFD_ASSERT (i
== armap_count
);
3689 hashtable
= raw_armap
+ 4;
3690 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3692 /* Look through the list of undefined symbols. */
3693 pundef
= &info
->hash
->undefs
;
3694 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3696 struct bfd_link_hash_entry
*h
;
3697 unsigned int hash
, rehash
;
3698 unsigned int file_offset
;
3704 /* When a symbol is defined, it is not necessarily removed from
3706 if (h
->type
!= bfd_link_hash_undefined
3707 && h
->type
!= bfd_link_hash_common
)
3709 /* Remove this entry from the list, for general cleanliness
3710 and because we are going to look through the list again
3711 if we search any more libraries. We can't remove the
3712 entry if it is the tail, because that would lose any
3713 entries we add to the list later on. */
3714 if (*pundef
!= info
->hash
->undefs_tail
)
3715 *pundef
= (*pundef
)->next
;
3717 pundef
= &(*pundef
)->next
;
3721 /* Native ECOFF linkers do not pull in archive elements merely
3722 to satisfy common definitions, so neither do we. We leave
3723 them on the list, though, in case we are linking against some
3724 other object format. */
3725 if (h
->type
!= bfd_link_hash_undefined
)
3727 pundef
= &(*pundef
)->next
;
3731 /* Look for this symbol in the archive hash table. */
3732 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3735 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3736 if (file_offset
== 0)
3738 /* Nothing in this slot. */
3739 pundef
= &(*pundef
)->next
;
3743 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3744 if (name
[0] != h
->root
.string
[0]
3745 || strcmp (name
, h
->root
.string
) != 0)
3750 /* That was the wrong symbol. Try rehashing. */
3752 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3754 srch
= (srch
+ rehash
) & (armap_count
- 1))
3756 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3757 if (file_offset
== 0)
3759 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3760 if (name
[0] == h
->root
.string
[0]
3761 && strcmp (name
, h
->root
.string
) == 0)
3770 pundef
= &(*pundef
)->next
;
3777 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3778 if (element
== (bfd
*) NULL
)
3781 if (! bfd_check_format (element
, bfd_object
))
3784 /* Unlike the generic linker, we know that this element provides
3785 a definition for an undefined symbol and we know that we want
3786 to include it. We don't need to check anything. */
3787 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3789 if (! ecoff_link_add_object_symbols (element
, info
))
3792 pundef
= &(*pundef
)->next
;
3798 /* This is called if we used _bfd_generic_link_add_archive_symbols
3799 because we were not dealing with an ECOFF archive. */
3802 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3804 struct bfd_link_info
*info
;
3807 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3808 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3809 = backend
->debug_swap
.swap_ext_in
;
3811 bfd_size_type external_ext_size
;
3812 PTR external_ext
= NULL
;
3820 if (! ecoff_slurp_symbolic_header (abfd
))
3823 /* If there are no symbols, we don't want it. */
3824 if (bfd_get_symcount (abfd
) == 0)
3825 goto successful_return
;
3827 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3829 /* Read in the external symbols and external strings. */
3830 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3831 esize
= symhdr
->iextMax
* external_ext_size
;
3832 external_ext
= (PTR
) malloc (esize
);
3833 if (external_ext
== NULL
&& esize
!= 0)
3835 bfd_set_error (bfd_error_no_memory
);
3839 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3840 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3843 ssext
= (char *) malloc (symhdr
->issExtMax
);
3844 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3846 bfd_set_error (bfd_error_no_memory
);
3850 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3851 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3854 /* Look through the external symbols to see if they define some
3855 symbol that is currently undefined. */
3856 ext_ptr
= (char *) external_ext
;
3857 ext_end
= ext_ptr
+ esize
;
3858 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3863 struct bfd_link_hash_entry
*h
;
3865 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3867 /* See if this symbol defines something. */
3868 if (esym
.asym
.st
!= stGlobal
3869 && esym
.asym
.st
!= stLabel
3870 && esym
.asym
.st
!= stProc
)
3873 switch (esym
.asym
.sc
)
3896 name
= ssext
+ esym
.asym
.iss
;
3897 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3899 /* Unlike the generic linker, we do not pull in elements because
3900 of common symbols. */
3901 if (h
== (struct bfd_link_hash_entry
*) NULL
3902 || h
->type
!= bfd_link_hash_undefined
)
3905 /* Include this element. */
3906 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3908 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3912 goto successful_return
;
3916 if (external_ext
!= NULL
)
3917 free (external_ext
);
3922 if (external_ext
!= NULL
)
3923 free (external_ext
);
3929 /* Add symbols from an ECOFF object file to the global linker hash
3933 ecoff_link_add_object_symbols (abfd
, info
)
3935 struct bfd_link_info
*info
;
3938 bfd_size_type external_ext_size
;
3939 PTR external_ext
= NULL
;
3944 if (! ecoff_slurp_symbolic_header (abfd
))
3947 /* If there are no symbols, we don't want it. */
3948 if (bfd_get_symcount (abfd
) == 0)
3951 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3953 /* Read in the external symbols and external strings. */
3954 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3955 esize
= symhdr
->iextMax
* external_ext_size
;
3956 external_ext
= (PTR
) malloc (esize
);
3957 if (external_ext
== NULL
&& esize
!= 0)
3959 bfd_set_error (bfd_error_no_memory
);
3963 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3964 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3967 ssext
= (char *) malloc (symhdr
->issExtMax
);
3968 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3970 bfd_set_error (bfd_error_no_memory
);
3974 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3975 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3978 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3982 if (external_ext
!= NULL
)
3983 free (external_ext
);
3989 if (external_ext
!= NULL
)
3990 free (external_ext
);
3994 /* Add the external symbols of an object file to the global linker
3995 hash table. The external symbols and strings we are passed are
3996 just allocated on the stack, and will be discarded. We must
3997 explicitly save any information we may need later on in the link.
3998 We do not want to read the external symbol information again. */
4001 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
4003 struct bfd_link_info
*info
;
4007 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4008 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
4009 = backend
->debug_swap
.swap_ext_in
;
4010 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
4011 unsigned long ext_count
;
4012 struct ecoff_link_hash_entry
**sym_hash
;
4016 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
4018 sym_hash
= ((struct ecoff_link_hash_entry
**)
4020 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
4023 bfd_set_error (bfd_error_no_memory
);
4026 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
4028 ext_ptr
= (char *) external_ext
;
4029 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
4030 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
4037 struct ecoff_link_hash_entry
*h
;
4041 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
4043 /* Skip debugging symbols. */
4045 switch (esym
.asym
.st
)
4061 /* Get the information for this symbol. */
4062 value
= esym
.asym
.value
;
4063 switch (esym
.asym
.sc
)
4083 section
= bfd_make_section_old_way (abfd
, ".text");
4084 value
-= section
->vma
;
4087 section
= bfd_make_section_old_way (abfd
, ".data");
4088 value
-= section
->vma
;
4091 section
= bfd_make_section_old_way (abfd
, ".bss");
4092 value
-= section
->vma
;
4095 section
= &bfd_abs_section
;
4098 section
= &bfd_und_section
;
4101 section
= bfd_make_section_old_way (abfd
, ".sdata");
4102 value
-= section
->vma
;
4105 section
= bfd_make_section_old_way (abfd
, ".sbss");
4106 value
-= section
->vma
;
4109 section
= bfd_make_section_old_way (abfd
, ".rdata");
4110 value
-= section
->vma
;
4113 if (value
> ecoff_data (abfd
)->gp_size
)
4115 section
= &bfd_com_section
;
4120 if (ecoff_scom_section
.name
== NULL
)
4122 /* Initialize the small common section. */
4123 ecoff_scom_section
.name
= SCOMMON
;
4124 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
4125 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
4126 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
4127 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
4128 ecoff_scom_symbol
.name
= SCOMMON
;
4129 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
4130 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
4131 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
4133 section
= &ecoff_scom_section
;
4136 section
= &bfd_und_section
;
4139 section
= bfd_make_section_old_way (abfd
, ".init");
4140 value
-= section
->vma
;
4143 section
= bfd_make_section_old_way (abfd
, ".fini");
4144 value
-= section
->vma
;
4148 if (section
== (asection
*) NULL
)
4151 name
= ssext
+ esym
.asym
.iss
;
4153 if (! (_bfd_generic_link_add_one_symbol
4154 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
4155 (const char *) NULL
, true, true,
4156 (struct bfd_link_hash_entry
**) &h
)))
4161 /* If we are building an ECOFF hash table, save the external
4162 symbol information. */
4163 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4165 if (h
->abfd
== (bfd
*) NULL
4166 || (section
!= &bfd_und_section
4167 && (! bfd_is_com_section (section
)
4168 || h
->root
.type
!= bfd_link_hash_defined
)))
4179 /* ECOFF final link routines. */
4181 static boolean ecoff_final_link_debug_accumulate
4182 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4184 static boolean ecoff_link_write_external
4185 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4186 static boolean ecoff_indirect_link_order
4187 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4188 struct bfd_link_order
*));
4189 static boolean ecoff_reloc_link_order
4190 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4191 struct bfd_link_order
*));
4193 /* ECOFF final link routine. This looks through all the input BFDs
4194 and gathers together all the debugging information, and then
4195 processes all the link order information. This may cause it to
4196 close and reopen some input BFDs; I'll see how bad this is. */
4199 ecoff_bfd_final_link (abfd
, info
)
4201 struct bfd_link_info
*info
;
4203 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4204 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4207 register bfd
*input_bfd
;
4209 struct bfd_link_order
*p
;
4211 /* We accumulate the debugging information counts in the symbolic
4213 symhdr
= &debug
->symbolic_header
;
4215 symhdr
->ilineMax
= 0;
4219 symhdr
->isymMax
= 0;
4220 symhdr
->ioptMax
= 0;
4221 symhdr
->iauxMax
= 0;
4223 symhdr
->issExtMax
= 0;
4226 symhdr
->iextMax
= 0;
4228 /* We accumulate the debugging information itself in the debug_info
4231 debug
->external_dnr
= NULL
;
4232 debug
->external_pdr
= NULL
;
4233 debug
->external_sym
= NULL
;
4234 debug
->external_opt
= NULL
;
4235 debug
->external_aux
= NULL
;
4237 debug
->ssext
= debug
->ssext_end
= NULL
;
4238 debug
->external_fdr
= NULL
;
4239 debug
->external_rfd
= NULL
;
4240 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4242 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4243 if (handle
== (PTR
) NULL
)
4246 /* Accumulate the debugging symbols from each input BFD. */
4247 for (input_bfd
= info
->input_bfds
;
4248 input_bfd
!= (bfd
*) NULL
;
4249 input_bfd
= input_bfd
->link_next
)
4253 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4255 /* Abitrarily set the symbolic header vstamp to the vstamp
4256 of the first object file in the link. */
4257 if (symhdr
->vstamp
== 0)
4259 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4260 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4264 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4265 debug
, &backend
->debug_swap
,
4270 /* Combine the register masks. */
4271 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4272 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4273 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4274 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4275 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4276 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4279 /* Write out the external symbols. */
4280 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4281 ecoff_link_write_external
,
4284 if (info
->relocateable
)
4286 /* We need to make a pass over the link_orders to count up the
4287 number of relocations we will need to output, so that we know
4288 how much space they will take up. */
4289 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4292 for (p
= o
->link_order_head
;
4293 p
!= (struct bfd_link_order
*) NULL
;
4295 if (p
->type
== bfd_indirect_link_order
)
4296 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4297 else if (p
->type
== bfd_section_reloc_link_order
4298 || p
->type
== bfd_symbol_reloc_link_order
)
4303 /* Compute the reloc and symbol file positions. */
4304 ecoff_compute_reloc_file_positions (abfd
);
4306 /* Write out the debugging information. */
4307 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4308 &backend
->debug_swap
, info
,
4309 ecoff_data (abfd
)->sym_filepos
))
4312 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4314 if (info
->relocateable
)
4316 /* Now reset the reloc_count field of the sections in the output
4317 BFD to 0, so that we can use them to keep track of how many
4318 relocs we have output thus far. */
4319 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4323 /* Get a value for the GP register. */
4324 if (ecoff_data (abfd
)->gp
== 0)
4326 struct bfd_link_hash_entry
*h
;
4328 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4329 if (h
!= (struct bfd_link_hash_entry
*) NULL
4330 && h
->type
== bfd_link_hash_defined
)
4331 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4332 + h
->u
.def
.section
->output_section
->vma
4333 + h
->u
.def
.section
->output_offset
);
4334 else if (info
->relocateable
)
4338 /* Make up a value. */
4340 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4343 && (strcmp (o
->name
, _SBSS
) == 0
4344 || strcmp (o
->name
, _SDATA
) == 0
4345 || strcmp (o
->name
, _LIT4
) == 0
4346 || strcmp (o
->name
, _LIT8
) == 0
4347 || strcmp (o
->name
, _LITA
) == 0))
4350 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4354 /* If the relocate_section function needs to do a reloc
4355 involving the GP value, it should make a reloc_dangerous
4356 callback to warn that GP is not defined. */
4360 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4362 /* Ignore any link_orders for the .reginfo section, which does
4363 not really exist. */
4364 if (strcmp (o
->name
, REGINFO
) == 0)
4367 for (p
= o
->link_order_head
;
4368 p
!= (struct bfd_link_order
*) NULL
;
4371 if (p
->type
== bfd_indirect_link_order
4372 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4373 == bfd_target_ecoff_flavour
))
4375 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4378 else if (p
->type
== bfd_section_reloc_link_order
4379 || p
->type
== bfd_symbol_reloc_link_order
)
4381 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4386 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4392 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4397 /* Accumulate the debugging information for an input BFD into the
4398 output BFD. This must read in the symbolic information of the
4402 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4405 struct bfd_link_info
*info
;
4408 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4409 const struct ecoff_debug_swap
* const swap
=
4410 &ecoff_backend (input_bfd
)->debug_swap
;
4411 HDRR
*symhdr
= &debug
->symbolic_header
;
4414 #define READ(ptr, offset, count, size, type) \
4415 if (symhdr->count == 0) \
4416 debug->ptr = NULL; \
4419 debug->ptr = (type) malloc (size * symhdr->count); \
4420 if (debug->ptr == NULL) \
4422 bfd_set_error (bfd_error_no_memory); \
4424 goto return_something; \
4426 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4428 || (bfd_read (debug->ptr, size, symhdr->count, \
4429 input_bfd) != size * symhdr->count)) \
4432 goto return_something; \
4436 /* If raw_syments is not NULL, then the data was already by read by
4437 ecoff_slurp_symbolic_info. */
4438 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4440 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4442 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4443 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4444 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4445 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4446 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4448 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4449 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4450 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4454 /* We do not read the external strings or the external symbols. */
4456 ret
= (bfd_ecoff_debug_accumulate
4457 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4458 &ecoff_backend (output_bfd
)->debug_swap
,
4459 input_bfd
, debug
, swap
, info
));
4462 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4464 if (debug
->line
!= NULL
)
4466 if (debug
->external_dnr
!= NULL
)
4467 free (debug
->external_dnr
);
4468 if (debug
->external_pdr
!= NULL
)
4469 free (debug
->external_pdr
);
4470 if (debug
->external_sym
!= NULL
)
4471 free (debug
->external_sym
);
4472 if (debug
->external_opt
!= NULL
)
4473 free (debug
->external_opt
);
4474 if (debug
->external_aux
!= NULL
)
4475 free (debug
->external_aux
);
4476 if (debug
->ss
!= NULL
)
4478 if (debug
->external_fdr
!= NULL
)
4479 free (debug
->external_fdr
);
4480 if (debug
->external_rfd
!= NULL
)
4481 free (debug
->external_rfd
);
4483 /* Make sure we don't accidentally follow one of these pointers
4484 into freed memory. */
4486 debug
->external_dnr
= NULL
;
4487 debug
->external_pdr
= NULL
;
4488 debug
->external_sym
= NULL
;
4489 debug
->external_opt
= NULL
;
4490 debug
->external_aux
= NULL
;
4492 debug
->external_fdr
= NULL
;
4493 debug
->external_rfd
= NULL
;
4499 /* Put out information for an external symbol. These come only from
4503 ecoff_link_write_external (h
, data
)
4504 struct ecoff_link_hash_entry
*h
;
4507 bfd
*output_bfd
= (bfd
*) data
;
4509 /* FIXME: We should check if this symbol is being stripped. */
4511 if (h
->root
.written
)
4514 if (h
->abfd
== (bfd
*) NULL
)
4517 h
->esym
.cobol_main
= 0;
4518 h
->esym
.weakext
= 0;
4519 h
->esym
.reserved
= 0;
4520 h
->esym
.ifd
= ifdNil
;
4521 h
->esym
.asym
.value
= 0;
4522 h
->esym
.asym
.st
= stGlobal
;
4524 if (h
->root
.type
!= bfd_link_hash_defined
)
4525 h
->esym
.asym
.sc
= scAbs
;
4528 asection
*output_section
;
4531 output_section
= h
->root
.u
.def
.section
->output_section
;
4532 name
= bfd_section_name (output_section
->owner
, output_section
);
4534 if (strcmp (name
, _TEXT
) == 0)
4535 h
->esym
.asym
.sc
= scText
;
4536 else if (strcmp (name
, _DATA
) == 0)
4537 h
->esym
.asym
.sc
= scData
;
4538 else if (strcmp (name
, _SDATA
) == 0)
4539 h
->esym
.asym
.sc
= scSData
;
4540 else if (strcmp (name
, _RDATA
) == 0)
4541 h
->esym
.asym
.sc
= scRData
;
4542 else if (strcmp (name
, _BSS
) == 0)
4543 h
->esym
.asym
.sc
= scBss
;
4544 else if (strcmp (name
, _SBSS
) == 0)
4545 h
->esym
.asym
.sc
= scSBss
;
4546 else if (strcmp (name
, _INIT
) == 0)
4547 h
->esym
.asym
.sc
= scInit
;
4548 else if (strcmp (name
, _FINI
) == 0)
4549 h
->esym
.asym
.sc
= scFini
;
4550 else if (strcmp (name
, _PDATA
) == 0)
4551 h
->esym
.asym
.sc
= scPData
;
4552 else if (strcmp (name
, _XDATA
) == 0)
4553 h
->esym
.asym
.sc
= scXData
;
4555 h
->esym
.asym
.sc
= scAbs
;
4558 h
->esym
.asym
.reserved
= 0;
4559 h
->esym
.asym
.index
= indexNil
;
4561 else if (h
->esym
.ifd
!= -1)
4563 struct ecoff_debug_info
*debug
;
4565 /* Adjust the FDR index for the symbol by that used for the
4567 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4568 BFD_ASSERT (h
->esym
.ifd
>= 0
4569 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4570 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4573 switch (h
->root
.type
)
4576 case bfd_link_hash_new
:
4578 case bfd_link_hash_undefined
:
4579 case bfd_link_hash_weak
:
4580 if (h
->esym
.asym
.sc
!= scUndefined
4581 && h
->esym
.asym
.sc
!= scSUndefined
)
4582 h
->esym
.asym
.sc
= scUndefined
;
4584 case bfd_link_hash_defined
:
4585 if (h
->esym
.asym
.sc
== scUndefined
4586 || h
->esym
.asym
.sc
== scSUndefined
)
4587 h
->esym
.asym
.sc
= scAbs
;
4588 else if (h
->esym
.asym
.sc
== scCommon
)
4589 h
->esym
.asym
.sc
= scBss
;
4590 else if (h
->esym
.asym
.sc
== scSCommon
)
4591 h
->esym
.asym
.sc
= scSBss
;
4592 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4593 + h
->root
.u
.def
.section
->output_section
->vma
4594 + h
->root
.u
.def
.section
->output_offset
);
4596 case bfd_link_hash_common
:
4597 if (h
->esym
.asym
.sc
!= scCommon
4598 && h
->esym
.asym
.sc
!= scSCommon
)
4599 h
->esym
.asym
.sc
= scCommon
;
4600 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4602 case bfd_link_hash_indirect
:
4603 case bfd_link_hash_warning
:
4604 /* FIXME: Ignore these for now. The circumstances under which
4605 they should be written out are not clear to me. */
4609 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4611 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4612 h
->root
.written
= true;
4614 return (bfd_ecoff_debug_one_external
4615 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4616 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4620 /* Relocate and write an ECOFF section into an ECOFF output file. */
4623 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4625 struct bfd_link_info
*info
;
4626 asection
*output_section
;
4627 struct bfd_link_order
*link_order
;
4629 asection
*input_section
;
4631 struct ecoff_section_tdata
*section_tdata
;
4632 bfd_size_type raw_size
;
4633 bfd_size_type cooked_size
;
4634 bfd_byte
*contents
= NULL
;
4635 bfd_size_type external_reloc_size
;
4636 bfd_size_type external_relocs_size
;
4637 PTR external_relocs
= NULL
;
4639 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4641 if (link_order
->size
== 0)
4644 input_section
= link_order
->u
.indirect
.section
;
4645 input_bfd
= input_section
->owner
;
4646 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4648 raw_size
= input_section
->_raw_size
;
4649 cooked_size
= input_section
->_cooked_size
;
4650 if (cooked_size
== 0)
4651 cooked_size
= raw_size
;
4653 BFD_ASSERT (input_section
->output_section
== output_section
);
4654 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4655 BFD_ASSERT (cooked_size
== link_order
->size
);
4657 /* Get the section contents. We allocate memory for the larger of
4658 the size before relocating and the size after relocating. */
4659 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4662 if (contents
== NULL
&& raw_size
!= 0)
4664 bfd_set_error (bfd_error_no_memory
);
4668 /* If we are relaxing, the contents may have already been read into
4669 memory, in which case we copy them into our new buffer. We don't
4670 simply reuse the old buffer in case cooked_size > raw_size. */
4671 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4672 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4673 memcpy (contents
, section_tdata
->contents
, raw_size
);
4676 if (! bfd_get_section_contents (input_bfd
, input_section
,
4678 (file_ptr
) 0, raw_size
))
4682 /* Get the relocs. If we are relaxing MIPS code, they will already
4683 have been read in. Otherwise, we read them in now. */
4684 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4685 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4687 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4688 external_relocs
= section_tdata
->external_relocs
;
4691 external_relocs
= (PTR
) malloc (external_relocs_size
);
4692 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4694 bfd_set_error (bfd_error_no_memory
);
4698 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4699 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4700 != external_relocs_size
))
4704 /* Relocate the section contents. */
4705 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4706 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4710 /* Write out the relocated section. */
4711 if (! bfd_set_section_contents (output_bfd
,
4714 input_section
->output_offset
,
4718 /* If we are producing relocateable output, the relocs were
4719 modified, and we write them out now. We use the reloc_count
4720 field of output_section to keep track of the number of relocs we
4721 have output so far. */
4722 if (info
->relocateable
)
4724 if (bfd_seek (output_bfd
,
4725 (output_section
->rel_filepos
+
4726 output_section
->reloc_count
* external_reloc_size
),
4728 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4729 != external_relocs_size
))
4731 output_section
->reloc_count
+= input_section
->reloc_count
;
4734 if (contents
!= NULL
)
4736 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4737 free (external_relocs
);
4741 if (contents
!= NULL
)
4743 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4744 free (external_relocs
);
4748 /* Generate a reloc when linking an ECOFF file. This is a reloc
4749 requested by the linker, and does come from any input file. This
4750 is used to build constructor and destructor tables when linking
4754 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4756 struct bfd_link_info
*info
;
4757 asection
*output_section
;
4758 struct bfd_link_order
*link_order
;
4761 struct internal_reloc in
;
4762 bfd_size_type external_reloc_size
;
4766 /* We set up an arelent to pass to the backend adjust_reloc_out
4768 rel
.address
= link_order
->offset
;
4770 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4771 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4773 bfd_set_error (bfd_error_bad_value
);
4777 if (link_order
->type
== bfd_section_reloc_link_order
)
4778 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4781 /* We can't set up a reloc against a symbol correctly, because
4782 we have no asymbol structure. Currently no adjust_reloc_out
4784 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4787 /* All ECOFF relocs are in-place. Put the addend into the object
4790 BFD_ASSERT (rel
.howto
->partial_inplace
);
4791 if (link_order
->u
.reloc
.p
->addend
!= 0)
4794 bfd_reloc_status_type rstat
;
4798 size
= bfd_get_reloc_size (rel
.howto
);
4799 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4800 if (buf
== (bfd_byte
*) NULL
)
4802 bfd_set_error (bfd_error_no_memory
);
4805 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4806 link_order
->u
.reloc
.p
->addend
, buf
);
4812 case bfd_reloc_outofrange
:
4814 case bfd_reloc_overflow
:
4815 if (! ((*info
->callbacks
->reloc_overflow
)
4817 (link_order
->type
== bfd_section_reloc_link_order
4818 ? bfd_section_name (output_bfd
,
4819 link_order
->u
.reloc
.p
->u
.section
)
4820 : link_order
->u
.reloc
.p
->u
.name
),
4821 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4822 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4829 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4830 (file_ptr
) link_order
->offset
, size
);
4838 /* Move the information into a internal_reloc structure. */
4839 in
.r_vaddr
= (rel
.address
4840 + bfd_get_section_vma (output_bfd
, output_section
));
4841 in
.r_type
= rel
.howto
->type
;
4843 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4845 struct ecoff_link_hash_entry
*h
;
4847 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4848 link_order
->u
.reloc
.p
->u
.name
,
4849 false, false, true);
4850 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4852 in
.r_symndx
= h
->indx
;
4855 if (! ((*info
->callbacks
->unattached_reloc
)
4856 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4857 (asection
*) NULL
, (bfd_vma
) 0)))
4867 name
= bfd_get_section_name (output_bfd
,
4868 link_order
->u
.reloc
.p
->u
.section
);
4869 if (strcmp (name
, ".text") == 0)
4870 in
.r_symndx
= RELOC_SECTION_TEXT
;
4871 else if (strcmp (name
, ".rdata") == 0)
4872 in
.r_symndx
= RELOC_SECTION_RDATA
;
4873 else if (strcmp (name
, ".data") == 0)
4874 in
.r_symndx
= RELOC_SECTION_DATA
;
4875 else if (strcmp (name
, ".sdata") == 0)
4876 in
.r_symndx
= RELOC_SECTION_SDATA
;
4877 else if (strcmp (name
, ".sbss") == 0)
4878 in
.r_symndx
= RELOC_SECTION_SBSS
;
4879 else if (strcmp (name
, ".bss") == 0)
4880 in
.r_symndx
= RELOC_SECTION_BSS
;
4881 else if (strcmp (name
, ".init") == 0)
4882 in
.r_symndx
= RELOC_SECTION_INIT
;
4883 else if (strcmp (name
, ".lit8") == 0)
4884 in
.r_symndx
= RELOC_SECTION_LIT8
;
4885 else if (strcmp (name
, ".lit4") == 0)
4886 in
.r_symndx
= RELOC_SECTION_LIT4
;
4887 else if (strcmp (name
, ".xdata") == 0)
4888 in
.r_symndx
= RELOC_SECTION_XDATA
;
4889 else if (strcmp (name
, ".pdata") == 0)
4890 in
.r_symndx
= RELOC_SECTION_PDATA
;
4891 else if (strcmp (name
, ".fini") == 0)
4892 in
.r_symndx
= RELOC_SECTION_FINI
;
4893 else if (strcmp (name
, ".lita") == 0)
4894 in
.r_symndx
= RELOC_SECTION_LITA
;
4895 else if (strcmp (name
, "*ABS*") == 0)
4896 in
.r_symndx
= RELOC_SECTION_ABS
;
4902 /* Let the BFD backend adjust the reloc. */
4903 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4905 /* Get some memory and swap out the reloc. */
4906 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4907 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4908 if (rbuf
== (bfd_byte
*) NULL
)
4910 bfd_set_error (bfd_error_no_memory
);
4914 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4916 ok
= (bfd_seek (output_bfd
,
4917 (output_section
->rel_filepos
+
4918 output_section
->reloc_count
* external_reloc_size
),
4920 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4921 == external_reloc_size
));
4924 ++output_section
->reloc_count
;