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
, char *string
,
53 RNDXR
*rndx
, long isym
,
55 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
56 unsigned int indx
, int bigendian
));
57 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
59 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
60 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
61 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
62 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
63 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
68 /* This stuff is somewhat copied from coffcode.h. */
70 static asection bfd_debug_section
= { "*DEBUG*" };
72 /* Create an ECOFF object. */
78 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
79 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
80 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
82 bfd_set_error (bfd_error_no_memory
);
89 /* This is a hook called by coff_real_object_p to create any backend
90 specific information. */
93 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
98 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
99 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
100 ecoff_data_type
*ecoff
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 /* Create the .reginfo section to give programs outside BFD a way to
111 see the information stored in the a.out header. See the comment
113 regsec
= bfd_make_section (abfd
, REGINFO
);
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 /* For the .pdata section, which has a special meaning on the Alpha,
160 we set the alignment to 8. We correct this later in
161 ecoff_compute_section_file_positions. We do this hackery because
162 we need to know the exact unaligned size of the .pdata section in
163 order to set the lnnoptr field correctly. */
164 if (strcmp (section
->name
, _PDATA
) == 0)
165 section
->alignment_power
= 3;
167 section
->alignment_power
= abfd
->xvec
->align_power_min
;
169 if (strcmp (section
->name
, _TEXT
) == 0)
170 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
171 else if (strcmp (section
->name
, _DATA
) == 0
172 || strcmp (section
->name
, _SDATA
) == 0)
173 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
174 else if (strcmp (section
->name
, _RDATA
) == 0
175 || strcmp (section
->name
, _LIT8
) == 0
176 || strcmp (section
->name
, _LIT4
) == 0)
177 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
178 else if (strcmp (section
->name
, _BSS
) == 0
179 || strcmp (section
->name
, _SBSS
) == 0)
180 section
->flags
|= SEC_ALLOC
;
181 else if (strcmp (section
->name
, REGINFO
) == 0)
183 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
184 section completely alone. */
185 section
->flags
|= (SEC_SHARED_LIBRARY
188 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
191 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
192 uncertain about .init on some systems and I don't know how shared
198 /* Determine the machine architecture and type. This is called from
199 the generic COFF routines. It is the inverse of ecoff_get_magic,
200 below. This could be an ECOFF backend routine, with one version
201 for each target, but there aren't all that many ECOFF targets. */
204 ecoff_set_arch_mach_hook (abfd
, filehdr
)
208 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
209 enum bfd_architecture arch
;
212 switch (internal_f
->f_magic
)
215 case MIPS_MAGIC_LITTLE
:
217 arch
= bfd_arch_mips
;
221 case MIPS_MAGIC_LITTLE2
:
222 case MIPS_MAGIC_BIG2
:
223 /* MIPS ISA level 2: the r6000 */
224 arch
= bfd_arch_mips
;
228 case MIPS_MAGIC_LITTLE3
:
229 case MIPS_MAGIC_BIG3
:
230 /* MIPS ISA level 3: the r4000 */
231 arch
= bfd_arch_mips
;
236 arch
= bfd_arch_alpha
;
241 arch
= bfd_arch_obscure
;
246 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
249 /* Get the magic number to use based on the architecture and machine.
250 This is the inverse of ecoff_set_arch_mach_hook, above. */
253 ecoff_get_magic (abfd
)
258 switch (bfd_get_arch (abfd
))
261 switch (bfd_get_mach (abfd
))
266 big
= MIPS_MAGIC_BIG
;
267 little
= MIPS_MAGIC_LITTLE
;
271 big
= MIPS_MAGIC_BIG2
;
272 little
= MIPS_MAGIC_LITTLE2
;
276 big
= MIPS_MAGIC_BIG3
;
277 little
= MIPS_MAGIC_LITTLE3
;
281 return abfd
->xvec
->byteorder_big_p
? big
: little
;
292 /* Get the section s_flags to use for a section. */
295 ecoff_sec_to_styp_flags (name
, flags
)
303 if (strcmp (name
, _TEXT
) == 0)
305 else if (strcmp (name
, _DATA
) == 0)
307 else if (strcmp (name
, _SDATA
) == 0)
309 else if (strcmp (name
, _RDATA
) == 0)
311 else if (strcmp (name
, _LITA
) == 0)
313 else if (strcmp (name
, _LIT8
) == 0)
315 else if (strcmp (name
, _LIT4
) == 0)
317 else if (strcmp (name
, _BSS
) == 0)
319 else if (strcmp (name
, _SBSS
) == 0)
321 else if (strcmp (name
, _INIT
) == 0)
322 styp
= STYP_ECOFF_INIT
;
323 else if (strcmp (name
, _FINI
) == 0)
324 styp
= STYP_ECOFF_FINI
;
325 else if (strcmp (name
, _PDATA
) == 0)
327 else if (strcmp (name
, _XDATA
) == 0)
329 else if (flags
& SEC_CODE
)
331 else if (flags
& SEC_DATA
)
333 else if (flags
& SEC_READONLY
)
335 else if (flags
& SEC_LOAD
)
340 if (flags
& SEC_NEVER_LOAD
)
346 /* Get the BFD flags to use for a section. */
350 ecoff_styp_to_sec_flags (abfd
, hdr
)
354 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
355 long styp_flags
= internal_s
->s_flags
;
356 flagword sec_flags
=0;
358 if (styp_flags
& STYP_NOLOAD
)
359 sec_flags
|= SEC_NEVER_LOAD
;
361 /* For 386 COFF, at least, an unloadable text or data section is
362 actually a shared library section. */
363 if ((styp_flags
& STYP_TEXT
)
364 || (styp_flags
& STYP_ECOFF_INIT
)
365 || (styp_flags
& STYP_ECOFF_FINI
))
367 if (sec_flags
& SEC_NEVER_LOAD
)
368 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
370 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
372 else if ((styp_flags
& STYP_DATA
)
373 || (styp_flags
& STYP_RDATA
)
374 || (styp_flags
& STYP_SDATA
)
375 || styp_flags
== STYP_PDATA
376 || styp_flags
== STYP_XDATA
)
378 if (sec_flags
& SEC_NEVER_LOAD
)
379 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
381 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
382 if ((styp_flags
& STYP_RDATA
)
383 || styp_flags
== STYP_PDATA
)
384 sec_flags
|= SEC_READONLY
;
386 else if ((styp_flags
& STYP_BSS
)
387 || (styp_flags
& STYP_SBSS
))
389 sec_flags
|= SEC_ALLOC
;
391 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
393 sec_flags
|= SEC_NEVER_LOAD
;
395 else if ((styp_flags
& STYP_LITA
)
396 || (styp_flags
& STYP_LIT8
)
397 || (styp_flags
& STYP_LIT4
))
399 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
403 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
409 /* Routines to swap auxiliary information in and out. I am assuming
410 that the auxiliary information format is always going to be target
413 /* Swap in a type information record.
414 BIGEND says whether AUX symbols are big-endian or little-endian; this
415 info comes from the file header record (fh-fBigendian). */
418 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
420 struct tir_ext
*ext_copy
;
423 struct tir_ext ext
[1];
425 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
427 /* now the fun stuff... */
429 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
430 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
431 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
432 >> TIR_BITS1_BT_SH_BIG
;
433 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
434 >> TIR_BITS_TQ4_SH_BIG
;
435 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
436 >> TIR_BITS_TQ5_SH_BIG
;
437 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
438 >> TIR_BITS_TQ0_SH_BIG
;
439 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
440 >> TIR_BITS_TQ1_SH_BIG
;
441 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
442 >> TIR_BITS_TQ2_SH_BIG
;
443 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
444 >> TIR_BITS_TQ3_SH_BIG
;
446 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
447 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
448 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
449 >> TIR_BITS1_BT_SH_LITTLE
;
450 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
451 >> TIR_BITS_TQ4_SH_LITTLE
;
452 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
453 >> TIR_BITS_TQ5_SH_LITTLE
;
454 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
455 >> TIR_BITS_TQ0_SH_LITTLE
;
456 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
457 >> TIR_BITS_TQ1_SH_LITTLE
;
458 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
459 >> TIR_BITS_TQ2_SH_LITTLE
;
460 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
461 >> TIR_BITS_TQ3_SH_LITTLE
;
465 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
470 /* Swap out a type information record.
471 BIGEND says whether AUX symbols are big-endian or little-endian; this
472 info comes from the file header record (fh-fBigendian). */
475 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
482 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
484 /* now the fun stuff... */
486 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
487 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
488 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
489 & TIR_BITS1_BT_BIG
));
490 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
492 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
493 & TIR_BITS_TQ5_BIG
));
494 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
496 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
497 & TIR_BITS_TQ1_BIG
));
498 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
500 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
501 & TIR_BITS_TQ3_BIG
));
503 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
504 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
505 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
506 & TIR_BITS1_BT_LITTLE
));
507 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
508 & TIR_BITS_TQ4_LITTLE
)
509 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
510 & TIR_BITS_TQ5_LITTLE
));
511 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
512 & TIR_BITS_TQ0_LITTLE
)
513 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
514 & TIR_BITS_TQ1_LITTLE
));
515 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
516 & TIR_BITS_TQ2_LITTLE
)
517 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
518 & TIR_BITS_TQ3_LITTLE
));
522 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
527 /* Swap in a relative symbol record. BIGEND says whether it is in
528 big-endian or little-endian format.*/
531 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
533 struct rndx_ext
*ext_copy
;
536 struct rndx_ext ext
[1];
538 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
540 /* now the fun stuff... */
542 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
543 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
544 >> RNDX_BITS1_RFD_SH_BIG
);
545 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
546 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
547 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
548 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
550 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
551 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
552 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
553 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
554 >> RNDX_BITS1_INDEX_SH_LITTLE
)
555 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
556 | ((unsigned int) ext
->r_bits
[3]
557 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
561 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
566 /* Swap out a relative symbol record. BIGEND says whether it is in
567 big-endian or little-endian format.*/
570 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
573 struct rndx_ext
*ext
;
577 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
579 /* now the fun stuff... */
581 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
582 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
583 & RNDX_BITS1_RFD_BIG
)
584 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
585 & RNDX_BITS1_INDEX_BIG
));
586 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
587 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
589 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
590 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
591 & RNDX_BITS1_RFD_LITTLE
)
592 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
593 & RNDX_BITS1_INDEX_LITTLE
));
594 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
595 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
599 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
604 /* Read in the symbolic header for an ECOFF object file. */
607 ecoff_slurp_symbolic_header (abfd
)
610 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
611 bfd_size_type external_hdr_size
;
613 HDRR
*internal_symhdr
;
615 /* See if we've already read it in. */
616 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
617 backend
->debug_swap
.sym_magic
)
620 /* See whether there is a symbolic header. */
621 if (ecoff_data (abfd
)->sym_filepos
== 0)
623 bfd_get_symcount (abfd
) = 0;
627 /* At this point bfd_get_symcount (abfd) holds the number of symbols
628 as read from the file header, but on ECOFF this is always the
629 size of the symbolic information header. It would be cleaner to
630 handle this when we first read the file in coffgen.c. */
631 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
632 if (bfd_get_symcount (abfd
) != external_hdr_size
)
634 bfd_set_error (bfd_error_bad_value
);
638 /* Read the symbolic information header. */
639 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
642 bfd_set_error (bfd_error_no_memory
);
646 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
647 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
648 != external_hdr_size
))
650 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
651 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
653 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
655 bfd_set_error (bfd_error_bad_value
);
659 /* Now we can get the correct number of symbols. */
660 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
661 + internal_symhdr
->iextMax
);
672 /* Read in and swap the important symbolic information for an ECOFF
673 object file. This is called by gdb. */
676 ecoff_slurp_symbolic_info (abfd
)
679 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
680 HDRR
*internal_symhdr
;
681 bfd_size_type raw_base
;
682 bfd_size_type raw_size
;
684 bfd_size_type external_fdr_size
;
688 bfd_size_type raw_end
;
689 bfd_size_type cb_end
;
691 /* Check whether we've already gotten it, and whether there's any to
693 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
695 if (ecoff_data (abfd
)->sym_filepos
== 0)
697 bfd_get_symcount (abfd
) = 0;
701 if (! ecoff_slurp_symbolic_header (abfd
))
704 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
706 /* Read all the symbolic information at once. */
707 raw_base
= (ecoff_data (abfd
)->sym_filepos
708 + backend
->debug_swap
.external_hdr_size
);
710 /* Alpha ecoff makes the determination of raw_size difficult. It has
711 an undocumented debug data section between the symhdr and the first
712 documented section. And the ordering of the sections varies between
713 statically and dynamically linked executables.
714 If bfd supports SEEK_END someday, this code could be simplified. */
718 #define UPDATE_RAW_END(start, count, size) \
719 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
720 if (cb_end > raw_end) \
723 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
724 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
725 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
726 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
727 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
728 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
729 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
730 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
731 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
732 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
733 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
735 #undef UPDATE_RAW_END
737 raw_size
= raw_end
- raw_base
;
740 ecoff_data (abfd
)->sym_filepos
= 0;
743 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
746 bfd_set_error (bfd_error_no_memory
);
750 (ecoff_data (abfd
)->sym_filepos
751 + backend
->debug_swap
.external_hdr_size
),
753 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
755 bfd_release (abfd
, raw
);
759 ecoff_data (abfd
)->raw_syments
= raw
;
761 /* Get pointers for the numeric offsets in the HDRR structure. */
762 #define FIX(off1, off2, type) \
763 if (internal_symhdr->off1 == 0) \
764 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
766 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
767 + internal_symhdr->off1 \
769 FIX (cbLineOffset
, line
, unsigned char *);
770 FIX (cbDnOffset
, external_dnr
, PTR
);
771 FIX (cbPdOffset
, external_pdr
, PTR
);
772 FIX (cbSymOffset
, external_sym
, PTR
);
773 FIX (cbOptOffset
, external_opt
, PTR
);
774 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
775 FIX (cbSsOffset
, ss
, char *);
776 FIX (cbSsExtOffset
, ssext
, char *);
777 FIX (cbFdOffset
, external_fdr
, PTR
);
778 FIX (cbRfdOffset
, external_rfd
, PTR
);
779 FIX (cbExtOffset
, external_ext
, PTR
);
782 /* I don't want to always swap all the data, because it will just
783 waste time and most programs will never look at it. The only
784 time the linker needs most of the debugging information swapped
785 is when linking big-endian and little-endian MIPS object files
786 together, which is not a common occurrence.
788 We need to look at the fdr to deal with a lot of information in
789 the symbols, so we swap them here. */
790 ecoff_data (abfd
)->debug_info
.fdr
=
791 (struct fdr
*) bfd_alloc (abfd
,
792 (internal_symhdr
->ifdMax
*
793 sizeof (struct fdr
)));
794 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
796 bfd_set_error (bfd_error_no_memory
);
799 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
800 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
801 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
802 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
803 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
804 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
809 /* ECOFF symbol table routines. The ECOFF symbol table is described
810 in gcc/mips-tfile.c. */
812 /* ECOFF uses two common sections. One is the usual one, and the
813 other is for small objects. All the small objects are kept
814 together, and then referenced via the gp pointer, which yields
815 faster assembler code. This is what we use for the small common
817 static asection ecoff_scom_section
;
818 static asymbol ecoff_scom_symbol
;
819 static asymbol
*ecoff_scom_symbol_ptr
;
821 /* Create an empty symbol. */
824 ecoff_make_empty_symbol (abfd
)
827 ecoff_symbol_type
*new;
829 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
830 if (new == (ecoff_symbol_type
*) NULL
)
832 bfd_set_error (bfd_error_no_memory
);
833 return (asymbol
*) NULL
;
835 memset ((PTR
) new, 0, sizeof *new);
836 new->symbol
.section
= (asection
*) NULL
;
837 new->fdr
= (FDR
*) NULL
;
840 new->symbol
.the_bfd
= abfd
;
844 /* Set the BFD flags and section for an ECOFF symbol. */
847 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
852 asymbol
**indirect_ptr_ptr
;
854 asym
->the_bfd
= abfd
;
855 asym
->value
= ecoff_sym
->value
;
856 asym
->section
= &bfd_debug_section
;
859 /* An indirect symbol requires two consecutive stabs symbols. */
860 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
862 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
864 /* @@ Stuffing pointers into integers is a no-no.
865 We can usually get away with it if the integer is
866 large enough though. */
867 if (sizeof (asym
) > sizeof (bfd_vma
))
869 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
871 asym
->flags
= BSF_DEBUGGING
;
872 asym
->section
= &bfd_und_section
;
873 *indirect_ptr_ptr
= NULL
;
877 if (ECOFF_IS_STAB (ecoff_sym
)
878 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
880 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
881 asym
->section
= &bfd_ind_section
;
882 /* Pass this symbol on to the next call to this function. */
883 *indirect_ptr_ptr
= asym
;
887 /* Most symbol types are just for debugging. */
888 switch (ecoff_sym
->st
)
897 if (ECOFF_IS_STAB (ecoff_sym
))
899 asym
->flags
= BSF_DEBUGGING
;
904 asym
->flags
= BSF_DEBUGGING
;
909 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
911 asym
->flags
= BSF_LOCAL
;
912 switch (ecoff_sym
->sc
)
915 /* Used for compiler generated labels. Leave them in the
916 debugging section, and mark them as local. If BSF_DEBUGGING
917 is set, then nm does not display them for some reason. If no
918 flags are set then the linker whines about them. */
919 asym
->flags
= BSF_LOCAL
;
922 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
923 asym
->value
-= asym
->section
->vma
;
926 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
927 asym
->value
-= asym
->section
->vma
;
930 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
931 asym
->value
-= asym
->section
->vma
;
934 asym
->flags
= BSF_DEBUGGING
;
937 asym
->section
= &bfd_abs_section
;
940 asym
->section
= &bfd_und_section
;
950 asym
->flags
= BSF_DEBUGGING
;
953 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
954 asym
->value
-= asym
->section
->vma
;
957 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
958 asym
->value
-= asym
->section
->vma
;
961 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
962 asym
->value
-= asym
->section
->vma
;
965 asym
->flags
= BSF_DEBUGGING
;
968 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
970 asym
->section
= &bfd_com_section
;
976 if (ecoff_scom_section
.name
== NULL
)
978 /* Initialize the small common section. */
979 ecoff_scom_section
.name
= SCOMMON
;
980 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
981 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
982 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
983 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
984 ecoff_scom_symbol
.name
= SCOMMON
;
985 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
986 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
987 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
989 asym
->section
= &ecoff_scom_section
;
994 asym
->flags
= BSF_DEBUGGING
;
997 asym
->section
= &bfd_und_section
;
1002 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1003 asym
->value
-= asym
->section
->vma
;
1008 asym
->flags
= BSF_DEBUGGING
;
1011 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1012 asym
->value
-= asym
->section
->vma
;
1018 /* Look for special constructors symbols and make relocation entries
1019 in a special construction section. These are produced by the
1020 -fgnu-linker argument to g++. */
1021 if (ECOFF_IS_STAB (ecoff_sym
))
1023 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1035 arelent_chain
*reloc_chain
;
1036 unsigned int bitsize
;
1038 /* Get a section with the same name as the symbol (usually
1039 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1040 name ___CTOR_LIST (three underscores). We need
1041 __CTOR_LIST (two underscores), since ECOFF doesn't use
1042 a leading underscore. This should be handled by gcc,
1043 but instead we do it here. Actually, this should all
1044 be done differently anyhow. */
1045 name
= bfd_asymbol_name (asym
);
1046 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1051 section
= bfd_get_section_by_name (abfd
, name
);
1052 if (section
== (asection
*) NULL
)
1056 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1059 bfd_set_error (bfd_error_no_memory
);
1062 strcpy (copy
, name
);
1063 section
= bfd_make_section (abfd
, copy
);
1066 /* Build a reloc pointing to this constructor. */
1068 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1071 bfd_set_error (bfd_error_no_memory
);
1074 reloc_chain
->relent
.sym_ptr_ptr
=
1075 bfd_get_section (asym
)->symbol_ptr_ptr
;
1076 reloc_chain
->relent
.address
= section
->_raw_size
;
1077 reloc_chain
->relent
.addend
= asym
->value
;
1078 reloc_chain
->relent
.howto
=
1079 ecoff_backend (abfd
)->constructor_reloc
;
1081 /* Set up the constructor section to hold the reloc. */
1082 section
->flags
= SEC_CONSTRUCTOR
;
1083 ++section
->reloc_count
;
1085 /* Constructor sections must be rounded to a boundary
1086 based on the bitsize. These are not real sections--
1087 they are handled specially by the linker--so the ECOFF
1088 16 byte alignment restriction does not apply. */
1089 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1090 section
->alignment_power
= 1;
1091 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1092 ++section
->alignment_power
;
1094 reloc_chain
->next
= section
->constructor_chain
;
1095 section
->constructor_chain
= reloc_chain
;
1096 section
->_raw_size
+= bitsize
/ 8;
1098 /* Mark the symbol as a constructor. */
1099 asym
->flags
|= BSF_CONSTRUCTOR
;
1107 /* Read an ECOFF symbol table. */
1110 ecoff_slurp_symbol_table (abfd
)
1113 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1114 const bfd_size_type external_ext_size
1115 = backend
->debug_swap
.external_ext_size
;
1116 const bfd_size_type external_sym_size
1117 = backend
->debug_swap
.external_sym_size
;
1118 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1119 = backend
->debug_swap
.swap_ext_in
;
1120 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1121 = backend
->debug_swap
.swap_sym_in
;
1122 bfd_size_type internal_size
;
1123 ecoff_symbol_type
*internal
;
1124 ecoff_symbol_type
*internal_ptr
;
1125 asymbol
*indirect_ptr
;
1131 /* If we've already read in the symbol table, do nothing. */
1132 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1135 /* Get the symbolic information. */
1136 if (ecoff_slurp_symbolic_info (abfd
) == false)
1138 if (bfd_get_symcount (abfd
) == 0)
1141 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1142 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1143 if (internal
== NULL
)
1145 bfd_set_error (bfd_error_no_memory
);
1149 internal_ptr
= internal
;
1150 indirect_ptr
= NULL
;
1151 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1152 eraw_end
= (eraw_src
1153 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1154 * external_ext_size
));
1155 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1159 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1160 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1161 + internal_esym
.asym
.iss
);
1162 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1163 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1165 /* The alpha uses a negative ifd field for section symbols. */
1166 if (internal_esym
.ifd
>= 0)
1167 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1168 + internal_esym
.ifd
);
1170 internal_ptr
->fdr
= NULL
;
1171 internal_ptr
->local
= false;
1172 internal_ptr
->native
= (PTR
) eraw_src
;
1174 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1176 /* The local symbols must be accessed via the fdr's, because the
1177 string and aux indices are relative to the fdr information. */
1178 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1179 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1180 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1185 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1186 + fdr_ptr
->isymBase
* external_sym_size
);
1187 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1189 lraw_src
< lraw_end
;
1190 lraw_src
+= external_sym_size
, internal_ptr
++)
1194 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1195 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1197 + internal_sym
.iss
);
1198 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1199 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1201 internal_ptr
->fdr
= fdr_ptr
;
1202 internal_ptr
->local
= true;
1203 internal_ptr
->native
= (PTR
) lraw_src
;
1206 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1208 ecoff_data (abfd
)->canonical_symbols
= internal
;
1213 /* Return the amount of space needed for the canonical symbols. */
1216 ecoff_get_symtab_upper_bound (abfd
)
1219 if (! ecoff_slurp_symbolic_info (abfd
))
1222 if (bfd_get_symcount (abfd
) == 0)
1225 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1228 /* Get the canonical symbols. */
1231 ecoff_get_symtab (abfd
, alocation
)
1233 asymbol
**alocation
;
1235 unsigned int counter
= 0;
1236 ecoff_symbol_type
*symbase
;
1237 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1239 if (ecoff_slurp_symbol_table (abfd
) == false)
1241 if (bfd_get_symcount (abfd
) == 0)
1244 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1245 while (counter
< bfd_get_symcount (abfd
))
1247 *(location
++) = symbase
++;
1250 *location
++ = (ecoff_symbol_type
*) NULL
;
1251 return bfd_get_symcount (abfd
);
1254 /* Turn ECOFF type information into a printable string.
1255 ecoff_emit_aggregate and ecoff_type_to_string are from
1256 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1258 /* Write aggregate information to a string. */
1261 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1268 int ifd
= rndx
->rfd
;
1269 int indx
= rndx
->index
;
1270 int sym_base
, ss_base
;
1276 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1277 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1279 if (indx
== indexNil
)
1280 name
= "/* no name */";
1283 const struct ecoff_debug_swap
* const debug_swap
1284 = &ecoff_backend (abfd
)->debug_swap
;
1288 (*debug_swap
->swap_sym_in
)
1290 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1291 + indx
* debug_swap
->external_sym_size
),
1293 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1297 "%s %s { ifd = %d, index = %ld }",
1300 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1303 /* Convert the type information to string format. */
1306 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1308 union aux_ext
*aux_ptr
;
1320 unsigned int basic_type
;
1322 static char buffer1
[1024];
1323 static char buffer2
[1024];
1328 for (i
= 0; i
< 7; i
++)
1330 qualifiers
[i
].low_bound
= 0;
1331 qualifiers
[i
].high_bound
= 0;
1332 qualifiers
[i
].stride
= 0;
1335 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1336 return "-1 (no type)";
1337 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1339 basic_type
= u
.ti
.bt
;
1340 qualifiers
[0].type
= u
.ti
.tq0
;
1341 qualifiers
[1].type
= u
.ti
.tq1
;
1342 qualifiers
[2].type
= u
.ti
.tq2
;
1343 qualifiers
[3].type
= u
.ti
.tq3
;
1344 qualifiers
[4].type
= u
.ti
.tq4
;
1345 qualifiers
[5].type
= u
.ti
.tq5
;
1346 qualifiers
[6].type
= tqNil
;
1349 * Go get the basic type.
1353 case btNil
: /* undefined */
1357 case btAdr
: /* address - integer same size as pointer */
1358 strcpy (p1
, "address");
1361 case btChar
: /* character */
1362 strcpy (p1
, "char");
1365 case btUChar
: /* unsigned character */
1366 strcpy (p1
, "unsigned char");
1369 case btShort
: /* short */
1370 strcpy (p1
, "short");
1373 case btUShort
: /* unsigned short */
1374 strcpy (p1
, "unsigned short");
1377 case btInt
: /* int */
1381 case btUInt
: /* unsigned int */
1382 strcpy (p1
, "unsigned int");
1385 case btLong
: /* long */
1386 strcpy (p1
, "long");
1389 case btULong
: /* unsigned long */
1390 strcpy (p1
, "unsigned long");
1393 case btFloat
: /* float (real) */
1394 strcpy (p1
, "float");
1397 case btDouble
: /* Double (real) */
1398 strcpy (p1
, "double");
1401 /* Structures add 1-2 aux words:
1402 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1403 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1405 case btStruct
: /* Structure (Record) */
1406 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1407 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1408 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1410 indx
++; /* skip aux words */
1413 /* Unions add 1-2 aux words:
1414 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1415 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1417 case btUnion
: /* Union */
1418 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1419 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1420 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1422 indx
++; /* skip aux words */
1425 /* Enumerations add 1-2 aux words:
1426 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1427 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1429 case btEnum
: /* Enumeration */
1430 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1431 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1432 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1434 indx
++; /* skip aux words */
1437 case btTypedef
: /* defined via a typedef, isymRef points */
1438 strcpy (p1
, "typedef");
1441 case btRange
: /* subrange of int */
1442 strcpy (p1
, "subrange");
1445 case btSet
: /* pascal sets */
1449 case btComplex
: /* fortran complex */
1450 strcpy (p1
, "complex");
1453 case btDComplex
: /* fortran double complex */
1454 strcpy (p1
, "double complex");
1457 case btIndirect
: /* forward or unnamed typedef */
1458 strcpy (p1
, "forward/unamed typedef");
1461 case btFixedDec
: /* Fixed Decimal */
1462 strcpy (p1
, "fixed decimal");
1465 case btFloatDec
: /* Float Decimal */
1466 strcpy (p1
, "float decimal");
1469 case btString
: /* Varying Length Character String */
1470 strcpy (p1
, "string");
1473 case btBit
: /* Aligned Bit String */
1477 case btPicture
: /* Picture */
1478 strcpy (p1
, "picture");
1481 case btVoid
: /* Void */
1482 strcpy (p1
, "void");
1486 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1490 p1
+= strlen (buffer1
);
1493 * If this is a bitfield, get the bitsize.
1499 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1500 sprintf (p1
, " : %d", bitsize
);
1501 p1
+= strlen (buffer1
);
1506 * Deal with any qualifiers.
1508 if (qualifiers
[0].type
!= tqNil
)
1511 * Snarf up any array bounds in the correct order. Arrays
1512 * store 5 successive words in the aux. table:
1513 * word 0 RNDXR to type of the bounds (ie, int)
1514 * word 1 Current file descriptor index
1516 * word 3 high bound (or -1 if [])
1517 * word 4 stride size in bits
1519 for (i
= 0; i
< 7; i
++)
1521 if (qualifiers
[i
].type
== tqArray
)
1523 qualifiers
[i
].low_bound
=
1524 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1525 qualifiers
[i
].high_bound
=
1526 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1527 qualifiers
[i
].stride
=
1528 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1534 * Now print out the qualifiers.
1536 for (i
= 0; i
< 6; i
++)
1538 switch (qualifiers
[i
].type
)
1545 strcpy (p2
, "ptr to ");
1546 p2
+= sizeof ("ptr to ")-1;
1550 strcpy (p2
, "volatile ");
1551 p2
+= sizeof ("volatile ")-1;
1555 strcpy (p2
, "far ");
1556 p2
+= sizeof ("far ")-1;
1560 strcpy (p2
, "func. ret. ");
1561 p2
+= sizeof ("func. ret. ");
1566 int first_array
= i
;
1569 /* Print array bounds reversed (ie, in the order the C
1570 programmer writes them). C is such a fun language.... */
1572 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1575 for (j
= i
; j
>= first_array
; j
--)
1577 strcpy (p2
, "array [");
1578 p2
+= sizeof ("array [")-1;
1579 if (qualifiers
[j
].low_bound
!= 0)
1581 "%ld:%ld {%ld bits}",
1582 (long) qualifiers
[j
].low_bound
,
1583 (long) qualifiers
[j
].high_bound
,
1584 (long) qualifiers
[j
].stride
);
1586 else if (qualifiers
[j
].high_bound
!= -1)
1589 (long) (qualifiers
[j
].high_bound
+ 1),
1590 (long) (qualifiers
[j
].stride
));
1593 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1596 strcpy (p2
, "] of ");
1597 p2
+= sizeof ("] of ")-1;
1605 strcpy (p2
, buffer1
);
1609 /* Return information about ECOFF symbol SYMBOL in RET. */
1613 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1614 bfd
*abfd
; /* Ignored. */
1618 bfd_symbol_info (symbol
, ret
);
1621 /* Print information about an ECOFF symbol. */
1624 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1628 bfd_print_symbol_type how
;
1630 const struct ecoff_debug_swap
* const debug_swap
1631 = &ecoff_backend (abfd
)->debug_swap
;
1632 FILE *file
= (FILE *)filep
;
1636 case bfd_print_symbol_name
:
1637 fprintf (file
, "%s", symbol
->name
);
1639 case bfd_print_symbol_more
:
1640 if (ecoffsymbol (symbol
)->local
)
1644 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1646 fprintf (file
, "ecoff local ");
1647 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1648 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1649 (unsigned) ecoff_sym
.sc
);
1655 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1657 fprintf (file
, "ecoff extern ");
1658 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1659 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1660 (unsigned) ecoff_ext
.asym
.sc
);
1663 case bfd_print_symbol_all
:
1664 /* Print out the symbols in a reasonable way */
1673 if (ecoffsymbol (symbol
)->local
)
1675 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1678 pos
= ((((char *) ecoffsymbol (symbol
)->native
1679 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1680 / debug_swap
->external_sym_size
)
1681 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1688 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1691 pos
= (((char *) ecoffsymbol (symbol
)->native
1692 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1693 / debug_swap
->external_ext_size
);
1694 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1695 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1696 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1699 fprintf (file
, "[%3d] %c ",
1701 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1702 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1703 (unsigned) ecoff_ext
.asym
.st
,
1704 (unsigned) ecoff_ext
.asym
.sc
,
1705 (unsigned) ecoff_ext
.asym
.index
,
1706 jmptbl
, cobol_main
, weakext
,
1709 if (ecoffsymbol (symbol
)->fdr
!= NULL
1710 && ecoff_ext
.asym
.index
!= indexNil
)
1714 bfd_size_type sym_base
;
1715 union aux_ext
*aux_base
;
1717 indx
= ecoff_ext
.asym
.index
;
1719 /* sym_base is used to map the fdr relative indices which
1720 appear in the file to the position number which we are
1722 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1723 if (ecoffsymbol (symbol
)->local
)
1725 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1727 /* aux_base is the start of the aux entries for this file;
1728 asym.index is an offset from this. */
1729 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1730 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1732 /* The aux entries are stored in host byte order; the
1733 order is indicated by a bit in the fdr. */
1734 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1736 /* This switch is basically from gcc/mips-tdump.c */
1737 switch (ecoff_ext
.asym
.st
)
1745 fprintf (file
, "\n End+1 symbol: %ld",
1746 (long) (indx
+ sym_base
));
1750 if (ecoff_ext
.asym
.sc
== scText
1751 || ecoff_ext
.asym
.sc
== scInfo
)
1752 fprintf (file
, "\n First symbol: %ld",
1753 (long) (indx
+ sym_base
));
1755 fprintf (file
, "\n First symbol: %ld",
1756 (long) (AUX_GET_ISYM (bigendian
,
1757 &aux_base
[ecoff_ext
.asym
.index
])
1763 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1765 else if (ecoffsymbol (symbol
)->local
)
1766 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1767 (long) (AUX_GET_ISYM (bigendian
,
1768 &aux_base
[ecoff_ext
.asym
.index
])
1770 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1773 fprintf (file
, "\n Local symbol: %ld",
1776 + (ecoff_data (abfd
)
1777 ->debug_info
.symbolic_header
.iextMax
)));
1781 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1782 fprintf (file
, "\n Type: %s",
1783 ecoff_type_to_string (abfd
, aux_base
, indx
,
1793 /* Read in the relocs for a section. */
1796 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1801 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1802 arelent
*internal_relocs
;
1803 bfd_size_type external_reloc_size
;
1804 bfd_size_type external_relocs_size
;
1805 char *external_relocs
;
1809 if (section
->relocation
!= (arelent
*) NULL
1810 || section
->reloc_count
== 0
1811 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1814 if (ecoff_slurp_symbol_table (abfd
) == false)
1817 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1819 * section
->reloc_count
));
1820 external_reloc_size
= backend
->external_reloc_size
;
1821 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1822 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1823 if (internal_relocs
== (arelent
*) NULL
1824 || external_relocs
== (char *) NULL
)
1826 bfd_set_error (bfd_error_no_memory
);
1829 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1831 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1832 != external_relocs_size
)
1835 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1837 struct internal_reloc intern
;
1839 (*backend
->swap_reloc_in
) (abfd
,
1840 external_relocs
+ i
* external_reloc_size
,
1843 if (intern
.r_extern
)
1845 /* r_symndx is an index into the external symbols. */
1846 BFD_ASSERT (intern
.r_symndx
>= 0
1848 < (ecoff_data (abfd
)
1849 ->debug_info
.symbolic_header
.iextMax
)));
1850 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1853 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1854 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1856 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1861 CONST
char *sec_name
;
1864 /* r_symndx is a section key. */
1865 switch (intern
.r_symndx
)
1867 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1868 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1869 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1870 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1871 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1872 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1873 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1874 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1875 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1876 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1877 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1878 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1879 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1883 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1884 if (sec
== (asection
*) NULL
)
1886 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1888 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1891 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1893 /* Let the backend select the howto field and do any other
1894 required processing. */
1895 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1898 bfd_release (abfd
, external_relocs
);
1900 section
->relocation
= internal_relocs
;
1905 /* Get a canonical list of relocs. */
1908 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1916 if (section
->flags
& SEC_CONSTRUCTOR
)
1918 arelent_chain
*chain
;
1920 /* This section has relocs made up by us, not the file, so take
1921 them out of their chain and place them into the data area
1923 for (count
= 0, chain
= section
->constructor_chain
;
1924 count
< section
->reloc_count
;
1925 count
++, chain
= chain
->next
)
1926 *relptr
++ = &chain
->relent
;
1932 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1935 tblptr
= section
->relocation
;
1936 if (tblptr
== (arelent
*) NULL
)
1939 for (count
= 0; count
< section
->reloc_count
; count
++)
1940 *relptr
++ = tblptr
++;
1943 *relptr
= (arelent
*) NULL
;
1945 return section
->reloc_count
;
1948 /* Provided a BFD, a section and an offset into the section, calculate
1949 and return the name of the source file and the line nearest to the
1954 ecoff_find_nearest_line (abfd
,
1963 asymbol
**ignore_symbols
;
1965 CONST
char **filename_ptr
;
1966 CONST
char **functionname_ptr
;
1967 unsigned int *retline_ptr
;
1969 const struct ecoff_debug_swap
* const debug_swap
1970 = &ecoff_backend (abfd
)->debug_swap
;
1975 bfd_size_type external_pdr_size
;
1979 unsigned char *line_ptr
;
1980 unsigned char *line_end
;
1983 /* If we're not in the .text section, we don't have any line
1985 if (strcmp (section
->name
, _TEXT
) != 0
1986 || offset
< ecoff_data (abfd
)->text_start
1987 || offset
>= ecoff_data (abfd
)->text_end
)
1990 /* Make sure we have the FDR's. */
1991 if (ecoff_slurp_symbolic_info (abfd
) == false
1992 || bfd_get_symcount (abfd
) == 0)
1995 /* Each file descriptor (FDR) has a memory address. Here we track
1996 down which FDR we want. The FDR's are stored in increasing
1997 memory order. If speed is ever important, this can become a
1998 binary search. We must ignore FDR's with no PDR entries; they
1999 will have the adr of the FDR before or after them. */
2000 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2001 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2002 fdr_hold
= (FDR
*) NULL
;
2003 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2005 if (fdr_ptr
->cpd
== 0)
2007 if (offset
< fdr_ptr
->adr
)
2011 if (fdr_hold
== (FDR
*) NULL
)
2015 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2016 have an address, which is relative to the FDR address, and are
2017 also stored in increasing memory order. */
2018 offset
-= fdr_ptr
->adr
;
2019 external_pdr_size
= debug_swap
->external_pdr_size
;
2020 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2021 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2022 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2023 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2025 /* The address of the first PDR is an offset which applies to the
2026 addresses of all the PDR's. */
2029 for (pdr_ptr
+= external_pdr_size
;
2031 pdr_ptr
+= external_pdr_size
)
2033 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2034 if (offset
< pdr
.adr
)
2038 /* Now we can look for the actual line number. The line numbers are
2039 stored in a very funky format, which I won't try to describe.
2040 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2041 we want; we need this to compute line_end. */
2042 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2043 if (pdr_ptr
== pdr_end
)
2044 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2046 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2048 /* Now change pdr and pdr_ptr to the one we want. */
2049 pdr_ptr
-= external_pdr_size
;
2050 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2054 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2055 + fdr_ptr
->cbLineOffset
2056 + pdr
.cbLineOffset
);
2057 while (line_ptr
< line_end
)
2062 delta
= *line_ptr
>> 4;
2065 count
= (*line_ptr
& 0xf) + 1;
2069 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2070 if (delta
>= 0x8000)
2075 if (offset
< count
* 4)
2077 offset
-= count
* 4;
2080 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2081 at least according to gdb/mipsread.c. */
2082 if (fdr_ptr
->rss
== -1)
2084 *filename_ptr
= NULL
;
2086 *functionname_ptr
= NULL
;
2091 (*debug_swap
->swap_ext_in
)
2093 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2094 + pdr
.isym
* debug_swap
->external_ext_size
),
2096 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2097 + proc_ext
.asym
.iss
);
2104 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2107 (*debug_swap
->swap_sym_in
)
2109 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2110 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2112 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2116 if (lineno
== ilineNil
)
2118 *retline_ptr
= lineno
;
2122 /* Set the architecture. The supported architecture is stored in the
2123 backend pointer. We always set the architecture anyhow, since many
2124 callers ignore the return value. */
2127 ecoff_set_arch_mach (abfd
, arch
, machine
)
2129 enum bfd_architecture arch
;
2130 unsigned long machine
;
2132 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2133 return arch
== ecoff_backend (abfd
)->arch
;
2136 /* Get the size of the section headers. We do not output the .reginfo
2141 ecoff_sizeof_headers (abfd
, reloc
)
2150 for (current
= abfd
->sections
;
2151 current
!= (asection
*)NULL
;
2152 current
= current
->next
)
2153 if (strcmp (current
->name
, REGINFO
) != 0)
2156 ret
= (bfd_coff_filhsz (abfd
)
2157 + bfd_coff_aoutsz (abfd
)
2158 + c
* bfd_coff_scnhsz (abfd
));
2159 return BFD_ALIGN (ret
, 16);
2162 /* Get the contents of a section. This is where we handle reading the
2163 .reginfo section, which implicitly holds the contents of an
2164 ecoff_reginfo structure. */
2167 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2172 bfd_size_type count
;
2174 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2175 struct ecoff_reginfo s
;
2178 if (strcmp (section
->name
, REGINFO
) != 0)
2179 return bfd_generic_get_section_contents (abfd
, section
, location
,
2182 s
.gp_value
= tdata
->gp
;
2183 s
.gprmask
= tdata
->gprmask
;
2184 for (i
= 0; i
< 4; i
++)
2185 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2186 s
.fprmask
= tdata
->fprmask
;
2188 /* bfd_get_section_contents has already checked that the offset and
2189 size is reasonable. We don't have to worry about swapping or any
2190 such thing; the .reginfo section is defined such that the
2191 contents are an ecoff_reginfo structure as seen on the host. */
2192 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2196 /* Calculate the file position for each section, and set
2200 ecoff_compute_section_file_positions (abfd
)
2208 sofar
= ecoff_sizeof_headers (abfd
, false);
2211 for (current
= abfd
->sections
;
2212 current
!= (asection
*) NULL
;
2213 current
= current
->next
)
2215 unsigned int alignment_power
;
2217 /* Only deal with sections which have contents */
2218 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2219 || strcmp (current
->name
, REGINFO
) == 0)
2222 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2223 supposed to indicate the number of .pdata entries that are
2224 really in the section. Each entry is 8 bytes. We store this
2225 away in line_filepos before increasing the section size. */
2226 if (strcmp (current
->name
, _PDATA
) != 0)
2227 alignment_power
= current
->alignment_power
;
2230 current
->line_filepos
= current
->_raw_size
/ 8;
2231 alignment_power
= 4;
2234 /* On Ultrix, the data sections in an executable file must be
2235 aligned to a page boundary within the file. This does not
2236 affect the section size, though. FIXME: Does this work for
2237 other platforms? It requires some modification for the
2238 Alpha, because .rdata on the Alpha goes with the text, not
2240 if ((abfd
->flags
& EXEC_P
) != 0
2241 && (abfd
->flags
& D_PAGED
) != 0
2242 && first_data
!= false
2243 && (current
->flags
& SEC_CODE
) == 0
2244 && (! ecoff_backend (abfd
)->rdata_in_text
2245 || strcmp (current
->name
, _RDATA
) != 0)
2246 && strcmp (current
->name
, _PDATA
) != 0)
2248 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2250 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2254 /* Align the sections in the file to the same boundary on
2255 which they are aligned in virtual memory. */
2257 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2259 current
->filepos
= sofar
;
2261 sofar
+= current
->_raw_size
;
2263 /* make sure that this section is of the right size too */
2265 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2266 current
->_raw_size
+= sofar
- old_sofar
;
2269 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2272 /* Determine the location of the relocs for all the sections in the
2273 output file, as well as the location of the symbolic debugging
2276 static bfd_size_type
2277 ecoff_compute_reloc_file_positions (abfd
)
2280 const bfd_size_type external_reloc_size
=
2281 ecoff_backend (abfd
)->external_reloc_size
;
2282 file_ptr reloc_base
;
2283 bfd_size_type reloc_size
;
2287 if (! abfd
->output_has_begun
)
2289 ecoff_compute_section_file_positions (abfd
);
2290 abfd
->output_has_begun
= true;
2293 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2296 for (current
= abfd
->sections
;
2297 current
!= (asection
*)NULL
;
2298 current
= current
->next
)
2300 if (strcmp (current
->name
, REGINFO
) == 0)
2302 if (current
->reloc_count
== 0)
2303 current
->rel_filepos
= 0;
2306 bfd_size_type relsize
;
2308 current
->rel_filepos
= reloc_base
;
2309 relsize
= current
->reloc_count
* external_reloc_size
;
2310 reloc_size
+= relsize
;
2311 reloc_base
+= relsize
;
2315 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2317 /* At least on Ultrix, the symbol table of an executable file must
2318 be aligned to a page boundary. FIXME: Is this true on other
2320 if ((abfd
->flags
& EXEC_P
) != 0
2321 && (abfd
->flags
& D_PAGED
) != 0)
2322 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2323 &~ (ecoff_backend (abfd
)->round
- 1));
2325 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2330 /* Set the contents of a section. This is where we handle setting the
2331 contents of the .reginfo section, which implicitly holds a
2332 ecoff_reginfo structure. */
2335 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2340 bfd_size_type count
;
2342 /* This must be done first, because bfd_set_section_contents is
2343 going to set output_has_begun to true. */
2344 if (abfd
->output_has_begun
== false)
2345 ecoff_compute_section_file_positions (abfd
);
2350 if (strcmp (section
->name
, REGINFO
) == 0)
2352 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2353 struct ecoff_reginfo s
;
2356 /* If the caller is only changing part of the structure, we must
2357 retrieve the current information before the memcpy. */
2358 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2360 s
.gp_value
= tdata
->gp
;
2361 s
.gprmask
= tdata
->gprmask
;
2362 for (i
= 0; i
< 4; i
++)
2363 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2364 s
.fprmask
= tdata
->fprmask
;
2367 /* bfd_set_section_contents has already checked that the offset
2368 and size is reasonable. We don't have to worry about
2369 swapping or any such thing; the .reginfo section is defined
2370 such that the contents are an ecoff_reginfo structure as seen
2372 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2374 tdata
->gp
= s
.gp_value
;
2375 tdata
->gprmask
= s
.gprmask
;
2376 for (i
= 0; i
< 4; i
++)
2377 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2378 tdata
->fprmask
= s
.fprmask
;
2383 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2384 || bfd_write (location
, 1, count
, abfd
) != count
)
2390 /* Get ECOFF EXTR information for an external symbol. This function
2391 is passed to bfd_ecoff_debug_externals. */
2394 ecoff_get_extr (sym
, esym
)
2398 ecoff_symbol_type
*ecoff_sym_ptr
;
2401 /* Don't include debugging, local or section symbols. */
2402 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2403 || (sym
->flags
& BSF_LOCAL
) != 0
2404 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2407 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2408 || ecoffsymbol (sym
)->native
== NULL
)
2411 esym
->cobol_main
= 0;
2415 /* FIXME: we can do better than this for st and sc. */
2416 esym
->asym
.st
= stGlobal
;
2417 esym
->asym
.sc
= scAbs
;
2418 esym
->asym
.reserved
= 0;
2419 esym
->asym
.index
= indexNil
;
2423 ecoff_sym_ptr
= ecoffsymbol (sym
);
2425 if (ecoff_sym_ptr
->local
)
2428 input_bfd
= bfd_asymbol_bfd (sym
);
2429 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2430 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2432 /* If the symbol was defined by the linker, then esym will be
2433 undefined but sym will not be. Get a better class for such a
2435 if ((esym
->asym
.sc
== scUndefined
2436 || esym
->asym
.sc
== scSUndefined
)
2437 && bfd_get_section (sym
) != &bfd_und_section
)
2438 esym
->asym
.sc
= scAbs
;
2440 /* Adjust the FDR index for the symbol by that used for the input
2442 if (esym
->ifd
!= -1)
2444 struct ecoff_debug_info
*input_debug
;
2446 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2447 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2448 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2449 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2455 /* Set the external symbol index. This routine is passed to
2456 bfd_ecoff_debug_externals. */
2459 ecoff_set_index (sym
, indx
)
2463 ecoff_set_sym_index (sym
, indx
);
2466 /* Write out an ECOFF file. */
2469 ecoff_write_object_contents (abfd
)
2472 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2473 const bfd_vma round
= backend
->round
;
2474 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2475 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2476 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2477 const bfd_size_type external_hdr_size
2478 = backend
->debug_swap
.external_hdr_size
;
2479 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2480 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2482 struct internal_reloc
*))
2483 = backend
->adjust_reloc_out
;
2484 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2485 const struct internal_reloc
*,
2487 = backend
->swap_reloc_out
;
2488 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2489 HDRR
* const symhdr
= &debug
->symbolic_header
;
2492 bfd_size_type reloc_size
;
2493 bfd_size_type text_size
;
2495 boolean set_text_start
;
2496 bfd_size_type data_size
;
2498 boolean set_data_start
;
2499 bfd_size_type bss_size
;
2501 PTR reloc_buff
= NULL
;
2502 struct internal_filehdr internal_f
;
2503 struct internal_aouthdr internal_a
;
2506 /* Determine where the sections and relocs will go in the output
2508 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2511 for (current
= abfd
->sections
;
2512 current
!= (asection
*)NULL
;
2513 current
= current
->next
)
2515 if (strcmp (current
->name
, REGINFO
) == 0)
2517 current
->target_index
= count
;
2521 if ((abfd
->flags
& D_PAGED
) != 0)
2522 text_size
= ecoff_sizeof_headers (abfd
, false);
2526 set_text_start
= false;
2529 set_data_start
= false;
2532 /* Write section headers to the file. */
2534 /* Allocate buff big enough to hold a section header,
2535 file header, or a.out header. */
2543 buff
= (PTR
) malloc (siz
);
2546 bfd_set_error (bfd_error_no_memory
);
2551 internal_f
.f_nscns
= 0;
2552 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2554 for (current
= abfd
->sections
;
2555 current
!= (asection
*) NULL
;
2556 current
= current
->next
)
2558 struct internal_scnhdr section
;
2561 if (strcmp (current
->name
, REGINFO
) == 0)
2563 BFD_ASSERT (current
->reloc_count
== 0);
2567 ++internal_f
.f_nscns
;
2569 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2571 /* FIXME: is this correct for shared libraries? I think it is
2572 but I have no platform to check. Ian Lance Taylor. */
2573 vma
= bfd_get_section_vma (abfd
, current
);
2574 if (strcmp (current
->name
, _LIB
) == 0)
2575 section
.s_vaddr
= 0;
2577 section
.s_vaddr
= vma
;
2579 section
.s_paddr
= vma
;
2580 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2582 /* If this section is unloadable then the scnptr will be 0. */
2583 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2584 section
.s_scnptr
= 0;
2586 section
.s_scnptr
= current
->filepos
;
2587 section
.s_relptr
= current
->rel_filepos
;
2589 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2590 object file produced by the assembler is supposed to point to
2591 information about how much room is required by objects of
2592 various different sizes. I think this only matters if we
2593 want the linker to compute the best size to use, or
2594 something. I don't know what happens if the information is
2596 if (strcmp (current
->name
, _PDATA
) != 0)
2597 section
.s_lnnoptr
= 0;
2600 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2601 hold the number of entries in the section (each entry is
2602 8 bytes). We stored this in the line_filepos field in
2603 ecoff_compute_section_file_positions. */
2604 section
.s_lnnoptr
= current
->line_filepos
;
2607 section
.s_nreloc
= current
->reloc_count
;
2608 section
.s_nlnno
= 0;
2609 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2612 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2613 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2616 if ((section
.s_flags
& STYP_TEXT
) != 0
2617 || ((section
.s_flags
& STYP_RDATA
) != 0
2618 && backend
->rdata_in_text
)
2619 || strcmp (current
->name
, _PDATA
) == 0)
2621 text_size
+= bfd_get_section_size_before_reloc (current
);
2622 if (! set_text_start
|| text_start
> vma
)
2625 set_text_start
= true;
2628 else if ((section
.s_flags
& STYP_RDATA
) != 0
2629 || (section
.s_flags
& STYP_DATA
) != 0
2630 || (section
.s_flags
& STYP_LITA
) != 0
2631 || (section
.s_flags
& STYP_LIT8
) != 0
2632 || (section
.s_flags
& STYP_LIT4
) != 0
2633 || (section
.s_flags
& STYP_SDATA
) != 0
2634 || strcmp (current
->name
, _XDATA
) == 0)
2636 data_size
+= bfd_get_section_size_before_reloc (current
);
2637 if (! set_data_start
|| data_start
> vma
)
2640 set_data_start
= true;
2643 else if ((section
.s_flags
& STYP_BSS
) != 0
2644 || (section
.s_flags
& STYP_SBSS
) != 0)
2645 bss_size
+= bfd_get_section_size_before_reloc (current
);
2650 /* Set up the file header. */
2652 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2654 /* We will NOT put a fucking timestamp in the header here. Every
2655 time you put it back, I will come in and take it out again. I'm
2656 sorry. This field does not belong here. We fill it with a 0 so
2657 it compares the same but is not a reasonable time. --
2659 internal_f
.f_timdat
= 0;
2661 if (bfd_get_symcount (abfd
) != 0)
2663 /* The ECOFF f_nsyms field is not actually the number of
2664 symbols, it's the size of symbolic information header. */
2665 internal_f
.f_nsyms
= external_hdr_size
;
2666 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2670 internal_f
.f_nsyms
= 0;
2671 internal_f
.f_symptr
= 0;
2674 internal_f
.f_opthdr
= aoutsz
;
2676 internal_f
.f_flags
= F_LNNO
;
2677 if (reloc_size
== 0)
2678 internal_f
.f_flags
|= F_RELFLG
;
2679 if (bfd_get_symcount (abfd
) == 0)
2680 internal_f
.f_flags
|= F_LSYMS
;
2681 if (abfd
->flags
& EXEC_P
)
2682 internal_f
.f_flags
|= F_EXEC
;
2684 if (! abfd
->xvec
->byteorder_big_p
)
2685 internal_f
.f_flags
|= F_AR32WR
;
2687 internal_f
.f_flags
|= F_AR32W
;
2689 /* Set up the ``optional'' header. */
2690 if ((abfd
->flags
& D_PAGED
) != 0)
2691 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2693 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2695 /* FIXME: Is this really correct? */
2696 internal_a
.vstamp
= symhdr
->vstamp
;
2698 /* At least on Ultrix, these have to be rounded to page boundaries.
2699 FIXME: Is this true on other platforms? */
2700 if ((abfd
->flags
& D_PAGED
) != 0)
2702 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2703 internal_a
.text_start
= text_start
&~ (round
- 1);
2704 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2705 internal_a
.data_start
= data_start
&~ (round
- 1);
2709 internal_a
.tsize
= text_size
;
2710 internal_a
.text_start
= text_start
;
2711 internal_a
.dsize
= data_size
;
2712 internal_a
.data_start
= data_start
;
2715 /* On Ultrix, the initial portions of the .sbss and .bss segments
2716 are at the end of the data section. The bsize field in the
2717 optional header records how many bss bytes are required beyond
2718 those in the data section. The value is not rounded to a page
2720 if (bss_size
< internal_a
.dsize
- data_size
)
2723 bss_size
-= internal_a
.dsize
- data_size
;
2724 internal_a
.bsize
= bss_size
;
2725 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2727 internal_a
.entry
= bfd_get_start_address (abfd
);
2729 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2731 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2732 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2733 for (i
= 0; i
< 4; i
++)
2734 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2736 /* Write out the file header and the optional header. */
2738 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2741 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2742 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2745 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2746 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2749 /* Build the external symbol information. This must be done before
2750 writing out the relocs so that we know the symbol indices. The
2751 condition checks makes sure this object was not created by
2752 ecoff_bfd_final_link, since if it was we do not want to tamper
2753 with the external symbols. */
2754 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2756 symhdr
->iextMax
= 0;
2757 symhdr
->issExtMax
= 0;
2758 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2759 debug
->ssext
= debug
->ssext_end
= NULL
;
2760 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2761 (((abfd
->flags
& EXEC_P
) == 0)
2763 ecoff_get_extr
, ecoff_set_index
)
2767 /* Write out the relocs. */
2768 for (current
= abfd
->sections
;
2769 current
!= (asection
*) NULL
;
2770 current
= current
->next
)
2772 arelent
**reloc_ptr_ptr
;
2773 arelent
**reloc_end
;
2776 if (current
->reloc_count
== 0)
2780 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2781 if (reloc_buff
== NULL
)
2783 bfd_set_error (bfd_error_no_memory
);
2787 reloc_ptr_ptr
= current
->orelocation
;
2788 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2789 out_ptr
= (char *) reloc_buff
;
2791 reloc_ptr_ptr
< reloc_end
;
2792 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2796 struct internal_reloc in
;
2798 memset ((PTR
) &in
, 0, sizeof in
);
2800 reloc
= *reloc_ptr_ptr
;
2801 sym
= *reloc
->sym_ptr_ptr
;
2803 in
.r_vaddr
= (reloc
->address
2804 + bfd_get_section_vma (abfd
, current
));
2805 in
.r_type
= reloc
->howto
->type
;
2807 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2809 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2816 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2817 if (strcmp (name
, ".text") == 0)
2818 in
.r_symndx
= RELOC_SECTION_TEXT
;
2819 else if (strcmp (name
, ".rdata") == 0)
2820 in
.r_symndx
= RELOC_SECTION_RDATA
;
2821 else if (strcmp (name
, ".data") == 0)
2822 in
.r_symndx
= RELOC_SECTION_DATA
;
2823 else if (strcmp (name
, ".sdata") == 0)
2824 in
.r_symndx
= RELOC_SECTION_SDATA
;
2825 else if (strcmp (name
, ".sbss") == 0)
2826 in
.r_symndx
= RELOC_SECTION_SBSS
;
2827 else if (strcmp (name
, ".bss") == 0)
2828 in
.r_symndx
= RELOC_SECTION_BSS
;
2829 else if (strcmp (name
, ".init") == 0)
2830 in
.r_symndx
= RELOC_SECTION_INIT
;
2831 else if (strcmp (name
, ".lit8") == 0)
2832 in
.r_symndx
= RELOC_SECTION_LIT8
;
2833 else if (strcmp (name
, ".lit4") == 0)
2834 in
.r_symndx
= RELOC_SECTION_LIT4
;
2835 else if (strcmp (name
, ".xdata") == 0)
2836 in
.r_symndx
= RELOC_SECTION_XDATA
;
2837 else if (strcmp (name
, ".pdata") == 0)
2838 in
.r_symndx
= RELOC_SECTION_PDATA
;
2839 else if (strcmp (name
, ".fini") == 0)
2840 in
.r_symndx
= RELOC_SECTION_FINI
;
2841 else if (strcmp (name
, ".lita") == 0)
2842 in
.r_symndx
= RELOC_SECTION_LITA
;
2843 else if (strcmp (name
, "*ABS*") == 0)
2844 in
.r_symndx
= RELOC_SECTION_ABS
;
2850 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2852 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2855 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2857 if (bfd_write (reloc_buff
,
2858 external_reloc_size
, current
->reloc_count
, abfd
)
2859 != external_reloc_size
* current
->reloc_count
)
2861 bfd_release (abfd
, reloc_buff
);
2865 /* Write out the symbolic debugging information. */
2866 if (bfd_get_symcount (abfd
) > 0)
2868 /* Write out the debugging information. */
2869 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2870 ecoff_data (abfd
)->sym_filepos
)
2876 /* The .bss section of a demand paged executable must receive an
2877 entire page. If there are symbols, the symbols will start on the
2878 next page. If there are no symbols, we must fill out the page by
2880 if (bfd_get_symcount (abfd
) == 0
2881 && (abfd
->flags
& EXEC_P
) != 0
2882 && (abfd
->flags
& D_PAGED
) != 0)
2886 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2889 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2891 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2894 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2898 if (reloc_buff
!= NULL
)
2899 bfd_release (abfd
, reloc_buff
);
2904 if (reloc_buff
!= NULL
)
2905 bfd_release (abfd
, reloc_buff
);
2911 /* Archive handling. ECOFF uses what appears to be a unique type of
2912 archive header (armap). The byte ordering of the armap and the
2913 contents are encoded in the name of the armap itself. At least for
2914 now, we only support archives with the same byte ordering in the
2915 armap and the contents.
2917 The first four bytes in the armap are the number of symbol
2918 definitions. This is always a power of two.
2920 This is followed by the symbol definitions. Each symbol definition
2921 occupies 8 bytes. The first four bytes are the offset from the
2922 start of the armap strings to the null-terminated string naming
2923 this symbol. The second four bytes are the file offset to the
2924 archive member which defines this symbol. If the second four bytes
2925 are 0, then this is not actually a symbol definition, and it should
2928 The symbols are hashed into the armap with a closed hashing scheme.
2929 See the functions below for the details of the algorithm.
2931 After the symbol definitions comes four bytes holding the size of
2932 the string table, followed by the string table itself. */
2934 /* The name of an archive headers looks like this:
2935 __________E[BL]E[BL]_ (with a trailing space).
2936 The trailing space is changed to an X if the archive is changed to
2937 indicate that the armap is out of date.
2939 The Alpha seems to use ________64E[BL]E[BL]_. */
2941 #define ARMAP_BIG_ENDIAN 'B'
2942 #define ARMAP_LITTLE_ENDIAN 'L'
2943 #define ARMAP_MARKER 'E'
2944 #define ARMAP_START_LENGTH 10
2945 #define ARMAP_HEADER_MARKER_INDEX 10
2946 #define ARMAP_HEADER_ENDIAN_INDEX 11
2947 #define ARMAP_OBJECT_MARKER_INDEX 12
2948 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2949 #define ARMAP_END_INDEX 14
2950 #define ARMAP_END "_ "
2952 /* This is a magic number used in the hashing algorithm. */
2953 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2955 /* This returns the hash value to use for a string. It also sets
2956 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2957 is the number of entries in the hash table, and HLOG is the log
2961 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2963 unsigned int *rehash
;
2971 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2972 hash
*= ARMAP_HASH_MAGIC
;
2973 *rehash
= (hash
& (size
- 1)) | 1;
2974 return hash
>> (32 - hlog
);
2977 /* Read in the armap. */
2980 ecoff_slurp_armap (abfd
)
2985 struct areltdata
*mapdata
;
2986 bfd_size_type parsed_size
;
2988 struct artdata
*ardata
;
2991 struct symdef
*symdef_ptr
;
2994 /* Get the name of the first element. */
2995 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3001 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3003 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3004 standard COFF armap. We could move the ECOFF armap stuff into
3005 bfd_slurp_armap, but that seems inappropriate since no other
3006 target uses this format. Instead, we check directly for a COFF
3008 if (strncmp (nextname
, "/ ", 16) == 0)
3009 return bfd_slurp_armap (abfd
);
3011 /* See if the first element is an armap. */
3012 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3013 ARMAP_START_LENGTH
) != 0
3014 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3015 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3016 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3017 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3018 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3019 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3020 || strncmp (nextname
+ ARMAP_END_INDEX
,
3021 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3023 bfd_has_map (abfd
) = false;
3027 /* Make sure we have the right byte ordering. */
3028 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3029 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3030 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3031 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3033 bfd_set_error (bfd_error_wrong_format
);
3037 /* Read in the armap. */
3038 ardata
= bfd_ardata (abfd
);
3039 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3040 if (mapdata
== (struct areltdata
*) NULL
)
3042 parsed_size
= mapdata
->parsed_size
;
3043 bfd_release (abfd
, (PTR
) mapdata
);
3045 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3046 if (raw_armap
== (char *) NULL
)
3048 bfd_set_error (bfd_error_no_memory
);
3052 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3054 bfd_set_error (bfd_error_malformed_archive
);
3055 bfd_release (abfd
, (PTR
) raw_armap
);
3059 ardata
->tdata
= (PTR
) raw_armap
;
3061 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3063 ardata
->symdef_count
= 0;
3064 ardata
->cache
= (struct ar_cache
*) NULL
;
3066 /* This code used to overlay the symdefs over the raw archive data,
3067 but that doesn't work on a 64 bit host. */
3069 stringbase
= raw_armap
+ count
* 8 + 8;
3071 #ifdef CHECK_ARMAP_HASH
3075 /* Double check that I have the hashing algorithm right by making
3076 sure that every symbol can be looked up successfully. */
3078 for (i
= 1; i
< count
; i
<<= 1)
3080 BFD_ASSERT (i
== count
);
3082 raw_ptr
= raw_armap
+ 4;
3083 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3085 unsigned int name_offset
, file_offset
;
3086 unsigned int hash
, rehash
, srch
;
3088 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3089 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3090 if (file_offset
== 0)
3092 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3097 /* See if we can rehash to this location. */
3098 for (srch
= (hash
+ rehash
) & (count
- 1);
3099 srch
!= hash
&& srch
!= i
;
3100 srch
= (srch
+ rehash
) & (count
- 1))
3101 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3103 BFD_ASSERT (srch
== i
);
3107 #endif /* CHECK_ARMAP_HASH */
3109 raw_ptr
= raw_armap
+ 4;
3110 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3111 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3112 ++ardata
->symdef_count
;
3114 symdef_ptr
= ((struct symdef
*)
3116 ardata
->symdef_count
* sizeof (struct symdef
)));
3119 bfd_set_error (bfd_error_no_memory
);
3123 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3125 raw_ptr
= raw_armap
+ 4;
3126 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3128 unsigned int name_offset
, file_offset
;
3130 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3131 if (file_offset
== 0)
3133 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3134 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3135 symdef_ptr
->file_offset
= file_offset
;
3139 ardata
->first_file_filepos
= bfd_tell (abfd
);
3140 /* Pad to an even boundary. */
3141 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3143 bfd_has_map (abfd
) = true;
3148 /* Write out an armap. */
3151 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3153 unsigned int elength
;
3155 unsigned int orl_count
;
3158 unsigned int hashsize
, hashlog
;
3159 unsigned int symdefsize
;
3161 unsigned int stringsize
;
3162 unsigned int mapsize
;
3165 struct stat statbuf
;
3168 bfd_byte
*hashtable
;
3172 /* Ultrix appears to use as a hash table size the least power of two
3173 greater than twice the number of entries. */
3174 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3176 hashsize
= 1 << hashlog
;
3178 symdefsize
= hashsize
* 8;
3180 stringsize
= stridx
+ padit
;
3182 /* Include 8 bytes to store symdefsize and stringsize in output. */
3183 mapsize
= symdefsize
+ stringsize
+ 8;
3185 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3187 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3189 /* Work out the ECOFF armap name. */
3190 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3191 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3192 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3193 (abfd
->xvec
->header_byteorder_big_p
3195 : ARMAP_LITTLE_ENDIAN
);
3196 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3197 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3198 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3199 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3201 /* Write the timestamp of the archive header to be just a little bit
3202 later than the timestamp of the file, otherwise the linker will
3203 complain that the index is out of date. Actually, the Ultrix
3204 linker just checks the archive name; the GNU linker may check the
3206 stat (abfd
->filename
, &statbuf
);
3207 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3209 /* The DECstation uses zeroes for the uid, gid and mode of the
3211 hdr
.ar_uid
[0] = '0';
3212 hdr
.ar_gid
[0] = '0';
3213 hdr
.ar_mode
[0] = '0';
3215 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3217 hdr
.ar_fmag
[0] = '`';
3218 hdr
.ar_fmag
[1] = '\012';
3220 /* Turn all null bytes in the header into spaces. */
3221 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3222 if (((char *)(&hdr
))[i
] == '\0')
3223 (((char *)(&hdr
))[i
]) = ' ';
3225 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3226 != sizeof (struct ar_hdr
))
3229 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3230 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3233 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3236 bfd_set_error (bfd_error_no_memory
);
3240 current
= abfd
->archive_head
;
3242 for (i
= 0; i
< orl_count
; i
++)
3244 unsigned int hash
, rehash
;
3246 /* Advance firstreal to the file position of this archive
3248 if (((bfd
*) map
[i
].pos
) != last_elt
)
3252 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3253 firstreal
+= firstreal
% 2;
3254 current
= current
->next
;
3256 while (current
!= (bfd
*) map
[i
].pos
);
3261 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3262 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3266 /* The desired slot is already taken. */
3267 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3269 srch
= (srch
+ rehash
) & (hashsize
- 1))
3270 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3273 BFD_ASSERT (srch
!= hash
);
3278 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3279 (PTR
) (hashtable
+ hash
* 8));
3280 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3281 (PTR
) (hashtable
+ hash
* 8 + 4));
3284 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3287 bfd_release (abfd
, hashtable
);
3289 /* Now write the strings. */
3290 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3291 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3293 for (i
= 0; i
< orl_count
; i
++)
3297 len
= strlen (*map
[i
].name
) + 1;
3298 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3302 /* The spec sez this should be a newline. But in order to be
3303 bug-compatible for DECstation ar we use a null. */
3306 if (bfd_write ("", 1, 1, abfd
) != 1)
3313 /* See whether this BFD is an archive. If it is, read in the armap
3314 and the extended name table. */
3317 ecoff_archive_p (abfd
)
3320 char armag
[SARMAG
+ 1];
3322 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3323 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3325 bfd_set_error (bfd_error_wrong_format
);
3326 return (bfd_target
*) NULL
;
3329 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3330 involves a cast, we can't do it as the left operand of
3332 abfd
->tdata
.aout_ar_data
=
3333 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3335 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3337 bfd_set_error (bfd_error_no_memory
);
3338 return (bfd_target
*) NULL
;
3341 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3342 bfd_ardata (abfd
)->cache
= NULL
;
3343 bfd_ardata (abfd
)->archive_head
= NULL
;
3344 bfd_ardata (abfd
)->symdefs
= NULL
;
3345 bfd_ardata (abfd
)->extended_names
= NULL
;
3346 bfd_ardata (abfd
)->tdata
= NULL
;
3348 if (ecoff_slurp_armap (abfd
) == false
3349 || ecoff_slurp_extended_name_table (abfd
) == false)
3351 bfd_release (abfd
, bfd_ardata (abfd
));
3352 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3353 return (bfd_target
*) NULL
;
3359 /* ECOFF linker code. */
3361 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3362 PARAMS ((struct bfd_hash_entry
*entry
,
3363 struct bfd_hash_table
*table
,
3364 const char *string
));
3365 static boolean ecoff_link_add_archive_symbols
3366 PARAMS ((bfd
*, struct bfd_link_info
*));
3367 static boolean ecoff_link_check_archive_element
3368 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3369 static boolean ecoff_link_add_object_symbols
3370 PARAMS ((bfd
*, struct bfd_link_info
*));
3371 static boolean ecoff_link_add_externals
3372 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3374 /* Routine to create an entry in an ECOFF link hash table. */
3376 static struct bfd_hash_entry
*
3377 ecoff_link_hash_newfunc (entry
, table
, string
)
3378 struct bfd_hash_entry
*entry
;
3379 struct bfd_hash_table
*table
;
3382 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3384 /* Allocate the structure if it has not already been allocated by a
3386 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3387 ret
= ((struct ecoff_link_hash_entry
*)
3388 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3389 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3391 bfd_set_error (bfd_error_no_memory
);
3395 /* Call the allocation method of the superclass. */
3396 ret
= ((struct ecoff_link_hash_entry
*)
3397 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3402 /* Set local fields. */
3406 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3408 return (struct bfd_hash_entry
*) ret
;
3411 /* Create an ECOFF link hash table. */
3413 struct bfd_link_hash_table
*
3414 ecoff_bfd_link_hash_table_create (abfd
)
3417 struct ecoff_link_hash_table
*ret
;
3419 ret
= ((struct ecoff_link_hash_table
*)
3420 malloc (sizeof (struct ecoff_link_hash_table
)));
3423 bfd_set_error (bfd_error_no_memory
);
3426 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3427 ecoff_link_hash_newfunc
))
3430 return (struct bfd_link_hash_table
*) NULL
;
3435 /* Look up an entry in an ECOFF link hash table. */
3437 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3438 ((struct ecoff_link_hash_entry *) \
3439 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3441 /* Traverse an ECOFF link hash table. */
3443 #define ecoff_link_hash_traverse(table, func, info) \
3444 (bfd_link_hash_traverse \
3446 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3449 /* Get the ECOFF link hash table from the info structure. This is
3452 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3454 /* Given an ECOFF BFD, add symbols to the global hash table as
3458 ecoff_bfd_link_add_symbols (abfd
, info
)
3460 struct bfd_link_info
*info
;
3462 switch (bfd_get_format (abfd
))
3465 return ecoff_link_add_object_symbols (abfd
, info
);
3467 return ecoff_link_add_archive_symbols (abfd
, info
);
3469 bfd_set_error (bfd_error_wrong_format
);
3474 /* Add the symbols from an archive file to the global hash table.
3475 This looks through the undefined symbols, looks each one up in the
3476 archive hash table, and adds any associated object file. We do not
3477 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3478 already have a hash table, so there is no reason to construct
3482 ecoff_link_add_archive_symbols (abfd
, info
)
3484 struct bfd_link_info
*info
;
3486 const bfd_byte
*raw_armap
;
3487 struct bfd_link_hash_entry
**pundef
;
3488 unsigned int armap_count
;
3489 unsigned int armap_log
;
3491 const bfd_byte
*hashtable
;
3492 const char *stringbase
;
3494 if (! bfd_has_map (abfd
))
3496 bfd_set_error (bfd_error_no_symbols
);
3500 /* If we don't have any raw data for this archive, as can happen on
3501 Irix 4.0.5F, we call the generic routine.
3502 FIXME: We should be more clever about this, since someday tdata
3503 may get to something for a generic archive. */
3504 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3505 if (raw_armap
== (bfd_byte
*) NULL
)
3506 return (_bfd_generic_link_add_archive_symbols
3507 (abfd
, info
, ecoff_link_check_archive_element
));
3509 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3512 for (i
= 1; i
< armap_count
; i
<<= 1)
3514 BFD_ASSERT (i
== armap_count
);
3516 hashtable
= raw_armap
+ 4;
3517 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3519 /* Look through the list of undefined symbols. */
3520 pundef
= &info
->hash
->undefs
;
3521 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3523 struct bfd_link_hash_entry
*h
;
3524 unsigned int hash
, rehash
;
3525 unsigned int file_offset
;
3531 /* When a symbol is defined, it is not necessarily removed from
3533 if (h
->type
!= bfd_link_hash_undefined
3534 && h
->type
!= bfd_link_hash_common
)
3536 /* Remove this entry from the list, for general cleanliness
3537 and because we are going to look through the list again
3538 if we search any more libraries. We can't remove the
3539 entry if it is the tail, because that would lose any
3540 entries we add to the list later on. */
3541 if (*pundef
!= info
->hash
->undefs_tail
)
3542 *pundef
= (*pundef
)->next
;
3544 pundef
= &(*pundef
)->next
;
3548 /* Native ECOFF linkers do not pull in archive elements merely
3549 to satisfy common definitions, so neither do we. We leave
3550 them on the list, though, in case we are linking against some
3551 other object format. */
3552 if (h
->type
!= bfd_link_hash_undefined
)
3554 pundef
= &(*pundef
)->next
;
3558 /* Look for this symbol in the archive hash table. */
3559 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3562 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3563 if (file_offset
== 0)
3565 /* Nothing in this slot. */
3566 pundef
= &(*pundef
)->next
;
3570 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3571 if (name
[0] != h
->root
.string
[0]
3572 || strcmp (name
, h
->root
.string
) != 0)
3577 /* That was the wrong symbol. Try rehashing. */
3579 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3581 srch
= (srch
+ rehash
) & (armap_count
- 1))
3583 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3584 if (file_offset
== 0)
3586 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3587 if (name
[0] == h
->root
.string
[0]
3588 && strcmp (name
, h
->root
.string
) == 0)
3597 pundef
= &(*pundef
)->next
;
3604 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3605 if (element
== (bfd
*) NULL
)
3608 if (! bfd_check_format (element
, bfd_object
))
3611 /* Unlike the generic linker, we know that this element provides
3612 a definition for an undefined symbol and we know that we want
3613 to include it. We don't need to check anything. */
3614 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3616 if (! ecoff_link_add_object_symbols (element
, info
))
3619 pundef
= &(*pundef
)->next
;
3625 /* This is called if we used _bfd_generic_link_add_archive_symbols
3626 because we were not dealing with an ECOFF archive. */
3629 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3631 struct bfd_link_info
*info
;
3634 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3635 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3636 = backend
->debug_swap
.swap_ext_in
;
3638 bfd_size_type external_ext_size
;
3639 PTR external_ext
= NULL
;
3647 if (! ecoff_slurp_symbolic_header (abfd
))
3650 /* If there are no symbols, we don't want it. */
3651 if (bfd_get_symcount (abfd
) == 0)
3652 goto successful_return
;
3654 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3656 /* Read in the external symbols and external strings. */
3657 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3658 esize
= symhdr
->iextMax
* external_ext_size
;
3659 external_ext
= (PTR
) malloc (esize
);
3660 if (external_ext
== NULL
&& esize
!= 0)
3662 bfd_set_error (bfd_error_no_memory
);
3666 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3667 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3670 ssext
= (char *) malloc (symhdr
->issExtMax
);
3671 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3673 bfd_set_error (bfd_error_no_memory
);
3677 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3678 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3681 /* Look through the external symbols to see if they define some
3682 symbol that is currently undefined. */
3683 ext_ptr
= (char *) external_ext
;
3684 ext_end
= ext_ptr
+ esize
;
3685 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3690 struct bfd_link_hash_entry
*h
;
3692 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3694 /* See if this symbol defines something. */
3695 if (esym
.asym
.st
!= stGlobal
3696 && esym
.asym
.st
!= stLabel
3697 && esym
.asym
.st
!= stProc
)
3700 switch (esym
.asym
.sc
)
3723 name
= ssext
+ esym
.asym
.iss
;
3724 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3726 /* Unlike the generic linker, we do not pull in elements because
3727 of common symbols. */
3728 if (h
== (struct bfd_link_hash_entry
*) NULL
3729 || h
->type
!= bfd_link_hash_undefined
)
3732 /* Include this element. */
3733 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3735 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3739 goto successful_return
;
3743 if (external_ext
!= NULL
)
3744 free (external_ext
);
3749 if (external_ext
!= NULL
)
3750 free (external_ext
);
3756 /* Add symbols from an ECOFF object file to the global linker hash
3760 ecoff_link_add_object_symbols (abfd
, info
)
3762 struct bfd_link_info
*info
;
3765 bfd_size_type external_ext_size
;
3766 PTR external_ext
= NULL
;
3771 if (! ecoff_slurp_symbolic_header (abfd
))
3774 /* If there are no symbols, we don't want it. */
3775 if (bfd_get_symcount (abfd
) == 0)
3778 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3780 /* Read in the external symbols and external strings. */
3781 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3782 esize
= symhdr
->iextMax
* external_ext_size
;
3783 external_ext
= (PTR
) malloc (esize
);
3784 if (external_ext
== NULL
&& esize
!= 0)
3786 bfd_set_error (bfd_error_no_memory
);
3790 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3791 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3794 ssext
= (char *) malloc (symhdr
->issExtMax
);
3795 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3797 bfd_set_error (bfd_error_no_memory
);
3801 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3802 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3805 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3809 if (external_ext
!= NULL
)
3810 free (external_ext
);
3816 if (external_ext
!= NULL
)
3817 free (external_ext
);
3821 /* Add the external symbols of an object file to the global linker
3822 hash table. The external symbols and strings we are passed are
3823 just allocated on the stack, and will be discarded. We must
3824 explicitly save any information we may need later on in the link.
3825 We do not want to read the external symbol information again. */
3828 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3830 struct bfd_link_info
*info
;
3834 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3835 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3836 = backend
->debug_swap
.swap_ext_in
;
3837 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3838 unsigned long ext_count
;
3839 struct ecoff_link_hash_entry
**sym_hash
;
3843 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3845 sym_hash
= ((struct ecoff_link_hash_entry
**)
3847 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3850 bfd_set_error (bfd_error_no_memory
);
3853 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3855 ext_ptr
= (char *) external_ext
;
3856 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3857 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3864 struct ecoff_link_hash_entry
*h
;
3868 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3870 /* Skip debugging symbols. */
3872 switch (esym
.asym
.st
)
3888 /* Get the information for this symbol. */
3889 value
= esym
.asym
.value
;
3890 switch (esym
.asym
.sc
)
3910 section
= bfd_make_section_old_way (abfd
, ".text");
3911 value
-= section
->vma
;
3914 section
= bfd_make_section_old_way (abfd
, ".data");
3915 value
-= section
->vma
;
3918 section
= bfd_make_section_old_way (abfd
, ".bss");
3919 value
-= section
->vma
;
3922 section
= &bfd_abs_section
;
3925 section
= &bfd_und_section
;
3928 section
= bfd_make_section_old_way (abfd
, ".sdata");
3929 value
-= section
->vma
;
3932 section
= bfd_make_section_old_way (abfd
, ".sbss");
3933 value
-= section
->vma
;
3936 section
= bfd_make_section_old_way (abfd
, ".rdata");
3937 value
-= section
->vma
;
3940 if (value
> ecoff_data (abfd
)->gp_size
)
3942 section
= &bfd_com_section
;
3947 if (ecoff_scom_section
.name
== NULL
)
3949 /* Initialize the small common section. */
3950 ecoff_scom_section
.name
= SCOMMON
;
3951 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3952 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3953 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3954 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3955 ecoff_scom_symbol
.name
= SCOMMON
;
3956 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3957 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3958 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3960 section
= &ecoff_scom_section
;
3963 section
= &bfd_und_section
;
3966 section
= bfd_make_section_old_way (abfd
, ".init");
3967 value
-= section
->vma
;
3970 section
= bfd_make_section_old_way (abfd
, ".fini");
3971 value
-= section
->vma
;
3975 if (section
== (asection
*) NULL
)
3978 name
= ssext
+ esym
.asym
.iss
;
3980 if (! (_bfd_generic_link_add_one_symbol
3981 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3982 (const char *) NULL
, true, true,
3983 (struct bfd_link_hash_entry
**) &h
)))
3988 /* If we are building an ECOFF hash table, save the external
3989 symbol information. */
3990 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3992 if (h
->abfd
== (bfd
*) NULL
3993 || (section
!= &bfd_und_section
3994 && (! bfd_is_com_section (section
)
3995 || h
->root
.type
!= bfd_link_hash_defined
)))
4006 /* ECOFF final link routines. */
4008 static boolean ecoff_final_link_debug_accumulate
4009 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4011 static boolean ecoff_link_write_external
4012 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4013 static boolean ecoff_indirect_link_order
4014 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4015 struct bfd_link_order
*));
4016 static boolean ecoff_reloc_link_order
4017 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4018 struct bfd_link_order
*));
4020 /* ECOFF final link routine. This looks through all the input BFDs
4021 and gathers together all the debugging information, and then
4022 processes all the link order information. This may cause it to
4023 close and reopen some input BFDs; I'll see how bad this is. */
4026 ecoff_bfd_final_link (abfd
, info
)
4028 struct bfd_link_info
*info
;
4030 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4031 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4034 register bfd
*input_bfd
;
4036 struct bfd_link_order
*p
;
4038 /* We accumulate the debugging information counts in the symbolic
4040 symhdr
= &debug
->symbolic_header
;
4042 symhdr
->ilineMax
= 0;
4046 symhdr
->isymMax
= 0;
4047 symhdr
->ioptMax
= 0;
4048 symhdr
->iauxMax
= 0;
4050 symhdr
->issExtMax
= 0;
4053 symhdr
->iextMax
= 0;
4055 /* We accumulate the debugging information itself in the debug_info
4058 debug
->external_dnr
= NULL
;
4059 debug
->external_pdr
= NULL
;
4060 debug
->external_sym
= NULL
;
4061 debug
->external_opt
= NULL
;
4062 debug
->external_aux
= NULL
;
4064 debug
->ssext
= debug
->ssext_end
= NULL
;
4065 debug
->external_fdr
= NULL
;
4066 debug
->external_rfd
= NULL
;
4067 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4069 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4070 if (handle
== (PTR
) NULL
)
4073 /* Accumulate the debugging symbols from each input BFD. */
4074 for (input_bfd
= info
->input_bfds
;
4075 input_bfd
!= (bfd
*) NULL
;
4076 input_bfd
= input_bfd
->link_next
)
4080 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4082 /* Abitrarily set the symbolic header vstamp to the vstamp
4083 of the first object file in the link. */
4084 if (symhdr
->vstamp
== 0)
4086 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4087 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4091 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4092 debug
, &backend
->debug_swap
,
4097 /* Combine the register masks. */
4098 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4099 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4100 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4101 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4102 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4103 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4106 /* Write out the external symbols. */
4107 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4108 ecoff_link_write_external
,
4111 if (info
->relocateable
)
4113 /* We need to make a pass over the link_orders to count up the
4114 number of relocations we will need to output, so that we know
4115 how much space they will take up. */
4116 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4119 for (p
= o
->link_order_head
;
4120 p
!= (struct bfd_link_order
*) NULL
;
4122 if (p
->type
== bfd_indirect_link_order
)
4123 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4124 else if (p
->type
== bfd_section_reloc_link_order
4125 || p
->type
== bfd_symbol_reloc_link_order
)
4130 /* Compute the reloc and symbol file positions. */
4131 ecoff_compute_reloc_file_positions (abfd
);
4133 /* Write out the debugging information. */
4134 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4135 &backend
->debug_swap
, info
,
4136 ecoff_data (abfd
)->sym_filepos
))
4139 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4141 if (info
->relocateable
)
4143 /* Now reset the reloc_count field of the sections in the output
4144 BFD to 0, so that we can use them to keep track of how many
4145 relocs we have output thus far. */
4146 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4150 /* Get a value for the GP register. */
4151 if (ecoff_data (abfd
)->gp
== 0)
4153 struct bfd_link_hash_entry
*h
;
4155 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4156 if (h
!= (struct bfd_link_hash_entry
*) NULL
4157 && h
->type
== bfd_link_hash_defined
)
4158 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4159 + h
->u
.def
.section
->output_section
->vma
4160 + h
->u
.def
.section
->output_offset
);
4161 else if (info
->relocateable
)
4165 /* Make up a value. */
4167 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4170 && (strcmp (o
->name
, _SBSS
) == 0
4171 || strcmp (o
->name
, _SDATA
) == 0
4172 || strcmp (o
->name
, _LIT4
) == 0
4173 || strcmp (o
->name
, _LIT8
) == 0
4174 || strcmp (o
->name
, _LITA
) == 0))
4177 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4181 /* If the relocate_section function needs to do a reloc
4182 involving the GP value, it should make a reloc_dangerous
4183 callback to warn that GP is not defined. */
4187 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4189 /* Ignore any link_orders for the .reginfo section, which does
4190 not really exist. */
4191 if (strcmp (o
->name
, REGINFO
) == 0)
4194 for (p
= o
->link_order_head
;
4195 p
!= (struct bfd_link_order
*) NULL
;
4198 if (p
->type
== bfd_indirect_link_order
4199 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4200 == bfd_target_ecoff_flavour
))
4202 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4205 else if (p
->type
== bfd_section_reloc_link_order
4206 || p
->type
== bfd_symbol_reloc_link_order
)
4208 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4213 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4219 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4224 /* Accumulate the debugging information for an input BFD into the
4225 output BFD. This must read in the symbolic information of the
4229 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4232 struct bfd_link_info
*info
;
4235 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4236 const struct ecoff_debug_swap
* const swap
=
4237 &ecoff_backend (input_bfd
)->debug_swap
;
4238 HDRR
*symhdr
= &debug
->symbolic_header
;
4241 #define READ(ptr, offset, count, size, type) \
4242 if (symhdr->count == 0) \
4243 debug->ptr = NULL; \
4246 debug->ptr = (type) malloc (size * symhdr->count); \
4247 if (debug->ptr == NULL) \
4249 bfd_set_error (bfd_error_no_memory); \
4251 goto return_something; \
4253 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4255 || (bfd_read (debug->ptr, size, symhdr->count, \
4256 input_bfd) != size * symhdr->count)) \
4259 goto return_something; \
4263 /* If raw_syments is not NULL, then the data was already by read by
4264 ecoff_slurp_symbolic_info. */
4265 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4267 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4269 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4270 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4271 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4272 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4273 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4275 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4276 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4277 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4281 /* We do not read the external strings or the external symbols. */
4283 ret
= (bfd_ecoff_debug_accumulate
4284 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4285 &ecoff_backend (output_bfd
)->debug_swap
,
4286 input_bfd
, debug
, swap
, info
));
4289 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4291 if (debug
->line
!= NULL
)
4293 if (debug
->external_dnr
!= NULL
)
4294 free (debug
->external_dnr
);
4295 if (debug
->external_pdr
!= NULL
)
4296 free (debug
->external_pdr
);
4297 if (debug
->external_sym
!= NULL
)
4298 free (debug
->external_sym
);
4299 if (debug
->external_opt
!= NULL
)
4300 free (debug
->external_opt
);
4301 if (debug
->external_aux
!= NULL
)
4302 free (debug
->external_aux
);
4303 if (debug
->ss
!= NULL
)
4305 if (debug
->external_fdr
!= NULL
)
4306 free (debug
->external_fdr
);
4307 if (debug
->external_rfd
!= NULL
)
4308 free (debug
->external_rfd
);
4310 /* Make sure we don't accidentally follow one of these pointers
4311 into freed memory. */
4313 debug
->external_dnr
= NULL
;
4314 debug
->external_pdr
= NULL
;
4315 debug
->external_sym
= NULL
;
4316 debug
->external_opt
= NULL
;
4317 debug
->external_aux
= NULL
;
4319 debug
->external_fdr
= NULL
;
4320 debug
->external_rfd
= NULL
;
4326 /* Put out information for an external symbol. These come only from
4330 ecoff_link_write_external (h
, data
)
4331 struct ecoff_link_hash_entry
*h
;
4334 bfd
*output_bfd
= (bfd
*) data
;
4336 /* FIXME: We should check if this symbol is being stripped. */
4338 if (h
->root
.written
)
4341 if (h
->abfd
== (bfd
*) NULL
)
4344 h
->esym
.cobol_main
= 0;
4345 h
->esym
.weakext
= 0;
4346 h
->esym
.reserved
= 0;
4347 h
->esym
.ifd
= ifdNil
;
4348 h
->esym
.asym
.value
= 0;
4349 h
->esym
.asym
.st
= stGlobal
;
4351 if (h
->root
.type
!= bfd_link_hash_defined
)
4352 h
->esym
.asym
.sc
= scAbs
;
4355 asection
*output_section
;
4358 output_section
= h
->root
.u
.def
.section
->output_section
;
4359 name
= bfd_section_name (output_section
->owner
, output_section
);
4361 if (strcmp (name
, _TEXT
) == 0)
4362 h
->esym
.asym
.sc
= scText
;
4363 else if (strcmp (name
, _DATA
) == 0)
4364 h
->esym
.asym
.sc
= scData
;
4365 else if (strcmp (name
, _SDATA
) == 0)
4366 h
->esym
.asym
.sc
= scSData
;
4367 else if (strcmp (name
, _RDATA
) == 0)
4368 h
->esym
.asym
.sc
= scRData
;
4369 else if (strcmp (name
, _BSS
) == 0)
4370 h
->esym
.asym
.sc
= scBss
;
4371 else if (strcmp (name
, _SBSS
) == 0)
4372 h
->esym
.asym
.sc
= scSBss
;
4373 else if (strcmp (name
, _INIT
) == 0)
4374 h
->esym
.asym
.sc
= scInit
;
4375 else if (strcmp (name
, _FINI
) == 0)
4376 h
->esym
.asym
.sc
= scFini
;
4377 else if (strcmp (name
, _PDATA
) == 0)
4378 h
->esym
.asym
.sc
= scPData
;
4379 else if (strcmp (name
, _XDATA
) == 0)
4380 h
->esym
.asym
.sc
= scXData
;
4382 h
->esym
.asym
.sc
= scAbs
;
4385 h
->esym
.asym
.reserved
= 0;
4386 h
->esym
.asym
.index
= indexNil
;
4388 else if (h
->esym
.ifd
!= -1)
4390 struct ecoff_debug_info
*debug
;
4392 /* Adjust the FDR index for the symbol by that used for the
4394 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4395 BFD_ASSERT (h
->esym
.ifd
>= 0
4396 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4397 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4400 switch (h
->root
.type
)
4403 case bfd_link_hash_new
:
4405 case bfd_link_hash_undefined
:
4406 case bfd_link_hash_weak
:
4407 if (h
->esym
.asym
.sc
!= scUndefined
4408 && h
->esym
.asym
.sc
!= scSUndefined
)
4409 h
->esym
.asym
.sc
= scUndefined
;
4411 case bfd_link_hash_defined
:
4412 if (h
->esym
.asym
.sc
== scUndefined
4413 || h
->esym
.asym
.sc
== scSUndefined
)
4414 h
->esym
.asym
.sc
= scAbs
;
4415 else if (h
->esym
.asym
.sc
== scCommon
)
4416 h
->esym
.asym
.sc
= scBss
;
4417 else if (h
->esym
.asym
.sc
== scSCommon
)
4418 h
->esym
.asym
.sc
= scSBss
;
4419 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4420 + h
->root
.u
.def
.section
->output_section
->vma
4421 + h
->root
.u
.def
.section
->output_offset
);
4423 case bfd_link_hash_common
:
4424 if (h
->esym
.asym
.sc
!= scCommon
4425 && h
->esym
.asym
.sc
!= scSCommon
)
4426 h
->esym
.asym
.sc
= scCommon
;
4427 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4429 case bfd_link_hash_indirect
:
4430 case bfd_link_hash_warning
:
4431 /* FIXME: Ignore these for now. The circumstances under which
4432 they should be written out are not clear to me. */
4436 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4438 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4439 h
->root
.written
= true;
4441 return (bfd_ecoff_debug_one_external
4442 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4443 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4447 /* Relocate and write an ECOFF section into an ECOFF output file. */
4450 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4452 struct bfd_link_info
*info
;
4453 asection
*output_section
;
4454 struct bfd_link_order
*link_order
;
4456 asection
*input_section
;
4458 struct ecoff_section_tdata
*section_tdata
;
4459 bfd_size_type raw_size
;
4460 bfd_size_type cooked_size
;
4461 bfd_byte
*contents
= NULL
;
4462 bfd_size_type external_reloc_size
;
4463 bfd_size_type external_relocs_size
;
4464 PTR external_relocs
= NULL
;
4466 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4468 if (link_order
->size
== 0)
4471 input_section
= link_order
->u
.indirect
.section
;
4472 input_bfd
= input_section
->owner
;
4473 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4475 raw_size
= input_section
->_raw_size
;
4476 cooked_size
= input_section
->_cooked_size
;
4477 if (cooked_size
== 0)
4478 cooked_size
= raw_size
;
4480 BFD_ASSERT (input_section
->output_section
== output_section
);
4481 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4482 BFD_ASSERT (cooked_size
== link_order
->size
);
4484 /* Get the section contents. We allocate memory for the larger of
4485 the size before relocating and the size after relocating. */
4486 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4489 if (contents
== NULL
&& raw_size
!= 0)
4491 bfd_set_error (bfd_error_no_memory
);
4495 /* If we are relaxing, the contents may have already been read into
4496 memory, in which case we copy them into our new buffer. We don't
4497 simply reuse the old buffer in case cooked_size > raw_size. */
4498 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4499 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4500 memcpy (contents
, section_tdata
->contents
, raw_size
);
4503 if (! bfd_get_section_contents (input_bfd
, input_section
,
4505 (file_ptr
) 0, raw_size
))
4509 /* Get the relocs. If we are relaxing MIPS code, they will already
4510 have been read in. Otherwise, we read them in now. */
4511 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4512 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4514 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4515 external_relocs
= section_tdata
->external_relocs
;
4518 external_relocs
= (PTR
) malloc (external_relocs_size
);
4519 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4521 bfd_set_error (bfd_error_no_memory
);
4525 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4526 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4527 != external_relocs_size
))
4531 /* Relocate the section contents. */
4532 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4533 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4537 /* Write out the relocated section. */
4538 if (! bfd_set_section_contents (output_bfd
,
4541 input_section
->output_offset
,
4545 /* If we are producing relocateable output, the relocs were
4546 modified, and we write them out now. We use the reloc_count
4547 field of output_section to keep track of the number of relocs we
4548 have output so far. */
4549 if (info
->relocateable
)
4551 if (bfd_seek (output_bfd
,
4552 (output_section
->rel_filepos
+
4553 output_section
->reloc_count
* external_reloc_size
),
4555 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4556 != external_relocs_size
))
4558 output_section
->reloc_count
+= input_section
->reloc_count
;
4561 if (contents
!= NULL
)
4563 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4564 free (external_relocs
);
4568 if (contents
!= NULL
)
4570 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4571 free (external_relocs
);
4575 /* Generate a reloc when linking an ECOFF file. This is a reloc
4576 requested by the linker, and does come from any input file. This
4577 is used to build constructor and destructor tables when linking
4581 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4583 struct bfd_link_info
*info
;
4584 asection
*output_section
;
4585 struct bfd_link_order
*link_order
;
4588 struct internal_reloc in
;
4589 bfd_size_type external_reloc_size
;
4593 /* We set up an arelent to pass to the backend adjust_reloc_out
4595 rel
.address
= link_order
->offset
;
4597 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4598 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4600 bfd_set_error (bfd_error_bad_value
);
4604 if (link_order
->type
== bfd_section_reloc_link_order
)
4605 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4608 /* We can't set up a reloc against a symbol correctly, because
4609 we have no asymbol structure. Currently no adjust_reloc_out
4611 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4614 /* All ECOFF relocs are in-place. Put the addend into the object
4617 BFD_ASSERT (rel
.howto
->partial_inplace
);
4618 if (link_order
->u
.reloc
.p
->addend
!= 0)
4621 bfd_reloc_status_type rstat
;
4625 size
= bfd_get_reloc_size (rel
.howto
);
4626 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4627 if (buf
== (bfd_byte
*) NULL
)
4629 bfd_set_error (bfd_error_no_memory
);
4632 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4633 link_order
->u
.reloc
.p
->addend
, buf
);
4639 case bfd_reloc_outofrange
:
4641 case bfd_reloc_overflow
:
4642 if (! ((*info
->callbacks
->reloc_overflow
)
4644 (link_order
->type
== bfd_section_reloc_link_order
4645 ? bfd_section_name (output_bfd
,
4646 link_order
->u
.reloc
.p
->u
.section
)
4647 : link_order
->u
.reloc
.p
->u
.name
),
4648 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4649 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4656 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4657 (file_ptr
) link_order
->offset
, size
);
4665 /* Move the information into a internal_reloc structure. */
4666 in
.r_vaddr
= (rel
.address
4667 + bfd_get_section_vma (output_bfd
, output_section
));
4668 in
.r_type
= rel
.howto
->type
;
4670 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4672 struct ecoff_link_hash_entry
*h
;
4674 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4675 link_order
->u
.reloc
.p
->u
.name
,
4676 false, false, true);
4677 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4679 in
.r_symndx
= h
->indx
;
4682 if (! ((*info
->callbacks
->unattached_reloc
)
4683 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4684 (asection
*) NULL
, (bfd_vma
) 0)))
4694 name
= bfd_get_section_name (output_bfd
,
4695 link_order
->u
.reloc
.p
->u
.section
);
4696 if (strcmp (name
, ".text") == 0)
4697 in
.r_symndx
= RELOC_SECTION_TEXT
;
4698 else if (strcmp (name
, ".rdata") == 0)
4699 in
.r_symndx
= RELOC_SECTION_RDATA
;
4700 else if (strcmp (name
, ".data") == 0)
4701 in
.r_symndx
= RELOC_SECTION_DATA
;
4702 else if (strcmp (name
, ".sdata") == 0)
4703 in
.r_symndx
= RELOC_SECTION_SDATA
;
4704 else if (strcmp (name
, ".sbss") == 0)
4705 in
.r_symndx
= RELOC_SECTION_SBSS
;
4706 else if (strcmp (name
, ".bss") == 0)
4707 in
.r_symndx
= RELOC_SECTION_BSS
;
4708 else if (strcmp (name
, ".init") == 0)
4709 in
.r_symndx
= RELOC_SECTION_INIT
;
4710 else if (strcmp (name
, ".lit8") == 0)
4711 in
.r_symndx
= RELOC_SECTION_LIT8
;
4712 else if (strcmp (name
, ".lit4") == 0)
4713 in
.r_symndx
= RELOC_SECTION_LIT4
;
4714 else if (strcmp (name
, ".xdata") == 0)
4715 in
.r_symndx
= RELOC_SECTION_XDATA
;
4716 else if (strcmp (name
, ".pdata") == 0)
4717 in
.r_symndx
= RELOC_SECTION_PDATA
;
4718 else if (strcmp (name
, ".fini") == 0)
4719 in
.r_symndx
= RELOC_SECTION_FINI
;
4720 else if (strcmp (name
, ".lita") == 0)
4721 in
.r_symndx
= RELOC_SECTION_LITA
;
4722 else if (strcmp (name
, "*ABS*") == 0)
4723 in
.r_symndx
= RELOC_SECTION_ABS
;
4729 /* Let the BFD backend adjust the reloc. */
4730 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4732 /* Get some memory and swap out the reloc. */
4733 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4734 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4735 if (rbuf
== (bfd_byte
*) NULL
)
4737 bfd_set_error (bfd_error_no_memory
);
4741 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4743 ok
= (bfd_seek (output_bfd
,
4744 (output_section
->rel_filepos
+
4745 output_section
->reloc_count
* external_reloc_size
),
4747 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4748 == external_reloc_size
));
4751 ++output_section
->reloc_count
;