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 bfd_size_type data_size
;
2497 bfd_size_type bss_size
;
2499 PTR reloc_buff
= NULL
;
2500 struct internal_filehdr internal_f
;
2501 struct internal_aouthdr internal_a
;
2504 /* Determine where the sections and relocs will go in the output
2506 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2509 for (current
= abfd
->sections
;
2510 current
!= (asection
*)NULL
;
2511 current
= current
->next
)
2513 if (strcmp (current
->name
, REGINFO
) == 0)
2515 current
->target_index
= count
;
2519 if ((abfd
->flags
& D_PAGED
) != 0)
2520 text_size
= ecoff_sizeof_headers (abfd
, false);
2528 /* Write section headers to the file. */
2530 /* Allocate buff big enough to hold a section header,
2531 file header, or a.out header. */
2539 buff
= (PTR
) malloc (siz
);
2542 bfd_set_error (bfd_error_no_memory
);
2547 internal_f
.f_nscns
= 0;
2548 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2550 for (current
= abfd
->sections
;
2551 current
!= (asection
*) NULL
;
2552 current
= current
->next
)
2554 struct internal_scnhdr section
;
2557 if (strcmp (current
->name
, REGINFO
) == 0)
2559 BFD_ASSERT (current
->reloc_count
== 0);
2563 ++internal_f
.f_nscns
;
2565 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2567 /* FIXME: is this correct for shared libraries? I think it is
2568 but I have no platform to check. Ian Lance Taylor. */
2569 vma
= bfd_get_section_vma (abfd
, current
);
2570 if (strcmp (current
->name
, _LIB
) == 0)
2571 section
.s_vaddr
= 0;
2573 section
.s_vaddr
= vma
;
2575 section
.s_paddr
= vma
;
2576 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2578 /* If this section is unloadable then the scnptr will be 0. */
2579 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2580 section
.s_scnptr
= 0;
2582 section
.s_scnptr
= current
->filepos
;
2583 section
.s_relptr
= current
->rel_filepos
;
2585 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2586 object file produced by the assembler is supposed to point to
2587 information about how much room is required by objects of
2588 various different sizes. I think this only matters if we
2589 want the linker to compute the best size to use, or
2590 something. I don't know what happens if the information is
2592 if (strcmp (current
->name
, _PDATA
) != 0)
2593 section
.s_lnnoptr
= 0;
2596 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2597 hold the number of entries in the section (each entry is
2598 8 bytes). We stored this in the line_filepos field in
2599 ecoff_compute_section_file_positions. */
2600 section
.s_lnnoptr
= current
->line_filepos
;
2603 section
.s_nreloc
= current
->reloc_count
;
2604 section
.s_nlnno
= 0;
2605 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2608 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2609 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2612 if ((section
.s_flags
& STYP_TEXT
) != 0
2613 || ((section
.s_flags
& STYP_RDATA
) != 0
2614 && backend
->rdata_in_text
)
2615 || strcmp (current
->name
, _PDATA
) == 0)
2617 text_size
+= bfd_get_section_size_before_reloc (current
);
2618 if (text_start
== 0 || text_start
> vma
)
2621 else if ((section
.s_flags
& STYP_RDATA
) != 0
2622 || (section
.s_flags
& STYP_DATA
) != 0
2623 || (section
.s_flags
& STYP_LITA
) != 0
2624 || (section
.s_flags
& STYP_LIT8
) != 0
2625 || (section
.s_flags
& STYP_LIT4
) != 0
2626 || (section
.s_flags
& STYP_SDATA
) != 0
2627 || strcmp (current
->name
, _XDATA
) == 0)
2629 data_size
+= bfd_get_section_size_before_reloc (current
);
2630 if (data_start
== 0 || data_start
> vma
)
2633 else if ((section
.s_flags
& STYP_BSS
) != 0
2634 || (section
.s_flags
& STYP_SBSS
) != 0)
2635 bss_size
+= bfd_get_section_size_before_reloc (current
);
2640 /* Set up the file header. */
2642 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2644 /* We will NOT put a fucking timestamp in the header here. Every
2645 time you put it back, I will come in and take it out again. I'm
2646 sorry. This field does not belong here. We fill it with a 0 so
2647 it compares the same but is not a reasonable time. --
2649 internal_f
.f_timdat
= 0;
2651 if (bfd_get_symcount (abfd
) != 0)
2653 /* The ECOFF f_nsyms field is not actually the number of
2654 symbols, it's the size of symbolic information header. */
2655 internal_f
.f_nsyms
= external_hdr_size
;
2656 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2660 internal_f
.f_nsyms
= 0;
2661 internal_f
.f_symptr
= 0;
2664 internal_f
.f_opthdr
= aoutsz
;
2666 internal_f
.f_flags
= F_LNNO
;
2667 if (reloc_size
== 0)
2668 internal_f
.f_flags
|= F_RELFLG
;
2669 if (bfd_get_symcount (abfd
) == 0)
2670 internal_f
.f_flags
|= F_LSYMS
;
2671 if (abfd
->flags
& EXEC_P
)
2672 internal_f
.f_flags
|= F_EXEC
;
2674 if (! abfd
->xvec
->byteorder_big_p
)
2675 internal_f
.f_flags
|= F_AR32WR
;
2677 internal_f
.f_flags
|= F_AR32W
;
2679 /* Set up the ``optional'' header. */
2680 if ((abfd
->flags
& D_PAGED
) != 0)
2681 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2683 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2685 /* FIXME: Is this really correct? */
2686 internal_a
.vstamp
= symhdr
->vstamp
;
2688 /* At least on Ultrix, these have to be rounded to page boundaries.
2689 FIXME: Is this true on other platforms? */
2690 if ((abfd
->flags
& D_PAGED
) != 0)
2692 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2693 internal_a
.text_start
= text_start
&~ (round
- 1);
2694 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2695 internal_a
.data_start
= data_start
&~ (round
- 1);
2699 internal_a
.tsize
= text_size
;
2700 internal_a
.text_start
= text_start
;
2701 internal_a
.dsize
= data_size
;
2702 internal_a
.data_start
= data_start
;
2705 /* On Ultrix, the initial portions of the .sbss and .bss segments
2706 are at the end of the data section. The bsize field in the
2707 optional header records how many bss bytes are required beyond
2708 those in the data section. The value is not rounded to a page
2710 if (bss_size
< internal_a
.dsize
- data_size
)
2713 bss_size
-= internal_a
.dsize
- data_size
;
2714 internal_a
.bsize
= bss_size
;
2715 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2717 internal_a
.entry
= bfd_get_start_address (abfd
);
2719 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2721 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2722 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2723 for (i
= 0; i
< 4; i
++)
2724 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2726 /* Write out the file header and the optional header. */
2728 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2731 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2732 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2735 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2736 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2739 /* Build the external symbol information. This must be done before
2740 writing out the relocs so that we know the symbol indices. The
2741 condition checks makes sure this object was not created by
2742 ecoff_bfd_final_link, since if it was we do not want to tamper
2743 with the external symbols. */
2744 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2746 symhdr
->iextMax
= 0;
2747 symhdr
->issExtMax
= 0;
2748 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2749 debug
->ssext
= debug
->ssext_end
= NULL
;
2750 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2751 (((abfd
->flags
& EXEC_P
) == 0)
2753 ecoff_get_extr
, ecoff_set_index
)
2757 /* Write out the relocs. */
2758 for (current
= abfd
->sections
;
2759 current
!= (asection
*) NULL
;
2760 current
= current
->next
)
2762 arelent
**reloc_ptr_ptr
;
2763 arelent
**reloc_end
;
2766 if (current
->reloc_count
== 0)
2770 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2771 if (reloc_buff
== NULL
)
2773 bfd_set_error (bfd_error_no_memory
);
2777 reloc_ptr_ptr
= current
->orelocation
;
2778 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2779 out_ptr
= (char *) reloc_buff
;
2781 reloc_ptr_ptr
< reloc_end
;
2782 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2786 struct internal_reloc in
;
2788 memset ((PTR
) &in
, 0, sizeof in
);
2790 reloc
= *reloc_ptr_ptr
;
2791 sym
= *reloc
->sym_ptr_ptr
;
2793 in
.r_vaddr
= (reloc
->address
2794 + bfd_get_section_vma (abfd
, current
));
2795 in
.r_type
= reloc
->howto
->type
;
2797 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2799 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2806 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2807 if (strcmp (name
, ".text") == 0)
2808 in
.r_symndx
= RELOC_SECTION_TEXT
;
2809 else if (strcmp (name
, ".rdata") == 0)
2810 in
.r_symndx
= RELOC_SECTION_RDATA
;
2811 else if (strcmp (name
, ".data") == 0)
2812 in
.r_symndx
= RELOC_SECTION_DATA
;
2813 else if (strcmp (name
, ".sdata") == 0)
2814 in
.r_symndx
= RELOC_SECTION_SDATA
;
2815 else if (strcmp (name
, ".sbss") == 0)
2816 in
.r_symndx
= RELOC_SECTION_SBSS
;
2817 else if (strcmp (name
, ".bss") == 0)
2818 in
.r_symndx
= RELOC_SECTION_BSS
;
2819 else if (strcmp (name
, ".init") == 0)
2820 in
.r_symndx
= RELOC_SECTION_INIT
;
2821 else if (strcmp (name
, ".lit8") == 0)
2822 in
.r_symndx
= RELOC_SECTION_LIT8
;
2823 else if (strcmp (name
, ".lit4") == 0)
2824 in
.r_symndx
= RELOC_SECTION_LIT4
;
2825 else if (strcmp (name
, ".xdata") == 0)
2826 in
.r_symndx
= RELOC_SECTION_XDATA
;
2827 else if (strcmp (name
, ".pdata") == 0)
2828 in
.r_symndx
= RELOC_SECTION_PDATA
;
2829 else if (strcmp (name
, ".fini") == 0)
2830 in
.r_symndx
= RELOC_SECTION_FINI
;
2831 else if (strcmp (name
, ".lita") == 0)
2832 in
.r_symndx
= RELOC_SECTION_LITA
;
2833 else if (strcmp (name
, "*ABS*") == 0)
2834 in
.r_symndx
= RELOC_SECTION_ABS
;
2840 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2842 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2845 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2847 if (bfd_write (reloc_buff
,
2848 external_reloc_size
, current
->reloc_count
, abfd
)
2849 != external_reloc_size
* current
->reloc_count
)
2851 bfd_release (abfd
, reloc_buff
);
2855 /* Write out the symbolic debugging information. */
2856 if (bfd_get_symcount (abfd
) > 0)
2858 /* Write out the debugging information. */
2859 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2860 ecoff_data (abfd
)->sym_filepos
)
2866 /* The .bss section of a demand paged executable must receive an
2867 entire page. If there are symbols, the symbols will start on the
2868 next page. If there are no symbols, we must fill out the page by
2870 if (bfd_get_symcount (abfd
) == 0
2871 && (abfd
->flags
& EXEC_P
) != 0
2872 && (abfd
->flags
& D_PAGED
) != 0)
2876 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2879 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2881 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2884 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2888 if (reloc_buff
!= NULL
)
2889 bfd_release (abfd
, reloc_buff
);
2894 if (reloc_buff
!= NULL
)
2895 bfd_release (abfd
, reloc_buff
);
2901 /* Archive handling. ECOFF uses what appears to be a unique type of
2902 archive header (armap). The byte ordering of the armap and the
2903 contents are encoded in the name of the armap itself. At least for
2904 now, we only support archives with the same byte ordering in the
2905 armap and the contents.
2907 The first four bytes in the armap are the number of symbol
2908 definitions. This is always a power of two.
2910 This is followed by the symbol definitions. Each symbol definition
2911 occupies 8 bytes. The first four bytes are the offset from the
2912 start of the armap strings to the null-terminated string naming
2913 this symbol. The second four bytes are the file offset to the
2914 archive member which defines this symbol. If the second four bytes
2915 are 0, then this is not actually a symbol definition, and it should
2918 The symbols are hashed into the armap with a closed hashing scheme.
2919 See the functions below for the details of the algorithm.
2921 After the symbol definitions comes four bytes holding the size of
2922 the string table, followed by the string table itself. */
2924 /* The name of an archive headers looks like this:
2925 __________E[BL]E[BL]_ (with a trailing space).
2926 The trailing space is changed to an X if the archive is changed to
2927 indicate that the armap is out of date.
2929 The Alpha seems to use ________64E[BL]E[BL]_. */
2931 #define ARMAP_BIG_ENDIAN 'B'
2932 #define ARMAP_LITTLE_ENDIAN 'L'
2933 #define ARMAP_MARKER 'E'
2934 #define ARMAP_START_LENGTH 10
2935 #define ARMAP_HEADER_MARKER_INDEX 10
2936 #define ARMAP_HEADER_ENDIAN_INDEX 11
2937 #define ARMAP_OBJECT_MARKER_INDEX 12
2938 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2939 #define ARMAP_END_INDEX 14
2940 #define ARMAP_END "_ "
2942 /* This is a magic number used in the hashing algorithm. */
2943 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2945 /* This returns the hash value to use for a string. It also sets
2946 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2947 is the number of entries in the hash table, and HLOG is the log
2951 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2953 unsigned int *rehash
;
2961 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2962 hash
*= ARMAP_HASH_MAGIC
;
2963 *rehash
= (hash
& (size
- 1)) | 1;
2964 return hash
>> (32 - hlog
);
2967 /* Read in the armap. */
2970 ecoff_slurp_armap (abfd
)
2975 struct areltdata
*mapdata
;
2976 bfd_size_type parsed_size
;
2978 struct artdata
*ardata
;
2981 struct symdef
*symdef_ptr
;
2984 /* Get the name of the first element. */
2985 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2991 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2993 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2994 standard COFF armap. We could move the ECOFF armap stuff into
2995 bfd_slurp_armap, but that seems inappropriate since no other
2996 target uses this format. Instead, we check directly for a COFF
2998 if (strncmp (nextname
, "/ ", 16) == 0)
2999 return bfd_slurp_armap (abfd
);
3001 /* See if the first element is an armap. */
3002 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3003 ARMAP_START_LENGTH
) != 0
3004 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3005 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3006 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3007 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3008 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3009 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3010 || strncmp (nextname
+ ARMAP_END_INDEX
,
3011 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3013 bfd_has_map (abfd
) = false;
3017 /* Make sure we have the right byte ordering. */
3018 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3019 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3020 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3021 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3023 bfd_set_error (bfd_error_wrong_format
);
3027 /* Read in the armap. */
3028 ardata
= bfd_ardata (abfd
);
3029 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3030 if (mapdata
== (struct areltdata
*) NULL
)
3032 parsed_size
= mapdata
->parsed_size
;
3033 bfd_release (abfd
, (PTR
) mapdata
);
3035 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3036 if (raw_armap
== (char *) NULL
)
3038 bfd_set_error (bfd_error_no_memory
);
3042 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3044 bfd_set_error (bfd_error_malformed_archive
);
3045 bfd_release (abfd
, (PTR
) raw_armap
);
3049 ardata
->tdata
= (PTR
) raw_armap
;
3051 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3053 ardata
->symdef_count
= 0;
3054 ardata
->cache
= (struct ar_cache
*) NULL
;
3056 /* This code used to overlay the symdefs over the raw archive data,
3057 but that doesn't work on a 64 bit host. */
3059 stringbase
= raw_armap
+ count
* 8 + 8;
3061 #ifdef CHECK_ARMAP_HASH
3065 /* Double check that I have the hashing algorithm right by making
3066 sure that every symbol can be looked up successfully. */
3068 for (i
= 1; i
< count
; i
<<= 1)
3070 BFD_ASSERT (i
== count
);
3072 raw_ptr
= raw_armap
+ 4;
3073 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3075 unsigned int name_offset
, file_offset
;
3076 unsigned int hash
, rehash
, srch
;
3078 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3079 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3080 if (file_offset
== 0)
3082 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3087 /* See if we can rehash to this location. */
3088 for (srch
= (hash
+ rehash
) & (count
- 1);
3089 srch
!= hash
&& srch
!= i
;
3090 srch
= (srch
+ rehash
) & (count
- 1))
3091 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3093 BFD_ASSERT (srch
== i
);
3097 #endif /* CHECK_ARMAP_HASH */
3099 raw_ptr
= raw_armap
+ 4;
3100 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3101 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3102 ++ardata
->symdef_count
;
3104 symdef_ptr
= ((struct symdef
*)
3106 ardata
->symdef_count
* sizeof (struct symdef
)));
3109 bfd_set_error (bfd_error_no_memory
);
3113 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3115 raw_ptr
= raw_armap
+ 4;
3116 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3118 unsigned int name_offset
, file_offset
;
3120 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3121 if (file_offset
== 0)
3123 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3124 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3125 symdef_ptr
->file_offset
= file_offset
;
3129 ardata
->first_file_filepos
= bfd_tell (abfd
);
3130 /* Pad to an even boundary. */
3131 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3133 bfd_has_map (abfd
) = true;
3138 /* Write out an armap. */
3141 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3143 unsigned int elength
;
3145 unsigned int orl_count
;
3148 unsigned int hashsize
, hashlog
;
3149 unsigned int symdefsize
;
3151 unsigned int stringsize
;
3152 unsigned int mapsize
;
3155 struct stat statbuf
;
3158 bfd_byte
*hashtable
;
3162 /* Ultrix appears to use as a hash table size the least power of two
3163 greater than twice the number of entries. */
3164 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3166 hashsize
= 1 << hashlog
;
3168 symdefsize
= hashsize
* 8;
3170 stringsize
= stridx
+ padit
;
3172 /* Include 8 bytes to store symdefsize and stringsize in output. */
3173 mapsize
= symdefsize
+ stringsize
+ 8;
3175 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3177 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3179 /* Work out the ECOFF armap name. */
3180 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3181 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3182 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3183 (abfd
->xvec
->header_byteorder_big_p
3185 : ARMAP_LITTLE_ENDIAN
);
3186 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3187 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3188 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3189 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3191 /* Write the timestamp of the archive header to be just a little bit
3192 later than the timestamp of the file, otherwise the linker will
3193 complain that the index is out of date. Actually, the Ultrix
3194 linker just checks the archive name; the GNU linker may check the
3196 stat (abfd
->filename
, &statbuf
);
3197 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3199 /* The DECstation uses zeroes for the uid, gid and mode of the
3201 hdr
.ar_uid
[0] = '0';
3202 hdr
.ar_gid
[0] = '0';
3203 hdr
.ar_mode
[0] = '0';
3205 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3207 hdr
.ar_fmag
[0] = '`';
3208 hdr
.ar_fmag
[1] = '\012';
3210 /* Turn all null bytes in the header into spaces. */
3211 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3212 if (((char *)(&hdr
))[i
] == '\0')
3213 (((char *)(&hdr
))[i
]) = ' ';
3215 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3216 != sizeof (struct ar_hdr
))
3219 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3220 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3223 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3226 bfd_set_error (bfd_error_no_memory
);
3230 current
= abfd
->archive_head
;
3232 for (i
= 0; i
< orl_count
; i
++)
3234 unsigned int hash
, rehash
;
3236 /* Advance firstreal to the file position of this archive
3238 if (((bfd
*) map
[i
].pos
) != last_elt
)
3242 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3243 firstreal
+= firstreal
% 2;
3244 current
= current
->next
;
3246 while (current
!= (bfd
*) map
[i
].pos
);
3251 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3252 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3256 /* The desired slot is already taken. */
3257 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3259 srch
= (srch
+ rehash
) & (hashsize
- 1))
3260 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3263 BFD_ASSERT (srch
!= hash
);
3268 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3269 (PTR
) (hashtable
+ hash
* 8));
3270 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3271 (PTR
) (hashtable
+ hash
* 8 + 4));
3274 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3277 bfd_release (abfd
, hashtable
);
3279 /* Now write the strings. */
3280 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3281 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3283 for (i
= 0; i
< orl_count
; i
++)
3287 len
= strlen (*map
[i
].name
) + 1;
3288 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3292 /* The spec sez this should be a newline. But in order to be
3293 bug-compatible for DECstation ar we use a null. */
3296 if (bfd_write ("", 1, 1, abfd
) != 1)
3303 /* See whether this BFD is an archive. If it is, read in the armap
3304 and the extended name table. */
3307 ecoff_archive_p (abfd
)
3310 char armag
[SARMAG
+ 1];
3312 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3313 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3315 bfd_set_error (bfd_error_wrong_format
);
3316 return (bfd_target
*) NULL
;
3319 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3320 involves a cast, we can't do it as the left operand of
3322 abfd
->tdata
.aout_ar_data
=
3323 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3325 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3327 bfd_set_error (bfd_error_no_memory
);
3328 return (bfd_target
*) NULL
;
3331 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3332 bfd_ardata (abfd
)->cache
= NULL
;
3333 bfd_ardata (abfd
)->archive_head
= NULL
;
3334 bfd_ardata (abfd
)->symdefs
= NULL
;
3335 bfd_ardata (abfd
)->extended_names
= NULL
;
3336 bfd_ardata (abfd
)->tdata
= NULL
;
3338 if (ecoff_slurp_armap (abfd
) == false
3339 || ecoff_slurp_extended_name_table (abfd
) == false)
3341 bfd_release (abfd
, bfd_ardata (abfd
));
3342 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3343 return (bfd_target
*) NULL
;
3349 /* ECOFF linker code. */
3351 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3352 PARAMS ((struct bfd_hash_entry
*entry
,
3353 struct bfd_hash_table
*table
,
3354 const char *string
));
3355 static boolean ecoff_link_add_archive_symbols
3356 PARAMS ((bfd
*, struct bfd_link_info
*));
3357 static boolean ecoff_link_check_archive_element
3358 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3359 static boolean ecoff_link_add_object_symbols
3360 PARAMS ((bfd
*, struct bfd_link_info
*));
3361 static boolean ecoff_link_add_externals
3362 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3364 /* Routine to create an entry in an ECOFF link hash table. */
3366 static struct bfd_hash_entry
*
3367 ecoff_link_hash_newfunc (entry
, table
, string
)
3368 struct bfd_hash_entry
*entry
;
3369 struct bfd_hash_table
*table
;
3372 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3374 /* Allocate the structure if it has not already been allocated by a
3376 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3377 ret
= ((struct ecoff_link_hash_entry
*)
3378 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3379 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3381 bfd_set_error (bfd_error_no_memory
);
3385 /* Call the allocation method of the superclass. */
3386 ret
= ((struct ecoff_link_hash_entry
*)
3387 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3392 /* Set local fields. */
3396 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3398 return (struct bfd_hash_entry
*) ret
;
3401 /* Create an ECOFF link hash table. */
3403 struct bfd_link_hash_table
*
3404 ecoff_bfd_link_hash_table_create (abfd
)
3407 struct ecoff_link_hash_table
*ret
;
3409 ret
= ((struct ecoff_link_hash_table
*)
3410 malloc (sizeof (struct ecoff_link_hash_table
)));
3413 bfd_set_error (bfd_error_no_memory
);
3416 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3417 ecoff_link_hash_newfunc
))
3420 return (struct bfd_link_hash_table
*) NULL
;
3425 /* Look up an entry in an ECOFF link hash table. */
3427 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3428 ((struct ecoff_link_hash_entry *) \
3429 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3431 /* Traverse an ECOFF link hash table. */
3433 #define ecoff_link_hash_traverse(table, func, info) \
3434 (bfd_link_hash_traverse \
3436 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3439 /* Get the ECOFF link hash table from the info structure. This is
3442 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3444 /* Given an ECOFF BFD, add symbols to the global hash table as
3448 ecoff_bfd_link_add_symbols (abfd
, info
)
3450 struct bfd_link_info
*info
;
3452 switch (bfd_get_format (abfd
))
3455 return ecoff_link_add_object_symbols (abfd
, info
);
3457 return ecoff_link_add_archive_symbols (abfd
, info
);
3459 bfd_set_error (bfd_error_wrong_format
);
3464 /* Add the symbols from an archive file to the global hash table.
3465 This looks through the undefined symbols, looks each one up in the
3466 archive hash table, and adds any associated object file. We do not
3467 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3468 already have a hash table, so there is no reason to construct
3472 ecoff_link_add_archive_symbols (abfd
, info
)
3474 struct bfd_link_info
*info
;
3476 const bfd_byte
*raw_armap
;
3477 struct bfd_link_hash_entry
**pundef
;
3478 unsigned int armap_count
;
3479 unsigned int armap_log
;
3481 const bfd_byte
*hashtable
;
3482 const char *stringbase
;
3484 if (! bfd_has_map (abfd
))
3486 bfd_set_error (bfd_error_no_symbols
);
3490 /* If we don't have any raw data for this archive, as can happen on
3491 Irix 4.0.5F, we call the generic routine.
3492 FIXME: We should be more clever about this, since someday tdata
3493 may get to something for a generic archive. */
3494 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3495 if (raw_armap
== (bfd_byte
*) NULL
)
3496 return (_bfd_generic_link_add_archive_symbols
3497 (abfd
, info
, ecoff_link_check_archive_element
));
3499 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3502 for (i
= 1; i
< armap_count
; i
<<= 1)
3504 BFD_ASSERT (i
== armap_count
);
3506 hashtable
= raw_armap
+ 4;
3507 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3509 /* Look through the list of undefined symbols. */
3510 pundef
= &info
->hash
->undefs
;
3511 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3513 struct bfd_link_hash_entry
*h
;
3514 unsigned int hash
, rehash
;
3515 unsigned int file_offset
;
3521 /* When a symbol is defined, it is not necessarily removed from
3523 if (h
->type
!= bfd_link_hash_undefined
3524 && h
->type
!= bfd_link_hash_common
)
3526 /* Remove this entry from the list, for general cleanliness
3527 and because we are going to look through the list again
3528 if we search any more libraries. We can't remove the
3529 entry if it is the tail, because that would lose any
3530 entries we add to the list later on. */
3531 if (*pundef
!= info
->hash
->undefs_tail
)
3532 *pundef
= (*pundef
)->next
;
3534 pundef
= &(*pundef
)->next
;
3538 /* Native ECOFF linkers do not pull in archive elements merely
3539 to satisfy common definitions, so neither do we. We leave
3540 them on the list, though, in case we are linking against some
3541 other object format. */
3542 if (h
->type
!= bfd_link_hash_undefined
)
3544 pundef
= &(*pundef
)->next
;
3548 /* Look for this symbol in the archive hash table. */
3549 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3552 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3553 if (file_offset
== 0)
3555 /* Nothing in this slot. */
3556 pundef
= &(*pundef
)->next
;
3560 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3561 if (name
[0] != h
->root
.string
[0]
3562 || strcmp (name
, h
->root
.string
) != 0)
3567 /* That was the wrong symbol. Try rehashing. */
3569 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3571 srch
= (srch
+ rehash
) & (armap_count
- 1))
3573 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3574 if (file_offset
== 0)
3576 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3577 if (name
[0] == h
->root
.string
[0]
3578 && strcmp (name
, h
->root
.string
) == 0)
3587 pundef
= &(*pundef
)->next
;
3594 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3595 if (element
== (bfd
*) NULL
)
3598 if (! bfd_check_format (element
, bfd_object
))
3601 /* Unlike the generic linker, we know that this element provides
3602 a definition for an undefined symbol and we know that we want
3603 to include it. We don't need to check anything. */
3604 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3606 if (! ecoff_link_add_object_symbols (element
, info
))
3609 pundef
= &(*pundef
)->next
;
3615 /* This is called if we used _bfd_generic_link_add_archive_symbols
3616 because we were not dealing with an ECOFF archive. */
3619 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3621 struct bfd_link_info
*info
;
3624 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3625 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3626 = backend
->debug_swap
.swap_ext_in
;
3628 bfd_size_type external_ext_size
;
3629 PTR external_ext
= NULL
;
3637 if (! ecoff_slurp_symbolic_header (abfd
))
3640 /* If there are no symbols, we don't want it. */
3641 if (bfd_get_symcount (abfd
) == 0)
3642 goto successful_return
;
3644 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3646 /* Read in the external symbols and external strings. */
3647 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3648 esize
= symhdr
->iextMax
* external_ext_size
;
3649 external_ext
= (PTR
) malloc (esize
);
3650 if (external_ext
== NULL
&& esize
!= 0)
3652 bfd_set_error (bfd_error_no_memory
);
3656 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3657 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3660 ssext
= (char *) malloc (symhdr
->issExtMax
);
3661 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3663 bfd_set_error (bfd_error_no_memory
);
3667 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3668 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3671 /* Look through the external symbols to see if they define some
3672 symbol that is currently undefined. */
3673 ext_ptr
= (char *) external_ext
;
3674 ext_end
= ext_ptr
+ esize
;
3675 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3680 struct bfd_link_hash_entry
*h
;
3682 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3684 /* See if this symbol defines something. */
3685 if (esym
.asym
.st
!= stGlobal
3686 && esym
.asym
.st
!= stLabel
3687 && esym
.asym
.st
!= stProc
)
3690 switch (esym
.asym
.sc
)
3713 name
= ssext
+ esym
.asym
.iss
;
3714 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3716 /* Unlike the generic linker, we do not pull in elements because
3717 of common symbols. */
3718 if (h
== (struct bfd_link_hash_entry
*) NULL
3719 || h
->type
!= bfd_link_hash_undefined
)
3722 /* Include this element. */
3723 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3725 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3729 goto successful_return
;
3733 if (external_ext
!= NULL
)
3734 free (external_ext
);
3739 if (external_ext
!= NULL
)
3740 free (external_ext
);
3746 /* Add symbols from an ECOFF object file to the global linker hash
3750 ecoff_link_add_object_symbols (abfd
, info
)
3752 struct bfd_link_info
*info
;
3755 bfd_size_type external_ext_size
;
3756 PTR external_ext
= NULL
;
3761 if (! ecoff_slurp_symbolic_header (abfd
))
3764 /* If there are no symbols, we don't want it. */
3765 if (bfd_get_symcount (abfd
) == 0)
3768 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3770 /* Read in the external symbols and external strings. */
3771 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3772 esize
= symhdr
->iextMax
* external_ext_size
;
3773 external_ext
= (PTR
) malloc (esize
);
3774 if (external_ext
== NULL
&& esize
!= 0)
3776 bfd_set_error (bfd_error_no_memory
);
3780 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3781 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3784 ssext
= (char *) malloc (symhdr
->issExtMax
);
3785 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3787 bfd_set_error (bfd_error_no_memory
);
3791 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3792 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3795 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3799 if (external_ext
!= NULL
)
3800 free (external_ext
);
3806 if (external_ext
!= NULL
)
3807 free (external_ext
);
3811 /* Add the external symbols of an object file to the global linker
3812 hash table. The external symbols and strings we are passed are
3813 just allocated on the stack, and will be discarded. We must
3814 explicitly save any information we may need later on in the link.
3815 We do not want to read the external symbol information again. */
3818 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3820 struct bfd_link_info
*info
;
3824 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3825 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3826 = backend
->debug_swap
.swap_ext_in
;
3827 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3828 unsigned long ext_count
;
3829 struct ecoff_link_hash_entry
**sym_hash
;
3833 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3835 sym_hash
= ((struct ecoff_link_hash_entry
**)
3837 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3840 bfd_set_error (bfd_error_no_memory
);
3843 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3845 ext_ptr
= (char *) external_ext
;
3846 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3847 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3854 struct ecoff_link_hash_entry
*h
;
3858 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3860 /* Skip debugging symbols. */
3862 switch (esym
.asym
.st
)
3878 /* Get the information for this symbol. */
3879 value
= esym
.asym
.value
;
3880 switch (esym
.asym
.sc
)
3900 section
= bfd_make_section_old_way (abfd
, ".text");
3901 value
-= section
->vma
;
3904 section
= bfd_make_section_old_way (abfd
, ".data");
3905 value
-= section
->vma
;
3908 section
= bfd_make_section_old_way (abfd
, ".bss");
3909 value
-= section
->vma
;
3912 section
= &bfd_abs_section
;
3915 section
= &bfd_und_section
;
3918 section
= bfd_make_section_old_way (abfd
, ".sdata");
3919 value
-= section
->vma
;
3922 section
= bfd_make_section_old_way (abfd
, ".sbss");
3923 value
-= section
->vma
;
3926 section
= bfd_make_section_old_way (abfd
, ".rdata");
3927 value
-= section
->vma
;
3930 if (value
> ecoff_data (abfd
)->gp_size
)
3932 section
= &bfd_com_section
;
3937 if (ecoff_scom_section
.name
== NULL
)
3939 /* Initialize the small common section. */
3940 ecoff_scom_section
.name
= SCOMMON
;
3941 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3942 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3943 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3944 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3945 ecoff_scom_symbol
.name
= SCOMMON
;
3946 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3947 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3948 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3950 section
= &ecoff_scom_section
;
3953 section
= &bfd_und_section
;
3956 section
= bfd_make_section_old_way (abfd
, ".init");
3957 value
-= section
->vma
;
3960 section
= bfd_make_section_old_way (abfd
, ".fini");
3961 value
-= section
->vma
;
3965 if (section
== (asection
*) NULL
)
3968 name
= ssext
+ esym
.asym
.iss
;
3970 if (! (_bfd_generic_link_add_one_symbol
3971 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3972 (const char *) NULL
, true, true,
3973 (struct bfd_link_hash_entry
**) &h
)))
3978 /* If we are building an ECOFF hash table, save the external
3979 symbol information. */
3980 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3982 if (h
->abfd
== (bfd
*) NULL
3983 || (section
!= &bfd_und_section
3984 && (! bfd_is_com_section (section
)
3985 || h
->root
.type
!= bfd_link_hash_defined
)))
3996 /* ECOFF final link routines. */
3998 static boolean ecoff_final_link_debug_accumulate
3999 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4001 static boolean ecoff_link_write_external
4002 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4003 static boolean ecoff_indirect_link_order
4004 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4005 struct bfd_link_order
*));
4006 static boolean ecoff_reloc_link_order
4007 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4008 struct bfd_link_order
*));
4010 /* ECOFF final link routine. This looks through all the input BFDs
4011 and gathers together all the debugging information, and then
4012 processes all the link order information. This may cause it to
4013 close and reopen some input BFDs; I'll see how bad this is. */
4016 ecoff_bfd_final_link (abfd
, info
)
4018 struct bfd_link_info
*info
;
4020 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4021 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4024 register bfd
*input_bfd
;
4026 struct bfd_link_order
*p
;
4028 /* We accumulate the debugging information counts in the symbolic
4030 symhdr
= &debug
->symbolic_header
;
4032 symhdr
->ilineMax
= 0;
4036 symhdr
->isymMax
= 0;
4037 symhdr
->ioptMax
= 0;
4038 symhdr
->iauxMax
= 0;
4040 symhdr
->issExtMax
= 0;
4043 symhdr
->iextMax
= 0;
4045 /* We accumulate the debugging information itself in the debug_info
4048 debug
->external_dnr
= NULL
;
4049 debug
->external_pdr
= NULL
;
4050 debug
->external_sym
= NULL
;
4051 debug
->external_opt
= NULL
;
4052 debug
->external_aux
= NULL
;
4054 debug
->ssext
= debug
->ssext_end
= NULL
;
4055 debug
->external_fdr
= NULL
;
4056 debug
->external_rfd
= NULL
;
4057 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4059 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4060 if (handle
== (PTR
) NULL
)
4063 /* Accumulate the debugging symbols from each input BFD. */
4064 for (input_bfd
= info
->input_bfds
;
4065 input_bfd
!= (bfd
*) NULL
;
4066 input_bfd
= input_bfd
->link_next
)
4070 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4072 /* Abitrarily set the symbolic header vstamp to the vstamp
4073 of the first object file in the link. */
4074 if (symhdr
->vstamp
== 0)
4076 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4077 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4081 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4082 debug
, &backend
->debug_swap
,
4087 /* Combine the register masks. */
4088 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4089 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4090 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4091 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4092 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4093 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4096 /* Write out the external symbols. */
4097 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4098 ecoff_link_write_external
,
4101 if (info
->relocateable
)
4103 /* We need to make a pass over the link_orders to count up the
4104 number of relocations we will need to output, so that we know
4105 how much space they will take up. */
4106 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4109 for (p
= o
->link_order_head
;
4110 p
!= (struct bfd_link_order
*) NULL
;
4112 if (p
->type
== bfd_indirect_link_order
)
4113 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4114 else if (p
->type
== bfd_section_reloc_link_order
4115 || p
->type
== bfd_symbol_reloc_link_order
)
4120 /* Compute the reloc and symbol file positions. */
4121 ecoff_compute_reloc_file_positions (abfd
);
4123 /* Write out the debugging information. */
4124 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4125 &backend
->debug_swap
, info
,
4126 ecoff_data (abfd
)->sym_filepos
))
4129 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4131 if (info
->relocateable
)
4133 /* Now reset the reloc_count field of the sections in the output
4134 BFD to 0, so that we can use them to keep track of how many
4135 relocs we have output thus far. */
4136 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4140 /* Get a value for the GP register. */
4141 if (ecoff_data (abfd
)->gp
== 0)
4143 struct bfd_link_hash_entry
*h
;
4145 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4146 if (h
!= (struct bfd_link_hash_entry
*) NULL
4147 && h
->type
== bfd_link_hash_defined
)
4148 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4149 + h
->u
.def
.section
->output_section
->vma
4150 + h
->u
.def
.section
->output_offset
);
4151 else if (info
->relocateable
)
4155 /* Make up a value. */
4157 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4160 && (strcmp (o
->name
, _SBSS
) == 0
4161 || strcmp (o
->name
, _SDATA
) == 0
4162 || strcmp (o
->name
, _LIT4
) == 0
4163 || strcmp (o
->name
, _LIT8
) == 0
4164 || strcmp (o
->name
, _LITA
) == 0))
4167 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4171 /* If the relocate_section function needs to do a reloc
4172 involving the GP value, it should make a reloc_dangerous
4173 callback to warn that GP is not defined. */
4177 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4179 /* Ignore any link_orders for the .reginfo section, which does
4180 not really exist. */
4181 if (strcmp (o
->name
, REGINFO
) == 0)
4184 for (p
= o
->link_order_head
;
4185 p
!= (struct bfd_link_order
*) NULL
;
4188 if (p
->type
== bfd_indirect_link_order
4189 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4190 == bfd_target_ecoff_flavour
))
4192 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4195 else if (p
->type
== bfd_section_reloc_link_order
4196 || p
->type
== bfd_symbol_reloc_link_order
)
4198 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4203 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4209 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4214 /* Accumulate the debugging information for an input BFD into the
4215 output BFD. This must read in the symbolic information of the
4219 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4222 struct bfd_link_info
*info
;
4225 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4226 const struct ecoff_debug_swap
* const swap
=
4227 &ecoff_backend (input_bfd
)->debug_swap
;
4228 HDRR
*symhdr
= &debug
->symbolic_header
;
4231 #define READ(ptr, offset, count, size, type) \
4232 if (symhdr->count == 0) \
4233 debug->ptr = NULL; \
4236 debug->ptr = (type) malloc (size * symhdr->count); \
4237 if (debug->ptr == NULL) \
4239 bfd_set_error (bfd_error_no_memory); \
4241 goto return_something; \
4243 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4245 || (bfd_read (debug->ptr, size, symhdr->count, \
4246 input_bfd) != size * symhdr->count)) \
4249 goto return_something; \
4253 /* If raw_syments is not NULL, then the data was already by read by
4254 ecoff_slurp_symbolic_info. */
4255 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4257 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4259 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4260 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4261 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4262 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4263 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4265 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4266 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4267 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4271 /* We do not read the external strings or the external symbols. */
4273 ret
= (bfd_ecoff_debug_accumulate
4274 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4275 &ecoff_backend (output_bfd
)->debug_swap
,
4276 input_bfd
, debug
, swap
, info
));
4279 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4281 if (debug
->line
!= NULL
)
4283 if (debug
->external_dnr
!= NULL
)
4284 free (debug
->external_dnr
);
4285 if (debug
->external_pdr
!= NULL
)
4286 free (debug
->external_pdr
);
4287 if (debug
->external_sym
!= NULL
)
4288 free (debug
->external_sym
);
4289 if (debug
->external_opt
!= NULL
)
4290 free (debug
->external_opt
);
4291 if (debug
->external_aux
!= NULL
)
4292 free (debug
->external_aux
);
4293 if (debug
->ss
!= NULL
)
4295 if (debug
->external_fdr
!= NULL
)
4296 free (debug
->external_fdr
);
4297 if (debug
->external_rfd
!= NULL
)
4298 free (debug
->external_rfd
);
4300 /* Make sure we don't accidentally follow one of these pointers
4301 into freed memory. */
4303 debug
->external_dnr
= NULL
;
4304 debug
->external_pdr
= NULL
;
4305 debug
->external_sym
= NULL
;
4306 debug
->external_opt
= NULL
;
4307 debug
->external_aux
= NULL
;
4309 debug
->external_fdr
= NULL
;
4310 debug
->external_rfd
= NULL
;
4316 /* Put out information for an external symbol. These come only from
4320 ecoff_link_write_external (h
, data
)
4321 struct ecoff_link_hash_entry
*h
;
4324 bfd
*output_bfd
= (bfd
*) data
;
4326 /* FIXME: We should check if this symbol is being stripped. */
4328 if (h
->root
.written
)
4331 if (h
->abfd
== (bfd
*) NULL
)
4334 h
->esym
.cobol_main
= 0;
4335 h
->esym
.weakext
= 0;
4336 h
->esym
.reserved
= 0;
4337 h
->esym
.ifd
= ifdNil
;
4338 h
->esym
.asym
.value
= 0;
4339 h
->esym
.asym
.st
= stGlobal
;
4341 if (h
->root
.type
!= bfd_link_hash_defined
)
4342 h
->esym
.asym
.sc
= scAbs
;
4345 asection
*output_section
;
4348 output_section
= h
->root
.u
.def
.section
->output_section
;
4349 name
= bfd_section_name (output_section
->owner
, output_section
);
4351 if (strcmp (name
, _TEXT
) == 0)
4352 h
->esym
.asym
.sc
= scText
;
4353 else if (strcmp (name
, _DATA
) == 0)
4354 h
->esym
.asym
.sc
= scData
;
4355 else if (strcmp (name
, _SDATA
) == 0)
4356 h
->esym
.asym
.sc
= scSData
;
4357 else if (strcmp (name
, _RDATA
) == 0)
4358 h
->esym
.asym
.sc
= scRData
;
4359 else if (strcmp (name
, _BSS
) == 0)
4360 h
->esym
.asym
.sc
= scBss
;
4361 else if (strcmp (name
, _SBSS
) == 0)
4362 h
->esym
.asym
.sc
= scSBss
;
4363 else if (strcmp (name
, _INIT
) == 0)
4364 h
->esym
.asym
.sc
= scInit
;
4365 else if (strcmp (name
, _FINI
) == 0)
4366 h
->esym
.asym
.sc
= scFini
;
4367 else if (strcmp (name
, _PDATA
) == 0)
4368 h
->esym
.asym
.sc
= scPData
;
4369 else if (strcmp (name
, _XDATA
) == 0)
4370 h
->esym
.asym
.sc
= scXData
;
4372 h
->esym
.asym
.sc
= scAbs
;
4375 h
->esym
.asym
.reserved
= 0;
4376 h
->esym
.asym
.index
= indexNil
;
4378 else if (h
->esym
.ifd
!= -1)
4380 struct ecoff_debug_info
*debug
;
4382 /* Adjust the FDR index for the symbol by that used for the
4384 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4385 BFD_ASSERT (h
->esym
.ifd
>= 0
4386 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4387 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4390 switch (h
->root
.type
)
4393 case bfd_link_hash_new
:
4395 case bfd_link_hash_undefined
:
4396 case bfd_link_hash_weak
:
4397 if (h
->esym
.asym
.sc
!= scUndefined
4398 && h
->esym
.asym
.sc
!= scSUndefined
)
4399 h
->esym
.asym
.sc
= scUndefined
;
4401 case bfd_link_hash_defined
:
4402 if (h
->esym
.asym
.sc
== scUndefined
4403 || h
->esym
.asym
.sc
== scSUndefined
)
4404 h
->esym
.asym
.sc
= scAbs
;
4405 else if (h
->esym
.asym
.sc
== scCommon
)
4406 h
->esym
.asym
.sc
= scBss
;
4407 else if (h
->esym
.asym
.sc
== scSCommon
)
4408 h
->esym
.asym
.sc
= scSBss
;
4409 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4410 + h
->root
.u
.def
.section
->output_section
->vma
4411 + h
->root
.u
.def
.section
->output_offset
);
4413 case bfd_link_hash_common
:
4414 if (h
->esym
.asym
.sc
!= scCommon
4415 && h
->esym
.asym
.sc
!= scSCommon
)
4416 h
->esym
.asym
.sc
= scCommon
;
4417 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4419 case bfd_link_hash_indirect
:
4420 case bfd_link_hash_warning
:
4421 /* FIXME: Ignore these for now. The circumstances under which
4422 they should be written out are not clear to me. */
4426 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4428 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4429 h
->root
.written
= true;
4431 return (bfd_ecoff_debug_one_external
4432 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4433 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4437 /* Relocate and write an ECOFF section into an ECOFF output file. */
4440 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4442 struct bfd_link_info
*info
;
4443 asection
*output_section
;
4444 struct bfd_link_order
*link_order
;
4446 asection
*input_section
;
4448 struct ecoff_section_tdata
*section_tdata
;
4449 bfd_size_type raw_size
;
4450 bfd_size_type cooked_size
;
4451 bfd_byte
*contents
= NULL
;
4452 bfd_size_type external_reloc_size
;
4453 bfd_size_type external_relocs_size
;
4454 PTR external_relocs
= NULL
;
4456 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4458 if (link_order
->size
== 0)
4461 input_section
= link_order
->u
.indirect
.section
;
4462 input_bfd
= input_section
->owner
;
4463 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4465 raw_size
= input_section
->_raw_size
;
4466 cooked_size
= input_section
->_cooked_size
;
4467 if (cooked_size
== 0)
4468 cooked_size
= raw_size
;
4470 BFD_ASSERT (input_section
->output_section
== output_section
);
4471 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4472 BFD_ASSERT (cooked_size
== link_order
->size
);
4474 /* Get the section contents. We allocate memory for the larger of
4475 the size before relocating and the size after relocating. */
4476 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4479 if (contents
== NULL
&& raw_size
!= 0)
4481 bfd_set_error (bfd_error_no_memory
);
4485 /* If we are relaxing, the contents may have already been read into
4486 memory, in which case we copy them into our new buffer. We don't
4487 simply reuse the old buffer in case cooked_size > raw_size. */
4488 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4489 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4490 memcpy (contents
, section_tdata
->contents
, raw_size
);
4493 if (! bfd_get_section_contents (input_bfd
, input_section
,
4495 (file_ptr
) 0, raw_size
))
4499 /* Get the relocs. If we are relaxing MIPS code, they will already
4500 have been read in. Otherwise, we read them in now. */
4501 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4502 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4504 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4505 external_relocs
= section_tdata
->external_relocs
;
4508 external_relocs
= (PTR
) malloc (external_relocs_size
);
4509 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4511 bfd_set_error (bfd_error_no_memory
);
4515 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4516 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4517 != external_relocs_size
))
4521 /* Relocate the section contents. */
4522 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4523 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4527 /* Write out the relocated section. */
4528 if (! bfd_set_section_contents (output_bfd
,
4531 input_section
->output_offset
,
4535 /* If we are producing relocateable output, the relocs were
4536 modified, and we write them out now. We use the reloc_count
4537 field of output_section to keep track of the number of relocs we
4538 have output so far. */
4539 if (info
->relocateable
)
4541 if (bfd_seek (output_bfd
,
4542 (output_section
->rel_filepos
+
4543 output_section
->reloc_count
* external_reloc_size
),
4545 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4546 != external_relocs_size
))
4548 output_section
->reloc_count
+= input_section
->reloc_count
;
4551 if (contents
!= NULL
)
4553 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4554 free (external_relocs
);
4558 if (contents
!= NULL
)
4560 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4561 free (external_relocs
);
4565 /* Generate a reloc when linking an ECOFF file. This is a reloc
4566 requested by the linker, and does come from any input file. This
4567 is used to build constructor and destructor tables when linking
4571 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4573 struct bfd_link_info
*info
;
4574 asection
*output_section
;
4575 struct bfd_link_order
*link_order
;
4578 struct internal_reloc in
;
4579 bfd_size_type external_reloc_size
;
4583 /* We set up an arelent to pass to the backend adjust_reloc_out
4585 rel
.address
= link_order
->offset
;
4587 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4588 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4590 bfd_set_error (bfd_error_bad_value
);
4594 if (link_order
->type
== bfd_section_reloc_link_order
)
4595 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4598 /* We can't set up a reloc against a symbol correctly, because
4599 we have no asymbol structure. Currently no adjust_reloc_out
4601 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4604 /* All ECOFF relocs are in-place. Put the addend into the object
4607 BFD_ASSERT (rel
.howto
->partial_inplace
);
4608 if (link_order
->u
.reloc
.p
->addend
!= 0)
4611 bfd_reloc_status_type rstat
;
4615 size
= bfd_get_reloc_size (rel
.howto
);
4616 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4617 if (buf
== (bfd_byte
*) NULL
)
4619 bfd_set_error (bfd_error_no_memory
);
4622 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4623 link_order
->u
.reloc
.p
->addend
, buf
);
4629 case bfd_reloc_outofrange
:
4631 case bfd_reloc_overflow
:
4632 if (! ((*info
->callbacks
->reloc_overflow
)
4634 (link_order
->type
== bfd_section_reloc_link_order
4635 ? bfd_section_name (output_bfd
,
4636 link_order
->u
.reloc
.p
->u
.section
)
4637 : link_order
->u
.reloc
.p
->u
.name
),
4638 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4639 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4646 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4647 (file_ptr
) link_order
->offset
, size
);
4655 /* Move the information into a internal_reloc structure. */
4656 in
.r_vaddr
= (rel
.address
4657 + bfd_get_section_vma (output_bfd
, output_section
));
4658 in
.r_type
= rel
.howto
->type
;
4660 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4662 struct ecoff_link_hash_entry
*h
;
4664 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4665 link_order
->u
.reloc
.p
->u
.name
,
4666 false, false, true);
4667 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4669 in
.r_symndx
= h
->indx
;
4672 if (! ((*info
->callbacks
->unattached_reloc
)
4673 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4674 (asection
*) NULL
, (bfd_vma
) 0)))
4684 name
= bfd_get_section_name (output_bfd
,
4685 link_order
->u
.reloc
.p
->u
.section
);
4686 if (strcmp (name
, ".text") == 0)
4687 in
.r_symndx
= RELOC_SECTION_TEXT
;
4688 else if (strcmp (name
, ".rdata") == 0)
4689 in
.r_symndx
= RELOC_SECTION_RDATA
;
4690 else if (strcmp (name
, ".data") == 0)
4691 in
.r_symndx
= RELOC_SECTION_DATA
;
4692 else if (strcmp (name
, ".sdata") == 0)
4693 in
.r_symndx
= RELOC_SECTION_SDATA
;
4694 else if (strcmp (name
, ".sbss") == 0)
4695 in
.r_symndx
= RELOC_SECTION_SBSS
;
4696 else if (strcmp (name
, ".bss") == 0)
4697 in
.r_symndx
= RELOC_SECTION_BSS
;
4698 else if (strcmp (name
, ".init") == 0)
4699 in
.r_symndx
= RELOC_SECTION_INIT
;
4700 else if (strcmp (name
, ".lit8") == 0)
4701 in
.r_symndx
= RELOC_SECTION_LIT8
;
4702 else if (strcmp (name
, ".lit4") == 0)
4703 in
.r_symndx
= RELOC_SECTION_LIT4
;
4704 else if (strcmp (name
, ".xdata") == 0)
4705 in
.r_symndx
= RELOC_SECTION_XDATA
;
4706 else if (strcmp (name
, ".pdata") == 0)
4707 in
.r_symndx
= RELOC_SECTION_PDATA
;
4708 else if (strcmp (name
, ".fini") == 0)
4709 in
.r_symndx
= RELOC_SECTION_FINI
;
4710 else if (strcmp (name
, ".lita") == 0)
4711 in
.r_symndx
= RELOC_SECTION_LITA
;
4712 else if (strcmp (name
, "*ABS*") == 0)
4713 in
.r_symndx
= RELOC_SECTION_ABS
;
4719 /* Let the BFD backend adjust the reloc. */
4720 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4722 /* Get some memory and swap out the reloc. */
4723 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4724 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4725 if (rbuf
== (bfd_byte
*) NULL
)
4727 bfd_set_error (bfd_error_no_memory
);
4731 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4733 ok
= (bfd_seek (output_bfd
,
4734 (output_section
->rel_filepos
+
4735 output_section
->reloc_count
* external_reloc_size
),
4737 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4738 == external_reloc_size
));
4741 ++output_section
->reloc_count
;