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
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
114 ecoff
->text_start
= internal_a
->text_start
;
115 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
116 ecoff
->gp
= internal_a
->gp_value
;
117 ecoff
->gprmask
= internal_a
->gprmask
;
118 for (i
= 0; i
< 4; i
++)
119 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
120 ecoff
->fprmask
= internal_a
->fprmask
;
121 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
122 abfd
->flags
|= D_PAGED
;
125 /* It turns out that no special action is required by the MIPS or
126 Alpha ECOFF backends. They have different information in the
127 a.out header, but we just copy it all (e.g., gprmask, cprmask and
128 fprmask) and let the swapping routines ensure that only relevant
129 information is written out. */
134 /* This is a hook needed by SCO COFF, but we have nothing to do. */
138 ecoff_make_section_hook (abfd
, name
)
142 return (asection
*) NULL
;
145 /* Initialize a new section. */
148 ecoff_new_section_hook (abfd
, section
)
152 /* For the .pdata section, which has a special meaning on the Alpha,
153 we set the alignment to 8. We correct this later in
154 ecoff_compute_section_file_positions. We do this hackery because
155 we need to know the exact unaligned size of the .pdata section in
156 order to set the lnnoptr field correctly. */
157 if (strcmp (section
->name
, _PDATA
) == 0)
158 section
->alignment_power
= 3;
160 section
->alignment_power
= abfd
->xvec
->align_power_min
;
162 if (strcmp (section
->name
, _TEXT
) == 0)
163 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
164 else if (strcmp (section
->name
, _DATA
) == 0
165 || strcmp (section
->name
, _SDATA
) == 0)
166 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
167 else if (strcmp (section
->name
, _RDATA
) == 0
168 || strcmp (section
->name
, _LIT8
) == 0
169 || strcmp (section
->name
, _LIT4
) == 0)
170 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
171 else if (strcmp (section
->name
, _BSS
) == 0
172 || strcmp (section
->name
, _SBSS
) == 0)
173 section
->flags
|= SEC_ALLOC
;
174 else if (strcmp (section
->name
, _LIB
) == 0)
176 /* An Irix 4 shared libary. */
177 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
180 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
181 uncertain about .init on some systems and I don't know how shared
187 /* Determine the machine architecture and type. This is called from
188 the generic COFF routines. It is the inverse of ecoff_get_magic,
189 below. This could be an ECOFF backend routine, with one version
190 for each target, but there aren't all that many ECOFF targets. */
193 ecoff_set_arch_mach_hook (abfd
, filehdr
)
197 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
198 enum bfd_architecture arch
;
201 switch (internal_f
->f_magic
)
204 case MIPS_MAGIC_LITTLE
:
206 arch
= bfd_arch_mips
;
210 case MIPS_MAGIC_LITTLE2
:
211 case MIPS_MAGIC_BIG2
:
212 /* MIPS ISA level 2: the r6000 */
213 arch
= bfd_arch_mips
;
217 case MIPS_MAGIC_LITTLE3
:
218 case MIPS_MAGIC_BIG3
:
219 /* MIPS ISA level 3: the r4000 */
220 arch
= bfd_arch_mips
;
225 arch
= bfd_arch_alpha
;
230 arch
= bfd_arch_obscure
;
235 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
238 /* Get the magic number to use based on the architecture and machine.
239 This is the inverse of ecoff_set_arch_mach_hook, above. */
242 ecoff_get_magic (abfd
)
247 switch (bfd_get_arch (abfd
))
250 switch (bfd_get_mach (abfd
))
255 big
= MIPS_MAGIC_BIG
;
256 little
= MIPS_MAGIC_LITTLE
;
260 big
= MIPS_MAGIC_BIG2
;
261 little
= MIPS_MAGIC_LITTLE2
;
265 big
= MIPS_MAGIC_BIG3
;
266 little
= MIPS_MAGIC_LITTLE3
;
270 return abfd
->xvec
->byteorder_big_p
? big
: little
;
281 /* Get the section s_flags to use for a section. */
284 ecoff_sec_to_styp_flags (name
, flags
)
292 if (strcmp (name
, _TEXT
) == 0)
294 else if (strcmp (name
, _DATA
) == 0)
296 else if (strcmp (name
, _SDATA
) == 0)
298 else if (strcmp (name
, _RDATA
) == 0)
300 else if (strcmp (name
, _LITA
) == 0)
302 else if (strcmp (name
, _LIT8
) == 0)
304 else if (strcmp (name
, _LIT4
) == 0)
306 else if (strcmp (name
, _BSS
) == 0)
308 else if (strcmp (name
, _SBSS
) == 0)
310 else if (strcmp (name
, _INIT
) == 0)
311 styp
= STYP_ECOFF_INIT
;
312 else if (strcmp (name
, _FINI
) == 0)
313 styp
= STYP_ECOFF_FINI
;
314 else if (strcmp (name
, _PDATA
) == 0)
316 else if (strcmp (name
, _XDATA
) == 0)
318 else if (strcmp (name
, _LIB
) == 0)
319 styp
= STYP_ECOFF_LIB
;
320 else if (flags
& SEC_CODE
)
322 else if (flags
& SEC_DATA
)
324 else if (flags
& SEC_READONLY
)
326 else if (flags
& SEC_LOAD
)
331 if (flags
& SEC_NEVER_LOAD
)
337 /* Get the BFD flags to use for a section. */
341 ecoff_styp_to_sec_flags (abfd
, hdr
)
345 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
346 long styp_flags
= internal_s
->s_flags
;
347 flagword sec_flags
=0;
349 if (styp_flags
& STYP_NOLOAD
)
350 sec_flags
|= SEC_NEVER_LOAD
;
352 /* For 386 COFF, at least, an unloadable text or data section is
353 actually a shared library section. */
354 if ((styp_flags
& STYP_TEXT
)
355 || (styp_flags
& STYP_ECOFF_INIT
)
356 || (styp_flags
& STYP_ECOFF_FINI
))
358 if (sec_flags
& SEC_NEVER_LOAD
)
359 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
361 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
363 else if ((styp_flags
& STYP_DATA
)
364 || (styp_flags
& STYP_RDATA
)
365 || (styp_flags
& STYP_SDATA
)
366 || styp_flags
== STYP_PDATA
367 || styp_flags
== STYP_XDATA
)
369 if (sec_flags
& SEC_NEVER_LOAD
)
370 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
372 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
373 if ((styp_flags
& STYP_RDATA
)
374 || styp_flags
== STYP_PDATA
)
375 sec_flags
|= SEC_READONLY
;
377 else if ((styp_flags
& STYP_BSS
)
378 || (styp_flags
& STYP_SBSS
))
380 sec_flags
|= SEC_ALLOC
;
382 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
384 sec_flags
|= SEC_NEVER_LOAD
;
386 else if ((styp_flags
& STYP_LITA
)
387 || (styp_flags
& STYP_LIT8
)
388 || (styp_flags
& STYP_LIT4
))
390 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
392 else if (styp_flags
& STYP_ECOFF_LIB
)
394 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
398 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
404 /* Routines to swap auxiliary information in and out. I am assuming
405 that the auxiliary information format is always going to be target
408 /* Swap in a type information record.
409 BIGEND says whether AUX symbols are big-endian or little-endian; this
410 info comes from the file header record (fh-fBigendian). */
413 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
415 struct tir_ext
*ext_copy
;
418 struct tir_ext ext
[1];
420 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
422 /* now the fun stuff... */
424 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
425 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
426 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
427 >> TIR_BITS1_BT_SH_BIG
;
428 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
429 >> TIR_BITS_TQ4_SH_BIG
;
430 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
431 >> TIR_BITS_TQ5_SH_BIG
;
432 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
433 >> TIR_BITS_TQ0_SH_BIG
;
434 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
435 >> TIR_BITS_TQ1_SH_BIG
;
436 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
437 >> TIR_BITS_TQ2_SH_BIG
;
438 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
439 >> TIR_BITS_TQ3_SH_BIG
;
441 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
442 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
443 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
444 >> TIR_BITS1_BT_SH_LITTLE
;
445 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
446 >> TIR_BITS_TQ4_SH_LITTLE
;
447 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
448 >> TIR_BITS_TQ5_SH_LITTLE
;
449 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
450 >> TIR_BITS_TQ0_SH_LITTLE
;
451 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
452 >> TIR_BITS_TQ1_SH_LITTLE
;
453 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
454 >> TIR_BITS_TQ2_SH_LITTLE
;
455 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
456 >> TIR_BITS_TQ3_SH_LITTLE
;
460 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
465 /* Swap out a type information record.
466 BIGEND says whether AUX symbols are big-endian or little-endian; this
467 info comes from the file header record (fh-fBigendian). */
470 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
477 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
479 /* now the fun stuff... */
481 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
482 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
483 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
484 & TIR_BITS1_BT_BIG
));
485 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
487 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
488 & TIR_BITS_TQ5_BIG
));
489 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
491 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
492 & TIR_BITS_TQ1_BIG
));
493 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
495 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
496 & TIR_BITS_TQ3_BIG
));
498 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
499 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
500 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
501 & TIR_BITS1_BT_LITTLE
));
502 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
503 & TIR_BITS_TQ4_LITTLE
)
504 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
505 & TIR_BITS_TQ5_LITTLE
));
506 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
507 & TIR_BITS_TQ0_LITTLE
)
508 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
509 & TIR_BITS_TQ1_LITTLE
));
510 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
511 & TIR_BITS_TQ2_LITTLE
)
512 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
513 & TIR_BITS_TQ3_LITTLE
));
517 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
522 /* Swap in a relative symbol record. BIGEND says whether it is in
523 big-endian or little-endian format.*/
526 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
528 struct rndx_ext
*ext_copy
;
531 struct rndx_ext ext
[1];
533 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
535 /* now the fun stuff... */
537 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
538 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
539 >> RNDX_BITS1_RFD_SH_BIG
);
540 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
541 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
542 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
543 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
545 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
546 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
547 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
548 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
549 >> RNDX_BITS1_INDEX_SH_LITTLE
)
550 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
551 | ((unsigned int) ext
->r_bits
[3]
552 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
556 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
561 /* Swap out a relative symbol record. BIGEND says whether it is in
562 big-endian or little-endian format.*/
565 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
568 struct rndx_ext
*ext
;
572 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
574 /* now the fun stuff... */
576 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
577 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
578 & RNDX_BITS1_RFD_BIG
)
579 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
580 & RNDX_BITS1_INDEX_BIG
));
581 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
582 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
584 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
585 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
586 & RNDX_BITS1_RFD_LITTLE
)
587 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
588 & RNDX_BITS1_INDEX_LITTLE
));
589 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
590 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
594 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
599 /* Read in the symbolic header for an ECOFF object file. */
602 ecoff_slurp_symbolic_header (abfd
)
605 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
606 bfd_size_type external_hdr_size
;
608 HDRR
*internal_symhdr
;
610 /* See if we've already read it in. */
611 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
612 backend
->debug_swap
.sym_magic
)
615 /* See whether there is a symbolic header. */
616 if (ecoff_data (abfd
)->sym_filepos
== 0)
618 bfd_get_symcount (abfd
) = 0;
622 /* At this point bfd_get_symcount (abfd) holds the number of symbols
623 as read from the file header, but on ECOFF this is always the
624 size of the symbolic information header. It would be cleaner to
625 handle this when we first read the file in coffgen.c. */
626 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
627 if (bfd_get_symcount (abfd
) != external_hdr_size
)
629 bfd_set_error (bfd_error_bad_value
);
633 /* Read the symbolic information header. */
634 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
637 bfd_set_error (bfd_error_no_memory
);
641 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
642 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
643 != external_hdr_size
))
645 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
646 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
648 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
650 bfd_set_error (bfd_error_bad_value
);
654 /* Now we can get the correct number of symbols. */
655 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
656 + internal_symhdr
->iextMax
);
667 /* Read in and swap the important symbolic information for an ECOFF
668 object file. This is called by gdb. */
671 ecoff_slurp_symbolic_info (abfd
)
674 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
675 HDRR
*internal_symhdr
;
676 bfd_size_type raw_base
;
677 bfd_size_type raw_size
;
679 bfd_size_type external_fdr_size
;
683 bfd_size_type raw_end
;
684 bfd_size_type cb_end
;
686 /* Check whether we've already gotten it, and whether there's any to
688 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
690 if (ecoff_data (abfd
)->sym_filepos
== 0)
692 bfd_get_symcount (abfd
) = 0;
696 if (! ecoff_slurp_symbolic_header (abfd
))
699 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
701 /* Read all the symbolic information at once. */
702 raw_base
= (ecoff_data (abfd
)->sym_filepos
703 + backend
->debug_swap
.external_hdr_size
);
705 /* Alpha ecoff makes the determination of raw_size difficult. It has
706 an undocumented debug data section between the symhdr and the first
707 documented section. And the ordering of the sections varies between
708 statically and dynamically linked executables.
709 If bfd supports SEEK_END someday, this code could be simplified. */
713 #define UPDATE_RAW_END(start, count, size) \
714 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
715 if (cb_end > raw_end) \
718 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
719 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
720 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
721 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
722 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
723 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
724 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
725 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
726 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
727 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
728 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
730 #undef UPDATE_RAW_END
732 raw_size
= raw_end
- raw_base
;
735 ecoff_data (abfd
)->sym_filepos
= 0;
738 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
741 bfd_set_error (bfd_error_no_memory
);
745 (ecoff_data (abfd
)->sym_filepos
746 + backend
->debug_swap
.external_hdr_size
),
748 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
750 bfd_release (abfd
, raw
);
754 ecoff_data (abfd
)->raw_syments
= raw
;
756 /* Get pointers for the numeric offsets in the HDRR structure. */
757 #define FIX(off1, off2, type) \
758 if (internal_symhdr->off1 == 0) \
759 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
761 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
762 + internal_symhdr->off1 \
764 FIX (cbLineOffset
, line
, unsigned char *);
765 FIX (cbDnOffset
, external_dnr
, PTR
);
766 FIX (cbPdOffset
, external_pdr
, PTR
);
767 FIX (cbSymOffset
, external_sym
, PTR
);
768 FIX (cbOptOffset
, external_opt
, PTR
);
769 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
770 FIX (cbSsOffset
, ss
, char *);
771 FIX (cbSsExtOffset
, ssext
, char *);
772 FIX (cbFdOffset
, external_fdr
, PTR
);
773 FIX (cbRfdOffset
, external_rfd
, PTR
);
774 FIX (cbExtOffset
, external_ext
, PTR
);
777 /* I don't want to always swap all the data, because it will just
778 waste time and most programs will never look at it. The only
779 time the linker needs most of the debugging information swapped
780 is when linking big-endian and little-endian MIPS object files
781 together, which is not a common occurrence.
783 We need to look at the fdr to deal with a lot of information in
784 the symbols, so we swap them here. */
785 ecoff_data (abfd
)->debug_info
.fdr
=
786 (struct fdr
*) bfd_alloc (abfd
,
787 (internal_symhdr
->ifdMax
*
788 sizeof (struct fdr
)));
789 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
791 bfd_set_error (bfd_error_no_memory
);
794 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
795 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
796 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
797 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
798 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
799 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
804 /* ECOFF symbol table routines. The ECOFF symbol table is described
805 in gcc/mips-tfile.c. */
807 /* ECOFF uses two common sections. One is the usual one, and the
808 other is for small objects. All the small objects are kept
809 together, and then referenced via the gp pointer, which yields
810 faster assembler code. This is what we use for the small common
812 static asection ecoff_scom_section
;
813 static asymbol ecoff_scom_symbol
;
814 static asymbol
*ecoff_scom_symbol_ptr
;
816 /* Create an empty symbol. */
819 ecoff_make_empty_symbol (abfd
)
822 ecoff_symbol_type
*new;
824 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
825 if (new == (ecoff_symbol_type
*) NULL
)
827 bfd_set_error (bfd_error_no_memory
);
828 return (asymbol
*) NULL
;
830 memset ((PTR
) new, 0, sizeof *new);
831 new->symbol
.section
= (asection
*) NULL
;
832 new->fdr
= (FDR
*) NULL
;
835 new->symbol
.the_bfd
= abfd
;
839 /* Set the BFD flags and section for an ECOFF symbol. */
842 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
847 asymbol
**indirect_ptr_ptr
;
849 asym
->the_bfd
= abfd
;
850 asym
->value
= ecoff_sym
->value
;
851 asym
->section
= &bfd_debug_section
;
854 /* An indirect symbol requires two consecutive stabs symbols. */
855 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
857 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
859 /* @@ Stuffing pointers into integers is a no-no.
860 We can usually get away with it if the integer is
861 large enough though. */
862 if (sizeof (asym
) > sizeof (bfd_vma
))
864 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
866 asym
->flags
= BSF_DEBUGGING
;
867 asym
->section
= &bfd_und_section
;
868 *indirect_ptr_ptr
= NULL
;
872 if (ECOFF_IS_STAB (ecoff_sym
)
873 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
875 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
876 asym
->section
= &bfd_ind_section
;
877 /* Pass this symbol on to the next call to this function. */
878 *indirect_ptr_ptr
= asym
;
882 /* Most symbol types are just for debugging. */
883 switch (ecoff_sym
->st
)
892 if (ECOFF_IS_STAB (ecoff_sym
))
894 asym
->flags
= BSF_DEBUGGING
;
899 asym
->flags
= BSF_DEBUGGING
;
904 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
906 asym
->flags
= BSF_LOCAL
;
907 switch (ecoff_sym
->sc
)
910 /* Used for compiler generated labels. Leave them in the
911 debugging section, and mark them as local. If BSF_DEBUGGING
912 is set, then nm does not display them for some reason. If no
913 flags are set then the linker whines about them. */
914 asym
->flags
= BSF_LOCAL
;
917 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
918 asym
->value
-= asym
->section
->vma
;
921 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
922 asym
->value
-= asym
->section
->vma
;
925 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
926 asym
->value
-= asym
->section
->vma
;
929 asym
->flags
= BSF_DEBUGGING
;
932 asym
->section
= &bfd_abs_section
;
935 asym
->section
= &bfd_und_section
;
945 asym
->flags
= BSF_DEBUGGING
;
948 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
949 asym
->value
-= asym
->section
->vma
;
952 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
953 asym
->value
-= asym
->section
->vma
;
956 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
957 asym
->value
-= asym
->section
->vma
;
960 asym
->flags
= BSF_DEBUGGING
;
963 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
965 asym
->section
= &bfd_com_section
;
971 if (ecoff_scom_section
.name
== NULL
)
973 /* Initialize the small common section. */
974 ecoff_scom_section
.name
= SCOMMON
;
975 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
976 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
977 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
978 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
979 ecoff_scom_symbol
.name
= SCOMMON
;
980 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
981 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
982 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
984 asym
->section
= &ecoff_scom_section
;
989 asym
->flags
= BSF_DEBUGGING
;
992 asym
->section
= &bfd_und_section
;
997 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
998 asym
->value
-= asym
->section
->vma
;
1003 asym
->flags
= BSF_DEBUGGING
;
1006 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1007 asym
->value
-= asym
->section
->vma
;
1013 /* Look for special constructors symbols and make relocation entries
1014 in a special construction section. These are produced by the
1015 -fgnu-linker argument to g++. */
1016 if (ECOFF_IS_STAB (ecoff_sym
))
1018 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1030 arelent_chain
*reloc_chain
;
1031 unsigned int bitsize
;
1033 /* Get a section with the same name as the symbol (usually
1034 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1035 name ___CTOR_LIST (three underscores). We need
1036 __CTOR_LIST (two underscores), since ECOFF doesn't use
1037 a leading underscore. This should be handled by gcc,
1038 but instead we do it here. Actually, this should all
1039 be done differently anyhow. */
1040 name
= bfd_asymbol_name (asym
);
1041 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1046 section
= bfd_get_section_by_name (abfd
, name
);
1047 if (section
== (asection
*) NULL
)
1051 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1054 bfd_set_error (bfd_error_no_memory
);
1057 strcpy (copy
, name
);
1058 section
= bfd_make_section (abfd
, copy
);
1061 /* Build a reloc pointing to this constructor. */
1063 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1066 bfd_set_error (bfd_error_no_memory
);
1069 reloc_chain
->relent
.sym_ptr_ptr
=
1070 bfd_get_section (asym
)->symbol_ptr_ptr
;
1071 reloc_chain
->relent
.address
= section
->_raw_size
;
1072 reloc_chain
->relent
.addend
= asym
->value
;
1073 reloc_chain
->relent
.howto
=
1074 ecoff_backend (abfd
)->constructor_reloc
;
1076 /* Set up the constructor section to hold the reloc. */
1077 section
->flags
= SEC_CONSTRUCTOR
;
1078 ++section
->reloc_count
;
1080 /* Constructor sections must be rounded to a boundary
1081 based on the bitsize. These are not real sections--
1082 they are handled specially by the linker--so the ECOFF
1083 16 byte alignment restriction does not apply. */
1084 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1085 section
->alignment_power
= 1;
1086 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1087 ++section
->alignment_power
;
1089 reloc_chain
->next
= section
->constructor_chain
;
1090 section
->constructor_chain
= reloc_chain
;
1091 section
->_raw_size
+= bitsize
/ 8;
1093 /* Mark the symbol as a constructor. */
1094 asym
->flags
|= BSF_CONSTRUCTOR
;
1102 /* Read an ECOFF symbol table. */
1105 ecoff_slurp_symbol_table (abfd
)
1108 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1109 const bfd_size_type external_ext_size
1110 = backend
->debug_swap
.external_ext_size
;
1111 const bfd_size_type external_sym_size
1112 = backend
->debug_swap
.external_sym_size
;
1113 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1114 = backend
->debug_swap
.swap_ext_in
;
1115 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1116 = backend
->debug_swap
.swap_sym_in
;
1117 bfd_size_type internal_size
;
1118 ecoff_symbol_type
*internal
;
1119 ecoff_symbol_type
*internal_ptr
;
1120 asymbol
*indirect_ptr
;
1126 /* If we've already read in the symbol table, do nothing. */
1127 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1130 /* Get the symbolic information. */
1131 if (ecoff_slurp_symbolic_info (abfd
) == false)
1133 if (bfd_get_symcount (abfd
) == 0)
1136 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1137 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1138 if (internal
== NULL
)
1140 bfd_set_error (bfd_error_no_memory
);
1144 internal_ptr
= internal
;
1145 indirect_ptr
= NULL
;
1146 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1147 eraw_end
= (eraw_src
1148 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1149 * external_ext_size
));
1150 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1154 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1155 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1156 + internal_esym
.asym
.iss
);
1157 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1158 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1160 /* The alpha uses a negative ifd field for section symbols. */
1161 if (internal_esym
.ifd
>= 0)
1162 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1163 + internal_esym
.ifd
);
1165 internal_ptr
->fdr
= NULL
;
1166 internal_ptr
->local
= false;
1167 internal_ptr
->native
= (PTR
) eraw_src
;
1169 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1171 /* The local symbols must be accessed via the fdr's, because the
1172 string and aux indices are relative to the fdr information. */
1173 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1174 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1175 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1180 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1181 + fdr_ptr
->isymBase
* external_sym_size
);
1182 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1184 lraw_src
< lraw_end
;
1185 lraw_src
+= external_sym_size
, internal_ptr
++)
1189 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1190 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1192 + internal_sym
.iss
);
1193 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1194 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1196 internal_ptr
->fdr
= fdr_ptr
;
1197 internal_ptr
->local
= true;
1198 internal_ptr
->native
= (PTR
) lraw_src
;
1201 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1203 ecoff_data (abfd
)->canonical_symbols
= internal
;
1208 /* Return the amount of space needed for the canonical symbols. */
1211 ecoff_get_symtab_upper_bound (abfd
)
1214 if (! ecoff_slurp_symbolic_info (abfd
))
1217 if (bfd_get_symcount (abfd
) == 0)
1220 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1223 /* Get the canonical symbols. */
1226 ecoff_get_symtab (abfd
, alocation
)
1228 asymbol
**alocation
;
1230 unsigned int counter
= 0;
1231 ecoff_symbol_type
*symbase
;
1232 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1234 if (ecoff_slurp_symbol_table (abfd
) == false)
1236 if (bfd_get_symcount (abfd
) == 0)
1239 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1240 while (counter
< bfd_get_symcount (abfd
))
1242 *(location
++) = symbase
++;
1245 *location
++ = (ecoff_symbol_type
*) NULL
;
1246 return bfd_get_symcount (abfd
);
1249 /* Turn ECOFF type information into a printable string.
1250 ecoff_emit_aggregate and ecoff_type_to_string are from
1251 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1253 /* Write aggregate information to a string. */
1256 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1264 const struct ecoff_debug_swap
* const debug_swap
=
1265 &ecoff_backend (abfd
)->debug_swap
;
1266 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1267 unsigned int ifd
= rndx
->rfd
;
1268 unsigned int indx
= rndx
->index
;
1274 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1275 struct return type of a procedure compiled without -g. */
1276 if (ifd
== 0xffffffff
1277 || (rndx
->rfd
== 0xfff && indx
== 0))
1278 name
= "<undefined>";
1279 else if (indx
== indexNil
)
1285 if (debug_info
->external_rfd
== NULL
)
1286 fdr
= debug_info
->fdr
+ ifd
;
1291 (*debug_swap
->swap_rfd_in
) (abfd
,
1292 ((char *) debug_info
->external_rfd
1293 + ((fdr
->rfdBase
+ ifd
)
1294 * debug_swap
->external_rfd_size
)),
1296 fdr
= debug_info
->fdr
+ rfd
;
1299 indx
+= fdr
->isymBase
;
1301 (*debug_swap
->swap_sym_in
) (abfd
,
1302 ((char *) debug_info
->external_sym
1303 + indx
* debug_swap
->external_sym_size
),
1306 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1310 "%s %s { ifd = %u, index = %lu }",
1313 + debug_info
->symbolic_header
.iextMax
));
1316 /* Convert the type information to string format. */
1319 ecoff_type_to_string (abfd
, fdr
, indx
)
1324 union aux_ext
*aux_ptr
;
1333 unsigned int basic_type
;
1335 static char buffer1
[1024];
1336 static char buffer2
[1024];
1341 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1342 bigendian
= fdr
->fBigendian
;
1344 for (i
= 0; i
< 7; i
++)
1346 qualifiers
[i
].low_bound
= 0;
1347 qualifiers
[i
].high_bound
= 0;
1348 qualifiers
[i
].stride
= 0;
1351 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1352 return "-1 (no type)";
1353 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1355 basic_type
= u
.ti
.bt
;
1356 qualifiers
[0].type
= u
.ti
.tq0
;
1357 qualifiers
[1].type
= u
.ti
.tq1
;
1358 qualifiers
[2].type
= u
.ti
.tq2
;
1359 qualifiers
[3].type
= u
.ti
.tq3
;
1360 qualifiers
[4].type
= u
.ti
.tq4
;
1361 qualifiers
[5].type
= u
.ti
.tq5
;
1362 qualifiers
[6].type
= tqNil
;
1365 * Go get the basic type.
1369 case btNil
: /* undefined */
1373 case btAdr
: /* address - integer same size as pointer */
1374 strcpy (p1
, "address");
1377 case btChar
: /* character */
1378 strcpy (p1
, "char");
1381 case btUChar
: /* unsigned character */
1382 strcpy (p1
, "unsigned char");
1385 case btShort
: /* short */
1386 strcpy (p1
, "short");
1389 case btUShort
: /* unsigned short */
1390 strcpy (p1
, "unsigned short");
1393 case btInt
: /* int */
1397 case btUInt
: /* unsigned int */
1398 strcpy (p1
, "unsigned int");
1401 case btLong
: /* long */
1402 strcpy (p1
, "long");
1405 case btULong
: /* unsigned long */
1406 strcpy (p1
, "unsigned long");
1409 case btFloat
: /* float (real) */
1410 strcpy (p1
, "float");
1413 case btDouble
: /* Double (real) */
1414 strcpy (p1
, "double");
1417 /* Structures add 1-2 aux words:
1418 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1419 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1421 case btStruct
: /* Structure (Record) */
1422 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1423 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1424 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1426 indx
++; /* skip aux words */
1429 /* Unions add 1-2 aux words:
1430 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1431 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1433 case btUnion
: /* Union */
1434 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1435 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1436 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1438 indx
++; /* skip aux words */
1441 /* Enumerations add 1-2 aux words:
1442 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1443 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1445 case btEnum
: /* Enumeration */
1446 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1447 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1448 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1450 indx
++; /* skip aux words */
1453 case btTypedef
: /* defined via a typedef, isymRef points */
1454 strcpy (p1
, "typedef");
1457 case btRange
: /* subrange of int */
1458 strcpy (p1
, "subrange");
1461 case btSet
: /* pascal sets */
1465 case btComplex
: /* fortran complex */
1466 strcpy (p1
, "complex");
1469 case btDComplex
: /* fortran double complex */
1470 strcpy (p1
, "double complex");
1473 case btIndirect
: /* forward or unnamed typedef */
1474 strcpy (p1
, "forward/unamed typedef");
1477 case btFixedDec
: /* Fixed Decimal */
1478 strcpy (p1
, "fixed decimal");
1481 case btFloatDec
: /* Float Decimal */
1482 strcpy (p1
, "float decimal");
1485 case btString
: /* Varying Length Character String */
1486 strcpy (p1
, "string");
1489 case btBit
: /* Aligned Bit String */
1493 case btPicture
: /* Picture */
1494 strcpy (p1
, "picture");
1497 case btVoid
: /* Void */
1498 strcpy (p1
, "void");
1502 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1506 p1
+= strlen (buffer1
);
1509 * If this is a bitfield, get the bitsize.
1515 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1516 sprintf (p1
, " : %d", bitsize
);
1517 p1
+= strlen (buffer1
);
1522 * Deal with any qualifiers.
1524 if (qualifiers
[0].type
!= tqNil
)
1527 * Snarf up any array bounds in the correct order. Arrays
1528 * store 5 successive words in the aux. table:
1529 * word 0 RNDXR to type of the bounds (ie, int)
1530 * word 1 Current file descriptor index
1532 * word 3 high bound (or -1 if [])
1533 * word 4 stride size in bits
1535 for (i
= 0; i
< 7; i
++)
1537 if (qualifiers
[i
].type
== tqArray
)
1539 qualifiers
[i
].low_bound
=
1540 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1541 qualifiers
[i
].high_bound
=
1542 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1543 qualifiers
[i
].stride
=
1544 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1550 * Now print out the qualifiers.
1552 for (i
= 0; i
< 6; i
++)
1554 switch (qualifiers
[i
].type
)
1561 strcpy (p2
, "ptr to ");
1562 p2
+= sizeof ("ptr to ")-1;
1566 strcpy (p2
, "volatile ");
1567 p2
+= sizeof ("volatile ")-1;
1571 strcpy (p2
, "far ");
1572 p2
+= sizeof ("far ")-1;
1576 strcpy (p2
, "func. ret. ");
1577 p2
+= sizeof ("func. ret. ");
1582 int first_array
= i
;
1585 /* Print array bounds reversed (ie, in the order the C
1586 programmer writes them). C is such a fun language.... */
1588 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1591 for (j
= i
; j
>= first_array
; j
--)
1593 strcpy (p2
, "array [");
1594 p2
+= sizeof ("array [")-1;
1595 if (qualifiers
[j
].low_bound
!= 0)
1597 "%ld:%ld {%ld bits}",
1598 (long) qualifiers
[j
].low_bound
,
1599 (long) qualifiers
[j
].high_bound
,
1600 (long) qualifiers
[j
].stride
);
1602 else if (qualifiers
[j
].high_bound
!= -1)
1605 (long) (qualifiers
[j
].high_bound
+ 1),
1606 (long) (qualifiers
[j
].stride
));
1609 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1612 strcpy (p2
, "] of ");
1613 p2
+= sizeof ("] of ")-1;
1621 strcpy (p2
, buffer1
);
1625 /* Return information about ECOFF symbol SYMBOL in RET. */
1629 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1630 bfd
*abfd
; /* Ignored. */
1634 bfd_symbol_info (symbol
, ret
);
1637 /* Print information about an ECOFF symbol. */
1640 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1644 bfd_print_symbol_type how
;
1646 const struct ecoff_debug_swap
* const debug_swap
1647 = &ecoff_backend (abfd
)->debug_swap
;
1648 FILE *file
= (FILE *)filep
;
1652 case bfd_print_symbol_name
:
1653 fprintf (file
, "%s", symbol
->name
);
1655 case bfd_print_symbol_more
:
1656 if (ecoffsymbol (symbol
)->local
)
1660 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1662 fprintf (file
, "ecoff local ");
1663 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1664 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1665 (unsigned) ecoff_sym
.sc
);
1671 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1673 fprintf (file
, "ecoff extern ");
1674 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1675 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1676 (unsigned) ecoff_ext
.asym
.sc
);
1679 case bfd_print_symbol_all
:
1680 /* Print out the symbols in a reasonable way */
1689 if (ecoffsymbol (symbol
)->local
)
1691 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1694 pos
= ((((char *) ecoffsymbol (symbol
)->native
1695 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1696 / debug_swap
->external_sym_size
)
1697 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1704 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1707 pos
= (((char *) ecoffsymbol (symbol
)->native
1708 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1709 / debug_swap
->external_ext_size
);
1710 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1711 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1712 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1715 fprintf (file
, "[%3d] %c ",
1717 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1718 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1719 (unsigned) ecoff_ext
.asym
.st
,
1720 (unsigned) ecoff_ext
.asym
.sc
,
1721 (unsigned) ecoff_ext
.asym
.index
,
1722 jmptbl
, cobol_main
, weakext
,
1725 if (ecoffsymbol (symbol
)->fdr
!= NULL
1726 && ecoff_ext
.asym
.index
!= indexNil
)
1731 bfd_size_type sym_base
;
1732 union aux_ext
*aux_base
;
1734 fdr
= ecoffsymbol (symbol
)->fdr
;
1735 indx
= ecoff_ext
.asym
.index
;
1737 /* sym_base is used to map the fdr relative indices which
1738 appear in the file to the position number which we are
1740 sym_base
= fdr
->isymBase
;
1741 if (ecoffsymbol (symbol
)->local
)
1743 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1745 /* aux_base is the start of the aux entries for this file;
1746 asym.index is an offset from this. */
1747 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1750 /* The aux entries are stored in host byte order; the
1751 order is indicated by a bit in the fdr. */
1752 bigendian
= fdr
->fBigendian
;
1754 /* This switch is basically from gcc/mips-tdump.c */
1755 switch (ecoff_ext
.asym
.st
)
1763 fprintf (file
, "\n End+1 symbol: %ld",
1764 (long) (indx
+ sym_base
));
1768 if (ecoff_ext
.asym
.sc
== scText
1769 || ecoff_ext
.asym
.sc
== scInfo
)
1770 fprintf (file
, "\n First symbol: %ld",
1771 (long) (indx
+ sym_base
));
1773 fprintf (file
, "\n First symbol: %ld",
1775 (AUX_GET_ISYM (bigendian
,
1776 &aux_base
[ecoff_ext
.asym
.index
])
1782 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1784 else if (ecoffsymbol (symbol
)->local
)
1785 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1787 (AUX_GET_ISYM (bigendian
,
1788 &aux_base
[ecoff_ext
.asym
.index
])
1790 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1792 fprintf (file
, "\n Local symbol: %ld",
1795 + (ecoff_data (abfd
)
1796 ->debug_info
.symbolic_header
.iextMax
)));
1800 fprintf (file
, "\n struct; End+1 symbol: %ld",
1801 (long) (indx
+ sym_base
));
1805 fprintf (file
, "\n union; End+1 symbol: %ld",
1806 (long) (indx
+ sym_base
));
1810 fprintf (file
, "\n enum; End+1 symbol: %ld",
1811 (long) (indx
+ sym_base
));
1815 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1816 fprintf (file
, "\n Type: %s",
1817 ecoff_type_to_string (abfd
, fdr
, indx
));
1826 /* Read in the relocs for a section. */
1829 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1834 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1835 arelent
*internal_relocs
;
1836 bfd_size_type external_reloc_size
;
1837 bfd_size_type external_relocs_size
;
1838 char *external_relocs
;
1842 if (section
->relocation
!= (arelent
*) NULL
1843 || section
->reloc_count
== 0
1844 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1847 if (ecoff_slurp_symbol_table (abfd
) == false)
1850 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1852 * section
->reloc_count
));
1853 external_reloc_size
= backend
->external_reloc_size
;
1854 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1855 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1856 if (internal_relocs
== (arelent
*) NULL
1857 || external_relocs
== (char *) NULL
)
1859 bfd_set_error (bfd_error_no_memory
);
1862 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1864 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1865 != external_relocs_size
)
1868 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1870 struct internal_reloc intern
;
1872 (*backend
->swap_reloc_in
) (abfd
,
1873 external_relocs
+ i
* external_reloc_size
,
1876 if (intern
.r_extern
)
1878 /* r_symndx is an index into the external symbols. */
1879 BFD_ASSERT (intern
.r_symndx
>= 0
1881 < (ecoff_data (abfd
)
1882 ->debug_info
.symbolic_header
.iextMax
)));
1883 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1886 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1887 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1889 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1894 CONST
char *sec_name
;
1897 /* r_symndx is a section key. */
1898 switch (intern
.r_symndx
)
1900 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1901 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1902 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1903 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1904 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1905 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1906 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1907 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1908 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1909 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1910 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1911 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1912 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1916 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1917 if (sec
== (asection
*) NULL
)
1919 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1921 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1924 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1926 /* Let the backend select the howto field and do any other
1927 required processing. */
1928 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1931 bfd_release (abfd
, external_relocs
);
1933 section
->relocation
= internal_relocs
;
1938 /* Get a canonical list of relocs. */
1941 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1949 if (section
->flags
& SEC_CONSTRUCTOR
)
1951 arelent_chain
*chain
;
1953 /* This section has relocs made up by us, not the file, so take
1954 them out of their chain and place them into the data area
1956 for (count
= 0, chain
= section
->constructor_chain
;
1957 count
< section
->reloc_count
;
1958 count
++, chain
= chain
->next
)
1959 *relptr
++ = &chain
->relent
;
1965 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1968 tblptr
= section
->relocation
;
1970 for (count
= 0; count
< section
->reloc_count
; count
++)
1971 *relptr
++ = tblptr
++;
1974 *relptr
= (arelent
*) NULL
;
1976 return section
->reloc_count
;
1979 /* Provided a BFD, a section and an offset into the section, calculate
1980 and return the name of the source file and the line nearest to the
1985 ecoff_find_nearest_line (abfd
,
1994 asymbol
**ignore_symbols
;
1996 CONST
char **filename_ptr
;
1997 CONST
char **functionname_ptr
;
1998 unsigned int *retline_ptr
;
2000 const struct ecoff_debug_swap
* const debug_swap
2001 = &ecoff_backend (abfd
)->debug_swap
;
2006 bfd_size_type external_pdr_size
;
2011 unsigned char *line_ptr
;
2012 unsigned char *line_end
;
2015 /* If we're not in the .text section, we don't have any line
2017 if (strcmp (section
->name
, _TEXT
) != 0
2018 || offset
< ecoff_data (abfd
)->text_start
2019 || offset
>= ecoff_data (abfd
)->text_end
)
2022 /* Make sure we have the FDR's. */
2023 if (ecoff_slurp_symbolic_info (abfd
) == false
2024 || bfd_get_symcount (abfd
) == 0)
2027 /* Each file descriptor (FDR) has a memory address. Here we track
2028 down which FDR we want. The FDR's are stored in increasing
2029 memory order. If speed is ever important, this can become a
2030 binary search. We must ignore FDR's with no PDR entries; they
2031 will have the adr of the FDR before or after them. */
2032 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2033 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2034 fdr_hold
= (FDR
*) NULL
;
2035 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2037 if (fdr_ptr
->cpd
== 0)
2039 if (offset
< fdr_ptr
->adr
)
2043 if (fdr_hold
== (FDR
*) NULL
)
2047 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2048 have an address, which is relative to the FDR address, and are
2049 also stored in increasing memory order. */
2050 offset
-= fdr_ptr
->adr
;
2051 external_pdr_size
= debug_swap
->external_pdr_size
;
2052 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2053 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2054 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2055 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2056 if (offset
< pdr
.adr
)
2059 /* The address of the first PDR is an offset which applies to the
2060 addresses of all the PDR's. */
2061 first_off
= pdr
.adr
;
2063 for (pdr_ptr
+= external_pdr_size
;
2065 pdr_ptr
+= external_pdr_size
)
2067 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2068 if (offset
< pdr
.adr
)
2072 /* Now we can look for the actual line number. The line numbers are
2073 stored in a very funky format, which I won't try to describe.
2074 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2075 we want; we need this to compute line_end. */
2076 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2077 if (pdr_ptr
== pdr_end
)
2078 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2080 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2082 /* Now change pdr and pdr_ptr to the one we want. */
2083 pdr_ptr
-= external_pdr_size
;
2084 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2086 offset
-= pdr
.adr
- first_off
;
2088 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2089 + fdr_ptr
->cbLineOffset
2090 + pdr
.cbLineOffset
);
2091 while (line_ptr
< line_end
)
2096 delta
= *line_ptr
>> 4;
2099 count
= (*line_ptr
& 0xf) + 1;
2103 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2104 if (delta
>= 0x8000)
2109 if (offset
< count
* 4)
2111 offset
-= count
* 4;
2114 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2115 at least according to gdb/mipsread.c. */
2116 if (fdr_ptr
->rss
== -1)
2118 *filename_ptr
= NULL
;
2120 *functionname_ptr
= NULL
;
2125 (*debug_swap
->swap_ext_in
)
2127 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2128 + pdr
.isym
* debug_swap
->external_ext_size
),
2130 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2131 + proc_ext
.asym
.iss
);
2138 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2141 (*debug_swap
->swap_sym_in
)
2143 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2144 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2146 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2150 if (lineno
== ilineNil
)
2152 *retline_ptr
= lineno
;
2156 /* Copy private BFD data. This is called by objcopy and strip. We
2157 use it to copy the ECOFF debugging information from one BFD to the
2158 other. It would be theoretically possible to represent the ECOFF
2159 debugging information in the symbol table. However, it would be a
2160 lot of work, and there would be little gain (gas, gdb, and ld
2161 already access the ECOFF debugging information via the
2162 ecoff_debug_info structure, and that structure would have to be
2163 retained in order to support ECOFF debugging in MIPS ELF).
2165 The debugging information for the ECOFF external symbols comes from
2166 the symbol table, so this function only handles the other debugging
2170 ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
2174 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
2175 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
2177 asymbol
**sym_ptr_ptr
;
2181 /* This function is selected based on the input vector. We only
2182 want to copy information over if the output BFD also uses ECOFF
2184 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
2187 /* Copy the GP value and the register masks. */
2188 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
2189 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
2190 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
2191 for (i
= 0; i
< 3; i
++)
2192 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
2194 /* Copy the version stamp. */
2195 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
2197 /* If there are no symbols, don't copy any debugging information. */
2198 c
= bfd_get_symcount (obfd
);
2199 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2200 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
2203 /* See if there are any local symbols. */
2205 for (; c
> 0; c
--, sym_ptr_ptr
++)
2207 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
2216 /* There are some local symbols. We just bring over all the
2217 debugging information. FIXME: This is not quite the right
2218 thing to do. If the user has asked us to discard all
2219 debugging information, then we are probably going to wind up
2220 keeping it because there will probably be some local symbol
2221 which objcopy did not discard. We should actually break
2222 apart the debugging information and only keep that which
2223 applies to the symbols we want to keep. */
2224 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
2225 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
2226 oinfo
->line
= iinfo
->line
;
2228 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
2229 oinfo
->external_dnr
= iinfo
->external_dnr
;
2231 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
2232 oinfo
->external_pdr
= iinfo
->external_pdr
;
2234 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
2235 oinfo
->external_sym
= iinfo
->external_sym
;
2237 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
2238 oinfo
->external_opt
= iinfo
->external_opt
;
2240 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
2241 oinfo
->external_aux
= iinfo
->external_aux
;
2243 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
2244 oinfo
->ss
= iinfo
->ss
;
2246 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
2247 oinfo
->external_fdr
= iinfo
->external_fdr
;
2249 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
2250 oinfo
->external_rfd
= iinfo
->external_rfd
;
2254 /* We are discarding all the local symbol information. Look
2255 through the external symbols and remove all references to FDR
2256 or aux information. */
2257 c
= bfd_get_symcount (obfd
);
2258 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2259 for (; c
> 0; c
--, sym_ptr_ptr
++)
2263 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
2264 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
2266 esym
.asym
.index
= indexNil
;
2267 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
2268 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
2275 /* Set the architecture. The supported architecture is stored in the
2276 backend pointer. We always set the architecture anyhow, since many
2277 callers ignore the return value. */
2280 ecoff_set_arch_mach (abfd
, arch
, machine
)
2282 enum bfd_architecture arch
;
2283 unsigned long machine
;
2285 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2286 return arch
== ecoff_backend (abfd
)->arch
;
2289 /* Get the size of the section headers. */
2293 ecoff_sizeof_headers (abfd
, reloc
)
2302 for (current
= abfd
->sections
;
2303 current
!= (asection
*)NULL
;
2304 current
= current
->next
)
2307 ret
= (bfd_coff_filhsz (abfd
)
2308 + bfd_coff_aoutsz (abfd
)
2309 + c
* bfd_coff_scnhsz (abfd
));
2310 return BFD_ALIGN (ret
, 16);
2313 /* Get the contents of a section. */
2316 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2321 bfd_size_type count
;
2323 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2327 /* Calculate the file position for each section, and set
2331 ecoff_compute_section_file_positions (abfd
)
2339 sofar
= ecoff_sizeof_headers (abfd
, false);
2342 for (current
= abfd
->sections
;
2343 current
!= (asection
*) NULL
;
2344 current
= current
->next
)
2346 unsigned int alignment_power
;
2348 /* Only deal with sections which have contents */
2349 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2352 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2353 supposed to indicate the number of .pdata entries that are
2354 really in the section. Each entry is 8 bytes. We store this
2355 away in line_filepos before increasing the section size. */
2356 if (strcmp (current
->name
, _PDATA
) != 0)
2357 alignment_power
= current
->alignment_power
;
2360 current
->line_filepos
= current
->_raw_size
/ 8;
2361 alignment_power
= 4;
2364 /* On Ultrix, the data sections in an executable file must be
2365 aligned to a page boundary within the file. This does not
2366 affect the section size, though. FIXME: Does this work for
2367 other platforms? It requires some modification for the
2368 Alpha, because .rdata on the Alpha goes with the text, not
2370 if ((abfd
->flags
& EXEC_P
) != 0
2371 && (abfd
->flags
& D_PAGED
) != 0
2372 && first_data
!= false
2373 && (current
->flags
& SEC_CODE
) == 0
2374 && (! ecoff_backend (abfd
)->rdata_in_text
2375 || strcmp (current
->name
, _RDATA
) != 0)
2376 && strcmp (current
->name
, _PDATA
) != 0)
2378 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2380 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2383 else if (strcmp (current
->name
, _LIB
) == 0)
2385 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2386 /* On Irix 4, the location of contents of the .lib section
2387 from a shared library section is also rounded up to a
2390 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2393 /* Align the sections in the file to the same boundary on
2394 which they are aligned in virtual memory. */
2396 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2398 current
->filepos
= sofar
;
2400 sofar
+= current
->_raw_size
;
2402 /* make sure that this section is of the right size too */
2404 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2405 current
->_raw_size
+= sofar
- old_sofar
;
2408 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2411 /* Determine the location of the relocs for all the sections in the
2412 output file, as well as the location of the symbolic debugging
2415 static bfd_size_type
2416 ecoff_compute_reloc_file_positions (abfd
)
2419 const bfd_size_type external_reloc_size
=
2420 ecoff_backend (abfd
)->external_reloc_size
;
2421 file_ptr reloc_base
;
2422 bfd_size_type reloc_size
;
2426 if (! abfd
->output_has_begun
)
2428 ecoff_compute_section_file_positions (abfd
);
2429 abfd
->output_has_begun
= true;
2432 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2435 for (current
= abfd
->sections
;
2436 current
!= (asection
*)NULL
;
2437 current
= current
->next
)
2439 if (current
->reloc_count
== 0)
2440 current
->rel_filepos
= 0;
2443 bfd_size_type relsize
;
2445 current
->rel_filepos
= reloc_base
;
2446 relsize
= current
->reloc_count
* external_reloc_size
;
2447 reloc_size
+= relsize
;
2448 reloc_base
+= relsize
;
2452 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2454 /* At least on Ultrix, the symbol table of an executable file must
2455 be aligned to a page boundary. FIXME: Is this true on other
2457 if ((abfd
->flags
& EXEC_P
) != 0
2458 && (abfd
->flags
& D_PAGED
) != 0)
2459 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2460 &~ (ecoff_backend (abfd
)->round
- 1));
2462 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2467 /* Set the contents of a section. */
2470 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2475 bfd_size_type count
;
2477 /* This must be done first, because bfd_set_section_contents is
2478 going to set output_has_begun to true. */
2479 if (abfd
->output_has_begun
== false)
2480 ecoff_compute_section_file_positions (abfd
);
2482 /* If this is a .lib section, bump the vma address so that it winds
2483 up being the number of .lib sections output. This is right for
2484 Irix 4. Ian Taylor <ian@cygnus.com>. */
2485 if (strcmp (section
->name
, _LIB
) == 0)
2491 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2492 || bfd_write (location
, 1, count
, abfd
) != count
)
2498 /* Get the GP value for an ECOFF file. This is a hook used by
2502 bfd_ecoff_get_gp_value (abfd
)
2505 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2506 || bfd_get_format (abfd
) != bfd_object
)
2508 bfd_set_error (bfd_error_invalid_operation
);
2512 return ecoff_data (abfd
)->gp
;
2515 /* Set the GP value for an ECOFF file. This is a hook used by the
2519 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2523 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2524 || bfd_get_format (abfd
) != bfd_object
)
2526 bfd_set_error (bfd_error_invalid_operation
);
2530 ecoff_data (abfd
)->gp
= gp_value
;
2535 /* Set the register masks for an ECOFF file. This is a hook used by
2539 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2541 unsigned long gprmask
;
2542 unsigned long fprmask
;
2543 unsigned long *cprmask
;
2545 ecoff_data_type
*tdata
;
2547 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2548 || bfd_get_format (abfd
) != bfd_object
)
2550 bfd_set_error (bfd_error_invalid_operation
);
2554 tdata
= ecoff_data (abfd
);
2555 tdata
->gprmask
= gprmask
;
2556 tdata
->fprmask
= fprmask
;
2557 if (cprmask
!= (unsigned long *) NULL
)
2561 for (i
= 0; i
< 3; i
++)
2562 tdata
->cprmask
[i
] = cprmask
[i
];
2568 /* Get ECOFF EXTR information for an external symbol. This function
2569 is passed to bfd_ecoff_debug_externals. */
2572 ecoff_get_extr (sym
, esym
)
2576 ecoff_symbol_type
*ecoff_sym_ptr
;
2579 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2580 || ecoffsymbol (sym
)->native
== NULL
)
2582 /* Don't include debugging, local, or section symbols. */
2583 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2584 || (sym
->flags
& BSF_LOCAL
) != 0
2585 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2589 esym
->cobol_main
= 0;
2593 /* FIXME: we can do better than this for st and sc. */
2594 esym
->asym
.st
= stGlobal
;
2595 esym
->asym
.sc
= scAbs
;
2596 esym
->asym
.reserved
= 0;
2597 esym
->asym
.index
= indexNil
;
2601 ecoff_sym_ptr
= ecoffsymbol (sym
);
2603 if (ecoff_sym_ptr
->local
)
2606 input_bfd
= bfd_asymbol_bfd (sym
);
2607 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2608 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2610 /* If the symbol was defined by the linker, then esym will be
2611 undefined but sym will not be. Get a better class for such a
2613 if ((esym
->asym
.sc
== scUndefined
2614 || esym
->asym
.sc
== scSUndefined
)
2615 && bfd_get_section (sym
) != &bfd_und_section
)
2616 esym
->asym
.sc
= scAbs
;
2618 /* Adjust the FDR index for the symbol by that used for the input
2620 if (esym
->ifd
!= -1)
2622 struct ecoff_debug_info
*input_debug
;
2624 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2625 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2626 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2627 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2633 /* Set the external symbol index. This routine is passed to
2634 bfd_ecoff_debug_externals. */
2637 ecoff_set_index (sym
, indx
)
2641 ecoff_set_sym_index (sym
, indx
);
2644 /* Write out an ECOFF file. */
2647 ecoff_write_object_contents (abfd
)
2650 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2651 const bfd_vma round
= backend
->round
;
2652 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2653 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2654 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2655 const bfd_size_type external_hdr_size
2656 = backend
->debug_swap
.external_hdr_size
;
2657 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2658 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2660 struct internal_reloc
*))
2661 = backend
->adjust_reloc_out
;
2662 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2663 const struct internal_reloc
*,
2665 = backend
->swap_reloc_out
;
2666 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2667 HDRR
* const symhdr
= &debug
->symbolic_header
;
2670 bfd_size_type reloc_size
;
2671 bfd_size_type text_size
;
2673 boolean set_text_start
;
2674 bfd_size_type data_size
;
2676 boolean set_data_start
;
2677 bfd_size_type bss_size
;
2679 PTR reloc_buff
= NULL
;
2680 struct internal_filehdr internal_f
;
2681 struct internal_aouthdr internal_a
;
2684 /* Determine where the sections and relocs will go in the output
2686 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2689 for (current
= abfd
->sections
;
2690 current
!= (asection
*)NULL
;
2691 current
= current
->next
)
2693 current
->target_index
= count
;
2697 if ((abfd
->flags
& D_PAGED
) != 0)
2698 text_size
= ecoff_sizeof_headers (abfd
, false);
2702 set_text_start
= false;
2705 set_data_start
= false;
2708 /* Write section headers to the file. */
2710 /* Allocate buff big enough to hold a section header,
2711 file header, or a.out header. */
2719 buff
= (PTR
) malloc (siz
);
2722 bfd_set_error (bfd_error_no_memory
);
2727 internal_f
.f_nscns
= 0;
2728 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2730 for (current
= abfd
->sections
;
2731 current
!= (asection
*) NULL
;
2732 current
= current
->next
)
2734 struct internal_scnhdr section
;
2737 ++internal_f
.f_nscns
;
2739 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2741 /* This seems to be correct for Irix 4 shared libraries. */
2742 vma
= bfd_get_section_vma (abfd
, current
);
2743 if (strcmp (current
->name
, _LIB
) == 0)
2744 section
.s_vaddr
= 0;
2746 section
.s_vaddr
= vma
;
2748 section
.s_paddr
= vma
;
2749 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2751 /* If this section is unloadable then the scnptr will be 0. */
2752 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2753 section
.s_scnptr
= 0;
2755 section
.s_scnptr
= current
->filepos
;
2756 section
.s_relptr
= current
->rel_filepos
;
2758 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2759 object file produced by the assembler is supposed to point to
2760 information about how much room is required by objects of
2761 various different sizes. I think this only matters if we
2762 want the linker to compute the best size to use, or
2763 something. I don't know what happens if the information is
2765 if (strcmp (current
->name
, _PDATA
) != 0)
2766 section
.s_lnnoptr
= 0;
2769 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2770 hold the number of entries in the section (each entry is
2771 8 bytes). We stored this in the line_filepos field in
2772 ecoff_compute_section_file_positions. */
2773 section
.s_lnnoptr
= current
->line_filepos
;
2776 section
.s_nreloc
= current
->reloc_count
;
2777 section
.s_nlnno
= 0;
2778 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2781 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2782 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2785 if ((section
.s_flags
& STYP_TEXT
) != 0
2786 || ((section
.s_flags
& STYP_RDATA
) != 0
2787 && backend
->rdata_in_text
)
2788 || strcmp (current
->name
, _PDATA
) == 0)
2790 text_size
+= bfd_get_section_size_before_reloc (current
);
2791 if (! set_text_start
|| text_start
> vma
)
2794 set_text_start
= true;
2797 else if ((section
.s_flags
& STYP_RDATA
) != 0
2798 || (section
.s_flags
& STYP_DATA
) != 0
2799 || (section
.s_flags
& STYP_LITA
) != 0
2800 || (section
.s_flags
& STYP_LIT8
) != 0
2801 || (section
.s_flags
& STYP_LIT4
) != 0
2802 || (section
.s_flags
& STYP_SDATA
) != 0
2803 || strcmp (current
->name
, _XDATA
) == 0)
2805 data_size
+= bfd_get_section_size_before_reloc (current
);
2806 if (! set_data_start
|| data_start
> vma
)
2809 set_data_start
= true;
2812 else if ((section
.s_flags
& STYP_BSS
) != 0
2813 || (section
.s_flags
& STYP_SBSS
) != 0)
2814 bss_size
+= bfd_get_section_size_before_reloc (current
);
2815 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
2821 /* Set up the file header. */
2823 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2825 /* We will NOT put a fucking timestamp in the header here. Every
2826 time you put it back, I will come in and take it out again. I'm
2827 sorry. This field does not belong here. We fill it with a 0 so
2828 it compares the same but is not a reasonable time. --
2830 internal_f
.f_timdat
= 0;
2832 if (bfd_get_symcount (abfd
) != 0)
2834 /* The ECOFF f_nsyms field is not actually the number of
2835 symbols, it's the size of symbolic information header. */
2836 internal_f
.f_nsyms
= external_hdr_size
;
2837 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2841 internal_f
.f_nsyms
= 0;
2842 internal_f
.f_symptr
= 0;
2845 internal_f
.f_opthdr
= aoutsz
;
2847 internal_f
.f_flags
= F_LNNO
;
2848 if (reloc_size
== 0)
2849 internal_f
.f_flags
|= F_RELFLG
;
2850 if (bfd_get_symcount (abfd
) == 0)
2851 internal_f
.f_flags
|= F_LSYMS
;
2852 if (abfd
->flags
& EXEC_P
)
2853 internal_f
.f_flags
|= F_EXEC
;
2855 if (! abfd
->xvec
->byteorder_big_p
)
2856 internal_f
.f_flags
|= F_AR32WR
;
2858 internal_f
.f_flags
|= F_AR32W
;
2860 /* Set up the ``optional'' header. */
2861 if ((abfd
->flags
& D_PAGED
) != 0)
2862 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2864 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2866 /* FIXME: Is this really correct? */
2867 internal_a
.vstamp
= symhdr
->vstamp
;
2869 /* At least on Ultrix, these have to be rounded to page boundaries.
2870 FIXME: Is this true on other platforms? */
2871 if ((abfd
->flags
& D_PAGED
) != 0)
2873 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2874 internal_a
.text_start
= text_start
&~ (round
- 1);
2875 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2876 internal_a
.data_start
= data_start
&~ (round
- 1);
2880 internal_a
.tsize
= text_size
;
2881 internal_a
.text_start
= text_start
;
2882 internal_a
.dsize
= data_size
;
2883 internal_a
.data_start
= data_start
;
2886 /* On Ultrix, the initial portions of the .sbss and .bss segments
2887 are at the end of the data section. The bsize field in the
2888 optional header records how many bss bytes are required beyond
2889 those in the data section. The value is not rounded to a page
2891 if (bss_size
< internal_a
.dsize
- data_size
)
2894 bss_size
-= internal_a
.dsize
- data_size
;
2895 internal_a
.bsize
= bss_size
;
2896 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2898 internal_a
.entry
= bfd_get_start_address (abfd
);
2900 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2902 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2903 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2904 for (i
= 0; i
< 4; i
++)
2905 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2907 /* Write out the file header and the optional header. */
2909 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2912 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2913 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2916 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2917 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2920 /* Build the external symbol information. This must be done before
2921 writing out the relocs so that we know the symbol indices. We
2922 don't do this if this BFD was created by the backend linker,
2923 since it will have already handled the symbols and relocs. */
2924 if (! ecoff_data (abfd
)->linker
)
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. */
3581 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3583 return (struct bfd_hash_entry
*) ret
;
3586 /* Create an ECOFF link hash table. */
3588 struct bfd_link_hash_table
*
3589 ecoff_bfd_link_hash_table_create (abfd
)
3592 struct ecoff_link_hash_table
*ret
;
3594 ret
= ((struct ecoff_link_hash_table
*)
3595 malloc (sizeof (struct ecoff_link_hash_table
)));
3598 bfd_set_error (bfd_error_no_memory
);
3601 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3602 ecoff_link_hash_newfunc
))
3605 return (struct bfd_link_hash_table
*) NULL
;
3610 /* Look up an entry in an ECOFF link hash table. */
3612 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3613 ((struct ecoff_link_hash_entry *) \
3614 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3616 /* Traverse an ECOFF link hash table. */
3618 #define ecoff_link_hash_traverse(table, func, info) \
3619 (bfd_link_hash_traverse \
3621 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3624 /* Get the ECOFF link hash table from the info structure. This is
3627 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3629 /* Given an ECOFF BFD, add symbols to the global hash table as
3633 ecoff_bfd_link_add_symbols (abfd
, info
)
3635 struct bfd_link_info
*info
;
3637 switch (bfd_get_format (abfd
))
3640 return ecoff_link_add_object_symbols (abfd
, info
);
3642 return ecoff_link_add_archive_symbols (abfd
, info
);
3644 bfd_set_error (bfd_error_wrong_format
);
3649 /* Add the symbols from an archive file to the global hash table.
3650 This looks through the undefined symbols, looks each one up in the
3651 archive hash table, and adds any associated object file. We do not
3652 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3653 already have a hash table, so there is no reason to construct
3657 ecoff_link_add_archive_symbols (abfd
, info
)
3659 struct bfd_link_info
*info
;
3661 const bfd_byte
*raw_armap
;
3662 struct bfd_link_hash_entry
**pundef
;
3663 unsigned int armap_count
;
3664 unsigned int armap_log
;
3666 const bfd_byte
*hashtable
;
3667 const char *stringbase
;
3669 if (! bfd_has_map (abfd
))
3671 bfd_set_error (bfd_error_no_symbols
);
3675 /* If we don't have any raw data for this archive, as can happen on
3676 Irix 4.0.5F, we call the generic routine.
3677 FIXME: We should be more clever about this, since someday tdata
3678 may get to something for a generic archive. */
3679 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3680 if (raw_armap
== (bfd_byte
*) NULL
)
3681 return (_bfd_generic_link_add_archive_symbols
3682 (abfd
, info
, ecoff_link_check_archive_element
));
3684 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3687 for (i
= 1; i
< armap_count
; i
<<= 1)
3689 BFD_ASSERT (i
== armap_count
);
3691 hashtable
= raw_armap
+ 4;
3692 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3694 /* Look through the list of undefined symbols. */
3695 pundef
= &info
->hash
->undefs
;
3696 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3698 struct bfd_link_hash_entry
*h
;
3699 unsigned int hash
, rehash
;
3700 unsigned int file_offset
;
3706 /* When a symbol is defined, it is not necessarily removed from
3708 if (h
->type
!= bfd_link_hash_undefined
3709 && h
->type
!= bfd_link_hash_common
)
3711 /* Remove this entry from the list, for general cleanliness
3712 and because we are going to look through the list again
3713 if we search any more libraries. We can't remove the
3714 entry if it is the tail, because that would lose any
3715 entries we add to the list later on. */
3716 if (*pundef
!= info
->hash
->undefs_tail
)
3717 *pundef
= (*pundef
)->next
;
3719 pundef
= &(*pundef
)->next
;
3723 /* Native ECOFF linkers do not pull in archive elements merely
3724 to satisfy common definitions, so neither do we. We leave
3725 them on the list, though, in case we are linking against some
3726 other object format. */
3727 if (h
->type
!= bfd_link_hash_undefined
)
3729 pundef
= &(*pundef
)->next
;
3733 /* Look for this symbol in the archive hash table. */
3734 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3737 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3738 if (file_offset
== 0)
3740 /* Nothing in this slot. */
3741 pundef
= &(*pundef
)->next
;
3745 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3746 if (name
[0] != h
->root
.string
[0]
3747 || strcmp (name
, h
->root
.string
) != 0)
3752 /* That was the wrong symbol. Try rehashing. */
3754 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3756 srch
= (srch
+ rehash
) & (armap_count
- 1))
3758 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3759 if (file_offset
== 0)
3761 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3762 if (name
[0] == h
->root
.string
[0]
3763 && strcmp (name
, h
->root
.string
) == 0)
3772 pundef
= &(*pundef
)->next
;
3779 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3780 if (element
== (bfd
*) NULL
)
3783 if (! bfd_check_format (element
, bfd_object
))
3786 /* Unlike the generic linker, we know that this element provides
3787 a definition for an undefined symbol and we know that we want
3788 to include it. We don't need to check anything. */
3789 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3791 if (! ecoff_link_add_object_symbols (element
, info
))
3794 pundef
= &(*pundef
)->next
;
3800 /* This is called if we used _bfd_generic_link_add_archive_symbols
3801 because we were not dealing with an ECOFF archive. */
3804 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3806 struct bfd_link_info
*info
;
3809 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3810 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3811 = backend
->debug_swap
.swap_ext_in
;
3813 bfd_size_type external_ext_size
;
3814 PTR external_ext
= NULL
;
3822 if (! ecoff_slurp_symbolic_header (abfd
))
3825 /* If there are no symbols, we don't want it. */
3826 if (bfd_get_symcount (abfd
) == 0)
3827 goto successful_return
;
3829 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3831 /* Read in the external symbols and external strings. */
3832 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3833 esize
= symhdr
->iextMax
* external_ext_size
;
3834 external_ext
= (PTR
) malloc (esize
);
3835 if (external_ext
== NULL
&& esize
!= 0)
3837 bfd_set_error (bfd_error_no_memory
);
3841 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3842 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3845 ssext
= (char *) malloc (symhdr
->issExtMax
);
3846 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3848 bfd_set_error (bfd_error_no_memory
);
3852 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3853 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3856 /* Look through the external symbols to see if they define some
3857 symbol that is currently undefined. */
3858 ext_ptr
= (char *) external_ext
;
3859 ext_end
= ext_ptr
+ esize
;
3860 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3865 struct bfd_link_hash_entry
*h
;
3867 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3869 /* See if this symbol defines something. */
3870 if (esym
.asym
.st
!= stGlobal
3871 && esym
.asym
.st
!= stLabel
3872 && esym
.asym
.st
!= stProc
)
3875 switch (esym
.asym
.sc
)
3898 name
= ssext
+ esym
.asym
.iss
;
3899 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3901 /* Unlike the generic linker, we do not pull in elements because
3902 of common symbols. */
3903 if (h
== (struct bfd_link_hash_entry
*) NULL
3904 || h
->type
!= bfd_link_hash_undefined
)
3907 /* Include this element. */
3908 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3910 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3914 goto successful_return
;
3918 if (external_ext
!= NULL
)
3919 free (external_ext
);
3924 if (external_ext
!= NULL
)
3925 free (external_ext
);
3931 /* Add symbols from an ECOFF object file to the global linker hash
3935 ecoff_link_add_object_symbols (abfd
, info
)
3937 struct bfd_link_info
*info
;
3940 bfd_size_type external_ext_size
;
3941 PTR external_ext
= NULL
;
3946 if (! ecoff_slurp_symbolic_header (abfd
))
3949 /* If there are no symbols, we don't want it. */
3950 if (bfd_get_symcount (abfd
) == 0)
3953 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3955 /* Read in the external symbols and external strings. */
3956 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3957 esize
= symhdr
->iextMax
* external_ext_size
;
3958 external_ext
= (PTR
) malloc (esize
);
3959 if (external_ext
== NULL
&& esize
!= 0)
3961 bfd_set_error (bfd_error_no_memory
);
3965 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3966 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3969 ssext
= (char *) malloc (symhdr
->issExtMax
);
3970 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3972 bfd_set_error (bfd_error_no_memory
);
3976 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3977 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3980 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3984 if (external_ext
!= NULL
)
3985 free (external_ext
);
3991 if (external_ext
!= NULL
)
3992 free (external_ext
);
3996 /* Add the external symbols of an object file to the global linker
3997 hash table. The external symbols and strings we are passed are
3998 just allocated on the stack, and will be discarded. We must
3999 explicitly save any information we may need later on in the link.
4000 We do not want to read the external symbol information again. */
4003 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
4005 struct bfd_link_info
*info
;
4009 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4010 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
4011 = backend
->debug_swap
.swap_ext_in
;
4012 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
4013 unsigned long ext_count
;
4014 struct ecoff_link_hash_entry
**sym_hash
;
4018 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
4020 sym_hash
= ((struct ecoff_link_hash_entry
**)
4022 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
4025 bfd_set_error (bfd_error_no_memory
);
4028 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
4030 ext_ptr
= (char *) external_ext
;
4031 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
4032 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
4039 struct ecoff_link_hash_entry
*h
;
4043 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
4045 /* Skip debugging symbols. */
4047 switch (esym
.asym
.st
)
4063 /* Get the information for this symbol. */
4064 value
= esym
.asym
.value
;
4065 switch (esym
.asym
.sc
)
4085 section
= bfd_make_section_old_way (abfd
, ".text");
4086 value
-= section
->vma
;
4089 section
= bfd_make_section_old_way (abfd
, ".data");
4090 value
-= section
->vma
;
4093 section
= bfd_make_section_old_way (abfd
, ".bss");
4094 value
-= section
->vma
;
4097 section
= &bfd_abs_section
;
4100 section
= &bfd_und_section
;
4103 section
= bfd_make_section_old_way (abfd
, ".sdata");
4104 value
-= section
->vma
;
4107 section
= bfd_make_section_old_way (abfd
, ".sbss");
4108 value
-= section
->vma
;
4111 section
= bfd_make_section_old_way (abfd
, ".rdata");
4112 value
-= section
->vma
;
4115 if (value
> ecoff_data (abfd
)->gp_size
)
4117 section
= &bfd_com_section
;
4122 if (ecoff_scom_section
.name
== NULL
)
4124 /* Initialize the small common section. */
4125 ecoff_scom_section
.name
= SCOMMON
;
4126 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
4127 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
4128 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
4129 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
4130 ecoff_scom_symbol
.name
= SCOMMON
;
4131 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
4132 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
4133 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
4135 section
= &ecoff_scom_section
;
4138 section
= &bfd_und_section
;
4141 section
= bfd_make_section_old_way (abfd
, ".init");
4142 value
-= section
->vma
;
4145 section
= bfd_make_section_old_way (abfd
, ".fini");
4146 value
-= section
->vma
;
4150 if (section
== (asection
*) NULL
)
4153 name
= ssext
+ esym
.asym
.iss
;
4156 if (! (_bfd_generic_link_add_one_symbol
4157 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
4158 (const char *) NULL
, true, true,
4159 (struct bfd_link_hash_entry
**) &h
)))
4164 /* If we are building an ECOFF hash table, save the external
4165 symbol information. */
4166 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4168 if (h
->abfd
== (bfd
*) NULL
4169 || (section
!= &bfd_und_section
4170 && (! bfd_is_com_section (section
)
4171 || h
->root
.type
!= bfd_link_hash_defined
)))
4177 /* Remember whether this symbol was small undefined. */
4178 if (esym
.asym
.sc
== scSUndefined
)
4181 /* If this symbol was ever small undefined, it needs to wind
4182 up in a GP relative section. We can't control the
4183 section of a defined symbol, but we can control the
4184 section of a common symbol. This case is actually needed
4185 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4187 && h
->root
.type
== bfd_link_hash_common
4188 && strcmp (h
->root
.u
.c
.section
->name
, SCOMMON
) != 0)
4190 h
->root
.u
.c
.section
= bfd_make_section_old_way (abfd
, SCOMMON
);
4191 h
->root
.u
.c
.section
->flags
= SEC_ALLOC
;
4192 if (h
->esym
.asym
.sc
== scCommon
)
4193 h
->esym
.asym
.sc
= scSCommon
;
4201 /* ECOFF final link routines. */
4203 static boolean ecoff_final_link_debug_accumulate
4204 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4206 static boolean ecoff_link_write_external
4207 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4208 static boolean ecoff_indirect_link_order
4209 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4210 struct bfd_link_order
*));
4211 static boolean ecoff_reloc_link_order
4212 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4213 struct bfd_link_order
*));
4215 /* ECOFF final link routine. This looks through all the input BFDs
4216 and gathers together all the debugging information, and then
4217 processes all the link order information. This may cause it to
4218 close and reopen some input BFDs; I'll see how bad this is. */
4221 ecoff_bfd_final_link (abfd
, info
)
4223 struct bfd_link_info
*info
;
4225 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4226 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4229 register bfd
*input_bfd
;
4231 struct bfd_link_order
*p
;
4233 /* We accumulate the debugging information counts in the symbolic
4235 symhdr
= &debug
->symbolic_header
;
4237 symhdr
->ilineMax
= 0;
4241 symhdr
->isymMax
= 0;
4242 symhdr
->ioptMax
= 0;
4243 symhdr
->iauxMax
= 0;
4245 symhdr
->issExtMax
= 0;
4248 symhdr
->iextMax
= 0;
4250 /* We accumulate the debugging information itself in the debug_info
4253 debug
->external_dnr
= NULL
;
4254 debug
->external_pdr
= NULL
;
4255 debug
->external_sym
= NULL
;
4256 debug
->external_opt
= NULL
;
4257 debug
->external_aux
= NULL
;
4259 debug
->ssext
= debug
->ssext_end
= NULL
;
4260 debug
->external_fdr
= NULL
;
4261 debug
->external_rfd
= NULL
;
4262 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4264 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4265 if (handle
== (PTR
) NULL
)
4268 /* Accumulate the debugging symbols from each input BFD. */
4269 for (input_bfd
= info
->input_bfds
;
4270 input_bfd
!= (bfd
*) NULL
;
4271 input_bfd
= input_bfd
->link_next
)
4275 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4277 /* Abitrarily set the symbolic header vstamp to the vstamp
4278 of the first object file in the link. */
4279 if (symhdr
->vstamp
== 0)
4281 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4282 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4286 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4287 debug
, &backend
->debug_swap
,
4292 /* Combine the register masks. */
4293 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4294 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4295 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4296 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4297 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4298 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4301 /* Write out the external symbols. */
4302 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4303 ecoff_link_write_external
,
4306 if (info
->relocateable
)
4308 /* We need to make a pass over the link_orders to count up the
4309 number of relocations we will need to output, so that we know
4310 how much space they will take up. */
4311 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4314 for (p
= o
->link_order_head
;
4315 p
!= (struct bfd_link_order
*) NULL
;
4317 if (p
->type
== bfd_indirect_link_order
)
4318 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4319 else if (p
->type
== bfd_section_reloc_link_order
4320 || p
->type
== bfd_symbol_reloc_link_order
)
4325 /* Compute the reloc and symbol file positions. */
4326 ecoff_compute_reloc_file_positions (abfd
);
4328 /* Write out the debugging information. */
4329 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4330 &backend
->debug_swap
, info
,
4331 ecoff_data (abfd
)->sym_filepos
))
4334 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4336 if (info
->relocateable
)
4338 /* Now reset the reloc_count field of the sections in the output
4339 BFD to 0, so that we can use them to keep track of how many
4340 relocs we have output thus far. */
4341 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4345 /* Get a value for the GP register. */
4346 if (ecoff_data (abfd
)->gp
== 0)
4348 struct bfd_link_hash_entry
*h
;
4350 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4351 if (h
!= (struct bfd_link_hash_entry
*) NULL
4352 && h
->type
== bfd_link_hash_defined
)
4353 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4354 + h
->u
.def
.section
->output_section
->vma
4355 + h
->u
.def
.section
->output_offset
);
4356 else if (info
->relocateable
)
4360 /* Make up a value. */
4362 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4365 && (strcmp (o
->name
, _SBSS
) == 0
4366 || strcmp (o
->name
, _SDATA
) == 0
4367 || strcmp (o
->name
, _LIT4
) == 0
4368 || strcmp (o
->name
, _LIT8
) == 0
4369 || strcmp (o
->name
, _LITA
) == 0))
4372 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4376 /* If the relocate_section function needs to do a reloc
4377 involving the GP value, it should make a reloc_dangerous
4378 callback to warn that GP is not defined. */
4382 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4384 for (p
= o
->link_order_head
;
4385 p
!= (struct bfd_link_order
*) NULL
;
4388 if (p
->type
== bfd_indirect_link_order
4389 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4390 == bfd_target_ecoff_flavour
))
4392 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4395 else if (p
->type
== bfd_section_reloc_link_order
4396 || p
->type
== bfd_symbol_reloc_link_order
)
4398 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4403 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4409 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4411 ecoff_data (abfd
)->linker
= true;
4416 /* Accumulate the debugging information for an input BFD into the
4417 output BFD. This must read in the symbolic information of the
4421 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4424 struct bfd_link_info
*info
;
4427 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4428 const struct ecoff_debug_swap
* const swap
=
4429 &ecoff_backend (input_bfd
)->debug_swap
;
4430 HDRR
*symhdr
= &debug
->symbolic_header
;
4433 #define READ(ptr, offset, count, size, type) \
4434 if (symhdr->count == 0) \
4435 debug->ptr = NULL; \
4438 debug->ptr = (type) malloc (size * symhdr->count); \
4439 if (debug->ptr == NULL) \
4441 bfd_set_error (bfd_error_no_memory); \
4443 goto return_something; \
4445 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4447 || (bfd_read (debug->ptr, size, symhdr->count, \
4448 input_bfd) != size * symhdr->count)) \
4451 goto return_something; \
4455 /* If raw_syments is not NULL, then the data was already by read by
4456 ecoff_slurp_symbolic_info. */
4457 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4459 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4461 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4462 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4463 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4464 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4465 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4467 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4468 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4469 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4473 /* We do not read the external strings or the external symbols. */
4475 ret
= (bfd_ecoff_debug_accumulate
4476 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4477 &ecoff_backend (output_bfd
)->debug_swap
,
4478 input_bfd
, debug
, swap
, info
));
4481 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4483 if (debug
->line
!= NULL
)
4485 if (debug
->external_dnr
!= NULL
)
4486 free (debug
->external_dnr
);
4487 if (debug
->external_pdr
!= NULL
)
4488 free (debug
->external_pdr
);
4489 if (debug
->external_sym
!= NULL
)
4490 free (debug
->external_sym
);
4491 if (debug
->external_opt
!= NULL
)
4492 free (debug
->external_opt
);
4493 if (debug
->external_aux
!= NULL
)
4494 free (debug
->external_aux
);
4495 if (debug
->ss
!= NULL
)
4497 if (debug
->external_fdr
!= NULL
)
4498 free (debug
->external_fdr
);
4499 if (debug
->external_rfd
!= NULL
)
4500 free (debug
->external_rfd
);
4502 /* Make sure we don't accidentally follow one of these pointers
4503 into freed memory. */
4505 debug
->external_dnr
= NULL
;
4506 debug
->external_pdr
= NULL
;
4507 debug
->external_sym
= NULL
;
4508 debug
->external_opt
= NULL
;
4509 debug
->external_aux
= NULL
;
4511 debug
->external_fdr
= NULL
;
4512 debug
->external_rfd
= NULL
;
4518 /* Put out information for an external symbol. These come only from
4522 ecoff_link_write_external (h
, data
)
4523 struct ecoff_link_hash_entry
*h
;
4526 bfd
*output_bfd
= (bfd
*) data
;
4528 /* FIXME: We should check if this symbol is being stripped. */
4533 if (h
->abfd
== (bfd
*) NULL
)
4536 h
->esym
.cobol_main
= 0;
4537 h
->esym
.weakext
= 0;
4538 h
->esym
.reserved
= 0;
4539 h
->esym
.ifd
= ifdNil
;
4540 h
->esym
.asym
.value
= 0;
4541 h
->esym
.asym
.st
= stGlobal
;
4543 if (h
->root
.type
!= bfd_link_hash_defined
)
4544 h
->esym
.asym
.sc
= scAbs
;
4547 asection
*output_section
;
4550 output_section
= h
->root
.u
.def
.section
->output_section
;
4551 name
= bfd_section_name (output_section
->owner
, output_section
);
4553 if (strcmp (name
, _TEXT
) == 0)
4554 h
->esym
.asym
.sc
= scText
;
4555 else if (strcmp (name
, _DATA
) == 0)
4556 h
->esym
.asym
.sc
= scData
;
4557 else if (strcmp (name
, _SDATA
) == 0)
4558 h
->esym
.asym
.sc
= scSData
;
4559 else if (strcmp (name
, _RDATA
) == 0)
4560 h
->esym
.asym
.sc
= scRData
;
4561 else if (strcmp (name
, _BSS
) == 0)
4562 h
->esym
.asym
.sc
= scBss
;
4563 else if (strcmp (name
, _SBSS
) == 0)
4564 h
->esym
.asym
.sc
= scSBss
;
4565 else if (strcmp (name
, _INIT
) == 0)
4566 h
->esym
.asym
.sc
= scInit
;
4567 else if (strcmp (name
, _FINI
) == 0)
4568 h
->esym
.asym
.sc
= scFini
;
4569 else if (strcmp (name
, _PDATA
) == 0)
4570 h
->esym
.asym
.sc
= scPData
;
4571 else if (strcmp (name
, _XDATA
) == 0)
4572 h
->esym
.asym
.sc
= scXData
;
4574 h
->esym
.asym
.sc
= scAbs
;
4577 h
->esym
.asym
.reserved
= 0;
4578 h
->esym
.asym
.index
= indexNil
;
4580 else if (h
->esym
.ifd
!= -1)
4582 struct ecoff_debug_info
*debug
;
4584 /* Adjust the FDR index for the symbol by that used for the
4586 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4587 BFD_ASSERT (h
->esym
.ifd
>= 0
4588 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4589 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4592 switch (h
->root
.type
)
4595 case bfd_link_hash_new
:
4597 case bfd_link_hash_undefined
:
4598 case bfd_link_hash_weak
:
4599 if (h
->esym
.asym
.sc
!= scUndefined
4600 && h
->esym
.asym
.sc
!= scSUndefined
)
4601 h
->esym
.asym
.sc
= scUndefined
;
4603 case bfd_link_hash_defined
:
4604 if (h
->esym
.asym
.sc
== scUndefined
4605 || h
->esym
.asym
.sc
== scSUndefined
)
4606 h
->esym
.asym
.sc
= scAbs
;
4607 else if (h
->esym
.asym
.sc
== scCommon
)
4608 h
->esym
.asym
.sc
= scBss
;
4609 else if (h
->esym
.asym
.sc
== scSCommon
)
4610 h
->esym
.asym
.sc
= scSBss
;
4611 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4612 + h
->root
.u
.def
.section
->output_section
->vma
4613 + h
->root
.u
.def
.section
->output_offset
);
4615 case bfd_link_hash_common
:
4616 if (h
->esym
.asym
.sc
!= scCommon
4617 && h
->esym
.asym
.sc
!= scSCommon
)
4618 h
->esym
.asym
.sc
= scCommon
;
4619 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4621 case bfd_link_hash_indirect
:
4622 case bfd_link_hash_warning
:
4623 /* FIXME: Ignore these for now. The circumstances under which
4624 they should be written out are not clear to me. */
4628 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4630 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4633 return (bfd_ecoff_debug_one_external
4634 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4635 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4639 /* Relocate and write an ECOFF section into an ECOFF output file. */
4642 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4644 struct bfd_link_info
*info
;
4645 asection
*output_section
;
4646 struct bfd_link_order
*link_order
;
4648 asection
*input_section
;
4650 struct ecoff_section_tdata
*section_tdata
;
4651 bfd_size_type raw_size
;
4652 bfd_size_type cooked_size
;
4653 bfd_byte
*contents
= NULL
;
4654 bfd_size_type external_reloc_size
;
4655 bfd_size_type external_relocs_size
;
4656 PTR external_relocs
= NULL
;
4658 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4660 if (link_order
->size
== 0)
4663 input_section
= link_order
->u
.indirect
.section
;
4664 input_bfd
= input_section
->owner
;
4665 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4667 raw_size
= input_section
->_raw_size
;
4668 cooked_size
= input_section
->_cooked_size
;
4669 if (cooked_size
== 0)
4670 cooked_size
= raw_size
;
4672 BFD_ASSERT (input_section
->output_section
== output_section
);
4673 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4674 BFD_ASSERT (cooked_size
== link_order
->size
);
4676 /* Get the section contents. We allocate memory for the larger of
4677 the size before relocating and the size after relocating. */
4678 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4681 if (contents
== NULL
&& raw_size
!= 0)
4683 bfd_set_error (bfd_error_no_memory
);
4687 /* If we are relaxing, the contents may have already been read into
4688 memory, in which case we copy them into our new buffer. We don't
4689 simply reuse the old buffer in case cooked_size > raw_size. */
4690 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4691 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4692 memcpy (contents
, section_tdata
->contents
, raw_size
);
4695 if (! bfd_get_section_contents (input_bfd
, input_section
,
4697 (file_ptr
) 0, raw_size
))
4701 /* Get the relocs. If we are relaxing MIPS code, they will already
4702 have been read in. Otherwise, we read them in now. */
4703 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4704 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4706 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4707 external_relocs
= section_tdata
->external_relocs
;
4710 external_relocs
= (PTR
) malloc (external_relocs_size
);
4711 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4713 bfd_set_error (bfd_error_no_memory
);
4717 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4718 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4719 != external_relocs_size
))
4723 /* Relocate the section contents. */
4724 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4725 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4729 /* Write out the relocated section. */
4730 if (! bfd_set_section_contents (output_bfd
,
4733 input_section
->output_offset
,
4737 /* If we are producing relocateable output, the relocs were
4738 modified, and we write them out now. We use the reloc_count
4739 field of output_section to keep track of the number of relocs we
4740 have output so far. */
4741 if (info
->relocateable
)
4743 if (bfd_seek (output_bfd
,
4744 (output_section
->rel_filepos
+
4745 output_section
->reloc_count
* external_reloc_size
),
4747 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4748 != external_relocs_size
))
4750 output_section
->reloc_count
+= input_section
->reloc_count
;
4753 if (contents
!= NULL
)
4755 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4756 free (external_relocs
);
4760 if (contents
!= NULL
)
4762 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4763 free (external_relocs
);
4767 /* Generate a reloc when linking an ECOFF file. This is a reloc
4768 requested by the linker, and does come from any input file. This
4769 is used to build constructor and destructor tables when linking
4773 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4775 struct bfd_link_info
*info
;
4776 asection
*output_section
;
4777 struct bfd_link_order
*link_order
;
4780 struct internal_reloc in
;
4781 bfd_size_type external_reloc_size
;
4785 /* We set up an arelent to pass to the backend adjust_reloc_out
4787 rel
.address
= link_order
->offset
;
4789 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4790 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4792 bfd_set_error (bfd_error_bad_value
);
4796 if (link_order
->type
== bfd_section_reloc_link_order
)
4797 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4800 /* We can't set up a reloc against a symbol correctly, because
4801 we have no asymbol structure. Currently no adjust_reloc_out
4803 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4806 /* All ECOFF relocs are in-place. Put the addend into the object
4809 BFD_ASSERT (rel
.howto
->partial_inplace
);
4810 if (link_order
->u
.reloc
.p
->addend
!= 0)
4813 bfd_reloc_status_type rstat
;
4817 size
= bfd_get_reloc_size (rel
.howto
);
4818 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4819 if (buf
== (bfd_byte
*) NULL
)
4821 bfd_set_error (bfd_error_no_memory
);
4824 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4825 link_order
->u
.reloc
.p
->addend
, buf
);
4831 case bfd_reloc_outofrange
:
4833 case bfd_reloc_overflow
:
4834 if (! ((*info
->callbacks
->reloc_overflow
)
4836 (link_order
->type
== bfd_section_reloc_link_order
4837 ? bfd_section_name (output_bfd
,
4838 link_order
->u
.reloc
.p
->u
.section
)
4839 : link_order
->u
.reloc
.p
->u
.name
),
4840 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4841 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4848 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4849 (file_ptr
) link_order
->offset
, size
);
4857 /* Move the information into a internal_reloc structure. */
4858 in
.r_vaddr
= (rel
.address
4859 + bfd_get_section_vma (output_bfd
, output_section
));
4860 in
.r_type
= rel
.howto
->type
;
4862 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4864 struct ecoff_link_hash_entry
*h
;
4866 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4867 link_order
->u
.reloc
.p
->u
.name
,
4868 false, false, true);
4869 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4871 in
.r_symndx
= h
->indx
;
4874 if (! ((*info
->callbacks
->unattached_reloc
)
4875 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4876 (asection
*) NULL
, (bfd_vma
) 0)))
4886 name
= bfd_get_section_name (output_bfd
,
4887 link_order
->u
.reloc
.p
->u
.section
);
4888 if (strcmp (name
, ".text") == 0)
4889 in
.r_symndx
= RELOC_SECTION_TEXT
;
4890 else if (strcmp (name
, ".rdata") == 0)
4891 in
.r_symndx
= RELOC_SECTION_RDATA
;
4892 else if (strcmp (name
, ".data") == 0)
4893 in
.r_symndx
= RELOC_SECTION_DATA
;
4894 else if (strcmp (name
, ".sdata") == 0)
4895 in
.r_symndx
= RELOC_SECTION_SDATA
;
4896 else if (strcmp (name
, ".sbss") == 0)
4897 in
.r_symndx
= RELOC_SECTION_SBSS
;
4898 else if (strcmp (name
, ".bss") == 0)
4899 in
.r_symndx
= RELOC_SECTION_BSS
;
4900 else if (strcmp (name
, ".init") == 0)
4901 in
.r_symndx
= RELOC_SECTION_INIT
;
4902 else if (strcmp (name
, ".lit8") == 0)
4903 in
.r_symndx
= RELOC_SECTION_LIT8
;
4904 else if (strcmp (name
, ".lit4") == 0)
4905 in
.r_symndx
= RELOC_SECTION_LIT4
;
4906 else if (strcmp (name
, ".xdata") == 0)
4907 in
.r_symndx
= RELOC_SECTION_XDATA
;
4908 else if (strcmp (name
, ".pdata") == 0)
4909 in
.r_symndx
= RELOC_SECTION_PDATA
;
4910 else if (strcmp (name
, ".fini") == 0)
4911 in
.r_symndx
= RELOC_SECTION_FINI
;
4912 else if (strcmp (name
, ".lita") == 0)
4913 in
.r_symndx
= RELOC_SECTION_LITA
;
4914 else if (strcmp (name
, "*ABS*") == 0)
4915 in
.r_symndx
= RELOC_SECTION_ABS
;
4921 /* Let the BFD backend adjust the reloc. */
4922 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4924 /* Get some memory and swap out the reloc. */
4925 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4926 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4927 if (rbuf
== (bfd_byte
*) NULL
)
4929 bfd_set_error (bfd_error_no_memory
);
4933 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4935 ok
= (bfd_seek (output_bfd
,
4936 (output_section
->rel_filepos
+
4937 output_section
->reloc_count
* external_reloc_size
),
4939 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4940 == external_reloc_size
));
4943 ++output_section
->reloc_count
;