1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
48 asymbol
*asym
, int ext
,
49 asymbol
**indirect_ptr_ptr
));
50 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
51 RNDXR
*rndx
, long isym
,
53 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
54 unsigned int indx
, int bigendian
));
55 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
57 static void ecoff_clear_output_flags
PARAMS ((bfd
*abfd
));
58 static boolean ecoff_rel
PARAMS ((bfd
*output_bfd
, bfd_seclet_type
*seclet
,
59 asection
*output_section
, PTR data
,
60 boolean relocateable
));
61 static boolean ecoff_dump_seclet
PARAMS ((bfd
*abfd
, bfd_seclet_type
*seclet
,
62 asection
*section
, PTR data
,
63 boolean relocateable
));
64 static long ecoff_add_string
PARAMS ((bfd
*output_bfd
, FDR
*fdr
,
65 CONST
char *string
, boolean external
));
66 static boolean ecoff_get_debug
PARAMS ((bfd
*output_bfd
,
67 bfd_seclet_type
*seclet
,
69 boolean relocateable
));
70 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
71 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
76 /* This stuff is somewhat copied from coffcode.h. */
78 static asection bfd_debug_section
= { "*DEBUG*" };
80 /* Create an ECOFF object. */
86 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
87 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
88 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
90 bfd_error
= no_memory
;
94 /* Always create a .scommon section for every BFD. This is a hack so
95 that the linker has something to attach scSCommon symbols to. */
96 bfd_make_section (abfd
, SCOMMON
);
101 /* This is a hook needed by SCO COFF, but we have nothing to do. */
104 ecoff_make_section_hook (abfd
, name
)
108 return (asection
*) NULL
;
111 /* Initialize a new section. */
114 ecoff_new_section_hook (abfd
, section
)
118 section
->alignment_power
= abfd
->xvec
->align_power_min
;
120 if (strcmp (section
->name
, _TEXT
) == 0)
121 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
122 else if (strcmp (section
->name
, _DATA
) == 0
123 || strcmp (section
->name
, _SDATA
) == 0)
124 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
125 else if (strcmp (section
->name
, _RDATA
) == 0
126 || strcmp (section
->name
, _LIT8
) == 0
127 || strcmp (section
->name
, _LIT4
) == 0)
128 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
129 else if (strcmp (section
->name
, _BSS
) == 0
130 || strcmp (section
->name
, _SBSS
) == 0)
131 section
->flags
|= SEC_ALLOC
;
133 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
134 uncertain about .init on some systems and I don't know how shared
140 /* Determine the machine architecture and type. */
143 ecoff_set_arch_mach_hook (abfd
, filehdr
)
147 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
148 enum bfd_architecture arch
;
150 switch (internal_f
->f_magic
)
153 case MIPS_MAGIC_LITTLE
:
155 arch
= bfd_arch_mips
;
159 arch
= bfd_arch_alpha
;
163 arch
= bfd_arch_obscure
;
167 bfd_default_set_arch_mach (abfd
, arch
, (unsigned long) 0);
172 /* Get the section s_flags to use for a section. */
175 ecoff_sec_to_styp_flags (name
, flags
)
183 if (strcmp (name
, _TEXT
) == 0)
185 else if (strcmp (name
, _DATA
) == 0)
187 else if (strcmp (name
, _SDATA
) == 0)
189 else if (strcmp (name
, _RDATA
) == 0)
191 else if (strcmp (name
, _LIT8
) == 0)
193 else if (strcmp (name
, _LIT4
) == 0)
195 else if (strcmp (name
, _BSS
) == 0)
197 else if (strcmp (name
, _SBSS
) == 0)
199 else if (strcmp (name
, _INIT
) == 0)
200 styp
= STYP_ECOFF_INIT
;
201 else if (flags
& SEC_CODE
)
203 else if (flags
& SEC_DATA
)
205 else if (flags
& SEC_READONLY
)
207 else if (flags
& SEC_LOAD
)
212 if (flags
& SEC_NEVER_LOAD
)
218 /* Get the BFD flags to use for a section. */
221 ecoff_styp_to_sec_flags (abfd
, hdr
)
225 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
226 long styp_flags
= internal_s
->s_flags
;
227 flagword sec_flags
=0;
229 if (styp_flags
& STYP_NOLOAD
)
230 sec_flags
|= SEC_NEVER_LOAD
;
232 /* For 386 COFF, at least, an unloadable text or data section is
233 actually a shared library section. */
234 if ((styp_flags
& STYP_TEXT
)
235 || (styp_flags
& STYP_ECOFF_INIT
))
237 if (sec_flags
& SEC_NEVER_LOAD
)
238 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
240 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
242 else if ((styp_flags
& STYP_DATA
)
243 || (styp_flags
& STYP_RDATA
)
244 || (styp_flags
& STYP_SDATA
))
246 if (sec_flags
& SEC_NEVER_LOAD
)
247 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
249 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
250 if (styp_flags
& STYP_RDATA
)
251 sec_flags
|= SEC_READONLY
;
253 else if ((styp_flags
& STYP_BSS
)
254 || (styp_flags
& STYP_SBSS
))
256 sec_flags
|= SEC_ALLOC
;
258 else if (styp_flags
& STYP_INFO
)
260 sec_flags
|= SEC_NEVER_LOAD
;
262 else if ((styp_flags
& STYP_LIT8
)
263 || (styp_flags
& STYP_LIT4
))
265 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
269 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
275 /* Routines to swap auxiliary information in and out. I am assuming
276 that the auxiliary information format is always going to be target
279 /* Swap in a type information record.
280 BIGEND says whether AUX symbols are big-endian or little-endian; this
281 info comes from the file header record (fh-fBigendian). */
284 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
286 struct tir_ext
*ext_copy
;
289 struct tir_ext ext
[1];
291 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
293 /* now the fun stuff... */
295 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
296 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
297 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
298 >> TIR_BITS1_BT_SH_BIG
;
299 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
300 >> TIR_BITS_TQ4_SH_BIG
;
301 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
302 >> TIR_BITS_TQ5_SH_BIG
;
303 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
304 >> TIR_BITS_TQ0_SH_BIG
;
305 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
306 >> TIR_BITS_TQ1_SH_BIG
;
307 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
308 >> TIR_BITS_TQ2_SH_BIG
;
309 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
310 >> TIR_BITS_TQ3_SH_BIG
;
312 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
313 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
314 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
315 >> TIR_BITS1_BT_SH_LITTLE
;
316 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
317 >> TIR_BITS_TQ4_SH_LITTLE
;
318 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
319 >> TIR_BITS_TQ5_SH_LITTLE
;
320 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
321 >> TIR_BITS_TQ0_SH_LITTLE
;
322 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
323 >> TIR_BITS_TQ1_SH_LITTLE
;
324 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
325 >> TIR_BITS_TQ2_SH_LITTLE
;
326 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
327 >> TIR_BITS_TQ3_SH_LITTLE
;
331 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
336 /* Swap out a type information record.
337 BIGEND says whether AUX symbols are big-endian or little-endian; this
338 info comes from the file header record (fh-fBigendian). */
341 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
348 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
350 /* now the fun stuff... */
352 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
353 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
354 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
355 & TIR_BITS1_BT_BIG
));
356 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
358 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
359 & TIR_BITS_TQ5_BIG
));
360 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
362 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
363 & TIR_BITS_TQ1_BIG
));
364 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
366 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
367 & TIR_BITS_TQ3_BIG
));
369 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
370 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
371 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
372 & TIR_BITS1_BT_LITTLE
));
373 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
374 & TIR_BITS_TQ4_LITTLE
)
375 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
376 & TIR_BITS_TQ5_LITTLE
));
377 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
378 & TIR_BITS_TQ0_LITTLE
)
379 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
380 & TIR_BITS_TQ1_LITTLE
));
381 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
382 & TIR_BITS_TQ2_LITTLE
)
383 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
384 & TIR_BITS_TQ3_LITTLE
));
388 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
393 /* Swap in a relative symbol record. BIGEND says whether it is in
394 big-endian or little-endian format.*/
397 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
399 struct rndx_ext
*ext_copy
;
402 struct rndx_ext ext
[1];
404 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
406 /* now the fun stuff... */
408 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
409 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
410 >> RNDX_BITS1_RFD_SH_BIG
);
411 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
412 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
413 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
414 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
416 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
417 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
418 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
419 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
420 >> RNDX_BITS1_INDEX_SH_LITTLE
)
421 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
422 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
426 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
431 /* Swap out a relative symbol record. BIGEND says whether it is in
432 big-endian or little-endian format.*/
435 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
438 struct rndx_ext
*ext
;
442 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
444 /* now the fun stuff... */
446 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
447 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
448 & RNDX_BITS1_RFD_BIG
)
449 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
450 & RNDX_BITS1_INDEX_BIG
));
451 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
452 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
454 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
455 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
456 & RNDX_BITS1_RFD_LITTLE
)
457 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
458 & RNDX_BITS1_INDEX_LITTLE
));
459 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
460 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
464 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
469 /* Read in and swap the important symbolic information for an ECOFF
470 object file. This is called by gdb. */
473 ecoff_slurp_symbolic_info (abfd
)
476 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
477 bfd_size_type external_hdr_size
;
478 HDRR
*internal_symhdr
;
479 bfd_size_type raw_base
;
480 bfd_size_type raw_size
;
482 bfd_size_type external_fdr_size
;
487 /* Check whether we've already gotten it, and whether there's any to
489 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
491 if (ecoff_data (abfd
)->sym_filepos
== 0)
493 bfd_get_symcount (abfd
) = 0;
497 /* At this point bfd_get_symcount (abfd) holds the number of symbols
498 as read from the file header, but on ECOFF this is always the
499 size of the symbolic information header. It would be cleaner to
500 handle this when we first read the file in coffgen.c. */
501 external_hdr_size
= backend
->external_hdr_size
;
502 if (bfd_get_symcount (abfd
) != external_hdr_size
)
504 bfd_error
= bad_value
;
508 /* Read the symbolic information header. */
509 raw
= (PTR
) alloca (external_hdr_size
);
510 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
511 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
512 != external_hdr_size
))
514 bfd_error
= system_call_error
;
517 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
518 (*backend
->swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
520 if (internal_symhdr
->magic
!= backend
->sym_magic
)
522 bfd_error
= bad_value
;
526 /* Now we can get the correct number of symbols. */
527 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
528 + internal_symhdr
->iextMax
);
530 /* Read all the symbolic information at once. */
531 raw_base
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
533 if (internal_symhdr
->cbExtOffset
!= 0)
534 raw_size
= (internal_symhdr
->cbExtOffset
536 + internal_symhdr
->iextMax
* backend
->external_ext_size
);
539 long cbline
, issmax
, issextmax
;
541 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 3;
542 issmax
= (internal_symhdr
->issMax
+ 3) &~ 3;
543 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 3;
544 raw_size
= (cbline
* sizeof (unsigned char)
545 + internal_symhdr
->idnMax
* backend
->external_dnr_size
546 + internal_symhdr
->ipdMax
* backend
->external_pdr_size
547 + internal_symhdr
->isymMax
* backend
->external_sym_size
548 + internal_symhdr
->ioptMax
* backend
->external_opt_size
549 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
550 + issmax
* sizeof (char)
551 + issextmax
* sizeof (char)
552 + internal_symhdr
->ifdMax
* backend
->external_fdr_size
553 + internal_symhdr
->crfd
* backend
->external_rfd_size
554 + internal_symhdr
->iextMax
* backend
->external_ext_size
);
559 ecoff_data (abfd
)->sym_filepos
= 0;
562 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
565 bfd_error
= no_memory
;
568 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
570 bfd_error
= system_call_error
;
571 bfd_release (abfd
, raw
);
575 ecoff_data (abfd
)->raw_size
= raw_size
;
576 ecoff_data (abfd
)->raw_syments
= raw
;
578 /* Get pointers for the numeric offsets in the HDRR structure. */
579 #define FIX(off1, off2, type) \
580 if (internal_symhdr->off1 == 0) \
581 ecoff_data (abfd)->off2 = (type) NULL; \
583 ecoff_data (abfd)->off2 = (type) ((char *) raw \
584 + internal_symhdr->off1 \
586 FIX (cbLineOffset
, line
, unsigned char *);
587 FIX (cbDnOffset
, external_dnr
, PTR
);
588 FIX (cbPdOffset
, external_pdr
, PTR
);
589 FIX (cbSymOffset
, external_sym
, PTR
);
590 FIX (cbOptOffset
, external_opt
, PTR
);
591 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
592 FIX (cbSsOffset
, ss
, char *);
593 FIX (cbSsExtOffset
, ssext
, char *);
594 FIX (cbFdOffset
, external_fdr
, PTR
);
595 FIX (cbRfdOffset
, external_rfd
, PTR
);
596 FIX (cbExtOffset
, external_ext
, PTR
);
599 /* I don't want to always swap all the data, because it will just
600 waste time and most programs will never look at it. The only
601 time the linker needs most of the debugging information swapped
602 is when linking big-endian and little-endian MIPS object files
603 together, which is not a common occurrence.
605 We need to look at the fdr to deal with a lot of information in
606 the symbols, so we swap them here. */
607 ecoff_data (abfd
)->fdr
=
608 (struct fdr
*) bfd_alloc (abfd
,
609 (internal_symhdr
->ifdMax
*
610 sizeof (struct fdr
)));
611 if (ecoff_data (abfd
)->fdr
== NULL
)
613 bfd_error
= no_memory
;
616 external_fdr_size
= backend
->external_fdr_size
;
617 fdr_ptr
= ecoff_data (abfd
)->fdr
;
618 fraw_src
= (char *) ecoff_data (abfd
)->external_fdr
;
619 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
620 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
621 (*backend
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
626 /* ECOFF symbol table routines. The ECOFF symbol table is described
627 in gcc/mips-tfile.c. */
629 /* ECOFF uses two common sections. One is the usual one, and the
630 other is for small objects. All the small objects are kept
631 together, and then referenced via the gp pointer, which yields
632 faster assembler code. This is what we use for the small common
634 static asection ecoff_scom_section
;
635 static asymbol ecoff_scom_symbol
;
636 static asymbol
*ecoff_scom_symbol_ptr
;
638 /* Create an empty symbol. */
641 ecoff_make_empty_symbol (abfd
)
644 ecoff_symbol_type
*new;
646 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
647 if (new == (ecoff_symbol_type
*) NULL
)
649 bfd_error
= no_memory
;
650 return (asymbol
*) NULL
;
652 memset (new, 0, sizeof *new);
653 new->symbol
.section
= (asection
*) NULL
;
654 new->fdr
= (FDR
*) NULL
;
657 new->symbol
.the_bfd
= abfd
;
661 /* Set the BFD flags and section for an ECOFF symbol. */
664 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
669 asymbol
**indirect_ptr_ptr
;
671 asym
->the_bfd
= abfd
;
672 asym
->value
= ecoff_sym
->value
;
673 asym
->section
= &bfd_debug_section
;
676 /* An indirect symbol requires two consecutive stabs symbols. */
677 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
679 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
681 /* @@ Stuffing pointers into integers is a no-no.
682 We can usually get away with it if the integer is
683 large enough though. */
684 if (sizeof (asym
) > sizeof (bfd_vma
))
686 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
688 asym
->flags
= BSF_DEBUGGING
;
689 asym
->section
= &bfd_und_section
;
690 *indirect_ptr_ptr
= NULL
;
694 if (ECOFF_IS_STAB (ecoff_sym
)
695 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
697 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
698 asym
->section
= &bfd_ind_section
;
699 /* Pass this symbol on to the next call to this function. */
700 *indirect_ptr_ptr
= asym
;
704 /* Most symbol types are just for debugging. */
705 switch (ecoff_sym
->st
)
714 if (ECOFF_IS_STAB (ecoff_sym
))
716 asym
->flags
= BSF_DEBUGGING
;
721 asym
->flags
= BSF_DEBUGGING
;
726 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
728 asym
->flags
= BSF_LOCAL
;
729 switch (ecoff_sym
->sc
)
732 /* Used for compiler generated labels. Leave them in the
733 debugging section, and mark them as local. If BSF_DEBUGGING
734 is set, then nm does not display them for some reason. If no
735 flags are set then the linker whines about them. */
736 asym
->flags
= BSF_LOCAL
;
739 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
740 asym
->value
-= asym
->section
->vma
;
743 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
744 asym
->value
-= asym
->section
->vma
;
747 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
748 asym
->value
-= asym
->section
->vma
;
751 asym
->flags
= BSF_DEBUGGING
;
754 asym
->section
= &bfd_abs_section
;
757 asym
->section
= &bfd_und_section
;
767 asym
->flags
= BSF_DEBUGGING
;
770 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
771 asym
->value
-= asym
->section
->vma
;
774 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
775 asym
->value
-= asym
->section
->vma
;
778 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
779 asym
->value
-= asym
->section
->vma
;
782 asym
->flags
= BSF_DEBUGGING
;
785 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
787 asym
->section
= &bfd_com_section
;
793 if (ecoff_scom_section
.name
== NULL
)
795 /* Initialize the small common section. */
796 ecoff_scom_section
.name
= SCOMMON
;
797 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
798 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
799 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
800 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
801 ecoff_scom_symbol
.name
= SCOMMON
;
802 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
803 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
804 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
806 asym
->section
= &ecoff_scom_section
;
811 asym
->flags
= BSF_DEBUGGING
;
814 asym
->section
= &bfd_und_section
;
819 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
820 asym
->value
-= asym
->section
->vma
;
825 asym
->flags
= BSF_DEBUGGING
;
828 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
829 asym
->value
-= asym
->section
->vma
;
835 /* Look for special constructors symbols and make relocation entries
836 in a special construction section. These are produced by the
837 -fgnu-linker argument to g++. */
838 if (ECOFF_IS_STAB (ecoff_sym
))
840 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
852 arelent_chain
*reloc_chain
;
853 unsigned int bitsize
;
855 /* Get a section with the same name as the symbol (usually
856 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
857 name ___CTOR_LIST (three underscores). We need
858 __CTOR_LIST (two underscores), since ECOFF doesn't use
859 a leading underscore. This should be handled by gcc,
860 but instead we do it here. Actually, this should all
861 be done differently anyhow. */
862 name
= bfd_asymbol_name (asym
);
863 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
868 section
= bfd_get_section_by_name (abfd
, name
);
869 if (section
== (asection
*) NULL
)
873 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
875 section
= bfd_make_section (abfd
, copy
);
878 /* Build a reloc pointing to this constructor. */
880 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
881 reloc_chain
->relent
.sym_ptr_ptr
=
882 bfd_get_section (asym
)->symbol_ptr_ptr
;
883 reloc_chain
->relent
.address
= section
->_raw_size
;
884 reloc_chain
->relent
.addend
= asym
->value
;
885 reloc_chain
->relent
.howto
=
886 ecoff_backend (abfd
)->constructor_reloc
;
888 /* Set up the constructor section to hold the reloc. */
889 section
->flags
= SEC_CONSTRUCTOR
;
890 ++section
->reloc_count
;
892 /* Constructor sections must be rounded to a boundary
893 based on the bitsize. These are not real sections--
894 they are handled specially by the linker--so the ECOFF
895 16 byte alignment restriction does not apply. */
896 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
897 section
->alignment_power
= 1;
898 while ((1 << section
->alignment_power
) < bitsize
/ 8)
899 ++section
->alignment_power
;
901 reloc_chain
->next
= section
->constructor_chain
;
902 section
->constructor_chain
= reloc_chain
;
903 section
->_raw_size
+= bitsize
/ 8;
905 /* Mark the symbol as a constructor. */
906 asym
->flags
|= BSF_CONSTRUCTOR
;
913 /* Read an ECOFF symbol table. */
916 ecoff_slurp_symbol_table (abfd
)
919 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
920 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
921 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
922 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
923 = backend
->swap_ext_in
;
924 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
925 = backend
->swap_sym_in
;
926 bfd_size_type internal_size
;
927 ecoff_symbol_type
*internal
;
928 ecoff_symbol_type
*internal_ptr
;
929 asymbol
*indirect_ptr
;
935 /* If we've already read in the symbol table, do nothing. */
936 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
939 /* Get the symbolic information. */
940 if (ecoff_slurp_symbolic_info (abfd
) == false)
942 if (bfd_get_symcount (abfd
) == 0)
945 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
946 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
947 if (internal
== NULL
)
949 bfd_error
= no_memory
;
953 internal_ptr
= internal
;
955 eraw_src
= (char *) ecoff_data (abfd
)->external_ext
;
957 + (ecoff_data (abfd
)->symbolic_header
.iextMax
958 * external_ext_size
));
959 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
963 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
964 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
965 + internal_esym
.asym
.iss
);
966 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
967 &internal_ptr
->symbol
, 1, &indirect_ptr
);
968 /* The alpha uses a negative ifd field for section symbols. */
969 if (internal_esym
.ifd
>= 0)
970 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
972 internal_ptr
->fdr
= NULL
;
973 internal_ptr
->local
= false;
974 internal_ptr
->native
= (PTR
) eraw_src
;
976 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
978 /* The local symbols must be accessed via the fdr's, because the
979 string and aux indices are relative to the fdr information. */
980 fdr_ptr
= ecoff_data (abfd
)->fdr
;
981 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
982 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
987 lraw_src
= ((char *) ecoff_data (abfd
)->external_sym
988 + fdr_ptr
->isymBase
* external_sym_size
);
989 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
992 lraw_src
+= external_sym_size
, internal_ptr
++)
996 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
997 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
1000 ecoff_set_symbol_info (abfd
, &internal_sym
,
1001 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1002 internal_ptr
->fdr
= fdr_ptr
;
1003 internal_ptr
->local
= true;
1004 internal_ptr
->native
= (PTR
) lraw_src
;
1007 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1009 ecoff_data (abfd
)->canonical_symbols
= internal
;
1014 /* Return the amount of space needed for the canonical symbols. */
1017 ecoff_get_symtab_upper_bound (abfd
)
1020 if (ecoff_slurp_symbolic_info (abfd
) == false
1021 || bfd_get_symcount (abfd
) == 0)
1024 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1027 /* Get the canonicals symbols. */
1030 ecoff_get_symtab (abfd
, alocation
)
1032 asymbol
**alocation
;
1034 unsigned int counter
= 0;
1035 ecoff_symbol_type
*symbase
;
1036 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1038 if (ecoff_slurp_symbol_table (abfd
) == false
1039 || bfd_get_symcount (abfd
) == 0)
1042 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1043 while (counter
< bfd_get_symcount (abfd
))
1045 *(location
++) = symbase
++;
1048 *location
++ = (ecoff_symbol_type
*) NULL
;
1049 return bfd_get_symcount (abfd
);
1052 /* Turn ECOFF type information into a printable string.
1053 ecoff_emit_aggregate and ecoff_type_to_string are from
1054 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1056 /* Write aggregate information to a string. */
1059 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1066 int ifd
= rndx
->rfd
;
1067 int indx
= rndx
->index
;
1068 int sym_base
, ss_base
;
1074 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
1075 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
1077 if (indx
== indexNil
)
1078 name
= "/* no name */";
1081 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1085 (*backend
->swap_sym_in
) (abfd
,
1086 ((char *) ecoff_data (abfd
)->external_sym
1087 + indx
* backend
->external_sym_size
),
1089 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
1093 "%s %s { ifd = %d, index = %d }",
1095 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
1098 /* Convert the type information to string format. */
1101 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1103 union aux_ext
*aux_ptr
;
1115 unsigned int basic_type
;
1117 static char buffer1
[1024];
1118 static char buffer2
[1024];
1123 for (i
= 0; i
< 7; i
++)
1125 qualifiers
[i
].low_bound
= 0;
1126 qualifiers
[i
].high_bound
= 0;
1127 qualifiers
[i
].stride
= 0;
1130 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1131 return "-1 (no type)";
1132 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1134 basic_type
= u
.ti
.bt
;
1135 qualifiers
[0].type
= u
.ti
.tq0
;
1136 qualifiers
[1].type
= u
.ti
.tq1
;
1137 qualifiers
[2].type
= u
.ti
.tq2
;
1138 qualifiers
[3].type
= u
.ti
.tq3
;
1139 qualifiers
[4].type
= u
.ti
.tq4
;
1140 qualifiers
[5].type
= u
.ti
.tq5
;
1141 qualifiers
[6].type
= tqNil
;
1144 * Go get the basic type.
1148 case btNil
: /* undefined */
1152 case btAdr
: /* address - integer same size as pointer */
1153 strcpy (p1
, "address");
1156 case btChar
: /* character */
1157 strcpy (p1
, "char");
1160 case btUChar
: /* unsigned character */
1161 strcpy (p1
, "unsigned char");
1164 case btShort
: /* short */
1165 strcpy (p1
, "short");
1168 case btUShort
: /* unsigned short */
1169 strcpy (p1
, "unsigned short");
1172 case btInt
: /* int */
1176 case btUInt
: /* unsigned int */
1177 strcpy (p1
, "unsigned int");
1180 case btLong
: /* long */
1181 strcpy (p1
, "long");
1184 case btULong
: /* unsigned long */
1185 strcpy (p1
, "unsigned long");
1188 case btFloat
: /* float (real) */
1189 strcpy (p1
, "float");
1192 case btDouble
: /* Double (real) */
1193 strcpy (p1
, "double");
1196 /* Structures add 1-2 aux words:
1197 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1198 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1200 case btStruct
: /* Structure (Record) */
1201 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1202 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1203 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1205 indx
++; /* skip aux words */
1208 /* Unions add 1-2 aux words:
1209 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1210 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1212 case btUnion
: /* Union */
1213 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1214 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1215 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1217 indx
++; /* skip aux words */
1220 /* Enumerations add 1-2 aux words:
1221 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1222 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1224 case btEnum
: /* Enumeration */
1225 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1226 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1227 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1229 indx
++; /* skip aux words */
1232 case btTypedef
: /* defined via a typedef, isymRef points */
1233 strcpy (p1
, "typedef");
1236 case btRange
: /* subrange of int */
1237 strcpy (p1
, "subrange");
1240 case btSet
: /* pascal sets */
1244 case btComplex
: /* fortran complex */
1245 strcpy (p1
, "complex");
1248 case btDComplex
: /* fortran double complex */
1249 strcpy (p1
, "double complex");
1252 case btIndirect
: /* forward or unnamed typedef */
1253 strcpy (p1
, "forward/unamed typedef");
1256 case btFixedDec
: /* Fixed Decimal */
1257 strcpy (p1
, "fixed decimal");
1260 case btFloatDec
: /* Float Decimal */
1261 strcpy (p1
, "float decimal");
1264 case btString
: /* Varying Length Character String */
1265 strcpy (p1
, "string");
1268 case btBit
: /* Aligned Bit String */
1272 case btPicture
: /* Picture */
1273 strcpy (p1
, "picture");
1276 case btVoid
: /* Void */
1277 strcpy (p1
, "void");
1281 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1285 p1
+= strlen (buffer1
);
1288 * If this is a bitfield, get the bitsize.
1294 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1295 sprintf (p1
, " : %d", bitsize
);
1296 p1
+= strlen (buffer1
);
1301 * Deal with any qualifiers.
1303 if (qualifiers
[0].type
!= tqNil
)
1306 * Snarf up any array bounds in the correct order. Arrays
1307 * store 5 successive words in the aux. table:
1308 * word 0 RNDXR to type of the bounds (ie, int)
1309 * word 1 Current file descriptor index
1311 * word 3 high bound (or -1 if [])
1312 * word 4 stride size in bits
1314 for (i
= 0; i
< 7; i
++)
1316 if (qualifiers
[i
].type
== tqArray
)
1318 qualifiers
[i
].low_bound
=
1319 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1320 qualifiers
[i
].high_bound
=
1321 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1322 qualifiers
[i
].stride
=
1323 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1329 * Now print out the qualifiers.
1331 for (i
= 0; i
< 6; i
++)
1333 switch (qualifiers
[i
].type
)
1340 strcpy (p2
, "ptr to ");
1341 p2
+= sizeof ("ptr to ")-1;
1345 strcpy (p2
, "volatile ");
1346 p2
+= sizeof ("volatile ")-1;
1350 strcpy (p2
, "far ");
1351 p2
+= sizeof ("far ")-1;
1355 strcpy (p2
, "func. ret. ");
1356 p2
+= sizeof ("func. ret. ");
1361 int first_array
= i
;
1364 /* Print array bounds reversed (ie, in the order the C
1365 programmer writes them). C is such a fun language.... */
1367 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1370 for (j
= i
; j
>= first_array
; j
--)
1372 strcpy (p2
, "array [");
1373 p2
+= sizeof ("array [")-1;
1374 if (qualifiers
[j
].low_bound
!= 0)
1376 "%ld:%ld {%ld bits}",
1377 (long) qualifiers
[j
].low_bound
,
1378 (long) qualifiers
[j
].high_bound
,
1379 (long) qualifiers
[j
].stride
);
1381 else if (qualifiers
[j
].high_bound
!= -1)
1384 (long) (qualifiers
[j
].high_bound
+ 1),
1385 (long) (qualifiers
[j
].stride
));
1388 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1391 strcpy (p2
, "] of ");
1392 p2
+= sizeof ("] of ")-1;
1400 strcpy (p2
, buffer1
);
1404 /* Return information about ECOFF symbol SYMBOL in RET. */
1407 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1408 bfd
*abfd
; /* Ignored. */
1412 bfd_symbol_info (symbol
, ret
);
1415 /* Print information about an ECOFF symbol. */
1418 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1422 bfd_print_symbol_type how
;
1424 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1425 FILE *file
= (FILE *)filep
;
1429 case bfd_print_symbol_name
:
1430 fprintf (file
, "%s", symbol
->name
);
1432 case bfd_print_symbol_more
:
1433 if (ecoffsymbol (symbol
)->local
)
1437 (*backend
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1439 fprintf (file
, "ecoff local ");
1440 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1441 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1442 (unsigned) ecoff_sym
.sc
);
1448 (*backend
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1450 fprintf (file
, "ecoff extern ");
1451 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1452 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1453 (unsigned) ecoff_ext
.asym
.sc
);
1456 case bfd_print_symbol_all
:
1457 /* Print out the symbols in a reasonable way */
1466 if (ecoffsymbol (symbol
)->local
)
1468 (*backend
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1471 pos
= ((((char *) ecoffsymbol (symbol
)->native
1472 - (char *) ecoff_data (abfd
)->external_sym
)
1473 / backend
->external_sym_size
)
1474 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1481 (*backend
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1484 pos
= (((char *) ecoffsymbol (symbol
)->native
1485 - (char *) ecoff_data (abfd
)->external_ext
)
1486 / backend
->external_ext_size
);
1487 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1488 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1489 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1492 fprintf (file
, "[%3d] %c ",
1494 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1495 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1496 (unsigned) ecoff_ext
.asym
.st
,
1497 (unsigned) ecoff_ext
.asym
.sc
,
1498 (unsigned) ecoff_ext
.asym
.index
,
1499 jmptbl
, cobol_main
, weakext
,
1502 if (ecoffsymbol (symbol
)->fdr
!= NULL
1503 && ecoff_ext
.asym
.index
!= indexNil
)
1507 bfd_size_type sym_base
;
1508 union aux_ext
*aux_base
;
1510 indx
= ecoff_ext
.asym
.index
;
1512 /* sym_base is used to map the fdr relative indices which
1513 appear in the file to the position number which we are
1515 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1516 if (ecoffsymbol (symbol
)->local
)
1517 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1519 /* aux_base is the start of the aux entries for this file;
1520 asym.index is an offset from this. */
1521 aux_base
= (ecoff_data (abfd
)->external_aux
1522 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1524 /* The aux entries are stored in host byte order; the
1525 order is indicated by a bit in the fdr. */
1526 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1528 /* This switch is basically from gcc/mips-tdump.c */
1529 switch (ecoff_ext
.asym
.st
)
1537 fprintf (file
, "\n End+1 symbol: %ld",
1538 (long) (indx
+ sym_base
));
1542 if (ecoff_ext
.asym
.sc
== scText
1543 || ecoff_ext
.asym
.sc
== scInfo
)
1544 fprintf (file
, "\n First symbol: %ld",
1545 (long) (indx
+ sym_base
));
1547 fprintf (file
, "\n First symbol: %ld",
1548 (long) (AUX_GET_ISYM (bigendian
,
1549 &aux_base
[ecoff_ext
.asym
.index
])
1555 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1557 else if (ecoffsymbol (symbol
)->local
)
1558 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1559 (long) (AUX_GET_ISYM (bigendian
,
1560 &aux_base
[ecoff_ext
.asym
.index
])
1562 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1565 fprintf (file
, "\n Local symbol: %d",
1568 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1572 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1573 fprintf (file
, "\n Type: %s",
1574 ecoff_type_to_string (abfd
, aux_base
, indx
,
1584 /* Read in the relocs for a section. */
1587 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1592 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1593 arelent
*internal_relocs
;
1594 bfd_size_type external_reloc_size
;
1595 bfd_size_type external_relocs_size
;
1596 char *external_relocs
;
1600 if (section
->relocation
!= (arelent
*) NULL
1601 || section
->reloc_count
== 0
1602 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1605 if (ecoff_slurp_symbol_table (abfd
) == false)
1608 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1610 * section
->reloc_count
));
1611 external_reloc_size
= backend
->external_reloc_size
;
1612 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1613 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1614 if (internal_relocs
== (arelent
*) NULL
1615 || external_relocs
== (char *) NULL
)
1617 bfd_error
= no_memory
;
1620 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1622 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1623 != external_relocs_size
)
1625 bfd_error
= system_call_error
;
1629 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1631 struct internal_reloc intern
;
1633 (*backend
->swap_reloc_in
) (abfd
,
1634 external_relocs
+ i
* external_reloc_size
,
1637 if (intern
.r_extern
)
1639 /* r_symndx is an index into the external symbols. */
1640 BFD_ASSERT (intern
.r_symndx
>= 0
1642 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1643 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1646 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1647 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1649 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1654 CONST
char *sec_name
;
1657 /* r_symndx is a section key. */
1658 switch (intern
.r_symndx
)
1660 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1661 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1662 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1663 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1664 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1665 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1666 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1667 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1668 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1669 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1670 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1671 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1675 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1676 if (sec
== (asection
*) NULL
)
1678 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1680 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1683 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1685 /* Let the backend select the howto field and do any other
1686 required processing. */
1687 (*backend
->finish_reloc
) (abfd
, &intern
, rptr
);
1690 bfd_release (abfd
, external_relocs
);
1692 section
->relocation
= internal_relocs
;
1697 /* Get a canonical list of relocs. */
1700 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1708 if (section
->flags
& SEC_CONSTRUCTOR
)
1710 arelent_chain
*chain
;
1712 /* This section has relocs made up by us, not the file, so take
1713 them out of their chain and place them into the data area
1715 for (count
= 0, chain
= section
->constructor_chain
;
1716 count
< section
->reloc_count
;
1717 count
++, chain
= chain
->next
)
1718 *relptr
++ = &chain
->relent
;
1724 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1727 tblptr
= section
->relocation
;
1728 if (tblptr
== (arelent
*) NULL
)
1731 for (count
= 0; count
< section
->reloc_count
; count
++)
1732 *relptr
++ = tblptr
++;
1735 *relptr
= (arelent
*) NULL
;
1737 return section
->reloc_count
;
1740 /* Provided a BFD, a section and an offset into the section, calculate
1741 and return the name of the source file and the line nearest to the
1745 ecoff_find_nearest_line (abfd
,
1754 asymbol
**ignore_symbols
;
1756 CONST
char **filename_ptr
;
1757 CONST
char **functionname_ptr
;
1758 unsigned int *retline_ptr
;
1760 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1765 bfd_size_type external_pdr_size
;
1769 unsigned char *line_ptr
;
1770 unsigned char *line_end
;
1773 /* If we're not in the .text section, we don't have any line
1775 if (strcmp (section
->name
, _TEXT
) != 0
1776 || offset
< ecoff_data (abfd
)->text_start
1777 || offset
>= ecoff_data (abfd
)->text_end
)
1780 /* Make sure we have the FDR's. */
1781 if (ecoff_slurp_symbolic_info (abfd
) == false
1782 || bfd_get_symcount (abfd
) == 0)
1785 /* Each file descriptor (FDR) has a memory address. Here we track
1786 down which FDR we want. The FDR's are stored in increasing
1787 memory order. If speed is ever important, this can become a
1788 binary search. We must ignore FDR's with no PDR entries; they
1789 will have the adr of the FDR before or after them. */
1790 fdr_start
= ecoff_data (abfd
)->fdr
;
1791 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1792 fdr_hold
= (FDR
*) NULL
;
1793 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1795 if (fdr_ptr
->cpd
== 0)
1797 if (offset
< fdr_ptr
->adr
)
1801 if (fdr_hold
== (FDR
*) NULL
)
1805 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1806 have an address, which is relative to the FDR address, and are
1807 also stored in increasing memory order. */
1808 offset
-= fdr_ptr
->adr
;
1809 external_pdr_size
= backend
->external_pdr_size
;
1810 pdr_ptr
= ((char *) ecoff_data (abfd
)->external_pdr
1811 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1812 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1813 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1815 /* The address of the first PDR is an offset which applies to the
1816 addresses of all the PDR's. */
1819 for (pdr_ptr
+= external_pdr_size
;
1821 pdr_ptr
+= external_pdr_size
)
1823 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1824 if (offset
< pdr
.adr
)
1828 /* Now we can look for the actual line number. The line numbers are
1829 stored in a very funky format, which I won't try to describe.
1830 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1831 we want; we need this to compute line_end. */
1832 line_end
= ecoff_data (abfd
)->line
;
1833 if (pdr_ptr
== pdr_end
)
1834 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1836 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1838 /* Now change pdr and pdr_ptr to the one we want. */
1839 pdr_ptr
-= external_pdr_size
;
1840 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1844 line_ptr
= (ecoff_data (abfd
)->line
1845 + fdr_ptr
->cbLineOffset
1846 + pdr
.cbLineOffset
);
1847 while (line_ptr
< line_end
)
1852 delta
= *line_ptr
>> 4;
1855 count
= (*line_ptr
& 0xf) + 1;
1859 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
1860 if (delta
>= 0x8000)
1865 if (offset
< count
* 4)
1867 offset
-= count
* 4;
1870 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
1871 at least according to gdb/mipsread.c. */
1872 if (fdr_ptr
->rss
== -1)
1874 *filename_ptr
= NULL
;
1876 *functionname_ptr
= NULL
;
1881 (*backend
->swap_ext_in
) (abfd
,
1882 ((char *) ecoff_data (abfd
)->external_ext
1883 + pdr
.isym
* backend
->external_ext_size
),
1885 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
1892 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
1893 (*backend
->swap_sym_in
) (abfd
,
1894 ((char *) ecoff_data (abfd
)->external_sym
1895 + ((fdr_ptr
->isymBase
+ pdr
.isym
)
1896 * backend
->external_sym_size
)),
1898 *functionname_ptr
= (ecoff_data (abfd
)->ss
1902 if (lineno
== ilineNil
)
1904 *retline_ptr
= lineno
;
1908 /* We can't use the generic linking routines for ECOFF, because we
1909 have to handle all the debugging information. The generic link
1910 routine just works out the section contents and attaches a list of
1913 We link by looping over all the seclets. We make two passes. On
1914 the first we set the actual section contents and determine the size
1915 of the debugging information. On the second we accumulate the
1916 debugging information and write it out.
1918 This currently always accumulates the debugging information, which
1919 is incorrect, because it ignores the -s and -S options of the
1920 linker. The linker needs to be modified to give us that
1921 information in a more useful format (currently it just provides a
1922 list of symbols which should appear in the output file). */
1924 /* Clear the output_has_begun flag for all the input BFD's. We use it
1925 to avoid linking in the debugging information for a BFD more than
1929 ecoff_clear_output_flags (abfd
)
1932 register asection
*o
;
1933 register bfd_seclet_type
*p
;
1935 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1936 for (p
= o
->seclets_head
;
1937 p
!= (bfd_seclet_type
*) NULL
;
1939 if (p
->type
== bfd_indirect_seclet
)
1940 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
1943 /* Handle an indirect seclet on the first pass. Set the contents of
1944 the output section, and accumulate the debugging information if
1948 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
1950 bfd_seclet_type
*seclet
;
1951 asection
*output_section
;
1953 boolean relocateable
;
1956 HDRR
*output_symhdr
;
1959 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
1960 && !(output_section
->flags
& SEC_NEVER_LOAD
)
1961 && (output_section
->flags
& SEC_LOAD
)
1964 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
1968 if (bfd_set_section_contents (output_bfd
,
1979 input_bfd
= seclet
->u
.indirect
.section
->owner
;
1981 /* We want to figure out how much space will be required to
1982 incorporate all the debugging information from input_bfd. We use
1983 the output_has_begun field to avoid adding it in more than once.
1984 The actual incorporation is done in the second pass, in
1985 ecoff_get_debug. The code has to parallel that code in its
1986 manipulations of output_symhdr. */
1988 if (input_bfd
->output_has_begun
)
1990 input_bfd
->output_has_begun
= true;
1992 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
1994 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2000 /* We just accumulate local symbols from a non-ECOFF BFD. The
2001 external symbols are handled separately. */
2003 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2004 get_symtab_upper_bound (input_bfd
));
2005 if (symbols
== (asymbol
**) NULL
)
2007 bfd_error
= no_memory
;
2010 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2012 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2016 len
= strlen ((*sym_ptr
)->name
);
2017 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2019 ++output_symhdr
->isymMax
;
2020 output_symhdr
->issMax
+= len
+ 1;
2024 bfd_release (output_bfd
, (PTR
) symbols
);
2026 ++output_symhdr
->ifdMax
;
2031 /* We simply add in the information from another ECOFF BFD. First
2032 we make sure we have the symbolic information. */
2033 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2035 if (bfd_get_symcount (input_bfd
) == 0)
2038 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2040 /* Figure out how much information we are going to be putting in.
2041 The external symbols are handled separately. */
2042 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2043 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2044 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2045 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2046 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2047 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2048 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2049 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2050 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2052 /* The RFD's are special, since we create them if needed. */
2053 if (input_symhdr
->crfd
> 0)
2054 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2056 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2061 /* Handle an arbitrary seclet on the first pass. */
2064 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2066 bfd_seclet_type
*seclet
;
2069 boolean relocateable
;
2071 switch (seclet
->type
)
2073 case bfd_indirect_seclet
:
2074 /* The contents of this section come from another one somewhere
2076 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2078 case bfd_fill_seclet
:
2079 /* Fill in the section with fill.value. This is used to pad out
2080 sections, but we must avoid padding the .bss section. */
2081 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2083 if (seclet
->u
.fill
.value
!= 0)
2088 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2092 for (i
= 0; i
< seclet
->size
; i
+=2)
2093 d
[i
] = seclet
->u
.fill
.value
>> 8;
2094 for (i
= 1; i
< seclet
->size
; i
+=2)
2095 d
[i
] = seclet
->u
.fill
.value
;
2096 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2098 bfd_release (abfd
, (PTR
) d
);
2110 /* Add a string to the debugging information we are accumulating for a
2111 file. Return the offset from the fdr string base or from the
2112 external string base. */
2115 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2125 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2126 len
= strlen (string
);
2129 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2130 ret
= symhdr
->issExtMax
;
2131 symhdr
->issExtMax
+= len
+ 1;
2135 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2137 symhdr
->issMax
+= len
+ 1;
2138 fdr
->cbSs
+= len
+ 1;
2143 /* Accumulate the debugging information from an input section. */
2146 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2148 bfd_seclet_type
*seclet
;
2150 boolean relocateable
;
2152 const struct ecoff_backend_data
* const backend
= ecoff_backend (output_bfd
);
2153 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
2154 const bfd_size_type external_pdr_size
= backend
->external_pdr_size
;
2155 const bfd_size_type external_fdr_size
= backend
->external_fdr_size
;
2156 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
2157 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2158 = backend
->swap_sym_in
;
2159 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2160 = backend
->swap_sym_out
;
2161 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2162 = backend
->swap_pdr_in
;
2163 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
2164 = backend
->swap_fdr_out
;
2165 void (* const swap_rfd_out
) PARAMS ((bfd
*, const RFDT
*, PTR
))
2166 = backend
->swap_rfd_out
;
2168 HDRR
*output_symhdr
;
2170 ecoff_data_type
*output_ecoff
;
2171 ecoff_data_type
*input_ecoff
;
2174 ecoff_symbol_type
*esym_ptr
;
2175 ecoff_symbol_type
*esym_end
;
2180 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2182 /* Don't get the information more than once. */
2183 if (input_bfd
->output_has_begun
)
2185 input_bfd
->output_has_begun
= true;
2187 output_ecoff
= ecoff_data (output_bfd
);
2188 output_symhdr
= &output_ecoff
->symbolic_header
;
2190 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2197 /* This is not an ECOFF BFD. Just gather the symbols. */
2199 memset (&fdr
, 0, sizeof fdr
);
2201 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2202 fdr
.issBase
= output_symhdr
->issMax
;
2204 fdr
.rss
= ecoff_add_string (output_bfd
,
2206 bfd_get_filename (input_bfd
),
2208 fdr
.isymBase
= output_symhdr
->isymMax
;
2210 /* Get the local symbols from the input BFD. */
2211 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2212 get_symtab_upper_bound (input_bfd
));
2213 if (symbols
== (asymbol
**) NULL
)
2215 bfd_error
= no_memory
;
2218 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2220 /* Handle the local symbols. Any external symbols are handled
2223 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2227 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2229 memset (&internal_sym
, 0, sizeof internal_sym
);
2230 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2235 if (bfd_is_com_section ((*sym_ptr
)->section
)
2236 || (*sym_ptr
)->section
== &bfd_und_section
)
2237 internal_sym
.value
= (*sym_ptr
)->value
;
2239 internal_sym
.value
= ((*sym_ptr
)->value
2240 + (*sym_ptr
)->section
->output_offset
2241 + (*sym_ptr
)->section
->output_section
->vma
);
2242 internal_sym
.st
= stNil
;
2243 internal_sym
.sc
= scUndefined
;
2244 internal_sym
.index
= indexNil
;
2245 (*swap_sym_out
) (output_bfd
, &internal_sym
,
2246 ((char *) output_ecoff
->external_sym
2247 + output_symhdr
->isymMax
* external_sym_size
));
2249 ++output_symhdr
->isymMax
;
2252 bfd_release (output_bfd
, (PTR
) symbols
);
2254 /* Leave everything else in the FDR zeroed out. This will cause
2255 the lang field to be langC. The fBigendian field will
2256 indicate little endian format, but it doesn't matter because
2257 it only applies to aux fields and there are none. */
2259 (*swap_fdr_out
) (output_bfd
, &fdr
,
2260 ((char *) output_ecoff
->external_fdr
2261 + output_symhdr
->ifdMax
* external_fdr_size
));
2262 ++output_symhdr
->ifdMax
;
2266 /* This is an ECOFF BFD. We want to grab the information from
2267 input_bfd and attach it to output_bfd. */
2268 count
= bfd_get_symcount (input_bfd
);
2271 input_ecoff
= ecoff_data (input_bfd
);
2272 input_symhdr
= &input_ecoff
->symbolic_header
;
2274 /* I think that it is more efficient to simply copy the debugging
2275 information from the input BFD to the output BFD. Because ECOFF
2276 uses relative pointers for most of the debugging information,
2277 only a little of it has to be changed at all. */
2279 /* Swap in the local symbols, adjust their values, and swap them out
2280 again. The external symbols are handled separately. */
2281 sym_out
= ((char *) output_ecoff
->external_sym
2282 + output_symhdr
->isymMax
* external_sym_size
);
2284 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2285 esym_end
= esym_ptr
+ count
;
2286 for (; esym_ptr
< esym_end
; esym_ptr
++)
2288 if (esym_ptr
->local
)
2292 (*swap_sym_in
) (input_bfd
, esym_ptr
->native
, &sym
);
2294 /* If we're producing an executable, move common symbols
2296 if (relocateable
== false)
2298 if (sym
.sc
== scCommon
)
2300 else if (sym
.sc
== scSCommon
)
2304 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2305 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2306 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2307 sym
.value
= (esym_ptr
->symbol
.value
2308 + esym_ptr
->symbol
.section
->output_offset
2309 + esym_ptr
->symbol
.section
->output_section
->vma
);
2310 (*swap_sym_out
) (output_bfd
, &sym
, sym_out
);
2311 sym_out
+= external_sym_size
;
2315 /* That should have accounted for all the local symbols in
2318 /* Copy the information that does not need swapping. */
2319 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2321 input_symhdr
->cbLine
* sizeof (unsigned char));
2322 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2323 input_ecoff
->external_aux
,
2324 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2325 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2327 input_symhdr
->issMax
* sizeof (char));
2329 /* Some of the information may need to be swapped. */
2330 if (output_bfd
->xvec
->header_byteorder_big_p
2331 == input_bfd
->xvec
->header_byteorder_big_p
)
2333 /* The two BFD's have the same endianness, so memcpy will
2335 if (input_symhdr
->idnMax
> 0)
2336 memcpy (((char *) output_ecoff
->external_dnr
2337 + output_symhdr
->idnMax
* backend
->external_dnr_size
),
2338 input_ecoff
->external_dnr
,
2339 input_symhdr
->idnMax
* backend
->external_dnr_size
);
2340 if (input_symhdr
->ipdMax
> 0)
2341 memcpy (((char *) output_ecoff
->external_pdr
2342 + output_symhdr
->ipdMax
* external_pdr_size
),
2343 input_ecoff
->external_pdr
,
2344 input_symhdr
->ipdMax
* external_pdr_size
);
2345 if (input_symhdr
->ioptMax
> 0)
2346 memcpy (((char *) output_ecoff
->external_opt
2347 + output_symhdr
->ioptMax
* backend
->external_opt_size
),
2348 input_ecoff
->external_opt
,
2349 input_symhdr
->ioptMax
* backend
->external_opt_size
);
2358 /* The two BFD's have different endianness, so we must swap
2359 everything in and out. This code would always work, but it
2360 would be slow in the normal case. */
2361 sz
= backend
->external_dnr_size
;
2362 in
= (char *) input_ecoff
->external_dnr
;
2363 end
= in
+ input_symhdr
->idnMax
* sz
;
2364 out
= (char *) output_ecoff
->external_dnr
+ output_symhdr
->idnMax
* sz
;
2365 for (; in
< end
; in
+= sz
, out
+= sz
)
2369 (*backend
->swap_dnr_in
) (input_bfd
, in
, &dnr
);
2370 (*backend
->swap_dnr_out
) (output_bfd
, &dnr
, out
);
2373 sz
= external_pdr_size
;
2374 in
= (char *) input_ecoff
->external_pdr
;
2375 end
= in
+ input_symhdr
->ipdMax
* sz
;
2376 out
= (char *) output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
* sz
;
2377 for (; in
< end
; in
+= sz
, out
+= sz
)
2381 (*swap_pdr_in
) (input_bfd
, in
, &pdr
);
2382 (*backend
->swap_pdr_out
) (output_bfd
, &pdr
, out
);
2385 sz
= backend
->external_opt_size
;
2386 in
= (char *) input_ecoff
->external_opt
;
2387 end
= in
+ input_symhdr
->ioptMax
* sz
;
2388 out
= (char *) output_ecoff
->external_opt
+ output_symhdr
->ioptMax
* sz
;
2389 for (; in
< end
; in
+= sz
, out
+= sz
)
2393 (*backend
->swap_opt_in
) (input_bfd
, in
, &opt
);
2394 (*backend
->swap_opt_out
) (output_bfd
, &opt
, out
);
2398 /* Set ifdbase so that the external symbols know how to adjust their
2400 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2402 fdr_ptr
= input_ecoff
->fdr
;
2403 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2404 fdr_out
= ((char *) output_ecoff
->external_fdr
2405 + output_symhdr
->ifdMax
* external_fdr_size
);
2406 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
+= external_fdr_size
)
2409 unsigned long pdr_off
;
2413 /* The memory address for this fdr is the address for the seclet
2414 plus the offset to this fdr within input_bfd. For some
2415 reason the offset of the first procedure pointer is also
2423 (*swap_pdr_in
) (input_bfd
,
2424 ((char *) input_ecoff
->external_pdr
2425 + fdr
.ipdFirst
* external_pdr_size
),
2429 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2431 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2434 fdr
.issBase
+= output_symhdr
->issMax
;
2435 fdr
.isymBase
+= output_symhdr
->isymMax
;
2436 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2437 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2438 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2439 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2440 fdr
.rfdBase
+= output_symhdr
->crfd
;
2442 /* If there are no RFD's, we are going to add some. We don't
2443 want to adjust irfd for this, so that all the FDR's can share
2445 if (input_symhdr
->crfd
== 0)
2446 fdr
.crfd
= input_symhdr
->ifdMax
;
2448 if (fdr
.cbLine
!= 0)
2449 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2451 (*swap_fdr_out
) (output_bfd
, &fdr
, fdr_out
);
2454 if (input_symhdr
->crfd
> 0)
2456 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2457 = backend
->swap_rfd_in
;
2462 /* Swap and adjust the RFD's. RFD's are only created by the
2463 linker, so this will only be necessary if one of the input
2464 files is the result of a partial link. Presumably all
2465 necessary RFD's are present. */
2466 rfd_in
= (char *) input_ecoff
->external_rfd
;
2467 rfd_end
= rfd_in
+ input_symhdr
->crfd
* external_rfd_size
;
2468 rfd_out
= ((char *) output_ecoff
->external_rfd
2469 + output_symhdr
->crfd
* external_rfd_size
);
2472 rfd_in
+= external_rfd_size
, rfd_out
+= external_rfd_size
)
2476 (*swap_rfd_in
) (input_bfd
, rfd_in
, &rfd
);
2477 rfd
+= output_symhdr
->ifdMax
;
2478 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2480 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2488 /* Create RFD's. Some of the debugging information includes
2489 relative file indices. These indices are taken as indices to
2490 the RFD table if there is one, or to the global table if
2491 there is not. If we did not create RFD's, we would have to
2492 parse and adjust all the debugging information which contains
2494 rfd
= output_symhdr
->ifdMax
;
2495 rfd_out
= ((char *) output_ecoff
->external_rfd
2496 + output_symhdr
->crfd
* external_rfd_size
);
2497 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
* external_rfd_size
;
2498 for (; rfd_out
< rfd_end
; rfd_out
+= external_rfd_size
, rfd
++)
2499 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2500 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2503 /* Combine the register masks. Not all of these are used on all
2504 targets, but that's OK because only the relevant ones will be
2505 swapped in and out. */
2509 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2510 output_ecoff
->fprmask
|= input_ecoff
->fprmask
;
2511 for (i
= 0; i
< 4; i
++)
2512 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2515 /* Update the counts. */
2516 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2517 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2518 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2519 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2520 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2521 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2522 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2523 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2524 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2529 /* This is the actual link routine. It makes two passes over all the
2533 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2536 boolean relocateable
;
2538 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2541 register asection
*o
;
2542 register bfd_seclet_type
*p
;
2543 asymbol
**sym_ptr_ptr
;
2544 bfd_size_type debug_align
;
2548 /* We accumulate the debugging information counts in the symbolic
2550 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2551 symhdr
->magic
= backend
->sym_magic
;
2552 /* FIXME: What should the version stamp be? */
2554 symhdr
->ilineMax
= 0;
2558 symhdr
->isymMax
= 0;
2559 symhdr
->ioptMax
= 0;
2560 symhdr
->iauxMax
= 0;
2562 symhdr
->issExtMax
= 0;
2565 symhdr
->iextMax
= 0;
2567 /* We need to copy over the debugging symbols from each input BFD.
2568 When we do this copying, we have to adjust the text address in
2569 the FDR structures, so we have to know the text address used for
2570 the input BFD. Since we only want to copy the symbols once per
2571 input BFD, but we are going to look at each input BFD multiple
2572 times (once for each section it provides), we arrange to always
2573 look at the text section first. That means that when we copy the
2574 debugging information, we always know the text address. So we
2575 actually do each pass in two sub passes; first the text sections,
2576 then the non-text sections. We use the output_has_begun flag to
2577 determine whether we have copied over the debugging information
2580 /* Do the first pass: set the output section contents and count the
2581 debugging information. */
2582 ecoff_clear_output_flags (abfd
);
2583 for (ipass
= 0; ipass
< 2; ipass
++)
2585 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2587 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2588 so they are done on pass 0. For other sections the
2589 expression is true, so they are done on pass 1. */
2590 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2593 for (p
= o
->seclets_head
;
2594 p
!= (bfd_seclet_type
*) NULL
;
2597 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2604 /* We handle the external symbols differently. We use the ones
2605 attached to the output_bfd. The linker will have already
2606 determined which symbols are to be attached. Here we just
2607 determine how much space we will need for them. */
2608 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2609 if (sym_ptr_ptr
!= NULL
)
2613 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2614 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2616 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2617 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2620 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2625 /* Adjust the counts so that structures are longword aligned. */
2626 debug_align
= backend
->debug_align
;
2628 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2629 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2630 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2632 /* Now the counts in symhdr are the correct size for the debugging
2633 information. We allocate the right amount of space, and reset
2634 the counts so that the second pass can use them as indices. It
2635 would be possible to output the debugging information directly to
2636 the file in pass 2, rather than to build it in memory and then
2637 write it out. Outputting to the file would require a lot of
2638 seeks and small writes, though, and I think this approach is
2640 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2641 + symhdr
->idnMax
* backend
->external_dnr_size
2642 + symhdr
->ipdMax
* backend
->external_pdr_size
2643 + symhdr
->isymMax
* backend
->external_sym_size
2644 + symhdr
->ioptMax
* backend
->external_opt_size
2645 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2646 + symhdr
->issMax
* sizeof (char)
2647 + symhdr
->issExtMax
* sizeof (char)
2648 + symhdr
->ifdMax
* backend
->external_fdr_size
2649 + symhdr
->crfd
* backend
->external_rfd_size
2650 + symhdr
->iextMax
* backend
->external_ext_size
);
2651 raw
= (char *) bfd_alloc (abfd
, size
);
2652 if (raw
== (char *) NULL
)
2654 bfd_error
= no_memory
;
2657 ecoff_data (abfd
)->raw_size
= size
;
2658 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2660 /* Initialize the raw pointers. */
2661 #define SET(field, count, type, size) \
2662 ecoff_data (abfd)->field = (type) raw; \
2663 raw += symhdr->count * size
2665 SET (line
, cbLine
, unsigned char *, sizeof (unsigned char));
2666 SET (external_dnr
, idnMax
, PTR
, backend
->external_dnr_size
);
2667 SET (external_pdr
, ipdMax
, PTR
, backend
->external_pdr_size
);
2668 SET (external_sym
, isymMax
, PTR
, backend
->external_sym_size
);
2669 SET (external_opt
, ioptMax
, PTR
, backend
->external_opt_size
);
2670 SET (external_aux
, iauxMax
, union aux_ext
*, sizeof (union aux_ext
));
2671 SET (ss
, issMax
, char *, sizeof (char));
2672 SET (ssext
, issExtMax
, char *, sizeof (char));
2673 SET (external_fdr
, ifdMax
, PTR
, backend
->external_fdr_size
);
2674 SET (external_rfd
, crfd
, PTR
, backend
->external_rfd_size
);
2675 SET (external_ext
, iextMax
, PTR
, backend
->external_ext_size
);
2678 /* Reset the counts so the second pass can use them to know how far
2680 symhdr
->ilineMax
= 0;
2684 symhdr
->isymMax
= 0;
2685 symhdr
->ioptMax
= 0;
2686 symhdr
->iauxMax
= 0;
2688 symhdr
->issExtMax
= 0;
2691 symhdr
->iextMax
= 0;
2693 /* Do the second pass: accumulate the debugging information. */
2694 ecoff_clear_output_flags (abfd
);
2695 for (ipass
= 0; ipass
< 2; ipass
++)
2697 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2699 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2701 for (p
= o
->seclets_head
;
2702 p
!= (bfd_seclet_type
*) NULL
;
2705 if (p
->type
== bfd_indirect_seclet
)
2707 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
2714 /* Put in the external symbols. */
2715 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2716 if (sym_ptr_ptr
!= NULL
)
2718 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
2719 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
2720 = backend
->swap_ext_in
;
2721 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
2722 = backend
->swap_ext_out
;
2726 ssext
= ecoff_data (abfd
)->ssext
;
2727 external_ext
= (char *) ecoff_data (abfd
)->external_ext
;
2728 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2733 sym_ptr
= *sym_ptr_ptr
;
2735 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2736 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2739 /* The native pointer can be NULL for a symbol created by
2740 the linker via ecoff_make_empty_symbol. */
2741 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2742 || ecoffsymbol (sym_ptr
)->native
== NULL
)
2745 esym
.cobol_main
= 0;
2749 /* FIXME: we can do better than this for st and sc. */
2750 esym
.asym
.st
= stGlobal
;
2751 esym
.asym
.sc
= scAbs
;
2752 esym
.asym
.reserved
= 0;
2753 esym
.asym
.index
= indexNil
;
2757 ecoff_symbol_type
*ecoff_sym_ptr
;
2759 ecoff_sym_ptr
= ecoffsymbol (sym_ptr
);
2760 if (ecoff_sym_ptr
->local
)
2762 (*swap_ext_in
) (abfd
, ecoff_sym_ptr
->native
, &esym
);
2764 /* If we're producing an executable, move common symbols
2766 if (relocateable
== false)
2768 if (esym
.asym
.sc
== scCommon
)
2769 esym
.asym
.sc
= scBss
;
2770 else if (esym
.asym
.sc
== scSCommon
)
2771 esym
.asym
.sc
= scSBss
;
2774 /* Adjust the FDR index for the symbol by that used for
2776 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2779 esym
.asym
.iss
= symhdr
->issExtMax
;
2781 if (bfd_is_com_section (sym_ptr
->section
)
2782 || sym_ptr
->section
== &bfd_und_section
)
2783 esym
.asym
.value
= sym_ptr
->value
;
2785 esym
.asym
.value
= (sym_ptr
->value
2786 + sym_ptr
->section
->output_offset
2787 + sym_ptr
->section
->output_section
->vma
);
2789 (*swap_ext_out
) (abfd
, &esym
, external_ext
);
2791 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2793 external_ext
+= external_ext_size
;
2796 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2797 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2801 /* Adjust the counts so that structures are longword aligned. */
2802 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2803 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2804 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2809 /* Set the architecture. The supported architecture is stored in the
2810 backend pointer. We always set the architecture anyhow, since many
2811 callers ignore the return value. */
2814 ecoff_set_arch_mach (abfd
, arch
, machine
)
2816 enum bfd_architecture arch
;
2817 unsigned long machine
;
2819 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2820 return arch
== ecoff_backend (abfd
)->arch
;
2823 /* Get the size of the section headers. We do not output the .scommon
2824 section which we created in ecoff_mkobject. */
2827 ecoff_sizeof_headers (abfd
, reloc
)
2831 return (bfd_coff_filhsz (abfd
)
2832 + bfd_coff_aoutsz (abfd
)
2833 + (abfd
->section_count
- 1) * bfd_coff_scnhsz (abfd
));
2836 /* Calculate the file position for each section, and set
2840 ecoff_compute_section_file_positions (abfd
)
2848 if (bfd_get_start_address (abfd
))
2849 abfd
->flags
|= EXEC_P
;
2851 sofar
= ecoff_sizeof_headers (abfd
, false);
2854 for (current
= abfd
->sections
;
2855 current
!= (asection
*) NULL
;
2856 current
= current
->next
)
2858 /* Only deal with sections which have contents */
2859 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2860 || strcmp (current
->name
, SCOMMON
) == 0)
2863 /* On Ultrix, the data sections in an executable file must be
2864 aligned to a page boundary within the file. This does not
2865 affect the section size, though. FIXME: Does this work for
2867 if ((abfd
->flags
& EXEC_P
) != 0
2868 && (abfd
->flags
& D_PAGED
) != 0
2869 && first_data
!= false
2870 && (current
->flags
& SEC_CODE
) == 0)
2872 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2874 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2878 /* Align the sections in the file to the same boundary on
2879 which they are aligned in virtual memory. */
2881 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2883 current
->filepos
= sofar
;
2885 sofar
+= current
->_raw_size
;
2887 /* make sure that this section is of the right size too */
2889 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2890 current
->_raw_size
+= sofar
- old_sofar
;
2893 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2896 /* Set the contents of a section. */
2899 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2904 bfd_size_type count
;
2906 if (abfd
->output_has_begun
== false)
2907 ecoff_compute_section_file_positions (abfd
);
2909 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
2912 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
2917 /* Write out an ECOFF file. */
2920 ecoff_write_object_contents (abfd
)
2923 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2924 const bfd_vma round
= backend
->round
;
2925 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2926 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2927 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2928 const bfd_size_type external_hdr_size
= backend
->external_hdr_size
;
2929 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2930 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2931 const struct internal_reloc
*,
2933 = backend
->swap_reloc_out
;
2937 file_ptr reloc_base
;
2939 unsigned long reloc_size
;
2940 unsigned long text_size
;
2941 unsigned long text_start
;
2942 unsigned long data_size
;
2943 unsigned long data_start
;
2944 unsigned long bss_size
;
2946 struct internal_filehdr internal_f
;
2947 struct internal_aouthdr internal_a
;
2950 bfd_error
= system_call_error
;
2952 if(abfd
->output_has_begun
== false)
2953 ecoff_compute_section_file_positions(abfd
);
2955 if (abfd
->sections
!= (asection
*) NULL
)
2956 scn_base
= abfd
->sections
->filepos
;
2959 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2963 for (current
= abfd
->sections
;
2964 current
!= (asection
*)NULL
;
2965 current
= current
->next
)
2967 if (strcmp (current
->name
, SCOMMON
) == 0)
2969 current
->target_index
= count
;
2971 if (current
->reloc_count
!= 0)
2973 bfd_size_type relsize
;
2975 current
->rel_filepos
= reloc_base
;
2976 relsize
= current
->reloc_count
* external_reloc_size
;
2977 reloc_size
+= relsize
;
2978 reloc_base
+= relsize
;
2981 current
->rel_filepos
= 0;
2984 sym_base
= reloc_base
+ reloc_size
;
2986 /* At least on Ultrix, the symbol table of an executable file must
2987 be aligned to a page boundary. FIXME: Is this true on other
2989 if ((abfd
->flags
& EXEC_P
) != 0
2990 && (abfd
->flags
& D_PAGED
) != 0)
2991 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
2993 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2995 if ((abfd
->flags
& D_PAGED
) != 0)
2996 text_size
= ecoff_sizeof_headers (abfd
, false);
3004 /* Write section headers to the file. */
3006 buff
= (PTR
) alloca (scnhsz
);
3007 internal_f
.f_nscns
= 0;
3008 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
3010 for (current
= abfd
->sections
;
3011 current
!= (asection
*) NULL
;
3012 current
= current
->next
)
3014 struct internal_scnhdr section
;
3017 if (strcmp (current
->name
, SCOMMON
) == 0)
3019 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3020 && current
->reloc_count
== 0);
3024 ++internal_f
.f_nscns
;
3026 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3028 /* FIXME: is this correct for shared libraries? I think it is
3029 but I have no platform to check. Ian Lance Taylor. */
3030 vma
= bfd_get_section_vma (abfd
, current
);
3031 if (strcmp (current
->name
, _LIB
) == 0)
3032 section
.s_vaddr
= 0;
3034 section
.s_vaddr
= vma
;
3036 section
.s_paddr
= vma
;
3037 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3039 /* If this section is unloadable then the scnptr will be 0. */
3040 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3041 section
.s_scnptr
= 0;
3043 section
.s_scnptr
= current
->filepos
;
3044 section
.s_relptr
= current
->rel_filepos
;
3046 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3047 object file produced by the assembler is supposed to point to
3048 information about how much room is required by objects of
3049 various different sizes. I think this only matters if we
3050 want the linker to compute the best size to use, or
3051 something. I don't know what happens if the information is
3053 section
.s_lnnoptr
= 0;
3055 section
.s_nreloc
= current
->reloc_count
;
3056 section
.s_nlnno
= 0;
3057 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3060 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
3061 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
3064 if ((section
.s_flags
& STYP_TEXT
) != 0)
3066 text_size
+= bfd_get_section_size_before_reloc (current
);
3067 if (text_start
== 0 || text_start
> vma
)
3070 else if ((section
.s_flags
& STYP_RDATA
) != 0
3071 || (section
.s_flags
& STYP_DATA
) != 0
3072 || (section
.s_flags
& STYP_LIT8
) != 0
3073 || (section
.s_flags
& STYP_LIT4
) != 0
3074 || (section
.s_flags
& STYP_SDATA
) != 0)
3076 data_size
+= bfd_get_section_size_before_reloc (current
);
3077 if (data_start
== 0 || data_start
> vma
)
3080 else if ((section
.s_flags
& STYP_BSS
) != 0
3081 || (section
.s_flags
& STYP_SBSS
) != 0)
3082 bss_size
+= bfd_get_section_size_before_reloc (current
);
3085 /* Set up the file header. */
3087 if (abfd
->xvec
->header_byteorder_big_p
!= false)
3088 internal_f
.f_magic
= backend
->big_magic
;
3090 internal_f
.f_magic
= backend
->little_magic
;
3092 /* We will NOT put a fucking timestamp in the header here. Every
3093 time you put it back, I will come in and take it out again. I'm
3094 sorry. This field does not belong here. We fill it with a 0 so
3095 it compares the same but is not a reasonable time. --
3097 internal_f
.f_timdat
= 0;
3099 if (bfd_get_symcount (abfd
) != 0)
3101 /* The ECOFF f_nsyms field is not actually the number of
3102 symbols, it's the size of symbolic information header. */
3103 internal_f
.f_nsyms
= external_hdr_size
;
3104 internal_f
.f_symptr
= sym_base
;
3108 internal_f
.f_nsyms
= 0;
3109 internal_f
.f_symptr
= 0;
3112 internal_f
.f_opthdr
= aoutsz
;
3114 internal_f
.f_flags
= F_LNNO
;
3115 if (reloc_size
== 0)
3116 internal_f
.f_flags
|= F_RELFLG
;
3117 if (bfd_get_symcount (abfd
) == 0)
3118 internal_f
.f_flags
|= F_LSYMS
;
3119 if (abfd
->flags
& EXEC_P
)
3120 internal_f
.f_flags
|= F_EXEC
;
3122 if (! abfd
->xvec
->byteorder_big_p
)
3123 internal_f
.f_flags
|= F_AR32WR
;
3125 internal_f
.f_flags
|= F_AR32W
;
3127 /* Set up the ``optional'' header. */
3128 if ((abfd
->flags
& D_PAGED
) != 0)
3129 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
3131 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
3133 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3134 linker happy. But, is it right? */
3135 internal_a
.vstamp
= 0x20a;
3137 /* At least on Ultrix, these have to be rounded to page boundaries.
3138 FIXME: Is this true on other platforms? */
3139 if ((abfd
->flags
& D_PAGED
) != 0)
3141 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
3142 internal_a
.text_start
= text_start
&~ (round
- 1);
3143 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
3144 internal_a
.data_start
= data_start
&~ (round
- 1);
3148 internal_a
.tsize
= text_size
;
3149 internal_a
.text_start
= text_start
;
3150 internal_a
.dsize
= data_size
;
3151 internal_a
.data_start
= data_start
;
3154 /* On Ultrix, the initial portions of the .sbss and .bss segments
3155 are at the end of the data section. The bsize field in the
3156 optional header records how many bss bytes are required beyond
3157 those in the data section. The value is not rounded to a page
3159 if (bss_size
< internal_a
.dsize
- data_size
)
3162 bss_size
-= internal_a
.dsize
- data_size
;
3163 internal_a
.bsize
= bss_size
;
3164 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3166 internal_a
.entry
= bfd_get_start_address (abfd
);
3168 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3170 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3171 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
3172 for (i
= 0; i
< 4; i
++)
3173 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3175 /* Write out the file header and the optional header. */
3177 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3180 buff
= (PTR
) alloca (filhsz
);
3181 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
3182 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
3185 buff
= (PTR
) alloca (aoutsz
);
3186 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
3187 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
3190 /* Write out the relocs. */
3191 for (current
= abfd
->sections
;
3192 current
!= (asection
*) NULL
;
3193 current
= current
->next
)
3195 arelent
**reloc_ptr_ptr
;
3196 arelent
**reloc_end
;
3199 if (current
->reloc_count
== 0)
3202 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
3205 bfd_error
= no_memory
;
3209 reloc_ptr_ptr
= current
->orelocation
;
3210 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3211 out_ptr
= (char *) buff
;
3213 reloc_ptr_ptr
< reloc_end
;
3214 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
3218 struct internal_reloc in
;
3220 memset (&in
, 0, sizeof in
);
3222 reloc
= *reloc_ptr_ptr
;
3223 sym
= *reloc
->sym_ptr_ptr
;
3225 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3226 in
.r_type
= reloc
->howto
->type
;
3228 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3230 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3237 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3238 if (strcmp (name
, ".text") == 0)
3239 in
.r_symndx
= RELOC_SECTION_TEXT
;
3240 else if (strcmp (name
, ".rdata") == 0)
3241 in
.r_symndx
= RELOC_SECTION_RDATA
;
3242 else if (strcmp (name
, ".data") == 0)
3243 in
.r_symndx
= RELOC_SECTION_DATA
;
3244 else if (strcmp (name
, ".sdata") == 0)
3245 in
.r_symndx
= RELOC_SECTION_SDATA
;
3246 else if (strcmp (name
, ".sbss") == 0)
3247 in
.r_symndx
= RELOC_SECTION_SBSS
;
3248 else if (strcmp (name
, ".bss") == 0)
3249 in
.r_symndx
= RELOC_SECTION_BSS
;
3250 else if (strcmp (name
, ".init") == 0)
3251 in
.r_symndx
= RELOC_SECTION_INIT
;
3252 else if (strcmp (name
, ".lit8") == 0)
3253 in
.r_symndx
= RELOC_SECTION_LIT8
;
3254 else if (strcmp (name
, ".lit4") == 0)
3255 in
.r_symndx
= RELOC_SECTION_LIT4
;
3261 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3264 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3266 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
3267 != external_reloc_size
* current
->reloc_count
)
3269 bfd_release (abfd
, buff
);
3272 /* Write out the symbolic debugging information. */
3273 if (bfd_get_symcount (abfd
) > 0)
3276 unsigned long sym_offset
;
3278 /* Set up the offsets in the symbolic header. */
3279 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3280 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
3282 #define SET(offset, size, ptr) \
3283 if (symhdr->size == 0) \
3284 symhdr->offset = 0; \
3286 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3287 - (char *) ecoff_data (abfd)->raw_syments) \
3290 SET (cbLineOffset
, cbLine
, line
);
3291 SET (cbDnOffset
, idnMax
, external_dnr
);
3292 SET (cbPdOffset
, ipdMax
, external_pdr
);
3293 SET (cbSymOffset
, isymMax
, external_sym
);
3294 SET (cbOptOffset
, ioptMax
, external_opt
);
3295 SET (cbAuxOffset
, iauxMax
, external_aux
);
3296 SET (cbSsOffset
, issMax
, ss
);
3297 SET (cbSsExtOffset
, issExtMax
, ssext
);
3298 SET (cbFdOffset
, ifdMax
, external_fdr
);
3299 SET (cbRfdOffset
, crfd
, external_rfd
);
3300 SET (cbExtOffset
, iextMax
, external_ext
);
3303 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3306 buff
= (PTR
) alloca (external_hdr_size
);
3307 (*backend
->swap_hdr_out
) (abfd
, &ecoff_data (abfd
)->symbolic_header
,
3309 if (bfd_write (buff
, 1, external_hdr_size
, abfd
) != external_hdr_size
)
3311 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3312 ecoff_data (abfd
)->raw_size
, abfd
)
3313 != ecoff_data (abfd
)->raw_size
)
3316 else if ((abfd
->flags
& EXEC_P
) != 0
3317 && (abfd
->flags
& D_PAGED
) != 0)
3321 /* A demand paged executable must occupy an even number of
3323 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3326 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3328 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3331 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3338 /* Archive handling. ECOFF uses what appears to be a unique type of
3339 archive header (which I call an armap). The byte ordering of the
3340 armap and the contents are encoded in the name of the armap itself.
3341 At least for now, we only support archives with the same byte
3342 ordering in the armap and the contents.
3344 The first four bytes in the armap are the number of symbol
3345 definitions. This is always a power of two.
3347 This is followed by the symbol definitions. Each symbol definition
3348 occupies 8 bytes. The first four bytes are the offset from the
3349 start of the armap strings to the null-terminated string naming
3350 this symbol. The second four bytes are the file offset to the
3351 archive member which defines this symbol. If the second four bytes
3352 are 0, then this is not actually a symbol definition, and it should
3355 The symbols are hashed into the armap with a closed hashing scheme.
3356 See the functions below for the details of the algorithm.
3358 We could use the hash table when looking up symbols in a library.
3359 This would require a new BFD target entry point to replace the
3360 bfd_get_next_mapent function used by the linker.
3362 After the symbol definitions comes four bytes holding the size of
3363 the string table, followed by the string table itself. */
3365 /* The name of an archive headers looks like this:
3366 __________E[BL]E[BL]_ (with a trailing space).
3367 The trailing space is changed to an X if the archive is changed to
3368 indicate that the armap is out of date.
3370 The Alpha seems to use ________64E[BL]E[BL]_. */
3372 #define ARMAP_BIG_ENDIAN 'B'
3373 #define ARMAP_LITTLE_ENDIAN 'L'
3374 #define ARMAP_MARKER 'E'
3375 #define ARMAP_START_LENGTH 10
3376 #define ARMAP_HEADER_MARKER_INDEX 10
3377 #define ARMAP_HEADER_ENDIAN_INDEX 11
3378 #define ARMAP_OBJECT_MARKER_INDEX 12
3379 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3380 #define ARMAP_END_INDEX 14
3381 #define ARMAP_END "_ "
3383 /* This is a magic number used in the hashing algorithm. */
3384 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3386 /* This returns the hash value to use for a string. It also sets
3387 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3388 is the number of entries in the hash table, and HLOG is the log
3392 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3394 unsigned int *rehash
;
3402 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3403 hash
*= ARMAP_HASH_MAGIC
;
3404 *rehash
= (hash
& (size
- 1)) | 1;
3405 return hash
>> (32 - hlog
);
3408 /* Read in the armap. */
3411 ecoff_slurp_armap (abfd
)
3416 struct areltdata
*mapdata
;
3417 bfd_size_type parsed_size
;
3419 struct artdata
*ardata
;
3422 struct symdef
*symdef_ptr
;
3425 /* Get the name of the first element. */
3426 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3432 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3434 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3435 standard COFF armap. We could move the ECOFF armap stuff into
3436 bfd_slurp_armap, but that seems inappropriate since no other
3437 target uses this format. Instead, we check directly for a COFF
3439 if (strncmp (nextname
, "/ ", 16) == 0)
3440 return bfd_slurp_armap (abfd
);
3442 /* See if the first element is an armap. */
3443 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3444 ARMAP_START_LENGTH
) != 0
3445 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3446 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3447 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3448 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3449 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3450 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3451 || strncmp (nextname
+ ARMAP_END_INDEX
,
3452 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3454 bfd_has_map (abfd
) = false;
3458 /* Make sure we have the right byte ordering. */
3459 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3460 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3461 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3462 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3464 bfd_error
= wrong_format
;
3468 /* Read in the armap. */
3469 ardata
= bfd_ardata (abfd
);
3470 mapdata
= snarf_ar_hdr (abfd
);
3471 if (mapdata
== (struct areltdata
*) NULL
)
3473 parsed_size
= mapdata
->parsed_size
;
3474 bfd_release (abfd
, (PTR
) mapdata
);
3476 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3477 if (raw_armap
== (char *) NULL
)
3479 bfd_error
= no_memory
;
3483 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3485 bfd_error
= malformed_archive
;
3486 bfd_release (abfd
, (PTR
) raw_armap
);
3490 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3492 ardata
->symdef_count
= 0;
3493 ardata
->cache
= (struct ar_cache
*) NULL
;
3495 /* This code used to overlay the symdefs over the raw archive data,
3496 but that doesn't work on a 64 bit host. */
3498 stringbase
= raw_armap
+ count
* 8 + 8;
3500 #ifdef CHECK_ARMAP_HASH
3504 /* Double check that I have the hashing algorithm right by making
3505 sure that every symbol can be looked up successfully. */
3507 for (i
= 1; i
< count
; i
<<= 1)
3509 BFD_ASSERT (i
== count
);
3511 raw_ptr
= raw_armap
+ 4;
3512 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3514 unsigned int name_offset
, file_offset
;
3515 unsigned int hash
, rehash
, srch
;
3517 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3518 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3519 if (file_offset
== 0)
3521 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3526 /* See if we can rehash to this location. */
3527 for (srch
= (hash
+ rehash
) & (count
- 1);
3528 srch
!= hash
&& srch
!= i
;
3529 srch
= (srch
+ rehash
) & (count
- 1))
3530 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
3532 BFD_ASSERT (srch
== i
);
3536 #endif /* CHECK_ARMAP_HASH */
3538 raw_ptr
= raw_armap
+ 4;
3539 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3540 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3541 ++ardata
->symdef_count
;
3543 symdef_ptr
= ((struct symdef
*)
3545 ardata
->symdef_count
* sizeof (struct symdef
)));
3546 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3548 raw_ptr
= raw_armap
+ 4;
3549 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3551 unsigned int name_offset
, file_offset
;
3553 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3554 if (file_offset
== 0)
3556 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3557 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3558 symdef_ptr
->file_offset
= file_offset
;
3562 ardata
->first_file_filepos
= bfd_tell (abfd
);
3563 /* Pad to an even boundary. */
3564 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3566 bfd_has_map (abfd
) = true;
3571 /* Write out an armap. */
3574 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3576 unsigned int elength
;
3578 unsigned int orl_count
;
3581 unsigned int hashsize
, hashlog
;
3582 unsigned int symdefsize
;
3584 unsigned int stringsize
;
3585 unsigned int mapsize
;
3588 struct stat statbuf
;
3591 bfd_byte
*hashtable
;
3595 /* Ultrix appears to use as a hash table size the least power of two
3596 greater than twice the number of entries. */
3597 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3599 hashsize
= 1 << hashlog
;
3601 symdefsize
= hashsize
* 8;
3603 stringsize
= stridx
+ padit
;
3605 /* Include 8 bytes to store symdefsize and stringsize in output. */
3606 mapsize
= symdefsize
+ stringsize
+ 8;
3608 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3610 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3612 /* Work out the ECOFF armap name. */
3613 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3614 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3615 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3616 (abfd
->xvec
->header_byteorder_big_p
3618 : ARMAP_LITTLE_ENDIAN
);
3619 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3620 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3621 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3622 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3624 /* Write the timestamp of the archive header to be just a little bit
3625 later than the timestamp of the file, otherwise the linker will
3626 complain that the index is out of date. Actually, the Ultrix
3627 linker just checks the archive name; the GNU linker may check the
3629 stat (abfd
->filename
, &statbuf
);
3630 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3632 /* The DECstation uses zeroes for the uid, gid and mode of the
3634 hdr
.ar_uid
[0] = '0';
3635 hdr
.ar_gid
[0] = '0';
3636 hdr
.ar_mode
[0] = '0';
3638 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3640 hdr
.ar_fmag
[0] = '`';
3641 hdr
.ar_fmag
[1] = '\n';
3643 /* Turn all null bytes in the header into spaces. */
3644 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3645 if (((char *)(&hdr
))[i
] == '\0')
3646 (((char *)(&hdr
))[i
]) = ' ';
3648 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3649 != sizeof (struct ar_hdr
))
3652 bfd_h_put_32 (abfd
, hashsize
, temp
);
3653 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3656 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3658 current
= abfd
->archive_head
;
3660 for (i
= 0; i
< orl_count
; i
++)
3662 unsigned int hash
, rehash
;
3664 /* Advance firstreal to the file position of this archive
3666 if (((bfd
*) map
[i
].pos
) != last_elt
)
3670 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3671 firstreal
+= firstreal
% 2;
3672 current
= current
->next
;
3674 while (current
!= (bfd
*) map
[i
].pos
);
3679 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3680 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3684 /* The desired slot is already taken. */
3685 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3687 srch
= (srch
+ rehash
) & (hashsize
- 1))
3688 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3691 BFD_ASSERT (srch
!= hash
);
3696 bfd_h_put_32 (abfd
, map
[i
].namidx
, (PTR
) (hashtable
+ hash
* 8));
3697 bfd_h_put_32 (abfd
, firstreal
, (PTR
) (hashtable
+ hash
* 8 + 4));
3700 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3703 bfd_release (abfd
, hashtable
);
3705 /* Now write the strings. */
3706 bfd_h_put_32 (abfd
, stringsize
, temp
);
3707 if (bfd_write (temp
, 1, 4, abfd
) != 4)
3709 for (i
= 0; i
< orl_count
; i
++)
3713 len
= strlen (*map
[i
].name
) + 1;
3714 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3718 /* The spec sez this should be a newline. But in order to be
3719 bug-compatible for DECstation ar we use a null. */
3722 if (bfd_write ("\0", 1, 1, abfd
) != 1)
3729 /* See whether this BFD is an archive. If it is, read in the armap
3730 and the extended name table. */
3733 ecoff_archive_p (abfd
)
3736 char armag
[SARMAG
+ 1];
3738 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3739 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3741 bfd_error
= wrong_format
;
3742 return (bfd_target
*) NULL
;
3745 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3746 involves a cast, we can't do it as the left operand of
3748 abfd
->tdata
.aout_ar_data
=
3749 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3751 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3753 bfd_error
= no_memory
;
3754 return (bfd_target
*) NULL
;
3757 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3759 if (ecoff_slurp_armap (abfd
) == false
3760 || ecoff_slurp_extended_name_table (abfd
) == false)
3762 bfd_release (abfd
, bfd_ardata (abfd
));
3763 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3764 return (bfd_target
*) NULL
;