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
, _LIB
) == 0)
183 /* An Irix 4 shared libary. */
184 section
->flags
|= SEC_SHARED_LIBRARY
;
186 else if (strcmp (section
->name
, REGINFO
) == 0)
188 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
189 section completely alone. */
190 section
->flags
|= (SEC_SHARED_LIBRARY
193 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
196 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
197 uncertain about .init on some systems and I don't know how shared
203 /* Determine the machine architecture and type. This is called from
204 the generic COFF routines. It is the inverse of ecoff_get_magic,
205 below. This could be an ECOFF backend routine, with one version
206 for each target, but there aren't all that many ECOFF targets. */
209 ecoff_set_arch_mach_hook (abfd
, filehdr
)
213 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
214 enum bfd_architecture arch
;
217 switch (internal_f
->f_magic
)
220 case MIPS_MAGIC_LITTLE
:
222 arch
= bfd_arch_mips
;
226 case MIPS_MAGIC_LITTLE2
:
227 case MIPS_MAGIC_BIG2
:
228 /* MIPS ISA level 2: the r6000 */
229 arch
= bfd_arch_mips
;
233 case MIPS_MAGIC_LITTLE3
:
234 case MIPS_MAGIC_BIG3
:
235 /* MIPS ISA level 3: the r4000 */
236 arch
= bfd_arch_mips
;
241 arch
= bfd_arch_alpha
;
246 arch
= bfd_arch_obscure
;
251 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
254 /* Get the magic number to use based on the architecture and machine.
255 This is the inverse of ecoff_set_arch_mach_hook, above. */
258 ecoff_get_magic (abfd
)
263 switch (bfd_get_arch (abfd
))
266 switch (bfd_get_mach (abfd
))
271 big
= MIPS_MAGIC_BIG
;
272 little
= MIPS_MAGIC_LITTLE
;
276 big
= MIPS_MAGIC_BIG2
;
277 little
= MIPS_MAGIC_LITTLE2
;
281 big
= MIPS_MAGIC_BIG3
;
282 little
= MIPS_MAGIC_LITTLE3
;
286 return abfd
->xvec
->byteorder_big_p
? big
: little
;
297 /* Get the section s_flags to use for a section. */
300 ecoff_sec_to_styp_flags (name
, flags
)
308 if (strcmp (name
, _TEXT
) == 0)
310 else if (strcmp (name
, _DATA
) == 0)
312 else if (strcmp (name
, _SDATA
) == 0)
314 else if (strcmp (name
, _RDATA
) == 0)
316 else if (strcmp (name
, _LITA
) == 0)
318 else if (strcmp (name
, _LIT8
) == 0)
320 else if (strcmp (name
, _LIT4
) == 0)
322 else if (strcmp (name
, _BSS
) == 0)
324 else if (strcmp (name
, _SBSS
) == 0)
326 else if (strcmp (name
, _INIT
) == 0)
327 styp
= STYP_ECOFF_INIT
;
328 else if (strcmp (name
, _FINI
) == 0)
329 styp
= STYP_ECOFF_FINI
;
330 else if (strcmp (name
, _PDATA
) == 0)
332 else if (strcmp (name
, _XDATA
) == 0)
334 else if (strcmp (name
, _LIB
) == 0)
335 styp
= STYP_ECOFF_LIB
;
336 else if (flags
& SEC_CODE
)
338 else if (flags
& SEC_DATA
)
340 else if (flags
& SEC_READONLY
)
342 else if (flags
& SEC_LOAD
)
347 if (flags
& SEC_NEVER_LOAD
)
353 /* Get the BFD flags to use for a section. */
357 ecoff_styp_to_sec_flags (abfd
, hdr
)
361 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
362 long styp_flags
= internal_s
->s_flags
;
363 flagword sec_flags
=0;
365 if (styp_flags
& STYP_NOLOAD
)
366 sec_flags
|= SEC_NEVER_LOAD
;
368 /* For 386 COFF, at least, an unloadable text or data section is
369 actually a shared library section. */
370 if ((styp_flags
& STYP_TEXT
)
371 || (styp_flags
& STYP_ECOFF_INIT
)
372 || (styp_flags
& STYP_ECOFF_FINI
))
374 if (sec_flags
& SEC_NEVER_LOAD
)
375 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
377 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
379 else if ((styp_flags
& STYP_DATA
)
380 || (styp_flags
& STYP_RDATA
)
381 || (styp_flags
& STYP_SDATA
)
382 || styp_flags
== STYP_PDATA
383 || styp_flags
== STYP_XDATA
)
385 if (sec_flags
& SEC_NEVER_LOAD
)
386 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
388 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
389 if ((styp_flags
& STYP_RDATA
)
390 || styp_flags
== STYP_PDATA
)
391 sec_flags
|= SEC_READONLY
;
393 else if ((styp_flags
& STYP_BSS
)
394 || (styp_flags
& STYP_SBSS
))
396 sec_flags
|= SEC_ALLOC
;
398 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
400 sec_flags
|= SEC_NEVER_LOAD
;
402 else if ((styp_flags
& STYP_LITA
)
403 || (styp_flags
& STYP_LIT8
)
404 || (styp_flags
& STYP_LIT4
))
406 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
408 else if (styp_flags
& STYP_ECOFF_LIB
)
410 sec_flags
|= SEC_SHARED_LIBRARY
;
414 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
420 /* Routines to swap auxiliary information in and out. I am assuming
421 that the auxiliary information format is always going to be target
424 /* Swap in a type information record.
425 BIGEND says whether AUX symbols are big-endian or little-endian; this
426 info comes from the file header record (fh-fBigendian). */
429 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
431 struct tir_ext
*ext_copy
;
434 struct tir_ext ext
[1];
436 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
438 /* now the fun stuff... */
440 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
441 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
442 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
443 >> TIR_BITS1_BT_SH_BIG
;
444 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
445 >> TIR_BITS_TQ4_SH_BIG
;
446 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
447 >> TIR_BITS_TQ5_SH_BIG
;
448 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
449 >> TIR_BITS_TQ0_SH_BIG
;
450 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
451 >> TIR_BITS_TQ1_SH_BIG
;
452 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
453 >> TIR_BITS_TQ2_SH_BIG
;
454 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
455 >> TIR_BITS_TQ3_SH_BIG
;
457 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
458 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
459 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
460 >> TIR_BITS1_BT_SH_LITTLE
;
461 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
462 >> TIR_BITS_TQ4_SH_LITTLE
;
463 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
464 >> TIR_BITS_TQ5_SH_LITTLE
;
465 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
466 >> TIR_BITS_TQ0_SH_LITTLE
;
467 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
468 >> TIR_BITS_TQ1_SH_LITTLE
;
469 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
470 >> TIR_BITS_TQ2_SH_LITTLE
;
471 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
472 >> TIR_BITS_TQ3_SH_LITTLE
;
476 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
481 /* Swap out a type information record.
482 BIGEND says whether AUX symbols are big-endian or little-endian; this
483 info comes from the file header record (fh-fBigendian). */
486 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
493 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
495 /* now the fun stuff... */
497 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
498 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
499 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
500 & TIR_BITS1_BT_BIG
));
501 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
503 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
504 & TIR_BITS_TQ5_BIG
));
505 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
507 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
508 & TIR_BITS_TQ1_BIG
));
509 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
511 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
512 & TIR_BITS_TQ3_BIG
));
514 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
515 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
516 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
517 & TIR_BITS1_BT_LITTLE
));
518 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
519 & TIR_BITS_TQ4_LITTLE
)
520 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
521 & TIR_BITS_TQ5_LITTLE
));
522 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
523 & TIR_BITS_TQ0_LITTLE
)
524 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
525 & TIR_BITS_TQ1_LITTLE
));
526 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
527 & TIR_BITS_TQ2_LITTLE
)
528 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
529 & TIR_BITS_TQ3_LITTLE
));
533 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
538 /* Swap in a relative symbol record. BIGEND says whether it is in
539 big-endian or little-endian format.*/
542 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
544 struct rndx_ext
*ext_copy
;
547 struct rndx_ext ext
[1];
549 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
551 /* now the fun stuff... */
553 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
554 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
555 >> RNDX_BITS1_RFD_SH_BIG
);
556 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
557 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
558 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
559 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
561 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
562 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
563 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
564 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
565 >> RNDX_BITS1_INDEX_SH_LITTLE
)
566 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
567 | ((unsigned int) ext
->r_bits
[3]
568 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
572 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
577 /* Swap out a relative symbol record. BIGEND says whether it is in
578 big-endian or little-endian format.*/
581 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
584 struct rndx_ext
*ext
;
588 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
590 /* now the fun stuff... */
592 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
593 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
594 & RNDX_BITS1_RFD_BIG
)
595 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
596 & RNDX_BITS1_INDEX_BIG
));
597 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
598 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
600 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
601 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
602 & RNDX_BITS1_RFD_LITTLE
)
603 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
604 & RNDX_BITS1_INDEX_LITTLE
));
605 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
606 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
610 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
615 /* Read in the symbolic header for an ECOFF object file. */
618 ecoff_slurp_symbolic_header (abfd
)
621 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
622 bfd_size_type external_hdr_size
;
624 HDRR
*internal_symhdr
;
626 /* See if we've already read it in. */
627 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
628 backend
->debug_swap
.sym_magic
)
631 /* See whether there is a symbolic header. */
632 if (ecoff_data (abfd
)->sym_filepos
== 0)
634 bfd_get_symcount (abfd
) = 0;
638 /* At this point bfd_get_symcount (abfd) holds the number of symbols
639 as read from the file header, but on ECOFF this is always the
640 size of the symbolic information header. It would be cleaner to
641 handle this when we first read the file in coffgen.c. */
642 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
643 if (bfd_get_symcount (abfd
) != external_hdr_size
)
645 bfd_set_error (bfd_error_bad_value
);
649 /* Read the symbolic information header. */
650 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
653 bfd_set_error (bfd_error_no_memory
);
657 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
658 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
659 != external_hdr_size
))
661 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
662 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
664 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
666 bfd_set_error (bfd_error_bad_value
);
670 /* Now we can get the correct number of symbols. */
671 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
672 + internal_symhdr
->iextMax
);
683 /* Read in and swap the important symbolic information for an ECOFF
684 object file. This is called by gdb. */
687 ecoff_slurp_symbolic_info (abfd
)
690 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
691 HDRR
*internal_symhdr
;
692 bfd_size_type raw_base
;
693 bfd_size_type raw_size
;
695 bfd_size_type external_fdr_size
;
699 bfd_size_type raw_end
;
700 bfd_size_type cb_end
;
702 /* Check whether we've already gotten it, and whether there's any to
704 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
706 if (ecoff_data (abfd
)->sym_filepos
== 0)
708 bfd_get_symcount (abfd
) = 0;
712 if (! ecoff_slurp_symbolic_header (abfd
))
715 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
717 /* Read all the symbolic information at once. */
718 raw_base
= (ecoff_data (abfd
)->sym_filepos
719 + backend
->debug_swap
.external_hdr_size
);
721 /* Alpha ecoff makes the determination of raw_size difficult. It has
722 an undocumented debug data section between the symhdr and the first
723 documented section. And the ordering of the sections varies between
724 statically and dynamically linked executables.
725 If bfd supports SEEK_END someday, this code could be simplified. */
729 #define UPDATE_RAW_END(start, count, size) \
730 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
731 if (cb_end > raw_end) \
734 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
735 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
736 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
737 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
738 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
739 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
740 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
741 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
742 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
743 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
744 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
746 #undef UPDATE_RAW_END
748 raw_size
= raw_end
- raw_base
;
751 ecoff_data (abfd
)->sym_filepos
= 0;
754 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
757 bfd_set_error (bfd_error_no_memory
);
761 (ecoff_data (abfd
)->sym_filepos
762 + backend
->debug_swap
.external_hdr_size
),
764 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
766 bfd_release (abfd
, raw
);
770 ecoff_data (abfd
)->raw_syments
= raw
;
772 /* Get pointers for the numeric offsets in the HDRR structure. */
773 #define FIX(off1, off2, type) \
774 if (internal_symhdr->off1 == 0) \
775 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
777 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
778 + internal_symhdr->off1 \
780 FIX (cbLineOffset
, line
, unsigned char *);
781 FIX (cbDnOffset
, external_dnr
, PTR
);
782 FIX (cbPdOffset
, external_pdr
, PTR
);
783 FIX (cbSymOffset
, external_sym
, PTR
);
784 FIX (cbOptOffset
, external_opt
, PTR
);
785 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
786 FIX (cbSsOffset
, ss
, char *);
787 FIX (cbSsExtOffset
, ssext
, char *);
788 FIX (cbFdOffset
, external_fdr
, PTR
);
789 FIX (cbRfdOffset
, external_rfd
, PTR
);
790 FIX (cbExtOffset
, external_ext
, PTR
);
793 /* I don't want to always swap all the data, because it will just
794 waste time and most programs will never look at it. The only
795 time the linker needs most of the debugging information swapped
796 is when linking big-endian and little-endian MIPS object files
797 together, which is not a common occurrence.
799 We need to look at the fdr to deal with a lot of information in
800 the symbols, so we swap them here. */
801 ecoff_data (abfd
)->debug_info
.fdr
=
802 (struct fdr
*) bfd_alloc (abfd
,
803 (internal_symhdr
->ifdMax
*
804 sizeof (struct fdr
)));
805 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
807 bfd_set_error (bfd_error_no_memory
);
810 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
811 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
812 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
813 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
814 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
815 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
820 /* ECOFF symbol table routines. The ECOFF symbol table is described
821 in gcc/mips-tfile.c. */
823 /* ECOFF uses two common sections. One is the usual one, and the
824 other is for small objects. All the small objects are kept
825 together, and then referenced via the gp pointer, which yields
826 faster assembler code. This is what we use for the small common
828 static asection ecoff_scom_section
;
829 static asymbol ecoff_scom_symbol
;
830 static asymbol
*ecoff_scom_symbol_ptr
;
832 /* Create an empty symbol. */
835 ecoff_make_empty_symbol (abfd
)
838 ecoff_symbol_type
*new;
840 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
841 if (new == (ecoff_symbol_type
*) NULL
)
843 bfd_set_error (bfd_error_no_memory
);
844 return (asymbol
*) NULL
;
846 memset ((PTR
) new, 0, sizeof *new);
847 new->symbol
.section
= (asection
*) NULL
;
848 new->fdr
= (FDR
*) NULL
;
851 new->symbol
.the_bfd
= abfd
;
855 /* Set the BFD flags and section for an ECOFF symbol. */
858 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
863 asymbol
**indirect_ptr_ptr
;
865 asym
->the_bfd
= abfd
;
866 asym
->value
= ecoff_sym
->value
;
867 asym
->section
= &bfd_debug_section
;
870 /* An indirect symbol requires two consecutive stabs symbols. */
871 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
873 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
875 /* @@ Stuffing pointers into integers is a no-no.
876 We can usually get away with it if the integer is
877 large enough though. */
878 if (sizeof (asym
) > sizeof (bfd_vma
))
880 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
882 asym
->flags
= BSF_DEBUGGING
;
883 asym
->section
= &bfd_und_section
;
884 *indirect_ptr_ptr
= NULL
;
888 if (ECOFF_IS_STAB (ecoff_sym
)
889 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
891 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
892 asym
->section
= &bfd_ind_section
;
893 /* Pass this symbol on to the next call to this function. */
894 *indirect_ptr_ptr
= asym
;
898 /* Most symbol types are just for debugging. */
899 switch (ecoff_sym
->st
)
908 if (ECOFF_IS_STAB (ecoff_sym
))
910 asym
->flags
= BSF_DEBUGGING
;
915 asym
->flags
= BSF_DEBUGGING
;
920 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
922 asym
->flags
= BSF_LOCAL
;
923 switch (ecoff_sym
->sc
)
926 /* Used for compiler generated labels. Leave them in the
927 debugging section, and mark them as local. If BSF_DEBUGGING
928 is set, then nm does not display them for some reason. If no
929 flags are set then the linker whines about them. */
930 asym
->flags
= BSF_LOCAL
;
933 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
934 asym
->value
-= asym
->section
->vma
;
937 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
938 asym
->value
-= asym
->section
->vma
;
941 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
942 asym
->value
-= asym
->section
->vma
;
945 asym
->flags
= BSF_DEBUGGING
;
948 asym
->section
= &bfd_abs_section
;
951 asym
->section
= &bfd_und_section
;
961 asym
->flags
= BSF_DEBUGGING
;
964 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
965 asym
->value
-= asym
->section
->vma
;
968 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
969 asym
->value
-= asym
->section
->vma
;
972 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
973 asym
->value
-= asym
->section
->vma
;
976 asym
->flags
= BSF_DEBUGGING
;
979 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
981 asym
->section
= &bfd_com_section
;
987 if (ecoff_scom_section
.name
== NULL
)
989 /* Initialize the small common section. */
990 ecoff_scom_section
.name
= SCOMMON
;
991 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
992 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
993 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
994 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
995 ecoff_scom_symbol
.name
= SCOMMON
;
996 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
997 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
998 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
1000 asym
->section
= &ecoff_scom_section
;
1005 asym
->flags
= BSF_DEBUGGING
;
1008 asym
->section
= &bfd_und_section
;
1013 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1014 asym
->value
-= asym
->section
->vma
;
1019 asym
->flags
= BSF_DEBUGGING
;
1022 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1023 asym
->value
-= asym
->section
->vma
;
1029 /* Look for special constructors symbols and make relocation entries
1030 in a special construction section. These are produced by the
1031 -fgnu-linker argument to g++. */
1032 if (ECOFF_IS_STAB (ecoff_sym
))
1034 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1046 arelent_chain
*reloc_chain
;
1047 unsigned int bitsize
;
1049 /* Get a section with the same name as the symbol (usually
1050 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1051 name ___CTOR_LIST (three underscores). We need
1052 __CTOR_LIST (two underscores), since ECOFF doesn't use
1053 a leading underscore. This should be handled by gcc,
1054 but instead we do it here. Actually, this should all
1055 be done differently anyhow. */
1056 name
= bfd_asymbol_name (asym
);
1057 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1062 section
= bfd_get_section_by_name (abfd
, name
);
1063 if (section
== (asection
*) NULL
)
1067 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1070 bfd_set_error (bfd_error_no_memory
);
1073 strcpy (copy
, name
);
1074 section
= bfd_make_section (abfd
, copy
);
1077 /* Build a reloc pointing to this constructor. */
1079 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1082 bfd_set_error (bfd_error_no_memory
);
1085 reloc_chain
->relent
.sym_ptr_ptr
=
1086 bfd_get_section (asym
)->symbol_ptr_ptr
;
1087 reloc_chain
->relent
.address
= section
->_raw_size
;
1088 reloc_chain
->relent
.addend
= asym
->value
;
1089 reloc_chain
->relent
.howto
=
1090 ecoff_backend (abfd
)->constructor_reloc
;
1092 /* Set up the constructor section to hold the reloc. */
1093 section
->flags
= SEC_CONSTRUCTOR
;
1094 ++section
->reloc_count
;
1096 /* Constructor sections must be rounded to a boundary
1097 based on the bitsize. These are not real sections--
1098 they are handled specially by the linker--so the ECOFF
1099 16 byte alignment restriction does not apply. */
1100 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1101 section
->alignment_power
= 1;
1102 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1103 ++section
->alignment_power
;
1105 reloc_chain
->next
= section
->constructor_chain
;
1106 section
->constructor_chain
= reloc_chain
;
1107 section
->_raw_size
+= bitsize
/ 8;
1109 /* Mark the symbol as a constructor. */
1110 asym
->flags
|= BSF_CONSTRUCTOR
;
1118 /* Read an ECOFF symbol table. */
1121 ecoff_slurp_symbol_table (abfd
)
1124 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1125 const bfd_size_type external_ext_size
1126 = backend
->debug_swap
.external_ext_size
;
1127 const bfd_size_type external_sym_size
1128 = backend
->debug_swap
.external_sym_size
;
1129 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1130 = backend
->debug_swap
.swap_ext_in
;
1131 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1132 = backend
->debug_swap
.swap_sym_in
;
1133 bfd_size_type internal_size
;
1134 ecoff_symbol_type
*internal
;
1135 ecoff_symbol_type
*internal_ptr
;
1136 asymbol
*indirect_ptr
;
1142 /* If we've already read in the symbol table, do nothing. */
1143 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1146 /* Get the symbolic information. */
1147 if (ecoff_slurp_symbolic_info (abfd
) == false)
1149 if (bfd_get_symcount (abfd
) == 0)
1152 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1153 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1154 if (internal
== NULL
)
1156 bfd_set_error (bfd_error_no_memory
);
1160 internal_ptr
= internal
;
1161 indirect_ptr
= NULL
;
1162 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1163 eraw_end
= (eraw_src
1164 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1165 * external_ext_size
));
1166 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1170 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1171 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1172 + internal_esym
.asym
.iss
);
1173 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1174 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1176 /* The alpha uses a negative ifd field for section symbols. */
1177 if (internal_esym
.ifd
>= 0)
1178 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1179 + internal_esym
.ifd
);
1181 internal_ptr
->fdr
= NULL
;
1182 internal_ptr
->local
= false;
1183 internal_ptr
->native
= (PTR
) eraw_src
;
1185 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1187 /* The local symbols must be accessed via the fdr's, because the
1188 string and aux indices are relative to the fdr information. */
1189 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1190 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1191 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1196 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1197 + fdr_ptr
->isymBase
* external_sym_size
);
1198 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1200 lraw_src
< lraw_end
;
1201 lraw_src
+= external_sym_size
, internal_ptr
++)
1205 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1206 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1208 + internal_sym
.iss
);
1209 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1210 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1212 internal_ptr
->fdr
= fdr_ptr
;
1213 internal_ptr
->local
= true;
1214 internal_ptr
->native
= (PTR
) lraw_src
;
1217 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1219 ecoff_data (abfd
)->canonical_symbols
= internal
;
1224 /* Return the amount of space needed for the canonical symbols. */
1227 ecoff_get_symtab_upper_bound (abfd
)
1230 if (! ecoff_slurp_symbolic_info (abfd
))
1233 if (bfd_get_symcount (abfd
) == 0)
1236 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1239 /* Get the canonical symbols. */
1242 ecoff_get_symtab (abfd
, alocation
)
1244 asymbol
**alocation
;
1246 unsigned int counter
= 0;
1247 ecoff_symbol_type
*symbase
;
1248 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1250 if (ecoff_slurp_symbol_table (abfd
) == false)
1252 if (bfd_get_symcount (abfd
) == 0)
1255 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1256 while (counter
< bfd_get_symcount (abfd
))
1258 *(location
++) = symbase
++;
1261 *location
++ = (ecoff_symbol_type
*) NULL
;
1262 return bfd_get_symcount (abfd
);
1265 /* Turn ECOFF type information into a printable string.
1266 ecoff_emit_aggregate and ecoff_type_to_string are from
1267 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1269 /* Write aggregate information to a string. */
1272 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1279 int ifd
= rndx
->rfd
;
1280 int indx
= rndx
->index
;
1281 int sym_base
, ss_base
;
1287 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1288 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1290 if (indx
== indexNil
)
1291 name
= "/* no name */";
1294 const struct ecoff_debug_swap
* const debug_swap
1295 = &ecoff_backend (abfd
)->debug_swap
;
1299 (*debug_swap
->swap_sym_in
)
1301 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1302 + indx
* debug_swap
->external_sym_size
),
1304 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1308 "%s %s { ifd = %d, index = %ld }",
1311 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1314 /* Convert the type information to string format. */
1317 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1319 union aux_ext
*aux_ptr
;
1331 unsigned int basic_type
;
1333 static char buffer1
[1024];
1334 static char buffer2
[1024];
1339 for (i
= 0; i
< 7; i
++)
1341 qualifiers
[i
].low_bound
= 0;
1342 qualifiers
[i
].high_bound
= 0;
1343 qualifiers
[i
].stride
= 0;
1346 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1347 return "-1 (no type)";
1348 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1350 basic_type
= u
.ti
.bt
;
1351 qualifiers
[0].type
= u
.ti
.tq0
;
1352 qualifiers
[1].type
= u
.ti
.tq1
;
1353 qualifiers
[2].type
= u
.ti
.tq2
;
1354 qualifiers
[3].type
= u
.ti
.tq3
;
1355 qualifiers
[4].type
= u
.ti
.tq4
;
1356 qualifiers
[5].type
= u
.ti
.tq5
;
1357 qualifiers
[6].type
= tqNil
;
1360 * Go get the basic type.
1364 case btNil
: /* undefined */
1368 case btAdr
: /* address - integer same size as pointer */
1369 strcpy (p1
, "address");
1372 case btChar
: /* character */
1373 strcpy (p1
, "char");
1376 case btUChar
: /* unsigned character */
1377 strcpy (p1
, "unsigned char");
1380 case btShort
: /* short */
1381 strcpy (p1
, "short");
1384 case btUShort
: /* unsigned short */
1385 strcpy (p1
, "unsigned short");
1388 case btInt
: /* int */
1392 case btUInt
: /* unsigned int */
1393 strcpy (p1
, "unsigned int");
1396 case btLong
: /* long */
1397 strcpy (p1
, "long");
1400 case btULong
: /* unsigned long */
1401 strcpy (p1
, "unsigned long");
1404 case btFloat
: /* float (real) */
1405 strcpy (p1
, "float");
1408 case btDouble
: /* Double (real) */
1409 strcpy (p1
, "double");
1412 /* Structures add 1-2 aux words:
1413 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1414 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1416 case btStruct
: /* Structure (Record) */
1417 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1418 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1419 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1421 indx
++; /* skip aux words */
1424 /* Unions add 1-2 aux words:
1425 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1426 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1428 case btUnion
: /* Union */
1429 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1430 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1431 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1433 indx
++; /* skip aux words */
1436 /* Enumerations add 1-2 aux words:
1437 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1438 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1440 case btEnum
: /* Enumeration */
1441 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1442 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1443 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1445 indx
++; /* skip aux words */
1448 case btTypedef
: /* defined via a typedef, isymRef points */
1449 strcpy (p1
, "typedef");
1452 case btRange
: /* subrange of int */
1453 strcpy (p1
, "subrange");
1456 case btSet
: /* pascal sets */
1460 case btComplex
: /* fortran complex */
1461 strcpy (p1
, "complex");
1464 case btDComplex
: /* fortran double complex */
1465 strcpy (p1
, "double complex");
1468 case btIndirect
: /* forward or unnamed typedef */
1469 strcpy (p1
, "forward/unamed typedef");
1472 case btFixedDec
: /* Fixed Decimal */
1473 strcpy (p1
, "fixed decimal");
1476 case btFloatDec
: /* Float Decimal */
1477 strcpy (p1
, "float decimal");
1480 case btString
: /* Varying Length Character String */
1481 strcpy (p1
, "string");
1484 case btBit
: /* Aligned Bit String */
1488 case btPicture
: /* Picture */
1489 strcpy (p1
, "picture");
1492 case btVoid
: /* Void */
1493 strcpy (p1
, "void");
1497 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1501 p1
+= strlen (buffer1
);
1504 * If this is a bitfield, get the bitsize.
1510 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1511 sprintf (p1
, " : %d", bitsize
);
1512 p1
+= strlen (buffer1
);
1517 * Deal with any qualifiers.
1519 if (qualifiers
[0].type
!= tqNil
)
1522 * Snarf up any array bounds in the correct order. Arrays
1523 * store 5 successive words in the aux. table:
1524 * word 0 RNDXR to type of the bounds (ie, int)
1525 * word 1 Current file descriptor index
1527 * word 3 high bound (or -1 if [])
1528 * word 4 stride size in bits
1530 for (i
= 0; i
< 7; i
++)
1532 if (qualifiers
[i
].type
== tqArray
)
1534 qualifiers
[i
].low_bound
=
1535 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1536 qualifiers
[i
].high_bound
=
1537 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1538 qualifiers
[i
].stride
=
1539 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1545 * Now print out the qualifiers.
1547 for (i
= 0; i
< 6; i
++)
1549 switch (qualifiers
[i
].type
)
1556 strcpy (p2
, "ptr to ");
1557 p2
+= sizeof ("ptr to ")-1;
1561 strcpy (p2
, "volatile ");
1562 p2
+= sizeof ("volatile ")-1;
1566 strcpy (p2
, "far ");
1567 p2
+= sizeof ("far ")-1;
1571 strcpy (p2
, "func. ret. ");
1572 p2
+= sizeof ("func. ret. ");
1577 int first_array
= i
;
1580 /* Print array bounds reversed (ie, in the order the C
1581 programmer writes them). C is such a fun language.... */
1583 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1586 for (j
= i
; j
>= first_array
; j
--)
1588 strcpy (p2
, "array [");
1589 p2
+= sizeof ("array [")-1;
1590 if (qualifiers
[j
].low_bound
!= 0)
1592 "%ld:%ld {%ld bits}",
1593 (long) qualifiers
[j
].low_bound
,
1594 (long) qualifiers
[j
].high_bound
,
1595 (long) qualifiers
[j
].stride
);
1597 else if (qualifiers
[j
].high_bound
!= -1)
1600 (long) (qualifiers
[j
].high_bound
+ 1),
1601 (long) (qualifiers
[j
].stride
));
1604 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1607 strcpy (p2
, "] of ");
1608 p2
+= sizeof ("] of ")-1;
1616 strcpy (p2
, buffer1
);
1620 /* Return information about ECOFF symbol SYMBOL in RET. */
1624 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1625 bfd
*abfd
; /* Ignored. */
1629 bfd_symbol_info (symbol
, ret
);
1632 /* Print information about an ECOFF symbol. */
1635 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1639 bfd_print_symbol_type how
;
1641 const struct ecoff_debug_swap
* const debug_swap
1642 = &ecoff_backend (abfd
)->debug_swap
;
1643 FILE *file
= (FILE *)filep
;
1647 case bfd_print_symbol_name
:
1648 fprintf (file
, "%s", symbol
->name
);
1650 case bfd_print_symbol_more
:
1651 if (ecoffsymbol (symbol
)->local
)
1655 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1657 fprintf (file
, "ecoff local ");
1658 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1659 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1660 (unsigned) ecoff_sym
.sc
);
1666 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1668 fprintf (file
, "ecoff extern ");
1669 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1670 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1671 (unsigned) ecoff_ext
.asym
.sc
);
1674 case bfd_print_symbol_all
:
1675 /* Print out the symbols in a reasonable way */
1684 if (ecoffsymbol (symbol
)->local
)
1686 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1689 pos
= ((((char *) ecoffsymbol (symbol
)->native
1690 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1691 / debug_swap
->external_sym_size
)
1692 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1699 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1702 pos
= (((char *) ecoffsymbol (symbol
)->native
1703 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1704 / debug_swap
->external_ext_size
);
1705 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1706 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1707 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1710 fprintf (file
, "[%3d] %c ",
1712 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1713 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1714 (unsigned) ecoff_ext
.asym
.st
,
1715 (unsigned) ecoff_ext
.asym
.sc
,
1716 (unsigned) ecoff_ext
.asym
.index
,
1717 jmptbl
, cobol_main
, weakext
,
1720 if (ecoffsymbol (symbol
)->fdr
!= NULL
1721 && ecoff_ext
.asym
.index
!= indexNil
)
1725 bfd_size_type sym_base
;
1726 union aux_ext
*aux_base
;
1728 indx
= ecoff_ext
.asym
.index
;
1730 /* sym_base is used to map the fdr relative indices which
1731 appear in the file to the position number which we are
1733 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1734 if (ecoffsymbol (symbol
)->local
)
1736 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1738 /* aux_base is the start of the aux entries for this file;
1739 asym.index is an offset from this. */
1740 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1741 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1743 /* The aux entries are stored in host byte order; the
1744 order is indicated by a bit in the fdr. */
1745 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1747 /* This switch is basically from gcc/mips-tdump.c */
1748 switch (ecoff_ext
.asym
.st
)
1756 fprintf (file
, "\n End+1 symbol: %ld",
1757 (long) (indx
+ sym_base
));
1761 if (ecoff_ext
.asym
.sc
== scText
1762 || ecoff_ext
.asym
.sc
== scInfo
)
1763 fprintf (file
, "\n First symbol: %ld",
1764 (long) (indx
+ sym_base
));
1766 fprintf (file
, "\n First symbol: %ld",
1767 (long) (AUX_GET_ISYM (bigendian
,
1768 &aux_base
[ecoff_ext
.asym
.index
])
1774 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1776 else if (ecoffsymbol (symbol
)->local
)
1777 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1778 (long) (AUX_GET_ISYM (bigendian
,
1779 &aux_base
[ecoff_ext
.asym
.index
])
1781 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1784 fprintf (file
, "\n Local symbol: %ld",
1787 + (ecoff_data (abfd
)
1788 ->debug_info
.symbolic_header
.iextMax
)));
1792 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1793 fprintf (file
, "\n Type: %s",
1794 ecoff_type_to_string (abfd
, aux_base
, indx
,
1804 /* Read in the relocs for a section. */
1807 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1812 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1813 arelent
*internal_relocs
;
1814 bfd_size_type external_reloc_size
;
1815 bfd_size_type external_relocs_size
;
1816 char *external_relocs
;
1820 if (section
->relocation
!= (arelent
*) NULL
1821 || section
->reloc_count
== 0
1822 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1825 if (ecoff_slurp_symbol_table (abfd
) == false)
1828 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1830 * section
->reloc_count
));
1831 external_reloc_size
= backend
->external_reloc_size
;
1832 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1833 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1834 if (internal_relocs
== (arelent
*) NULL
1835 || external_relocs
== (char *) NULL
)
1837 bfd_set_error (bfd_error_no_memory
);
1840 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1842 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1843 != external_relocs_size
)
1846 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1848 struct internal_reloc intern
;
1850 (*backend
->swap_reloc_in
) (abfd
,
1851 external_relocs
+ i
* external_reloc_size
,
1854 if (intern
.r_extern
)
1856 /* r_symndx is an index into the external symbols. */
1857 BFD_ASSERT (intern
.r_symndx
>= 0
1859 < (ecoff_data (abfd
)
1860 ->debug_info
.symbolic_header
.iextMax
)));
1861 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1864 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1865 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1867 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1872 CONST
char *sec_name
;
1875 /* r_symndx is a section key. */
1876 switch (intern
.r_symndx
)
1878 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1879 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1880 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1881 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1882 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1883 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1884 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1885 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1886 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1887 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1888 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1889 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1890 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1894 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1895 if (sec
== (asection
*) NULL
)
1897 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1899 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1902 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1904 /* Let the backend select the howto field and do any other
1905 required processing. */
1906 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1909 bfd_release (abfd
, external_relocs
);
1911 section
->relocation
= internal_relocs
;
1916 /* Get a canonical list of relocs. */
1919 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1927 if (section
->flags
& SEC_CONSTRUCTOR
)
1929 arelent_chain
*chain
;
1931 /* This section has relocs made up by us, not the file, so take
1932 them out of their chain and place them into the data area
1934 for (count
= 0, chain
= section
->constructor_chain
;
1935 count
< section
->reloc_count
;
1936 count
++, chain
= chain
->next
)
1937 *relptr
++ = &chain
->relent
;
1943 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1946 tblptr
= section
->relocation
;
1947 if (tblptr
== (arelent
*) NULL
)
1950 for (count
= 0; count
< section
->reloc_count
; count
++)
1951 *relptr
++ = tblptr
++;
1954 *relptr
= (arelent
*) NULL
;
1956 return section
->reloc_count
;
1959 /* Provided a BFD, a section and an offset into the section, calculate
1960 and return the name of the source file and the line nearest to the
1965 ecoff_find_nearest_line (abfd
,
1974 asymbol
**ignore_symbols
;
1976 CONST
char **filename_ptr
;
1977 CONST
char **functionname_ptr
;
1978 unsigned int *retline_ptr
;
1980 const struct ecoff_debug_swap
* const debug_swap
1981 = &ecoff_backend (abfd
)->debug_swap
;
1986 bfd_size_type external_pdr_size
;
1990 unsigned char *line_ptr
;
1991 unsigned char *line_end
;
1994 /* If we're not in the .text section, we don't have any line
1996 if (strcmp (section
->name
, _TEXT
) != 0
1997 || offset
< ecoff_data (abfd
)->text_start
1998 || offset
>= ecoff_data (abfd
)->text_end
)
2001 /* Make sure we have the FDR's. */
2002 if (ecoff_slurp_symbolic_info (abfd
) == false
2003 || bfd_get_symcount (abfd
) == 0)
2006 /* Each file descriptor (FDR) has a memory address. Here we track
2007 down which FDR we want. The FDR's are stored in increasing
2008 memory order. If speed is ever important, this can become a
2009 binary search. We must ignore FDR's with no PDR entries; they
2010 will have the adr of the FDR before or after them. */
2011 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2012 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2013 fdr_hold
= (FDR
*) NULL
;
2014 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2016 if (fdr_ptr
->cpd
== 0)
2018 if (offset
< fdr_ptr
->adr
)
2022 if (fdr_hold
== (FDR
*) NULL
)
2026 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2027 have an address, which is relative to the FDR address, and are
2028 also stored in increasing memory order. */
2029 offset
-= fdr_ptr
->adr
;
2030 external_pdr_size
= debug_swap
->external_pdr_size
;
2031 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2032 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2033 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2034 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2036 /* The address of the first PDR is an offset which applies to the
2037 addresses of all the PDR's. */
2040 for (pdr_ptr
+= external_pdr_size
;
2042 pdr_ptr
+= external_pdr_size
)
2044 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2045 if (offset
< pdr
.adr
)
2049 /* Now we can look for the actual line number. The line numbers are
2050 stored in a very funky format, which I won't try to describe.
2051 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2052 we want; we need this to compute line_end. */
2053 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2054 if (pdr_ptr
== pdr_end
)
2055 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2057 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2059 /* Now change pdr and pdr_ptr to the one we want. */
2060 pdr_ptr
-= external_pdr_size
;
2061 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2065 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2066 + fdr_ptr
->cbLineOffset
2067 + pdr
.cbLineOffset
);
2068 while (line_ptr
< line_end
)
2073 delta
= *line_ptr
>> 4;
2076 count
= (*line_ptr
& 0xf) + 1;
2080 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2081 if (delta
>= 0x8000)
2086 if (offset
< count
* 4)
2088 offset
-= count
* 4;
2091 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2092 at least according to gdb/mipsread.c. */
2093 if (fdr_ptr
->rss
== -1)
2095 *filename_ptr
= NULL
;
2097 *functionname_ptr
= NULL
;
2102 (*debug_swap
->swap_ext_in
)
2104 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2105 + pdr
.isym
* debug_swap
->external_ext_size
),
2107 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2108 + proc_ext
.asym
.iss
);
2115 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2118 (*debug_swap
->swap_sym_in
)
2120 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2121 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2123 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2127 if (lineno
== ilineNil
)
2129 *retline_ptr
= lineno
;
2133 /* Set the architecture. The supported architecture is stored in the
2134 backend pointer. We always set the architecture anyhow, since many
2135 callers ignore the return value. */
2138 ecoff_set_arch_mach (abfd
, arch
, machine
)
2140 enum bfd_architecture arch
;
2141 unsigned long machine
;
2143 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2144 return arch
== ecoff_backend (abfd
)->arch
;
2147 /* Get the size of the section headers. We do not output the .reginfo
2152 ecoff_sizeof_headers (abfd
, reloc
)
2161 for (current
= abfd
->sections
;
2162 current
!= (asection
*)NULL
;
2163 current
= current
->next
)
2164 if (strcmp (current
->name
, REGINFO
) != 0)
2167 ret
= (bfd_coff_filhsz (abfd
)
2168 + bfd_coff_aoutsz (abfd
)
2169 + c
* bfd_coff_scnhsz (abfd
));
2170 return BFD_ALIGN (ret
, 16);
2173 /* Get the contents of a section. This is where we handle reading the
2174 .reginfo section, which implicitly holds the contents of an
2175 ecoff_reginfo structure. */
2178 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2183 bfd_size_type count
;
2185 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2186 struct ecoff_reginfo s
;
2189 if (strcmp (section
->name
, REGINFO
) != 0)
2190 return bfd_generic_get_section_contents (abfd
, section
, location
,
2193 s
.gp_value
= tdata
->gp
;
2194 s
.gprmask
= tdata
->gprmask
;
2195 for (i
= 0; i
< 4; i
++)
2196 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2197 s
.fprmask
= tdata
->fprmask
;
2199 /* bfd_get_section_contents has already checked that the offset and
2200 size is reasonable. We don't have to worry about swapping or any
2201 such thing; the .reginfo section is defined such that the
2202 contents are an ecoff_reginfo structure as seen on the host. */
2203 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2207 /* Calculate the file position for each section, and set
2211 ecoff_compute_section_file_positions (abfd
)
2219 sofar
= ecoff_sizeof_headers (abfd
, false);
2222 for (current
= abfd
->sections
;
2223 current
!= (asection
*) NULL
;
2224 current
= current
->next
)
2226 unsigned int alignment_power
;
2228 /* Only deal with sections which have contents */
2229 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2230 || strcmp (current
->name
, REGINFO
) == 0)
2233 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2234 supposed to indicate the number of .pdata entries that are
2235 really in the section. Each entry is 8 bytes. We store this
2236 away in line_filepos before increasing the section size. */
2237 if (strcmp (current
->name
, _PDATA
) != 0)
2238 alignment_power
= current
->alignment_power
;
2241 current
->line_filepos
= current
->_raw_size
/ 8;
2242 alignment_power
= 4;
2245 /* On Ultrix, the data sections in an executable file must be
2246 aligned to a page boundary within the file. This does not
2247 affect the section size, though. FIXME: Does this work for
2248 other platforms? It requires some modification for the
2249 Alpha, because .rdata on the Alpha goes with the text, not
2251 if ((abfd
->flags
& EXEC_P
) != 0
2252 && (abfd
->flags
& D_PAGED
) != 0
2253 && first_data
!= false
2254 && (current
->flags
& SEC_CODE
) == 0
2255 && (! ecoff_backend (abfd
)->rdata_in_text
2256 || strcmp (current
->name
, _RDATA
) != 0)
2257 && strcmp (current
->name
, _PDATA
) != 0)
2259 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2261 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2264 else if (strcmp (current
->name
, _LIB
) == 0)
2266 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2267 /* On Irix 4, the location of contents of the .lib section
2268 from a shared library section is also rounded up to a
2271 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2274 /* Align the sections in the file to the same boundary on
2275 which they are aligned in virtual memory. */
2277 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2279 current
->filepos
= sofar
;
2281 sofar
+= current
->_raw_size
;
2283 /* make sure that this section is of the right size too */
2285 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2286 current
->_raw_size
+= sofar
- old_sofar
;
2289 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2292 /* Determine the location of the relocs for all the sections in the
2293 output file, as well as the location of the symbolic debugging
2296 static bfd_size_type
2297 ecoff_compute_reloc_file_positions (abfd
)
2300 const bfd_size_type external_reloc_size
=
2301 ecoff_backend (abfd
)->external_reloc_size
;
2302 file_ptr reloc_base
;
2303 bfd_size_type reloc_size
;
2307 if (! abfd
->output_has_begun
)
2309 ecoff_compute_section_file_positions (abfd
);
2310 abfd
->output_has_begun
= true;
2313 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2316 for (current
= abfd
->sections
;
2317 current
!= (asection
*)NULL
;
2318 current
= current
->next
)
2320 if (strcmp (current
->name
, REGINFO
) == 0)
2322 if (current
->reloc_count
== 0)
2323 current
->rel_filepos
= 0;
2326 bfd_size_type relsize
;
2328 current
->rel_filepos
= reloc_base
;
2329 relsize
= current
->reloc_count
* external_reloc_size
;
2330 reloc_size
+= relsize
;
2331 reloc_base
+= relsize
;
2335 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2337 /* At least on Ultrix, the symbol table of an executable file must
2338 be aligned to a page boundary. FIXME: Is this true on other
2340 if ((abfd
->flags
& EXEC_P
) != 0
2341 && (abfd
->flags
& D_PAGED
) != 0)
2342 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2343 &~ (ecoff_backend (abfd
)->round
- 1));
2345 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2350 /* Set the contents of a section. This is where we handle setting the
2351 contents of the .reginfo section, which implicitly holds a
2352 ecoff_reginfo structure. */
2355 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2360 bfd_size_type count
;
2362 /* This must be done first, because bfd_set_section_contents is
2363 going to set output_has_begun to true. */
2364 if (abfd
->output_has_begun
== false)
2365 ecoff_compute_section_file_positions (abfd
);
2367 /* If this is a .lib section, bump the vma address so that it winds
2368 up being the number of .lib sections output. This is right for
2369 Irix 4. Ian Taylor <ian@cygnus.com>. */
2370 if (strcmp (section
->name
, _LIB
) == 0)
2376 if (strcmp (section
->name
, REGINFO
) == 0)
2378 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2379 struct ecoff_reginfo s
;
2382 /* If the caller is only changing part of the structure, we must
2383 retrieve the current information before the memcpy. */
2384 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2386 s
.gp_value
= tdata
->gp
;
2387 s
.gprmask
= tdata
->gprmask
;
2388 for (i
= 0; i
< 4; i
++)
2389 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2390 s
.fprmask
= tdata
->fprmask
;
2393 /* bfd_set_section_contents has already checked that the offset
2394 and size is reasonable. We don't have to worry about
2395 swapping or any such thing; the .reginfo section is defined
2396 such that the contents are an ecoff_reginfo structure as seen
2398 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2400 tdata
->gp
= s
.gp_value
;
2401 tdata
->gprmask
= s
.gprmask
;
2402 for (i
= 0; i
< 4; i
++)
2403 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2404 tdata
->fprmask
= s
.fprmask
;
2409 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2410 || bfd_write (location
, 1, count
, abfd
) != count
)
2416 /* Get ECOFF EXTR information for an external symbol. This function
2417 is passed to bfd_ecoff_debug_externals. */
2420 ecoff_get_extr (sym
, esym
)
2424 ecoff_symbol_type
*ecoff_sym_ptr
;
2427 /* Don't include debugging, local or section symbols. */
2428 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2429 || (sym
->flags
& BSF_LOCAL
) != 0
2430 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2433 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2434 || ecoffsymbol (sym
)->native
== NULL
)
2437 esym
->cobol_main
= 0;
2441 /* FIXME: we can do better than this for st and sc. */
2442 esym
->asym
.st
= stGlobal
;
2443 esym
->asym
.sc
= scAbs
;
2444 esym
->asym
.reserved
= 0;
2445 esym
->asym
.index
= indexNil
;
2449 ecoff_sym_ptr
= ecoffsymbol (sym
);
2451 if (ecoff_sym_ptr
->local
)
2454 input_bfd
= bfd_asymbol_bfd (sym
);
2455 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2456 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2458 /* If the symbol was defined by the linker, then esym will be
2459 undefined but sym will not be. Get a better class for such a
2461 if ((esym
->asym
.sc
== scUndefined
2462 || esym
->asym
.sc
== scSUndefined
)
2463 && bfd_get_section (sym
) != &bfd_und_section
)
2464 esym
->asym
.sc
= scAbs
;
2466 /* Adjust the FDR index for the symbol by that used for the input
2468 if (esym
->ifd
!= -1)
2470 struct ecoff_debug_info
*input_debug
;
2472 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2473 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2474 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2475 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2481 /* Set the external symbol index. This routine is passed to
2482 bfd_ecoff_debug_externals. */
2485 ecoff_set_index (sym
, indx
)
2489 ecoff_set_sym_index (sym
, indx
);
2492 /* Write out an ECOFF file. */
2495 ecoff_write_object_contents (abfd
)
2498 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2499 const bfd_vma round
= backend
->round
;
2500 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2501 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2502 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2503 const bfd_size_type external_hdr_size
2504 = backend
->debug_swap
.external_hdr_size
;
2505 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2506 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2508 struct internal_reloc
*))
2509 = backend
->adjust_reloc_out
;
2510 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2511 const struct internal_reloc
*,
2513 = backend
->swap_reloc_out
;
2514 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2515 HDRR
* const symhdr
= &debug
->symbolic_header
;
2518 bfd_size_type reloc_size
;
2519 bfd_size_type text_size
;
2521 boolean set_text_start
;
2522 bfd_size_type data_size
;
2524 boolean set_data_start
;
2525 bfd_size_type bss_size
;
2527 PTR reloc_buff
= NULL
;
2528 struct internal_filehdr internal_f
;
2529 struct internal_aouthdr internal_a
;
2532 /* Determine where the sections and relocs will go in the output
2534 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2537 for (current
= abfd
->sections
;
2538 current
!= (asection
*)NULL
;
2539 current
= current
->next
)
2541 if (strcmp (current
->name
, REGINFO
) == 0)
2543 current
->target_index
= count
;
2547 if ((abfd
->flags
& D_PAGED
) != 0)
2548 text_size
= ecoff_sizeof_headers (abfd
, false);
2552 set_text_start
= false;
2555 set_data_start
= false;
2558 /* Write section headers to the file. */
2560 /* Allocate buff big enough to hold a section header,
2561 file header, or a.out header. */
2569 buff
= (PTR
) malloc (siz
);
2572 bfd_set_error (bfd_error_no_memory
);
2577 internal_f
.f_nscns
= 0;
2578 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2580 for (current
= abfd
->sections
;
2581 current
!= (asection
*) NULL
;
2582 current
= current
->next
)
2584 struct internal_scnhdr section
;
2587 if (strcmp (current
->name
, REGINFO
) == 0)
2589 BFD_ASSERT (current
->reloc_count
== 0);
2593 ++internal_f
.f_nscns
;
2595 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2597 /* This seems to be correct for Irix 4 shared libraries. */
2598 vma
= bfd_get_section_vma (abfd
, current
);
2599 if (strcmp (current
->name
, _LIB
) == 0)
2600 section
.s_vaddr
= 0;
2602 section
.s_vaddr
= vma
;
2604 section
.s_paddr
= vma
;
2605 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2607 /* If this section is unloadable then the scnptr will be 0. */
2608 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2609 section
.s_scnptr
= 0;
2611 section
.s_scnptr
= current
->filepos
;
2612 section
.s_relptr
= current
->rel_filepos
;
2614 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2615 object file produced by the assembler is supposed to point to
2616 information about how much room is required by objects of
2617 various different sizes. I think this only matters if we
2618 want the linker to compute the best size to use, or
2619 something. I don't know what happens if the information is
2621 if (strcmp (current
->name
, _PDATA
) != 0)
2622 section
.s_lnnoptr
= 0;
2625 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2626 hold the number of entries in the section (each entry is
2627 8 bytes). We stored this in the line_filepos field in
2628 ecoff_compute_section_file_positions. */
2629 section
.s_lnnoptr
= current
->line_filepos
;
2632 section
.s_nreloc
= current
->reloc_count
;
2633 section
.s_nlnno
= 0;
2634 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2637 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2638 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2641 if ((section
.s_flags
& STYP_TEXT
) != 0
2642 || ((section
.s_flags
& STYP_RDATA
) != 0
2643 && backend
->rdata_in_text
)
2644 || strcmp (current
->name
, _PDATA
) == 0)
2646 text_size
+= bfd_get_section_size_before_reloc (current
);
2647 if (! set_text_start
|| text_start
> vma
)
2650 set_text_start
= true;
2653 else if ((section
.s_flags
& STYP_RDATA
) != 0
2654 || (section
.s_flags
& STYP_DATA
) != 0
2655 || (section
.s_flags
& STYP_LITA
) != 0
2656 || (section
.s_flags
& STYP_LIT8
) != 0
2657 || (section
.s_flags
& STYP_LIT4
) != 0
2658 || (section
.s_flags
& STYP_SDATA
) != 0
2659 || strcmp (current
->name
, _XDATA
) == 0)
2661 data_size
+= bfd_get_section_size_before_reloc (current
);
2662 if (! set_data_start
|| data_start
> vma
)
2665 set_data_start
= true;
2668 else if ((section
.s_flags
& STYP_BSS
) != 0
2669 || (section
.s_flags
& STYP_SBSS
) != 0)
2670 bss_size
+= bfd_get_section_size_before_reloc (current
);
2671 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
2677 /* Set up the file header. */
2679 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2681 /* We will NOT put a fucking timestamp in the header here. Every
2682 time you put it back, I will come in and take it out again. I'm
2683 sorry. This field does not belong here. We fill it with a 0 so
2684 it compares the same but is not a reasonable time. --
2686 internal_f
.f_timdat
= 0;
2688 if (bfd_get_symcount (abfd
) != 0)
2690 /* The ECOFF f_nsyms field is not actually the number of
2691 symbols, it's the size of symbolic information header. */
2692 internal_f
.f_nsyms
= external_hdr_size
;
2693 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2697 internal_f
.f_nsyms
= 0;
2698 internal_f
.f_symptr
= 0;
2701 internal_f
.f_opthdr
= aoutsz
;
2703 internal_f
.f_flags
= F_LNNO
;
2704 if (reloc_size
== 0)
2705 internal_f
.f_flags
|= F_RELFLG
;
2706 if (bfd_get_symcount (abfd
) == 0)
2707 internal_f
.f_flags
|= F_LSYMS
;
2708 if (abfd
->flags
& EXEC_P
)
2709 internal_f
.f_flags
|= F_EXEC
;
2711 if (! abfd
->xvec
->byteorder_big_p
)
2712 internal_f
.f_flags
|= F_AR32WR
;
2714 internal_f
.f_flags
|= F_AR32W
;
2716 /* Set up the ``optional'' header. */
2717 if ((abfd
->flags
& D_PAGED
) != 0)
2718 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2720 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2722 /* FIXME: Is this really correct? */
2723 internal_a
.vstamp
= symhdr
->vstamp
;
2725 /* At least on Ultrix, these have to be rounded to page boundaries.
2726 FIXME: Is this true on other platforms? */
2727 if ((abfd
->flags
& D_PAGED
) != 0)
2729 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2730 internal_a
.text_start
= text_start
&~ (round
- 1);
2731 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2732 internal_a
.data_start
= data_start
&~ (round
- 1);
2736 internal_a
.tsize
= text_size
;
2737 internal_a
.text_start
= text_start
;
2738 internal_a
.dsize
= data_size
;
2739 internal_a
.data_start
= data_start
;
2742 /* On Ultrix, the initial portions of the .sbss and .bss segments
2743 are at the end of the data section. The bsize field in the
2744 optional header records how many bss bytes are required beyond
2745 those in the data section. The value is not rounded to a page
2747 if (bss_size
< internal_a
.dsize
- data_size
)
2750 bss_size
-= internal_a
.dsize
- data_size
;
2751 internal_a
.bsize
= bss_size
;
2752 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2754 internal_a
.entry
= bfd_get_start_address (abfd
);
2756 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2758 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2759 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2760 for (i
= 0; i
< 4; i
++)
2761 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2763 /* Write out the file header and the optional header. */
2765 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2768 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2769 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2772 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2773 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2776 /* Build the external symbol information. This must be done before
2777 writing out the relocs so that we know the symbol indices. The
2778 condition checks makes sure this object was not created by
2779 ecoff_bfd_final_link, since if it was we do not want to tamper
2780 with the external symbols. */
2781 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2783 symhdr
->iextMax
= 0;
2784 symhdr
->issExtMax
= 0;
2785 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2786 debug
->ssext
= debug
->ssext_end
= NULL
;
2787 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2788 (((abfd
->flags
& EXEC_P
) == 0)
2790 ecoff_get_extr
, ecoff_set_index
)
2794 /* Write out the relocs. */
2795 for (current
= abfd
->sections
;
2796 current
!= (asection
*) NULL
;
2797 current
= current
->next
)
2799 arelent
**reloc_ptr_ptr
;
2800 arelent
**reloc_end
;
2803 if (current
->reloc_count
== 0)
2807 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2808 if (reloc_buff
== NULL
)
2810 bfd_set_error (bfd_error_no_memory
);
2814 reloc_ptr_ptr
= current
->orelocation
;
2815 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2816 out_ptr
= (char *) reloc_buff
;
2818 reloc_ptr_ptr
< reloc_end
;
2819 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2823 struct internal_reloc in
;
2825 memset ((PTR
) &in
, 0, sizeof in
);
2827 reloc
= *reloc_ptr_ptr
;
2828 sym
= *reloc
->sym_ptr_ptr
;
2830 in
.r_vaddr
= (reloc
->address
2831 + bfd_get_section_vma (abfd
, current
));
2832 in
.r_type
= reloc
->howto
->type
;
2834 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2836 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2843 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2844 if (strcmp (name
, ".text") == 0)
2845 in
.r_symndx
= RELOC_SECTION_TEXT
;
2846 else if (strcmp (name
, ".rdata") == 0)
2847 in
.r_symndx
= RELOC_SECTION_RDATA
;
2848 else if (strcmp (name
, ".data") == 0)
2849 in
.r_symndx
= RELOC_SECTION_DATA
;
2850 else if (strcmp (name
, ".sdata") == 0)
2851 in
.r_symndx
= RELOC_SECTION_SDATA
;
2852 else if (strcmp (name
, ".sbss") == 0)
2853 in
.r_symndx
= RELOC_SECTION_SBSS
;
2854 else if (strcmp (name
, ".bss") == 0)
2855 in
.r_symndx
= RELOC_SECTION_BSS
;
2856 else if (strcmp (name
, ".init") == 0)
2857 in
.r_symndx
= RELOC_SECTION_INIT
;
2858 else if (strcmp (name
, ".lit8") == 0)
2859 in
.r_symndx
= RELOC_SECTION_LIT8
;
2860 else if (strcmp (name
, ".lit4") == 0)
2861 in
.r_symndx
= RELOC_SECTION_LIT4
;
2862 else if (strcmp (name
, ".xdata") == 0)
2863 in
.r_symndx
= RELOC_SECTION_XDATA
;
2864 else if (strcmp (name
, ".pdata") == 0)
2865 in
.r_symndx
= RELOC_SECTION_PDATA
;
2866 else if (strcmp (name
, ".fini") == 0)
2867 in
.r_symndx
= RELOC_SECTION_FINI
;
2868 else if (strcmp (name
, ".lita") == 0)
2869 in
.r_symndx
= RELOC_SECTION_LITA
;
2870 else if (strcmp (name
, "*ABS*") == 0)
2871 in
.r_symndx
= RELOC_SECTION_ABS
;
2877 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2879 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2882 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2884 if (bfd_write (reloc_buff
,
2885 external_reloc_size
, current
->reloc_count
, abfd
)
2886 != external_reloc_size
* current
->reloc_count
)
2888 bfd_release (abfd
, reloc_buff
);
2892 /* Write out the symbolic debugging information. */
2893 if (bfd_get_symcount (abfd
) > 0)
2895 /* Write out the debugging information. */
2896 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2897 ecoff_data (abfd
)->sym_filepos
)
2903 /* The .bss section of a demand paged executable must receive an
2904 entire page. If there are symbols, the symbols will start on the
2905 next page. If there are no symbols, we must fill out the page by
2907 if (bfd_get_symcount (abfd
) == 0
2908 && (abfd
->flags
& EXEC_P
) != 0
2909 && (abfd
->flags
& D_PAGED
) != 0)
2913 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2916 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2918 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2921 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2925 if (reloc_buff
!= NULL
)
2926 bfd_release (abfd
, reloc_buff
);
2931 if (reloc_buff
!= NULL
)
2932 bfd_release (abfd
, reloc_buff
);
2938 /* Archive handling. ECOFF uses what appears to be a unique type of
2939 archive header (armap). The byte ordering of the armap and the
2940 contents are encoded in the name of the armap itself. At least for
2941 now, we only support archives with the same byte ordering in the
2942 armap and the contents.
2944 The first four bytes in the armap are the number of symbol
2945 definitions. This is always a power of two.
2947 This is followed by the symbol definitions. Each symbol definition
2948 occupies 8 bytes. The first four bytes are the offset from the
2949 start of the armap strings to the null-terminated string naming
2950 this symbol. The second four bytes are the file offset to the
2951 archive member which defines this symbol. If the second four bytes
2952 are 0, then this is not actually a symbol definition, and it should
2955 The symbols are hashed into the armap with a closed hashing scheme.
2956 See the functions below for the details of the algorithm.
2958 After the symbol definitions comes four bytes holding the size of
2959 the string table, followed by the string table itself. */
2961 /* The name of an archive headers looks like this:
2962 __________E[BL]E[BL]_ (with a trailing space).
2963 The trailing space is changed to an X if the archive is changed to
2964 indicate that the armap is out of date.
2966 The Alpha seems to use ________64E[BL]E[BL]_. */
2968 #define ARMAP_BIG_ENDIAN 'B'
2969 #define ARMAP_LITTLE_ENDIAN 'L'
2970 #define ARMAP_MARKER 'E'
2971 #define ARMAP_START_LENGTH 10
2972 #define ARMAP_HEADER_MARKER_INDEX 10
2973 #define ARMAP_HEADER_ENDIAN_INDEX 11
2974 #define ARMAP_OBJECT_MARKER_INDEX 12
2975 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2976 #define ARMAP_END_INDEX 14
2977 #define ARMAP_END "_ "
2979 /* This is a magic number used in the hashing algorithm. */
2980 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2982 /* This returns the hash value to use for a string. It also sets
2983 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2984 is the number of entries in the hash table, and HLOG is the log
2988 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2990 unsigned int *rehash
;
2998 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2999 hash
*= ARMAP_HASH_MAGIC
;
3000 *rehash
= (hash
& (size
- 1)) | 1;
3001 return hash
>> (32 - hlog
);
3004 /* Read in the armap. */
3007 ecoff_slurp_armap (abfd
)
3012 struct areltdata
*mapdata
;
3013 bfd_size_type parsed_size
;
3015 struct artdata
*ardata
;
3018 struct symdef
*symdef_ptr
;
3021 /* Get the name of the first element. */
3022 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3028 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
3031 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3032 standard COFF armap. We could move the ECOFF armap stuff into
3033 bfd_slurp_armap, but that seems inappropriate since no other
3034 target uses this format. Instead, we check directly for a COFF
3036 if (strncmp (nextname
, "/ ", 16) == 0)
3037 return bfd_slurp_armap (abfd
);
3039 /* See if the first element is an armap. */
3040 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3041 ARMAP_START_LENGTH
) != 0
3042 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3043 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3044 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3045 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3046 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3047 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3048 || strncmp (nextname
+ ARMAP_END_INDEX
,
3049 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3051 bfd_has_map (abfd
) = false;
3055 /* Make sure we have the right byte ordering. */
3056 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3057 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3058 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3059 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3061 bfd_set_error (bfd_error_wrong_format
);
3065 /* Read in the armap. */
3066 ardata
= bfd_ardata (abfd
);
3067 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3068 if (mapdata
== (struct areltdata
*) NULL
)
3070 parsed_size
= mapdata
->parsed_size
;
3071 bfd_release (abfd
, (PTR
) mapdata
);
3073 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3074 if (raw_armap
== (char *) NULL
)
3076 bfd_set_error (bfd_error_no_memory
);
3080 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3082 if (bfd_get_error () != bfd_error_system_call
)
3083 bfd_set_error (bfd_error_malformed_archive
);
3084 bfd_release (abfd
, (PTR
) raw_armap
);
3088 ardata
->tdata
= (PTR
) raw_armap
;
3090 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3092 ardata
->symdef_count
= 0;
3093 ardata
->cache
= (struct ar_cache
*) NULL
;
3095 /* This code used to overlay the symdefs over the raw archive data,
3096 but that doesn't work on a 64 bit host. */
3098 stringbase
= raw_armap
+ count
* 8 + 8;
3100 #ifdef CHECK_ARMAP_HASH
3104 /* Double check that I have the hashing algorithm right by making
3105 sure that every symbol can be looked up successfully. */
3107 for (i
= 1; i
< count
; i
<<= 1)
3109 BFD_ASSERT (i
== count
);
3111 raw_ptr
= raw_armap
+ 4;
3112 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3114 unsigned int name_offset
, file_offset
;
3115 unsigned int hash
, rehash
, srch
;
3117 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3118 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3119 if (file_offset
== 0)
3121 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3126 /* See if we can rehash to this location. */
3127 for (srch
= (hash
+ rehash
) & (count
- 1);
3128 srch
!= hash
&& srch
!= i
;
3129 srch
= (srch
+ rehash
) & (count
- 1))
3130 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3132 BFD_ASSERT (srch
== i
);
3136 #endif /* CHECK_ARMAP_HASH */
3138 raw_ptr
= raw_armap
+ 4;
3139 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3140 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3141 ++ardata
->symdef_count
;
3143 symdef_ptr
= ((struct symdef
*)
3145 ardata
->symdef_count
* sizeof (struct symdef
)));
3148 bfd_set_error (bfd_error_no_memory
);
3152 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3154 raw_ptr
= raw_armap
+ 4;
3155 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3157 unsigned int name_offset
, file_offset
;
3159 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3160 if (file_offset
== 0)
3162 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3163 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3164 symdef_ptr
->file_offset
= file_offset
;
3168 ardata
->first_file_filepos
= bfd_tell (abfd
);
3169 /* Pad to an even boundary. */
3170 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3172 bfd_has_map (abfd
) = true;
3177 /* Write out an armap. */
3180 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3182 unsigned int elength
;
3184 unsigned int orl_count
;
3187 unsigned int hashsize
, hashlog
;
3188 unsigned int symdefsize
;
3190 unsigned int stringsize
;
3191 unsigned int mapsize
;
3194 struct stat statbuf
;
3197 bfd_byte
*hashtable
;
3201 /* Ultrix appears to use as a hash table size the least power of two
3202 greater than twice the number of entries. */
3203 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3205 hashsize
= 1 << hashlog
;
3207 symdefsize
= hashsize
* 8;
3209 stringsize
= stridx
+ padit
;
3211 /* Include 8 bytes to store symdefsize and stringsize in output. */
3212 mapsize
= symdefsize
+ stringsize
+ 8;
3214 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3216 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3218 /* Work out the ECOFF armap name. */
3219 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3220 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3221 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3222 (abfd
->xvec
->header_byteorder_big_p
3224 : ARMAP_LITTLE_ENDIAN
);
3225 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3226 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3227 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3228 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3230 /* Write the timestamp of the archive header to be just a little bit
3231 later than the timestamp of the file, otherwise the linker will
3232 complain that the index is out of date. Actually, the Ultrix
3233 linker just checks the archive name; the GNU linker may check the
3235 stat (abfd
->filename
, &statbuf
);
3236 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3238 /* The DECstation uses zeroes for the uid, gid and mode of the
3240 hdr
.ar_uid
[0] = '0';
3241 hdr
.ar_gid
[0] = '0';
3242 hdr
.ar_mode
[0] = '0';
3244 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3246 hdr
.ar_fmag
[0] = '`';
3247 hdr
.ar_fmag
[1] = '\012';
3249 /* Turn all null bytes in the header into spaces. */
3250 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3251 if (((char *)(&hdr
))[i
] == '\0')
3252 (((char *)(&hdr
))[i
]) = ' ';
3254 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3255 != sizeof (struct ar_hdr
))
3258 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3259 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3262 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3265 bfd_set_error (bfd_error_no_memory
);
3269 current
= abfd
->archive_head
;
3271 for (i
= 0; i
< orl_count
; i
++)
3273 unsigned int hash
, rehash
;
3275 /* Advance firstreal to the file position of this archive
3277 if (((bfd
*) map
[i
].pos
) != last_elt
)
3281 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3282 firstreal
+= firstreal
% 2;
3283 current
= current
->next
;
3285 while (current
!= (bfd
*) map
[i
].pos
);
3290 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3291 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3295 /* The desired slot is already taken. */
3296 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3298 srch
= (srch
+ rehash
) & (hashsize
- 1))
3299 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3302 BFD_ASSERT (srch
!= hash
);
3307 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3308 (PTR
) (hashtable
+ hash
* 8));
3309 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3310 (PTR
) (hashtable
+ hash
* 8 + 4));
3313 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3316 bfd_release (abfd
, hashtable
);
3318 /* Now write the strings. */
3319 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3320 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3322 for (i
= 0; i
< orl_count
; i
++)
3326 len
= strlen (*map
[i
].name
) + 1;
3327 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3331 /* The spec sez this should be a newline. But in order to be
3332 bug-compatible for DECstation ar we use a null. */
3335 if (bfd_write ("", 1, 1, abfd
) != 1)
3342 /* See whether this BFD is an archive. If it is, read in the armap
3343 and the extended name table. */
3346 ecoff_archive_p (abfd
)
3349 char armag
[SARMAG
+ 1];
3351 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3352 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3354 if (bfd_get_error () != bfd_error_system_call
)
3355 bfd_set_error (bfd_error_wrong_format
);
3356 return (bfd_target
*) NULL
;
3359 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3360 involves a cast, we can't do it as the left operand of
3362 abfd
->tdata
.aout_ar_data
=
3363 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3365 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3367 bfd_set_error (bfd_error_no_memory
);
3368 return (bfd_target
*) NULL
;
3371 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3372 bfd_ardata (abfd
)->cache
= NULL
;
3373 bfd_ardata (abfd
)->archive_head
= NULL
;
3374 bfd_ardata (abfd
)->symdefs
= NULL
;
3375 bfd_ardata (abfd
)->extended_names
= NULL
;
3376 bfd_ardata (abfd
)->tdata
= NULL
;
3378 if (ecoff_slurp_armap (abfd
) == false
3379 || ecoff_slurp_extended_name_table (abfd
) == false)
3381 bfd_release (abfd
, bfd_ardata (abfd
));
3382 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3383 return (bfd_target
*) NULL
;
3389 /* ECOFF linker code. */
3391 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3392 PARAMS ((struct bfd_hash_entry
*entry
,
3393 struct bfd_hash_table
*table
,
3394 const char *string
));
3395 static boolean ecoff_link_add_archive_symbols
3396 PARAMS ((bfd
*, struct bfd_link_info
*));
3397 static boolean ecoff_link_check_archive_element
3398 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3399 static boolean ecoff_link_add_object_symbols
3400 PARAMS ((bfd
*, struct bfd_link_info
*));
3401 static boolean ecoff_link_add_externals
3402 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3404 /* Routine to create an entry in an ECOFF link hash table. */
3406 static struct bfd_hash_entry
*
3407 ecoff_link_hash_newfunc (entry
, table
, string
)
3408 struct bfd_hash_entry
*entry
;
3409 struct bfd_hash_table
*table
;
3412 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3414 /* Allocate the structure if it has not already been allocated by a
3416 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3417 ret
= ((struct ecoff_link_hash_entry
*)
3418 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3419 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3421 bfd_set_error (bfd_error_no_memory
);
3425 /* Call the allocation method of the superclass. */
3426 ret
= ((struct ecoff_link_hash_entry
*)
3427 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3432 /* Set local fields. */
3436 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3438 return (struct bfd_hash_entry
*) ret
;
3441 /* Create an ECOFF link hash table. */
3443 struct bfd_link_hash_table
*
3444 ecoff_bfd_link_hash_table_create (abfd
)
3447 struct ecoff_link_hash_table
*ret
;
3449 ret
= ((struct ecoff_link_hash_table
*)
3450 malloc (sizeof (struct ecoff_link_hash_table
)));
3453 bfd_set_error (bfd_error_no_memory
);
3456 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3457 ecoff_link_hash_newfunc
))
3460 return (struct bfd_link_hash_table
*) NULL
;
3465 /* Look up an entry in an ECOFF link hash table. */
3467 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3468 ((struct ecoff_link_hash_entry *) \
3469 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3471 /* Traverse an ECOFF link hash table. */
3473 #define ecoff_link_hash_traverse(table, func, info) \
3474 (bfd_link_hash_traverse \
3476 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3479 /* Get the ECOFF link hash table from the info structure. This is
3482 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3484 /* Given an ECOFF BFD, add symbols to the global hash table as
3488 ecoff_bfd_link_add_symbols (abfd
, info
)
3490 struct bfd_link_info
*info
;
3492 switch (bfd_get_format (abfd
))
3495 return ecoff_link_add_object_symbols (abfd
, info
);
3497 return ecoff_link_add_archive_symbols (abfd
, info
);
3499 bfd_set_error (bfd_error_wrong_format
);
3504 /* Add the symbols from an archive file to the global hash table.
3505 This looks through the undefined symbols, looks each one up in the
3506 archive hash table, and adds any associated object file. We do not
3507 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3508 already have a hash table, so there is no reason to construct
3512 ecoff_link_add_archive_symbols (abfd
, info
)
3514 struct bfd_link_info
*info
;
3516 const bfd_byte
*raw_armap
;
3517 struct bfd_link_hash_entry
**pundef
;
3518 unsigned int armap_count
;
3519 unsigned int armap_log
;
3521 const bfd_byte
*hashtable
;
3522 const char *stringbase
;
3524 if (! bfd_has_map (abfd
))
3526 bfd_set_error (bfd_error_no_symbols
);
3530 /* If we don't have any raw data for this archive, as can happen on
3531 Irix 4.0.5F, we call the generic routine.
3532 FIXME: We should be more clever about this, since someday tdata
3533 may get to something for a generic archive. */
3534 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3535 if (raw_armap
== (bfd_byte
*) NULL
)
3536 return (_bfd_generic_link_add_archive_symbols
3537 (abfd
, info
, ecoff_link_check_archive_element
));
3539 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3542 for (i
= 1; i
< armap_count
; i
<<= 1)
3544 BFD_ASSERT (i
== armap_count
);
3546 hashtable
= raw_armap
+ 4;
3547 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3549 /* Look through the list of undefined symbols. */
3550 pundef
= &info
->hash
->undefs
;
3551 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3553 struct bfd_link_hash_entry
*h
;
3554 unsigned int hash
, rehash
;
3555 unsigned int file_offset
;
3561 /* When a symbol is defined, it is not necessarily removed from
3563 if (h
->type
!= bfd_link_hash_undefined
3564 && h
->type
!= bfd_link_hash_common
)
3566 /* Remove this entry from the list, for general cleanliness
3567 and because we are going to look through the list again
3568 if we search any more libraries. We can't remove the
3569 entry if it is the tail, because that would lose any
3570 entries we add to the list later on. */
3571 if (*pundef
!= info
->hash
->undefs_tail
)
3572 *pundef
= (*pundef
)->next
;
3574 pundef
= &(*pundef
)->next
;
3578 /* Native ECOFF linkers do not pull in archive elements merely
3579 to satisfy common definitions, so neither do we. We leave
3580 them on the list, though, in case we are linking against some
3581 other object format. */
3582 if (h
->type
!= bfd_link_hash_undefined
)
3584 pundef
= &(*pundef
)->next
;
3588 /* Look for this symbol in the archive hash table. */
3589 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3592 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3593 if (file_offset
== 0)
3595 /* Nothing in this slot. */
3596 pundef
= &(*pundef
)->next
;
3600 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3601 if (name
[0] != h
->root
.string
[0]
3602 || strcmp (name
, h
->root
.string
) != 0)
3607 /* That was the wrong symbol. Try rehashing. */
3609 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3611 srch
= (srch
+ rehash
) & (armap_count
- 1))
3613 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3614 if (file_offset
== 0)
3616 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3617 if (name
[0] == h
->root
.string
[0]
3618 && strcmp (name
, h
->root
.string
) == 0)
3627 pundef
= &(*pundef
)->next
;
3634 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3635 if (element
== (bfd
*) NULL
)
3638 if (! bfd_check_format (element
, bfd_object
))
3641 /* Unlike the generic linker, we know that this element provides
3642 a definition for an undefined symbol and we know that we want
3643 to include it. We don't need to check anything. */
3644 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3646 if (! ecoff_link_add_object_symbols (element
, info
))
3649 pundef
= &(*pundef
)->next
;
3655 /* This is called if we used _bfd_generic_link_add_archive_symbols
3656 because we were not dealing with an ECOFF archive. */
3659 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3661 struct bfd_link_info
*info
;
3664 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3665 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3666 = backend
->debug_swap
.swap_ext_in
;
3668 bfd_size_type external_ext_size
;
3669 PTR external_ext
= NULL
;
3677 if (! ecoff_slurp_symbolic_header (abfd
))
3680 /* If there are no symbols, we don't want it. */
3681 if (bfd_get_symcount (abfd
) == 0)
3682 goto successful_return
;
3684 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3686 /* Read in the external symbols and external strings. */
3687 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3688 esize
= symhdr
->iextMax
* external_ext_size
;
3689 external_ext
= (PTR
) malloc (esize
);
3690 if (external_ext
== NULL
&& esize
!= 0)
3692 bfd_set_error (bfd_error_no_memory
);
3696 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3697 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3700 ssext
= (char *) malloc (symhdr
->issExtMax
);
3701 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3703 bfd_set_error (bfd_error_no_memory
);
3707 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3708 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3711 /* Look through the external symbols to see if they define some
3712 symbol that is currently undefined. */
3713 ext_ptr
= (char *) external_ext
;
3714 ext_end
= ext_ptr
+ esize
;
3715 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3720 struct bfd_link_hash_entry
*h
;
3722 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3724 /* See if this symbol defines something. */
3725 if (esym
.asym
.st
!= stGlobal
3726 && esym
.asym
.st
!= stLabel
3727 && esym
.asym
.st
!= stProc
)
3730 switch (esym
.asym
.sc
)
3753 name
= ssext
+ esym
.asym
.iss
;
3754 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3756 /* Unlike the generic linker, we do not pull in elements because
3757 of common symbols. */
3758 if (h
== (struct bfd_link_hash_entry
*) NULL
3759 || h
->type
!= bfd_link_hash_undefined
)
3762 /* Include this element. */
3763 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3765 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3769 goto successful_return
;
3773 if (external_ext
!= NULL
)
3774 free (external_ext
);
3779 if (external_ext
!= NULL
)
3780 free (external_ext
);
3786 /* Add symbols from an ECOFF object file to the global linker hash
3790 ecoff_link_add_object_symbols (abfd
, info
)
3792 struct bfd_link_info
*info
;
3795 bfd_size_type external_ext_size
;
3796 PTR external_ext
= NULL
;
3801 if (! ecoff_slurp_symbolic_header (abfd
))
3804 /* If there are no symbols, we don't want it. */
3805 if (bfd_get_symcount (abfd
) == 0)
3808 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3810 /* Read in the external symbols and external strings. */
3811 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3812 esize
= symhdr
->iextMax
* external_ext_size
;
3813 external_ext
= (PTR
) malloc (esize
);
3814 if (external_ext
== NULL
&& esize
!= 0)
3816 bfd_set_error (bfd_error_no_memory
);
3820 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3821 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3824 ssext
= (char *) malloc (symhdr
->issExtMax
);
3825 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3827 bfd_set_error (bfd_error_no_memory
);
3831 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3832 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3835 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3839 if (external_ext
!= NULL
)
3840 free (external_ext
);
3846 if (external_ext
!= NULL
)
3847 free (external_ext
);
3851 /* Add the external symbols of an object file to the global linker
3852 hash table. The external symbols and strings we are passed are
3853 just allocated on the stack, and will be discarded. We must
3854 explicitly save any information we may need later on in the link.
3855 We do not want to read the external symbol information again. */
3858 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3860 struct bfd_link_info
*info
;
3864 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3865 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3866 = backend
->debug_swap
.swap_ext_in
;
3867 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3868 unsigned long ext_count
;
3869 struct ecoff_link_hash_entry
**sym_hash
;
3873 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3875 sym_hash
= ((struct ecoff_link_hash_entry
**)
3877 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3880 bfd_set_error (bfd_error_no_memory
);
3883 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3885 ext_ptr
= (char *) external_ext
;
3886 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3887 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3894 struct ecoff_link_hash_entry
*h
;
3898 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3900 /* Skip debugging symbols. */
3902 switch (esym
.asym
.st
)
3918 /* Get the information for this symbol. */
3919 value
= esym
.asym
.value
;
3920 switch (esym
.asym
.sc
)
3940 section
= bfd_make_section_old_way (abfd
, ".text");
3941 value
-= section
->vma
;
3944 section
= bfd_make_section_old_way (abfd
, ".data");
3945 value
-= section
->vma
;
3948 section
= bfd_make_section_old_way (abfd
, ".bss");
3949 value
-= section
->vma
;
3952 section
= &bfd_abs_section
;
3955 section
= &bfd_und_section
;
3958 section
= bfd_make_section_old_way (abfd
, ".sdata");
3959 value
-= section
->vma
;
3962 section
= bfd_make_section_old_way (abfd
, ".sbss");
3963 value
-= section
->vma
;
3966 section
= bfd_make_section_old_way (abfd
, ".rdata");
3967 value
-= section
->vma
;
3970 if (value
> ecoff_data (abfd
)->gp_size
)
3972 section
= &bfd_com_section
;
3977 if (ecoff_scom_section
.name
== NULL
)
3979 /* Initialize the small common section. */
3980 ecoff_scom_section
.name
= SCOMMON
;
3981 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3982 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3983 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3984 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3985 ecoff_scom_symbol
.name
= SCOMMON
;
3986 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3987 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3988 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3990 section
= &ecoff_scom_section
;
3993 section
= &bfd_und_section
;
3996 section
= bfd_make_section_old_way (abfd
, ".init");
3997 value
-= section
->vma
;
4000 section
= bfd_make_section_old_way (abfd
, ".fini");
4001 value
-= section
->vma
;
4005 if (section
== (asection
*) NULL
)
4008 name
= ssext
+ esym
.asym
.iss
;
4010 if (! (_bfd_generic_link_add_one_symbol
4011 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
4012 (const char *) NULL
, true, true,
4013 (struct bfd_link_hash_entry
**) &h
)))
4018 /* If we are building an ECOFF hash table, save the external
4019 symbol information. */
4020 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4022 if (h
->abfd
== (bfd
*) NULL
4023 || (section
!= &bfd_und_section
4024 && (! bfd_is_com_section (section
)
4025 || h
->root
.type
!= bfd_link_hash_defined
)))
4036 /* ECOFF final link routines. */
4038 static boolean ecoff_final_link_debug_accumulate
4039 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4041 static boolean ecoff_link_write_external
4042 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4043 static boolean ecoff_indirect_link_order
4044 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4045 struct bfd_link_order
*));
4046 static boolean ecoff_reloc_link_order
4047 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4048 struct bfd_link_order
*));
4050 /* ECOFF final link routine. This looks through all the input BFDs
4051 and gathers together all the debugging information, and then
4052 processes all the link order information. This may cause it to
4053 close and reopen some input BFDs; I'll see how bad this is. */
4056 ecoff_bfd_final_link (abfd
, info
)
4058 struct bfd_link_info
*info
;
4060 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4061 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4064 register bfd
*input_bfd
;
4066 struct bfd_link_order
*p
;
4068 /* We accumulate the debugging information counts in the symbolic
4070 symhdr
= &debug
->symbolic_header
;
4072 symhdr
->ilineMax
= 0;
4076 symhdr
->isymMax
= 0;
4077 symhdr
->ioptMax
= 0;
4078 symhdr
->iauxMax
= 0;
4080 symhdr
->issExtMax
= 0;
4083 symhdr
->iextMax
= 0;
4085 /* We accumulate the debugging information itself in the debug_info
4088 debug
->external_dnr
= NULL
;
4089 debug
->external_pdr
= NULL
;
4090 debug
->external_sym
= NULL
;
4091 debug
->external_opt
= NULL
;
4092 debug
->external_aux
= NULL
;
4094 debug
->ssext
= debug
->ssext_end
= NULL
;
4095 debug
->external_fdr
= NULL
;
4096 debug
->external_rfd
= NULL
;
4097 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4099 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4100 if (handle
== (PTR
) NULL
)
4103 /* Accumulate the debugging symbols from each input BFD. */
4104 for (input_bfd
= info
->input_bfds
;
4105 input_bfd
!= (bfd
*) NULL
;
4106 input_bfd
= input_bfd
->link_next
)
4110 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4112 /* Abitrarily set the symbolic header vstamp to the vstamp
4113 of the first object file in the link. */
4114 if (symhdr
->vstamp
== 0)
4116 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4117 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4121 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4122 debug
, &backend
->debug_swap
,
4127 /* Combine the register masks. */
4128 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4129 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4130 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4131 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4132 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4133 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4136 /* Write out the external symbols. */
4137 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4138 ecoff_link_write_external
,
4141 if (info
->relocateable
)
4143 /* We need to make a pass over the link_orders to count up the
4144 number of relocations we will need to output, so that we know
4145 how much space they will take up. */
4146 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4149 for (p
= o
->link_order_head
;
4150 p
!= (struct bfd_link_order
*) NULL
;
4152 if (p
->type
== bfd_indirect_link_order
)
4153 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4154 else if (p
->type
== bfd_section_reloc_link_order
4155 || p
->type
== bfd_symbol_reloc_link_order
)
4160 /* Compute the reloc and symbol file positions. */
4161 ecoff_compute_reloc_file_positions (abfd
);
4163 /* Write out the debugging information. */
4164 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4165 &backend
->debug_swap
, info
,
4166 ecoff_data (abfd
)->sym_filepos
))
4169 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4171 if (info
->relocateable
)
4173 /* Now reset the reloc_count field of the sections in the output
4174 BFD to 0, so that we can use them to keep track of how many
4175 relocs we have output thus far. */
4176 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4180 /* Get a value for the GP register. */
4181 if (ecoff_data (abfd
)->gp
== 0)
4183 struct bfd_link_hash_entry
*h
;
4185 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4186 if (h
!= (struct bfd_link_hash_entry
*) NULL
4187 && h
->type
== bfd_link_hash_defined
)
4188 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4189 + h
->u
.def
.section
->output_section
->vma
4190 + h
->u
.def
.section
->output_offset
);
4191 else if (info
->relocateable
)
4195 /* Make up a value. */
4197 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4200 && (strcmp (o
->name
, _SBSS
) == 0
4201 || strcmp (o
->name
, _SDATA
) == 0
4202 || strcmp (o
->name
, _LIT4
) == 0
4203 || strcmp (o
->name
, _LIT8
) == 0
4204 || strcmp (o
->name
, _LITA
) == 0))
4207 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4211 /* If the relocate_section function needs to do a reloc
4212 involving the GP value, it should make a reloc_dangerous
4213 callback to warn that GP is not defined. */
4217 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4219 /* Ignore any link_orders for the .reginfo section, which does
4220 not really exist. */
4221 if (strcmp (o
->name
, REGINFO
) == 0)
4224 for (p
= o
->link_order_head
;
4225 p
!= (struct bfd_link_order
*) NULL
;
4228 if (p
->type
== bfd_indirect_link_order
4229 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4230 == bfd_target_ecoff_flavour
))
4232 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4235 else if (p
->type
== bfd_section_reloc_link_order
4236 || p
->type
== bfd_symbol_reloc_link_order
)
4238 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4243 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4249 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4254 /* Accumulate the debugging information for an input BFD into the
4255 output BFD. This must read in the symbolic information of the
4259 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4262 struct bfd_link_info
*info
;
4265 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4266 const struct ecoff_debug_swap
* const swap
=
4267 &ecoff_backend (input_bfd
)->debug_swap
;
4268 HDRR
*symhdr
= &debug
->symbolic_header
;
4271 #define READ(ptr, offset, count, size, type) \
4272 if (symhdr->count == 0) \
4273 debug->ptr = NULL; \
4276 debug->ptr = (type) malloc (size * symhdr->count); \
4277 if (debug->ptr == NULL) \
4279 bfd_set_error (bfd_error_no_memory); \
4281 goto return_something; \
4283 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4285 || (bfd_read (debug->ptr, size, symhdr->count, \
4286 input_bfd) != size * symhdr->count)) \
4289 goto return_something; \
4293 /* If raw_syments is not NULL, then the data was already by read by
4294 ecoff_slurp_symbolic_info. */
4295 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4297 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4299 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4300 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4301 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4302 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4303 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4305 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4306 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4307 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4311 /* We do not read the external strings or the external symbols. */
4313 ret
= (bfd_ecoff_debug_accumulate
4314 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4315 &ecoff_backend (output_bfd
)->debug_swap
,
4316 input_bfd
, debug
, swap
, info
));
4319 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4321 if (debug
->line
!= NULL
)
4323 if (debug
->external_dnr
!= NULL
)
4324 free (debug
->external_dnr
);
4325 if (debug
->external_pdr
!= NULL
)
4326 free (debug
->external_pdr
);
4327 if (debug
->external_sym
!= NULL
)
4328 free (debug
->external_sym
);
4329 if (debug
->external_opt
!= NULL
)
4330 free (debug
->external_opt
);
4331 if (debug
->external_aux
!= NULL
)
4332 free (debug
->external_aux
);
4333 if (debug
->ss
!= NULL
)
4335 if (debug
->external_fdr
!= NULL
)
4336 free (debug
->external_fdr
);
4337 if (debug
->external_rfd
!= NULL
)
4338 free (debug
->external_rfd
);
4340 /* Make sure we don't accidentally follow one of these pointers
4341 into freed memory. */
4343 debug
->external_dnr
= NULL
;
4344 debug
->external_pdr
= NULL
;
4345 debug
->external_sym
= NULL
;
4346 debug
->external_opt
= NULL
;
4347 debug
->external_aux
= NULL
;
4349 debug
->external_fdr
= NULL
;
4350 debug
->external_rfd
= NULL
;
4356 /* Put out information for an external symbol. These come only from
4360 ecoff_link_write_external (h
, data
)
4361 struct ecoff_link_hash_entry
*h
;
4364 bfd
*output_bfd
= (bfd
*) data
;
4366 /* FIXME: We should check if this symbol is being stripped. */
4368 if (h
->root
.written
)
4371 if (h
->abfd
== (bfd
*) NULL
)
4374 h
->esym
.cobol_main
= 0;
4375 h
->esym
.weakext
= 0;
4376 h
->esym
.reserved
= 0;
4377 h
->esym
.ifd
= ifdNil
;
4378 h
->esym
.asym
.value
= 0;
4379 h
->esym
.asym
.st
= stGlobal
;
4381 if (h
->root
.type
!= bfd_link_hash_defined
)
4382 h
->esym
.asym
.sc
= scAbs
;
4385 asection
*output_section
;
4388 output_section
= h
->root
.u
.def
.section
->output_section
;
4389 name
= bfd_section_name (output_section
->owner
, output_section
);
4391 if (strcmp (name
, _TEXT
) == 0)
4392 h
->esym
.asym
.sc
= scText
;
4393 else if (strcmp (name
, _DATA
) == 0)
4394 h
->esym
.asym
.sc
= scData
;
4395 else if (strcmp (name
, _SDATA
) == 0)
4396 h
->esym
.asym
.sc
= scSData
;
4397 else if (strcmp (name
, _RDATA
) == 0)
4398 h
->esym
.asym
.sc
= scRData
;
4399 else if (strcmp (name
, _BSS
) == 0)
4400 h
->esym
.asym
.sc
= scBss
;
4401 else if (strcmp (name
, _SBSS
) == 0)
4402 h
->esym
.asym
.sc
= scSBss
;
4403 else if (strcmp (name
, _INIT
) == 0)
4404 h
->esym
.asym
.sc
= scInit
;
4405 else if (strcmp (name
, _FINI
) == 0)
4406 h
->esym
.asym
.sc
= scFini
;
4407 else if (strcmp (name
, _PDATA
) == 0)
4408 h
->esym
.asym
.sc
= scPData
;
4409 else if (strcmp (name
, _XDATA
) == 0)
4410 h
->esym
.asym
.sc
= scXData
;
4412 h
->esym
.asym
.sc
= scAbs
;
4415 h
->esym
.asym
.reserved
= 0;
4416 h
->esym
.asym
.index
= indexNil
;
4418 else if (h
->esym
.ifd
!= -1)
4420 struct ecoff_debug_info
*debug
;
4422 /* Adjust the FDR index for the symbol by that used for the
4424 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4425 BFD_ASSERT (h
->esym
.ifd
>= 0
4426 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4427 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4430 switch (h
->root
.type
)
4433 case bfd_link_hash_new
:
4435 case bfd_link_hash_undefined
:
4436 case bfd_link_hash_weak
:
4437 if (h
->esym
.asym
.sc
!= scUndefined
4438 && h
->esym
.asym
.sc
!= scSUndefined
)
4439 h
->esym
.asym
.sc
= scUndefined
;
4441 case bfd_link_hash_defined
:
4442 if (h
->esym
.asym
.sc
== scUndefined
4443 || h
->esym
.asym
.sc
== scSUndefined
)
4444 h
->esym
.asym
.sc
= scAbs
;
4445 else if (h
->esym
.asym
.sc
== scCommon
)
4446 h
->esym
.asym
.sc
= scBss
;
4447 else if (h
->esym
.asym
.sc
== scSCommon
)
4448 h
->esym
.asym
.sc
= scSBss
;
4449 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4450 + h
->root
.u
.def
.section
->output_section
->vma
4451 + h
->root
.u
.def
.section
->output_offset
);
4453 case bfd_link_hash_common
:
4454 if (h
->esym
.asym
.sc
!= scCommon
4455 && h
->esym
.asym
.sc
!= scSCommon
)
4456 h
->esym
.asym
.sc
= scCommon
;
4457 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4459 case bfd_link_hash_indirect
:
4460 case bfd_link_hash_warning
:
4461 /* FIXME: Ignore these for now. The circumstances under which
4462 they should be written out are not clear to me. */
4466 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4468 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4469 h
->root
.written
= true;
4471 return (bfd_ecoff_debug_one_external
4472 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4473 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4477 /* Relocate and write an ECOFF section into an ECOFF output file. */
4480 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4482 struct bfd_link_info
*info
;
4483 asection
*output_section
;
4484 struct bfd_link_order
*link_order
;
4486 asection
*input_section
;
4488 struct ecoff_section_tdata
*section_tdata
;
4489 bfd_size_type raw_size
;
4490 bfd_size_type cooked_size
;
4491 bfd_byte
*contents
= NULL
;
4492 bfd_size_type external_reloc_size
;
4493 bfd_size_type external_relocs_size
;
4494 PTR external_relocs
= NULL
;
4496 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4498 if (link_order
->size
== 0)
4501 input_section
= link_order
->u
.indirect
.section
;
4502 input_bfd
= input_section
->owner
;
4503 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4505 raw_size
= input_section
->_raw_size
;
4506 cooked_size
= input_section
->_cooked_size
;
4507 if (cooked_size
== 0)
4508 cooked_size
= raw_size
;
4510 BFD_ASSERT (input_section
->output_section
== output_section
);
4511 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4512 BFD_ASSERT (cooked_size
== link_order
->size
);
4514 /* Get the section contents. We allocate memory for the larger of
4515 the size before relocating and the size after relocating. */
4516 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4519 if (contents
== NULL
&& raw_size
!= 0)
4521 bfd_set_error (bfd_error_no_memory
);
4525 /* If we are relaxing, the contents may have already been read into
4526 memory, in which case we copy them into our new buffer. We don't
4527 simply reuse the old buffer in case cooked_size > raw_size. */
4528 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4529 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4530 memcpy (contents
, section_tdata
->contents
, raw_size
);
4533 if (! bfd_get_section_contents (input_bfd
, input_section
,
4535 (file_ptr
) 0, raw_size
))
4539 /* Get the relocs. If we are relaxing MIPS code, they will already
4540 have been read in. Otherwise, we read them in now. */
4541 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4542 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4544 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4545 external_relocs
= section_tdata
->external_relocs
;
4548 external_relocs
= (PTR
) malloc (external_relocs_size
);
4549 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4551 bfd_set_error (bfd_error_no_memory
);
4555 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4556 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4557 != external_relocs_size
))
4561 /* Relocate the section contents. */
4562 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4563 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4567 /* Write out the relocated section. */
4568 if (! bfd_set_section_contents (output_bfd
,
4571 input_section
->output_offset
,
4575 /* If we are producing relocateable output, the relocs were
4576 modified, and we write them out now. We use the reloc_count
4577 field of output_section to keep track of the number of relocs we
4578 have output so far. */
4579 if (info
->relocateable
)
4581 if (bfd_seek (output_bfd
,
4582 (output_section
->rel_filepos
+
4583 output_section
->reloc_count
* external_reloc_size
),
4585 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4586 != external_relocs_size
))
4588 output_section
->reloc_count
+= input_section
->reloc_count
;
4591 if (contents
!= NULL
)
4593 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4594 free (external_relocs
);
4598 if (contents
!= NULL
)
4600 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4601 free (external_relocs
);
4605 /* Generate a reloc when linking an ECOFF file. This is a reloc
4606 requested by the linker, and does come from any input file. This
4607 is used to build constructor and destructor tables when linking
4611 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4613 struct bfd_link_info
*info
;
4614 asection
*output_section
;
4615 struct bfd_link_order
*link_order
;
4618 struct internal_reloc in
;
4619 bfd_size_type external_reloc_size
;
4623 /* We set up an arelent to pass to the backend adjust_reloc_out
4625 rel
.address
= link_order
->offset
;
4627 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4628 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4630 bfd_set_error (bfd_error_bad_value
);
4634 if (link_order
->type
== bfd_section_reloc_link_order
)
4635 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4638 /* We can't set up a reloc against a symbol correctly, because
4639 we have no asymbol structure. Currently no adjust_reloc_out
4641 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4644 /* All ECOFF relocs are in-place. Put the addend into the object
4647 BFD_ASSERT (rel
.howto
->partial_inplace
);
4648 if (link_order
->u
.reloc
.p
->addend
!= 0)
4651 bfd_reloc_status_type rstat
;
4655 size
= bfd_get_reloc_size (rel
.howto
);
4656 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4657 if (buf
== (bfd_byte
*) NULL
)
4659 bfd_set_error (bfd_error_no_memory
);
4662 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4663 link_order
->u
.reloc
.p
->addend
, buf
);
4669 case bfd_reloc_outofrange
:
4671 case bfd_reloc_overflow
:
4672 if (! ((*info
->callbacks
->reloc_overflow
)
4674 (link_order
->type
== bfd_section_reloc_link_order
4675 ? bfd_section_name (output_bfd
,
4676 link_order
->u
.reloc
.p
->u
.section
)
4677 : link_order
->u
.reloc
.p
->u
.name
),
4678 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4679 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4686 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4687 (file_ptr
) link_order
->offset
, size
);
4695 /* Move the information into a internal_reloc structure. */
4696 in
.r_vaddr
= (rel
.address
4697 + bfd_get_section_vma (output_bfd
, output_section
));
4698 in
.r_type
= rel
.howto
->type
;
4700 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4702 struct ecoff_link_hash_entry
*h
;
4704 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4705 link_order
->u
.reloc
.p
->u
.name
,
4706 false, false, true);
4707 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4709 in
.r_symndx
= h
->indx
;
4712 if (! ((*info
->callbacks
->unattached_reloc
)
4713 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4714 (asection
*) NULL
, (bfd_vma
) 0)))
4724 name
= bfd_get_section_name (output_bfd
,
4725 link_order
->u
.reloc
.p
->u
.section
);
4726 if (strcmp (name
, ".text") == 0)
4727 in
.r_symndx
= RELOC_SECTION_TEXT
;
4728 else if (strcmp (name
, ".rdata") == 0)
4729 in
.r_symndx
= RELOC_SECTION_RDATA
;
4730 else if (strcmp (name
, ".data") == 0)
4731 in
.r_symndx
= RELOC_SECTION_DATA
;
4732 else if (strcmp (name
, ".sdata") == 0)
4733 in
.r_symndx
= RELOC_SECTION_SDATA
;
4734 else if (strcmp (name
, ".sbss") == 0)
4735 in
.r_symndx
= RELOC_SECTION_SBSS
;
4736 else if (strcmp (name
, ".bss") == 0)
4737 in
.r_symndx
= RELOC_SECTION_BSS
;
4738 else if (strcmp (name
, ".init") == 0)
4739 in
.r_symndx
= RELOC_SECTION_INIT
;
4740 else if (strcmp (name
, ".lit8") == 0)
4741 in
.r_symndx
= RELOC_SECTION_LIT8
;
4742 else if (strcmp (name
, ".lit4") == 0)
4743 in
.r_symndx
= RELOC_SECTION_LIT4
;
4744 else if (strcmp (name
, ".xdata") == 0)
4745 in
.r_symndx
= RELOC_SECTION_XDATA
;
4746 else if (strcmp (name
, ".pdata") == 0)
4747 in
.r_symndx
= RELOC_SECTION_PDATA
;
4748 else if (strcmp (name
, ".fini") == 0)
4749 in
.r_symndx
= RELOC_SECTION_FINI
;
4750 else if (strcmp (name
, ".lita") == 0)
4751 in
.r_symndx
= RELOC_SECTION_LITA
;
4752 else if (strcmp (name
, "*ABS*") == 0)
4753 in
.r_symndx
= RELOC_SECTION_ABS
;
4759 /* Let the BFD backend adjust the reloc. */
4760 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4762 /* Get some memory and swap out the reloc. */
4763 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4764 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4765 if (rbuf
== (bfd_byte
*) NULL
)
4767 bfd_set_error (bfd_error_no_memory
);
4771 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4773 ok
= (bfd_seek (output_bfd
,
4774 (output_section
->rel_filepos
+
4775 output_section
->reloc_count
* external_reloc_size
),
4777 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4778 == external_reloc_size
));
4781 ++output_section
->reloc_count
;