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 long ecoff_sec_to_styp_flags
PARAMS ((const char *name
,
50 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
51 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
52 asymbol
*asym
, int ext
,
53 asymbol
**indirect_ptr_ptr
));
54 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
56 RNDXR
*rndx
, long isym
,
58 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
60 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
62 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
63 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
64 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
65 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
66 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
71 /* This stuff is somewhat copied from coffcode.h. */
73 static asection bfd_debug_section
= { "*DEBUG*" };
75 /* Create an ECOFF object. */
78 _bfd_ecoff_mkobject (abfd
)
81 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
82 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
83 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
85 bfd_set_error (bfd_error_no_memory
);
92 /* This is a hook called by coff_real_object_p to create any backend
93 specific information. */
96 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
101 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
102 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
103 ecoff_data_type
*ecoff
;
105 if (_bfd_ecoff_mkobject (abfd
) == false)
108 ecoff
= ecoff_data (abfd
);
110 ecoff
->sym_filepos
= internal_f
->f_symptr
;
112 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
116 ecoff
->text_start
= internal_a
->text_start
;
117 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
118 ecoff
->gp
= internal_a
->gp_value
;
119 ecoff
->gprmask
= internal_a
->gprmask
;
120 for (i
= 0; i
< 4; i
++)
121 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
122 ecoff
->fprmask
= internal_a
->fprmask
;
123 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
124 abfd
->flags
|= D_PAGED
;
127 /* It turns out that no special action is required by the MIPS or
128 Alpha ECOFF backends. They have different information in the
129 a.out header, but we just copy it all (e.g., gprmask, cprmask and
130 fprmask) and let the swapping routines ensure that only relevant
131 information is written out. */
136 /* This is a hook needed by SCO COFF, but we have nothing to do. */
140 _bfd_ecoff_make_section_hook (abfd
, name
)
144 return (asection
*) NULL
;
147 /* Initialize a new section. */
150 _bfd_ecoff_new_section_hook (abfd
, section
)
154 /* For the .pdata section, which has a special meaning on the Alpha,
155 we set the alignment to 8. We correct this later in
156 ecoff_compute_section_file_positions. We do this hackery because
157 we need to know the exact unaligned size of the .pdata section in
158 order to set the lnnoptr field correctly. */
159 if (strcmp (section
->name
, _PDATA
) == 0)
160 section
->alignment_power
= 3;
162 section
->alignment_power
= abfd
->xvec
->align_power_min
;
164 if (strcmp (section
->name
, _TEXT
) == 0)
165 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
166 else if (strcmp (section
->name
, _DATA
) == 0
167 || strcmp (section
->name
, _SDATA
) == 0)
168 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
169 else if (strcmp (section
->name
, _RDATA
) == 0
170 || strcmp (section
->name
, _LIT8
) == 0
171 || strcmp (section
->name
, _LIT4
) == 0)
172 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
173 else if (strcmp (section
->name
, _BSS
) == 0
174 || strcmp (section
->name
, _SBSS
) == 0)
175 section
->flags
|= SEC_ALLOC
;
176 else if (strcmp (section
->name
, _LIB
) == 0)
178 /* An Irix 4 shared libary. */
179 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
182 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
183 uncertain about .init on some systems and I don't know how shared
189 /* Determine the machine architecture and type. This is called from
190 the generic COFF routines. It is the inverse of ecoff_get_magic,
191 below. This could be an ECOFF backend routine, with one version
192 for each target, but there aren't all that many ECOFF targets. */
195 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
199 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
200 enum bfd_architecture arch
;
203 switch (internal_f
->f_magic
)
206 case MIPS_MAGIC_LITTLE
:
208 arch
= bfd_arch_mips
;
212 case MIPS_MAGIC_LITTLE2
:
213 case MIPS_MAGIC_BIG2
:
214 /* MIPS ISA level 2: the r6000 */
215 arch
= bfd_arch_mips
;
219 case MIPS_MAGIC_LITTLE3
:
220 case MIPS_MAGIC_BIG3
:
221 /* MIPS ISA level 3: the r4000 */
222 arch
= bfd_arch_mips
;
227 arch
= bfd_arch_alpha
;
232 arch
= bfd_arch_obscure
;
237 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
240 /* Get the magic number to use based on the architecture and machine.
241 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
244 ecoff_get_magic (abfd
)
249 switch (bfd_get_arch (abfd
))
252 switch (bfd_get_mach (abfd
))
257 big
= MIPS_MAGIC_BIG
;
258 little
= MIPS_MAGIC_LITTLE
;
262 big
= MIPS_MAGIC_BIG2
;
263 little
= MIPS_MAGIC_LITTLE2
;
267 big
= MIPS_MAGIC_BIG3
;
268 little
= MIPS_MAGIC_LITTLE3
;
272 return abfd
->xvec
->byteorder_big_p
? big
: little
;
283 /* Get the section s_flags to use for a section. */
286 ecoff_sec_to_styp_flags (name
, flags
)
294 if (strcmp (name
, _TEXT
) == 0)
296 else if (strcmp (name
, _DATA
) == 0)
298 else if (strcmp (name
, _SDATA
) == 0)
300 else if (strcmp (name
, _RDATA
) == 0)
302 else if (strcmp (name
, _LITA
) == 0)
304 else if (strcmp (name
, _LIT8
) == 0)
306 else if (strcmp (name
, _LIT4
) == 0)
308 else if (strcmp (name
, _BSS
) == 0)
310 else if (strcmp (name
, _SBSS
) == 0)
312 else if (strcmp (name
, _INIT
) == 0)
313 styp
= STYP_ECOFF_INIT
;
314 else if (strcmp (name
, _FINI
) == 0)
315 styp
= STYP_ECOFF_FINI
;
316 else if (strcmp (name
, _PDATA
) == 0)
318 else if (strcmp (name
, _XDATA
) == 0)
320 else if (strcmp (name
, _LIB
) == 0)
321 styp
= STYP_ECOFF_LIB
;
322 else if (flags
& SEC_CODE
)
324 else if (flags
& SEC_DATA
)
326 else if (flags
& SEC_READONLY
)
328 else if (flags
& SEC_LOAD
)
333 if (flags
& SEC_NEVER_LOAD
)
339 /* Get the BFD flags to use for a section. */
343 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
)
347 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
348 long styp_flags
= internal_s
->s_flags
;
349 flagword sec_flags
=0;
351 if (styp_flags
& STYP_NOLOAD
)
352 sec_flags
|= SEC_NEVER_LOAD
;
354 /* For 386 COFF, at least, an unloadable text or data section is
355 actually a shared library section. */
356 if ((styp_flags
& STYP_TEXT
)
357 || (styp_flags
& STYP_ECOFF_INIT
)
358 || (styp_flags
& STYP_ECOFF_FINI
))
360 if (sec_flags
& SEC_NEVER_LOAD
)
361 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
363 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
365 else if ((styp_flags
& STYP_DATA
)
366 || (styp_flags
& STYP_RDATA
)
367 || (styp_flags
& STYP_SDATA
)
368 || styp_flags
== STYP_PDATA
369 || styp_flags
== STYP_XDATA
)
371 if (sec_flags
& SEC_NEVER_LOAD
)
372 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
374 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
375 if ((styp_flags
& STYP_RDATA
)
376 || styp_flags
== STYP_PDATA
)
377 sec_flags
|= SEC_READONLY
;
379 else if ((styp_flags
& STYP_BSS
)
380 || (styp_flags
& STYP_SBSS
))
382 sec_flags
|= SEC_ALLOC
;
384 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
386 sec_flags
|= SEC_NEVER_LOAD
;
388 else if ((styp_flags
& STYP_LITA
)
389 || (styp_flags
& STYP_LIT8
)
390 || (styp_flags
& STYP_LIT4
))
392 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
394 else if (styp_flags
& STYP_ECOFF_LIB
)
396 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
400 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
406 /* Routines to swap auxiliary information in and out. I am assuming
407 that the auxiliary information format is always going to be target
410 /* Swap in a type information record.
411 BIGEND says whether AUX symbols are big-endian or little-endian; this
412 info comes from the file header record (fh-fBigendian). */
415 _bfd_ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
417 const struct tir_ext
*ext_copy
;
420 struct tir_ext ext
[1];
422 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
424 /* now the fun stuff... */
426 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
427 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
428 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
429 >> TIR_BITS1_BT_SH_BIG
;
430 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
431 >> TIR_BITS_TQ4_SH_BIG
;
432 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
433 >> TIR_BITS_TQ5_SH_BIG
;
434 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
435 >> TIR_BITS_TQ0_SH_BIG
;
436 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
437 >> TIR_BITS_TQ1_SH_BIG
;
438 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
439 >> TIR_BITS_TQ2_SH_BIG
;
440 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
441 >> TIR_BITS_TQ3_SH_BIG
;
443 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
444 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
445 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
446 >> TIR_BITS1_BT_SH_LITTLE
;
447 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
448 >> TIR_BITS_TQ4_SH_LITTLE
;
449 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
450 >> TIR_BITS_TQ5_SH_LITTLE
;
451 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
452 >> TIR_BITS_TQ0_SH_LITTLE
;
453 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
454 >> TIR_BITS_TQ1_SH_LITTLE
;
455 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
456 >> TIR_BITS_TQ2_SH_LITTLE
;
457 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
458 >> TIR_BITS_TQ3_SH_LITTLE
;
462 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
467 /* Swap out a type information record.
468 BIGEND says whether AUX symbols are big-endian or little-endian; this
469 info comes from the file header record (fh-fBigendian). */
472 _bfd_ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
474 const TIR
*intern_copy
;
479 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
481 /* now the fun stuff... */
483 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
484 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
485 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
486 & TIR_BITS1_BT_BIG
));
487 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
489 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
490 & TIR_BITS_TQ5_BIG
));
491 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
493 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
494 & TIR_BITS_TQ1_BIG
));
495 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
497 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
498 & TIR_BITS_TQ3_BIG
));
500 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
501 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
502 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
503 & TIR_BITS1_BT_LITTLE
));
504 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
505 & TIR_BITS_TQ4_LITTLE
)
506 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
507 & TIR_BITS_TQ5_LITTLE
));
508 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
509 & TIR_BITS_TQ0_LITTLE
)
510 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
511 & TIR_BITS_TQ1_LITTLE
));
512 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
513 & TIR_BITS_TQ2_LITTLE
)
514 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
515 & TIR_BITS_TQ3_LITTLE
));
519 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
524 /* Swap in a relative symbol record. BIGEND says whether it is in
525 big-endian or little-endian format.*/
528 _bfd_ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
530 const struct rndx_ext
*ext_copy
;
533 struct rndx_ext ext
[1];
535 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
537 /* now the fun stuff... */
539 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
540 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
541 >> RNDX_BITS1_RFD_SH_BIG
);
542 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
543 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
544 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
545 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
547 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
548 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
549 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
550 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
551 >> RNDX_BITS1_INDEX_SH_LITTLE
)
552 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
553 | ((unsigned int) ext
->r_bits
[3]
554 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
558 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
563 /* Swap out a relative symbol record. BIGEND says whether it is in
564 big-endian or little-endian format.*/
567 _bfd_ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
569 const RNDXR
*intern_copy
;
570 struct rndx_ext
*ext
;
574 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
576 /* now the fun stuff... */
578 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
579 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
580 & RNDX_BITS1_RFD_BIG
)
581 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
582 & RNDX_BITS1_INDEX_BIG
));
583 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
584 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
586 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
587 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
588 & RNDX_BITS1_RFD_LITTLE
)
589 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
590 & RNDX_BITS1_INDEX_LITTLE
));
591 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
592 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
596 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
601 /* Read in the symbolic header for an ECOFF object file. */
604 ecoff_slurp_symbolic_header (abfd
)
607 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
608 bfd_size_type external_hdr_size
;
610 HDRR
*internal_symhdr
;
612 /* See if we've already read it in. */
613 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
614 backend
->debug_swap
.sym_magic
)
617 /* See whether there is a symbolic header. */
618 if (ecoff_data (abfd
)->sym_filepos
== 0)
620 bfd_get_symcount (abfd
) = 0;
624 /* At this point bfd_get_symcount (abfd) holds the number of symbols
625 as read from the file header, but on ECOFF this is always the
626 size of the symbolic information header. It would be cleaner to
627 handle this when we first read the file in coffgen.c. */
628 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
629 if (bfd_get_symcount (abfd
) != external_hdr_size
)
631 bfd_set_error (bfd_error_bad_value
);
635 /* Read the symbolic information header. */
636 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
639 bfd_set_error (bfd_error_no_memory
);
643 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
644 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
645 != external_hdr_size
))
647 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
648 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
650 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
652 bfd_set_error (bfd_error_bad_value
);
656 /* Now we can get the correct number of symbols. */
657 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
658 + internal_symhdr
->iextMax
);
669 /* Read in and swap the important symbolic information for an ECOFF
670 object file. This is called by gdb via the read_debug_info entry
671 point in the backend structure. */
675 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
678 struct ecoff_debug_info
*debug
;
680 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
681 HDRR
*internal_symhdr
;
682 bfd_size_type raw_base
;
683 bfd_size_type raw_size
;
685 bfd_size_type external_fdr_size
;
689 bfd_size_type raw_end
;
690 bfd_size_type cb_end
;
692 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
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
= &debug
->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_release (abfd
, raw
);
762 ecoff_data (abfd
)->raw_syments
= raw
;
764 /* Get pointers for the numeric offsets in the HDRR structure. */
765 #define FIX(off1, off2, type) \
766 if (internal_symhdr->off1 == 0) \
767 debug->off2 = (type) NULL; \
769 debug->off2 = (type) ((char *) raw \
770 + internal_symhdr->off1 \
772 FIX (cbLineOffset
, line
, unsigned char *);
773 FIX (cbDnOffset
, external_dnr
, PTR
);
774 FIX (cbPdOffset
, external_pdr
, PTR
);
775 FIX (cbSymOffset
, external_sym
, PTR
);
776 FIX (cbOptOffset
, external_opt
, PTR
);
777 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
778 FIX (cbSsOffset
, ss
, char *);
779 FIX (cbSsExtOffset
, ssext
, char *);
780 FIX (cbFdOffset
, external_fdr
, PTR
);
781 FIX (cbRfdOffset
, external_rfd
, PTR
);
782 FIX (cbExtOffset
, external_ext
, PTR
);
785 /* I don't want to always swap all the data, because it will just
786 waste time and most programs will never look at it. The only
787 time the linker needs most of the debugging information swapped
788 is when linking big-endian and little-endian MIPS object files
789 together, which is not a common occurrence.
791 We need to look at the fdr to deal with a lot of information in
792 the symbols, so we swap them here. */
793 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
,
794 (internal_symhdr
->ifdMax
*
795 sizeof (struct fdr
)));
796 if (debug
->fdr
== NULL
)
798 bfd_set_error (bfd_error_no_memory
);
801 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
802 fdr_ptr
= debug
->fdr
;
803 fraw_src
= (char *) debug
->external_fdr
;
804 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
805 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
806 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
811 /* ECOFF symbol table routines. The ECOFF symbol table is described
812 in gcc/mips-tfile.c. */
814 /* ECOFF uses two common sections. One is the usual one, and the
815 other is for small objects. All the small objects are kept
816 together, and then referenced via the gp pointer, which yields
817 faster assembler code. This is what we use for the small common
819 static asection ecoff_scom_section
;
820 static asymbol ecoff_scom_symbol
;
821 static asymbol
*ecoff_scom_symbol_ptr
;
823 /* Create an empty symbol. */
826 _bfd_ecoff_make_empty_symbol (abfd
)
829 ecoff_symbol_type
*new;
831 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
832 if (new == (ecoff_symbol_type
*) NULL
)
834 bfd_set_error (bfd_error_no_memory
);
835 return (asymbol
*) NULL
;
837 memset ((PTR
) new, 0, sizeof *new);
838 new->symbol
.section
= (asection
*) NULL
;
839 new->fdr
= (FDR
*) NULL
;
842 new->symbol
.the_bfd
= abfd
;
846 /* Set the BFD flags and section for an ECOFF symbol. */
849 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
854 asymbol
**indirect_ptr_ptr
;
856 asym
->the_bfd
= abfd
;
857 asym
->value
= ecoff_sym
->value
;
858 asym
->section
= &bfd_debug_section
;
861 /* An indirect symbol requires two consecutive stabs symbols. */
862 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
864 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
866 /* @@ Stuffing pointers into integers is a no-no.
867 We can usually get away with it if the integer is
868 large enough though. */
869 if (sizeof (asym
) > sizeof (bfd_vma
))
871 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
873 asym
->flags
= BSF_DEBUGGING
;
874 asym
->section
= &bfd_und_section
;
875 *indirect_ptr_ptr
= NULL
;
879 if (ECOFF_IS_STAB (ecoff_sym
)
880 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
882 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
883 asym
->section
= &bfd_ind_section
;
884 /* Pass this symbol on to the next call to this function. */
885 *indirect_ptr_ptr
= asym
;
889 /* Most symbol types are just for debugging. */
890 switch (ecoff_sym
->st
)
899 if (ECOFF_IS_STAB (ecoff_sym
))
901 asym
->flags
= BSF_DEBUGGING
;
906 asym
->flags
= BSF_DEBUGGING
;
911 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
913 asym
->flags
= BSF_LOCAL
;
914 switch (ecoff_sym
->sc
)
917 /* Used for compiler generated labels. Leave them in the
918 debugging section, and mark them as local. If BSF_DEBUGGING
919 is set, then nm does not display them for some reason. If no
920 flags are set then the linker whines about them. */
921 asym
->flags
= BSF_LOCAL
;
924 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
925 asym
->value
-= asym
->section
->vma
;
928 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
929 asym
->value
-= asym
->section
->vma
;
932 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
933 asym
->value
-= asym
->section
->vma
;
936 asym
->flags
= BSF_DEBUGGING
;
939 asym
->section
= &bfd_abs_section
;
942 asym
->section
= &bfd_und_section
;
952 asym
->flags
= BSF_DEBUGGING
;
955 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
956 asym
->value
-= asym
->section
->vma
;
959 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
960 asym
->value
-= asym
->section
->vma
;
963 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
964 asym
->value
-= asym
->section
->vma
;
967 asym
->flags
= BSF_DEBUGGING
;
970 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
972 asym
->section
= &bfd_com_section
;
978 if (ecoff_scom_section
.name
== NULL
)
980 /* Initialize the small common section. */
981 ecoff_scom_section
.name
= SCOMMON
;
982 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
983 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
984 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
985 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
986 ecoff_scom_symbol
.name
= SCOMMON
;
987 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
988 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
989 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
991 asym
->section
= &ecoff_scom_section
;
996 asym
->flags
= BSF_DEBUGGING
;
999 asym
->section
= &bfd_und_section
;
1004 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1005 asym
->value
-= asym
->section
->vma
;
1010 asym
->flags
= BSF_DEBUGGING
;
1013 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1014 asym
->value
-= asym
->section
->vma
;
1020 /* Look for special constructors symbols and make relocation entries
1021 in a special construction section. These are produced by the
1022 -fgnu-linker argument to g++. */
1023 if (ECOFF_IS_STAB (ecoff_sym
))
1025 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1037 arelent_chain
*reloc_chain
;
1038 unsigned int bitsize
;
1040 /* Get a section with the same name as the symbol (usually
1041 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1042 name ___CTOR_LIST (three underscores). We need
1043 __CTOR_LIST (two underscores), since ECOFF doesn't use
1044 a leading underscore. This should be handled by gcc,
1045 but instead we do it here. Actually, this should all
1046 be done differently anyhow. */
1047 name
= bfd_asymbol_name (asym
);
1048 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1053 section
= bfd_get_section_by_name (abfd
, name
);
1054 if (section
== (asection
*) NULL
)
1058 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1061 bfd_set_error (bfd_error_no_memory
);
1064 strcpy (copy
, name
);
1065 section
= bfd_make_section (abfd
, copy
);
1068 /* Build a reloc pointing to this constructor. */
1070 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1073 bfd_set_error (bfd_error_no_memory
);
1076 reloc_chain
->relent
.sym_ptr_ptr
=
1077 bfd_get_section (asym
)->symbol_ptr_ptr
;
1078 reloc_chain
->relent
.address
= section
->_raw_size
;
1079 reloc_chain
->relent
.addend
= asym
->value
;
1080 reloc_chain
->relent
.howto
=
1081 ecoff_backend (abfd
)->constructor_reloc
;
1083 /* Set up the constructor section to hold the reloc. */
1084 section
->flags
= SEC_CONSTRUCTOR
;
1085 ++section
->reloc_count
;
1087 /* Constructor sections must be rounded to a boundary
1088 based on the bitsize. These are not real sections--
1089 they are handled specially by the linker--so the ECOFF
1090 16 byte alignment restriction does not apply. */
1091 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1092 section
->alignment_power
= 1;
1093 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1094 ++section
->alignment_power
;
1096 reloc_chain
->next
= section
->constructor_chain
;
1097 section
->constructor_chain
= reloc_chain
;
1098 section
->_raw_size
+= bitsize
/ 8;
1100 /* Mark the symbol as a constructor. */
1101 asym
->flags
|= BSF_CONSTRUCTOR
;
1109 /* Read an ECOFF symbol table. */
1112 _bfd_ecoff_slurp_symbol_table (abfd
)
1115 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1116 const bfd_size_type external_ext_size
1117 = backend
->debug_swap
.external_ext_size
;
1118 const bfd_size_type external_sym_size
1119 = backend
->debug_swap
.external_sym_size
;
1120 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1121 = backend
->debug_swap
.swap_ext_in
;
1122 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1123 = backend
->debug_swap
.swap_sym_in
;
1124 bfd_size_type internal_size
;
1125 ecoff_symbol_type
*internal
;
1126 ecoff_symbol_type
*internal_ptr
;
1127 asymbol
*indirect_ptr
;
1133 /* If we've already read in the symbol table, do nothing. */
1134 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1137 /* Get the symbolic information. */
1138 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1139 &ecoff_data (abfd
)->debug_info
))
1141 if (bfd_get_symcount (abfd
) == 0)
1144 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1145 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1146 if (internal
== NULL
)
1148 bfd_set_error (bfd_error_no_memory
);
1152 internal_ptr
= internal
;
1153 indirect_ptr
= NULL
;
1154 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1155 eraw_end
= (eraw_src
1156 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1157 * external_ext_size
));
1158 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1162 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1163 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1164 + internal_esym
.asym
.iss
);
1165 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1166 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1168 /* The alpha uses a negative ifd field for section symbols. */
1169 if (internal_esym
.ifd
>= 0)
1170 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1171 + internal_esym
.ifd
);
1173 internal_ptr
->fdr
= NULL
;
1174 internal_ptr
->local
= false;
1175 internal_ptr
->native
= (PTR
) eraw_src
;
1177 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1179 /* The local symbols must be accessed via the fdr's, because the
1180 string and aux indices are relative to the fdr information. */
1181 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1182 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1183 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1188 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1189 + fdr_ptr
->isymBase
* external_sym_size
);
1190 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1192 lraw_src
< lraw_end
;
1193 lraw_src
+= external_sym_size
, internal_ptr
++)
1197 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1198 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1200 + internal_sym
.iss
);
1201 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1202 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1204 internal_ptr
->fdr
= fdr_ptr
;
1205 internal_ptr
->local
= true;
1206 internal_ptr
->native
= (PTR
) lraw_src
;
1209 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1211 ecoff_data (abfd
)->canonical_symbols
= internal
;
1216 /* Return the amount of space needed for the canonical symbols. */
1219 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1222 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1223 &ecoff_data (abfd
)->debug_info
))
1226 if (bfd_get_symcount (abfd
) == 0)
1229 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1232 /* Get the canonical symbols. */
1235 _bfd_ecoff_get_symtab (abfd
, alocation
)
1237 asymbol
**alocation
;
1239 unsigned int counter
= 0;
1240 ecoff_symbol_type
*symbase
;
1241 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1243 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1245 if (bfd_get_symcount (abfd
) == 0)
1248 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1249 while (counter
< bfd_get_symcount (abfd
))
1251 *(location
++) = symbase
++;
1254 *location
++ = (ecoff_symbol_type
*) NULL
;
1255 return bfd_get_symcount (abfd
);
1258 /* Turn ECOFF type information into a printable string.
1259 ecoff_emit_aggregate and ecoff_type_to_string are from
1260 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1262 /* Write aggregate information to a string. */
1265 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1273 const struct ecoff_debug_swap
* const debug_swap
=
1274 &ecoff_backend (abfd
)->debug_swap
;
1275 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1276 unsigned int ifd
= rndx
->rfd
;
1277 unsigned int indx
= rndx
->index
;
1283 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1284 struct return type of a procedure compiled without -g. */
1285 if (ifd
== 0xffffffff
1286 || (rndx
->rfd
== 0xfff && indx
== 0))
1287 name
= "<undefined>";
1288 else if (indx
== indexNil
)
1294 if (debug_info
->external_rfd
== NULL
)
1295 fdr
= debug_info
->fdr
+ ifd
;
1300 (*debug_swap
->swap_rfd_in
) (abfd
,
1301 ((char *) debug_info
->external_rfd
1302 + ((fdr
->rfdBase
+ ifd
)
1303 * debug_swap
->external_rfd_size
)),
1305 fdr
= debug_info
->fdr
+ rfd
;
1308 indx
+= fdr
->isymBase
;
1310 (*debug_swap
->swap_sym_in
) (abfd
,
1311 ((char *) debug_info
->external_sym
1312 + indx
* debug_swap
->external_sym_size
),
1315 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1319 "%s %s { ifd = %u, index = %lu }",
1322 + debug_info
->symbolic_header
.iextMax
));
1325 /* Convert the type information to string format. */
1328 ecoff_type_to_string (abfd
, fdr
, indx
)
1333 union aux_ext
*aux_ptr
;
1342 unsigned int basic_type
;
1344 static char buffer1
[1024];
1345 static char buffer2
[1024];
1350 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1351 bigendian
= fdr
->fBigendian
;
1353 for (i
= 0; i
< 7; i
++)
1355 qualifiers
[i
].low_bound
= 0;
1356 qualifiers
[i
].high_bound
= 0;
1357 qualifiers
[i
].stride
= 0;
1360 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1361 return "-1 (no type)";
1362 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1364 basic_type
= u
.ti
.bt
;
1365 qualifiers
[0].type
= u
.ti
.tq0
;
1366 qualifiers
[1].type
= u
.ti
.tq1
;
1367 qualifiers
[2].type
= u
.ti
.tq2
;
1368 qualifiers
[3].type
= u
.ti
.tq3
;
1369 qualifiers
[4].type
= u
.ti
.tq4
;
1370 qualifiers
[5].type
= u
.ti
.tq5
;
1371 qualifiers
[6].type
= tqNil
;
1374 * Go get the basic type.
1378 case btNil
: /* undefined */
1382 case btAdr
: /* address - integer same size as pointer */
1383 strcpy (p1
, "address");
1386 case btChar
: /* character */
1387 strcpy (p1
, "char");
1390 case btUChar
: /* unsigned character */
1391 strcpy (p1
, "unsigned char");
1394 case btShort
: /* short */
1395 strcpy (p1
, "short");
1398 case btUShort
: /* unsigned short */
1399 strcpy (p1
, "unsigned short");
1402 case btInt
: /* int */
1406 case btUInt
: /* unsigned int */
1407 strcpy (p1
, "unsigned int");
1410 case btLong
: /* long */
1411 strcpy (p1
, "long");
1414 case btULong
: /* unsigned long */
1415 strcpy (p1
, "unsigned long");
1418 case btFloat
: /* float (real) */
1419 strcpy (p1
, "float");
1422 case btDouble
: /* Double (real) */
1423 strcpy (p1
, "double");
1426 /* Structures add 1-2 aux words:
1427 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1428 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1430 case btStruct
: /* Structure (Record) */
1431 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1432 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1433 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1435 indx
++; /* skip aux words */
1438 /* Unions add 1-2 aux words:
1439 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1440 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1442 case btUnion
: /* Union */
1443 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1444 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1445 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1447 indx
++; /* skip aux words */
1450 /* Enumerations add 1-2 aux words:
1451 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1452 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1454 case btEnum
: /* Enumeration */
1455 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1456 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1457 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1459 indx
++; /* skip aux words */
1462 case btTypedef
: /* defined via a typedef, isymRef points */
1463 strcpy (p1
, "typedef");
1466 case btRange
: /* subrange of int */
1467 strcpy (p1
, "subrange");
1470 case btSet
: /* pascal sets */
1474 case btComplex
: /* fortran complex */
1475 strcpy (p1
, "complex");
1478 case btDComplex
: /* fortran double complex */
1479 strcpy (p1
, "double complex");
1482 case btIndirect
: /* forward or unnamed typedef */
1483 strcpy (p1
, "forward/unamed typedef");
1486 case btFixedDec
: /* Fixed Decimal */
1487 strcpy (p1
, "fixed decimal");
1490 case btFloatDec
: /* Float Decimal */
1491 strcpy (p1
, "float decimal");
1494 case btString
: /* Varying Length Character String */
1495 strcpy (p1
, "string");
1498 case btBit
: /* Aligned Bit String */
1502 case btPicture
: /* Picture */
1503 strcpy (p1
, "picture");
1506 case btVoid
: /* Void */
1507 strcpy (p1
, "void");
1511 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1515 p1
+= strlen (buffer1
);
1518 * If this is a bitfield, get the bitsize.
1524 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1525 sprintf (p1
, " : %d", bitsize
);
1526 p1
+= strlen (buffer1
);
1531 * Deal with any qualifiers.
1533 if (qualifiers
[0].type
!= tqNil
)
1536 * Snarf up any array bounds in the correct order. Arrays
1537 * store 5 successive words in the aux. table:
1538 * word 0 RNDXR to type of the bounds (ie, int)
1539 * word 1 Current file descriptor index
1541 * word 3 high bound (or -1 if [])
1542 * word 4 stride size in bits
1544 for (i
= 0; i
< 7; i
++)
1546 if (qualifiers
[i
].type
== tqArray
)
1548 qualifiers
[i
].low_bound
=
1549 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1550 qualifiers
[i
].high_bound
=
1551 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1552 qualifiers
[i
].stride
=
1553 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1559 * Now print out the qualifiers.
1561 for (i
= 0; i
< 6; i
++)
1563 switch (qualifiers
[i
].type
)
1570 strcpy (p2
, "ptr to ");
1571 p2
+= sizeof ("ptr to ")-1;
1575 strcpy (p2
, "volatile ");
1576 p2
+= sizeof ("volatile ")-1;
1580 strcpy (p2
, "far ");
1581 p2
+= sizeof ("far ")-1;
1585 strcpy (p2
, "func. ret. ");
1586 p2
+= sizeof ("func. ret. ");
1591 int first_array
= i
;
1594 /* Print array bounds reversed (ie, in the order the C
1595 programmer writes them). C is such a fun language.... */
1597 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1600 for (j
= i
; j
>= first_array
; j
--)
1602 strcpy (p2
, "array [");
1603 p2
+= sizeof ("array [")-1;
1604 if (qualifiers
[j
].low_bound
!= 0)
1606 "%ld:%ld {%ld bits}",
1607 (long) qualifiers
[j
].low_bound
,
1608 (long) qualifiers
[j
].high_bound
,
1609 (long) qualifiers
[j
].stride
);
1611 else if (qualifiers
[j
].high_bound
!= -1)
1614 (long) (qualifiers
[j
].high_bound
+ 1),
1615 (long) (qualifiers
[j
].stride
));
1618 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1621 strcpy (p2
, "] of ");
1622 p2
+= sizeof ("] of ")-1;
1630 strcpy (p2
, buffer1
);
1634 /* Return information about ECOFF symbol SYMBOL in RET. */
1638 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1639 bfd
*abfd
; /* Ignored. */
1643 bfd_symbol_info (symbol
, ret
);
1646 /* Print information about an ECOFF symbol. */
1649 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1653 bfd_print_symbol_type how
;
1655 const struct ecoff_debug_swap
* const debug_swap
1656 = &ecoff_backend (abfd
)->debug_swap
;
1657 FILE *file
= (FILE *)filep
;
1661 case bfd_print_symbol_name
:
1662 fprintf (file
, "%s", symbol
->name
);
1664 case bfd_print_symbol_more
:
1665 if (ecoffsymbol (symbol
)->local
)
1669 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1671 fprintf (file
, "ecoff local ");
1672 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1673 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1674 (unsigned) ecoff_sym
.sc
);
1680 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1682 fprintf (file
, "ecoff extern ");
1683 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1684 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1685 (unsigned) ecoff_ext
.asym
.sc
);
1688 case bfd_print_symbol_all
:
1689 /* Print out the symbols in a reasonable way */
1698 if (ecoffsymbol (symbol
)->local
)
1700 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1703 pos
= ((((char *) ecoffsymbol (symbol
)->native
1704 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1705 / debug_swap
->external_sym_size
)
1706 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1713 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1716 pos
= (((char *) ecoffsymbol (symbol
)->native
1717 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1718 / debug_swap
->external_ext_size
);
1719 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1720 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1721 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1724 fprintf (file
, "[%3d] %c ",
1726 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1727 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1728 (unsigned) ecoff_ext
.asym
.st
,
1729 (unsigned) ecoff_ext
.asym
.sc
,
1730 (unsigned) ecoff_ext
.asym
.index
,
1731 jmptbl
, cobol_main
, weakext
,
1734 if (ecoffsymbol (symbol
)->fdr
!= NULL
1735 && ecoff_ext
.asym
.index
!= indexNil
)
1740 bfd_size_type sym_base
;
1741 union aux_ext
*aux_base
;
1743 fdr
= ecoffsymbol (symbol
)->fdr
;
1744 indx
= ecoff_ext
.asym
.index
;
1746 /* sym_base is used to map the fdr relative indices which
1747 appear in the file to the position number which we are
1749 sym_base
= fdr
->isymBase
;
1750 if (ecoffsymbol (symbol
)->local
)
1752 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1754 /* aux_base is the start of the aux entries for this file;
1755 asym.index is an offset from this. */
1756 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1759 /* The aux entries are stored in host byte order; the
1760 order is indicated by a bit in the fdr. */
1761 bigendian
= fdr
->fBigendian
;
1763 /* This switch is basically from gcc/mips-tdump.c */
1764 switch (ecoff_ext
.asym
.st
)
1772 fprintf (file
, "\n End+1 symbol: %ld",
1773 (long) (indx
+ sym_base
));
1777 if (ecoff_ext
.asym
.sc
== scText
1778 || ecoff_ext
.asym
.sc
== scInfo
)
1779 fprintf (file
, "\n First symbol: %ld",
1780 (long) (indx
+ sym_base
));
1782 fprintf (file
, "\n First symbol: %ld",
1784 (AUX_GET_ISYM (bigendian
,
1785 &aux_base
[ecoff_ext
.asym
.index
])
1791 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1793 else if (ecoffsymbol (symbol
)->local
)
1794 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1796 (AUX_GET_ISYM (bigendian
,
1797 &aux_base
[ecoff_ext
.asym
.index
])
1799 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1801 fprintf (file
, "\n Local symbol: %ld",
1804 + (ecoff_data (abfd
)
1805 ->debug_info
.symbolic_header
.iextMax
)));
1809 fprintf (file
, "\n struct; End+1 symbol: %ld",
1810 (long) (indx
+ sym_base
));
1814 fprintf (file
, "\n union; End+1 symbol: %ld",
1815 (long) (indx
+ sym_base
));
1819 fprintf (file
, "\n enum; End+1 symbol: %ld",
1820 (long) (indx
+ sym_base
));
1824 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1825 fprintf (file
, "\n Type: %s",
1826 ecoff_type_to_string (abfd
, fdr
, indx
));
1835 /* Read in the relocs for a section. */
1838 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1843 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1844 arelent
*internal_relocs
;
1845 bfd_size_type external_reloc_size
;
1846 bfd_size_type external_relocs_size
;
1847 char *external_relocs
;
1851 if (section
->relocation
!= (arelent
*) NULL
1852 || section
->reloc_count
== 0
1853 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1856 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1859 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1861 * section
->reloc_count
));
1862 external_reloc_size
= backend
->external_reloc_size
;
1863 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1864 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1865 if (internal_relocs
== (arelent
*) NULL
1866 || external_relocs
== (char *) NULL
)
1868 bfd_set_error (bfd_error_no_memory
);
1871 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1873 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1874 != external_relocs_size
)
1877 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1879 struct internal_reloc intern
;
1881 (*backend
->swap_reloc_in
) (abfd
,
1882 external_relocs
+ i
* external_reloc_size
,
1885 if (intern
.r_extern
)
1887 /* r_symndx is an index into the external symbols. */
1888 BFD_ASSERT (intern
.r_symndx
>= 0
1890 < (ecoff_data (abfd
)
1891 ->debug_info
.symbolic_header
.iextMax
)));
1892 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1895 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1896 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1898 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1903 CONST
char *sec_name
;
1906 /* r_symndx is a section key. */
1907 switch (intern
.r_symndx
)
1909 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1910 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1911 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1912 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1913 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1914 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1915 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1916 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1917 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1918 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1919 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1920 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1921 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1925 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1926 if (sec
== (asection
*) NULL
)
1928 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1930 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1933 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1935 /* Let the backend select the howto field and do any other
1936 required processing. */
1937 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1940 bfd_release (abfd
, external_relocs
);
1942 section
->relocation
= internal_relocs
;
1947 /* Get a canonical list of relocs. */
1950 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1958 if (section
->flags
& SEC_CONSTRUCTOR
)
1960 arelent_chain
*chain
;
1962 /* This section has relocs made up by us, not the file, so take
1963 them out of their chain and place them into the data area
1965 for (count
= 0, chain
= section
->constructor_chain
;
1966 count
< section
->reloc_count
;
1967 count
++, chain
= chain
->next
)
1968 *relptr
++ = &chain
->relent
;
1974 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1977 tblptr
= section
->relocation
;
1979 for (count
= 0; count
< section
->reloc_count
; count
++)
1980 *relptr
++ = tblptr
++;
1983 *relptr
= (arelent
*) NULL
;
1985 return section
->reloc_count
;
1988 /* Provided a BFD, a section and an offset into the section, calculate
1989 and return the name of the source file and the line nearest to the
1994 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1995 filename_ptr
, functionname_ptr
, retline_ptr
)
1998 asymbol
**ignore_symbols
;
2000 CONST
char **filename_ptr
;
2001 CONST
char **functionname_ptr
;
2002 unsigned int *retline_ptr
;
2004 const struct ecoff_debug_swap
* const debug_swap
2005 = &ecoff_backend (abfd
)->debug_swap
;
2010 bfd_size_type external_pdr_size
;
2015 unsigned char *line_ptr
;
2016 unsigned char *line_end
;
2019 /* If we're not in the .text section, we don't have any line
2021 if (strcmp (section
->name
, _TEXT
) != 0
2022 || offset
< ecoff_data (abfd
)->text_start
2023 || offset
>= ecoff_data (abfd
)->text_end
)
2026 /* Make sure we have the FDR's. */
2027 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
2028 &ecoff_data (abfd
)->debug_info
)
2029 || bfd_get_symcount (abfd
) == 0)
2032 /* Each file descriptor (FDR) has a memory address. Here we track
2033 down which FDR we want. The FDR's are stored in increasing
2034 memory order. If speed is ever important, this can become a
2035 binary search. We must ignore FDR's with no PDR entries; they
2036 will have the adr of the FDR before or after them. */
2037 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
2038 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
2039 fdr_hold
= (FDR
*) NULL
;
2040 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2042 if (fdr_ptr
->cpd
== 0)
2044 if (offset
< fdr_ptr
->adr
)
2048 if (fdr_hold
== (FDR
*) NULL
)
2052 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2053 have an address, which is relative to the FDR address, and are
2054 also stored in increasing memory order. */
2055 offset
-= fdr_ptr
->adr
;
2056 external_pdr_size
= debug_swap
->external_pdr_size
;
2057 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
2058 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2059 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2060 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2061 if (offset
< pdr
.adr
)
2064 /* The address of the first PDR is an offset which applies to the
2065 addresses of all the PDR's. */
2066 first_off
= pdr
.adr
;
2068 for (pdr_ptr
+= external_pdr_size
;
2070 pdr_ptr
+= external_pdr_size
)
2072 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2073 if (offset
< pdr
.adr
)
2077 /* Now we can look for the actual line number. The line numbers are
2078 stored in a very funky format, which I won't try to describe.
2079 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2080 we want; we need this to compute line_end. */
2081 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2082 if (pdr_ptr
== pdr_end
)
2083 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2085 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2087 /* Now change pdr and pdr_ptr to the one we want. */
2088 pdr_ptr
-= external_pdr_size
;
2089 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2091 offset
-= pdr
.adr
- first_off
;
2093 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2094 + fdr_ptr
->cbLineOffset
2095 + pdr
.cbLineOffset
);
2096 while (line_ptr
< line_end
)
2101 delta
= *line_ptr
>> 4;
2104 count
= (*line_ptr
& 0xf) + 1;
2108 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2109 if (delta
>= 0x8000)
2114 if (offset
< count
* 4)
2116 offset
-= count
* 4;
2119 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2120 at least according to gdb/mipsread.c. */
2121 if (fdr_ptr
->rss
== -1)
2123 *filename_ptr
= NULL
;
2125 *functionname_ptr
= NULL
;
2130 (*debug_swap
->swap_ext_in
)
2132 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2133 + pdr
.isym
* debug_swap
->external_ext_size
),
2135 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2136 + proc_ext
.asym
.iss
);
2143 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2146 (*debug_swap
->swap_sym_in
)
2148 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2149 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2151 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2155 if (lineno
== ilineNil
)
2157 *retline_ptr
= lineno
;
2161 /* Copy private BFD data. This is called by objcopy and strip. We
2162 use it to copy the ECOFF debugging information from one BFD to the
2163 other. It would be theoretically possible to represent the ECOFF
2164 debugging information in the symbol table. However, it would be a
2165 lot of work, and there would be little gain (gas, gdb, and ld
2166 already access the ECOFF debugging information via the
2167 ecoff_debug_info structure, and that structure would have to be
2168 retained in order to support ECOFF debugging in MIPS ELF).
2170 The debugging information for the ECOFF external symbols comes from
2171 the symbol table, so this function only handles the other debugging
2175 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
2179 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
2180 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
2182 asymbol
**sym_ptr_ptr
;
2186 /* This function is selected based on the input vector. We only
2187 want to copy information over if the output BFD also uses ECOFF
2189 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
2192 /* Copy the GP value and the register masks. */
2193 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
2194 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
2195 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
2196 for (i
= 0; i
< 3; i
++)
2197 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
2199 /* Copy the version stamp. */
2200 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
2202 /* If there are no symbols, don't copy any debugging information. */
2203 c
= bfd_get_symcount (obfd
);
2204 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2205 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
2208 /* See if there are any local symbols. */
2210 for (; c
> 0; c
--, sym_ptr_ptr
++)
2212 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
2221 /* There are some local symbols. We just bring over all the
2222 debugging information. FIXME: This is not quite the right
2223 thing to do. If the user has asked us to discard all
2224 debugging information, then we are probably going to wind up
2225 keeping it because there will probably be some local symbol
2226 which objcopy did not discard. We should actually break
2227 apart the debugging information and only keep that which
2228 applies to the symbols we want to keep. */
2229 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
2230 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
2231 oinfo
->line
= iinfo
->line
;
2233 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
2234 oinfo
->external_dnr
= iinfo
->external_dnr
;
2236 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
2237 oinfo
->external_pdr
= iinfo
->external_pdr
;
2239 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
2240 oinfo
->external_sym
= iinfo
->external_sym
;
2242 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
2243 oinfo
->external_opt
= iinfo
->external_opt
;
2245 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
2246 oinfo
->external_aux
= iinfo
->external_aux
;
2248 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
2249 oinfo
->ss
= iinfo
->ss
;
2251 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
2252 oinfo
->external_fdr
= iinfo
->external_fdr
;
2254 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
2255 oinfo
->external_rfd
= iinfo
->external_rfd
;
2259 /* We are discarding all the local symbol information. Look
2260 through the external symbols and remove all references to FDR
2261 or aux information. */
2262 c
= bfd_get_symcount (obfd
);
2263 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2264 for (; c
> 0; c
--, sym_ptr_ptr
++)
2268 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
2269 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
2271 esym
.asym
.index
= indexNil
;
2272 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
2273 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
2280 /* Set the architecture. The supported architecture is stored in the
2281 backend pointer. We always set the architecture anyhow, since many
2282 callers ignore the return value. */
2285 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
2287 enum bfd_architecture arch
;
2288 unsigned long machine
;
2290 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2291 return arch
== ecoff_backend (abfd
)->arch
;
2294 /* Get the size of the section headers. */
2298 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
2307 for (current
= abfd
->sections
;
2308 current
!= (asection
*)NULL
;
2309 current
= current
->next
)
2312 ret
= (bfd_coff_filhsz (abfd
)
2313 + bfd_coff_aoutsz (abfd
)
2314 + c
* bfd_coff_scnhsz (abfd
));
2315 return BFD_ALIGN (ret
, 16);
2318 /* Get the contents of a section. */
2321 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2326 bfd_size_type count
;
2328 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2332 /* Calculate the file position for each section, and set
2336 ecoff_compute_section_file_positions (abfd
)
2344 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2347 for (current
= abfd
->sections
;
2348 current
!= (asection
*) NULL
;
2349 current
= current
->next
)
2351 unsigned int alignment_power
;
2353 /* Only deal with sections which have contents */
2354 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2357 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2358 supposed to indicate the number of .pdata entries that are
2359 really in the section. Each entry is 8 bytes. We store this
2360 away in line_filepos before increasing the section size. */
2361 if (strcmp (current
->name
, _PDATA
) != 0)
2362 alignment_power
= current
->alignment_power
;
2365 current
->line_filepos
= current
->_raw_size
/ 8;
2366 alignment_power
= 4;
2369 /* On Ultrix, the data sections in an executable file must be
2370 aligned to a page boundary within the file. This does not
2371 affect the section size, though. FIXME: Does this work for
2372 other platforms? It requires some modification for the
2373 Alpha, because .rdata on the Alpha goes with the text, not
2375 if ((abfd
->flags
& EXEC_P
) != 0
2376 && (abfd
->flags
& D_PAGED
) != 0
2377 && first_data
!= false
2378 && (current
->flags
& SEC_CODE
) == 0
2379 && (! ecoff_backend (abfd
)->rdata_in_text
2380 || strcmp (current
->name
, _RDATA
) != 0)
2381 && strcmp (current
->name
, _PDATA
) != 0)
2383 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2385 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2388 else if (strcmp (current
->name
, _LIB
) == 0)
2390 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2391 /* On Irix 4, the location of contents of the .lib section
2392 from a shared library section is also rounded up to a
2395 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2398 /* Align the sections in the file to the same boundary on
2399 which they are aligned in virtual memory. */
2401 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2403 current
->filepos
= sofar
;
2405 sofar
+= current
->_raw_size
;
2407 /* make sure that this section is of the right size too */
2409 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2410 current
->_raw_size
+= sofar
- old_sofar
;
2413 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2416 /* Determine the location of the relocs for all the sections in the
2417 output file, as well as the location of the symbolic debugging
2420 static bfd_size_type
2421 ecoff_compute_reloc_file_positions (abfd
)
2424 const bfd_size_type external_reloc_size
=
2425 ecoff_backend (abfd
)->external_reloc_size
;
2426 file_ptr reloc_base
;
2427 bfd_size_type reloc_size
;
2431 if (! abfd
->output_has_begun
)
2433 ecoff_compute_section_file_positions (abfd
);
2434 abfd
->output_has_begun
= true;
2437 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2440 for (current
= abfd
->sections
;
2441 current
!= (asection
*)NULL
;
2442 current
= current
->next
)
2444 if (current
->reloc_count
== 0)
2445 current
->rel_filepos
= 0;
2448 bfd_size_type relsize
;
2450 current
->rel_filepos
= reloc_base
;
2451 relsize
= current
->reloc_count
* external_reloc_size
;
2452 reloc_size
+= relsize
;
2453 reloc_base
+= relsize
;
2457 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2459 /* At least on Ultrix, the symbol table of an executable file must
2460 be aligned to a page boundary. FIXME: Is this true on other
2462 if ((abfd
->flags
& EXEC_P
) != 0
2463 && (abfd
->flags
& D_PAGED
) != 0)
2464 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2465 &~ (ecoff_backend (abfd
)->round
- 1));
2467 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2472 /* Set the contents of a section. */
2475 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2480 bfd_size_type count
;
2482 /* This must be done first, because bfd_set_section_contents is
2483 going to set output_has_begun to true. */
2484 if (abfd
->output_has_begun
== false)
2485 ecoff_compute_section_file_positions (abfd
);
2487 /* If this is a .lib section, bump the vma address so that it winds
2488 up being the number of .lib sections output. This is right for
2489 Irix 4. Ian Taylor <ian@cygnus.com>. */
2490 if (strcmp (section
->name
, _LIB
) == 0)
2496 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2497 || bfd_write (location
, 1, count
, abfd
) != count
)
2503 /* Get the GP value for an ECOFF file. This is a hook used by
2507 bfd_ecoff_get_gp_value (abfd
)
2510 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2511 || bfd_get_format (abfd
) != bfd_object
)
2513 bfd_set_error (bfd_error_invalid_operation
);
2517 return ecoff_data (abfd
)->gp
;
2520 /* Set the GP value for an ECOFF file. This is a hook used by the
2524 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2528 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2529 || bfd_get_format (abfd
) != bfd_object
)
2531 bfd_set_error (bfd_error_invalid_operation
);
2535 ecoff_data (abfd
)->gp
= gp_value
;
2540 /* Set the register masks for an ECOFF file. This is a hook used by
2544 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2546 unsigned long gprmask
;
2547 unsigned long fprmask
;
2548 unsigned long *cprmask
;
2550 ecoff_data_type
*tdata
;
2552 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2553 || bfd_get_format (abfd
) != bfd_object
)
2555 bfd_set_error (bfd_error_invalid_operation
);
2559 tdata
= ecoff_data (abfd
);
2560 tdata
->gprmask
= gprmask
;
2561 tdata
->fprmask
= fprmask
;
2562 if (cprmask
!= (unsigned long *) NULL
)
2566 for (i
= 0; i
< 3; i
++)
2567 tdata
->cprmask
[i
] = cprmask
[i
];
2573 /* Get ECOFF EXTR information for an external symbol. This function
2574 is passed to bfd_ecoff_debug_externals. */
2577 ecoff_get_extr (sym
, esym
)
2581 ecoff_symbol_type
*ecoff_sym_ptr
;
2584 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2585 || ecoffsymbol (sym
)->native
== NULL
)
2587 /* Don't include debugging, local, or section symbols. */
2588 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2589 || (sym
->flags
& BSF_LOCAL
) != 0
2590 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2594 esym
->cobol_main
= 0;
2598 /* FIXME: we can do better than this for st and sc. */
2599 esym
->asym
.st
= stGlobal
;
2600 esym
->asym
.sc
= scAbs
;
2601 esym
->asym
.reserved
= 0;
2602 esym
->asym
.index
= indexNil
;
2606 ecoff_sym_ptr
= ecoffsymbol (sym
);
2608 if (ecoff_sym_ptr
->local
)
2611 input_bfd
= bfd_asymbol_bfd (sym
);
2612 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2613 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2615 /* If the symbol was defined by the linker, then esym will be
2616 undefined but sym will not be. Get a better class for such a
2618 if ((esym
->asym
.sc
== scUndefined
2619 || esym
->asym
.sc
== scSUndefined
)
2620 && bfd_get_section (sym
) != &bfd_und_section
)
2621 esym
->asym
.sc
= scAbs
;
2623 /* Adjust the FDR index for the symbol by that used for the input
2625 if (esym
->ifd
!= -1)
2627 struct ecoff_debug_info
*input_debug
;
2629 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2630 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2631 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2632 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2638 /* Set the external symbol index. This routine is passed to
2639 bfd_ecoff_debug_externals. */
2642 ecoff_set_index (sym
, indx
)
2646 ecoff_set_sym_index (sym
, indx
);
2649 /* Write out an ECOFF file. */
2652 _bfd_ecoff_write_object_contents (abfd
)
2655 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2656 const bfd_vma round
= backend
->round
;
2657 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2658 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2659 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2660 const bfd_size_type external_hdr_size
2661 = backend
->debug_swap
.external_hdr_size
;
2662 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2663 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2665 struct internal_reloc
*))
2666 = backend
->adjust_reloc_out
;
2667 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2668 const struct internal_reloc
*,
2670 = backend
->swap_reloc_out
;
2671 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2672 HDRR
* const symhdr
= &debug
->symbolic_header
;
2675 bfd_size_type reloc_size
;
2676 bfd_size_type text_size
;
2678 boolean set_text_start
;
2679 bfd_size_type data_size
;
2681 boolean set_data_start
;
2682 bfd_size_type bss_size
;
2684 PTR reloc_buff
= NULL
;
2685 struct internal_filehdr internal_f
;
2686 struct internal_aouthdr internal_a
;
2689 /* Determine where the sections and relocs will go in the output
2691 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2694 for (current
= abfd
->sections
;
2695 current
!= (asection
*)NULL
;
2696 current
= current
->next
)
2698 current
->target_index
= count
;
2702 if ((abfd
->flags
& D_PAGED
) != 0)
2703 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2707 set_text_start
= false;
2710 set_data_start
= false;
2713 /* Write section headers to the file. */
2715 /* Allocate buff big enough to hold a section header,
2716 file header, or a.out header. */
2724 buff
= (PTR
) malloc (siz
);
2727 bfd_set_error (bfd_error_no_memory
);
2732 internal_f
.f_nscns
= 0;
2733 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2735 for (current
= abfd
->sections
;
2736 current
!= (asection
*) NULL
;
2737 current
= current
->next
)
2739 struct internal_scnhdr section
;
2742 ++internal_f
.f_nscns
;
2744 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2746 /* This seems to be correct for Irix 4 shared libraries. */
2747 vma
= bfd_get_section_vma (abfd
, current
);
2748 if (strcmp (current
->name
, _LIB
) == 0)
2749 section
.s_vaddr
= 0;
2751 section
.s_vaddr
= vma
;
2753 section
.s_paddr
= vma
;
2754 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2756 /* If this section is unloadable then the scnptr will be 0. */
2757 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2758 section
.s_scnptr
= 0;
2760 section
.s_scnptr
= current
->filepos
;
2761 section
.s_relptr
= current
->rel_filepos
;
2763 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2764 object file produced by the assembler is supposed to point to
2765 information about how much room is required by objects of
2766 various different sizes. I think this only matters if we
2767 want the linker to compute the best size to use, or
2768 something. I don't know what happens if the information is
2770 if (strcmp (current
->name
, _PDATA
) != 0)
2771 section
.s_lnnoptr
= 0;
2774 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2775 hold the number of entries in the section (each entry is
2776 8 bytes). We stored this in the line_filepos field in
2777 ecoff_compute_section_file_positions. */
2778 section
.s_lnnoptr
= current
->line_filepos
;
2781 section
.s_nreloc
= current
->reloc_count
;
2782 section
.s_nlnno
= 0;
2783 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2786 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2787 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2790 if ((section
.s_flags
& STYP_TEXT
) != 0
2791 || ((section
.s_flags
& STYP_RDATA
) != 0
2792 && backend
->rdata_in_text
)
2793 || strcmp (current
->name
, _PDATA
) == 0)
2795 text_size
+= bfd_get_section_size_before_reloc (current
);
2796 if (! set_text_start
|| text_start
> vma
)
2799 set_text_start
= true;
2802 else if ((section
.s_flags
& STYP_RDATA
) != 0
2803 || (section
.s_flags
& STYP_DATA
) != 0
2804 || (section
.s_flags
& STYP_LITA
) != 0
2805 || (section
.s_flags
& STYP_LIT8
) != 0
2806 || (section
.s_flags
& STYP_LIT4
) != 0
2807 || (section
.s_flags
& STYP_SDATA
) != 0
2808 || strcmp (current
->name
, _XDATA
) == 0)
2810 data_size
+= bfd_get_section_size_before_reloc (current
);
2811 if (! set_data_start
|| data_start
> vma
)
2814 set_data_start
= true;
2817 else if ((section
.s_flags
& STYP_BSS
) != 0
2818 || (section
.s_flags
& STYP_SBSS
) != 0)
2819 bss_size
+= bfd_get_section_size_before_reloc (current
);
2820 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
2826 /* Set up the file header. */
2828 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2830 /* We will NOT put a fucking timestamp in the header here. Every
2831 time you put it back, I will come in and take it out again. I'm
2832 sorry. This field does not belong here. We fill it with a 0 so
2833 it compares the same but is not a reasonable time. --
2835 internal_f
.f_timdat
= 0;
2837 if (bfd_get_symcount (abfd
) != 0)
2839 /* The ECOFF f_nsyms field is not actually the number of
2840 symbols, it's the size of symbolic information header. */
2841 internal_f
.f_nsyms
= external_hdr_size
;
2842 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2846 internal_f
.f_nsyms
= 0;
2847 internal_f
.f_symptr
= 0;
2850 internal_f
.f_opthdr
= aoutsz
;
2852 internal_f
.f_flags
= F_LNNO
;
2853 if (reloc_size
== 0)
2854 internal_f
.f_flags
|= F_RELFLG
;
2855 if (bfd_get_symcount (abfd
) == 0)
2856 internal_f
.f_flags
|= F_LSYMS
;
2857 if (abfd
->flags
& EXEC_P
)
2858 internal_f
.f_flags
|= F_EXEC
;
2860 if (! abfd
->xvec
->byteorder_big_p
)
2861 internal_f
.f_flags
|= F_AR32WR
;
2863 internal_f
.f_flags
|= F_AR32W
;
2865 /* Set up the ``optional'' header. */
2866 if ((abfd
->flags
& D_PAGED
) != 0)
2867 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2869 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2871 /* FIXME: Is this really correct? */
2872 internal_a
.vstamp
= symhdr
->vstamp
;
2874 /* At least on Ultrix, these have to be rounded to page boundaries.
2875 FIXME: Is this true on other platforms? */
2876 if ((abfd
->flags
& D_PAGED
) != 0)
2878 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2879 internal_a
.text_start
= text_start
&~ (round
- 1);
2880 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2881 internal_a
.data_start
= data_start
&~ (round
- 1);
2885 internal_a
.tsize
= text_size
;
2886 internal_a
.text_start
= text_start
;
2887 internal_a
.dsize
= data_size
;
2888 internal_a
.data_start
= data_start
;
2891 /* On Ultrix, the initial portions of the .sbss and .bss segments
2892 are at the end of the data section. The bsize field in the
2893 optional header records how many bss bytes are required beyond
2894 those in the data section. The value is not rounded to a page
2896 if (bss_size
< internal_a
.dsize
- data_size
)
2899 bss_size
-= internal_a
.dsize
- data_size
;
2900 internal_a
.bsize
= bss_size
;
2901 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2903 internal_a
.entry
= bfd_get_start_address (abfd
);
2905 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2907 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2908 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2909 for (i
= 0; i
< 4; i
++)
2910 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2912 /* Write out the file header and the optional header. */
2914 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2917 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2918 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2921 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2922 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2925 /* Build the external symbol information. This must be done before
2926 writing out the relocs so that we know the symbol indices. We
2927 don't do this if this BFD was created by the backend linker,
2928 since it will have already handled the symbols and relocs. */
2929 if (! ecoff_data (abfd
)->linker
)
2931 symhdr
->iextMax
= 0;
2932 symhdr
->issExtMax
= 0;
2933 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2934 debug
->ssext
= debug
->ssext_end
= NULL
;
2935 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2936 (((abfd
->flags
& EXEC_P
) == 0)
2938 ecoff_get_extr
, ecoff_set_index
)
2942 /* Write out the relocs. */
2943 for (current
= abfd
->sections
;
2944 current
!= (asection
*) NULL
;
2945 current
= current
->next
)
2947 arelent
**reloc_ptr_ptr
;
2948 arelent
**reloc_end
;
2951 if (current
->reloc_count
== 0)
2955 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2956 if (reloc_buff
== NULL
)
2958 bfd_set_error (bfd_error_no_memory
);
2962 reloc_ptr_ptr
= current
->orelocation
;
2963 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2964 out_ptr
= (char *) reloc_buff
;
2966 reloc_ptr_ptr
< reloc_end
;
2967 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2971 struct internal_reloc in
;
2973 memset ((PTR
) &in
, 0, sizeof in
);
2975 reloc
= *reloc_ptr_ptr
;
2976 sym
= *reloc
->sym_ptr_ptr
;
2978 in
.r_vaddr
= (reloc
->address
2979 + bfd_get_section_vma (abfd
, current
));
2980 in
.r_type
= reloc
->howto
->type
;
2982 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2984 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2991 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2992 if (strcmp (name
, ".text") == 0)
2993 in
.r_symndx
= RELOC_SECTION_TEXT
;
2994 else if (strcmp (name
, ".rdata") == 0)
2995 in
.r_symndx
= RELOC_SECTION_RDATA
;
2996 else if (strcmp (name
, ".data") == 0)
2997 in
.r_symndx
= RELOC_SECTION_DATA
;
2998 else if (strcmp (name
, ".sdata") == 0)
2999 in
.r_symndx
= RELOC_SECTION_SDATA
;
3000 else if (strcmp (name
, ".sbss") == 0)
3001 in
.r_symndx
= RELOC_SECTION_SBSS
;
3002 else if (strcmp (name
, ".bss") == 0)
3003 in
.r_symndx
= RELOC_SECTION_BSS
;
3004 else if (strcmp (name
, ".init") == 0)
3005 in
.r_symndx
= RELOC_SECTION_INIT
;
3006 else if (strcmp (name
, ".lit8") == 0)
3007 in
.r_symndx
= RELOC_SECTION_LIT8
;
3008 else if (strcmp (name
, ".lit4") == 0)
3009 in
.r_symndx
= RELOC_SECTION_LIT4
;
3010 else if (strcmp (name
, ".xdata") == 0)
3011 in
.r_symndx
= RELOC_SECTION_XDATA
;
3012 else if (strcmp (name
, ".pdata") == 0)
3013 in
.r_symndx
= RELOC_SECTION_PDATA
;
3014 else if (strcmp (name
, ".fini") == 0)
3015 in
.r_symndx
= RELOC_SECTION_FINI
;
3016 else if (strcmp (name
, ".lita") == 0)
3017 in
.r_symndx
= RELOC_SECTION_LITA
;
3018 else if (strcmp (name
, "*ABS*") == 0)
3019 in
.r_symndx
= RELOC_SECTION_ABS
;
3025 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
3027 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3030 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3032 if (bfd_write (reloc_buff
,
3033 external_reloc_size
, current
->reloc_count
, abfd
)
3034 != external_reloc_size
* current
->reloc_count
)
3036 bfd_release (abfd
, reloc_buff
);
3040 /* Write out the symbolic debugging information. */
3041 if (bfd_get_symcount (abfd
) > 0)
3043 /* Write out the debugging information. */
3044 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
3045 ecoff_data (abfd
)->sym_filepos
)
3051 /* The .bss section of a demand paged executable must receive an
3052 entire page. If there are symbols, the symbols will start on the
3053 next page. If there are no symbols, we must fill out the page by
3055 if (bfd_get_symcount (abfd
) == 0
3056 && (abfd
->flags
& EXEC_P
) != 0
3057 && (abfd
->flags
& D_PAGED
) != 0)
3061 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3064 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3066 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3069 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3073 if (reloc_buff
!= NULL
)
3074 bfd_release (abfd
, reloc_buff
);
3079 if (reloc_buff
!= NULL
)
3080 bfd_release (abfd
, reloc_buff
);
3086 /* Archive handling. ECOFF uses what appears to be a unique type of
3087 archive header (armap). The byte ordering of the armap and the
3088 contents are encoded in the name of the armap itself. At least for
3089 now, we only support archives with the same byte ordering in the
3090 armap and the contents.
3092 The first four bytes in the armap are the number of symbol
3093 definitions. This is always a power of two.
3095 This is followed by the symbol definitions. Each symbol definition
3096 occupies 8 bytes. The first four bytes are the offset from the
3097 start of the armap strings to the null-terminated string naming
3098 this symbol. The second four bytes are the file offset to the
3099 archive member which defines this symbol. If the second four bytes
3100 are 0, then this is not actually a symbol definition, and it should
3103 The symbols are hashed into the armap with a closed hashing scheme.
3104 See the functions below for the details of the algorithm.
3106 After the symbol definitions comes four bytes holding the size of
3107 the string table, followed by the string table itself. */
3109 /* The name of an archive headers looks like this:
3110 __________E[BL]E[BL]_ (with a trailing space).
3111 The trailing space is changed to an X if the archive is changed to
3112 indicate that the armap is out of date.
3114 The Alpha seems to use ________64E[BL]E[BL]_. */
3116 #define ARMAP_BIG_ENDIAN 'B'
3117 #define ARMAP_LITTLE_ENDIAN 'L'
3118 #define ARMAP_MARKER 'E'
3119 #define ARMAP_START_LENGTH 10
3120 #define ARMAP_HEADER_MARKER_INDEX 10
3121 #define ARMAP_HEADER_ENDIAN_INDEX 11
3122 #define ARMAP_OBJECT_MARKER_INDEX 12
3123 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3124 #define ARMAP_END_INDEX 14
3125 #define ARMAP_END "_ "
3127 /* This is a magic number used in the hashing algorithm. */
3128 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3130 /* This returns the hash value to use for a string. It also sets
3131 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3132 is the number of entries in the hash table, and HLOG is the log
3136 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3138 unsigned int *rehash
;
3146 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3147 hash
*= ARMAP_HASH_MAGIC
;
3148 *rehash
= (hash
& (size
- 1)) | 1;
3149 return hash
>> (32 - hlog
);
3152 /* Read in the armap. */
3155 _bfd_ecoff_slurp_armap (abfd
)
3160 struct areltdata
*mapdata
;
3161 bfd_size_type parsed_size
;
3163 struct artdata
*ardata
;
3166 struct symdef
*symdef_ptr
;
3169 /* Get the name of the first element. */
3170 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3176 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
3179 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3180 standard COFF armap. We could move the ECOFF armap stuff into
3181 bfd_slurp_armap, but that seems inappropriate since no other
3182 target uses this format. Instead, we check directly for a COFF
3184 if (strncmp (nextname
, "/ ", 16) == 0)
3185 return bfd_slurp_armap (abfd
);
3187 /* See if the first element is an armap. */
3188 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3189 ARMAP_START_LENGTH
) != 0
3190 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3191 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3192 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3193 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3194 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3195 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3196 || strncmp (nextname
+ ARMAP_END_INDEX
,
3197 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3199 bfd_has_map (abfd
) = false;
3203 /* Make sure we have the right byte ordering. */
3204 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3205 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3206 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3207 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3209 bfd_set_error (bfd_error_wrong_format
);
3213 /* Read in the armap. */
3214 ardata
= bfd_ardata (abfd
);
3215 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3216 if (mapdata
== (struct areltdata
*) NULL
)
3218 parsed_size
= mapdata
->parsed_size
;
3219 bfd_release (abfd
, (PTR
) mapdata
);
3221 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3222 if (raw_armap
== (char *) NULL
)
3224 bfd_set_error (bfd_error_no_memory
);
3228 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3230 if (bfd_get_error () != bfd_error_system_call
)
3231 bfd_set_error (bfd_error_malformed_archive
);
3232 bfd_release (abfd
, (PTR
) raw_armap
);
3236 ardata
->tdata
= (PTR
) raw_armap
;
3238 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3240 ardata
->symdef_count
= 0;
3241 ardata
->cache
= (struct ar_cache
*) NULL
;
3243 /* This code used to overlay the symdefs over the raw archive data,
3244 but that doesn't work on a 64 bit host. */
3246 stringbase
= raw_armap
+ count
* 8 + 8;
3248 #ifdef CHECK_ARMAP_HASH
3252 /* Double check that I have the hashing algorithm right by making
3253 sure that every symbol can be looked up successfully. */
3255 for (i
= 1; i
< count
; i
<<= 1)
3257 BFD_ASSERT (i
== count
);
3259 raw_ptr
= raw_armap
+ 4;
3260 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3262 unsigned int name_offset
, file_offset
;
3263 unsigned int hash
, rehash
, srch
;
3265 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3266 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3267 if (file_offset
== 0)
3269 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3274 /* See if we can rehash to this location. */
3275 for (srch
= (hash
+ rehash
) & (count
- 1);
3276 srch
!= hash
&& srch
!= i
;
3277 srch
= (srch
+ rehash
) & (count
- 1))
3278 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3280 BFD_ASSERT (srch
== i
);
3284 #endif /* CHECK_ARMAP_HASH */
3286 raw_ptr
= raw_armap
+ 4;
3287 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3288 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3289 ++ardata
->symdef_count
;
3291 symdef_ptr
= ((struct symdef
*)
3293 ardata
->symdef_count
* sizeof (struct symdef
)));
3296 bfd_set_error (bfd_error_no_memory
);
3300 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3302 raw_ptr
= raw_armap
+ 4;
3303 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3305 unsigned int name_offset
, file_offset
;
3307 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3308 if (file_offset
== 0)
3310 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3311 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3312 symdef_ptr
->file_offset
= file_offset
;
3316 ardata
->first_file_filepos
= bfd_tell (abfd
);
3317 /* Pad to an even boundary. */
3318 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3320 bfd_has_map (abfd
) = true;
3325 /* Write out an armap. */
3328 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3330 unsigned int elength
;
3332 unsigned int orl_count
;
3335 unsigned int hashsize
, hashlog
;
3336 unsigned int symdefsize
;
3338 unsigned int stringsize
;
3339 unsigned int mapsize
;
3342 struct stat statbuf
;
3345 bfd_byte
*hashtable
;
3349 /* Ultrix appears to use as a hash table size the least power of two
3350 greater than twice the number of entries. */
3351 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3353 hashsize
= 1 << hashlog
;
3355 symdefsize
= hashsize
* 8;
3357 stringsize
= stridx
+ padit
;
3359 /* Include 8 bytes to store symdefsize and stringsize in output. */
3360 mapsize
= symdefsize
+ stringsize
+ 8;
3362 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3364 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3366 /* Work out the ECOFF armap name. */
3367 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3368 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3369 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3370 (abfd
->xvec
->header_byteorder_big_p
3372 : ARMAP_LITTLE_ENDIAN
);
3373 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3374 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3375 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3376 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3378 /* Write the timestamp of the archive header to be just a little bit
3379 later than the timestamp of the file, otherwise the linker will
3380 complain that the index is out of date. Actually, the Ultrix
3381 linker just checks the archive name; the GNU linker may check the
3383 stat (abfd
->filename
, &statbuf
);
3384 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3386 /* The DECstation uses zeroes for the uid, gid and mode of the
3388 hdr
.ar_uid
[0] = '0';
3389 hdr
.ar_gid
[0] = '0';
3390 hdr
.ar_mode
[0] = '0';
3392 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3394 hdr
.ar_fmag
[0] = '`';
3395 hdr
.ar_fmag
[1] = '\012';
3397 /* Turn all null bytes in the header into spaces. */
3398 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3399 if (((char *)(&hdr
))[i
] == '\0')
3400 (((char *)(&hdr
))[i
]) = ' ';
3402 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3403 != sizeof (struct ar_hdr
))
3406 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3407 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3410 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3413 bfd_set_error (bfd_error_no_memory
);
3417 current
= abfd
->archive_head
;
3419 for (i
= 0; i
< orl_count
; i
++)
3421 unsigned int hash
, rehash
;
3423 /* Advance firstreal to the file position of this archive
3425 if (((bfd
*) map
[i
].pos
) != last_elt
)
3429 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3430 firstreal
+= firstreal
% 2;
3431 current
= current
->next
;
3433 while (current
!= (bfd
*) map
[i
].pos
);
3438 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3439 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3443 /* The desired slot is already taken. */
3444 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3446 srch
= (srch
+ rehash
) & (hashsize
- 1))
3447 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3450 BFD_ASSERT (srch
!= hash
);
3455 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3456 (PTR
) (hashtable
+ hash
* 8));
3457 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3458 (PTR
) (hashtable
+ hash
* 8 + 4));
3461 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3464 bfd_release (abfd
, hashtable
);
3466 /* Now write the strings. */
3467 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3468 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3470 for (i
= 0; i
< orl_count
; i
++)
3474 len
= strlen (*map
[i
].name
) + 1;
3475 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3479 /* The spec sez this should be a newline. But in order to be
3480 bug-compatible for DECstation ar we use a null. */
3483 if (bfd_write ("", 1, 1, abfd
) != 1)
3490 /* See whether this BFD is an archive. If it is, read in the armap
3491 and the extended name table. */
3494 _bfd_ecoff_archive_p (abfd
)
3497 char armag
[SARMAG
+ 1];
3499 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3500 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3502 if (bfd_get_error () != bfd_error_system_call
)
3503 bfd_set_error (bfd_error_wrong_format
);
3504 return (const bfd_target
*) NULL
;
3507 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3508 involves a cast, we can't do it as the left operand of
3510 abfd
->tdata
.aout_ar_data
=
3511 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3513 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3515 bfd_set_error (bfd_error_no_memory
);
3516 return (const bfd_target
*) NULL
;
3519 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3520 bfd_ardata (abfd
)->cache
= NULL
;
3521 bfd_ardata (abfd
)->archive_head
= NULL
;
3522 bfd_ardata (abfd
)->symdefs
= NULL
;
3523 bfd_ardata (abfd
)->extended_names
= NULL
;
3524 bfd_ardata (abfd
)->tdata
= NULL
;
3526 if (_bfd_ecoff_slurp_armap (abfd
) == false
3527 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3529 bfd_release (abfd
, bfd_ardata (abfd
));
3530 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3531 return (const bfd_target
*) NULL
;
3537 /* ECOFF linker code. */
3539 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3540 PARAMS ((struct bfd_hash_entry
*entry
,
3541 struct bfd_hash_table
*table
,
3542 const char *string
));
3543 static boolean ecoff_link_add_archive_symbols
3544 PARAMS ((bfd
*, struct bfd_link_info
*));
3545 static boolean ecoff_link_check_archive_element
3546 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3547 static boolean ecoff_link_add_object_symbols
3548 PARAMS ((bfd
*, struct bfd_link_info
*));
3549 static boolean ecoff_link_add_externals
3550 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3552 /* Routine to create an entry in an ECOFF link hash table. */
3554 static struct bfd_hash_entry
*
3555 ecoff_link_hash_newfunc (entry
, table
, string
)
3556 struct bfd_hash_entry
*entry
;
3557 struct bfd_hash_table
*table
;
3560 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3562 /* Allocate the structure if it has not already been allocated by a
3564 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3565 ret
= ((struct ecoff_link_hash_entry
*)
3566 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3567 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3569 bfd_set_error (bfd_error_no_memory
);
3573 /* Call the allocation method of the superclass. */
3574 ret
= ((struct ecoff_link_hash_entry
*)
3575 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3580 /* Set local fields. */
3586 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3588 return (struct bfd_hash_entry
*) ret
;
3591 /* Create an ECOFF link hash table. */
3593 struct bfd_link_hash_table
*
3594 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3597 struct ecoff_link_hash_table
*ret
;
3599 ret
= ((struct ecoff_link_hash_table
*)
3600 malloc (sizeof (struct ecoff_link_hash_table
)));
3603 bfd_set_error (bfd_error_no_memory
);
3606 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3607 ecoff_link_hash_newfunc
))
3610 return (struct bfd_link_hash_table
*) NULL
;
3615 /* Look up an entry in an ECOFF link hash table. */
3617 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3618 ((struct ecoff_link_hash_entry *) \
3619 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3621 /* Traverse an ECOFF link hash table. */
3623 #define ecoff_link_hash_traverse(table, func, info) \
3624 (bfd_link_hash_traverse \
3626 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3629 /* Get the ECOFF link hash table from the info structure. This is
3632 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3634 /* Given an ECOFF BFD, add symbols to the global hash table as
3638 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3640 struct bfd_link_info
*info
;
3642 switch (bfd_get_format (abfd
))
3645 return ecoff_link_add_object_symbols (abfd
, info
);
3647 return ecoff_link_add_archive_symbols (abfd
, info
);
3649 bfd_set_error (bfd_error_wrong_format
);
3654 /* Add the symbols from an archive file to the global hash table.
3655 This looks through the undefined symbols, looks each one up in the
3656 archive hash table, and adds any associated object file. We do not
3657 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3658 already have a hash table, so there is no reason to construct
3662 ecoff_link_add_archive_symbols (abfd
, info
)
3664 struct bfd_link_info
*info
;
3666 const bfd_byte
*raw_armap
;
3667 struct bfd_link_hash_entry
**pundef
;
3668 unsigned int armap_count
;
3669 unsigned int armap_log
;
3671 const bfd_byte
*hashtable
;
3672 const char *stringbase
;
3674 if (! bfd_has_map (abfd
))
3676 bfd_set_error (bfd_error_no_symbols
);
3680 /* If we don't have any raw data for this archive, as can happen on
3681 Irix 4.0.5F, we call the generic routine.
3682 FIXME: We should be more clever about this, since someday tdata
3683 may get to something for a generic archive. */
3684 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3685 if (raw_armap
== (bfd_byte
*) NULL
)
3686 return (_bfd_generic_link_add_archive_symbols
3687 (abfd
, info
, ecoff_link_check_archive_element
));
3689 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3692 for (i
= 1; i
< armap_count
; i
<<= 1)
3694 BFD_ASSERT (i
== armap_count
);
3696 hashtable
= raw_armap
+ 4;
3697 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3699 /* Look through the list of undefined symbols. */
3700 pundef
= &info
->hash
->undefs
;
3701 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3703 struct bfd_link_hash_entry
*h
;
3704 unsigned int hash
, rehash
;
3705 unsigned int file_offset
;
3711 /* When a symbol is defined, it is not necessarily removed from
3713 if (h
->type
!= bfd_link_hash_undefined
3714 && h
->type
!= bfd_link_hash_common
)
3716 /* Remove this entry from the list, for general cleanliness
3717 and because we are going to look through the list again
3718 if we search any more libraries. We can't remove the
3719 entry if it is the tail, because that would lose any
3720 entries we add to the list later on. */
3721 if (*pundef
!= info
->hash
->undefs_tail
)
3722 *pundef
= (*pundef
)->next
;
3724 pundef
= &(*pundef
)->next
;
3728 /* Native ECOFF linkers do not pull in archive elements merely
3729 to satisfy common definitions, so neither do we. We leave
3730 them on the list, though, in case we are linking against some
3731 other object format. */
3732 if (h
->type
!= bfd_link_hash_undefined
)
3734 pundef
= &(*pundef
)->next
;
3738 /* Look for this symbol in the archive hash table. */
3739 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3742 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3743 if (file_offset
== 0)
3745 /* Nothing in this slot. */
3746 pundef
= &(*pundef
)->next
;
3750 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3751 if (name
[0] != h
->root
.string
[0]
3752 || strcmp (name
, h
->root
.string
) != 0)
3757 /* That was the wrong symbol. Try rehashing. */
3759 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3761 srch
= (srch
+ rehash
) & (armap_count
- 1))
3763 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3764 if (file_offset
== 0)
3766 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3767 if (name
[0] == h
->root
.string
[0]
3768 && strcmp (name
, h
->root
.string
) == 0)
3777 pundef
= &(*pundef
)->next
;
3784 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3785 if (element
== (bfd
*) NULL
)
3788 if (! bfd_check_format (element
, bfd_object
))
3791 /* Unlike the generic linker, we know that this element provides
3792 a definition for an undefined symbol and we know that we want
3793 to include it. We don't need to check anything. */
3794 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3796 if (! ecoff_link_add_object_symbols (element
, info
))
3799 pundef
= &(*pundef
)->next
;
3805 /* This is called if we used _bfd_generic_link_add_archive_symbols
3806 because we were not dealing with an ECOFF archive. */
3809 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3811 struct bfd_link_info
*info
;
3814 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3815 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3816 = backend
->debug_swap
.swap_ext_in
;
3818 bfd_size_type external_ext_size
;
3819 PTR external_ext
= NULL
;
3827 if (! ecoff_slurp_symbolic_header (abfd
))
3830 /* If there are no symbols, we don't want it. */
3831 if (bfd_get_symcount (abfd
) == 0)
3832 goto successful_return
;
3834 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3836 /* Read in the external symbols and external strings. */
3837 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3838 esize
= symhdr
->iextMax
* external_ext_size
;
3839 external_ext
= (PTR
) malloc (esize
);
3840 if (external_ext
== NULL
&& esize
!= 0)
3842 bfd_set_error (bfd_error_no_memory
);
3846 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3847 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3850 ssext
= (char *) malloc (symhdr
->issExtMax
);
3851 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3853 bfd_set_error (bfd_error_no_memory
);
3857 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3858 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3861 /* Look through the external symbols to see if they define some
3862 symbol that is currently undefined. */
3863 ext_ptr
= (char *) external_ext
;
3864 ext_end
= ext_ptr
+ esize
;
3865 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3870 struct bfd_link_hash_entry
*h
;
3872 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3874 /* See if this symbol defines something. */
3875 if (esym
.asym
.st
!= stGlobal
3876 && esym
.asym
.st
!= stLabel
3877 && esym
.asym
.st
!= stProc
)
3880 switch (esym
.asym
.sc
)
3903 name
= ssext
+ esym
.asym
.iss
;
3904 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3906 /* Unlike the generic linker, we do not pull in elements because
3907 of common symbols. */
3908 if (h
== (struct bfd_link_hash_entry
*) NULL
3909 || h
->type
!= bfd_link_hash_undefined
)
3912 /* Include this element. */
3913 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3915 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3919 goto successful_return
;
3923 if (external_ext
!= NULL
)
3924 free (external_ext
);
3929 if (external_ext
!= NULL
)
3930 free (external_ext
);
3936 /* Add symbols from an ECOFF object file to the global linker hash
3940 ecoff_link_add_object_symbols (abfd
, info
)
3942 struct bfd_link_info
*info
;
3945 bfd_size_type external_ext_size
;
3946 PTR external_ext
= NULL
;
3951 if (! ecoff_slurp_symbolic_header (abfd
))
3954 /* If there are no symbols, we don't want it. */
3955 if (bfd_get_symcount (abfd
) == 0)
3958 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3960 /* Read in the external symbols and external strings. */
3961 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3962 esize
= symhdr
->iextMax
* external_ext_size
;
3963 external_ext
= (PTR
) malloc (esize
);
3964 if (external_ext
== NULL
&& esize
!= 0)
3966 bfd_set_error (bfd_error_no_memory
);
3970 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3971 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3974 ssext
= (char *) malloc (symhdr
->issExtMax
);
3975 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3977 bfd_set_error (bfd_error_no_memory
);
3981 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3982 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3985 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3989 if (external_ext
!= NULL
)
3990 free (external_ext
);
3996 if (external_ext
!= NULL
)
3997 free (external_ext
);
4001 /* Add the external symbols of an object file to the global linker
4002 hash table. The external symbols and strings we are passed are
4003 just allocated on the stack, and will be discarded. We must
4004 explicitly save any information we may need later on in the link.
4005 We do not want to read the external symbol information again. */
4008 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
4010 struct bfd_link_info
*info
;
4014 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4015 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
4016 = backend
->debug_swap
.swap_ext_in
;
4017 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
4018 unsigned long ext_count
;
4019 struct ecoff_link_hash_entry
**sym_hash
;
4023 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
4025 sym_hash
= ((struct ecoff_link_hash_entry
**)
4027 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
4030 bfd_set_error (bfd_error_no_memory
);
4033 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
4035 ext_ptr
= (char *) external_ext
;
4036 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
4037 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
4044 struct ecoff_link_hash_entry
*h
;
4048 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
4050 /* Skip debugging symbols. */
4052 switch (esym
.asym
.st
)
4068 /* Get the information for this symbol. */
4069 value
= esym
.asym
.value
;
4070 switch (esym
.asym
.sc
)
4090 section
= bfd_make_section_old_way (abfd
, ".text");
4091 value
-= section
->vma
;
4094 section
= bfd_make_section_old_way (abfd
, ".data");
4095 value
-= section
->vma
;
4098 section
= bfd_make_section_old_way (abfd
, ".bss");
4099 value
-= section
->vma
;
4102 section
= &bfd_abs_section
;
4105 section
= &bfd_und_section
;
4108 section
= bfd_make_section_old_way (abfd
, ".sdata");
4109 value
-= section
->vma
;
4112 section
= bfd_make_section_old_way (abfd
, ".sbss");
4113 value
-= section
->vma
;
4116 section
= bfd_make_section_old_way (abfd
, ".rdata");
4117 value
-= section
->vma
;
4120 if (value
> ecoff_data (abfd
)->gp_size
)
4122 section
= &bfd_com_section
;
4127 if (ecoff_scom_section
.name
== NULL
)
4129 /* Initialize the small common section. */
4130 ecoff_scom_section
.name
= SCOMMON
;
4131 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
4132 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
4133 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
4134 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
4135 ecoff_scom_symbol
.name
= SCOMMON
;
4136 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
4137 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
4138 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
4140 section
= &ecoff_scom_section
;
4143 section
= &bfd_und_section
;
4146 section
= bfd_make_section_old_way (abfd
, ".init");
4147 value
-= section
->vma
;
4150 section
= bfd_make_section_old_way (abfd
, ".fini");
4151 value
-= section
->vma
;
4155 if (section
== (asection
*) NULL
)
4158 name
= ssext
+ esym
.asym
.iss
;
4161 if (! (_bfd_generic_link_add_one_symbol
4162 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
4163 (const char *) NULL
, true, true,
4164 (struct bfd_link_hash_entry
**) &h
)))
4169 /* If we are building an ECOFF hash table, save the external
4170 symbol information. */
4171 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4173 if (h
->abfd
== (bfd
*) NULL
4174 || (section
!= &bfd_und_section
4175 && (! bfd_is_com_section (section
)
4176 || h
->root
.type
!= bfd_link_hash_defined
)))
4182 /* Remember whether this symbol was small undefined. */
4183 if (esym
.asym
.sc
== scSUndefined
)
4186 /* If this symbol was ever small undefined, it needs to wind
4187 up in a GP relative section. We can't control the
4188 section of a defined symbol, but we can control the
4189 section of a common symbol. This case is actually needed
4190 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4192 && h
->root
.type
== bfd_link_hash_common
4193 && strcmp (h
->root
.u
.c
.section
->name
, SCOMMON
) != 0)
4195 h
->root
.u
.c
.section
= bfd_make_section_old_way (abfd
, SCOMMON
);
4196 h
->root
.u
.c
.section
->flags
= SEC_ALLOC
;
4197 if (h
->esym
.asym
.sc
== scCommon
)
4198 h
->esym
.asym
.sc
= scSCommon
;
4206 /* ECOFF final link routines. */
4208 static boolean ecoff_final_link_debug_accumulate
4209 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4211 static boolean ecoff_link_write_external
4212 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4213 static boolean ecoff_indirect_link_order
4214 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4215 struct bfd_link_order
*));
4216 static boolean ecoff_reloc_link_order
4217 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4218 struct bfd_link_order
*));
4220 /* ECOFF final link routine. This looks through all the input BFDs
4221 and gathers together all the debugging information, and then
4222 processes all the link order information. This may cause it to
4223 close and reopen some input BFDs; I'll see how bad this is. */
4226 _bfd_ecoff_bfd_final_link (abfd
, info
)
4228 struct bfd_link_info
*info
;
4230 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4231 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4234 register bfd
*input_bfd
;
4236 struct bfd_link_order
*p
;
4238 /* We accumulate the debugging information counts in the symbolic
4240 symhdr
= &debug
->symbolic_header
;
4242 symhdr
->ilineMax
= 0;
4246 symhdr
->isymMax
= 0;
4247 symhdr
->ioptMax
= 0;
4248 symhdr
->iauxMax
= 0;
4250 symhdr
->issExtMax
= 0;
4253 symhdr
->iextMax
= 0;
4255 /* We accumulate the debugging information itself in the debug_info
4258 debug
->external_dnr
= NULL
;
4259 debug
->external_pdr
= NULL
;
4260 debug
->external_sym
= NULL
;
4261 debug
->external_opt
= NULL
;
4262 debug
->external_aux
= NULL
;
4264 debug
->ssext
= debug
->ssext_end
= NULL
;
4265 debug
->external_fdr
= NULL
;
4266 debug
->external_rfd
= NULL
;
4267 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4269 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4270 if (handle
== (PTR
) NULL
)
4273 /* Accumulate the debugging symbols from each input BFD. */
4274 for (input_bfd
= info
->input_bfds
;
4275 input_bfd
!= (bfd
*) NULL
;
4276 input_bfd
= input_bfd
->link_next
)
4280 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4282 /* Abitrarily set the symbolic header vstamp to the vstamp
4283 of the first object file in the link. */
4284 if (symhdr
->vstamp
== 0)
4286 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4287 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4291 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4292 debug
, &backend
->debug_swap
,
4297 /* Combine the register masks. */
4298 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4299 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4300 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4301 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4302 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4303 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4306 /* Write out the external symbols. */
4307 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4308 ecoff_link_write_external
,
4311 if (info
->relocateable
)
4313 /* We need to make a pass over the link_orders to count up the
4314 number of relocations we will need to output, so that we know
4315 how much space they will take up. */
4316 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4319 for (p
= o
->link_order_head
;
4320 p
!= (struct bfd_link_order
*) NULL
;
4322 if (p
->type
== bfd_indirect_link_order
)
4323 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4324 else if (p
->type
== bfd_section_reloc_link_order
4325 || p
->type
== bfd_symbol_reloc_link_order
)
4330 /* Compute the reloc and symbol file positions. */
4331 ecoff_compute_reloc_file_positions (abfd
);
4333 /* Write out the debugging information. */
4334 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4335 &backend
->debug_swap
, info
,
4336 ecoff_data (abfd
)->sym_filepos
))
4339 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4341 if (info
->relocateable
)
4343 /* Now reset the reloc_count field of the sections in the output
4344 BFD to 0, so that we can use them to keep track of how many
4345 relocs we have output thus far. */
4346 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4350 /* Get a value for the GP register. */
4351 if (ecoff_data (abfd
)->gp
== 0)
4353 struct bfd_link_hash_entry
*h
;
4355 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4356 if (h
!= (struct bfd_link_hash_entry
*) NULL
4357 && h
->type
== bfd_link_hash_defined
)
4358 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4359 + h
->u
.def
.section
->output_section
->vma
4360 + h
->u
.def
.section
->output_offset
);
4361 else if (info
->relocateable
)
4365 /* Make up a value. */
4367 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4370 && (strcmp (o
->name
, _SBSS
) == 0
4371 || strcmp (o
->name
, _SDATA
) == 0
4372 || strcmp (o
->name
, _LIT4
) == 0
4373 || strcmp (o
->name
, _LIT8
) == 0
4374 || strcmp (o
->name
, _LITA
) == 0))
4377 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4381 /* If the relocate_section function needs to do a reloc
4382 involving the GP value, it should make a reloc_dangerous
4383 callback to warn that GP is not defined. */
4387 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4389 for (p
= o
->link_order_head
;
4390 p
!= (struct bfd_link_order
*) NULL
;
4393 if (p
->type
== bfd_indirect_link_order
4394 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4395 == bfd_target_ecoff_flavour
))
4397 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4400 else if (p
->type
== bfd_section_reloc_link_order
4401 || p
->type
== bfd_symbol_reloc_link_order
)
4403 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4408 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4414 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4416 ecoff_data (abfd
)->linker
= true;
4421 /* Accumulate the debugging information for an input BFD into the
4422 output BFD. This must read in the symbolic information of the
4426 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4429 struct bfd_link_info
*info
;
4432 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4433 const struct ecoff_debug_swap
* const swap
=
4434 &ecoff_backend (input_bfd
)->debug_swap
;
4435 HDRR
*symhdr
= &debug
->symbolic_header
;
4438 #define READ(ptr, offset, count, size, type) \
4439 if (symhdr->count == 0) \
4440 debug->ptr = NULL; \
4443 debug->ptr = (type) malloc (size * symhdr->count); \
4444 if (debug->ptr == NULL) \
4446 bfd_set_error (bfd_error_no_memory); \
4448 goto return_something; \
4450 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4452 || (bfd_read (debug->ptr, size, symhdr->count, \
4453 input_bfd) != size * symhdr->count)) \
4456 goto return_something; \
4460 /* If raw_syments is not NULL, then the data was already by read by
4461 _bfd_ecoff_slurp_symbolic_info. */
4462 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4464 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4466 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4467 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4468 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4469 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4470 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4472 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4473 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4474 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4478 /* We do not read the external strings or the external symbols. */
4480 ret
= (bfd_ecoff_debug_accumulate
4481 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4482 &ecoff_backend (output_bfd
)->debug_swap
,
4483 input_bfd
, debug
, swap
, info
));
4486 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4488 if (debug
->line
!= NULL
)
4490 if (debug
->external_dnr
!= NULL
)
4491 free (debug
->external_dnr
);
4492 if (debug
->external_pdr
!= NULL
)
4493 free (debug
->external_pdr
);
4494 if (debug
->external_sym
!= NULL
)
4495 free (debug
->external_sym
);
4496 if (debug
->external_opt
!= NULL
)
4497 free (debug
->external_opt
);
4498 if (debug
->external_aux
!= NULL
)
4499 free (debug
->external_aux
);
4500 if (debug
->ss
!= NULL
)
4502 if (debug
->external_fdr
!= NULL
)
4503 free (debug
->external_fdr
);
4504 if (debug
->external_rfd
!= NULL
)
4505 free (debug
->external_rfd
);
4507 /* Make sure we don't accidentally follow one of these pointers
4508 into freed memory. */
4510 debug
->external_dnr
= NULL
;
4511 debug
->external_pdr
= NULL
;
4512 debug
->external_sym
= NULL
;
4513 debug
->external_opt
= NULL
;
4514 debug
->external_aux
= NULL
;
4516 debug
->external_fdr
= NULL
;
4517 debug
->external_rfd
= NULL
;
4523 /* Put out information for an external symbol. These come only from
4527 ecoff_link_write_external (h
, data
)
4528 struct ecoff_link_hash_entry
*h
;
4531 bfd
*output_bfd
= (bfd
*) data
;
4533 /* FIXME: We should check if this symbol is being stripped. */
4538 if (h
->abfd
== (bfd
*) NULL
)
4541 h
->esym
.cobol_main
= 0;
4542 h
->esym
.weakext
= 0;
4543 h
->esym
.reserved
= 0;
4544 h
->esym
.ifd
= ifdNil
;
4545 h
->esym
.asym
.value
= 0;
4546 h
->esym
.asym
.st
= stGlobal
;
4548 if (h
->root
.type
!= bfd_link_hash_defined
)
4549 h
->esym
.asym
.sc
= scAbs
;
4552 asection
*output_section
;
4555 output_section
= h
->root
.u
.def
.section
->output_section
;
4556 name
= bfd_section_name (output_section
->owner
, output_section
);
4558 if (strcmp (name
, _TEXT
) == 0)
4559 h
->esym
.asym
.sc
= scText
;
4560 else if (strcmp (name
, _DATA
) == 0)
4561 h
->esym
.asym
.sc
= scData
;
4562 else if (strcmp (name
, _SDATA
) == 0)
4563 h
->esym
.asym
.sc
= scSData
;
4564 else if (strcmp (name
, _RDATA
) == 0)
4565 h
->esym
.asym
.sc
= scRData
;
4566 else if (strcmp (name
, _BSS
) == 0)
4567 h
->esym
.asym
.sc
= scBss
;
4568 else if (strcmp (name
, _SBSS
) == 0)
4569 h
->esym
.asym
.sc
= scSBss
;
4570 else if (strcmp (name
, _INIT
) == 0)
4571 h
->esym
.asym
.sc
= scInit
;
4572 else if (strcmp (name
, _FINI
) == 0)
4573 h
->esym
.asym
.sc
= scFini
;
4574 else if (strcmp (name
, _PDATA
) == 0)
4575 h
->esym
.asym
.sc
= scPData
;
4576 else if (strcmp (name
, _XDATA
) == 0)
4577 h
->esym
.asym
.sc
= scXData
;
4579 h
->esym
.asym
.sc
= scAbs
;
4582 h
->esym
.asym
.reserved
= 0;
4583 h
->esym
.asym
.index
= indexNil
;
4585 else if (h
->esym
.ifd
!= -1)
4587 struct ecoff_debug_info
*debug
;
4589 /* Adjust the FDR index for the symbol by that used for the
4591 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4592 BFD_ASSERT (h
->esym
.ifd
>= 0
4593 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4594 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4597 switch (h
->root
.type
)
4600 case bfd_link_hash_new
:
4602 case bfd_link_hash_undefined
:
4603 case bfd_link_hash_weak
:
4604 if (h
->esym
.asym
.sc
!= scUndefined
4605 && h
->esym
.asym
.sc
!= scSUndefined
)
4606 h
->esym
.asym
.sc
= scUndefined
;
4608 case bfd_link_hash_defined
:
4609 if (h
->esym
.asym
.sc
== scUndefined
4610 || h
->esym
.asym
.sc
== scSUndefined
)
4611 h
->esym
.asym
.sc
= scAbs
;
4612 else if (h
->esym
.asym
.sc
== scCommon
)
4613 h
->esym
.asym
.sc
= scBss
;
4614 else if (h
->esym
.asym
.sc
== scSCommon
)
4615 h
->esym
.asym
.sc
= scSBss
;
4616 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4617 + h
->root
.u
.def
.section
->output_section
->vma
4618 + h
->root
.u
.def
.section
->output_offset
);
4620 case bfd_link_hash_common
:
4621 if (h
->esym
.asym
.sc
!= scCommon
4622 && h
->esym
.asym
.sc
!= scSCommon
)
4623 h
->esym
.asym
.sc
= scCommon
;
4624 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4626 case bfd_link_hash_indirect
:
4627 case bfd_link_hash_warning
:
4628 /* FIXME: Ignore these for now. The circumstances under which
4629 they should be written out are not clear to me. */
4633 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4635 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4638 return (bfd_ecoff_debug_one_external
4639 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4640 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4644 /* Relocate and write an ECOFF section into an ECOFF output file. */
4647 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4649 struct bfd_link_info
*info
;
4650 asection
*output_section
;
4651 struct bfd_link_order
*link_order
;
4653 asection
*input_section
;
4655 struct ecoff_section_tdata
*section_tdata
;
4656 bfd_size_type raw_size
;
4657 bfd_size_type cooked_size
;
4658 bfd_byte
*contents
= NULL
;
4659 bfd_size_type external_reloc_size
;
4660 bfd_size_type external_relocs_size
;
4661 PTR external_relocs
= NULL
;
4663 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4665 if (link_order
->size
== 0)
4668 input_section
= link_order
->u
.indirect
.section
;
4669 input_bfd
= input_section
->owner
;
4670 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4672 raw_size
= input_section
->_raw_size
;
4673 cooked_size
= input_section
->_cooked_size
;
4674 if (cooked_size
== 0)
4675 cooked_size
= raw_size
;
4677 BFD_ASSERT (input_section
->output_section
== output_section
);
4678 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4679 BFD_ASSERT (cooked_size
== link_order
->size
);
4681 /* Get the section contents. We allocate memory for the larger of
4682 the size before relocating and the size after relocating. */
4683 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
4686 if (contents
== NULL
&& raw_size
!= 0)
4688 bfd_set_error (bfd_error_no_memory
);
4692 /* If we are relaxing, the contents may have already been read into
4693 memory, in which case we copy them into our new buffer. We don't
4694 simply reuse the old buffer in case cooked_size > raw_size. */
4695 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4696 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4697 memcpy (contents
, section_tdata
->contents
, raw_size
);
4700 if (! bfd_get_section_contents (input_bfd
, input_section
,
4702 (file_ptr
) 0, raw_size
))
4706 /* Get the relocs. If we are relaxing MIPS code, they will already
4707 have been read in. Otherwise, we read them in now. */
4708 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4709 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4711 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
4712 external_relocs
= section_tdata
->external_relocs
;
4715 external_relocs
= (PTR
) malloc (external_relocs_size
);
4716 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4718 bfd_set_error (bfd_error_no_memory
);
4722 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4723 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4724 != external_relocs_size
))
4728 /* Relocate the section contents. */
4729 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4730 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4734 /* Write out the relocated section. */
4735 if (! bfd_set_section_contents (output_bfd
,
4738 input_section
->output_offset
,
4742 /* If we are producing relocateable output, the relocs were
4743 modified, and we write them out now. We use the reloc_count
4744 field of output_section to keep track of the number of relocs we
4745 have output so far. */
4746 if (info
->relocateable
)
4748 if (bfd_seek (output_bfd
,
4749 (output_section
->rel_filepos
+
4750 output_section
->reloc_count
* external_reloc_size
),
4752 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4753 != external_relocs_size
))
4755 output_section
->reloc_count
+= input_section
->reloc_count
;
4758 if (contents
!= NULL
)
4760 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4761 free (external_relocs
);
4765 if (contents
!= NULL
)
4767 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4768 free (external_relocs
);
4772 /* Generate a reloc when linking an ECOFF file. This is a reloc
4773 requested by the linker, and does come from any input file. This
4774 is used to build constructor and destructor tables when linking
4778 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4780 struct bfd_link_info
*info
;
4781 asection
*output_section
;
4782 struct bfd_link_order
*link_order
;
4785 struct internal_reloc in
;
4786 bfd_size_type external_reloc_size
;
4790 /* We set up an arelent to pass to the backend adjust_reloc_out
4792 rel
.address
= link_order
->offset
;
4794 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4795 if (rel
.howto
== (const reloc_howto_type
*) NULL
)
4797 bfd_set_error (bfd_error_bad_value
);
4801 if (link_order
->type
== bfd_section_reloc_link_order
)
4802 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
4805 /* We can't set up a reloc against a symbol correctly, because
4806 we have no asymbol structure. Currently no adjust_reloc_out
4808 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4811 /* All ECOFF relocs are in-place. Put the addend into the object
4814 BFD_ASSERT (rel
.howto
->partial_inplace
);
4815 if (link_order
->u
.reloc
.p
->addend
!= 0)
4818 bfd_reloc_status_type rstat
;
4822 size
= bfd_get_reloc_size (rel
.howto
);
4823 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4824 if (buf
== (bfd_byte
*) NULL
)
4826 bfd_set_error (bfd_error_no_memory
);
4829 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4830 link_order
->u
.reloc
.p
->addend
, buf
);
4836 case bfd_reloc_outofrange
:
4838 case bfd_reloc_overflow
:
4839 if (! ((*info
->callbacks
->reloc_overflow
)
4841 (link_order
->type
== bfd_section_reloc_link_order
4842 ? bfd_section_name (output_bfd
,
4843 link_order
->u
.reloc
.p
->u
.section
)
4844 : link_order
->u
.reloc
.p
->u
.name
),
4845 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
4846 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
4853 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4854 (file_ptr
) link_order
->offset
, size
);
4862 /* Move the information into a internal_reloc structure. */
4863 in
.r_vaddr
= (rel
.address
4864 + bfd_get_section_vma (output_bfd
, output_section
));
4865 in
.r_type
= rel
.howto
->type
;
4867 if (link_order
->type
== bfd_symbol_reloc_link_order
)
4869 struct ecoff_link_hash_entry
*h
;
4871 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
4872 link_order
->u
.reloc
.p
->u
.name
,
4873 false, false, true);
4874 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4876 in
.r_symndx
= h
->indx
;
4879 if (! ((*info
->callbacks
->unattached_reloc
)
4880 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4881 (asection
*) NULL
, (bfd_vma
) 0)))
4891 name
= bfd_get_section_name (output_bfd
,
4892 link_order
->u
.reloc
.p
->u
.section
);
4893 if (strcmp (name
, ".text") == 0)
4894 in
.r_symndx
= RELOC_SECTION_TEXT
;
4895 else if (strcmp (name
, ".rdata") == 0)
4896 in
.r_symndx
= RELOC_SECTION_RDATA
;
4897 else if (strcmp (name
, ".data") == 0)
4898 in
.r_symndx
= RELOC_SECTION_DATA
;
4899 else if (strcmp (name
, ".sdata") == 0)
4900 in
.r_symndx
= RELOC_SECTION_SDATA
;
4901 else if (strcmp (name
, ".sbss") == 0)
4902 in
.r_symndx
= RELOC_SECTION_SBSS
;
4903 else if (strcmp (name
, ".bss") == 0)
4904 in
.r_symndx
= RELOC_SECTION_BSS
;
4905 else if (strcmp (name
, ".init") == 0)
4906 in
.r_symndx
= RELOC_SECTION_INIT
;
4907 else if (strcmp (name
, ".lit8") == 0)
4908 in
.r_symndx
= RELOC_SECTION_LIT8
;
4909 else if (strcmp (name
, ".lit4") == 0)
4910 in
.r_symndx
= RELOC_SECTION_LIT4
;
4911 else if (strcmp (name
, ".xdata") == 0)
4912 in
.r_symndx
= RELOC_SECTION_XDATA
;
4913 else if (strcmp (name
, ".pdata") == 0)
4914 in
.r_symndx
= RELOC_SECTION_PDATA
;
4915 else if (strcmp (name
, ".fini") == 0)
4916 in
.r_symndx
= RELOC_SECTION_FINI
;
4917 else if (strcmp (name
, ".lita") == 0)
4918 in
.r_symndx
= RELOC_SECTION_LITA
;
4919 else if (strcmp (name
, "*ABS*") == 0)
4920 in
.r_symndx
= RELOC_SECTION_ABS
;
4926 /* Let the BFD backend adjust the reloc. */
4927 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4929 /* Get some memory and swap out the reloc. */
4930 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4931 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
4932 if (rbuf
== (bfd_byte
*) NULL
)
4934 bfd_set_error (bfd_error_no_memory
);
4938 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4940 ok
= (bfd_seek (output_bfd
,
4941 (output_section
->rel_filepos
+
4942 output_section
->reloc_count
* external_reloc_size
),
4944 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
4945 == external_reloc_size
));
4948 ++output_section
->reloc_count
;