1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 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"
28 #include "aout/stab_gnu.h"
30 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
31 some other stuff which we don't want and which conflicts with stuff
34 #include "aout/aout64.h"
37 #undef obj_sym_filepos
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
46 /* Prototypes for static functions. */
48 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
49 static long ecoff_sec_to_styp_flags
PARAMS ((const char *name
,
51 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
52 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
53 asymbol
*asym
, int ext
,
54 asymbol
**indirect_ptr_ptr
));
55 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
57 RNDXR
*rndx
, long isym
,
59 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
61 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
63 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
64 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
65 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
66 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
67 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
72 /* This stuff is somewhat copied from coffcode.h. */
74 static asection bfd_debug_section
= { "*DEBUG*" };
76 /* Create an ECOFF object. */
79 _bfd_ecoff_mkobject (abfd
)
82 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
83 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
84 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
86 bfd_set_error (bfd_error_no_memory
);
93 /* This is a hook called by coff_real_object_p to create any backend
94 specific information. */
97 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
102 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
103 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
104 ecoff_data_type
*ecoff
;
106 if (_bfd_ecoff_mkobject (abfd
) == false)
109 ecoff
= ecoff_data (abfd
);
111 ecoff
->sym_filepos
= internal_f
->f_symptr
;
113 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
117 ecoff
->text_start
= internal_a
->text_start
;
118 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
119 ecoff
->gp
= internal_a
->gp_value
;
120 ecoff
->gprmask
= internal_a
->gprmask
;
121 for (i
= 0; i
< 4; i
++)
122 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
123 ecoff
->fprmask
= internal_a
->fprmask
;
124 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
125 abfd
->flags
|= D_PAGED
;
128 /* It turns out that no special action is required by the MIPS or
129 Alpha ECOFF backends. They have different information in the
130 a.out header, but we just copy it all (e.g., gprmask, cprmask and
131 fprmask) and let the swapping routines ensure that only relevant
132 information is written out. */
137 /* This is a hook needed by SCO COFF, but we have nothing to do. */
141 _bfd_ecoff_make_section_hook (abfd
, name
)
145 return (asection
*) NULL
;
148 /* Initialize a new section. */
151 _bfd_ecoff_new_section_hook (abfd
, section
)
155 /* For the .pdata section, which has a special meaning on the Alpha,
156 we set the alignment power to 3. We correct this later in
157 ecoff_compute_section_file_positions. We do this hackery because
158 we need to know the exact unaligned size of the .pdata section in
159 order to set the lnnoptr field correctly. For every other
160 section we use an alignment power of 4; this could be made target
161 dependent by adding a field to ecoff_backend_data, but 4 appears
162 to be correct for both the MIPS and the Alpha. */
163 if (strcmp (section
->name
, _PDATA
) == 0)
164 section
->alignment_power
= 3;
166 section
->alignment_power
= 4;
168 if (strcmp (section
->name
, _TEXT
) == 0)
169 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
170 else if (strcmp (section
->name
, _DATA
) == 0
171 || strcmp (section
->name
, _SDATA
) == 0)
172 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
173 else if (strcmp (section
->name
, _RDATA
) == 0
174 || strcmp (section
->name
, _LIT8
) == 0
175 || strcmp (section
->name
, _LIT4
) == 0)
176 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
177 else if (strcmp (section
->name
, _BSS
) == 0
178 || strcmp (section
->name
, _SBSS
) == 0)
179 section
->flags
|= SEC_ALLOC
;
180 else if (strcmp (section
->name
, _LIB
) == 0)
182 /* An Irix 4 shared libary. */
183 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
186 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
187 uncertain about .init on some systems and I don't know how shared
193 /* Determine the machine architecture and type. This is called from
194 the generic COFF routines. It is the inverse of ecoff_get_magic,
195 below. This could be an ECOFF backend routine, with one version
196 for each target, but there aren't all that many ECOFF targets. */
199 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
203 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
204 enum bfd_architecture arch
;
207 switch (internal_f
->f_magic
)
210 case MIPS_MAGIC_LITTLE
:
212 arch
= bfd_arch_mips
;
216 case MIPS_MAGIC_LITTLE2
:
217 case MIPS_MAGIC_BIG2
:
218 /* MIPS ISA level 2: the r6000 */
219 arch
= bfd_arch_mips
;
223 case MIPS_MAGIC_LITTLE3
:
224 case MIPS_MAGIC_BIG3
:
225 /* MIPS ISA level 3: the r4000 */
226 arch
= bfd_arch_mips
;
231 arch
= bfd_arch_alpha
;
236 arch
= bfd_arch_obscure
;
241 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
244 /* Get the magic number to use based on the architecture and machine.
245 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
248 ecoff_get_magic (abfd
)
253 switch (bfd_get_arch (abfd
))
256 switch (bfd_get_mach (abfd
))
261 big
= MIPS_MAGIC_BIG
;
262 little
= MIPS_MAGIC_LITTLE
;
266 big
= MIPS_MAGIC_BIG2
;
267 little
= MIPS_MAGIC_LITTLE2
;
271 big
= MIPS_MAGIC_BIG3
;
272 little
= MIPS_MAGIC_LITTLE3
;
276 return abfd
->xvec
->byteorder_big_p
? big
: little
;
287 /* Get the section s_flags to use for a section. */
290 ecoff_sec_to_styp_flags (name
, flags
)
298 if (strcmp (name
, _TEXT
) == 0)
300 else if (strcmp (name
, _DATA
) == 0)
302 else if (strcmp (name
, _SDATA
) == 0)
304 else if (strcmp (name
, _RDATA
) == 0)
306 else if (strcmp (name
, _LITA
) == 0)
308 else if (strcmp (name
, _LIT8
) == 0)
310 else if (strcmp (name
, _LIT4
) == 0)
312 else if (strcmp (name
, _BSS
) == 0)
314 else if (strcmp (name
, _SBSS
) == 0)
316 else if (strcmp (name
, _INIT
) == 0)
317 styp
= STYP_ECOFF_INIT
;
318 else if (strcmp (name
, _FINI
) == 0)
319 styp
= STYP_ECOFF_FINI
;
320 else if (strcmp (name
, _PDATA
) == 0)
322 else if (strcmp (name
, _XDATA
) == 0)
324 else if (strcmp (name
, _LIB
) == 0)
325 styp
= STYP_ECOFF_LIB
;
326 else if (flags
& SEC_CODE
)
328 else if (flags
& SEC_DATA
)
330 else if (flags
& SEC_READONLY
)
332 else if (flags
& SEC_LOAD
)
337 if (flags
& SEC_NEVER_LOAD
)
343 /* Get the BFD flags to use for a section. */
347 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
)
352 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
353 long styp_flags
= internal_s
->s_flags
;
354 flagword sec_flags
=0;
356 if (styp_flags
& STYP_NOLOAD
)
357 sec_flags
|= SEC_NEVER_LOAD
;
359 /* For 386 COFF, at least, an unloadable text or data section is
360 actually a shared library section. */
361 if ((styp_flags
& STYP_TEXT
)
362 || (styp_flags
& STYP_ECOFF_INIT
)
363 || (styp_flags
& STYP_ECOFF_FINI
))
365 if (sec_flags
& SEC_NEVER_LOAD
)
366 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
368 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
370 else if ((styp_flags
& STYP_DATA
)
371 || (styp_flags
& STYP_RDATA
)
372 || (styp_flags
& STYP_SDATA
)
373 || styp_flags
== STYP_PDATA
374 || styp_flags
== STYP_XDATA
)
376 if (sec_flags
& SEC_NEVER_LOAD
)
377 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
379 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
380 if ((styp_flags
& STYP_RDATA
)
381 || styp_flags
== STYP_PDATA
)
382 sec_flags
|= SEC_READONLY
;
384 else if ((styp_flags
& STYP_BSS
)
385 || (styp_flags
& STYP_SBSS
))
387 sec_flags
|= SEC_ALLOC
;
389 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
391 sec_flags
|= SEC_NEVER_LOAD
;
393 else if ((styp_flags
& STYP_LITA
)
394 || (styp_flags
& STYP_LIT8
)
395 || (styp_flags
& STYP_LIT4
))
397 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
399 else if (styp_flags
& STYP_ECOFF_LIB
)
401 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
405 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
411 /* Routines to swap auxiliary information in and out. I am assuming
412 that the auxiliary information format is always going to be target
415 /* Swap in a type information record.
416 BIGEND says whether AUX symbols are big-endian or little-endian; this
417 info comes from the file header record (fh-fBigendian). */
420 _bfd_ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
422 const struct tir_ext
*ext_copy
;
425 struct tir_ext ext
[1];
427 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
429 /* now the fun stuff... */
431 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
432 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
433 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
434 >> TIR_BITS1_BT_SH_BIG
;
435 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
436 >> TIR_BITS_TQ4_SH_BIG
;
437 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
438 >> TIR_BITS_TQ5_SH_BIG
;
439 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
440 >> TIR_BITS_TQ0_SH_BIG
;
441 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
442 >> TIR_BITS_TQ1_SH_BIG
;
443 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
444 >> TIR_BITS_TQ2_SH_BIG
;
445 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
446 >> TIR_BITS_TQ3_SH_BIG
;
448 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
449 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
450 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
451 >> TIR_BITS1_BT_SH_LITTLE
;
452 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
453 >> TIR_BITS_TQ4_SH_LITTLE
;
454 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
455 >> TIR_BITS_TQ5_SH_LITTLE
;
456 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
457 >> TIR_BITS_TQ0_SH_LITTLE
;
458 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
459 >> TIR_BITS_TQ1_SH_LITTLE
;
460 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
461 >> TIR_BITS_TQ2_SH_LITTLE
;
462 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
463 >> TIR_BITS_TQ3_SH_LITTLE
;
467 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
472 /* Swap out a type information record.
473 BIGEND says whether AUX symbols are big-endian or little-endian; this
474 info comes from the file header record (fh-fBigendian). */
477 _bfd_ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
479 const TIR
*intern_copy
;
484 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
486 /* now the fun stuff... */
488 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
489 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
490 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
491 & TIR_BITS1_BT_BIG
));
492 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
494 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
495 & TIR_BITS_TQ5_BIG
));
496 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
498 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
499 & TIR_BITS_TQ1_BIG
));
500 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
502 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
503 & TIR_BITS_TQ3_BIG
));
505 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
506 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
507 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
508 & TIR_BITS1_BT_LITTLE
));
509 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
510 & TIR_BITS_TQ4_LITTLE
)
511 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
512 & TIR_BITS_TQ5_LITTLE
));
513 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
514 & TIR_BITS_TQ0_LITTLE
)
515 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
516 & TIR_BITS_TQ1_LITTLE
));
517 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
518 & TIR_BITS_TQ2_LITTLE
)
519 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
520 & TIR_BITS_TQ3_LITTLE
));
524 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
529 /* Swap in a relative symbol record. BIGEND says whether it is in
530 big-endian or little-endian format.*/
533 _bfd_ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
535 const struct rndx_ext
*ext_copy
;
538 struct rndx_ext ext
[1];
540 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
542 /* now the fun stuff... */
544 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
545 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
546 >> RNDX_BITS1_RFD_SH_BIG
);
547 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
548 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
549 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
550 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
552 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
553 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
554 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
555 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
556 >> RNDX_BITS1_INDEX_SH_LITTLE
)
557 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
558 | ((unsigned int) ext
->r_bits
[3]
559 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
563 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
568 /* Swap out a relative symbol record. BIGEND says whether it is in
569 big-endian or little-endian format.*/
572 _bfd_ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
574 const RNDXR
*intern_copy
;
575 struct rndx_ext
*ext
;
579 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
581 /* now the fun stuff... */
583 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
584 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
585 & RNDX_BITS1_RFD_BIG
)
586 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
587 & RNDX_BITS1_INDEX_BIG
));
588 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
589 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
591 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
592 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
593 & RNDX_BITS1_RFD_LITTLE
)
594 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
595 & RNDX_BITS1_INDEX_LITTLE
));
596 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
597 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
601 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
606 /* Read in the symbolic header for an ECOFF object file. */
609 ecoff_slurp_symbolic_header (abfd
)
612 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
613 bfd_size_type external_hdr_size
;
615 HDRR
*internal_symhdr
;
617 /* See if we've already read it in. */
618 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
619 backend
->debug_swap
.sym_magic
)
622 /* See whether there is a symbolic header. */
623 if (ecoff_data (abfd
)->sym_filepos
== 0)
625 bfd_get_symcount (abfd
) = 0;
629 /* At this point bfd_get_symcount (abfd) holds the number of symbols
630 as read from the file header, but on ECOFF this is always the
631 size of the symbolic information header. It would be cleaner to
632 handle this when we first read the file in coffgen.c. */
633 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
634 if (bfd_get_symcount (abfd
) != external_hdr_size
)
636 bfd_set_error (bfd_error_bad_value
);
640 /* Read the symbolic information header. */
641 raw
= (PTR
) malloc ((size_t) external_hdr_size
);
644 bfd_set_error (bfd_error_no_memory
);
648 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
649 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
650 != external_hdr_size
))
652 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
653 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
655 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
657 bfd_set_error (bfd_error_bad_value
);
661 /* Now we can get the correct number of symbols. */
662 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
663 + internal_symhdr
->iextMax
);
674 /* Read in and swap the important symbolic information for an ECOFF
675 object file. This is called by gdb via the read_debug_info entry
676 point in the backend structure. */
680 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
683 struct ecoff_debug_info
*debug
;
685 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
686 HDRR
*internal_symhdr
;
687 bfd_size_type raw_base
;
688 bfd_size_type raw_size
;
690 bfd_size_type external_fdr_size
;
694 bfd_size_type raw_end
;
695 bfd_size_type cb_end
;
697 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
699 /* Check whether we've already gotten it, and whether there's any to
701 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
703 if (ecoff_data (abfd
)->sym_filepos
== 0)
705 bfd_get_symcount (abfd
) = 0;
709 if (! ecoff_slurp_symbolic_header (abfd
))
712 internal_symhdr
= &debug
->symbolic_header
;
714 /* Read all the symbolic information at once. */
715 raw_base
= (ecoff_data (abfd
)->sym_filepos
716 + backend
->debug_swap
.external_hdr_size
);
718 /* Alpha ecoff makes the determination of raw_size difficult. It has
719 an undocumented debug data section between the symhdr and the first
720 documented section. And the ordering of the sections varies between
721 statically and dynamically linked executables.
722 If bfd supports SEEK_END someday, this code could be simplified. */
726 #define UPDATE_RAW_END(start, count, size) \
727 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
728 if (cb_end > raw_end) \
731 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
732 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
733 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
734 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
735 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
736 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
737 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
738 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
739 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
740 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
741 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
743 #undef UPDATE_RAW_END
745 raw_size
= raw_end
- raw_base
;
748 ecoff_data (abfd
)->sym_filepos
= 0;
751 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
754 bfd_set_error (bfd_error_no_memory
);
758 (ecoff_data (abfd
)->sym_filepos
759 + backend
->debug_swap
.external_hdr_size
),
761 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
763 bfd_release (abfd
, raw
);
767 ecoff_data (abfd
)->raw_syments
= raw
;
769 /* Get pointers for the numeric offsets in the HDRR structure. */
770 #define FIX(off1, off2, type) \
771 if (internal_symhdr->off1 == 0) \
772 debug->off2 = (type) NULL; \
774 debug->off2 = (type) ((char *) raw \
775 + internal_symhdr->off1 \
777 FIX (cbLineOffset
, line
, unsigned char *);
778 FIX (cbDnOffset
, external_dnr
, PTR
);
779 FIX (cbPdOffset
, external_pdr
, PTR
);
780 FIX (cbSymOffset
, external_sym
, PTR
);
781 FIX (cbOptOffset
, external_opt
, PTR
);
782 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
783 FIX (cbSsOffset
, ss
, char *);
784 FIX (cbSsExtOffset
, ssext
, char *);
785 FIX (cbFdOffset
, external_fdr
, PTR
);
786 FIX (cbRfdOffset
, external_rfd
, PTR
);
787 FIX (cbExtOffset
, external_ext
, PTR
);
790 /* I don't want to always swap all the data, because it will just
791 waste time and most programs will never look at it. The only
792 time the linker needs most of the debugging information swapped
793 is when linking big-endian and little-endian MIPS object files
794 together, which is not a common occurrence.
796 We need to look at the fdr to deal with a lot of information in
797 the symbols, so we swap them here. */
798 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
,
799 (internal_symhdr
->ifdMax
*
800 sizeof (struct fdr
)));
801 if (debug
->fdr
== NULL
)
803 bfd_set_error (bfd_error_no_memory
);
806 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
807 fdr_ptr
= debug
->fdr
;
808 fraw_src
= (char *) debug
->external_fdr
;
809 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
810 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
811 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
816 /* ECOFF symbol table routines. The ECOFF symbol table is described
817 in gcc/mips-tfile.c. */
819 /* ECOFF uses two common sections. One is the usual one, and the
820 other is for small objects. All the small objects are kept
821 together, and then referenced via the gp pointer, which yields
822 faster assembler code. This is what we use for the small common
824 static asection ecoff_scom_section
;
825 static asymbol ecoff_scom_symbol
;
826 static asymbol
*ecoff_scom_symbol_ptr
;
828 /* Create an empty symbol. */
831 _bfd_ecoff_make_empty_symbol (abfd
)
834 ecoff_symbol_type
*new;
836 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
837 if (new == (ecoff_symbol_type
*) NULL
)
839 bfd_set_error (bfd_error_no_memory
);
840 return (asymbol
*) NULL
;
842 memset ((PTR
) new, 0, sizeof *new);
843 new->symbol
.section
= (asection
*) NULL
;
844 new->fdr
= (FDR
*) NULL
;
847 new->symbol
.the_bfd
= abfd
;
851 /* Set the BFD flags and section for an ECOFF symbol. */
854 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
859 asymbol
**indirect_ptr_ptr
;
861 asym
->the_bfd
= abfd
;
862 asym
->value
= ecoff_sym
->value
;
863 asym
->section
= &bfd_debug_section
;
866 /* An indirect symbol requires two consecutive stabs symbols. */
867 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
869 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
871 /* @@ Stuffing pointers into integers is a no-no.
872 We can usually get away with it if the integer is
873 large enough though. */
874 if (sizeof (asym
) > sizeof (bfd_vma
))
876 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
878 asym
->flags
= BSF_DEBUGGING
;
879 asym
->section
= bfd_und_section_ptr
;
880 *indirect_ptr_ptr
= NULL
;
884 if (ECOFF_IS_STAB (ecoff_sym
)
885 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
887 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
888 asym
->section
= bfd_ind_section_ptr
;
889 /* Pass this symbol on to the next call to this function. */
890 *indirect_ptr_ptr
= asym
;
894 /* Most symbol types are just for debugging. */
895 switch (ecoff_sym
->st
)
904 if (ECOFF_IS_STAB (ecoff_sym
))
906 asym
->flags
= BSF_DEBUGGING
;
911 asym
->flags
= BSF_DEBUGGING
;
916 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
919 asym
->flags
= BSF_LOCAL
;
920 /* Normally, a local stProc symbol will have a corresponding
921 external symbol. We mark the local symbol as a debugging
922 symbol, in order to prevent nm from printing both out.
923 Similarly, we mark stLabel and stabs symbols as debugging
924 symbols. In both cases, we do want to set the value
925 correctly based on the symbol class. */
926 if (ecoff_sym
->st
== stProc
927 || ecoff_sym
->st
== stLabel
928 || ECOFF_IS_STAB (ecoff_sym
))
929 asym
->flags
|= BSF_DEBUGGING
;
931 switch (ecoff_sym
->sc
)
934 /* Used for compiler generated labels. Leave them in the
935 debugging section, and mark them as local. If BSF_DEBUGGING
936 is set, then nm does not display them for some reason. If no
937 flags are set then the linker whines about them. */
938 asym
->flags
= BSF_LOCAL
;
941 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
942 asym
->value
-= asym
->section
->vma
;
945 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
946 asym
->value
-= asym
->section
->vma
;
949 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
950 asym
->value
-= asym
->section
->vma
;
953 asym
->flags
= BSF_DEBUGGING
;
956 asym
->section
= bfd_abs_section_ptr
;
959 asym
->section
= bfd_und_section_ptr
;
969 asym
->flags
= BSF_DEBUGGING
;
972 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
973 asym
->value
-= asym
->section
->vma
;
976 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
977 asym
->value
-= asym
->section
->vma
;
980 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
981 asym
->value
-= asym
->section
->vma
;
984 asym
->flags
= BSF_DEBUGGING
;
987 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
989 asym
->section
= bfd_com_section_ptr
;
995 if (ecoff_scom_section
.name
== NULL
)
997 /* Initialize the small common section. */
998 ecoff_scom_section
.name
= SCOMMON
;
999 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
1000 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
1001 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
1002 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
1003 ecoff_scom_symbol
.name
= SCOMMON
;
1004 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
1005 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
1006 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
1008 asym
->section
= &ecoff_scom_section
;
1013 asym
->flags
= BSF_DEBUGGING
;
1016 asym
->section
= bfd_und_section_ptr
;
1021 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
1022 asym
->value
-= asym
->section
->vma
;
1027 asym
->flags
= BSF_DEBUGGING
;
1030 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
1031 asym
->value
-= asym
->section
->vma
;
1037 /* Look for special constructors symbols and make relocation entries
1038 in a special construction section. These are produced by the
1039 -fgnu-linker argument to g++. */
1040 if (ECOFF_IS_STAB (ecoff_sym
))
1042 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1054 arelent_chain
*reloc_chain
;
1055 unsigned int bitsize
;
1057 /* Get a section with the same name as the symbol (usually
1058 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1059 name ___CTOR_LIST (three underscores). We need
1060 __CTOR_LIST (two underscores), since ECOFF doesn't use
1061 a leading underscore. This should be handled by gcc,
1062 but instead we do it here. Actually, this should all
1063 be done differently anyhow. */
1064 name
= bfd_asymbol_name (asym
);
1065 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1070 section
= bfd_get_section_by_name (abfd
, name
);
1071 if (section
== (asection
*) NULL
)
1075 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1078 bfd_set_error (bfd_error_no_memory
);
1081 strcpy (copy
, name
);
1082 section
= bfd_make_section (abfd
, copy
);
1085 /* Build a reloc pointing to this constructor. */
1087 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1090 bfd_set_error (bfd_error_no_memory
);
1093 reloc_chain
->relent
.sym_ptr_ptr
=
1094 bfd_get_section (asym
)->symbol_ptr_ptr
;
1095 reloc_chain
->relent
.address
= section
->_raw_size
;
1096 reloc_chain
->relent
.addend
= asym
->value
;
1097 reloc_chain
->relent
.howto
=
1098 ecoff_backend (abfd
)->constructor_reloc
;
1100 /* Set up the constructor section to hold the reloc. */
1101 section
->flags
= SEC_CONSTRUCTOR
;
1102 ++section
->reloc_count
;
1104 /* Constructor sections must be rounded to a boundary
1105 based on the bitsize. These are not real sections--
1106 they are handled specially by the linker--so the ECOFF
1107 16 byte alignment restriction does not apply. */
1108 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1109 section
->alignment_power
= 1;
1110 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1111 ++section
->alignment_power
;
1113 reloc_chain
->next
= section
->constructor_chain
;
1114 section
->constructor_chain
= reloc_chain
;
1115 section
->_raw_size
+= bitsize
/ 8;
1117 /* Mark the symbol as a constructor. */
1118 asym
->flags
|= BSF_CONSTRUCTOR
;
1126 /* Read an ECOFF symbol table. */
1129 _bfd_ecoff_slurp_symbol_table (abfd
)
1132 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1133 const bfd_size_type external_ext_size
1134 = backend
->debug_swap
.external_ext_size
;
1135 const bfd_size_type external_sym_size
1136 = backend
->debug_swap
.external_sym_size
;
1137 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1138 = backend
->debug_swap
.swap_ext_in
;
1139 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1140 = backend
->debug_swap
.swap_sym_in
;
1141 bfd_size_type internal_size
;
1142 ecoff_symbol_type
*internal
;
1143 ecoff_symbol_type
*internal_ptr
;
1144 asymbol
*indirect_ptr
;
1150 /* If we've already read in the symbol table, do nothing. */
1151 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1154 /* Get the symbolic information. */
1155 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1156 &ecoff_data (abfd
)->debug_info
))
1158 if (bfd_get_symcount (abfd
) == 0)
1161 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1162 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1163 if (internal
== NULL
)
1165 bfd_set_error (bfd_error_no_memory
);
1169 internal_ptr
= internal
;
1170 indirect_ptr
= NULL
;
1171 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1172 eraw_end
= (eraw_src
1173 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1174 * external_ext_size
));
1175 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1179 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1180 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1181 + internal_esym
.asym
.iss
);
1182 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1183 &internal_ptr
->symbol
, 1, &indirect_ptr
))
1185 /* The alpha uses a negative ifd field for section symbols. */
1186 if (internal_esym
.ifd
>= 0)
1187 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1188 + internal_esym
.ifd
);
1190 internal_ptr
->fdr
= NULL
;
1191 internal_ptr
->local
= false;
1192 internal_ptr
->native
= (PTR
) eraw_src
;
1194 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1196 /* The local symbols must be accessed via the fdr's, because the
1197 string and aux indices are relative to the fdr information. */
1198 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1199 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1200 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1205 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1206 + fdr_ptr
->isymBase
* external_sym_size
);
1207 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1209 lraw_src
< lraw_end
;
1210 lraw_src
+= external_sym_size
, internal_ptr
++)
1214 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1215 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1217 + internal_sym
.iss
);
1218 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1219 &internal_ptr
->symbol
, 0, &indirect_ptr
))
1221 internal_ptr
->fdr
= fdr_ptr
;
1222 internal_ptr
->local
= true;
1223 internal_ptr
->native
= (PTR
) lraw_src
;
1226 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1228 ecoff_data (abfd
)->canonical_symbols
= internal
;
1233 /* Return the amount of space needed for the canonical symbols. */
1236 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1239 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1240 &ecoff_data (abfd
)->debug_info
))
1243 if (bfd_get_symcount (abfd
) == 0)
1246 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1249 /* Get the canonical symbols. */
1252 _bfd_ecoff_get_symtab (abfd
, alocation
)
1254 asymbol
**alocation
;
1256 unsigned int counter
= 0;
1257 ecoff_symbol_type
*symbase
;
1258 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1260 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1262 if (bfd_get_symcount (abfd
) == 0)
1265 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1266 while (counter
< bfd_get_symcount (abfd
))
1268 *(location
++) = symbase
++;
1271 *location
++ = (ecoff_symbol_type
*) NULL
;
1272 return bfd_get_symcount (abfd
);
1275 /* Turn ECOFF type information into a printable string.
1276 ecoff_emit_aggregate and ecoff_type_to_string are from
1277 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1279 /* Write aggregate information to a string. */
1282 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1290 const struct ecoff_debug_swap
* const debug_swap
=
1291 &ecoff_backend (abfd
)->debug_swap
;
1292 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1293 unsigned int ifd
= rndx
->rfd
;
1294 unsigned int indx
= rndx
->index
;
1300 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1301 struct return type of a procedure compiled without -g. */
1302 if (ifd
== 0xffffffff
1303 || (rndx
->rfd
== 0xfff && indx
== 0))
1304 name
= "<undefined>";
1305 else if (indx
== indexNil
)
1311 if (debug_info
->external_rfd
== NULL
)
1312 fdr
= debug_info
->fdr
+ ifd
;
1317 (*debug_swap
->swap_rfd_in
) (abfd
,
1318 ((char *) debug_info
->external_rfd
1319 + ((fdr
->rfdBase
+ ifd
)
1320 * debug_swap
->external_rfd_size
)),
1322 fdr
= debug_info
->fdr
+ rfd
;
1325 indx
+= fdr
->isymBase
;
1327 (*debug_swap
->swap_sym_in
) (abfd
,
1328 ((char *) debug_info
->external_sym
1329 + indx
* debug_swap
->external_sym_size
),
1332 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1336 "%s %s { ifd = %u, index = %lu }",
1339 + debug_info
->symbolic_header
.iextMax
));
1342 /* Convert the type information to string format. */
1345 ecoff_type_to_string (abfd
, fdr
, indx
)
1350 union aux_ext
*aux_ptr
;
1359 unsigned int basic_type
;
1362 static char buffer2
[1024];
1367 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1368 bigendian
= fdr
->fBigendian
;
1370 for (i
= 0; i
< 7; i
++)
1372 qualifiers
[i
].low_bound
= 0;
1373 qualifiers
[i
].high_bound
= 0;
1374 qualifiers
[i
].stride
= 0;
1377 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1378 return "-1 (no type)";
1379 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1381 basic_type
= u
.ti
.bt
;
1382 qualifiers
[0].type
= u
.ti
.tq0
;
1383 qualifiers
[1].type
= u
.ti
.tq1
;
1384 qualifiers
[2].type
= u
.ti
.tq2
;
1385 qualifiers
[3].type
= u
.ti
.tq3
;
1386 qualifiers
[4].type
= u
.ti
.tq4
;
1387 qualifiers
[5].type
= u
.ti
.tq5
;
1388 qualifiers
[6].type
= tqNil
;
1391 * Go get the basic type.
1395 case btNil
: /* undefined */
1399 case btAdr
: /* address - integer same size as pointer */
1400 strcpy (p1
, "address");
1403 case btChar
: /* character */
1404 strcpy (p1
, "char");
1407 case btUChar
: /* unsigned character */
1408 strcpy (p1
, "unsigned char");
1411 case btShort
: /* short */
1412 strcpy (p1
, "short");
1415 case btUShort
: /* unsigned short */
1416 strcpy (p1
, "unsigned short");
1419 case btInt
: /* int */
1423 case btUInt
: /* unsigned int */
1424 strcpy (p1
, "unsigned int");
1427 case btLong
: /* long */
1428 strcpy (p1
, "long");
1431 case btULong
: /* unsigned long */
1432 strcpy (p1
, "unsigned long");
1435 case btFloat
: /* float (real) */
1436 strcpy (p1
, "float");
1439 case btDouble
: /* Double (real) */
1440 strcpy (p1
, "double");
1443 /* Structures add 1-2 aux words:
1444 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1445 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1447 case btStruct
: /* Structure (Record) */
1448 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1449 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1450 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1452 indx
++; /* skip aux words */
1455 /* Unions add 1-2 aux words:
1456 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1457 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1459 case btUnion
: /* Union */
1460 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1461 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1462 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1464 indx
++; /* skip aux words */
1467 /* Enumerations add 1-2 aux words:
1468 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1469 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1471 case btEnum
: /* Enumeration */
1472 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1473 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1474 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1476 indx
++; /* skip aux words */
1479 case btTypedef
: /* defined via a typedef, isymRef points */
1480 strcpy (p1
, "typedef");
1483 case btRange
: /* subrange of int */
1484 strcpy (p1
, "subrange");
1487 case btSet
: /* pascal sets */
1491 case btComplex
: /* fortran complex */
1492 strcpy (p1
, "complex");
1495 case btDComplex
: /* fortran double complex */
1496 strcpy (p1
, "double complex");
1499 case btIndirect
: /* forward or unnamed typedef */
1500 strcpy (p1
, "forward/unamed typedef");
1503 case btFixedDec
: /* Fixed Decimal */
1504 strcpy (p1
, "fixed decimal");
1507 case btFloatDec
: /* Float Decimal */
1508 strcpy (p1
, "float decimal");
1511 case btString
: /* Varying Length Character String */
1512 strcpy (p1
, "string");
1515 case btBit
: /* Aligned Bit String */
1519 case btPicture
: /* Picture */
1520 strcpy (p1
, "picture");
1523 case btVoid
: /* Void */
1524 strcpy (p1
, "void");
1528 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1532 p1
+= strlen (buffer1
);
1535 * If this is a bitfield, get the bitsize.
1541 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1542 sprintf (p1
, " : %d", bitsize
);
1543 p1
+= strlen (buffer1
);
1548 * Deal with any qualifiers.
1550 if (qualifiers
[0].type
!= tqNil
)
1553 * Snarf up any array bounds in the correct order. Arrays
1554 * store 5 successive words in the aux. table:
1555 * word 0 RNDXR to type of the bounds (ie, int)
1556 * word 1 Current file descriptor index
1558 * word 3 high bound (or -1 if [])
1559 * word 4 stride size in bits
1561 for (i
= 0; i
< 7; i
++)
1563 if (qualifiers
[i
].type
== tqArray
)
1565 qualifiers
[i
].low_bound
=
1566 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1567 qualifiers
[i
].high_bound
=
1568 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1569 qualifiers
[i
].stride
=
1570 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1576 * Now print out the qualifiers.
1578 for (i
= 0; i
< 6; i
++)
1580 switch (qualifiers
[i
].type
)
1587 strcpy (p2
, "ptr to ");
1588 p2
+= sizeof ("ptr to ")-1;
1592 strcpy (p2
, "volatile ");
1593 p2
+= sizeof ("volatile ")-1;
1597 strcpy (p2
, "far ");
1598 p2
+= sizeof ("far ")-1;
1602 strcpy (p2
, "func. ret. ");
1603 p2
+= sizeof ("func. ret. ");
1608 int first_array
= i
;
1611 /* Print array bounds reversed (ie, in the order the C
1612 programmer writes them). C is such a fun language.... */
1614 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1617 for (j
= i
; j
>= first_array
; j
--)
1619 strcpy (p2
, "array [");
1620 p2
+= sizeof ("array [")-1;
1621 if (qualifiers
[j
].low_bound
!= 0)
1623 "%ld:%ld {%ld bits}",
1624 (long) qualifiers
[j
].low_bound
,
1625 (long) qualifiers
[j
].high_bound
,
1626 (long) qualifiers
[j
].stride
);
1628 else if (qualifiers
[j
].high_bound
!= -1)
1631 (long) (qualifiers
[j
].high_bound
+ 1),
1632 (long) (qualifiers
[j
].stride
));
1635 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1638 strcpy (p2
, "] of ");
1639 p2
+= sizeof ("] of ")-1;
1647 strcpy (p2
, buffer1
);
1651 /* Return information about ECOFF symbol SYMBOL in RET. */
1655 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1656 bfd
*abfd
; /* Ignored. */
1660 bfd_symbol_info (symbol
, ret
);
1663 /* Print information about an ECOFF symbol. */
1666 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1670 bfd_print_symbol_type how
;
1672 const struct ecoff_debug_swap
* const debug_swap
1673 = &ecoff_backend (abfd
)->debug_swap
;
1674 FILE *file
= (FILE *)filep
;
1678 case bfd_print_symbol_name
:
1679 fprintf (file
, "%s", symbol
->name
);
1681 case bfd_print_symbol_more
:
1682 if (ecoffsymbol (symbol
)->local
)
1686 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1688 fprintf (file
, "ecoff local ");
1689 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1690 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1691 (unsigned) ecoff_sym
.sc
);
1697 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1699 fprintf (file
, "ecoff extern ");
1700 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1701 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1702 (unsigned) ecoff_ext
.asym
.sc
);
1705 case bfd_print_symbol_all
:
1706 /* Print out the symbols in a reasonable way */
1715 if (ecoffsymbol (symbol
)->local
)
1717 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1720 pos
= ((((char *) ecoffsymbol (symbol
)->native
1721 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1722 / debug_swap
->external_sym_size
)
1723 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1730 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1733 pos
= (((char *) ecoffsymbol (symbol
)->native
1734 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1735 / debug_swap
->external_ext_size
);
1736 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1737 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1738 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1741 fprintf (file
, "[%3d] %c ",
1743 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1744 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1745 (unsigned) ecoff_ext
.asym
.st
,
1746 (unsigned) ecoff_ext
.asym
.sc
,
1747 (unsigned) ecoff_ext
.asym
.index
,
1748 jmptbl
, cobol_main
, weakext
,
1751 if (ecoffsymbol (symbol
)->fdr
!= NULL
1752 && ecoff_ext
.asym
.index
!= indexNil
)
1757 bfd_size_type sym_base
;
1758 union aux_ext
*aux_base
;
1760 fdr
= ecoffsymbol (symbol
)->fdr
;
1761 indx
= ecoff_ext
.asym
.index
;
1763 /* sym_base is used to map the fdr relative indices which
1764 appear in the file to the position number which we are
1766 sym_base
= fdr
->isymBase
;
1767 if (ecoffsymbol (symbol
)->local
)
1769 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1771 /* aux_base is the start of the aux entries for this file;
1772 asym.index is an offset from this. */
1773 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1776 /* The aux entries are stored in host byte order; the
1777 order is indicated by a bit in the fdr. */
1778 bigendian
= fdr
->fBigendian
;
1780 /* This switch is basically from gcc/mips-tdump.c */
1781 switch (ecoff_ext
.asym
.st
)
1789 fprintf (file
, "\n End+1 symbol: %ld",
1790 (long) (indx
+ sym_base
));
1794 if (ecoff_ext
.asym
.sc
== scText
1795 || ecoff_ext
.asym
.sc
== scInfo
)
1796 fprintf (file
, "\n First symbol: %ld",
1797 (long) (indx
+ sym_base
));
1799 fprintf (file
, "\n First symbol: %ld",
1801 (AUX_GET_ISYM (bigendian
,
1802 &aux_base
[ecoff_ext
.asym
.index
])
1808 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1810 else if (ecoffsymbol (symbol
)->local
)
1811 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1813 (AUX_GET_ISYM (bigendian
,
1814 &aux_base
[ecoff_ext
.asym
.index
])
1816 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1818 fprintf (file
, "\n Local symbol: %ld",
1821 + (ecoff_data (abfd
)
1822 ->debug_info
.symbolic_header
.iextMax
)));
1826 fprintf (file
, "\n struct; End+1 symbol: %ld",
1827 (long) (indx
+ sym_base
));
1831 fprintf (file
, "\n union; End+1 symbol: %ld",
1832 (long) (indx
+ sym_base
));
1836 fprintf (file
, "\n enum; End+1 symbol: %ld",
1837 (long) (indx
+ sym_base
));
1841 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1842 fprintf (file
, "\n Type: %s",
1843 ecoff_type_to_string (abfd
, fdr
, indx
));
1852 /* Read in the relocs for a section. */
1855 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1860 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1861 arelent
*internal_relocs
;
1862 bfd_size_type external_reloc_size
;
1863 bfd_size_type external_relocs_size
;
1864 char *external_relocs
;
1868 if (section
->relocation
!= (arelent
*) NULL
1869 || section
->reloc_count
== 0
1870 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1873 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1876 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1878 * section
->reloc_count
));
1879 external_reloc_size
= backend
->external_reloc_size
;
1880 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1881 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1882 if (internal_relocs
== (arelent
*) NULL
1883 || external_relocs
== (char *) NULL
)
1885 bfd_set_error (bfd_error_no_memory
);
1888 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1890 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1891 != external_relocs_size
)
1894 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1896 struct internal_reloc intern
;
1898 (*backend
->swap_reloc_in
) (abfd
,
1899 external_relocs
+ i
* external_reloc_size
,
1902 if (intern
.r_extern
)
1904 /* r_symndx is an index into the external symbols. */
1905 BFD_ASSERT (intern
.r_symndx
>= 0
1907 < (ecoff_data (abfd
)
1908 ->debug_info
.symbolic_header
.iextMax
)));
1909 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1912 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1913 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1915 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1920 CONST
char *sec_name
;
1923 /* r_symndx is a section key. */
1924 switch (intern
.r_symndx
)
1926 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1927 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1928 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1929 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1930 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1931 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1932 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1933 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1934 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1935 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1936 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1937 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1938 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1942 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1943 if (sec
== (asection
*) NULL
)
1945 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1947 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1950 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1952 /* Let the backend select the howto field and do any other
1953 required processing. */
1954 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1957 bfd_release (abfd
, external_relocs
);
1959 section
->relocation
= internal_relocs
;
1964 /* Get a canonical list of relocs. */
1967 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1975 if (section
->flags
& SEC_CONSTRUCTOR
)
1977 arelent_chain
*chain
;
1979 /* This section has relocs made up by us, not the file, so take
1980 them out of their chain and place them into the data area
1982 for (count
= 0, chain
= section
->constructor_chain
;
1983 count
< section
->reloc_count
;
1984 count
++, chain
= chain
->next
)
1985 *relptr
++ = &chain
->relent
;
1991 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1994 tblptr
= section
->relocation
;
1996 for (count
= 0; count
< section
->reloc_count
; count
++)
1997 *relptr
++ = tblptr
++;
2000 *relptr
= (arelent
*) NULL
;
2002 return section
->reloc_count
;
2007 cmp_fdrtab_entry (leftp
, rightp
)
2008 const void *leftp
, *rightp
;
2010 const struct ecoff_fdrtab_entry
*lp
= leftp
;
2011 const struct ecoff_fdrtab_entry
*rp
= rightp
;
2013 if (lp
->base_addr
< rp
->base_addr
)
2015 if (lp
->base_addr
> rp
->base_addr
)
2020 /* Each file descriptor (FDR) has a memory address, to simplify
2021 looking up an FDR by address, we build a table covering all FDRs
2022 that have a least one procedure descriptor in them. The final
2023 table will be sorted by address so we can look it up via binary
2029 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
2030 const struct ecoff_debug_swap
* const debug_swap
2031 = &ecoff_backend (abfd
)->debug_swap
;
2032 struct ecoff_fdrtab_entry
*tab
;
2039 /* Make sure we have the FDR's. */
2040 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
2041 || bfd_get_symcount (abfd
) == 0)
2044 fdr_start
= debug_info
->fdr
;
2045 fdr_end
= fdr_start
+ debug_info
->symbolic_header
.ifdMax
;
2047 /* First, let's see how long the table needs to be: */
2048 for (len
= 0, fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2050 if (fdr_ptr
->cpd
== 0) /* skip FDRs that have no PDRs */
2055 /* Now, create and fill in the table: */
2057 ecoff_data (abfd
)->fdrtab
= (struct ecoff_fdrtab_entry
*)
2058 bfd_zalloc (abfd
,len
* sizeof (struct ecoff_fdrtab_entry
));
2059 if (ecoff_data (abfd
)->fdrtab
== NULL
)
2061 bfd_set_error (bfd_error_no_memory
);
2064 ecoff_data (abfd
)->fdrtab_len
= len
;
2066 tab
= ecoff_data (abfd
)->fdrtab
;
2067 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2069 if (fdr_ptr
->cpd
== 0)
2072 /* Check whether this file has stabs debugging information. In
2073 a file with stabs debugging information, the second local
2074 symbol is named @stabs. */
2076 if (fdr_ptr
->csym
>= 2)
2081 sym_ptr
= ((char *) debug_info
->external_sym
2082 + (fdr_ptr
->isymBase
+ 1)*debug_swap
->external_sym_size
);
2083 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
2084 if (strcmp (debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
,
2091 bfd_size_type external_pdr_size
;
2095 external_pdr_size
= debug_swap
->external_pdr_size
;
2097 pdr_ptr
= ((char *) debug_info
->external_pdr
2098 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2099 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2100 /* The address of the first PDR is the offset of that
2101 procedure relative to the beginning of file FDR. */
2102 tab
->base_addr
= fdr_ptr
->adr
- pdr
.adr
;
2106 /* XXX I don't know about stabs, so this is a guess
2107 (davidm@cs.arizona.edu): */
2108 tab
->base_addr
= fdr_ptr
->adr
;
2113 /* Finally, the table is sorted in increasing memory-address order.
2114 The table is mostly sorted already, but there are cases (e.g.,
2115 static functions in include files), where this does not hold.
2116 Use "odump -PFv" to verify... */
2117 qsort((char*) ecoff_data (abfd
)->fdrtab
, len
,
2118 sizeof(struct ecoff_fdrtab_entry
), cmp_fdrtab_entry
);
2123 /* Return index of first FDR that covers to OFFSET. */
2125 lookup (abfd
, offset
)
2129 long low
, high
, len
;
2131 struct ecoff_fdrtab_entry
*tab
;
2133 len
= ecoff_data(abfd
)->fdrtab_len
;
2137 tab
= ecoff_data(abfd
)->fdrtab
;
2138 for (low
= 0, high
= len
- 1 ; low
!= high
;)
2140 mid
= (high
+ low
) / 2;
2141 if (offset
>= tab
[mid
].base_addr
&& offset
< tab
[mid
+ 1].base_addr
)
2144 if (tab
[mid
].base_addr
> offset
)
2151 /* last entry is catch-all for all higher addresses: */
2152 if (offset
< tab
[mid
].base_addr
)
2157 while (mid
> 0 && tab
[mid
- 1].base_addr
== tab
[mid
].base_addr
)
2163 /* Provided a BFD, a section and an offset into the section, calculate
2164 and return the name of the source file and the line nearest to the
2169 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
2170 filename_ptr
, functionname_ptr
, retline_ptr
)
2173 asymbol
**ignore_symbols
;
2175 CONST
char **filename_ptr
;
2176 CONST
char **functionname_ptr
;
2177 unsigned int *retline_ptr
;
2179 const struct ecoff_debug_swap
* const debug_swap
2180 = &ecoff_backend (abfd
)->debug_swap
;
2181 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
2182 struct ecoff_fdrtab_entry
*tab
;
2187 offset
+= section
->vma
;
2188 /* If we're not in the .text section, we don't have any line
2190 if (strcmp (section
->name
, _TEXT
) != 0
2191 || offset
< ecoff_data (abfd
)->text_start
2192 || offset
>= ecoff_data (abfd
)->text_end
)
2194 /* Build FDR table (sorted by object file's base-address) if we
2195 don't have it already. */
2196 if (!ecoff_data (abfd
)->fdrtab
&& !mk_fdrtab (abfd
))
2198 tab
= ecoff_data (abfd
)->fdrtab
;
2200 i
= lookup(abfd
, offset
); /* find first FDR for address OFFSET */
2202 return false; /* no FDR, no fun... */
2203 fdr_ptr
= tab
[i
].fdr
;
2205 /* Check whether this file has stabs debugging information. In a
2206 file with stabs debugging information, the second local symbol is
2209 if (fdr_ptr
->csym
>= 2)
2214 sym_ptr
= ((char *) debug_info
->external_sym
2215 + (fdr_ptr
->isymBase
+ 1) * debug_swap
->external_sym_size
);
2216 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
2217 if (strcmp (debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
,
2224 bfd_size_type external_pdr_size
;
2226 char *best_pdr
= NULL
;
2228 bfd_vma best_dist
= ~0;
2230 unsigned char *line_ptr
;
2231 unsigned char *line_end
;
2233 /* This file uses ECOFF debugging information. Each FDR has a
2234 list of procedure descriptors (PDR). The address in the FDR
2235 is the absolute address of the first procedure. The address
2236 in the first PDR gives the offset of that procedure relative
2237 to the object file's base-address. The addresses in
2238 subsequent PDRs specify each procedure's address relative to
2239 the object file's base-address. To make things more juicy,
2240 whenever the PROF bit in the PDR is set, the real entry point
2241 of the procedure may be 16 bytes below what would normally be
2242 the procedure's entry point. Instead, DEC came up with a
2243 wicked scheme to create profiled libraries "on the fly":
2244 instead of shipping a regular and a profiled version of each
2245 library, they insert 16 bytes of unused space in front of
2246 each procedure and set the "prof" bit in the PDR to indicate
2247 that there is a gap there (this is done automagically by "as"
2248 when option "-pg" is specified). Thus, normally, you link
2249 against such a library and, except for lots of 16 byte gaps
2250 between functions, things will behave as usual. However,
2251 when invoking "ld" with option "-pg", it will fill those gaps
2252 with code that calls mcount(). It then moves the function's
2253 entry point down by 16 bytes, and out pops a binary that has
2254 all functions profiled.
2256 NOTE: Neither FDRs nor PDRs are strictly sorted in memory
2257 order. For example, when including header-files that
2258 define functions, the FDRs follow behind the including
2259 file, even though their code may have been generated at
2260 a lower address. File coff-alpha.c from libbfd
2261 illustrates this (use "odump -PFv" to look at a file's
2262 FDR/PDR). Similarly, PDRs are sometimes out of order
2263 as well. An example of this is OSF/1 v3.0 libc's
2264 malloc.c. I'm not sure why this happens, but it could
2265 be due to optimizations that reorder a function's
2266 position within an object-file.
2270 On the first call to this function, we build a table of FDRs
2271 that is sorted by the base-address of the object-file the FDR
2272 is referring to. Notice that each object-file may contain
2273 code from multiple source files (e.g., due to code defined in
2274 include files). Thus, for any given base-address, there may
2275 be multiple FDRs (but this case is, fortunately, uncommon).
2276 lookup(addr) guarantees to return the first FDR that applies
2277 to address ADDR. Thus, after invoking lookup(), we have a
2278 list of FDRs that may contain the PDR for ADDR. Next, we
2279 walk through the PDRs of these FDRs and locate the one that
2280 is closest to ADDR (i.e., for which the difference between
2281 ADDR and the PDR's entry point is positive and minimal).
2282 Once, the right FDR and PDR are located, we simply walk
2283 through the line-number table to lookup the line-number that
2284 best matches ADDR. Obviously, things could be sped up by
2285 keeping a sorted list of PDRs instead of a sorted list of
2286 FDRs. However, this would increase space requirements
2287 considerably, which is undesirable. */
2288 external_pdr_size
= debug_swap
->external_pdr_size
;
2290 /* Make offset relative to object file's start-address: */
2291 offset
-= tab
[i
].base_addr
;
2292 /* Search FDR list starting at tab[i] for the PDR that best matches
2293 OFFSET. Normally, the FDR list is only one entry long. */
2297 bfd_vma dist
, min_dist
= 0;
2301 fdr_ptr
= tab
[i
].fdr
;
2303 pdr_ptr
= ((char *) debug_info
->external_pdr
2304 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2305 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2306 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2307 /* Find PDR that is closest to OFFSET. If pdr.prof is set,
2308 the procedure entry-point *may* be 0x10 below pdr.adr. We
2309 simply pretend that pdr.prof *implies* a lower entry-point.
2310 This is safe because it just means that may identify 4 NOPs
2311 in front of the function as belonging to the function. */
2312 for (pdr_hold
= NULL
;
2314 (pdr_ptr
+= external_pdr_size
,
2315 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
)))
2317 if (offset
>= (pdr
.adr
- 0x10 * pdr
.prof
))
2319 dist
= offset
- (pdr
.adr
- 0x10 * pdr
.prof
);
2320 if (!pdr_hold
|| dist
< min_dist
)
2328 if (!best_pdr
|| min_dist
< best_dist
)
2330 best_dist
= min_dist
;
2332 best_pdr
= pdr_hold
;
2334 /* continue looping until base_addr of next entry is different: */
2336 while (++i
< ecoff_data (abfd
)->fdrtab_len
2337 && tab
[i
].base_addr
== tab
[i
- 1].base_addr
);
2339 if (!best_fdr
|| !best_pdr
)
2340 return false; /* shouldn't happen... */
2342 /* phew, finally we got something that we can hold onto: */
2345 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2346 /* Now we can look for the actual line number. The line numbers
2347 are stored in a very funky format, which I won't try to
2348 describe. The search is bounded by the end of the FDRs line
2350 line_end
= debug_info
->line
+ fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2352 /* Make offset relative to procedure entry: */
2353 offset
-= pdr
.adr
- 0x10 * pdr
.prof
;
2355 line_ptr
= debug_info
->line
+ fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2356 while (line_ptr
< line_end
)
2361 delta
= *line_ptr
>> 4;
2364 count
= (*line_ptr
& 0xf) + 1;
2368 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2369 if (delta
>= 0x8000)
2374 if (offset
< count
* 4)
2376 offset
-= count
* 4;
2379 /* If fdr_ptr->rss is -1, then this file does not have full
2380 symbols, at least according to gdb/mipsread.c. */
2381 if (fdr_ptr
->rss
== -1)
2383 *filename_ptr
= NULL
;
2385 *functionname_ptr
= NULL
;
2390 (*debug_swap
->swap_ext_in
)
2392 ((char *) debug_info
->external_ext
2393 + pdr
.isym
* debug_swap
->external_ext_size
),
2395 *functionname_ptr
= debug_info
->ssext
+ proc_ext
.asym
.iss
;
2402 *filename_ptr
= debug_info
->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2403 (*debug_swap
->swap_sym_in
)
2405 ((char *) debug_info
->external_sym
2406 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2408 *functionname_ptr
= debug_info
->ss
+ fdr_ptr
->issBase
+ proc_sym
.iss
;
2410 if (lineno
== ilineNil
)
2412 *retline_ptr
= lineno
;
2416 bfd_size_type external_sym_size
;
2417 const char *directory_name
;
2418 const char *main_file_name
;
2419 const char *current_file_name
;
2420 const char *function_name
;
2421 const char *line_file_name
;
2422 bfd_vma low_func_vma
;
2423 bfd_vma low_line_vma
;
2424 char *sym_ptr
, *sym_ptr_end
;
2425 size_t len
, funclen
;
2426 char *buffer
= NULL
;
2428 /* This file uses stabs debugging information. */
2430 *filename_ptr
= NULL
;
2431 *functionname_ptr
= NULL
;
2434 directory_name
= NULL
;
2435 main_file_name
= NULL
;
2436 current_file_name
= NULL
;
2437 function_name
= NULL
;
2438 line_file_name
= NULL
;
2442 external_sym_size
= debug_swap
->external_sym_size
;
2444 sym_ptr
= ((char *) debug_info
->external_sym
2445 + (fdr_ptr
->isymBase
+ 2) * external_sym_size
);
2446 sym_ptr_end
= sym_ptr
+ fdr_ptr
->csym
* external_sym_size
;
2447 for (; sym_ptr
< sym_ptr_end
; sym_ptr
+= external_sym_size
)
2451 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
2453 if (ECOFF_IS_STAB (&sym
))
2455 switch (ECOFF_UNMARK_STAB (sym
.index
))
2458 main_file_name
= current_file_name
=
2459 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2461 /* Check the next symbol to see if it is also an
2463 if (sym_ptr
+ external_sym_size
< sym_ptr_end
)
2467 (*debug_swap
->swap_sym_in
) (abfd
,
2468 sym_ptr
+ external_sym_size
,
2470 if (ECOFF_IS_STAB (&nextsym
)
2471 && ECOFF_UNMARK_STAB (nextsym
.index
) == N_SO
)
2473 directory_name
= current_file_name
;
2474 main_file_name
= current_file_name
=
2475 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2476 sym_ptr
+= external_sym_size
;
2483 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2487 if (sym
.value
>= low_func_vma
2488 && sym
.value
<= offset
+ section
->vma
)
2490 low_func_vma
= sym
.value
;
2492 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2497 else if (sym
.st
== stLabel
&& sym
.index
!= indexNil
)
2499 if (sym
.value
> offset
+ section
->vma
)
2501 /* We have passed the location in the file we are
2502 looking for, so we can get out of the loop. */
2506 if (sym
.value
>= low_line_vma
)
2508 low_line_vma
= sym
.value
;
2509 line_file_name
= current_file_name
;
2510 *retline_ptr
= sym
.index
;
2515 if (*retline_ptr
!= 0)
2516 main_file_name
= line_file_name
;
2518 /* We need to remove the stuff after the colon in the function
2519 name. We also need to put the directory name and the file
2521 if (function_name
== NULL
)
2524 len
= funclen
= strlen (function_name
) + 1;
2526 if (main_file_name
!= NULL
2527 && directory_name
!= NULL
2528 && main_file_name
[0] != '/')
2529 len
+= strlen (directory_name
) + strlen (main_file_name
) + 1;
2533 if (ecoff_data (abfd
)->find_buffer
!= NULL
)
2534 free (ecoff_data (abfd
)->find_buffer
);
2535 buffer
= (char *) malloc (len
);
2538 bfd_set_error (bfd_error_no_memory
);
2541 ecoff_data (abfd
)->find_buffer
= buffer
;
2544 if (function_name
!= NULL
)
2548 strcpy (buffer
, function_name
);
2549 colon
= strchr (buffer
, ':');
2552 *functionname_ptr
= buffer
;
2555 if (main_file_name
!= NULL
)
2557 if (directory_name
== NULL
|| main_file_name
[0] == '/')
2558 *filename_ptr
= main_file_name
;
2561 sprintf (buffer
+ funclen
, "%s%s", directory_name
,
2563 *filename_ptr
= buffer
+ funclen
;
2572 /* Copy private BFD data. This is called by objcopy and strip. We
2573 use it to copy the ECOFF debugging information from one BFD to the
2574 other. It would be theoretically possible to represent the ECOFF
2575 debugging information in the symbol table. However, it would be a
2576 lot of work, and there would be little gain (gas, gdb, and ld
2577 already access the ECOFF debugging information via the
2578 ecoff_debug_info structure, and that structure would have to be
2579 retained in order to support ECOFF debugging in MIPS ELF).
2581 The debugging information for the ECOFF external symbols comes from
2582 the symbol table, so this function only handles the other debugging
2586 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
2590 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
2591 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
2593 asymbol
**sym_ptr_ptr
;
2597 /* This function is selected based on the input vector. We only
2598 want to copy information over if the output BFD also uses ECOFF
2600 if (bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
2603 /* Copy the GP value and the register masks. */
2604 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
2605 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
2606 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
2607 for (i
= 0; i
< 3; i
++)
2608 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
2610 /* Copy the version stamp. */
2611 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
2613 /* If there are no symbols, don't copy any debugging information. */
2614 c
= bfd_get_symcount (obfd
);
2615 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2616 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
2619 /* See if there are any local symbols. */
2621 for (; c
> 0; c
--, sym_ptr_ptr
++)
2623 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
2632 /* There are some local symbols. We just bring over all the
2633 debugging information. FIXME: This is not quite the right
2634 thing to do. If the user has asked us to discard all
2635 debugging information, then we are probably going to wind up
2636 keeping it because there will probably be some local symbol
2637 which objcopy did not discard. We should actually break
2638 apart the debugging information and only keep that which
2639 applies to the symbols we want to keep. */
2640 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
2641 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
2642 oinfo
->line
= iinfo
->line
;
2644 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
2645 oinfo
->external_dnr
= iinfo
->external_dnr
;
2647 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
2648 oinfo
->external_pdr
= iinfo
->external_pdr
;
2650 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
2651 oinfo
->external_sym
= iinfo
->external_sym
;
2653 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
2654 oinfo
->external_opt
= iinfo
->external_opt
;
2656 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
2657 oinfo
->external_aux
= iinfo
->external_aux
;
2659 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
2660 oinfo
->ss
= iinfo
->ss
;
2662 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
2663 oinfo
->external_fdr
= iinfo
->external_fdr
;
2665 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
2666 oinfo
->external_rfd
= iinfo
->external_rfd
;
2670 /* We are discarding all the local symbol information. Look
2671 through the external symbols and remove all references to FDR
2672 or aux information. */
2673 c
= bfd_get_symcount (obfd
);
2674 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
2675 for (; c
> 0; c
--, sym_ptr_ptr
++)
2679 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
2680 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
2682 esym
.asym
.index
= indexNil
;
2683 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
2684 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
2691 /* Set the architecture. The supported architecture is stored in the
2692 backend pointer. We always set the architecture anyhow, since many
2693 callers ignore the return value. */
2696 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
2698 enum bfd_architecture arch
;
2699 unsigned long machine
;
2701 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2702 return arch
== ecoff_backend (abfd
)->arch
;
2705 /* Get the size of the section headers. */
2709 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
2718 for (current
= abfd
->sections
;
2719 current
!= (asection
*)NULL
;
2720 current
= current
->next
)
2723 ret
= (bfd_coff_filhsz (abfd
)
2724 + bfd_coff_aoutsz (abfd
)
2725 + c
* bfd_coff_scnhsz (abfd
));
2726 return BFD_ALIGN (ret
, 16);
2729 /* Get the contents of a section. */
2732 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2737 bfd_size_type count
;
2739 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2743 /* Calculate the file position for each section, and set
2747 ecoff_compute_section_file_positions (abfd
)
2755 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2758 for (current
= abfd
->sections
;
2759 current
!= (asection
*) NULL
;
2760 current
= current
->next
)
2762 unsigned int alignment_power
;
2764 /* Only deal with sections which have contents */
2765 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0)
2768 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2769 supposed to indicate the number of .pdata entries that are
2770 really in the section. Each entry is 8 bytes. We store this
2771 away in line_filepos before increasing the section size. */
2772 if (strcmp (current
->name
, _PDATA
) != 0)
2773 alignment_power
= current
->alignment_power
;
2776 current
->line_filepos
= current
->_raw_size
/ 8;
2777 alignment_power
= 4;
2780 /* On Ultrix, the data sections in an executable file must be
2781 aligned to a page boundary within the file. This does not
2782 affect the section size, though. FIXME: Does this work for
2783 other platforms? It requires some modification for the
2784 Alpha, because .rdata on the Alpha goes with the text, not
2786 if ((abfd
->flags
& EXEC_P
) != 0
2787 && (abfd
->flags
& D_PAGED
) != 0
2788 && first_data
!= false
2789 && (current
->flags
& SEC_CODE
) == 0
2790 && (! ecoff_backend (abfd
)->rdata_in_text
2791 || strcmp (current
->name
, _RDATA
) != 0)
2792 && strcmp (current
->name
, _PDATA
) != 0)
2794 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2796 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2799 else if (strcmp (current
->name
, _LIB
) == 0)
2801 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2802 /* On Irix 4, the location of contents of the .lib section
2803 from a shared library section is also rounded up to a
2806 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2809 /* Align the sections in the file to the same boundary on
2810 which they are aligned in virtual memory. */
2812 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2814 current
->filepos
= sofar
;
2816 sofar
+= current
->_raw_size
;
2818 /* make sure that this section is of the right size too */
2820 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2821 current
->_raw_size
+= sofar
- old_sofar
;
2824 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2827 /* Determine the location of the relocs for all the sections in the
2828 output file, as well as the location of the symbolic debugging
2831 static bfd_size_type
2832 ecoff_compute_reloc_file_positions (abfd
)
2835 const bfd_size_type external_reloc_size
=
2836 ecoff_backend (abfd
)->external_reloc_size
;
2837 file_ptr reloc_base
;
2838 bfd_size_type reloc_size
;
2842 if (! abfd
->output_has_begun
)
2844 ecoff_compute_section_file_positions (abfd
);
2845 abfd
->output_has_begun
= true;
2848 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2851 for (current
= abfd
->sections
;
2852 current
!= (asection
*)NULL
;
2853 current
= current
->next
)
2855 if (current
->reloc_count
== 0)
2856 current
->rel_filepos
= 0;
2859 bfd_size_type relsize
;
2861 current
->rel_filepos
= reloc_base
;
2862 relsize
= current
->reloc_count
* external_reloc_size
;
2863 reloc_size
+= relsize
;
2864 reloc_base
+= relsize
;
2868 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2870 /* At least on Ultrix, the symbol table of an executable file must
2871 be aligned to a page boundary. FIXME: Is this true on other
2873 if ((abfd
->flags
& EXEC_P
) != 0
2874 && (abfd
->flags
& D_PAGED
) != 0)
2875 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2876 &~ (ecoff_backend (abfd
)->round
- 1));
2878 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2883 /* Set the contents of a section. */
2886 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2891 bfd_size_type count
;
2893 /* This must be done first, because bfd_set_section_contents is
2894 going to set output_has_begun to true. */
2895 if (abfd
->output_has_begun
== false)
2896 ecoff_compute_section_file_positions (abfd
);
2898 /* If this is a .lib section, bump the vma address so that it winds
2899 up being the number of .lib sections output. This is right for
2900 Irix 4. Ian Taylor <ian@cygnus.com>. */
2901 if (strcmp (section
->name
, _LIB
) == 0)
2907 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2908 || bfd_write (location
, 1, count
, abfd
) != count
)
2914 /* Get the GP value for an ECOFF file. This is a hook used by
2918 bfd_ecoff_get_gp_value (abfd
)
2921 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2922 || bfd_get_format (abfd
) != bfd_object
)
2924 bfd_set_error (bfd_error_invalid_operation
);
2928 return ecoff_data (abfd
)->gp
;
2931 /* Set the GP value for an ECOFF file. This is a hook used by the
2935 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2939 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2940 || bfd_get_format (abfd
) != bfd_object
)
2942 bfd_set_error (bfd_error_invalid_operation
);
2946 ecoff_data (abfd
)->gp
= gp_value
;
2951 /* Set the register masks for an ECOFF file. This is a hook used by
2955 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2957 unsigned long gprmask
;
2958 unsigned long fprmask
;
2959 unsigned long *cprmask
;
2961 ecoff_data_type
*tdata
;
2963 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2964 || bfd_get_format (abfd
) != bfd_object
)
2966 bfd_set_error (bfd_error_invalid_operation
);
2970 tdata
= ecoff_data (abfd
);
2971 tdata
->gprmask
= gprmask
;
2972 tdata
->fprmask
= fprmask
;
2973 if (cprmask
!= (unsigned long *) NULL
)
2977 for (i
= 0; i
< 3; i
++)
2978 tdata
->cprmask
[i
] = cprmask
[i
];
2984 /* Get ECOFF EXTR information for an external symbol. This function
2985 is passed to bfd_ecoff_debug_externals. */
2988 ecoff_get_extr (sym
, esym
)
2992 ecoff_symbol_type
*ecoff_sym_ptr
;
2995 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2996 || ecoffsymbol (sym
)->native
== NULL
)
2998 /* Don't include debugging, local, or section symbols. */
2999 if ((sym
->flags
& BSF_DEBUGGING
) != 0
3000 || (sym
->flags
& BSF_LOCAL
) != 0
3001 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
3005 esym
->cobol_main
= 0;
3009 /* FIXME: we can do better than this for st and sc. */
3010 esym
->asym
.st
= stGlobal
;
3011 esym
->asym
.sc
= scAbs
;
3012 esym
->asym
.reserved
= 0;
3013 esym
->asym
.index
= indexNil
;
3017 ecoff_sym_ptr
= ecoffsymbol (sym
);
3019 if (ecoff_sym_ptr
->local
)
3022 input_bfd
= bfd_asymbol_bfd (sym
);
3023 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
3024 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
3026 /* If the symbol was defined by the linker, then esym will be
3027 undefined but sym will not be. Get a better class for such a
3029 if ((esym
->asym
.sc
== scUndefined
3030 || esym
->asym
.sc
== scSUndefined
)
3031 && ! bfd_is_und_section (bfd_get_section (sym
)))
3032 esym
->asym
.sc
= scAbs
;
3034 /* Adjust the FDR index for the symbol by that used for the input
3036 if (esym
->ifd
!= -1)
3038 struct ecoff_debug_info
*input_debug
;
3040 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
3041 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
3042 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
3043 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
3049 /* Set the external symbol index. This routine is passed to
3050 bfd_ecoff_debug_externals. */
3053 ecoff_set_index (sym
, indx
)
3057 ecoff_set_sym_index (sym
, indx
);
3060 /* Write out an ECOFF file. */
3063 _bfd_ecoff_write_object_contents (abfd
)
3066 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3067 const bfd_vma round
= backend
->round
;
3068 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
3069 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
3070 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
3071 const bfd_size_type external_hdr_size
3072 = backend
->debug_swap
.external_hdr_size
;
3073 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
3074 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
3076 struct internal_reloc
*))
3077 = backend
->adjust_reloc_out
;
3078 void (* const swap_reloc_out
) PARAMS ((bfd
*,
3079 const struct internal_reloc
*,
3081 = backend
->swap_reloc_out
;
3082 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3083 HDRR
* const symhdr
= &debug
->symbolic_header
;
3086 bfd_size_type reloc_size
;
3087 bfd_size_type text_size
;
3089 boolean set_text_start
;
3090 bfd_size_type data_size
;
3092 boolean set_data_start
;
3093 bfd_size_type bss_size
;
3095 PTR reloc_buff
= NULL
;
3096 struct internal_filehdr internal_f
;
3097 struct internal_aouthdr internal_a
;
3100 /* Determine where the sections and relocs will go in the output
3102 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
3105 for (current
= abfd
->sections
;
3106 current
!= (asection
*)NULL
;
3107 current
= current
->next
)
3109 current
->target_index
= count
;
3113 if ((abfd
->flags
& D_PAGED
) != 0)
3114 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
3118 set_text_start
= false;
3121 set_data_start
= false;
3124 /* Write section headers to the file. */
3126 /* Allocate buff big enough to hold a section header,
3127 file header, or a.out header. */
3135 buff
= (PTR
) malloc (siz
);
3138 bfd_set_error (bfd_error_no_memory
);
3143 internal_f
.f_nscns
= 0;
3144 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
3146 for (current
= abfd
->sections
;
3147 current
!= (asection
*) NULL
;
3148 current
= current
->next
)
3150 struct internal_scnhdr section
;
3153 ++internal_f
.f_nscns
;
3155 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3157 /* This seems to be correct for Irix 4 shared libraries. */
3158 vma
= bfd_get_section_vma (abfd
, current
);
3159 if (strcmp (current
->name
, _LIB
) == 0)
3160 section
.s_vaddr
= 0;
3162 section
.s_vaddr
= vma
;
3164 section
.s_paddr
= vma
;
3165 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3167 /* If this section is unloadable then the scnptr will be 0. */
3168 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3169 section
.s_scnptr
= 0;
3171 section
.s_scnptr
= current
->filepos
;
3172 section
.s_relptr
= current
->rel_filepos
;
3174 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3175 object file produced by the assembler is supposed to point to
3176 information about how much room is required by objects of
3177 various different sizes. I think this only matters if we
3178 want the linker to compute the best size to use, or
3179 something. I don't know what happens if the information is
3181 if (strcmp (current
->name
, _PDATA
) != 0)
3182 section
.s_lnnoptr
= 0;
3185 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
3186 hold the number of entries in the section (each entry is
3187 8 bytes). We stored this in the line_filepos field in
3188 ecoff_compute_section_file_positions. */
3189 section
.s_lnnoptr
= current
->line_filepos
;
3192 section
.s_nreloc
= current
->reloc_count
;
3193 section
.s_nlnno
= 0;
3194 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3197 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
3198 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
3201 if ((section
.s_flags
& STYP_TEXT
) != 0
3202 || ((section
.s_flags
& STYP_RDATA
) != 0
3203 && backend
->rdata_in_text
)
3204 || strcmp (current
->name
, _PDATA
) == 0)
3206 text_size
+= bfd_get_section_size_before_reloc (current
);
3207 if (! set_text_start
|| text_start
> vma
)
3210 set_text_start
= true;
3213 else if ((section
.s_flags
& STYP_RDATA
) != 0
3214 || (section
.s_flags
& STYP_DATA
) != 0
3215 || (section
.s_flags
& STYP_LITA
) != 0
3216 || (section
.s_flags
& STYP_LIT8
) != 0
3217 || (section
.s_flags
& STYP_LIT4
) != 0
3218 || (section
.s_flags
& STYP_SDATA
) != 0
3219 || strcmp (current
->name
, _XDATA
) == 0)
3221 data_size
+= bfd_get_section_size_before_reloc (current
);
3222 if (! set_data_start
|| data_start
> vma
)
3225 set_data_start
= true;
3228 else if ((section
.s_flags
& STYP_BSS
) != 0
3229 || (section
.s_flags
& STYP_SBSS
) != 0)
3230 bss_size
+= bfd_get_section_size_before_reloc (current
);
3231 else if ((section
.s_flags
& STYP_ECOFF_LIB
) != 0)
3237 /* Set up the file header. */
3239 internal_f
.f_magic
= ecoff_get_magic (abfd
);
3241 /* We will NOT put a fucking timestamp in the header here. Every
3242 time you put it back, I will come in and take it out again. I'm
3243 sorry. This field does not belong here. We fill it with a 0 so
3244 it compares the same but is not a reasonable time. --
3246 internal_f
.f_timdat
= 0;
3248 if (bfd_get_symcount (abfd
) != 0)
3250 /* The ECOFF f_nsyms field is not actually the number of
3251 symbols, it's the size of symbolic information header. */
3252 internal_f
.f_nsyms
= external_hdr_size
;
3253 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
3257 internal_f
.f_nsyms
= 0;
3258 internal_f
.f_symptr
= 0;
3261 internal_f
.f_opthdr
= aoutsz
;
3263 internal_f
.f_flags
= F_LNNO
;
3264 if (reloc_size
== 0)
3265 internal_f
.f_flags
|= F_RELFLG
;
3266 if (bfd_get_symcount (abfd
) == 0)
3267 internal_f
.f_flags
|= F_LSYMS
;
3268 if (abfd
->flags
& EXEC_P
)
3269 internal_f
.f_flags
|= F_EXEC
;
3271 if (! abfd
->xvec
->byteorder_big_p
)
3272 internal_f
.f_flags
|= F_AR32WR
;
3274 internal_f
.f_flags
|= F_AR32W
;
3276 /* Set up the ``optional'' header. */
3277 if ((abfd
->flags
& D_PAGED
) != 0)
3278 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
3280 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
3282 /* FIXME: Is this really correct? */
3283 internal_a
.vstamp
= symhdr
->vstamp
;
3285 /* At least on Ultrix, these have to be rounded to page boundaries.
3286 FIXME: Is this true on other platforms? */
3287 if ((abfd
->flags
& D_PAGED
) != 0)
3289 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
3290 internal_a
.text_start
= text_start
&~ (round
- 1);
3291 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
3292 internal_a
.data_start
= data_start
&~ (round
- 1);
3296 internal_a
.tsize
= text_size
;
3297 internal_a
.text_start
= text_start
;
3298 internal_a
.dsize
= data_size
;
3299 internal_a
.data_start
= data_start
;
3302 /* On Ultrix, the initial portions of the .sbss and .bss segments
3303 are at the end of the data section. The bsize field in the
3304 optional header records how many bss bytes are required beyond
3305 those in the data section. The value is not rounded to a page
3307 if (bss_size
< internal_a
.dsize
- data_size
)
3310 bss_size
-= internal_a
.dsize
- data_size
;
3311 internal_a
.bsize
= bss_size
;
3312 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3314 internal_a
.entry
= bfd_get_start_address (abfd
);
3316 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3318 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3319 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
3320 for (i
= 0; i
< 4; i
++)
3321 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3323 /* Write out the file header and the optional header. */
3325 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3328 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
3329 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
3332 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
3333 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
3336 /* Build the external symbol information. This must be done before
3337 writing out the relocs so that we know the symbol indices. We
3338 don't do this if this BFD was created by the backend linker,
3339 since it will have already handled the symbols and relocs. */
3340 if (! ecoff_data (abfd
)->linker
)
3342 symhdr
->iextMax
= 0;
3343 symhdr
->issExtMax
= 0;
3344 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3345 debug
->ssext
= debug
->ssext_end
= NULL
;
3346 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
3347 (((abfd
->flags
& EXEC_P
) == 0)
3349 ecoff_get_extr
, ecoff_set_index
)
3353 /* Write out the relocs. */
3354 for (current
= abfd
->sections
;
3355 current
!= (asection
*) NULL
;
3356 current
= current
->next
)
3358 arelent
**reloc_ptr_ptr
;
3359 arelent
**reloc_end
;
3362 if (current
->reloc_count
== 0)
3366 bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
3367 if (reloc_buff
== NULL
)
3369 bfd_set_error (bfd_error_no_memory
);
3373 reloc_ptr_ptr
= current
->orelocation
;
3374 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3375 out_ptr
= (char *) reloc_buff
;
3377 reloc_ptr_ptr
< reloc_end
;
3378 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
3382 struct internal_reloc in
;
3384 memset ((PTR
) &in
, 0, sizeof in
);
3386 reloc
= *reloc_ptr_ptr
;
3387 sym
= *reloc
->sym_ptr_ptr
;
3389 in
.r_vaddr
= (reloc
->address
3390 + bfd_get_section_vma (abfd
, current
));
3391 in
.r_type
= reloc
->howto
->type
;
3393 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3395 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3402 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3403 if (strcmp (name
, ".text") == 0)
3404 in
.r_symndx
= RELOC_SECTION_TEXT
;
3405 else if (strcmp (name
, ".rdata") == 0)
3406 in
.r_symndx
= RELOC_SECTION_RDATA
;
3407 else if (strcmp (name
, ".data") == 0)
3408 in
.r_symndx
= RELOC_SECTION_DATA
;
3409 else if (strcmp (name
, ".sdata") == 0)
3410 in
.r_symndx
= RELOC_SECTION_SDATA
;
3411 else if (strcmp (name
, ".sbss") == 0)
3412 in
.r_symndx
= RELOC_SECTION_SBSS
;
3413 else if (strcmp (name
, ".bss") == 0)
3414 in
.r_symndx
= RELOC_SECTION_BSS
;
3415 else if (strcmp (name
, ".init") == 0)
3416 in
.r_symndx
= RELOC_SECTION_INIT
;
3417 else if (strcmp (name
, ".lit8") == 0)
3418 in
.r_symndx
= RELOC_SECTION_LIT8
;
3419 else if (strcmp (name
, ".lit4") == 0)
3420 in
.r_symndx
= RELOC_SECTION_LIT4
;
3421 else if (strcmp (name
, ".xdata") == 0)
3422 in
.r_symndx
= RELOC_SECTION_XDATA
;
3423 else if (strcmp (name
, ".pdata") == 0)
3424 in
.r_symndx
= RELOC_SECTION_PDATA
;
3425 else if (strcmp (name
, ".fini") == 0)
3426 in
.r_symndx
= RELOC_SECTION_FINI
;
3427 else if (strcmp (name
, ".lita") == 0)
3428 in
.r_symndx
= RELOC_SECTION_LITA
;
3429 else if (strcmp (name
, "*ABS*") == 0)
3430 in
.r_symndx
= RELOC_SECTION_ABS
;
3436 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
3438 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3441 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3443 if (bfd_write (reloc_buff
,
3444 external_reloc_size
, current
->reloc_count
, abfd
)
3445 != external_reloc_size
* current
->reloc_count
)
3447 bfd_release (abfd
, reloc_buff
);
3451 /* Write out the symbolic debugging information. */
3452 if (bfd_get_symcount (abfd
) > 0)
3454 /* Write out the debugging information. */
3455 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
3456 ecoff_data (abfd
)->sym_filepos
)
3462 /* The .bss section of a demand paged executable must receive an
3463 entire page. If there are symbols, the symbols will start on the
3464 next page. If there are no symbols, we must fill out the page by
3466 if (bfd_get_symcount (abfd
) == 0
3467 && (abfd
->flags
& EXEC_P
) != 0
3468 && (abfd
->flags
& D_PAGED
) != 0)
3472 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3475 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3477 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3480 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3484 if (reloc_buff
!= NULL
)
3485 bfd_release (abfd
, reloc_buff
);
3490 if (reloc_buff
!= NULL
)
3491 bfd_release (abfd
, reloc_buff
);
3497 /* Archive handling. ECOFF uses what appears to be a unique type of
3498 archive header (armap). The byte ordering of the armap and the
3499 contents are encoded in the name of the armap itself. At least for
3500 now, we only support archives with the same byte ordering in the
3501 armap and the contents.
3503 The first four bytes in the armap are the number of symbol
3504 definitions. This is always a power of two.
3506 This is followed by the symbol definitions. Each symbol definition
3507 occupies 8 bytes. The first four bytes are the offset from the
3508 start of the armap strings to the null-terminated string naming
3509 this symbol. The second four bytes are the file offset to the
3510 archive member which defines this symbol. If the second four bytes
3511 are 0, then this is not actually a symbol definition, and it should
3514 The symbols are hashed into the armap with a closed hashing scheme.
3515 See the functions below for the details of the algorithm.
3517 After the symbol definitions comes four bytes holding the size of
3518 the string table, followed by the string table itself. */
3520 /* The name of an archive headers looks like this:
3521 __________E[BL]E[BL]_ (with a trailing space).
3522 The trailing space is changed to an X if the archive is changed to
3523 indicate that the armap is out of date.
3525 The Alpha seems to use ________64E[BL]E[BL]_. */
3527 #define ARMAP_BIG_ENDIAN 'B'
3528 #define ARMAP_LITTLE_ENDIAN 'L'
3529 #define ARMAP_MARKER 'E'
3530 #define ARMAP_START_LENGTH 10
3531 #define ARMAP_HEADER_MARKER_INDEX 10
3532 #define ARMAP_HEADER_ENDIAN_INDEX 11
3533 #define ARMAP_OBJECT_MARKER_INDEX 12
3534 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3535 #define ARMAP_END_INDEX 14
3536 #define ARMAP_END "_ "
3538 /* This is a magic number used in the hashing algorithm. */
3539 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3541 /* This returns the hash value to use for a string. It also sets
3542 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3543 is the number of entries in the hash table, and HLOG is the log
3547 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3549 unsigned int *rehash
;
3557 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3558 hash
*= ARMAP_HASH_MAGIC
;
3559 *rehash
= (hash
& (size
- 1)) | 1;
3560 return hash
>> (32 - hlog
);
3563 /* Read in the armap. */
3566 _bfd_ecoff_slurp_armap (abfd
)
3571 struct areltdata
*mapdata
;
3572 bfd_size_type parsed_size
;
3574 struct artdata
*ardata
;
3577 struct symdef
*symdef_ptr
;
3580 /* Get the name of the first element. */
3581 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3587 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
3590 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3591 standard COFF armap. We could move the ECOFF armap stuff into
3592 bfd_slurp_armap, but that seems inappropriate since no other
3593 target uses this format. Instead, we check directly for a COFF
3595 if (strncmp (nextname
, "/ ", 16) == 0)
3596 return bfd_slurp_armap (abfd
);
3598 /* See if the first element is an armap. */
3599 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3600 ARMAP_START_LENGTH
) != 0
3601 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3602 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3603 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3604 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3605 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3606 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3607 || strncmp (nextname
+ ARMAP_END_INDEX
,
3608 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3610 bfd_has_map (abfd
) = false;
3614 /* Make sure we have the right byte ordering. */
3615 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3616 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3617 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3618 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3620 bfd_set_error (bfd_error_wrong_format
);
3624 /* Read in the armap. */
3625 ardata
= bfd_ardata (abfd
);
3626 mapdata
= _bfd_snarf_ar_hdr (abfd
);
3627 if (mapdata
== (struct areltdata
*) NULL
)
3629 parsed_size
= mapdata
->parsed_size
;
3630 bfd_release (abfd
, (PTR
) mapdata
);
3632 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3633 if (raw_armap
== (char *) NULL
)
3635 bfd_set_error (bfd_error_no_memory
);
3639 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3641 if (bfd_get_error () != bfd_error_system_call
)
3642 bfd_set_error (bfd_error_malformed_archive
);
3643 bfd_release (abfd
, (PTR
) raw_armap
);
3647 ardata
->tdata
= (PTR
) raw_armap
;
3649 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3651 ardata
->symdef_count
= 0;
3652 ardata
->cache
= (struct ar_cache
*) NULL
;
3654 /* This code used to overlay the symdefs over the raw archive data,
3655 but that doesn't work on a 64 bit host. */
3657 stringbase
= raw_armap
+ count
* 8 + 8;
3659 #ifdef CHECK_ARMAP_HASH
3663 /* Double check that I have the hashing algorithm right by making
3664 sure that every symbol can be looked up successfully. */
3666 for (i
= 1; i
< count
; i
<<= 1)
3668 BFD_ASSERT (i
== count
);
3670 raw_ptr
= raw_armap
+ 4;
3671 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3673 unsigned int name_offset
, file_offset
;
3674 unsigned int hash
, rehash
, srch
;
3676 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3677 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3678 if (file_offset
== 0)
3680 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3685 /* See if we can rehash to this location. */
3686 for (srch
= (hash
+ rehash
) & (count
- 1);
3687 srch
!= hash
&& srch
!= i
;
3688 srch
= (srch
+ rehash
) & (count
- 1))
3689 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3691 BFD_ASSERT (srch
== i
);
3695 #endif /* CHECK_ARMAP_HASH */
3697 raw_ptr
= raw_armap
+ 4;
3698 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3699 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3700 ++ardata
->symdef_count
;
3702 symdef_ptr
= ((struct symdef
*)
3704 ardata
->symdef_count
* sizeof (struct symdef
)));
3707 bfd_set_error (bfd_error_no_memory
);
3711 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3713 raw_ptr
= raw_armap
+ 4;
3714 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3716 unsigned int name_offset
, file_offset
;
3718 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3719 if (file_offset
== 0)
3721 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3722 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3723 symdef_ptr
->file_offset
= file_offset
;
3727 ardata
->first_file_filepos
= bfd_tell (abfd
);
3728 /* Pad to an even boundary. */
3729 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3731 bfd_has_map (abfd
) = true;
3736 /* Write out an armap. */
3739 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3741 unsigned int elength
;
3743 unsigned int orl_count
;
3746 unsigned int hashsize
, hashlog
;
3747 unsigned int symdefsize
;
3749 unsigned int stringsize
;
3750 unsigned int mapsize
;
3753 struct stat statbuf
;
3756 bfd_byte
*hashtable
;
3760 /* Ultrix appears to use as a hash table size the least power of two
3761 greater than twice the number of entries. */
3762 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3764 hashsize
= 1 << hashlog
;
3766 symdefsize
= hashsize
* 8;
3768 stringsize
= stridx
+ padit
;
3770 /* Include 8 bytes to store symdefsize and stringsize in output. */
3771 mapsize
= symdefsize
+ stringsize
+ 8;
3773 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3775 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3777 /* Work out the ECOFF armap name. */
3778 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3779 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3780 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3781 (abfd
->xvec
->header_byteorder_big_p
3783 : ARMAP_LITTLE_ENDIAN
);
3784 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3785 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3786 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3787 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3789 /* Write the timestamp of the archive header to be just a little bit
3790 later than the timestamp of the file, otherwise the linker will
3791 complain that the index is out of date. Actually, the Ultrix
3792 linker just checks the archive name; the GNU linker may check the
3794 stat (abfd
->filename
, &statbuf
);
3795 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3797 /* The DECstation uses zeroes for the uid, gid and mode of the
3799 hdr
.ar_uid
[0] = '0';
3800 hdr
.ar_gid
[0] = '0';
3801 hdr
.ar_mode
[0] = '0';
3803 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3805 hdr
.ar_fmag
[0] = '`';
3806 hdr
.ar_fmag
[1] = '\012';
3808 /* Turn all null bytes in the header into spaces. */
3809 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3810 if (((char *)(&hdr
))[i
] == '\0')
3811 (((char *)(&hdr
))[i
]) = ' ';
3813 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3814 != sizeof (struct ar_hdr
))
3817 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3818 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3821 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3824 bfd_set_error (bfd_error_no_memory
);
3828 current
= abfd
->archive_head
;
3830 for (i
= 0; i
< orl_count
; i
++)
3832 unsigned int hash
, rehash
;
3834 /* Advance firstreal to the file position of this archive
3836 if (((bfd
*) map
[i
].pos
) != last_elt
)
3840 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3841 firstreal
+= firstreal
% 2;
3842 current
= current
->next
;
3844 while (current
!= (bfd
*) map
[i
].pos
);
3849 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3850 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3854 /* The desired slot is already taken. */
3855 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3857 srch
= (srch
+ rehash
) & (hashsize
- 1))
3858 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3861 BFD_ASSERT (srch
!= hash
);
3866 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3867 (PTR
) (hashtable
+ hash
* 8));
3868 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3869 (PTR
) (hashtable
+ hash
* 8 + 4));
3872 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3875 bfd_release (abfd
, hashtable
);
3877 /* Now write the strings. */
3878 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3879 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3881 for (i
= 0; i
< orl_count
; i
++)
3885 len
= strlen (*map
[i
].name
) + 1;
3886 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3890 /* The spec sez this should be a newline. But in order to be
3891 bug-compatible for DECstation ar we use a null. */
3894 if (bfd_write ("", 1, 1, abfd
) != 1)
3901 /* See whether this BFD is an archive. If it is, read in the armap
3902 and the extended name table. */
3905 _bfd_ecoff_archive_p (abfd
)
3908 char armag
[SARMAG
+ 1];
3910 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3911 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3913 if (bfd_get_error () != bfd_error_system_call
)
3914 bfd_set_error (bfd_error_wrong_format
);
3915 return (const bfd_target
*) NULL
;
3918 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3919 involves a cast, we can't do it as the left operand of
3921 abfd
->tdata
.aout_ar_data
=
3922 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3924 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3926 bfd_set_error (bfd_error_no_memory
);
3927 return (const bfd_target
*) NULL
;
3930 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3931 bfd_ardata (abfd
)->cache
= NULL
;
3932 bfd_ardata (abfd
)->archive_head
= NULL
;
3933 bfd_ardata (abfd
)->symdefs
= NULL
;
3934 bfd_ardata (abfd
)->extended_names
= NULL
;
3935 bfd_ardata (abfd
)->tdata
= NULL
;
3937 if (_bfd_ecoff_slurp_armap (abfd
) == false
3938 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3940 bfd_release (abfd
, bfd_ardata (abfd
));
3941 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3942 return (const bfd_target
*) NULL
;
3948 /* ECOFF linker code. */
3950 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3951 PARAMS ((struct bfd_hash_entry
*entry
,
3952 struct bfd_hash_table
*table
,
3953 const char *string
));
3954 static boolean ecoff_link_add_archive_symbols
3955 PARAMS ((bfd
*, struct bfd_link_info
*));
3956 static boolean ecoff_link_check_archive_element
3957 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3958 static boolean ecoff_link_add_object_symbols
3959 PARAMS ((bfd
*, struct bfd_link_info
*));
3960 static boolean ecoff_link_add_externals
3961 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3963 /* Routine to create an entry in an ECOFF link hash table. */
3965 static struct bfd_hash_entry
*
3966 ecoff_link_hash_newfunc (entry
, table
, string
)
3967 struct bfd_hash_entry
*entry
;
3968 struct bfd_hash_table
*table
;
3971 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3973 /* Allocate the structure if it has not already been allocated by a
3975 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3976 ret
= ((struct ecoff_link_hash_entry
*)
3977 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3978 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3980 bfd_set_error (bfd_error_no_memory
);
3984 /* Call the allocation method of the superclass. */
3985 ret
= ((struct ecoff_link_hash_entry
*)
3986 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3991 /* Set local fields. */
3997 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3999 return (struct bfd_hash_entry
*) ret
;
4002 /* Create an ECOFF link hash table. */
4004 struct bfd_link_hash_table
*
4005 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
4008 struct ecoff_link_hash_table
*ret
;
4010 ret
= ((struct ecoff_link_hash_table
*)
4011 malloc (sizeof (struct ecoff_link_hash_table
)));
4014 bfd_set_error (bfd_error_no_memory
);
4017 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
4018 ecoff_link_hash_newfunc
))
4021 return (struct bfd_link_hash_table
*) NULL
;
4026 /* Look up an entry in an ECOFF link hash table. */
4028 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
4029 ((struct ecoff_link_hash_entry *) \
4030 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
4032 /* Traverse an ECOFF link hash table. */
4034 #define ecoff_link_hash_traverse(table, func, info) \
4035 (bfd_link_hash_traverse \
4037 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
4040 /* Get the ECOFF link hash table from the info structure. This is
4043 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
4045 /* Given an ECOFF BFD, add symbols to the global hash table as
4049 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
4051 struct bfd_link_info
*info
;
4053 switch (bfd_get_format (abfd
))
4056 return ecoff_link_add_object_symbols (abfd
, info
);
4058 return ecoff_link_add_archive_symbols (abfd
, info
);
4060 bfd_set_error (bfd_error_wrong_format
);
4065 /* Add the symbols from an archive file to the global hash table.
4066 This looks through the undefined symbols, looks each one up in the
4067 archive hash table, and adds any associated object file. We do not
4068 use _bfd_generic_link_add_archive_symbols because ECOFF archives
4069 already have a hash table, so there is no reason to construct
4073 ecoff_link_add_archive_symbols (abfd
, info
)
4075 struct bfd_link_info
*info
;
4077 const bfd_byte
*raw_armap
;
4078 struct bfd_link_hash_entry
**pundef
;
4079 unsigned int armap_count
;
4080 unsigned int armap_log
;
4082 const bfd_byte
*hashtable
;
4083 const char *stringbase
;
4085 if (! bfd_has_map (abfd
))
4087 /* An empty archive is a special case. */
4088 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
4090 bfd_set_error (bfd_error_no_symbols
);
4094 /* If we don't have any raw data for this archive, as can happen on
4095 Irix 4.0.5F, we call the generic routine.
4096 FIXME: We should be more clever about this, since someday tdata
4097 may get to something for a generic archive. */
4098 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
4099 if (raw_armap
== (bfd_byte
*) NULL
)
4100 return (_bfd_generic_link_add_archive_symbols
4101 (abfd
, info
, ecoff_link_check_archive_element
));
4103 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
4106 for (i
= 1; i
< armap_count
; i
<<= 1)
4108 BFD_ASSERT (i
== armap_count
);
4110 hashtable
= raw_armap
+ 4;
4111 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
4113 /* Look through the list of undefined symbols. */
4114 pundef
= &info
->hash
->undefs
;
4115 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
4117 struct bfd_link_hash_entry
*h
;
4118 unsigned int hash
, rehash
;
4119 unsigned int file_offset
;
4125 /* When a symbol is defined, it is not necessarily removed from
4127 if (h
->type
!= bfd_link_hash_undefined
4128 && h
->type
!= bfd_link_hash_common
)
4130 /* Remove this entry from the list, for general cleanliness
4131 and because we are going to look through the list again
4132 if we search any more libraries. We can't remove the
4133 entry if it is the tail, because that would lose any
4134 entries we add to the list later on. */
4135 if (*pundef
!= info
->hash
->undefs_tail
)
4136 *pundef
= (*pundef
)->next
;
4138 pundef
= &(*pundef
)->next
;
4142 /* Native ECOFF linkers do not pull in archive elements merely
4143 to satisfy common definitions, so neither do we. We leave
4144 them on the list, though, in case we are linking against some
4145 other object format. */
4146 if (h
->type
!= bfd_link_hash_undefined
)
4148 pundef
= &(*pundef
)->next
;
4152 /* Look for this symbol in the archive hash table. */
4153 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
4156 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
4157 if (file_offset
== 0)
4159 /* Nothing in this slot. */
4160 pundef
= &(*pundef
)->next
;
4164 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
4165 if (name
[0] != h
->root
.string
[0]
4166 || strcmp (name
, h
->root
.string
) != 0)
4171 /* That was the wrong symbol. Try rehashing. */
4173 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
4175 srch
= (srch
+ rehash
) & (armap_count
- 1))
4177 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
4178 if (file_offset
== 0)
4180 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
4181 if (name
[0] == h
->root
.string
[0]
4182 && strcmp (name
, h
->root
.string
) == 0)
4191 pundef
= &(*pundef
)->next
;
4198 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
4199 if (element
== (bfd
*) NULL
)
4202 if (! bfd_check_format (element
, bfd_object
))
4205 /* Unlike the generic linker, we know that this element provides
4206 a definition for an undefined symbol and we know that we want
4207 to include it. We don't need to check anything. */
4208 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
4210 if (! ecoff_link_add_object_symbols (element
, info
))
4213 pundef
= &(*pundef
)->next
;
4219 /* This is called if we used _bfd_generic_link_add_archive_symbols
4220 because we were not dealing with an ECOFF archive. */
4223 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
4225 struct bfd_link_info
*info
;
4228 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4229 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
4230 = backend
->debug_swap
.swap_ext_in
;
4232 bfd_size_type external_ext_size
;
4233 PTR external_ext
= NULL
;
4241 if (! ecoff_slurp_symbolic_header (abfd
))
4244 /* If there are no symbols, we don't want it. */
4245 if (bfd_get_symcount (abfd
) == 0)
4246 goto successful_return
;
4248 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
4250 /* Read in the external symbols and external strings. */
4251 external_ext_size
= backend
->debug_swap
.external_ext_size
;
4252 esize
= symhdr
->iextMax
* external_ext_size
;
4253 external_ext
= (PTR
) malloc (esize
);
4254 if (external_ext
== NULL
&& esize
!= 0)
4256 bfd_set_error (bfd_error_no_memory
);
4260 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
4261 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
4264 ssext
= (char *) malloc (symhdr
->issExtMax
);
4265 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
4267 bfd_set_error (bfd_error_no_memory
);
4271 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
4272 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
4275 /* Look through the external symbols to see if they define some
4276 symbol that is currently undefined. */
4277 ext_ptr
= (char *) external_ext
;
4278 ext_end
= ext_ptr
+ esize
;
4279 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
4284 struct bfd_link_hash_entry
*h
;
4286 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
4288 /* See if this symbol defines something. */
4289 if (esym
.asym
.st
!= stGlobal
4290 && esym
.asym
.st
!= stLabel
4291 && esym
.asym
.st
!= stProc
)
4294 switch (esym
.asym
.sc
)
4317 name
= ssext
+ esym
.asym
.iss
;
4318 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
4320 /* Unlike the generic linker, we do not pull in elements because
4321 of common symbols. */
4322 if (h
== (struct bfd_link_hash_entry
*) NULL
4323 || h
->type
!= bfd_link_hash_undefined
)
4326 /* Include this element. */
4327 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
4329 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
4333 goto successful_return
;
4337 if (external_ext
!= NULL
)
4338 free (external_ext
);
4343 if (external_ext
!= NULL
)
4344 free (external_ext
);
4350 /* Add symbols from an ECOFF object file to the global linker hash
4354 ecoff_link_add_object_symbols (abfd
, info
)
4356 struct bfd_link_info
*info
;
4359 bfd_size_type external_ext_size
;
4360 PTR external_ext
= NULL
;
4365 if (! ecoff_slurp_symbolic_header (abfd
))
4368 /* If there are no symbols, we don't want it. */
4369 if (bfd_get_symcount (abfd
) == 0)
4372 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
4374 /* Read in the external symbols and external strings. */
4375 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
4376 esize
= symhdr
->iextMax
* external_ext_size
;
4377 external_ext
= (PTR
) malloc (esize
);
4378 if (external_ext
== NULL
&& esize
!= 0)
4380 bfd_set_error (bfd_error_no_memory
);
4384 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
4385 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
4388 ssext
= (char *) malloc (symhdr
->issExtMax
);
4389 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
4391 bfd_set_error (bfd_error_no_memory
);
4395 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
4396 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
4399 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
4403 if (external_ext
!= NULL
)
4404 free (external_ext
);
4410 if (external_ext
!= NULL
)
4411 free (external_ext
);
4415 /* Add the external symbols of an object file to the global linker
4416 hash table. The external symbols and strings we are passed are
4417 just allocated on the stack, and will be discarded. We must
4418 explicitly save any information we may need later on in the link.
4419 We do not want to read the external symbol information again. */
4422 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
4424 struct bfd_link_info
*info
;
4428 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4429 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
4430 = backend
->debug_swap
.swap_ext_in
;
4431 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
4432 unsigned long ext_count
;
4433 struct ecoff_link_hash_entry
**sym_hash
;
4437 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
4439 sym_hash
= ((struct ecoff_link_hash_entry
**)
4441 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
4444 bfd_set_error (bfd_error_no_memory
);
4447 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
4449 ext_ptr
= (char *) external_ext
;
4450 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
4451 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
4458 struct ecoff_link_hash_entry
*h
;
4462 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
4464 /* Skip debugging symbols. */
4466 switch (esym
.asym
.st
)
4482 /* Get the information for this symbol. */
4483 value
= esym
.asym
.value
;
4484 switch (esym
.asym
.sc
)
4504 section
= bfd_make_section_old_way (abfd
, ".text");
4505 value
-= section
->vma
;
4508 section
= bfd_make_section_old_way (abfd
, ".data");
4509 value
-= section
->vma
;
4512 section
= bfd_make_section_old_way (abfd
, ".bss");
4513 value
-= section
->vma
;
4516 section
= bfd_abs_section_ptr
;
4519 section
= bfd_und_section_ptr
;
4522 section
= bfd_make_section_old_way (abfd
, ".sdata");
4523 value
-= section
->vma
;
4526 section
= bfd_make_section_old_way (abfd
, ".sbss");
4527 value
-= section
->vma
;
4530 section
= bfd_make_section_old_way (abfd
, ".rdata");
4531 value
-= section
->vma
;
4534 if (value
> ecoff_data (abfd
)->gp_size
)
4536 section
= bfd_com_section_ptr
;
4541 if (ecoff_scom_section
.name
== NULL
)
4543 /* Initialize the small common section. */
4544 ecoff_scom_section
.name
= SCOMMON
;
4545 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
4546 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
4547 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
4548 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
4549 ecoff_scom_symbol
.name
= SCOMMON
;
4550 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
4551 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
4552 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
4554 section
= &ecoff_scom_section
;
4557 section
= bfd_und_section_ptr
;
4560 section
= bfd_make_section_old_way (abfd
, ".init");
4561 value
-= section
->vma
;
4564 section
= bfd_make_section_old_way (abfd
, ".fini");
4565 value
-= section
->vma
;
4569 if (section
== (asection
*) NULL
)
4572 name
= ssext
+ esym
.asym
.iss
;
4575 if (! (_bfd_generic_link_add_one_symbol
4576 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
4577 (const char *) NULL
, true, true,
4578 (struct bfd_link_hash_entry
**) &h
)))
4583 /* If we are building an ECOFF hash table, save the external
4584 symbol information. */
4585 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4587 if (h
->abfd
== (bfd
*) NULL
4588 || (! bfd_is_und_section (section
)
4589 && (! bfd_is_com_section (section
)
4590 || (h
->root
.type
!= bfd_link_hash_defined
4591 && h
->root
.type
!= bfd_link_hash_defweak
))))
4597 /* Remember whether this symbol was small undefined. */
4598 if (esym
.asym
.sc
== scSUndefined
)
4601 /* If this symbol was ever small undefined, it needs to wind
4602 up in a GP relative section. We can't control the
4603 section of a defined symbol, but we can control the
4604 section of a common symbol. This case is actually needed
4605 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4607 && h
->root
.type
== bfd_link_hash_common
4608 && strcmp (h
->root
.u
.c
.section
->name
, SCOMMON
) != 0)
4610 h
->root
.u
.c
.section
= bfd_make_section_old_way (abfd
, SCOMMON
);
4611 h
->root
.u
.c
.section
->flags
= SEC_ALLOC
;
4612 if (h
->esym
.asym
.sc
== scCommon
)
4613 h
->esym
.asym
.sc
= scSCommon
;
4621 /* ECOFF final link routines. */
4623 static boolean ecoff_final_link_debug_accumulate
4624 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4626 static boolean ecoff_link_write_external
4627 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4628 static boolean ecoff_indirect_link_order
4629 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4630 struct bfd_link_order
*));
4631 static boolean ecoff_reloc_link_order
4632 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4633 struct bfd_link_order
*));
4635 /* ECOFF final link routine. This looks through all the input BFDs
4636 and gathers together all the debugging information, and then
4637 processes all the link order information. This may cause it to
4638 close and reopen some input BFDs; I'll see how bad this is. */
4641 _bfd_ecoff_bfd_final_link (abfd
, info
)
4643 struct bfd_link_info
*info
;
4645 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4646 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4649 register bfd
*input_bfd
;
4651 struct bfd_link_order
*p
;
4653 /* We accumulate the debugging information counts in the symbolic
4655 symhdr
= &debug
->symbolic_header
;
4657 symhdr
->ilineMax
= 0;
4661 symhdr
->isymMax
= 0;
4662 symhdr
->ioptMax
= 0;
4663 symhdr
->iauxMax
= 0;
4665 symhdr
->issExtMax
= 0;
4668 symhdr
->iextMax
= 0;
4670 /* We accumulate the debugging information itself in the debug_info
4673 debug
->external_dnr
= NULL
;
4674 debug
->external_pdr
= NULL
;
4675 debug
->external_sym
= NULL
;
4676 debug
->external_opt
= NULL
;
4677 debug
->external_aux
= NULL
;
4679 debug
->ssext
= debug
->ssext_end
= NULL
;
4680 debug
->external_fdr
= NULL
;
4681 debug
->external_rfd
= NULL
;
4682 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4684 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4685 if (handle
== (PTR
) NULL
)
4688 /* Accumulate the debugging symbols from each input BFD. */
4689 for (input_bfd
= info
->input_bfds
;
4690 input_bfd
!= (bfd
*) NULL
;
4691 input_bfd
= input_bfd
->link_next
)
4695 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4697 /* Abitrarily set the symbolic header vstamp to the vstamp
4698 of the first object file in the link. */
4699 if (symhdr
->vstamp
== 0)
4701 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4702 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4706 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4707 debug
, &backend
->debug_swap
,
4712 /* Combine the register masks. */
4713 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4714 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4715 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4716 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4717 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4718 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4721 /* Write out the external symbols. */
4722 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4723 ecoff_link_write_external
,
4726 if (info
->relocateable
)
4728 /* We need to make a pass over the link_orders to count up the
4729 number of relocations we will need to output, so that we know
4730 how much space they will take up. */
4731 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4734 for (p
= o
->link_order_head
;
4735 p
!= (struct bfd_link_order
*) NULL
;
4737 if (p
->type
== bfd_indirect_link_order
)
4738 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4739 else if (p
->type
== bfd_section_reloc_link_order
4740 || p
->type
== bfd_symbol_reloc_link_order
)
4745 /* Compute the reloc and symbol file positions. */
4746 ecoff_compute_reloc_file_positions (abfd
);
4748 /* Write out the debugging information. */
4749 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4750 &backend
->debug_swap
, info
,
4751 ecoff_data (abfd
)->sym_filepos
))
4754 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4756 if (info
->relocateable
)
4758 /* Now reset the reloc_count field of the sections in the output
4759 BFD to 0, so that we can use them to keep track of how many
4760 relocs we have output thus far. */
4761 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4765 /* Get a value for the GP register. */
4766 if (ecoff_data (abfd
)->gp
== 0)
4768 struct bfd_link_hash_entry
*h
;
4770 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4771 if (h
!= (struct bfd_link_hash_entry
*) NULL
4772 && h
->type
== bfd_link_hash_defined
)
4773 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4774 + h
->u
.def
.section
->output_section
->vma
4775 + h
->u
.def
.section
->output_offset
);
4776 else if (info
->relocateable
)
4780 /* Make up a value. */
4782 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4785 && (strcmp (o
->name
, _SBSS
) == 0
4786 || strcmp (o
->name
, _SDATA
) == 0
4787 || strcmp (o
->name
, _LIT4
) == 0
4788 || strcmp (o
->name
, _LIT8
) == 0
4789 || strcmp (o
->name
, _LITA
) == 0))
4792 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4796 /* If the relocate_section function needs to do a reloc
4797 involving the GP value, it should make a reloc_dangerous
4798 callback to warn that GP is not defined. */
4802 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4804 for (p
= o
->link_order_head
;
4805 p
!= (struct bfd_link_order
*) NULL
;
4808 if (p
->type
== bfd_indirect_link_order
4809 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4810 == bfd_target_ecoff_flavour
))
4812 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4815 else if (p
->type
== bfd_section_reloc_link_order
4816 || p
->type
== bfd_symbol_reloc_link_order
)
4818 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4823 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4829 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4831 ecoff_data (abfd
)->linker
= true;
4836 /* Accumulate the debugging information for an input BFD into the
4837 output BFD. This must read in the symbolic information of the
4841 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4844 struct bfd_link_info
*info
;
4847 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4848 const struct ecoff_debug_swap
* const swap
=
4849 &ecoff_backend (input_bfd
)->debug_swap
;
4850 HDRR
*symhdr
= &debug
->symbolic_header
;
4853 #define READ(ptr, offset, count, size, type) \
4854 if (symhdr->count == 0) \
4855 debug->ptr = NULL; \
4858 debug->ptr = (type) malloc (size * symhdr->count); \
4859 if (debug->ptr == NULL) \
4861 bfd_set_error (bfd_error_no_memory); \
4863 goto return_something; \
4865 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4867 || (bfd_read (debug->ptr, size, symhdr->count, \
4868 input_bfd) != size * symhdr->count)) \
4871 goto return_something; \
4875 /* If raw_syments is not NULL, then the data was already by read by
4876 _bfd_ecoff_slurp_symbolic_info. */
4877 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4879 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4881 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4882 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4883 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4884 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4885 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4887 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4888 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4889 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4893 /* We do not read the external strings or the external symbols. */
4895 ret
= (bfd_ecoff_debug_accumulate
4896 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4897 &ecoff_backend (output_bfd
)->debug_swap
,
4898 input_bfd
, debug
, swap
, info
));
4901 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4903 if (debug
->line
!= NULL
)
4905 if (debug
->external_dnr
!= NULL
)
4906 free (debug
->external_dnr
);
4907 if (debug
->external_pdr
!= NULL
)
4908 free (debug
->external_pdr
);
4909 if (debug
->external_sym
!= NULL
)
4910 free (debug
->external_sym
);
4911 if (debug
->external_opt
!= NULL
)
4912 free (debug
->external_opt
);
4913 if (debug
->external_aux
!= NULL
)
4914 free (debug
->external_aux
);
4915 if (debug
->ss
!= NULL
)
4917 if (debug
->external_fdr
!= NULL
)
4918 free (debug
->external_fdr
);
4919 if (debug
->external_rfd
!= NULL
)
4920 free (debug
->external_rfd
);
4922 /* Make sure we don't accidentally follow one of these pointers
4923 into freed memory. */
4925 debug
->external_dnr
= NULL
;
4926 debug
->external_pdr
= NULL
;
4927 debug
->external_sym
= NULL
;
4928 debug
->external_opt
= NULL
;
4929 debug
->external_aux
= NULL
;
4931 debug
->external_fdr
= NULL
;
4932 debug
->external_rfd
= NULL
;
4938 /* Put out information for an external symbol. These come only from
4942 ecoff_link_write_external (h
, data
)
4943 struct ecoff_link_hash_entry
*h
;
4946 bfd
*output_bfd
= (bfd
*) data
;
4948 /* FIXME: We should check if this symbol is being stripped. */
4953 if (h
->abfd
== (bfd
*) NULL
)
4956 h
->esym
.cobol_main
= 0;
4957 h
->esym
.weakext
= 0;
4958 h
->esym
.reserved
= 0;
4959 h
->esym
.ifd
= ifdNil
;
4960 h
->esym
.asym
.value
= 0;
4961 h
->esym
.asym
.st
= stGlobal
;
4963 if (h
->root
.type
!= bfd_link_hash_defined
4964 && h
->root
.type
!= bfd_link_hash_defweak
)
4965 h
->esym
.asym
.sc
= scAbs
;
4968 asection
*output_section
;
4971 output_section
= h
->root
.u
.def
.section
->output_section
;
4972 name
= bfd_section_name (output_section
->owner
, output_section
);
4974 if (strcmp (name
, _TEXT
) == 0)
4975 h
->esym
.asym
.sc
= scText
;
4976 else if (strcmp (name
, _DATA
) == 0)
4977 h
->esym
.asym
.sc
= scData
;
4978 else if (strcmp (name
, _SDATA
) == 0)
4979 h
->esym
.asym
.sc
= scSData
;
4980 else if (strcmp (name
, _RDATA
) == 0)
4981 h
->esym
.asym
.sc
= scRData
;
4982 else if (strcmp (name
, _BSS
) == 0)
4983 h
->esym
.asym
.sc
= scBss
;
4984 else if (strcmp (name
, _SBSS
) == 0)
4985 h
->esym
.asym
.sc
= scSBss
;
4986 else if (strcmp (name
, _INIT
) == 0)
4987 h
->esym
.asym
.sc
= scInit
;
4988 else if (strcmp (name
, _FINI
) == 0)
4989 h
->esym
.asym
.sc
= scFini
;
4990 else if (strcmp (name
, _PDATA
) == 0)
4991 h
->esym
.asym
.sc
= scPData
;
4992 else if (strcmp (name
, _XDATA
) == 0)
4993 h
->esym
.asym
.sc
= scXData
;
4995 h
->esym
.asym
.sc
= scAbs
;
4998 h
->esym
.asym
.reserved
= 0;
4999 h
->esym
.asym
.index
= indexNil
;
5001 else if (h
->esym
.ifd
!= -1)
5003 struct ecoff_debug_info
*debug
;
5005 /* Adjust the FDR index for the symbol by that used for the
5007 debug
= &ecoff_data (h
->abfd
)->debug_info
;
5008 BFD_ASSERT (h
->esym
.ifd
>= 0
5009 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
5010 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
5013 switch (h
->root
.type
)
5016 case bfd_link_hash_new
:
5018 case bfd_link_hash_undefined
:
5019 case bfd_link_hash_undefweak
:
5020 if (h
->esym
.asym
.sc
!= scUndefined
5021 && h
->esym
.asym
.sc
!= scSUndefined
)
5022 h
->esym
.asym
.sc
= scUndefined
;
5024 case bfd_link_hash_defined
:
5025 case bfd_link_hash_defweak
:
5026 if (h
->esym
.asym
.sc
== scUndefined
5027 || h
->esym
.asym
.sc
== scSUndefined
)
5028 h
->esym
.asym
.sc
= scAbs
;
5029 else if (h
->esym
.asym
.sc
== scCommon
)
5030 h
->esym
.asym
.sc
= scBss
;
5031 else if (h
->esym
.asym
.sc
== scSCommon
)
5032 h
->esym
.asym
.sc
= scSBss
;
5033 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
5034 + h
->root
.u
.def
.section
->output_section
->vma
5035 + h
->root
.u
.def
.section
->output_offset
);
5037 case bfd_link_hash_common
:
5038 if (h
->esym
.asym
.sc
!= scCommon
5039 && h
->esym
.asym
.sc
!= scSCommon
)
5040 h
->esym
.asym
.sc
= scCommon
;
5041 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
5043 case bfd_link_hash_indirect
:
5044 case bfd_link_hash_warning
:
5045 /* FIXME: Ignore these for now. The circumstances under which
5046 they should be written out are not clear to me. */
5050 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
5052 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
5055 return (bfd_ecoff_debug_one_external
5056 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
5057 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
5061 /* Relocate and write an ECOFF section into an ECOFF output file. */
5064 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
5066 struct bfd_link_info
*info
;
5067 asection
*output_section
;
5068 struct bfd_link_order
*link_order
;
5070 asection
*input_section
;
5072 struct ecoff_section_tdata
*section_tdata
;
5073 bfd_size_type raw_size
;
5074 bfd_size_type cooked_size
;
5075 bfd_byte
*contents
= NULL
;
5076 bfd_size_type external_reloc_size
;
5077 bfd_size_type external_relocs_size
;
5078 PTR external_relocs
= NULL
;
5080 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
5082 if (link_order
->size
== 0)
5085 input_section
= link_order
->u
.indirect
.section
;
5086 input_bfd
= input_section
->owner
;
5087 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
5089 raw_size
= input_section
->_raw_size
;
5090 cooked_size
= input_section
->_cooked_size
;
5091 if (cooked_size
== 0)
5092 cooked_size
= raw_size
;
5094 BFD_ASSERT (input_section
->output_section
== output_section
);
5095 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
5096 BFD_ASSERT (cooked_size
== link_order
->size
);
5098 /* Get the section contents. We allocate memory for the larger of
5099 the size before relocating and the size after relocating. */
5100 contents
= (bfd_byte
*) malloc (raw_size
>= cooked_size
5103 if (contents
== NULL
&& raw_size
!= 0)
5105 bfd_set_error (bfd_error_no_memory
);
5109 /* If we are relaxing, the contents may have already been read into
5110 memory, in which case we copy them into our new buffer. We don't
5111 simply reuse the old buffer in case cooked_size > raw_size. */
5112 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
5113 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
5114 memcpy (contents
, section_tdata
->contents
, raw_size
);
5117 if (! bfd_get_section_contents (input_bfd
, input_section
,
5119 (file_ptr
) 0, raw_size
))
5123 /* Get the relocs. If we are relaxing MIPS code, they will already
5124 have been read in. Otherwise, we read them in now. */
5125 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
5126 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
5128 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
)
5129 external_relocs
= section_tdata
->external_relocs
;
5132 external_relocs
= (PTR
) malloc (external_relocs_size
);
5133 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
5135 bfd_set_error (bfd_error_no_memory
);
5139 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
5140 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
5141 != external_relocs_size
))
5145 /* Relocate the section contents. */
5146 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
5147 (output_bfd
, info
, input_bfd
, input_section
, contents
,
5151 /* Write out the relocated section. */
5152 if (! bfd_set_section_contents (output_bfd
,
5155 input_section
->output_offset
,
5159 /* If we are producing relocateable output, the relocs were
5160 modified, and we write them out now. We use the reloc_count
5161 field of output_section to keep track of the number of relocs we
5162 have output so far. */
5163 if (info
->relocateable
)
5165 if (bfd_seek (output_bfd
,
5166 (output_section
->rel_filepos
+
5167 output_section
->reloc_count
* external_reloc_size
),
5169 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
5170 != external_relocs_size
))
5172 output_section
->reloc_count
+= input_section
->reloc_count
;
5175 if (contents
!= NULL
)
5177 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
5178 free (external_relocs
);
5182 if (contents
!= NULL
)
5184 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
5185 free (external_relocs
);
5189 /* Generate a reloc when linking an ECOFF file. This is a reloc
5190 requested by the linker, and does come from any input file. This
5191 is used to build constructor and destructor tables when linking
5195 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
5197 struct bfd_link_info
*info
;
5198 asection
*output_section
;
5199 struct bfd_link_order
*link_order
;
5202 struct internal_reloc in
;
5203 bfd_size_type external_reloc_size
;
5207 /* We set up an arelent to pass to the backend adjust_reloc_out
5209 rel
.address
= link_order
->offset
;
5211 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
5214 bfd_set_error (bfd_error_bad_value
);
5218 if (link_order
->type
== bfd_section_reloc_link_order
)
5219 rel
.sym_ptr_ptr
= link_order
->u
.reloc
.p
->u
.section
->symbol_ptr_ptr
;
5222 /* We can't set up a reloc against a symbol correctly, because
5223 we have no asymbol structure. Currently no adjust_reloc_out
5225 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
5228 /* All ECOFF relocs are in-place. Put the addend into the object
5231 BFD_ASSERT (rel
.howto
->partial_inplace
);
5232 if (link_order
->u
.reloc
.p
->addend
!= 0)
5235 bfd_reloc_status_type rstat
;
5239 size
= bfd_get_reloc_size (rel
.howto
);
5240 buf
= (bfd_byte
*) bfd_zmalloc (size
);
5241 if (buf
== (bfd_byte
*) NULL
)
5243 bfd_set_error (bfd_error_no_memory
);
5246 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
5247 link_order
->u
.reloc
.p
->addend
, buf
);
5253 case bfd_reloc_outofrange
:
5255 case bfd_reloc_overflow
:
5256 if (! ((*info
->callbacks
->reloc_overflow
)
5258 (link_order
->type
== bfd_section_reloc_link_order
5259 ? bfd_section_name (output_bfd
,
5260 link_order
->u
.reloc
.p
->u
.section
)
5261 : link_order
->u
.reloc
.p
->u
.name
),
5262 rel
.howto
->name
, link_order
->u
.reloc
.p
->addend
,
5263 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
5270 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
5271 (file_ptr
) link_order
->offset
, size
);
5279 /* Move the information into a internal_reloc structure. */
5280 in
.r_vaddr
= (rel
.address
5281 + bfd_get_section_vma (output_bfd
, output_section
));
5282 in
.r_type
= rel
.howto
->type
;
5284 if (link_order
->type
== bfd_symbol_reloc_link_order
)
5286 struct ecoff_link_hash_entry
*h
;
5288 h
= ecoff_link_hash_lookup (ecoff_hash_table (info
),
5289 link_order
->u
.reloc
.p
->u
.name
,
5290 false, false, true);
5291 if (h
!= (struct ecoff_link_hash_entry
*) NULL
5293 in
.r_symndx
= h
->indx
;
5296 if (! ((*info
->callbacks
->unattached_reloc
)
5297 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
5298 (asection
*) NULL
, (bfd_vma
) 0)))
5308 name
= bfd_get_section_name (output_bfd
,
5309 link_order
->u
.reloc
.p
->u
.section
);
5310 if (strcmp (name
, ".text") == 0)
5311 in
.r_symndx
= RELOC_SECTION_TEXT
;
5312 else if (strcmp (name
, ".rdata") == 0)
5313 in
.r_symndx
= RELOC_SECTION_RDATA
;
5314 else if (strcmp (name
, ".data") == 0)
5315 in
.r_symndx
= RELOC_SECTION_DATA
;
5316 else if (strcmp (name
, ".sdata") == 0)
5317 in
.r_symndx
= RELOC_SECTION_SDATA
;
5318 else if (strcmp (name
, ".sbss") == 0)
5319 in
.r_symndx
= RELOC_SECTION_SBSS
;
5320 else if (strcmp (name
, ".bss") == 0)
5321 in
.r_symndx
= RELOC_SECTION_BSS
;
5322 else if (strcmp (name
, ".init") == 0)
5323 in
.r_symndx
= RELOC_SECTION_INIT
;
5324 else if (strcmp (name
, ".lit8") == 0)
5325 in
.r_symndx
= RELOC_SECTION_LIT8
;
5326 else if (strcmp (name
, ".lit4") == 0)
5327 in
.r_symndx
= RELOC_SECTION_LIT4
;
5328 else if (strcmp (name
, ".xdata") == 0)
5329 in
.r_symndx
= RELOC_SECTION_XDATA
;
5330 else if (strcmp (name
, ".pdata") == 0)
5331 in
.r_symndx
= RELOC_SECTION_PDATA
;
5332 else if (strcmp (name
, ".fini") == 0)
5333 in
.r_symndx
= RELOC_SECTION_FINI
;
5334 else if (strcmp (name
, ".lita") == 0)
5335 in
.r_symndx
= RELOC_SECTION_LITA
;
5336 else if (strcmp (name
, "*ABS*") == 0)
5337 in
.r_symndx
= RELOC_SECTION_ABS
;
5343 /* Let the BFD backend adjust the reloc. */
5344 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
5346 /* Get some memory and swap out the reloc. */
5347 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
5348 rbuf
= (bfd_byte
*) malloc (external_reloc_size
);
5349 if (rbuf
== (bfd_byte
*) NULL
)
5351 bfd_set_error (bfd_error_no_memory
);
5355 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
5357 ok
= (bfd_seek (output_bfd
,
5358 (output_section
->rel_filepos
+
5359 output_section
->reloc_count
* external_reloc_size
),
5361 && (bfd_write ((PTR
) rbuf
, 1, external_reloc_size
, output_bfd
)
5362 == external_reloc_size
));
5365 ++output_section
->reloc_count
;