1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
48 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
49 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
50 asymbol
*asym
, int ext
,
51 asymbol
**indirect_ptr_ptr
));
52 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
53 RNDXR
*rndx
, long isym
,
55 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
56 unsigned int indx
, int bigendian
));
57 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
59 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
60 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
61 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
62 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
63 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
68 /* This stuff is somewhat copied from coffcode.h. */
70 static asection bfd_debug_section
= { "*DEBUG*" };
72 /* Create an ECOFF object. */
78 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
79 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
80 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
82 bfd_set_error (bfd_error_no_memory
);
89 /* This is a hook called by coff_real_object_p to create any backend
90 specific information. */
93 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
98 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
99 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
100 ecoff_data_type
*ecoff
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 /* Create the .reginfo section to give programs outside BFD a way to
111 see the information stored in the a.out header. See the comment
113 regsec
= bfd_make_section (abfd
, REGINFO
);
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 /* For the .pdata section, which has a special meaning on the Alpha,
160 we set the alignment to 8. We correct this later in
161 ecoff_compute_section_file_positions. We do this hackery because
162 we need to know the exact unaligned size of the .pdata section in
163 order to set the lnnoptr field correctly. */
164 if (strcmp (section
->name
, _PDATA
) == 0)
165 section
->alignment_power
= 3;
167 section
->alignment_power
= abfd
->xvec
->align_power_min
;
169 if (strcmp (section
->name
, _TEXT
) == 0)
170 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
171 else if (strcmp (section
->name
, _DATA
) == 0
172 || strcmp (section
->name
, _SDATA
) == 0)
173 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
174 else if (strcmp (section
->name
, _RDATA
) == 0
175 || strcmp (section
->name
, _LIT8
) == 0
176 || strcmp (section
->name
, _LIT4
) == 0)
177 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
178 else if (strcmp (section
->name
, _BSS
) == 0
179 || strcmp (section
->name
, _SBSS
) == 0)
180 section
->flags
|= SEC_ALLOC
;
181 else if (strcmp (section
->name
, REGINFO
) == 0)
183 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
184 section completely alone. */
185 section
->flags
|= (SEC_SHARED_LIBRARY
188 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
191 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
192 uncertain about .init on some systems and I don't know how shared
198 /* Determine the machine architecture and type. This is called from
199 the generic COFF routines. It is the inverse of ecoff_get_magic,
200 below. This could be an ECOFF backend routine, with one version
201 for each target, but there aren't all that many ECOFF targets. */
204 ecoff_set_arch_mach_hook (abfd
, filehdr
)
208 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
209 enum bfd_architecture arch
;
212 switch (internal_f
->f_magic
)
215 case MIPS_MAGIC_LITTLE
:
217 arch
= bfd_arch_mips
;
221 case MIPS_MAGIC_LITTLE2
:
222 case MIPS_MAGIC_BIG2
:
223 /* MIPS ISA level 2: the r6000 */
224 arch
= bfd_arch_mips
;
228 case MIPS_MAGIC_LITTLE3
:
229 case MIPS_MAGIC_BIG3
:
230 /* MIPS ISA level 3: the r4000 */
231 arch
= bfd_arch_mips
;
236 arch
= bfd_arch_alpha
;
241 arch
= bfd_arch_obscure
;
246 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
249 /* Get the magic number to use based on the architecture and machine.
250 This is the inverse of ecoff_set_arch_mach_hook, above. */
253 ecoff_get_magic (abfd
)
258 switch (bfd_get_arch (abfd
))
261 switch (bfd_get_mach (abfd
))
266 big
= MIPS_MAGIC_BIG
;
267 little
= MIPS_MAGIC_LITTLE
;
271 big
= MIPS_MAGIC_BIG2
;
272 little
= MIPS_MAGIC_LITTLE2
;
276 big
= MIPS_MAGIC_BIG3
;
277 little
= MIPS_MAGIC_LITTLE3
;
281 return abfd
->xvec
->byteorder_big_p
? big
: little
;
292 /* Get the section s_flags to use for a section. */
295 ecoff_sec_to_styp_flags (name
, flags
)
303 if (strcmp (name
, _TEXT
) == 0)
305 else if (strcmp (name
, _DATA
) == 0)
307 else if (strcmp (name
, _SDATA
) == 0)
309 else if (strcmp (name
, _RDATA
) == 0)
311 else if (strcmp (name
, _LITA
) == 0)
313 else if (strcmp (name
, _LIT8
) == 0)
315 else if (strcmp (name
, _LIT4
) == 0)
317 else if (strcmp (name
, _BSS
) == 0)
319 else if (strcmp (name
, _SBSS
) == 0)
321 else if (strcmp (name
, _INIT
) == 0)
322 styp
= STYP_ECOFF_INIT
;
323 else if (strcmp (name
, _FINI
) == 0)
324 styp
= STYP_ECOFF_FINI
;
325 else if (strcmp (name
, _PDATA
) == 0)
327 else if (strcmp (name
, _XDATA
) == 0)
329 else if (flags
& SEC_CODE
)
331 else if (flags
& SEC_DATA
)
333 else if (flags
& SEC_READONLY
)
335 else if (flags
& SEC_LOAD
)
340 if (flags
& SEC_NEVER_LOAD
)
346 /* Get the BFD flags to use for a section. */
350 ecoff_styp_to_sec_flags (abfd
, hdr
)
354 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
355 long styp_flags
= internal_s
->s_flags
;
356 flagword sec_flags
=0;
358 if (styp_flags
& STYP_NOLOAD
)
359 sec_flags
|= SEC_NEVER_LOAD
;
361 /* For 386 COFF, at least, an unloadable text or data section is
362 actually a shared library section. */
363 if ((styp_flags
& STYP_TEXT
)
364 || (styp_flags
& STYP_ECOFF_INIT
)
365 || (styp_flags
& STYP_ECOFF_FINI
))
367 if (sec_flags
& SEC_NEVER_LOAD
)
368 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
370 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
372 else if ((styp_flags
& STYP_DATA
)
373 || (styp_flags
& STYP_RDATA
)
374 || (styp_flags
& STYP_SDATA
)
375 || styp_flags
== STYP_PDATA
376 || styp_flags
== STYP_XDATA
)
378 if (sec_flags
& SEC_NEVER_LOAD
)
379 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
381 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
382 if ((styp_flags
& STYP_RDATA
)
383 || styp_flags
== STYP_PDATA
)
384 sec_flags
|= SEC_READONLY
;
386 else if ((styp_flags
& STYP_BSS
)
387 || (styp_flags
& STYP_SBSS
))
389 sec_flags
|= SEC_ALLOC
;
391 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
393 sec_flags
|= SEC_NEVER_LOAD
;
395 else if ((styp_flags
& STYP_LITA
)
396 || (styp_flags
& STYP_LIT8
)
397 || (styp_flags
& STYP_LIT4
))
399 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
403 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
409 /* Routines to swap auxiliary information in and out. I am assuming
410 that the auxiliary information format is always going to be target
413 /* Swap in a type information record.
414 BIGEND says whether AUX symbols are big-endian or little-endian; this
415 info comes from the file header record (fh-fBigendian). */
418 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
420 struct tir_ext
*ext_copy
;
423 struct tir_ext ext
[1];
425 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
427 /* now the fun stuff... */
429 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
430 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
431 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
432 >> TIR_BITS1_BT_SH_BIG
;
433 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
434 >> TIR_BITS_TQ4_SH_BIG
;
435 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
436 >> TIR_BITS_TQ5_SH_BIG
;
437 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
438 >> TIR_BITS_TQ0_SH_BIG
;
439 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
440 >> TIR_BITS_TQ1_SH_BIG
;
441 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
442 >> TIR_BITS_TQ2_SH_BIG
;
443 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
444 >> TIR_BITS_TQ3_SH_BIG
;
446 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
447 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
448 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
449 >> TIR_BITS1_BT_SH_LITTLE
;
450 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
451 >> TIR_BITS_TQ4_SH_LITTLE
;
452 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
453 >> TIR_BITS_TQ5_SH_LITTLE
;
454 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
455 >> TIR_BITS_TQ0_SH_LITTLE
;
456 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
457 >> TIR_BITS_TQ1_SH_LITTLE
;
458 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
459 >> TIR_BITS_TQ2_SH_LITTLE
;
460 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
461 >> TIR_BITS_TQ3_SH_LITTLE
;
465 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
470 /* Swap out a type information record.
471 BIGEND says whether AUX symbols are big-endian or little-endian; this
472 info comes from the file header record (fh-fBigendian). */
475 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
482 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
484 /* now the fun stuff... */
486 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
487 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
488 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
489 & TIR_BITS1_BT_BIG
));
490 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
492 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
493 & TIR_BITS_TQ5_BIG
));
494 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
496 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
497 & TIR_BITS_TQ1_BIG
));
498 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
500 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
501 & TIR_BITS_TQ3_BIG
));
503 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
504 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
505 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
506 & TIR_BITS1_BT_LITTLE
));
507 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
508 & TIR_BITS_TQ4_LITTLE
)
509 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
510 & TIR_BITS_TQ5_LITTLE
));
511 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
512 & TIR_BITS_TQ0_LITTLE
)
513 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
514 & TIR_BITS_TQ1_LITTLE
));
515 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
516 & TIR_BITS_TQ2_LITTLE
)
517 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
518 & TIR_BITS_TQ3_LITTLE
));
522 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
527 /* Swap in a relative symbol record. BIGEND says whether it is in
528 big-endian or little-endian format.*/
531 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
533 struct rndx_ext
*ext_copy
;
536 struct rndx_ext ext
[1];
538 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
540 /* now the fun stuff... */
542 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
543 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
544 >> RNDX_BITS1_RFD_SH_BIG
);
545 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
546 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
547 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
548 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
550 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
551 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
552 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
553 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
554 >> RNDX_BITS1_INDEX_SH_LITTLE
)
555 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
556 | ((unsigned int) ext
->r_bits
[3]
557 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
561 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
566 /* Swap out a relative symbol record. BIGEND says whether it is in
567 big-endian or little-endian format.*/
570 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
573 struct rndx_ext
*ext
;
577 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
579 /* now the fun stuff... */
581 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
582 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
583 & RNDX_BITS1_RFD_BIG
)
584 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
585 & RNDX_BITS1_INDEX_BIG
));
586 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
587 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
589 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
590 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
591 & RNDX_BITS1_RFD_LITTLE
)
592 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
593 & RNDX_BITS1_INDEX_LITTLE
));
594 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
595 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
599 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
604 /* Read in the symbolic header for an ECOFF object file. */
607 ecoff_slurp_symbolic_header (abfd
)
610 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
611 bfd_size_type external_hdr_size
;
613 HDRR
*internal_symhdr
;
615 /* See if we've already read it in. */
616 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
617 backend
->debug_swap
.sym_magic
)
620 /* See whether there is a symbolic header. */
621 if (ecoff_data (abfd
)->sym_filepos
== 0)
623 bfd_get_symcount (abfd
) = 0;
627 /* At this point bfd_get_symcount (abfd) holds the number of symbols
628 as read from the file header, but on ECOFF this is always the
629 size of the symbolic information header. It would be cleaner to
630 handle this when we first read the file in coffgen.c. */
631 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
632 if (bfd_get_symcount (abfd
) != external_hdr_size
)
634 bfd_set_error (bfd_error_bad_value
);
638 /* Read the symbolic information header. */
639 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
642 bfd_set_error (bfd_error_no_memory
);
646 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
647 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
648 != external_hdr_size
))
650 bfd_set_error (bfd_error_system_call
);
653 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
654 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
656 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
658 bfd_set_error (bfd_error_bad_value
);
662 /* Now we can get the correct number of symbols. */
663 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
664 + internal_symhdr
->iextMax
);
675 /* Read in and swap the important symbolic information for an ECOFF
676 object file. This is called by gdb. */
679 ecoff_slurp_symbolic_info (abfd
)
682 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
683 HDRR
*internal_symhdr
;
684 bfd_size_type raw_base
;
685 bfd_size_type raw_size
;
687 bfd_size_type external_fdr_size
;
691 bfd_size_type raw_end
;
692 bfd_size_type cb_end
;
694 /* Check whether we've already gotten it, and whether there's any to
696 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
698 if (ecoff_data (abfd
)->sym_filepos
== 0)
700 bfd_get_symcount (abfd
) = 0;
704 if (! ecoff_slurp_symbolic_header (abfd
))
707 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
709 /* Read all the symbolic information at once. */
710 raw_base
= (ecoff_data (abfd
)->sym_filepos
711 + backend
->debug_swap
.external_hdr_size
);
713 /* Alpha ecoff makes the determination of raw_size difficult. It has
714 an undocumented debug data section between the symhdr and the first
715 documented section. And the ordering of the sections varies between
716 statically and dynamically linked executables.
717 If bfd supports SEEK_END someday, this code could be simplified. */
721 #define UPDATE_RAW_END(start, count, size) \
722 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
723 if (cb_end > raw_end) \
726 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
727 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
728 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
729 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
730 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
731 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
732 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
733 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
734 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
735 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
736 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
738 #undef UPDATE_RAW_END
740 raw_size
= raw_end
- raw_base
;
743 ecoff_data (abfd
)->sym_filepos
= 0;
746 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
749 bfd_set_error (bfd_error_no_memory
);
753 (ecoff_data (abfd
)->sym_filepos
754 + backend
->debug_swap
.external_hdr_size
),
756 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
758 bfd_set_error (bfd_error_system_call
);
759 bfd_release (abfd
, raw
);
763 ecoff_data (abfd
)->raw_syments
= raw
;
765 /* Get pointers for the numeric offsets in the HDRR structure. */
766 #define FIX(off1, off2, type) \
767 if (internal_symhdr->off1 == 0) \
768 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
770 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
771 + internal_symhdr->off1 \
773 FIX (cbLineOffset
, line
, unsigned char *);
774 FIX (cbDnOffset
, external_dnr
, PTR
);
775 FIX (cbPdOffset
, external_pdr
, PTR
);
776 FIX (cbSymOffset
, external_sym
, PTR
);
777 FIX (cbOptOffset
, external_opt
, PTR
);
778 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
779 FIX (cbSsOffset
, ss
, char *);
780 FIX (cbSsExtOffset
, ssext
, char *);
781 FIX (cbFdOffset
, external_fdr
, PTR
);
782 FIX (cbRfdOffset
, external_rfd
, PTR
);
783 FIX (cbExtOffset
, external_ext
, PTR
);
786 /* I don't want to always swap all the data, because it will just
787 waste time and most programs will never look at it. The only
788 time the linker needs most of the debugging information swapped
789 is when linking big-endian and little-endian MIPS object files
790 together, which is not a common occurrence.
792 We need to look at the fdr to deal with a lot of information in
793 the symbols, so we swap them here. */
794 ecoff_data (abfd
)->debug_info
.fdr
=
795 (struct fdr
*) bfd_alloc (abfd
,
796 (internal_symhdr
->ifdMax
*
797 sizeof (struct fdr
)));
798 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
800 bfd_set_error (bfd_error_no_memory
);
803 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
804 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
805 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
806 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
807 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
808 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
813 /* ECOFF symbol table routines. The ECOFF symbol table is described
814 in gcc/mips-tfile.c. */
816 /* ECOFF uses two common sections. One is the usual one, and the
817 other is for small objects. All the small objects are kept
818 together, and then referenced via the gp pointer, which yields
819 faster assembler code. This is what we use for the small common
821 static asection ecoff_scom_section
;
822 static asymbol ecoff_scom_symbol
;
823 static asymbol
*ecoff_scom_symbol_ptr
;
825 /* Create an empty symbol. */
828 ecoff_make_empty_symbol (abfd
)
831 ecoff_symbol_type
*new;
833 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
834 if (new == (ecoff_symbol_type
*) NULL
)
836 bfd_set_error (bfd_error_no_memory
);
837 return (asymbol
*) NULL
;
839 memset ((PTR
) new, 0, sizeof *new);
840 new->symbol
.section
= (asection
*) NULL
;
841 new->fdr
= (FDR
*) NULL
;
844 new->symbol
.the_bfd
= abfd
;
848 /* Set the BFD flags and section for an ECOFF symbol. */
851 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
856 asymbol
**indirect_ptr_ptr
;
858 asym
->the_bfd
= abfd
;
859 asym
->value
= ecoff_sym
->value
;
860 asym
->section
= &bfd_debug_section
;
863 /* An indirect symbol requires two consecutive stabs symbols. */
864 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
866 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
868 /* @@ Stuffing pointers into integers is a no-no.
869 We can usually get away with it if the integer is
870 large enough though. */
871 if (sizeof (asym
) > sizeof (bfd_vma
))
873 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
875 asym
->flags
= BSF_DEBUGGING
;
876 asym
->section
= &bfd_und_section
;
877 *indirect_ptr_ptr
= NULL
;
881 if (ECOFF_IS_STAB (ecoff_sym
)
882 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
884 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
885 asym
->section
= &bfd_ind_section
;
886 /* Pass this symbol on to the next call to this function. */
887 *indirect_ptr_ptr
= asym
;
891 /* Most symbol types are just for debugging. */
892 switch (ecoff_sym
->st
)
901 if (ECOFF_IS_STAB (ecoff_sym
))
903 asym
->flags
= BSF_DEBUGGING
;
908 asym
->flags
= BSF_DEBUGGING
;
913 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
915 asym
->flags
= BSF_LOCAL
;
916 switch (ecoff_sym
->sc
)
919 /* Used for compiler generated labels. Leave them in the
920 debugging section, and mark them as local. If BSF_DEBUGGING
921 is set, then nm does not display them for some reason. If no
922 flags are set then the linker whines about them. */
923 asym
->flags
= BSF_LOCAL
;
926 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
927 asym
->value
-= asym
->section
->vma
;
930 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
931 asym
->value
-= asym
->section
->vma
;
934 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
935 asym
->value
-= asym
->section
->vma
;
938 asym
->flags
= BSF_DEBUGGING
;
941 asym
->section
= &bfd_abs_section
;
944 asym
->section
= &bfd_und_section
;
954 asym
->flags
= BSF_DEBUGGING
;
957 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
958 asym
->value
-= asym
->section
->vma
;
961 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
962 asym
->value
-= asym
->section
->vma
;
965 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
966 asym
->value
-= asym
->section
->vma
;
969 asym
->flags
= BSF_DEBUGGING
;
972 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
974 asym
->section
= &bfd_com_section
;
980 if (ecoff_scom_section
.name
== NULL
)
982 /* Initialize the small common section. */
983 ecoff_scom_section
.name
= SCOMMON
;
984 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
985 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
986 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
987 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
988 ecoff_scom_symbol
.name
= SCOMMON
;
989 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
990 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
991 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
993 asym
->section
= &ecoff_scom_section
;
998 asym
->flags
= BSF_DEBUGGING
;
1001 asym
->section
= &bfd_und_section
;
1006 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1007 asym
->value
-= asym
->section
->vma
;
1012 asym
->flags
= BSF_DEBUGGING
;
1015 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1016 asym
->value
-= asym
->section
->vma
;
1022 /* Look for special constructors symbols and make relocation entries
1023 in a special construction section. These are produced by the
1024 -fgnu-linker argument to g++. */
1025 if (ECOFF_IS_STAB (ecoff_sym
))
1027 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1039 arelent_chain
*reloc_chain
;
1040 unsigned int bitsize
;
1042 /* Get a section with the same name as the symbol (usually
1043 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1044 name ___CTOR_LIST (three underscores). We need
1045 __CTOR_LIST (two underscores), since ECOFF doesn't use
1046 a leading underscore. This should be handled by gcc,
1047 but instead we do it here. Actually, this should all
1048 be done differently anyhow. */
1049 name
= bfd_asymbol_name (asym
);
1050 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1055 section
= bfd_get_section_by_name (abfd
, name
);
1056 if (section
== (asection
*) NULL
)
1060 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1063 bfd_set_error (bfd_error_no_memory
);
1066 strcpy (copy
, name
);
1067 section
= bfd_make_section (abfd
, copy
);
1070 /* Build a reloc pointing to this constructor. */
1072 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1075 bfd_set_error (bfd_error_no_memory
);
1078 reloc_chain
->relent
.sym_ptr_ptr
=
1079 bfd_get_section (asym
)->symbol_ptr_ptr
;
1080 reloc_chain
->relent
.address
= section
->_raw_size
;
1081 reloc_chain
->relent
.addend
= asym
->value
;
1082 reloc_chain
->relent
.howto
=
1083 ecoff_backend (abfd
)->constructor_reloc
;
1085 /* Set up the constructor section to hold the reloc. */
1086 section
->flags
= SEC_CONSTRUCTOR
;
1087 ++section
->reloc_count
;
1089 /* Constructor sections must be rounded to a boundary
1090 based on the bitsize. These are not real sections--
1091 they are handled specially by the linker--so the ECOFF
1092 16 byte alignment restriction does not apply. */
1093 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1094 section
->alignment_power
= 1;
1095 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1096 ++section
->alignment_power
;
1098 reloc_chain
->next
= section
->constructor_chain
;
1099 section
->constructor_chain
= reloc_chain
;
1100 section
->_raw_size
+= bitsize
/ 8;
1102 /* Mark the symbol as a constructor. */
1103 asym
->flags
|= BSF_CONSTRUCTOR
;
1111 /* Read an ECOFF symbol table. */
1114 ecoff_slurp_symbol_table (abfd
)
1117 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1118 const bfd_size_type external_ext_size
1119 = backend
->debug_swap
.external_ext_size
;
1120 const bfd_size_type external_sym_size
1121 = backend
->debug_swap
.external_sym_size
;
1122 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1123 = backend
->debug_swap
.swap_ext_in
;
1124 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1125 = backend
->debug_swap
.swap_sym_in
;
1126 bfd_size_type internal_size
;
1127 ecoff_symbol_type
*internal
;
1128 ecoff_symbol_type
*internal_ptr
;
1129 asymbol
*indirect_ptr
;
1135 /* If we've already read in the symbol table, do nothing. */
1136 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1139 /* Get the symbolic information. */
1140 if (ecoff_slurp_symbolic_info (abfd
) == false)
1142 if (bfd_get_symcount (abfd
) == 0)
1145 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1146 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1147 if (internal
== NULL
)
1149 bfd_set_error (bfd_error_no_memory
);
1153 internal_ptr
= internal
;
1154 indirect_ptr
= NULL
;
1155 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1156 eraw_end
= (eraw_src
1157 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1158 * external_ext_size
));
1159 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1163 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1164 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1165 + internal_esym
.asym
.iss
);
1166 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1167 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1169 /* The alpha uses a negative ifd field for section symbols. */
1170 if (internal_esym
.ifd
>= 0)
1171 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1172 + internal_esym
.ifd
);
1174 internal_ptr
->fdr
= NULL
;
1175 internal_ptr
->local
= false;
1176 internal_ptr
->native
= (PTR
) eraw_src
;
1178 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1180 /* The local symbols must be accessed via the fdr's, because the
1181 string and aux indices are relative to the fdr information. */
1182 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1183 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1184 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1189 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1190 + fdr_ptr
->isymBase
* external_sym_size
);
1191 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1193 lraw_src
< lraw_end
;
1194 lraw_src
+= external_sym_size
, internal_ptr
++)
1198 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1199 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1201 + internal_sym
.iss
);
1202 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1203 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1205 internal_ptr
->fdr
= fdr_ptr
;
1206 internal_ptr
->local
= true;
1207 internal_ptr
->native
= (PTR
) lraw_src
;
1210 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1212 ecoff_data (abfd
)->canonical_symbols
= internal
;
1217 /* Return the amount of space needed for the canonical symbols. */
1220 ecoff_get_symtab_upper_bound (abfd
)
1223 if (ecoff_slurp_symbolic_info (abfd
) == false
1224 || bfd_get_symcount (abfd
) == 0)
1227 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1230 /* Get the canonical symbols. */
1233 ecoff_get_symtab (abfd
, alocation
)
1235 asymbol
**alocation
;
1237 unsigned int counter
= 0;
1238 ecoff_symbol_type
*symbase
;
1239 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1241 if (ecoff_slurp_symbol_table (abfd
) == false
1242 || bfd_get_symcount (abfd
) == 0)
1245 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1246 while (counter
< bfd_get_symcount (abfd
))
1248 *(location
++) = symbase
++;
1251 *location
++ = (ecoff_symbol_type
*) NULL
;
1252 return bfd_get_symcount (abfd
);
1255 /* Turn ECOFF type information into a printable string.
1256 ecoff_emit_aggregate and ecoff_type_to_string are from
1257 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1259 /* Write aggregate information to a string. */
1262 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1269 int ifd
= rndx
->rfd
;
1270 int indx
= rndx
->index
;
1271 int sym_base
, ss_base
;
1277 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1278 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1280 if (indx
== indexNil
)
1281 name
= "/* no name */";
1284 const struct ecoff_debug_swap
* const debug_swap
1285 = &ecoff_backend (abfd
)->debug_swap
;
1289 (*debug_swap
->swap_sym_in
)
1291 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1292 + indx
* debug_swap
->external_sym_size
),
1294 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1298 "%s %s { ifd = %d, index = %ld }",
1301 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1304 /* Convert the type information to string format. */
1307 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1309 union aux_ext
*aux_ptr
;
1321 unsigned int basic_type
;
1323 static char buffer1
[1024];
1324 static char buffer2
[1024];
1329 for (i
= 0; i
< 7; i
++)
1331 qualifiers
[i
].low_bound
= 0;
1332 qualifiers
[i
].high_bound
= 0;
1333 qualifiers
[i
].stride
= 0;
1336 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1337 return "-1 (no type)";
1338 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1340 basic_type
= u
.ti
.bt
;
1341 qualifiers
[0].type
= u
.ti
.tq0
;
1342 qualifiers
[1].type
= u
.ti
.tq1
;
1343 qualifiers
[2].type
= u
.ti
.tq2
;
1344 qualifiers
[3].type
= u
.ti
.tq3
;
1345 qualifiers
[4].type
= u
.ti
.tq4
;
1346 qualifiers
[5].type
= u
.ti
.tq5
;
1347 qualifiers
[6].type
= tqNil
;
1350 * Go get the basic type.
1354 case btNil
: /* undefined */
1358 case btAdr
: /* address - integer same size as pointer */
1359 strcpy (p1
, "address");
1362 case btChar
: /* character */
1363 strcpy (p1
, "char");
1366 case btUChar
: /* unsigned character */
1367 strcpy (p1
, "unsigned char");
1370 case btShort
: /* short */
1371 strcpy (p1
, "short");
1374 case btUShort
: /* unsigned short */
1375 strcpy (p1
, "unsigned short");
1378 case btInt
: /* int */
1382 case btUInt
: /* unsigned int */
1383 strcpy (p1
, "unsigned int");
1386 case btLong
: /* long */
1387 strcpy (p1
, "long");
1390 case btULong
: /* unsigned long */
1391 strcpy (p1
, "unsigned long");
1394 case btFloat
: /* float (real) */
1395 strcpy (p1
, "float");
1398 case btDouble
: /* Double (real) */
1399 strcpy (p1
, "double");
1402 /* Structures add 1-2 aux words:
1403 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1404 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1406 case btStruct
: /* Structure (Record) */
1407 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1408 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1409 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1411 indx
++; /* skip aux words */
1414 /* Unions add 1-2 aux words:
1415 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1416 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1418 case btUnion
: /* Union */
1419 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1420 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1421 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1423 indx
++; /* skip aux words */
1426 /* Enumerations add 1-2 aux words:
1427 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1428 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1430 case btEnum
: /* Enumeration */
1431 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1432 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1433 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1435 indx
++; /* skip aux words */
1438 case btTypedef
: /* defined via a typedef, isymRef points */
1439 strcpy (p1
, "typedef");
1442 case btRange
: /* subrange of int */
1443 strcpy (p1
, "subrange");
1446 case btSet
: /* pascal sets */
1450 case btComplex
: /* fortran complex */
1451 strcpy (p1
, "complex");
1454 case btDComplex
: /* fortran double complex */
1455 strcpy (p1
, "double complex");
1458 case btIndirect
: /* forward or unnamed typedef */
1459 strcpy (p1
, "forward/unamed typedef");
1462 case btFixedDec
: /* Fixed Decimal */
1463 strcpy (p1
, "fixed decimal");
1466 case btFloatDec
: /* Float Decimal */
1467 strcpy (p1
, "float decimal");
1470 case btString
: /* Varying Length Character String */
1471 strcpy (p1
, "string");
1474 case btBit
: /* Aligned Bit String */
1478 case btPicture
: /* Picture */
1479 strcpy (p1
, "picture");
1482 case btVoid
: /* Void */
1483 strcpy (p1
, "void");
1487 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1491 p1
+= strlen (buffer1
);
1494 * If this is a bitfield, get the bitsize.
1500 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1501 sprintf (p1
, " : %d", bitsize
);
1502 p1
+= strlen (buffer1
);
1507 * Deal with any qualifiers.
1509 if (qualifiers
[0].type
!= tqNil
)
1512 * Snarf up any array bounds in the correct order. Arrays
1513 * store 5 successive words in the aux. table:
1514 * word 0 RNDXR to type of the bounds (ie, int)
1515 * word 1 Current file descriptor index
1517 * word 3 high bound (or -1 if [])
1518 * word 4 stride size in bits
1520 for (i
= 0; i
< 7; i
++)
1522 if (qualifiers
[i
].type
== tqArray
)
1524 qualifiers
[i
].low_bound
=
1525 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1526 qualifiers
[i
].high_bound
=
1527 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1528 qualifiers
[i
].stride
=
1529 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1535 * Now print out the qualifiers.
1537 for (i
= 0; i
< 6; i
++)
1539 switch (qualifiers
[i
].type
)
1546 strcpy (p2
, "ptr to ");
1547 p2
+= sizeof ("ptr to ")-1;
1551 strcpy (p2
, "volatile ");
1552 p2
+= sizeof ("volatile ")-1;
1556 strcpy (p2
, "far ");
1557 p2
+= sizeof ("far ")-1;
1561 strcpy (p2
, "func. ret. ");
1562 p2
+= sizeof ("func. ret. ");
1567 int first_array
= i
;
1570 /* Print array bounds reversed (ie, in the order the C
1571 programmer writes them). C is such a fun language.... */
1573 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1576 for (j
= i
; j
>= first_array
; j
--)
1578 strcpy (p2
, "array [");
1579 p2
+= sizeof ("array [")-1;
1580 if (qualifiers
[j
].low_bound
!= 0)
1582 "%ld:%ld {%ld bits}",
1583 (long) qualifiers
[j
].low_bound
,
1584 (long) qualifiers
[j
].high_bound
,
1585 (long) qualifiers
[j
].stride
);
1587 else if (qualifiers
[j
].high_bound
!= -1)
1590 (long) (qualifiers
[j
].high_bound
+ 1),
1591 (long) (qualifiers
[j
].stride
));
1594 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1597 strcpy (p2
, "] of ");
1598 p2
+= sizeof ("] of ")-1;
1606 strcpy (p2
, buffer1
);
1610 /* Return information about ECOFF symbol SYMBOL in RET. */
1614 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1615 bfd
*abfd
; /* Ignored. */
1619 bfd_symbol_info (symbol
, ret
);
1622 /* Print information about an ECOFF symbol. */
1625 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1629 bfd_print_symbol_type how
;
1631 const struct ecoff_debug_swap
* const debug_swap
1632 = &ecoff_backend (abfd
)->debug_swap
;
1633 FILE *file
= (FILE *)filep
;
1637 case bfd_print_symbol_name
:
1638 fprintf (file
, "%s", symbol
->name
);
1640 case bfd_print_symbol_more
:
1641 if (ecoffsymbol (symbol
)->local
)
1645 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1647 fprintf (file
, "ecoff local ");
1648 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1649 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1650 (unsigned) ecoff_sym
.sc
);
1656 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1658 fprintf (file
, "ecoff extern ");
1659 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1660 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1661 (unsigned) ecoff_ext
.asym
.sc
);
1664 case bfd_print_symbol_all
:
1665 /* Print out the symbols in a reasonable way */
1674 if (ecoffsymbol (symbol
)->local
)
1676 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1679 pos
= ((((char *) ecoffsymbol (symbol
)->native
1680 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1681 / debug_swap
->external_sym_size
)
1682 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1689 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1692 pos
= (((char *) ecoffsymbol (symbol
)->native
1693 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1694 / debug_swap
->external_ext_size
);
1695 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1696 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1697 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1700 fprintf (file
, "[%3d] %c ",
1702 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1703 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1704 (unsigned) ecoff_ext
.asym
.st
,
1705 (unsigned) ecoff_ext
.asym
.sc
,
1706 (unsigned) ecoff_ext
.asym
.index
,
1707 jmptbl
, cobol_main
, weakext
,
1710 if (ecoffsymbol (symbol
)->fdr
!= NULL
1711 && ecoff_ext
.asym
.index
!= indexNil
)
1715 bfd_size_type sym_base
;
1716 union aux_ext
*aux_base
;
1718 indx
= ecoff_ext
.asym
.index
;
1720 /* sym_base is used to map the fdr relative indices which
1721 appear in the file to the position number which we are
1723 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1724 if (ecoffsymbol (symbol
)->local
)
1726 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1728 /* aux_base is the start of the aux entries for this file;
1729 asym.index is an offset from this. */
1730 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1731 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1733 /* The aux entries are stored in host byte order; the
1734 order is indicated by a bit in the fdr. */
1735 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1737 /* This switch is basically from gcc/mips-tdump.c */
1738 switch (ecoff_ext
.asym
.st
)
1746 fprintf (file
, "\n End+1 symbol: %ld",
1747 (long) (indx
+ sym_base
));
1751 if (ecoff_ext
.asym
.sc
== scText
1752 || ecoff_ext
.asym
.sc
== scInfo
)
1753 fprintf (file
, "\n First symbol: %ld",
1754 (long) (indx
+ sym_base
));
1756 fprintf (file
, "\n First symbol: %ld",
1757 (long) (AUX_GET_ISYM (bigendian
,
1758 &aux_base
[ecoff_ext
.asym
.index
])
1764 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1766 else if (ecoffsymbol (symbol
)->local
)
1767 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1768 (long) (AUX_GET_ISYM (bigendian
,
1769 &aux_base
[ecoff_ext
.asym
.index
])
1771 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1774 fprintf (file
, "\n Local symbol: %ld",
1777 + (ecoff_data (abfd
)
1778 ->debug_info
.symbolic_header
.iextMax
)));
1782 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1783 fprintf (file
, "\n Type: %s",
1784 ecoff_type_to_string (abfd
, aux_base
, indx
,
1794 /* Read in the relocs for a section. */
1797 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1802 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1803 arelent
*internal_relocs
;
1804 bfd_size_type external_reloc_size
;
1805 bfd_size_type external_relocs_size
;
1806 char *external_relocs
;
1810 if (section
->relocation
!= (arelent
*) NULL
1811 || section
->reloc_count
== 0
1812 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1815 if (ecoff_slurp_symbol_table (abfd
) == false)
1818 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1820 * section
->reloc_count
));
1821 external_reloc_size
= backend
->external_reloc_size
;
1822 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1823 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1824 if (internal_relocs
== (arelent
*) NULL
1825 || external_relocs
== (char *) NULL
)
1827 bfd_set_error (bfd_error_no_memory
);
1830 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1832 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1833 != external_relocs_size
)
1835 bfd_set_error (bfd_error_system_call
);
1839 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1841 struct internal_reloc intern
;
1843 (*backend
->swap_reloc_in
) (abfd
,
1844 external_relocs
+ i
* external_reloc_size
,
1847 if (intern
.r_extern
)
1849 /* r_symndx is an index into the external symbols. */
1850 BFD_ASSERT (intern
.r_symndx
>= 0
1852 < (ecoff_data (abfd
)
1853 ->debug_info
.symbolic_header
.iextMax
)));
1854 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1857 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1858 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1860 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1865 CONST
char *sec_name
;
1868 /* r_symndx is a section key. */
1869 switch (intern
.r_symndx
)
1871 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1872 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1873 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1874 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1875 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1876 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1877 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1878 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1879 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1880 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1881 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1882 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1883 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1887 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1888 if (sec
== (asection
*) NULL
)
1890 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1892 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1895 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1897 /* Let the backend select the howto field and do any other
1898 required processing. */
1899 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1902 bfd_release (abfd
, external_relocs
);
1904 section
->relocation
= internal_relocs
;
1909 /* Get a canonical list of relocs. */
1912 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1920 if (section
->flags
& SEC_CONSTRUCTOR
)
1922 arelent_chain
*chain
;
1924 /* This section has relocs made up by us, not the file, so take
1925 them out of their chain and place them into the data area
1927 for (count
= 0, chain
= section
->constructor_chain
;
1928 count
< section
->reloc_count
;
1929 count
++, chain
= chain
->next
)
1930 *relptr
++ = &chain
->relent
;
1936 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1939 tblptr
= section
->relocation
;
1940 if (tblptr
== (arelent
*) NULL
)
1943 for (count
= 0; count
< section
->reloc_count
; count
++)
1944 *relptr
++ = tblptr
++;
1947 *relptr
= (arelent
*) NULL
;
1949 return section
->reloc_count
;
1952 /* Provided a BFD, a section and an offset into the section, calculate
1953 and return the name of the source file and the line nearest to the
1958 ecoff_find_nearest_line (abfd
,
1967 asymbol
**ignore_symbols
;
1969 CONST
char **filename_ptr
;
1970 CONST
char **functionname_ptr
;
1971 unsigned int *retline_ptr
;
1973 const struct ecoff_debug_swap
* const debug_swap
1974 = &ecoff_backend (abfd
)->debug_swap
;
1979 bfd_size_type external_pdr_size
;
1983 unsigned char *line_ptr
;
1984 unsigned char *line_end
;
1987 /* If we're not in the .text section, we don't have any line
1989 if (strcmp (section
->name
, _TEXT
) != 0
1990 || offset
< ecoff_data (abfd
)->text_start
1991 || offset
>= ecoff_data (abfd
)->text_end
)
1994 /* Make sure we have the FDR's. */
1995 if (ecoff_slurp_symbolic_info (abfd
) == false
1996 || bfd_get_symcount (abfd
) == 0)
1999 /* Each file descriptor (FDR) has a memory address. Here we track
2000 down which FDR we want. The FDR's are stored in increasing
2001 memory order. If speed is ever important, this can become a
2002 binary search. We must ignore FDR's with no PDR entries; they
2003 will have the adr of the FDR before or after them. */
2004 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2005 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2006 fdr_hold
= (FDR
*) NULL
;
2007 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2009 if (fdr_ptr
->cpd
== 0)
2011 if (offset
< fdr_ptr
->adr
)
2015 if (fdr_hold
== (FDR
*) NULL
)
2019 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2020 have an address, which is relative to the FDR address, and are
2021 also stored in increasing memory order. */
2022 offset
-= fdr_ptr
->adr
;
2023 external_pdr_size
= debug_swap
->external_pdr_size
;
2024 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2025 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2026 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2027 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2029 /* The address of the first PDR is an offset which applies to the
2030 addresses of all the PDR's. */
2033 for (pdr_ptr
+= external_pdr_size
;
2035 pdr_ptr
+= external_pdr_size
)
2037 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2038 if (offset
< pdr
.adr
)
2042 /* Now we can look for the actual line number. The line numbers are
2043 stored in a very funky format, which I won't try to describe.
2044 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2045 we want; we need this to compute line_end. */
2046 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2047 if (pdr_ptr
== pdr_end
)
2048 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2050 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2052 /* Now change pdr and pdr_ptr to the one we want. */
2053 pdr_ptr
-= external_pdr_size
;
2054 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2058 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2059 + fdr_ptr
->cbLineOffset
2060 + pdr
.cbLineOffset
);
2061 while (line_ptr
< line_end
)
2066 delta
= *line_ptr
>> 4;
2069 count
= (*line_ptr
& 0xf) + 1;
2073 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2074 if (delta
>= 0x8000)
2079 if (offset
< count
* 4)
2081 offset
-= count
* 4;
2084 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2085 at least according to gdb/mipsread.c. */
2086 if (fdr_ptr
->rss
== -1)
2088 *filename_ptr
= NULL
;
2090 *functionname_ptr
= NULL
;
2095 (*debug_swap
->swap_ext_in
)
2097 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2098 + pdr
.isym
* debug_swap
->external_ext_size
),
2100 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2101 + proc_ext
.asym
.iss
);
2108 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2111 (*debug_swap
->swap_sym_in
)
2113 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2114 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2116 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2120 if (lineno
== ilineNil
)
2122 *retline_ptr
= lineno
;
2126 /* Set the architecture. The supported architecture is stored in the
2127 backend pointer. We always set the architecture anyhow, since many
2128 callers ignore the return value. */
2131 ecoff_set_arch_mach (abfd
, arch
, machine
)
2133 enum bfd_architecture arch
;
2134 unsigned long machine
;
2136 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2137 return arch
== ecoff_backend (abfd
)->arch
;
2140 /* Get the size of the section headers. We do not output the .reginfo
2145 ecoff_sizeof_headers (abfd
, reloc
)
2154 for (current
= abfd
->sections
;
2155 current
!= (asection
*)NULL
;
2156 current
= current
->next
)
2157 if (strcmp (current
->name
, REGINFO
) != 0)
2160 ret
= (bfd_coff_filhsz (abfd
)
2161 + bfd_coff_aoutsz (abfd
)
2162 + c
* bfd_coff_scnhsz (abfd
));
2163 return BFD_ALIGN (ret
, 16);
2166 /* Get the contents of a section. This is where we handle reading the
2167 .reginfo section, which implicitly holds the contents of an
2168 ecoff_reginfo structure. */
2171 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2176 bfd_size_type count
;
2178 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2179 struct ecoff_reginfo s
;
2182 if (strcmp (section
->name
, REGINFO
) != 0)
2183 return bfd_generic_get_section_contents (abfd
, section
, location
,
2186 s
.gp_value
= tdata
->gp
;
2187 s
.gprmask
= tdata
->gprmask
;
2188 for (i
= 0; i
< 4; i
++)
2189 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2190 s
.fprmask
= tdata
->fprmask
;
2192 /* bfd_get_section_contents has already checked that the offset and
2193 size is reasonable. We don't have to worry about swapping or any
2194 such thing; the .reginfo section is defined such that the
2195 contents are an ecoff_reginfo structure as seen on the host. */
2196 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2200 /* Calculate the file position for each section, and set
2204 ecoff_compute_section_file_positions (abfd
)
2212 sofar
= ecoff_sizeof_headers (abfd
, false);
2215 for (current
= abfd
->sections
;
2216 current
!= (asection
*) NULL
;
2217 current
= current
->next
)
2219 unsigned int alignment_power
;
2221 /* Only deal with sections which have contents */
2222 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2223 || strcmp (current
->name
, REGINFO
) == 0)
2226 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2227 supposed to indicate the number of .pdata entries that are
2228 really in the section. Each entry is 8 bytes. We store this
2229 away in line_filepos before increasing the section size. */
2230 if (strcmp (current
->name
, _PDATA
) != 0)
2231 alignment_power
= current
->alignment_power
;
2234 current
->line_filepos
= current
->_raw_size
/ 8;
2235 alignment_power
= 4;
2238 /* On Ultrix, the data sections in an executable file must be
2239 aligned to a page boundary within the file. This does not
2240 affect the section size, though. FIXME: Does this work for
2241 other platforms? It requires some modification for the
2242 Alpha, because .rdata on the Alpha goes with the text, not
2244 if ((abfd
->flags
& EXEC_P
) != 0
2245 && (abfd
->flags
& D_PAGED
) != 0
2246 && first_data
!= false
2247 && (current
->flags
& SEC_CODE
) == 0
2248 && (! ecoff_backend (abfd
)->rdata_in_text
2249 || strcmp (current
->name
, _RDATA
) != 0)
2250 && strcmp (current
->name
, _PDATA
) != 0)
2252 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2254 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2258 /* Align the sections in the file to the same boundary on
2259 which they are aligned in virtual memory. */
2261 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2263 current
->filepos
= sofar
;
2265 sofar
+= current
->_raw_size
;
2267 /* make sure that this section is of the right size too */
2269 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2270 current
->_raw_size
+= sofar
- old_sofar
;
2273 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2276 /* Determine the location of the relocs for all the sections in the
2277 output file, as well as the location of the symbolic debugging
2280 static bfd_size_type
2281 ecoff_compute_reloc_file_positions (abfd
)
2284 const bfd_size_type external_reloc_size
=
2285 ecoff_backend (abfd
)->external_reloc_size
;
2286 file_ptr reloc_base
;
2287 bfd_size_type reloc_size
;
2291 if (! abfd
->output_has_begun
)
2293 ecoff_compute_section_file_positions (abfd
);
2294 abfd
->output_has_begun
= true;
2297 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2300 for (current
= abfd
->sections
;
2301 current
!= (asection
*)NULL
;
2302 current
= current
->next
)
2304 if (strcmp (current
->name
, REGINFO
) == 0)
2306 if (current
->reloc_count
== 0)
2307 current
->rel_filepos
= 0;
2310 bfd_size_type relsize
;
2312 current
->rel_filepos
= reloc_base
;
2313 relsize
= current
->reloc_count
* external_reloc_size
;
2314 reloc_size
+= relsize
;
2315 reloc_base
+= relsize
;
2319 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2321 /* At least on Ultrix, the symbol table of an executable file must
2322 be aligned to a page boundary. FIXME: Is this true on other
2324 if ((abfd
->flags
& EXEC_P
) != 0
2325 && (abfd
->flags
& D_PAGED
) != 0)
2326 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2327 &~ (ecoff_backend (abfd
)->round
- 1));
2329 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2334 /* Set the contents of a section. This is where we handle setting the
2335 contents of the .reginfo section, which implicitly holds a
2336 ecoff_reginfo structure. */
2339 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2344 bfd_size_type count
;
2346 /* This must be done first, because bfd_set_section_contents is
2347 going to set output_has_begun to true. */
2348 if (abfd
->output_has_begun
== false)
2349 ecoff_compute_section_file_positions (abfd
);
2354 if (strcmp (section
->name
, REGINFO
) == 0)
2356 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2357 struct ecoff_reginfo s
;
2360 /* If the caller is only changing part of the structure, we must
2361 retrieve the current information before the memcpy. */
2362 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2364 s
.gp_value
= tdata
->gp
;
2365 s
.gprmask
= tdata
->gprmask
;
2366 for (i
= 0; i
< 4; i
++)
2367 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2368 s
.fprmask
= tdata
->fprmask
;
2371 /* bfd_set_section_contents has already checked that the offset
2372 and size is reasonable. We don't have to worry about
2373 swapping or any such thing; the .reginfo section is defined
2374 such that the contents are an ecoff_reginfo structure as seen
2376 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2378 tdata
->gp
= s
.gp_value
;
2379 tdata
->gprmask
= s
.gprmask
;
2380 for (i
= 0; i
< 4; i
++)
2381 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2382 tdata
->fprmask
= s
.fprmask
;
2387 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2388 || bfd_write (location
, 1, count
, abfd
) != count
)
2394 /* Get ECOFF EXTR information for an external symbol. This function
2395 is passed to bfd_ecoff_debug_externals. */
2398 ecoff_get_extr (sym
, esym
)
2402 ecoff_symbol_type
*ecoff_sym_ptr
;
2405 /* Don't include debugging, local or section symbols. */
2406 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2407 || (sym
->flags
& BSF_LOCAL
) != 0
2408 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2411 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2412 || ecoffsymbol (sym
)->native
== NULL
)
2415 esym
->cobol_main
= 0;
2419 /* FIXME: we can do better than this for st and sc. */
2420 esym
->asym
.st
= stGlobal
;
2421 esym
->asym
.sc
= scAbs
;
2422 esym
->asym
.reserved
= 0;
2423 esym
->asym
.index
= indexNil
;
2427 ecoff_sym_ptr
= ecoffsymbol (sym
);
2429 if (ecoff_sym_ptr
->local
)
2432 input_bfd
= bfd_asymbol_bfd (sym
);
2433 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2434 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2436 /* If the symbol was defined by the linker, then esym will be
2437 undefined but sym will not be. Get a better class for such a
2439 if ((esym
->asym
.sc
== scUndefined
2440 || esym
->asym
.sc
== scSUndefined
)
2441 && bfd_get_section (sym
) != &bfd_und_section
)
2442 esym
->asym
.sc
= scAbs
;
2444 /* Adjust the FDR index for the symbol by that used for the input
2446 if (esym
->ifd
!= -1)
2448 struct ecoff_debug_info
*input_debug
;
2450 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2451 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2452 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2453 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2459 /* Set the external symbol index. This routine is passed to
2460 bfd_ecoff_debug_externals. */
2463 ecoff_set_index (sym
, indx
)
2467 ecoff_set_sym_index (sym
, indx
);
2470 /* Write out an ECOFF file. */
2473 ecoff_write_object_contents (abfd
)
2476 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2477 const bfd_vma round
= backend
->round
;
2478 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2479 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2480 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2481 const bfd_size_type external_hdr_size
2482 = backend
->debug_swap
.external_hdr_size
;
2483 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2484 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2486 struct internal_reloc
*))
2487 = backend
->adjust_reloc_out
;
2488 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2489 const struct internal_reloc
*,
2491 = backend
->swap_reloc_out
;
2492 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2493 HDRR
* const symhdr
= &debug
->symbolic_header
;
2496 bfd_size_type reloc_size
;
2497 bfd_size_type text_size
;
2499 bfd_size_type data_size
;
2501 bfd_size_type bss_size
;
2503 PTR reloc_buff
= NULL
;
2504 struct internal_filehdr internal_f
;
2505 struct internal_aouthdr internal_a
;
2508 bfd_set_error (bfd_error_system_call
);
2510 /* Determine where the sections and relocs will go in the output
2512 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2515 for (current
= abfd
->sections
;
2516 current
!= (asection
*)NULL
;
2517 current
= current
->next
)
2519 if (strcmp (current
->name
, REGINFO
) == 0)
2521 current
->target_index
= count
;
2525 if ((abfd
->flags
& D_PAGED
) != 0)
2526 text_size
= ecoff_sizeof_headers (abfd
, false);
2534 /* Write section headers to the file. */
2536 /* Allocate buff big enough to hold a section header,
2537 file header, or a.out header. */
2545 buff
= (PTR
) malloc (siz
);
2548 bfd_set_error (bfd_error_no_memory
);
2553 internal_f
.f_nscns
= 0;
2554 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2556 for (current
= abfd
->sections
;
2557 current
!= (asection
*) NULL
;
2558 current
= current
->next
)
2560 struct internal_scnhdr section
;
2563 if (strcmp (current
->name
, REGINFO
) == 0)
2565 BFD_ASSERT (current
->reloc_count
== 0);
2569 ++internal_f
.f_nscns
;
2571 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2573 /* FIXME: is this correct for shared libraries? I think it is
2574 but I have no platform to check. Ian Lance Taylor. */
2575 vma
= bfd_get_section_vma (abfd
, current
);
2576 if (strcmp (current
->name
, _LIB
) == 0)
2577 section
.s_vaddr
= 0;
2579 section
.s_vaddr
= vma
;
2581 section
.s_paddr
= vma
;
2582 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2584 /* If this section is unloadable then the scnptr will be 0. */
2585 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2586 section
.s_scnptr
= 0;
2588 section
.s_scnptr
= current
->filepos
;
2589 section
.s_relptr
= current
->rel_filepos
;
2591 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2592 object file produced by the assembler is supposed to point to
2593 information about how much room is required by objects of
2594 various different sizes. I think this only matters if we
2595 want the linker to compute the best size to use, or
2596 something. I don't know what happens if the information is
2598 if (strcmp (current
->name
, _PDATA
) != 0)
2599 section
.s_lnnoptr
= 0;
2602 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2603 hold the number of entries in the section (each entry is
2604 8 bytes). We stored this in the line_filepos field in
2605 ecoff_compute_section_file_positions. */
2606 section
.s_lnnoptr
= current
->line_filepos
;
2609 section
.s_nreloc
= current
->reloc_count
;
2610 section
.s_nlnno
= 0;
2611 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2614 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2615 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2618 if ((section
.s_flags
& STYP_TEXT
) != 0
2619 || ((section
.s_flags
& STYP_RDATA
) != 0
2620 && backend
->rdata_in_text
)
2621 || strcmp (current
->name
, _PDATA
) == 0)
2623 text_size
+= bfd_get_section_size_before_reloc (current
);
2624 if (text_start
== 0 || text_start
> vma
)
2627 else if ((section
.s_flags
& STYP_RDATA
) != 0
2628 || (section
.s_flags
& STYP_DATA
) != 0
2629 || (section
.s_flags
& STYP_LITA
) != 0
2630 || (section
.s_flags
& STYP_LIT8
) != 0
2631 || (section
.s_flags
& STYP_LIT4
) != 0
2632 || (section
.s_flags
& STYP_SDATA
) != 0
2633 || strcmp (current
->name
, _XDATA
) == 0)
2635 data_size
+= bfd_get_section_size_before_reloc (current
);
2636 if (data_start
== 0 || data_start
> vma
)
2639 else if ((section
.s_flags
& STYP_BSS
) != 0
2640 || (section
.s_flags
& STYP_SBSS
) != 0)
2641 bss_size
+= bfd_get_section_size_before_reloc (current
);
2646 /* Set up the file header. */
2648 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2650 /* We will NOT put a fucking timestamp in the header here. Every
2651 time you put it back, I will come in and take it out again. I'm
2652 sorry. This field does not belong here. We fill it with a 0 so
2653 it compares the same but is not a reasonable time. --
2655 internal_f
.f_timdat
= 0;
2657 if (bfd_get_symcount (abfd
) != 0)
2659 /* The ECOFF f_nsyms field is not actually the number of
2660 symbols, it's the size of symbolic information header. */
2661 internal_f
.f_nsyms
= external_hdr_size
;
2662 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2666 internal_f
.f_nsyms
= 0;
2667 internal_f
.f_symptr
= 0;
2670 internal_f
.f_opthdr
= aoutsz
;
2672 internal_f
.f_flags
= F_LNNO
;
2673 if (reloc_size
== 0)
2674 internal_f
.f_flags
|= F_RELFLG
;
2675 if (bfd_get_symcount (abfd
) == 0)
2676 internal_f
.f_flags
|= F_LSYMS
;
2677 if (abfd
->flags
& EXEC_P
)
2678 internal_f
.f_flags
|= F_EXEC
;
2680 if (! abfd
->xvec
->byteorder_big_p
)
2681 internal_f
.f_flags
|= F_AR32WR
;
2683 internal_f
.f_flags
|= F_AR32W
;
2685 /* Set up the ``optional'' header. */
2686 if ((abfd
->flags
& D_PAGED
) != 0)
2687 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2689 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2691 /* FIXME: Is this really correct? */
2692 internal_a
.vstamp
= symhdr
->vstamp
;
2694 /* At least on Ultrix, these have to be rounded to page boundaries.
2695 FIXME: Is this true on other platforms? */
2696 if ((abfd
->flags
& D_PAGED
) != 0)
2698 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2699 internal_a
.text_start
= text_start
&~ (round
- 1);
2700 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2701 internal_a
.data_start
= data_start
&~ (round
- 1);
2705 internal_a
.tsize
= text_size
;
2706 internal_a
.text_start
= text_start
;
2707 internal_a
.dsize
= data_size
;
2708 internal_a
.data_start
= data_start
;
2711 /* On Ultrix, the initial portions of the .sbss and .bss segments
2712 are at the end of the data section. The bsize field in the
2713 optional header records how many bss bytes are required beyond
2714 those in the data section. The value is not rounded to a page
2716 if (bss_size
< internal_a
.dsize
- data_size
)
2719 bss_size
-= internal_a
.dsize
- data_size
;
2720 internal_a
.bsize
= bss_size
;
2721 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2723 internal_a
.entry
= bfd_get_start_address (abfd
);
2725 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2727 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2728 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2729 for (i
= 0; i
< 4; i
++)
2730 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2732 /* Write out the file header and the optional header. */
2734 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2737 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2738 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2741 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2742 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2745 /* Build the external symbol information. This must be done before
2746 writing out the relocs so that we know the symbol indices. The
2747 condition checks makes sure this object was not created by
2748 ecoff_bfd_final_link, since if it was we do not want to tamper
2749 with the external symbols. */
2750 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
)
2752 symhdr
->iextMax
= 0;
2753 symhdr
->issExtMax
= 0;
2754 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2755 debug
->ssext
= debug
->ssext_end
= NULL
;
2756 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2757 (((abfd
->flags
& EXEC_P
) == 0)
2759 ecoff_get_extr
, ecoff_set_index
)
2763 /* Write out the relocs. */
2764 for (current
= abfd
->sections
;
2765 current
!= (asection
*) NULL
;
2766 current
= current
->next
)
2768 arelent
**reloc_ptr_ptr
;
2769 arelent
**reloc_end
;
2772 if (current
->reloc_count
== 0)
2776 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2777 if (reloc_buff
== NULL
)
2779 bfd_set_error (bfd_error_no_memory
);
2783 reloc_ptr_ptr
= current
->orelocation
;
2784 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2785 out_ptr
= (char *) reloc_buff
;
2787 reloc_ptr_ptr
< reloc_end
;
2788 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2792 struct internal_reloc in
;
2794 memset ((PTR
) &in
, 0, sizeof in
);
2796 reloc
= *reloc_ptr_ptr
;
2797 sym
= *reloc
->sym_ptr_ptr
;
2799 in
.r_vaddr
= (reloc
->address
2800 + bfd_get_section_vma (abfd
, current
));
2801 in
.r_type
= reloc
->howto
->type
;
2803 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2805 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2812 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2813 if (strcmp (name
, ".text") == 0)
2814 in
.r_symndx
= RELOC_SECTION_TEXT
;
2815 else if (strcmp (name
, ".rdata") == 0)
2816 in
.r_symndx
= RELOC_SECTION_RDATA
;
2817 else if (strcmp (name
, ".data") == 0)
2818 in
.r_symndx
= RELOC_SECTION_DATA
;
2819 else if (strcmp (name
, ".sdata") == 0)
2820 in
.r_symndx
= RELOC_SECTION_SDATA
;
2821 else if (strcmp (name
, ".sbss") == 0)
2822 in
.r_symndx
= RELOC_SECTION_SBSS
;
2823 else if (strcmp (name
, ".bss") == 0)
2824 in
.r_symndx
= RELOC_SECTION_BSS
;
2825 else if (strcmp (name
, ".init") == 0)
2826 in
.r_symndx
= RELOC_SECTION_INIT
;
2827 else if (strcmp (name
, ".lit8") == 0)
2828 in
.r_symndx
= RELOC_SECTION_LIT8
;
2829 else if (strcmp (name
, ".lit4") == 0)
2830 in
.r_symndx
= RELOC_SECTION_LIT4
;
2831 else if (strcmp (name
, ".xdata") == 0)
2832 in
.r_symndx
= RELOC_SECTION_XDATA
;
2833 else if (strcmp (name
, ".pdata") == 0)
2834 in
.r_symndx
= RELOC_SECTION_PDATA
;
2835 else if (strcmp (name
, ".fini") == 0)
2836 in
.r_symndx
= RELOC_SECTION_FINI
;
2837 else if (strcmp (name
, ".lita") == 0)
2838 in
.r_symndx
= RELOC_SECTION_LITA
;
2839 else if (strcmp (name
, "*ABS*") == 0)
2840 in
.r_symndx
= RELOC_SECTION_ABS
;
2846 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2848 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2851 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2853 if (bfd_write (reloc_buff
,
2854 external_reloc_size
, current
->reloc_count
, abfd
)
2855 != external_reloc_size
* current
->reloc_count
)
2857 bfd_release (abfd
, reloc_buff
);
2861 /* Write out the symbolic debugging information. */
2862 if (bfd_get_symcount (abfd
) > 0)
2864 /* Write out the debugging information. */
2865 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2866 ecoff_data (abfd
)->sym_filepos
)
2872 /* The .bss section of a demand paged executable must receive an
2873 entire page. If there are symbols, the symbols will start on the
2874 next page. If there are no symbols, we must fill out the page by
2876 if (bfd_get_symcount (abfd
) == 0
2877 && (abfd
->flags
& EXEC_P
) != 0
2878 && (abfd
->flags
& D_PAGED
) != 0)
2882 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2885 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2887 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2890 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2894 if (reloc_buff
!= NULL
)
2895 bfd_release (abfd
, reloc_buff
);
2900 if (reloc_buff
!= NULL
)
2901 bfd_release (abfd
, reloc_buff
);
2907 /* Archive handling. ECOFF uses what appears to be a unique type of
2908 archive header (armap). The byte ordering of the armap and the
2909 contents are encoded in the name of the armap itself. At least for
2910 now, we only support archives with the same byte ordering in the
2911 armap and the contents.
2913 The first four bytes in the armap are the number of symbol
2914 definitions. This is always a power of two.
2916 This is followed by the symbol definitions. Each symbol definition
2917 occupies 8 bytes. The first four bytes are the offset from the
2918 start of the armap strings to the null-terminated string naming
2919 this symbol. The second four bytes are the file offset to the
2920 archive member which defines this symbol. If the second four bytes
2921 are 0, then this is not actually a symbol definition, and it should
2924 The symbols are hashed into the armap with a closed hashing scheme.
2925 See the functions below for the details of the algorithm.
2927 After the symbol definitions comes four bytes holding the size of
2928 the string table, followed by the string table itself. */
2930 /* The name of an archive headers looks like this:
2931 __________E[BL]E[BL]_ (with a trailing space).
2932 The trailing space is changed to an X if the archive is changed to
2933 indicate that the armap is out of date.
2935 The Alpha seems to use ________64E[BL]E[BL]_. */
2937 #define ARMAP_BIG_ENDIAN 'B'
2938 #define ARMAP_LITTLE_ENDIAN 'L'
2939 #define ARMAP_MARKER 'E'
2940 #define ARMAP_START_LENGTH 10
2941 #define ARMAP_HEADER_MARKER_INDEX 10
2942 #define ARMAP_HEADER_ENDIAN_INDEX 11
2943 #define ARMAP_OBJECT_MARKER_INDEX 12
2944 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2945 #define ARMAP_END_INDEX 14
2946 #define ARMAP_END "_ "
2948 /* This is a magic number used in the hashing algorithm. */
2949 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2951 /* This returns the hash value to use for a string. It also sets
2952 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2953 is the number of entries in the hash table, and HLOG is the log
2957 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2959 unsigned int *rehash
;
2967 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2968 hash
*= ARMAP_HASH_MAGIC
;
2969 *rehash
= (hash
& (size
- 1)) | 1;
2970 return hash
>> (32 - hlog
);
2973 /* Read in the armap. */
2976 ecoff_slurp_armap (abfd
)
2981 struct areltdata
*mapdata
;
2982 bfd_size_type parsed_size
;
2984 struct artdata
*ardata
;
2987 struct symdef
*symdef_ptr
;
2990 /* Get the name of the first element. */
2991 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2997 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2999 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3000 standard COFF armap. We could move the ECOFF armap stuff into
3001 bfd_slurp_armap, but that seems inappropriate since no other
3002 target uses this format. Instead, we check directly for a COFF
3004 if (strncmp (nextname
, "/ ", 16) == 0)
3005 return bfd_slurp_armap (abfd
);
3007 /* See if the first element is an armap. */
3008 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3009 ARMAP_START_LENGTH
) != 0
3010 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3011 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3012 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3013 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3014 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3015 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3016 || strncmp (nextname
+ ARMAP_END_INDEX
,
3017 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3019 bfd_has_map (abfd
) = false;
3023 /* Make sure we have the right byte ordering. */
3024 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3025 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3026 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3027 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3029 bfd_set_error (bfd_error_wrong_format
);
3033 /* Read in the armap. */
3034 ardata
= bfd_ardata (abfd
);
3035 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3036 if (mapdata
== (struct areltdata
*) NULL
)
3038 parsed_size
= mapdata
->parsed_size
;
3039 bfd_release (abfd
, (PTR
) mapdata
);
3041 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3042 if (raw_armap
== (char *) NULL
)
3044 bfd_set_error (bfd_error_no_memory
);
3048 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3050 bfd_set_error (bfd_error_malformed_archive
);
3051 bfd_release (abfd
, (PTR
) raw_armap
);
3055 ardata
->tdata
= (PTR
) raw_armap
;
3057 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3059 ardata
->symdef_count
= 0;
3060 ardata
->cache
= (struct ar_cache
*) NULL
;
3062 /* This code used to overlay the symdefs over the raw archive data,
3063 but that doesn't work on a 64 bit host. */
3065 stringbase
= raw_armap
+ count
* 8 + 8;
3067 #ifdef CHECK_ARMAP_HASH
3071 /* Double check that I have the hashing algorithm right by making
3072 sure that every symbol can be looked up successfully. */
3074 for (i
= 1; i
< count
; i
<<= 1)
3076 BFD_ASSERT (i
== count
);
3078 raw_ptr
= raw_armap
+ 4;
3079 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3081 unsigned int name_offset
, file_offset
;
3082 unsigned int hash
, rehash
, srch
;
3084 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3085 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3086 if (file_offset
== 0)
3088 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3093 /* See if we can rehash to this location. */
3094 for (srch
= (hash
+ rehash
) & (count
- 1);
3095 srch
!= hash
&& srch
!= i
;
3096 srch
= (srch
+ rehash
) & (count
- 1))
3097 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3099 BFD_ASSERT (srch
== i
);
3103 #endif /* CHECK_ARMAP_HASH */
3105 raw_ptr
= raw_armap
+ 4;
3106 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3107 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3108 ++ardata
->symdef_count
;
3110 symdef_ptr
= ((struct symdef
*)
3112 ardata
->symdef_count
* sizeof (struct symdef
)));
3115 bfd_set_error (bfd_error_no_memory
);
3119 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3121 raw_ptr
= raw_armap
+ 4;
3122 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3124 unsigned int name_offset
, file_offset
;
3126 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3127 if (file_offset
== 0)
3129 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3130 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3131 symdef_ptr
->file_offset
= file_offset
;
3135 ardata
->first_file_filepos
= bfd_tell (abfd
);
3136 /* Pad to an even boundary. */
3137 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3139 bfd_has_map (abfd
) = true;
3144 /* Write out an armap. */
3147 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3149 unsigned int elength
;
3151 unsigned int orl_count
;
3154 unsigned int hashsize
, hashlog
;
3155 unsigned int symdefsize
;
3157 unsigned int stringsize
;
3158 unsigned int mapsize
;
3161 struct stat statbuf
;
3164 bfd_byte
*hashtable
;
3168 /* Ultrix appears to use as a hash table size the least power of two
3169 greater than twice the number of entries. */
3170 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3172 hashsize
= 1 << hashlog
;
3174 symdefsize
= hashsize
* 8;
3176 stringsize
= stridx
+ padit
;
3178 /* Include 8 bytes to store symdefsize and stringsize in output. */
3179 mapsize
= symdefsize
+ stringsize
+ 8;
3181 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3183 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3185 /* Work out the ECOFF armap name. */
3186 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3187 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3188 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3189 (abfd
->xvec
->header_byteorder_big_p
3191 : ARMAP_LITTLE_ENDIAN
);
3192 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3193 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3194 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3195 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3197 /* Write the timestamp of the archive header to be just a little bit
3198 later than the timestamp of the file, otherwise the linker will
3199 complain that the index is out of date. Actually, the Ultrix
3200 linker just checks the archive name; the GNU linker may check the
3202 stat (abfd
->filename
, &statbuf
);
3203 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3205 /* The DECstation uses zeroes for the uid, gid and mode of the
3207 hdr
.ar_uid
[0] = '0';
3208 hdr
.ar_gid
[0] = '0';
3209 hdr
.ar_mode
[0] = '0';
3211 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3213 hdr
.ar_fmag
[0] = '`';
3214 hdr
.ar_fmag
[1] = '\012';
3216 /* Turn all null bytes in the header into spaces. */
3217 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3218 if (((char *)(&hdr
))[i
] == '\0')
3219 (((char *)(&hdr
))[i
]) = ' ';
3221 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3222 != sizeof (struct ar_hdr
))
3225 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3226 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3229 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3232 bfd_set_error (bfd_error_no_memory
);
3236 current
= abfd
->archive_head
;
3238 for (i
= 0; i
< orl_count
; i
++)
3240 unsigned int hash
, rehash
;
3242 /* Advance firstreal to the file position of this archive
3244 if (((bfd
*) map
[i
].pos
) != last_elt
)
3248 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3249 firstreal
+= firstreal
% 2;
3250 current
= current
->next
;
3252 while (current
!= (bfd
*) map
[i
].pos
);
3257 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3258 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3262 /* The desired slot is already taken. */
3263 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3265 srch
= (srch
+ rehash
) & (hashsize
- 1))
3266 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3269 BFD_ASSERT (srch
!= hash
);
3274 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3275 (PTR
) (hashtable
+ hash
* 8));
3276 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3277 (PTR
) (hashtable
+ hash
* 8 + 4));
3280 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3283 bfd_release (abfd
, hashtable
);
3285 /* Now write the strings. */
3286 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3287 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3289 for (i
= 0; i
< orl_count
; i
++)
3293 len
= strlen (*map
[i
].name
) + 1;
3294 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3298 /* The spec sez this should be a newline. But in order to be
3299 bug-compatible for DECstation ar we use a null. */
3302 if (bfd_write ("", 1, 1, abfd
) != 1)
3309 /* See whether this BFD is an archive. If it is, read in the armap
3310 and the extended name table. */
3313 ecoff_archive_p (abfd
)
3316 char armag
[SARMAG
+ 1];
3318 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3319 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3321 bfd_set_error (bfd_error_wrong_format
);
3322 return (bfd_target
*) NULL
;
3325 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3326 involves a cast, we can't do it as the left operand of
3328 abfd
->tdata
.aout_ar_data
=
3329 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3331 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3333 bfd_set_error (bfd_error_no_memory
);
3334 return (bfd_target
*) NULL
;
3337 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3338 bfd_ardata (abfd
)->cache
= NULL
;
3339 bfd_ardata (abfd
)->archive_head
= NULL
;
3340 bfd_ardata (abfd
)->symdefs
= NULL
;
3341 bfd_ardata (abfd
)->extended_names
= NULL
;
3342 bfd_ardata (abfd
)->tdata
= NULL
;
3344 if (ecoff_slurp_armap (abfd
) == false
3345 || ecoff_slurp_extended_name_table (abfd
) == false)
3347 bfd_release (abfd
, bfd_ardata (abfd
));
3348 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3349 return (bfd_target
*) NULL
;
3355 /* ECOFF linker code. */
3357 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3358 PARAMS ((struct bfd_hash_entry
*entry
,
3359 struct bfd_hash_table
*table
,
3360 const char *string
));
3361 static boolean ecoff_link_add_archive_symbols
3362 PARAMS ((bfd
*, struct bfd_link_info
*));
3363 static boolean ecoff_link_check_archive_element
3364 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3365 static boolean ecoff_link_add_object_symbols
3366 PARAMS ((bfd
*, struct bfd_link_info
*));
3367 static boolean ecoff_link_add_externals
3368 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3370 /* Routine to create an entry in an ECOFF link hash table. */
3372 static struct bfd_hash_entry
*
3373 ecoff_link_hash_newfunc (entry
, table
, string
)
3374 struct bfd_hash_entry
*entry
;
3375 struct bfd_hash_table
*table
;
3378 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3380 /* Allocate the structure if it has not already been allocated by a
3382 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3383 ret
= ((struct ecoff_link_hash_entry
*)
3384 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3385 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3387 bfd_set_error (bfd_error_no_memory
);
3391 /* Call the allocation method of the superclass. */
3392 ret
= ((struct ecoff_link_hash_entry
*)
3393 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3398 /* Set local fields. */
3402 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3404 return (struct bfd_hash_entry
*) ret
;
3407 /* Create an ECOFF link hash table. */
3409 struct bfd_link_hash_table
*
3410 ecoff_bfd_link_hash_table_create (abfd
)
3413 struct ecoff_link_hash_table
*ret
;
3415 ret
= ((struct ecoff_link_hash_table
*)
3416 malloc (sizeof (struct ecoff_link_hash_table
)));
3419 bfd_set_error (bfd_error_no_memory
);
3422 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3423 ecoff_link_hash_newfunc
))
3426 return (struct bfd_link_hash_table
*) NULL
;
3431 /* Look up an entry in an ECOFF link hash table. */
3433 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3434 ((struct ecoff_link_hash_entry *) \
3435 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3437 /* Traverse an ECOFF link hash table. */
3439 #define ecoff_link_hash_traverse(table, func, info) \
3440 (bfd_link_hash_traverse \
3442 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3445 /* Get the ECOFF link hash table from the info structure. This is
3448 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3450 /* Given an ECOFF BFD, add symbols to the global hash table as
3454 ecoff_bfd_link_add_symbols (abfd
, info
)
3456 struct bfd_link_info
*info
;
3458 switch (bfd_get_format (abfd
))
3461 return ecoff_link_add_object_symbols (abfd
, info
);
3463 return ecoff_link_add_archive_symbols (abfd
, info
);
3465 bfd_set_error (bfd_error_wrong_format
);
3470 /* Add the symbols from an archive file to the global hash table.
3471 This looks through the undefined symbols, looks each one up in the
3472 archive hash table, and adds any associated object file. We do not
3473 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3474 already have a hash table, so there is no reason to construct
3478 ecoff_link_add_archive_symbols (abfd
, info
)
3480 struct bfd_link_info
*info
;
3482 const bfd_byte
*raw_armap
;
3483 struct bfd_link_hash_entry
**pundef
;
3484 unsigned int armap_count
;
3485 unsigned int armap_log
;
3487 const bfd_byte
*hashtable
;
3488 const char *stringbase
;
3490 if (! bfd_has_map (abfd
))
3492 bfd_set_error (bfd_error_no_symbols
);
3496 /* If we don't have any raw data for this archive, as can happen on
3497 Irix 4.0.5F, we call the generic routine.
3498 FIXME: We should be more clever about this, since someday tdata
3499 may get to something for a generic archive. */
3500 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3501 if (raw_armap
== (bfd_byte
*) NULL
)
3502 return (_bfd_generic_link_add_archive_symbols
3503 (abfd
, info
, ecoff_link_check_archive_element
));
3505 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3508 for (i
= 1; i
< armap_count
; i
<<= 1)
3510 BFD_ASSERT (i
== armap_count
);
3512 hashtable
= raw_armap
+ 4;
3513 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3515 /* Look through the list of undefined symbols. */
3516 pundef
= &info
->hash
->undefs
;
3517 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3519 struct bfd_link_hash_entry
*h
;
3520 unsigned int hash
, rehash
;
3521 unsigned int file_offset
;
3527 /* When a symbol is defined, it is not necessarily removed from
3529 if (h
->type
!= bfd_link_hash_undefined
3530 && h
->type
!= bfd_link_hash_common
)
3532 /* Remove this entry from the list, for general cleanliness
3533 and because we are going to look through the list again
3534 if we search any more libraries. We can't remove the
3535 entry if it is the tail, because that would lose any
3536 entries we add to the list later on. */
3537 if (*pundef
!= info
->hash
->undefs_tail
)
3538 *pundef
= (*pundef
)->next
;
3540 pundef
= &(*pundef
)->next
;
3544 /* Native ECOFF linkers do not pull in archive elements merely
3545 to satisfy common definitions, so neither do we. We leave
3546 them on the list, though, in case we are linking against some
3547 other object format. */
3548 if (h
->type
!= bfd_link_hash_undefined
)
3550 pundef
= &(*pundef
)->next
;
3554 /* Look for this symbol in the archive hash table. */
3555 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3558 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3559 if (file_offset
== 0)
3561 /* Nothing in this slot. */
3562 pundef
= &(*pundef
)->next
;
3566 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3567 if (name
[0] != h
->root
.string
[0]
3568 || strcmp (name
, h
->root
.string
) != 0)
3573 /* That was the wrong symbol. Try rehashing. */
3575 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3577 srch
= (srch
+ rehash
) & (armap_count
- 1))
3579 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3580 if (file_offset
== 0)
3582 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3583 if (name
[0] == h
->root
.string
[0]
3584 && strcmp (name
, h
->root
.string
) == 0)
3593 pundef
= &(*pundef
)->next
;
3600 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3601 if (element
== (bfd
*) NULL
)
3604 if (! bfd_check_format (element
, bfd_object
))
3607 /* Unlike the generic linker, we know that this element provides
3608 a definition for an undefined symbol and we know that we want
3609 to include it. We don't need to check anything. */
3610 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3612 if (! ecoff_link_add_object_symbols (element
, info
))
3615 pundef
= &(*pundef
)->next
;
3621 /* This is called if we used _bfd_generic_link_add_archive_symbols
3622 because we were not dealing with an ECOFF archive. */
3625 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3627 struct bfd_link_info
*info
;
3630 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3631 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3632 = backend
->debug_swap
.swap_ext_in
;
3634 bfd_size_type external_ext_size
;
3635 PTR external_ext
= NULL
;
3643 if (! ecoff_slurp_symbolic_header (abfd
))
3646 /* If there are no symbols, we don't want it. */
3647 if (bfd_get_symcount (abfd
) == 0)
3648 goto successful_return
;
3650 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3652 /* Read in the external symbols and external strings. */
3653 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3654 esize
= symhdr
->iextMax
* external_ext_size
;
3655 external_ext
= (PTR
) malloc (esize
);
3656 if (external_ext
== NULL
&& esize
!= 0)
3658 bfd_set_error (bfd_error_no_memory
);
3662 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3663 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3666 ssext
= (char *) malloc (symhdr
->issExtMax
);
3667 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3669 bfd_set_error (bfd_error_no_memory
);
3673 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3674 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3677 /* Look through the external symbols to see if they define some
3678 symbol that is currently undefined. */
3679 ext_ptr
= (char *) external_ext
;
3680 ext_end
= ext_ptr
+ esize
;
3681 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3686 struct bfd_link_hash_entry
*h
;
3688 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3690 /* See if this symbol defines something. */
3691 if (esym
.asym
.st
!= stGlobal
3692 && esym
.asym
.st
!= stLabel
3693 && esym
.asym
.st
!= stProc
)
3696 switch (esym
.asym
.sc
)
3719 name
= ssext
+ esym
.asym
.iss
;
3720 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3722 /* Unlike the generic linker, we do not pull in elements because
3723 of common symbols. */
3724 if (h
== (struct bfd_link_hash_entry
*) NULL
3725 || h
->type
!= bfd_link_hash_undefined
)
3728 /* Include this element. */
3729 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3731 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3735 goto successful_return
;
3739 if (external_ext
!= NULL
)
3740 free (external_ext
);
3745 if (external_ext
!= NULL
)
3746 free (external_ext
);
3752 /* Add symbols from an ECOFF object file to the global linker hash
3756 ecoff_link_add_object_symbols (abfd
, info
)
3758 struct bfd_link_info
*info
;
3761 bfd_size_type external_ext_size
;
3762 PTR external_ext
= NULL
;
3767 if (! ecoff_slurp_symbolic_header (abfd
))
3770 /* If there are no symbols, we don't want it. */
3771 if (bfd_get_symcount (abfd
) == 0)
3774 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3776 /* Read in the external symbols and external strings. */
3777 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3778 esize
= symhdr
->iextMax
* external_ext_size
;
3779 external_ext
= (PTR
) malloc (esize
);
3780 if (external_ext
== NULL
&& esize
!= 0)
3782 bfd_set_error (bfd_error_no_memory
);
3786 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3787 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3790 ssext
= (char *) malloc (symhdr
->issExtMax
);
3791 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3793 bfd_set_error (bfd_error_no_memory
);
3797 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3798 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3801 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3805 if (external_ext
!= NULL
)
3806 free (external_ext
);
3812 if (external_ext
!= NULL
)
3813 free (external_ext
);
3817 /* Add the external symbols of an object file to the global linker
3818 hash table. The external symbols and strings we are passed are
3819 just allocated on the stack, and will be discarded. We must
3820 explicitly save any information we may need later on in the link.
3821 We do not want to read the external symbol information again. */
3824 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3826 struct bfd_link_info
*info
;
3830 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3831 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3832 = backend
->debug_swap
.swap_ext_in
;
3833 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3834 unsigned long ext_count
;
3835 struct ecoff_link_hash_entry
**sym_hash
;
3839 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3841 sym_hash
= ((struct ecoff_link_hash_entry
**)
3843 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3846 bfd_set_error (bfd_error_no_memory
);
3849 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3851 ext_ptr
= (char *) external_ext
;
3852 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3853 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3860 struct ecoff_link_hash_entry
*h
;
3864 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3866 /* Skip debugging symbols. */
3868 switch (esym
.asym
.st
)
3884 /* Get the information for this symbol. */
3885 value
= esym
.asym
.value
;
3886 switch (esym
.asym
.sc
)
3906 section
= bfd_make_section_old_way (abfd
, ".text");
3907 value
-= section
->vma
;
3910 section
= bfd_make_section_old_way (abfd
, ".data");
3911 value
-= section
->vma
;
3914 section
= bfd_make_section_old_way (abfd
, ".bss");
3915 value
-= section
->vma
;
3918 section
= &bfd_abs_section
;
3921 section
= &bfd_und_section
;
3924 section
= bfd_make_section_old_way (abfd
, ".sdata");
3925 value
-= section
->vma
;
3928 section
= bfd_make_section_old_way (abfd
, ".sbss");
3929 value
-= section
->vma
;
3932 section
= bfd_make_section_old_way (abfd
, ".rdata");
3933 value
-= section
->vma
;
3936 if (value
> ecoff_data (abfd
)->gp_size
)
3938 section
= &bfd_com_section
;
3943 if (ecoff_scom_section
.name
== NULL
)
3945 /* Initialize the small common section. */
3946 ecoff_scom_section
.name
= SCOMMON
;
3947 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3948 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3949 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3950 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3951 ecoff_scom_symbol
.name
= SCOMMON
;
3952 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3953 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3954 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3956 section
= &ecoff_scom_section
;
3959 section
= &bfd_und_section
;
3962 section
= bfd_make_section_old_way (abfd
, ".init");
3963 value
-= section
->vma
;
3966 section
= bfd_make_section_old_way (abfd
, ".fini");
3967 value
-= section
->vma
;
3971 if (section
== (asection
*) NULL
)
3974 name
= ssext
+ esym
.asym
.iss
;
3976 if (! (_bfd_generic_link_add_one_symbol
3977 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3978 (const char *) NULL
, true, true,
3979 (struct bfd_link_hash_entry
**) &h
)))
3984 /* If we are building an ECOFF hash table, save the external
3985 symbol information. */
3986 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3988 if (h
->abfd
== (bfd
*) NULL
3989 || (section
!= &bfd_und_section
3990 && (! bfd_is_com_section (section
)
3991 || h
->root
.type
!= bfd_link_hash_defined
)))
4002 /* ECOFF final link routines. */
4004 static boolean ecoff_final_link_debug_accumulate
4005 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4007 static boolean ecoff_link_write_external
4008 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4009 static boolean ecoff_indirect_link_order
4010 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4011 struct bfd_link_order
*));
4012 static boolean ecoff_reloc_link_order
4013 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4014 struct bfd_link_order
*));
4016 /* ECOFF final link routine. This looks through all the input BFDs
4017 and gathers together all the debugging information, and then
4018 processes all the link order information. This may cause it to
4019 close and reopen some input BFDs; I'll see how bad this is. */
4022 ecoff_bfd_final_link (abfd
, info
)
4024 struct bfd_link_info
*info
;
4026 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4027 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4030 register bfd
*input_bfd
;
4032 struct bfd_link_order
*p
;
4034 /* We accumulate the debugging information counts in the symbolic
4036 symhdr
= &debug
->symbolic_header
;
4038 symhdr
->ilineMax
= 0;
4042 symhdr
->isymMax
= 0;
4043 symhdr
->ioptMax
= 0;
4044 symhdr
->iauxMax
= 0;
4046 symhdr
->issExtMax
= 0;
4049 symhdr
->iextMax
= 0;
4051 /* We accumulate the debugging information itself in the debug_info
4054 debug
->external_dnr
= NULL
;
4055 debug
->external_pdr
= NULL
;
4056 debug
->external_sym
= NULL
;
4057 debug
->external_opt
= NULL
;
4058 debug
->external_aux
= NULL
;
4060 debug
->ssext
= debug
->ssext_end
= NULL
;
4061 debug
->external_fdr
= NULL
;
4062 debug
->external_rfd
= NULL
;
4063 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4065 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4066 if (handle
== (PTR
) NULL
)
4069 /* Accumulate the debugging symbols from each input BFD. */
4070 for (input_bfd
= info
->input_bfds
;
4071 input_bfd
!= (bfd
*) NULL
;
4072 input_bfd
= input_bfd
->link_next
)
4076 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4078 /* Abitrarily set the symbolic header vstamp to the vstamp
4079 of the first object file in the link. */
4080 if (symhdr
->vstamp
== 0)
4082 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4083 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4087 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4088 debug
, &backend
->debug_swap
,
4093 /* Combine the register masks. */
4094 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4095 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4096 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4097 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4098 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4099 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4102 /* Write out the external symbols. */
4103 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4104 ecoff_link_write_external
,
4107 if (info
->relocateable
)
4109 /* We need to make a pass over the link_orders to count up the
4110 number of relocations we will need to output, so that we know
4111 how much space they will take up. */
4112 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4115 for (p
= o
->link_order_head
;
4116 p
!= (struct bfd_link_order
*) NULL
;
4118 if (p
->type
== bfd_indirect_link_order
)
4119 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4120 else if (p
->type
== bfd_section_reloc_link_order
4121 || p
->type
== bfd_symbol_reloc_link_order
)
4126 /* Compute the reloc and symbol file positions. */
4127 ecoff_compute_reloc_file_positions (abfd
);
4129 /* Write out the debugging information. */
4130 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4131 &backend
->debug_swap
, info
,
4132 ecoff_data (abfd
)->sym_filepos
))
4135 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4137 if (info
->relocateable
)
4139 /* Now reset the reloc_count field of the sections in the output
4140 BFD to 0, so that we can use them to keep track of how many
4141 relocs we have output thus far. */
4142 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4146 /* Get a value for the GP register. */
4147 if (ecoff_data (abfd
)->gp
== 0)
4149 struct bfd_link_hash_entry
*h
;
4151 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4152 if (h
!= (struct bfd_link_hash_entry
*) NULL
4153 && h
->type
== bfd_link_hash_defined
)
4154 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4155 + h
->u
.def
.section
->output_section
->vma
4156 + h
->u
.def
.section
->output_offset
);
4157 else if (info
->relocateable
)
4161 /* Make up a value. */
4163 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4166 && (strcmp (o
->name
, _SBSS
) == 0
4167 || strcmp (o
->name
, _SDATA
) == 0
4168 || strcmp (o
->name
, _LIT4
) == 0
4169 || strcmp (o
->name
, _LIT8
) == 0
4170 || strcmp (o
->name
, _LITA
) == 0))
4173 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4177 /* If the relocate_section function needs to do a reloc
4178 involving the GP value, it should make a reloc_dangerous
4179 callback to warn that GP is not defined. */
4183 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4185 /* Ignore any link_orders for the .reginfo section, which does
4186 not really exist. */
4187 if (strcmp (o
->name
, REGINFO
) == 0)
4190 for (p
= o
->link_order_head
;
4191 p
!= (struct bfd_link_order
*) NULL
;
4194 if (p
->type
== bfd_indirect_link_order
4195 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4196 == bfd_target_ecoff_flavour
))
4198 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4201 else if (p
->type
== bfd_section_reloc_link_order
4202 || p
->type
== bfd_symbol_reloc_link_order
)
4204 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4209 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4215 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4220 /* Accumulate the debugging information for an input BFD into the
4221 output BFD. This must read in the symbolic information of the
4225 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4228 struct bfd_link_info
*info
;
4231 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4232 const struct ecoff_debug_swap
* const swap
=
4233 &ecoff_backend (input_bfd
)->debug_swap
;
4234 HDRR
*symhdr
= &debug
->symbolic_header
;
4237 #define READ(ptr, offset, count, size, type) \
4238 if (symhdr->count == 0) \
4239 debug->ptr = NULL; \
4242 debug->ptr = (type) malloc (size * symhdr->count); \
4243 if (debug->ptr == NULL) \
4245 bfd_set_error (bfd_error_no_memory); \
4247 goto return_something; \
4249 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4251 || (bfd_read (debug->ptr, size, symhdr->count, \
4252 input_bfd) != size * symhdr->count)) \
4255 goto return_something; \
4259 /* If raw_syments is not NULL, then the data was already by read by
4260 ecoff_slurp_symbolic_info. */
4261 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4263 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4265 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4266 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4267 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4268 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4269 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4271 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4272 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4273 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4277 /* We do not read the external strings or the external symbols. */
4279 ret
= (bfd_ecoff_debug_accumulate
4280 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4281 &ecoff_backend (output_bfd
)->debug_swap
,
4282 input_bfd
, debug
, swap
, info
));
4285 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4287 if (debug
->line
!= NULL
)
4289 if (debug
->external_dnr
!= NULL
)
4290 free (debug
->external_dnr
);
4291 if (debug
->external_pdr
!= NULL
)
4292 free (debug
->external_pdr
);
4293 if (debug
->external_sym
!= NULL
)
4294 free (debug
->external_sym
);
4295 if (debug
->external_opt
!= NULL
)
4296 free (debug
->external_opt
);
4297 if (debug
->external_aux
!= NULL
)
4298 free (debug
->external_aux
);
4299 if (debug
->ss
!= NULL
)
4301 if (debug
->external_fdr
!= NULL
)
4302 free (debug
->external_fdr
);
4303 if (debug
->external_rfd
!= NULL
)
4304 free (debug
->external_rfd
);
4306 /* Make sure we don't accidentally follow one of these pointers
4307 into freed memory. */
4309 debug
->external_dnr
= NULL
;
4310 debug
->external_pdr
= NULL
;
4311 debug
->external_sym
= NULL
;
4312 debug
->external_opt
= NULL
;
4313 debug
->external_aux
= NULL
;
4315 debug
->external_fdr
= NULL
;
4316 debug
->external_rfd
= NULL
;
4322 /* Put out information for an external symbol. These come only from
4326 ecoff_link_write_external (h
, data
)
4327 struct ecoff_link_hash_entry
*h
;
4330 bfd
*output_bfd
= (bfd
*) data
;
4332 /* FIXME: We should check if this symbol is being stripped. */
4334 if (h
->root
.written
)
4337 if (h
->abfd
== (bfd
*) NULL
)
4340 h
->esym
.cobol_main
= 0;
4341 h
->esym
.weakext
= 0;
4342 h
->esym
.reserved
= 0;
4343 h
->esym
.ifd
= ifdNil
;
4344 h
->esym
.asym
.value
= 0;
4345 h
->esym
.asym
.st
= stGlobal
;
4347 if (h
->root
.type
!= bfd_link_hash_defined
)
4348 h
->esym
.asym
.sc
= scAbs
;
4351 asection
*output_section
;
4354 output_section
= h
->root
.u
.def
.section
->output_section
;
4355 name
= bfd_section_name (output_section
->owner
, output_section
);
4357 if (strcmp (name
, _TEXT
) == 0)
4358 h
->esym
.asym
.sc
= scText
;
4359 else if (strcmp (name
, _DATA
) == 0)
4360 h
->esym
.asym
.sc
= scData
;
4361 else if (strcmp (name
, _SDATA
) == 0)
4362 h
->esym
.asym
.sc
= scSData
;
4363 else if (strcmp (name
, _RDATA
) == 0)
4364 h
->esym
.asym
.sc
= scRData
;
4365 else if (strcmp (name
, _BSS
) == 0)
4366 h
->esym
.asym
.sc
= scBss
;
4367 else if (strcmp (name
, _SBSS
) == 0)
4368 h
->esym
.asym
.sc
= scSBss
;
4369 else if (strcmp (name
, _INIT
) == 0)
4370 h
->esym
.asym
.sc
= scInit
;
4371 else if (strcmp (name
, _FINI
) == 0)
4372 h
->esym
.asym
.sc
= scFini
;
4373 else if (strcmp (name
, _PDATA
) == 0)
4374 h
->esym
.asym
.sc
= scPData
;
4375 else if (strcmp (name
, _XDATA
) == 0)
4376 h
->esym
.asym
.sc
= scXData
;
4378 h
->esym
.asym
.sc
= scAbs
;
4381 h
->esym
.asym
.reserved
= 0;
4382 h
->esym
.asym
.index
= indexNil
;
4384 else if (h
->esym
.ifd
!= -1)
4386 struct ecoff_debug_info
*debug
;
4388 /* Adjust the FDR index for the symbol by that used for the
4390 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4391 BFD_ASSERT (h
->esym
.ifd
>= 0
4392 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4393 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4396 switch (h
->root
.type
)
4399 case bfd_link_hash_new
:
4401 case bfd_link_hash_undefined
:
4402 case bfd_link_hash_weak
:
4403 if (h
->esym
.asym
.sc
!= scUndefined
4404 && h
->esym
.asym
.sc
!= scSUndefined
)
4405 h
->esym
.asym
.sc
= scUndefined
;
4407 case bfd_link_hash_defined
:
4408 if (h
->esym
.asym
.sc
== scUndefined
4409 || h
->esym
.asym
.sc
== scSUndefined
)
4410 h
->esym
.asym
.sc
= scAbs
;
4411 else if (h
->esym
.asym
.sc
== scCommon
)
4412 h
->esym
.asym
.sc
= scBss
;
4413 else if (h
->esym
.asym
.sc
== scSCommon
)
4414 h
->esym
.asym
.sc
= scSBss
;
4415 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4416 + h
->root
.u
.def
.section
->output_section
->vma
4417 + h
->root
.u
.def
.section
->output_offset
);
4419 case bfd_link_hash_common
:
4420 if (h
->esym
.asym
.sc
!= scCommon
4421 && h
->esym
.asym
.sc
!= scSCommon
)
4422 h
->esym
.asym
.sc
= scCommon
;
4423 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4425 case bfd_link_hash_indirect
:
4426 case bfd_link_hash_warning
:
4427 /* FIXME: Ignore these for now. The circumstances under which
4428 they should be written out are not clear to me. */
4432 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4434 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4435 h
->root
.written
= true;
4437 return (bfd_ecoff_debug_one_external
4438 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4439 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4443 /* Relocate and write an ECOFF section into an ECOFF output file. */
4446 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4448 struct bfd_link_info
*info
;
4449 asection
*output_section
;
4450 struct bfd_link_order
*link_order
;
4452 asection
*input_section
;
4454 struct ecoff_section_tdata
*section_tdata
;
4455 bfd_size_type raw_size
;
4456 bfd_size_type cooked_size
;
4457 bfd_byte
*contents
= NULL
;
4458 bfd_size_type external_reloc_size
;
4459 bfd_size_type external_relocs_size
;
4460 PTR external_relocs
= NULL
;
4462 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4464 if (link_order
->size
== 0)
4467 input_section
= link_order
->u
.indirect
.section
;
4468 input_bfd
= input_section
->owner
;
4469 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4471 raw_size
= input_section
->_raw_size
;
4472 cooked_size
= input_section
->_cooked_size
;
4473 if (cooked_size
== 0)
4474 cooked_size
= raw_size
;
4476 BFD_ASSERT (input_section
->output_section
== output_section
);
4477 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4478 BFD_ASSERT (cooked_size
== link_order
->size
);
4480 /* Get the section contents. We allocate memory for the larger of
4481 the size before relocating and the size after relocating. */
4482 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4485 if (contents
== NULL
&& raw_size
!= 0)
4487 bfd_set_error (bfd_error_no_memory
);
4491 /* If we are relaxing, the contents may have already been read into
4492 memory, in which case we copy them into our new buffer. We don't
4493 simply reuse the old buffer in case cooked_size > raw_size. */
4494 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4495 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4496 memcpy (contents
, section_tdata
->contents
, raw_size
);
4499 if (! bfd_get_section_contents (input_bfd
, input_section
,
4501 (file_ptr
) 0, raw_size
))
4505 /* Get the relocs. If we are relaxing MIPS code, they will already
4506 have been read in. Otherwise, we read them in now. */
4507 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4508 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4510 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4511 external_relocs
= section_tdata
->external_relocs
;
4514 external_relocs
= (PTR
) malloc (external_relocs_size
);
4515 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4517 bfd_set_error (bfd_error_no_memory
);
4521 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4522 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4523 != external_relocs_size
))
4527 /* Relocate the section contents. */
4528 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4529 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4533 /* Write out the relocated section. */
4534 if (! bfd_set_section_contents (output_bfd
,
4537 input_section
->output_offset
,
4541 /* If we are producing relocateable output, the relocs were
4542 modified, and we write them out now. We use the reloc_count
4543 field of output_section to keep track of the number of relocs we
4544 have output so far. */
4545 if (info
->relocateable
)
4547 if (bfd_seek (output_bfd
,
4548 (output_section
->rel_filepos
+
4549 output_section
->reloc_count
* external_reloc_size
),
4551 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4552 != external_relocs_size
))
4554 output_section
->reloc_count
+= input_section
->reloc_count
;
4557 if (contents
!= NULL
)
4559 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4560 free (external_relocs
);
4564 if (contents
!= NULL
)
4566 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4567 free (external_relocs
);
4571 /* Generate a reloc when linking an ECOFF file. This is a reloc
4572 requested by the linker, and does come from any input file. This
4573 is used to build constructor and destructor tables when linking
4577 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4579 struct bfd_link_info
*info
;
4580 asection
*output_section
;
4581 struct bfd_link_order
*link_order
;
4584 struct internal_reloc in
;
4585 bfd_size_type external_reloc_size
;
4589 /* We set up an arelent to pass to the backend adjust_reloc_out
4591 rel
.address
= link_order
->offset
;
4593 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4594 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4596 bfd_set_error (bfd_error_bad_value
);
4600 if (link_order
->type
== bfd_section_reloc_link_order
)
4601 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4604 /* We can't set up a reloc against a symbol correctly, because
4605 we have no asymbol structure. Currently no adjust_reloc_out
4607 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4610 /* All ECOFF relocs are in-place. Put the addend into the object
4613 BFD_ASSERT (rel
.howto
->partial_inplace
);
4614 if (link_order
->u
.reloc
.p
->addend
!= 0)
4617 bfd_reloc_status_type rstat
;
4621 size
= bfd_get_reloc_size (rel
.howto
);
4622 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4623 if (buf
== (bfd_byte
*) NULL
)
4625 bfd_set_error (bfd_error_no_memory
);
4628 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4629 link_order
->u
.reloc
.p
->addend
, buf
);
4635 case bfd_reloc_outofrange
:
4637 case bfd_reloc_overflow
:
4638 if (! ((*info
->callbacks
->reloc_overflow
)
4640 (link_order
->type
== bfd_section_reloc_link_order
4641 ? bfd_section_name (output_bfd
,
4642 link_order
->u
.reloc
.p
->u
.section
)
4643 : link_order
->u
.reloc
.p
->u
.name
),
4644 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4645 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4652 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4653 (file_ptr
) link_order
->offset
, size
);
4661 /* Move the information into a internal_reloc structure. */
4662 in
.r_vaddr
= (rel
.address
4663 + bfd_get_section_vma (output_bfd
, output_section
));
4664 in
.r_type
= rel
.howto
->type
;
4666 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4668 struct ecoff_link_hash_entry
*h
;
4670 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4671 link_order
->u
.reloc
.p
->u
.name
,
4672 false, false, true);
4673 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4675 in
.r_symndx
= h
->indx
;
4678 if (! ((*info
->callbacks
->unattached_reloc
)
4679 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4680 (asection
*) NULL
, (bfd_vma
) 0)))
4690 name
= bfd_get_section_name (output_bfd
,
4691 link_order
->u
.reloc
.p
->u
.section
);
4692 if (strcmp (name
, ".text") == 0)
4693 in
.r_symndx
= RELOC_SECTION_TEXT
;
4694 else if (strcmp (name
, ".rdata") == 0)
4695 in
.r_symndx
= RELOC_SECTION_RDATA
;
4696 else if (strcmp (name
, ".data") == 0)
4697 in
.r_symndx
= RELOC_SECTION_DATA
;
4698 else if (strcmp (name
, ".sdata") == 0)
4699 in
.r_symndx
= RELOC_SECTION_SDATA
;
4700 else if (strcmp (name
, ".sbss") == 0)
4701 in
.r_symndx
= RELOC_SECTION_SBSS
;
4702 else if (strcmp (name
, ".bss") == 0)
4703 in
.r_symndx
= RELOC_SECTION_BSS
;
4704 else if (strcmp (name
, ".init") == 0)
4705 in
.r_symndx
= RELOC_SECTION_INIT
;
4706 else if (strcmp (name
, ".lit8") == 0)
4707 in
.r_symndx
= RELOC_SECTION_LIT8
;
4708 else if (strcmp (name
, ".lit4") == 0)
4709 in
.r_symndx
= RELOC_SECTION_LIT4
;
4710 else if (strcmp (name
, ".xdata") == 0)
4711 in
.r_symndx
= RELOC_SECTION_XDATA
;
4712 else if (strcmp (name
, ".pdata") == 0)
4713 in
.r_symndx
= RELOC_SECTION_PDATA
;
4714 else if (strcmp (name
, ".fini") == 0)
4715 in
.r_symndx
= RELOC_SECTION_FINI
;
4716 else if (strcmp (name
, ".lita") == 0)
4717 in
.r_symndx
= RELOC_SECTION_LITA
;
4718 else if (strcmp (name
, "*ABS*") == 0)
4719 in
.r_symndx
= RELOC_SECTION_ABS
;
4725 /* Let the BFD backend adjust the reloc. */
4726 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4728 /* Get some memory and swap out the reloc. */
4729 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4730 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4731 if (rbuf
== (bfd_byte
*) NULL
)
4733 bfd_set_error (bfd_error_no_memory
);
4737 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4739 ok
= (bfd_seek (output_bfd
,
4740 (output_section
->rel_filepos
+
4741 output_section
->reloc_count
* external_reloc_size
),
4743 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4744 == external_reloc_size
));
4747 ++output_section
->reloc_count
;