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
;
1648 CONST
char *sec_name
;
1651 /* r_symndx is a section key. */
1652 switch (intern
.r_symndx
)
1654 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1655 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1656 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1657 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1658 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1659 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1660 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1661 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1662 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1663 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1664 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1665 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1666 case RELOC_SECTION_ABS
: sec_name
= ".abs"; break;
1670 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1671 if (sec
== (asection
*) NULL
)
1672 sec
= bfd_make_section (abfd
, sec_name
);
1673 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1675 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1678 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1680 /* Let the backend select the howto field and do any other
1681 required processing. */
1682 (*backend
->finish_reloc
) (abfd
, &intern
, rptr
);
1685 bfd_release (abfd
, external_relocs
);
1687 section
->relocation
= internal_relocs
;
1692 /* Get a canonical list of relocs. */
1695 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1703 if (section
->flags
& SEC_CONSTRUCTOR
)
1705 arelent_chain
*chain
;
1707 /* This section has relocs made up by us, not the file, so take
1708 them out of their chain and place them into the data area
1710 for (count
= 0, chain
= section
->constructor_chain
;
1711 count
< section
->reloc_count
;
1712 count
++, chain
= chain
->next
)
1713 *relptr
++ = &chain
->relent
;
1719 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1722 tblptr
= section
->relocation
;
1723 if (tblptr
== (arelent
*) NULL
)
1726 for (count
= 0; count
< section
->reloc_count
; count
++)
1727 *relptr
++ = tblptr
++;
1730 *relptr
= (arelent
*) NULL
;
1732 return section
->reloc_count
;
1735 /* Provided a BFD, a section and an offset into the section, calculate
1736 and return the name of the source file and the line nearest to the
1740 ecoff_find_nearest_line (abfd
,
1749 asymbol
**ignore_symbols
;
1751 CONST
char **filename_ptr
;
1752 CONST
char **functionname_ptr
;
1753 unsigned int *retline_ptr
;
1755 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1760 bfd_size_type external_pdr_size
;
1764 unsigned char *line_ptr
;
1765 unsigned char *line_end
;
1768 /* If we're not in the .text section, we don't have any line
1770 if (strcmp (section
->name
, _TEXT
) != 0
1771 || offset
< ecoff_data (abfd
)->text_start
1772 || offset
>= ecoff_data (abfd
)->text_end
)
1775 /* Make sure we have the FDR's. */
1776 if (ecoff_slurp_symbolic_info (abfd
) == false
1777 || bfd_get_symcount (abfd
) == 0)
1780 /* Each file descriptor (FDR) has a memory address. Here we track
1781 down which FDR we want. The FDR's are stored in increasing
1782 memory order. If speed is ever important, this can become a
1783 binary search. We must ignore FDR's with no PDR entries; they
1784 will have the adr of the FDR before or after them. */
1785 fdr_start
= ecoff_data (abfd
)->fdr
;
1786 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1787 fdr_hold
= (FDR
*) NULL
;
1788 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1790 if (fdr_ptr
->cpd
== 0)
1792 if (offset
< fdr_ptr
->adr
)
1796 if (fdr_hold
== (FDR
*) NULL
)
1800 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1801 have an address, which is relative to the FDR address, and are
1802 also stored in increasing memory order. */
1803 offset
-= fdr_ptr
->adr
;
1804 external_pdr_size
= backend
->external_pdr_size
;
1805 pdr_ptr
= ((char *) ecoff_data (abfd
)->external_pdr
1806 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1807 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1808 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1810 /* The address of the first PDR is an offset which applies to the
1811 addresses of all the PDR's. */
1814 for (pdr_ptr
+= external_pdr_size
;
1816 pdr_ptr
+= external_pdr_size
)
1818 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1819 if (offset
< pdr
.adr
)
1823 /* Now we can look for the actual line number. The line numbers are
1824 stored in a very funky format, which I won't try to describe.
1825 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1826 we want; we need this to compute line_end. */
1827 line_end
= ecoff_data (abfd
)->line
;
1828 if (pdr_ptr
== pdr_end
)
1829 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1831 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1833 /* Now change pdr and pdr_ptr to the one we want. */
1834 pdr_ptr
-= external_pdr_size
;
1835 (*backend
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1839 line_ptr
= (ecoff_data (abfd
)->line
1840 + fdr_ptr
->cbLineOffset
1841 + pdr
.cbLineOffset
);
1842 while (line_ptr
< line_end
)
1847 delta
= *line_ptr
>> 4;
1850 count
= (*line_ptr
& 0xf) + 1;
1854 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
1855 if (delta
>= 0x8000)
1860 if (offset
< count
* 4)
1862 offset
-= count
* 4;
1865 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
1866 at least according to gdb/mipsread.c. */
1867 if (fdr_ptr
->rss
== -1)
1869 *filename_ptr
= NULL
;
1871 *functionname_ptr
= NULL
;
1876 (*backend
->swap_ext_in
) (abfd
,
1877 ((char *) ecoff_data (abfd
)->external_ext
1878 + pdr
.isym
* backend
->external_ext_size
),
1880 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
1887 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
1888 (*backend
->swap_sym_in
) (abfd
,
1889 ((char *) ecoff_data (abfd
)->external_sym
1890 + ((fdr_ptr
->isymBase
+ pdr
.isym
)
1891 * backend
->external_sym_size
)),
1893 *functionname_ptr
= (ecoff_data (abfd
)->ss
1897 if (lineno
== ilineNil
)
1899 *retline_ptr
= lineno
;
1903 /* We can't use the generic linking routines for ECOFF, because we
1904 have to handle all the debugging information. The generic link
1905 routine just works out the section contents and attaches a list of
1908 We link by looping over all the seclets. We make two passes. On
1909 the first we set the actual section contents and determine the size
1910 of the debugging information. On the second we accumulate the
1911 debugging information and write it out.
1913 This currently always accumulates the debugging information, which
1914 is incorrect, because it ignores the -s and -S options of the
1915 linker. The linker needs to be modified to give us that
1916 information in a more useful format (currently it just provides a
1917 list of symbols which should appear in the output file). */
1919 /* Clear the output_has_begun flag for all the input BFD's. We use it
1920 to avoid linking in the debugging information for a BFD more than
1924 ecoff_clear_output_flags (abfd
)
1927 register asection
*o
;
1928 register bfd_seclet_type
*p
;
1930 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1931 for (p
= o
->seclets_head
;
1932 p
!= (bfd_seclet_type
*) NULL
;
1934 if (p
->type
== bfd_indirect_seclet
)
1935 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
1938 /* Handle an indirect seclet on the first pass. Set the contents of
1939 the output section, and accumulate the debugging information if
1943 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
1945 bfd_seclet_type
*seclet
;
1946 asection
*output_section
;
1948 boolean relocateable
;
1951 HDRR
*output_symhdr
;
1954 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
1955 && !(output_section
->flags
& SEC_NEVER_LOAD
)
1956 && (output_section
->flags
& SEC_LOAD
)
1959 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
1963 if (bfd_set_section_contents (output_bfd
,
1974 input_bfd
= seclet
->u
.indirect
.section
->owner
;
1976 /* We want to figure out how much space will be required to
1977 incorporate all the debugging information from input_bfd. We use
1978 the output_has_begun field to avoid adding it in more than once.
1979 The actual incorporation is done in the second pass, in
1980 ecoff_get_debug. The code has to parallel that code in its
1981 manipulations of output_symhdr. */
1983 if (input_bfd
->output_has_begun
)
1985 input_bfd
->output_has_begun
= true;
1987 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
1989 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
1995 /* We just accumulate local symbols from a non-ECOFF BFD. The
1996 external symbols are handled separately. */
1998 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
1999 get_symtab_upper_bound (input_bfd
));
2000 if (symbols
== (asymbol
**) NULL
)
2002 bfd_error
= no_memory
;
2005 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2007 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2011 len
= strlen ((*sym_ptr
)->name
);
2012 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2014 ++output_symhdr
->isymMax
;
2015 output_symhdr
->issMax
+= len
+ 1;
2019 bfd_release (output_bfd
, (PTR
) symbols
);
2021 ++output_symhdr
->ifdMax
;
2026 /* We simply add in the information from another ECOFF BFD. First
2027 we make sure we have the symbolic information. */
2028 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2030 if (bfd_get_symcount (input_bfd
) == 0)
2033 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2035 /* Figure out how much information we are going to be putting in.
2036 The external symbols are handled separately. */
2037 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2038 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2039 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2040 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2041 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2042 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2043 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2044 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2045 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2047 /* The RFD's are special, since we create them if needed. */
2048 if (input_symhdr
->crfd
> 0)
2049 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2051 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2056 /* Handle an arbitrary seclet on the first pass. */
2059 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2061 bfd_seclet_type
*seclet
;
2064 boolean relocateable
;
2066 switch (seclet
->type
)
2068 case bfd_indirect_seclet
:
2069 /* The contents of this section come from another one somewhere
2071 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2073 case bfd_fill_seclet
:
2074 /* Fill in the section with fill.value. This is used to pad out
2075 sections, but we must avoid padding the .bss section. */
2076 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2078 if (seclet
->u
.fill
.value
!= 0)
2083 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2087 for (i
= 0; i
< seclet
->size
; i
+=2)
2088 d
[i
] = seclet
->u
.fill
.value
>> 8;
2089 for (i
= 1; i
< seclet
->size
; i
+=2)
2090 d
[i
] = seclet
->u
.fill
.value
;
2091 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2093 bfd_release (abfd
, (PTR
) d
);
2105 /* Add a string to the debugging information we are accumulating for a
2106 file. Return the offset from the fdr string base or from the
2107 external string base. */
2110 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2120 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2121 len
= strlen (string
);
2124 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2125 ret
= symhdr
->issExtMax
;
2126 symhdr
->issExtMax
+= len
+ 1;
2130 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2132 symhdr
->issMax
+= len
+ 1;
2133 fdr
->cbSs
+= len
+ 1;
2138 /* Accumulate the debugging information from an input section. */
2141 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2143 bfd_seclet_type
*seclet
;
2145 boolean relocateable
;
2147 const struct ecoff_backend_data
* const backend
= ecoff_backend (output_bfd
);
2148 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
2149 const bfd_size_type external_pdr_size
= backend
->external_pdr_size
;
2150 const bfd_size_type external_fdr_size
= backend
->external_fdr_size
;
2151 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
2152 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2153 = backend
->swap_sym_in
;
2154 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2155 = backend
->swap_sym_out
;
2156 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2157 = backend
->swap_pdr_in
;
2158 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
2159 = backend
->swap_fdr_out
;
2160 void (* const swap_rfd_out
) PARAMS ((bfd
*, const RFDT
*, PTR
))
2161 = backend
->swap_rfd_out
;
2163 HDRR
*output_symhdr
;
2165 ecoff_data_type
*output_ecoff
;
2166 ecoff_data_type
*input_ecoff
;
2169 ecoff_symbol_type
*esym_ptr
;
2170 ecoff_symbol_type
*esym_end
;
2175 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2177 /* Don't get the information more than once. */
2178 if (input_bfd
->output_has_begun
)
2180 input_bfd
->output_has_begun
= true;
2182 output_ecoff
= ecoff_data (output_bfd
);
2183 output_symhdr
= &output_ecoff
->symbolic_header
;
2185 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2192 /* This is not an ECOFF BFD. Just gather the symbols. */
2194 memset (&fdr
, 0, sizeof fdr
);
2196 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2197 fdr
.issBase
= output_symhdr
->issMax
;
2199 fdr
.rss
= ecoff_add_string (output_bfd
,
2201 bfd_get_filename (input_bfd
),
2203 fdr
.isymBase
= output_symhdr
->isymMax
;
2205 /* Get the local symbols from the input BFD. */
2206 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2207 get_symtab_upper_bound (input_bfd
));
2208 if (symbols
== (asymbol
**) NULL
)
2210 bfd_error
= no_memory
;
2213 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2215 /* Handle the local symbols. Any external symbols are handled
2218 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2222 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2224 memset (&internal_sym
, 0, sizeof internal_sym
);
2225 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2230 if (bfd_is_com_section ((*sym_ptr
)->section
)
2231 || (*sym_ptr
)->section
== &bfd_und_section
)
2232 internal_sym
.value
= (*sym_ptr
)->value
;
2234 internal_sym
.value
= ((*sym_ptr
)->value
2235 + (*sym_ptr
)->section
->output_offset
2236 + (*sym_ptr
)->section
->output_section
->vma
);
2237 internal_sym
.st
= stNil
;
2238 internal_sym
.sc
= scUndefined
;
2239 internal_sym
.index
= indexNil
;
2240 (*swap_sym_out
) (output_bfd
, &internal_sym
,
2241 ((char *) output_ecoff
->external_sym
2242 + output_symhdr
->isymMax
* external_sym_size
));
2244 ++output_symhdr
->isymMax
;
2247 bfd_release (output_bfd
, (PTR
) symbols
);
2249 /* Leave everything else in the FDR zeroed out. This will cause
2250 the lang field to be langC. The fBigendian field will
2251 indicate little endian format, but it doesn't matter because
2252 it only applies to aux fields and there are none. */
2254 (*swap_fdr_out
) (output_bfd
, &fdr
,
2255 ((char *) output_ecoff
->external_fdr
2256 + output_symhdr
->ifdMax
* external_fdr_size
));
2257 ++output_symhdr
->ifdMax
;
2261 /* This is an ECOFF BFD. We want to grab the information from
2262 input_bfd and attach it to output_bfd. */
2263 count
= bfd_get_symcount (input_bfd
);
2266 input_ecoff
= ecoff_data (input_bfd
);
2267 input_symhdr
= &input_ecoff
->symbolic_header
;
2269 /* I think that it is more efficient to simply copy the debugging
2270 information from the input BFD to the output BFD. Because ECOFF
2271 uses relative pointers for most of the debugging information,
2272 only a little of it has to be changed at all. */
2274 /* Swap in the local symbols, adjust their values, and swap them out
2275 again. The external symbols are handled separately. */
2276 sym_out
= ((char *) output_ecoff
->external_sym
2277 + output_symhdr
->isymMax
* external_sym_size
);
2279 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2280 esym_end
= esym_ptr
+ count
;
2281 for (; esym_ptr
< esym_end
; esym_ptr
++)
2283 if (esym_ptr
->local
)
2287 (*swap_sym_in
) (input_bfd
, esym_ptr
->native
, &sym
);
2289 /* If we're producing an executable, move common symbols
2291 if (relocateable
== false)
2293 if (sym
.sc
== scCommon
)
2295 else if (sym
.sc
== scSCommon
)
2299 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2300 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2301 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2302 sym
.value
= (esym_ptr
->symbol
.value
2303 + esym_ptr
->symbol
.section
->output_offset
2304 + esym_ptr
->symbol
.section
->output_section
->vma
);
2305 (*swap_sym_out
) (output_bfd
, &sym
, sym_out
);
2306 sym_out
+= external_sym_size
;
2310 /* That should have accounted for all the local symbols in
2313 /* Copy the information that does not need swapping. */
2314 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2316 input_symhdr
->cbLine
* sizeof (unsigned char));
2317 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2318 input_ecoff
->external_aux
,
2319 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2320 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2322 input_symhdr
->issMax
* sizeof (char));
2324 /* Some of the information may need to be swapped. */
2325 if (output_bfd
->xvec
->header_byteorder_big_p
2326 == input_bfd
->xvec
->header_byteorder_big_p
)
2328 /* The two BFD's have the same endianness, so memcpy will
2330 if (input_symhdr
->idnMax
> 0)
2331 memcpy (((char *) output_ecoff
->external_dnr
2332 + output_symhdr
->idnMax
* backend
->external_dnr_size
),
2333 input_ecoff
->external_dnr
,
2334 input_symhdr
->idnMax
* backend
->external_dnr_size
);
2335 if (input_symhdr
->ipdMax
> 0)
2336 memcpy (((char *) output_ecoff
->external_pdr
2337 + output_symhdr
->ipdMax
* external_pdr_size
),
2338 input_ecoff
->external_pdr
,
2339 input_symhdr
->ipdMax
* external_pdr_size
);
2340 if (input_symhdr
->ioptMax
> 0)
2341 memcpy (((char *) output_ecoff
->external_opt
2342 + output_symhdr
->ioptMax
* backend
->external_opt_size
),
2343 input_ecoff
->external_opt
,
2344 input_symhdr
->ioptMax
* backend
->external_opt_size
);
2353 /* The two BFD's have different endianness, so we must swap
2354 everything in and out. This code would always work, but it
2355 would be slow in the normal case. */
2356 sz
= backend
->external_dnr_size
;
2357 in
= (char *) input_ecoff
->external_dnr
;
2358 end
= in
+ input_symhdr
->idnMax
* sz
;
2359 out
= (char *) output_ecoff
->external_dnr
+ output_symhdr
->idnMax
* sz
;
2360 for (; in
< end
; in
+= sz
, out
+= sz
)
2364 (*backend
->swap_dnr_in
) (input_bfd
, in
, &dnr
);
2365 (*backend
->swap_dnr_out
) (output_bfd
, &dnr
, out
);
2368 sz
= external_pdr_size
;
2369 in
= (char *) input_ecoff
->external_pdr
;
2370 end
= in
+ input_symhdr
->ipdMax
* sz
;
2371 out
= (char *) output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
* sz
;
2372 for (; in
< end
; in
+= sz
, out
+= sz
)
2376 (*swap_pdr_in
) (input_bfd
, in
, &pdr
);
2377 (*backend
->swap_pdr_out
) (output_bfd
, &pdr
, out
);
2380 sz
= backend
->external_opt_size
;
2381 in
= (char *) input_ecoff
->external_opt
;
2382 end
= in
+ input_symhdr
->ioptMax
* sz
;
2383 out
= (char *) output_ecoff
->external_opt
+ output_symhdr
->ioptMax
* sz
;
2384 for (; in
< end
; in
+= sz
, out
+= sz
)
2388 (*backend
->swap_opt_in
) (input_bfd
, in
, &opt
);
2389 (*backend
->swap_opt_out
) (output_bfd
, &opt
, out
);
2393 /* Set ifdbase so that the external symbols know how to adjust their
2395 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2397 fdr_ptr
= input_ecoff
->fdr
;
2398 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2399 fdr_out
= ((char *) output_ecoff
->external_fdr
2400 + output_symhdr
->ifdMax
* external_fdr_size
);
2401 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
+= external_fdr_size
)
2404 unsigned long pdr_off
;
2408 /* The memory address for this fdr is the address for the seclet
2409 plus the offset to this fdr within input_bfd. For some
2410 reason the offset of the first procedure pointer is also
2418 (*swap_pdr_in
) (input_bfd
,
2419 ((char *) input_ecoff
->external_pdr
2420 + fdr
.ipdFirst
* external_pdr_size
),
2424 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2426 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2429 fdr
.issBase
+= output_symhdr
->issMax
;
2430 fdr
.isymBase
+= output_symhdr
->isymMax
;
2431 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2432 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2433 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2434 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2435 fdr
.rfdBase
+= output_symhdr
->crfd
;
2437 /* If there are no RFD's, we are going to add some. We don't
2438 want to adjust irfd for this, so that all the FDR's can share
2440 if (input_symhdr
->crfd
== 0)
2441 fdr
.crfd
= input_symhdr
->ifdMax
;
2443 if (fdr
.cbLine
!= 0)
2444 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2446 (*swap_fdr_out
) (output_bfd
, &fdr
, fdr_out
);
2449 if (input_symhdr
->crfd
> 0)
2451 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2452 = backend
->swap_rfd_in
;
2457 /* Swap and adjust the RFD's. RFD's are only created by the
2458 linker, so this will only be necessary if one of the input
2459 files is the result of a partial link. Presumably all
2460 necessary RFD's are present. */
2461 rfd_in
= (char *) input_ecoff
->external_rfd
;
2462 rfd_end
= rfd_in
+ input_symhdr
->crfd
* external_rfd_size
;
2463 rfd_out
= ((char *) output_ecoff
->external_rfd
2464 + output_symhdr
->crfd
* external_rfd_size
);
2467 rfd_in
+= external_rfd_size
, rfd_out
+= external_rfd_size
)
2471 (*swap_rfd_in
) (input_bfd
, rfd_in
, &rfd
);
2472 rfd
+= output_symhdr
->ifdMax
;
2473 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2475 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2483 /* Create RFD's. Some of the debugging information includes
2484 relative file indices. These indices are taken as indices to
2485 the RFD table if there is one, or to the global table if
2486 there is not. If we did not create RFD's, we would have to
2487 parse and adjust all the debugging information which contains
2489 rfd
= output_symhdr
->ifdMax
;
2490 rfd_out
= ((char *) output_ecoff
->external_rfd
2491 + output_symhdr
->crfd
* external_rfd_size
);
2492 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
* external_rfd_size
;
2493 for (; rfd_out
< rfd_end
; rfd_out
+= external_rfd_size
, rfd
++)
2494 (*swap_rfd_out
) (output_bfd
, &rfd
, rfd_out
);
2495 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2498 /* Combine the register masks. Not all of these are used on all
2499 targets, but that's OK because only the relevant ones will be
2500 swapped in and out. */
2504 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2505 output_ecoff
->fprmask
|= input_ecoff
->fprmask
;
2506 for (i
= 0; i
< 4; i
++)
2507 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2510 /* Update the counts. */
2511 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2512 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2513 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2514 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2515 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2516 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2517 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2518 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2519 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2524 /* This is the actual link routine. It makes two passes over all the
2528 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2531 boolean relocateable
;
2533 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2536 register asection
*o
;
2537 register bfd_seclet_type
*p
;
2538 asymbol
**sym_ptr_ptr
;
2539 bfd_size_type debug_align
;
2543 /* We accumulate the debugging information counts in the symbolic
2545 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2546 symhdr
->magic
= backend
->sym_magic
;
2547 /* FIXME: What should the version stamp be? */
2549 symhdr
->ilineMax
= 0;
2553 symhdr
->isymMax
= 0;
2554 symhdr
->ioptMax
= 0;
2555 symhdr
->iauxMax
= 0;
2557 symhdr
->issExtMax
= 0;
2560 symhdr
->iextMax
= 0;
2562 /* We need to copy over the debugging symbols from each input BFD.
2563 When we do this copying, we have to adjust the text address in
2564 the FDR structures, so we have to know the text address used for
2565 the input BFD. Since we only want to copy the symbols once per
2566 input BFD, but we are going to look at each input BFD multiple
2567 times (once for each section it provides), we arrange to always
2568 look at the text section first. That means that when we copy the
2569 debugging information, we always know the text address. So we
2570 actually do each pass in two sub passes; first the text sections,
2571 then the non-text sections. We use the output_has_begun flag to
2572 determine whether we have copied over the debugging information
2575 /* Do the first pass: set the output section contents and count the
2576 debugging information. */
2577 ecoff_clear_output_flags (abfd
);
2578 for (ipass
= 0; ipass
< 2; ipass
++)
2580 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2582 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2583 so they are done on pass 0. For other sections the
2584 expression is true, so they are done on pass 1. */
2585 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2588 for (p
= o
->seclets_head
;
2589 p
!= (bfd_seclet_type
*) NULL
;
2592 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2599 /* We handle the external symbols differently. We use the ones
2600 attached to the output_bfd. The linker will have already
2601 determined which symbols are to be attached. Here we just
2602 determine how much space we will need for them. */
2603 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2604 if (sym_ptr_ptr
!= NULL
)
2608 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2609 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2611 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2612 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2615 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2620 /* Adjust the counts so that structures are longword aligned. */
2621 debug_align
= backend
->debug_align
;
2623 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2624 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2625 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2627 /* Now the counts in symhdr are the correct size for the debugging
2628 information. We allocate the right amount of space, and reset
2629 the counts so that the second pass can use them as indices. It
2630 would be possible to output the debugging information directly to
2631 the file in pass 2, rather than to build it in memory and then
2632 write it out. Outputting to the file would require a lot of
2633 seeks and small writes, though, and I think this approach is
2635 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2636 + symhdr
->idnMax
* backend
->external_dnr_size
2637 + symhdr
->ipdMax
* backend
->external_pdr_size
2638 + symhdr
->isymMax
* backend
->external_sym_size
2639 + symhdr
->ioptMax
* backend
->external_opt_size
2640 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2641 + symhdr
->issMax
* sizeof (char)
2642 + symhdr
->issExtMax
* sizeof (char)
2643 + symhdr
->ifdMax
* backend
->external_fdr_size
2644 + symhdr
->crfd
* backend
->external_rfd_size
2645 + symhdr
->iextMax
* backend
->external_ext_size
);
2646 raw
= (char *) bfd_alloc (abfd
, size
);
2647 if (raw
== (char *) NULL
)
2649 bfd_error
= no_memory
;
2652 ecoff_data (abfd
)->raw_size
= size
;
2653 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2655 /* Initialize the raw pointers. */
2656 #define SET(field, count, type, size) \
2657 ecoff_data (abfd)->field = (type) raw; \
2658 raw += symhdr->count * size
2660 SET (line
, cbLine
, unsigned char *, sizeof (unsigned char));
2661 SET (external_dnr
, idnMax
, PTR
, backend
->external_dnr_size
);
2662 SET (external_pdr
, ipdMax
, PTR
, backend
->external_pdr_size
);
2663 SET (external_sym
, isymMax
, PTR
, backend
->external_sym_size
);
2664 SET (external_opt
, ioptMax
, PTR
, backend
->external_opt_size
);
2665 SET (external_aux
, iauxMax
, union aux_ext
*, sizeof (union aux_ext
));
2666 SET (ss
, issMax
, char *, sizeof (char));
2667 SET (ssext
, issExtMax
, char *, sizeof (char));
2668 SET (external_fdr
, ifdMax
, PTR
, backend
->external_fdr_size
);
2669 SET (external_rfd
, crfd
, PTR
, backend
->external_rfd_size
);
2670 SET (external_ext
, iextMax
, PTR
, backend
->external_ext_size
);
2673 /* Reset the counts so the second pass can use them to know how far
2675 symhdr
->ilineMax
= 0;
2679 symhdr
->isymMax
= 0;
2680 symhdr
->ioptMax
= 0;
2681 symhdr
->iauxMax
= 0;
2683 symhdr
->issExtMax
= 0;
2686 symhdr
->iextMax
= 0;
2688 /* Do the second pass: accumulate the debugging information. */
2689 ecoff_clear_output_flags (abfd
);
2690 for (ipass
= 0; ipass
< 2; ipass
++)
2692 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2694 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2696 for (p
= o
->seclets_head
;
2697 p
!= (bfd_seclet_type
*) NULL
;
2700 if (p
->type
== bfd_indirect_seclet
)
2702 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
2709 /* Put in the external symbols. */
2710 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2711 if (sym_ptr_ptr
!= NULL
)
2713 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
2714 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
2715 = backend
->swap_ext_in
;
2716 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
2717 = backend
->swap_ext_out
;
2721 ssext
= ecoff_data (abfd
)->ssext
;
2722 external_ext
= (char *) ecoff_data (abfd
)->external_ext
;
2723 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2728 sym_ptr
= *sym_ptr_ptr
;
2730 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2731 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2734 /* The native pointer can be NULL for a symbol created by
2735 the linker via ecoff_make_empty_symbol. */
2736 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2737 || ecoffsymbol (sym_ptr
)->native
== NULL
)
2740 esym
.cobol_main
= 0;
2744 /* FIXME: we can do better than this for st and sc. */
2745 esym
.asym
.st
= stGlobal
;
2746 esym
.asym
.sc
= scAbs
;
2747 esym
.asym
.reserved
= 0;
2748 esym
.asym
.index
= indexNil
;
2752 ecoff_symbol_type
*ecoff_sym_ptr
;
2754 ecoff_sym_ptr
= ecoffsymbol (sym_ptr
);
2755 if (ecoff_sym_ptr
->local
)
2757 (*swap_ext_in
) (abfd
, ecoff_sym_ptr
->native
, &esym
);
2759 /* If we're producing an executable, move common symbols
2761 if (relocateable
== false)
2763 if (esym
.asym
.sc
== scCommon
)
2764 esym
.asym
.sc
= scBss
;
2765 else if (esym
.asym
.sc
== scSCommon
)
2766 esym
.asym
.sc
= scSBss
;
2769 /* Adjust the FDR index for the symbol by that used for
2771 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2774 esym
.asym
.iss
= symhdr
->issExtMax
;
2776 if (bfd_is_com_section (sym_ptr
->section
)
2777 || sym_ptr
->section
== &bfd_und_section
)
2778 esym
.asym
.value
= sym_ptr
->value
;
2780 esym
.asym
.value
= (sym_ptr
->value
2781 + sym_ptr
->section
->output_offset
2782 + sym_ptr
->section
->output_section
->vma
);
2784 (*swap_ext_out
) (abfd
, &esym
, external_ext
);
2786 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2788 external_ext
+= external_ext_size
;
2791 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2792 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2796 /* Adjust the counts so that structures are longword aligned. */
2797 symhdr
->cbLine
= (symhdr
->cbLine
+ debug_align
) &~ debug_align
;
2798 symhdr
->issMax
= (symhdr
->issMax
+ debug_align
) &~ debug_align
;
2799 symhdr
->issExtMax
= (symhdr
->issExtMax
+ debug_align
) &~ debug_align
;
2804 /* Set the architecture. The supported architecture is stored in the
2805 backend pointer. We always set the architecture anyhow, since many
2806 callers ignore the return value. */
2809 ecoff_set_arch_mach (abfd
, arch
, machine
)
2811 enum bfd_architecture arch
;
2812 unsigned long machine
;
2814 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2815 return arch
== ecoff_backend (abfd
)->arch
;
2818 /* Get the size of the section headers. We do not output the .scommon
2819 section which we created in ecoff_mkobject. */
2822 ecoff_sizeof_headers (abfd
, reloc
)
2826 return (bfd_coff_filhsz (abfd
)
2827 + bfd_coff_aoutsz (abfd
)
2828 + (abfd
->section_count
- 1) * bfd_coff_scnhsz (abfd
));
2831 /* Calculate the file position for each section, and set
2835 ecoff_compute_section_file_positions (abfd
)
2843 if (bfd_get_start_address (abfd
))
2844 abfd
->flags
|= EXEC_P
;
2846 sofar
= ecoff_sizeof_headers (abfd
, false);
2849 for (current
= abfd
->sections
;
2850 current
!= (asection
*) NULL
;
2851 current
= current
->next
)
2853 /* Only deal with sections which have contents */
2854 if (! (current
->flags
& SEC_HAS_CONTENTS
)
2855 || strcmp (current
->name
, SCOMMON
) == 0)
2858 /* On Ultrix, the data sections in an executable file must be
2859 aligned to a page boundary within the file. This does not
2860 affect the section size, though. FIXME: Does this work for
2862 if ((abfd
->flags
& EXEC_P
) != 0
2863 && (abfd
->flags
& D_PAGED
) != 0
2864 && first_data
!= false
2865 && (current
->flags
& SEC_CODE
) == 0)
2867 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2869 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2873 /* Align the sections in the file to the same boundary on
2874 which they are aligned in virtual memory. */
2876 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2878 current
->filepos
= sofar
;
2880 sofar
+= current
->_raw_size
;
2882 /* make sure that this section is of the right size too */
2884 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2885 current
->_raw_size
+= sofar
- old_sofar
;
2888 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2891 /* Set the contents of a section. */
2894 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2899 bfd_size_type count
;
2901 if (abfd
->output_has_begun
== false)
2902 ecoff_compute_section_file_positions (abfd
);
2904 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
2907 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
2912 /* Write out an ECOFF file. */
2915 ecoff_write_object_contents (abfd
)
2918 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2919 const bfd_vma round
= backend
->round
;
2920 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2921 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2922 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2923 const bfd_size_type external_hdr_size
= backend
->external_hdr_size
;
2924 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2925 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2926 const struct internal_reloc
*,
2928 = backend
->swap_reloc_out
;
2932 file_ptr reloc_base
;
2934 unsigned long reloc_size
;
2935 unsigned long text_size
;
2936 unsigned long text_start
;
2937 unsigned long data_size
;
2938 unsigned long data_start
;
2939 unsigned long bss_size
;
2941 struct internal_filehdr internal_f
;
2942 struct internal_aouthdr internal_a
;
2945 bfd_error
= system_call_error
;
2947 if(abfd
->output_has_begun
== false)
2948 ecoff_compute_section_file_positions(abfd
);
2950 if (abfd
->sections
!= (asection
*) NULL
)
2951 scn_base
= abfd
->sections
->filepos
;
2954 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2958 for (current
= abfd
->sections
;
2959 current
!= (asection
*)NULL
;
2960 current
= current
->next
)
2962 if (strcmp (current
->name
, SCOMMON
) == 0)
2964 current
->target_index
= count
;
2966 if (current
->reloc_count
!= 0)
2968 bfd_size_type relsize
;
2970 current
->rel_filepos
= reloc_base
;
2971 relsize
= current
->reloc_count
* external_reloc_size
;
2972 reloc_size
+= relsize
;
2973 reloc_base
+= relsize
;
2976 current
->rel_filepos
= 0;
2979 sym_base
= reloc_base
+ reloc_size
;
2981 /* At least on Ultrix, the symbol table of an executable file must
2982 be aligned to a page boundary. FIXME: Is this true on other
2984 if ((abfd
->flags
& EXEC_P
) != 0
2985 && (abfd
->flags
& D_PAGED
) != 0)
2986 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
2988 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2990 if ((abfd
->flags
& D_PAGED
) != 0)
2991 text_size
= ecoff_sizeof_headers (abfd
, false);
2999 /* Write section headers to the file. */
3001 buff
= (PTR
) alloca (scnhsz
);
3002 internal_f
.f_nscns
= 0;
3003 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
3005 for (current
= abfd
->sections
;
3006 current
!= (asection
*) NULL
;
3007 current
= current
->next
)
3009 struct internal_scnhdr section
;
3012 if (strcmp (current
->name
, SCOMMON
) == 0)
3014 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3015 && current
->reloc_count
== 0);
3019 ++internal_f
.f_nscns
;
3021 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3023 /* FIXME: is this correct for shared libraries? I think it is
3024 but I have no platform to check. Ian Lance Taylor. */
3025 vma
= bfd_get_section_vma (abfd
, current
);
3026 if (strcmp (current
->name
, _LIB
) == 0)
3027 section
.s_vaddr
= 0;
3029 section
.s_vaddr
= vma
;
3031 section
.s_paddr
= vma
;
3032 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3034 /* If this section has no size or is unloadable then the scnptr
3036 if (current
->_raw_size
== 0
3037 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3038 section
.s_scnptr
= 0;
3040 section
.s_scnptr
= current
->filepos
;
3041 section
.s_relptr
= current
->rel_filepos
;
3043 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3044 object file produced by the assembler is supposed to point to
3045 information about how much room is required by objects of
3046 various different sizes. I think this only matters if we
3047 want the linker to compute the best size to use, or
3048 something. I don't know what happens if the information is
3050 section
.s_lnnoptr
= 0;
3052 section
.s_nreloc
= current
->reloc_count
;
3053 section
.s_nlnno
= 0;
3054 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3057 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
3058 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
3061 if ((section
.s_flags
& STYP_TEXT
) != 0)
3063 text_size
+= bfd_get_section_size_before_reloc (current
);
3064 if (text_start
== 0 || text_start
> vma
)
3067 else if ((section
.s_flags
& STYP_RDATA
) != 0
3068 || (section
.s_flags
& STYP_DATA
) != 0
3069 || (section
.s_flags
& STYP_LIT8
) != 0
3070 || (section
.s_flags
& STYP_LIT4
) != 0
3071 || (section
.s_flags
& STYP_SDATA
) != 0)
3073 data_size
+= bfd_get_section_size_before_reloc (current
);
3074 if (data_start
== 0 || data_start
> vma
)
3077 else if ((section
.s_flags
& STYP_BSS
) != 0
3078 || (section
.s_flags
& STYP_SBSS
) != 0)
3079 bss_size
+= bfd_get_section_size_before_reloc (current
);
3082 /* Set up the file header. */
3084 if (abfd
->xvec
->header_byteorder_big_p
!= false)
3085 internal_f
.f_magic
= backend
->big_magic
;
3087 internal_f
.f_magic
= backend
->little_magic
;
3089 /* We will NOT put a fucking timestamp in the header here. Every
3090 time you put it back, I will come in and take it out again. I'm
3091 sorry. This field does not belong here. We fill it with a 0 so
3092 it compares the same but is not a reasonable time. --
3094 internal_f
.f_timdat
= 0;
3096 if (bfd_get_symcount (abfd
) != 0)
3098 /* The ECOFF f_nsyms field is not actually the number of
3099 symbols, it's the size of symbolic information header. */
3100 internal_f
.f_nsyms
= external_hdr_size
;
3101 internal_f
.f_symptr
= sym_base
;
3105 internal_f
.f_nsyms
= 0;
3106 internal_f
.f_symptr
= 0;
3109 internal_f
.f_opthdr
= aoutsz
;
3111 internal_f
.f_flags
= F_LNNO
;
3112 if (reloc_size
== 0)
3113 internal_f
.f_flags
|= F_RELFLG
;
3114 if (bfd_get_symcount (abfd
) == 0)
3115 internal_f
.f_flags
|= F_LSYMS
;
3116 if (abfd
->flags
& EXEC_P
)
3117 internal_f
.f_flags
|= F_EXEC
;
3119 if (! abfd
->xvec
->byteorder_big_p
)
3120 internal_f
.f_flags
|= F_AR32WR
;
3122 internal_f
.f_flags
|= F_AR32W
;
3124 /* Set up the ``optional'' header. */
3125 if ((abfd
->flags
& D_PAGED
) != 0)
3126 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
3128 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
3130 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3131 linker happy. But, is it right? */
3132 internal_a
.vstamp
= 0x20a;
3134 /* At least on Ultrix, these have to be rounded to page boundaries.
3135 FIXME: Is this true on other platforms? */
3136 if ((abfd
->flags
& D_PAGED
) != 0)
3138 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
3139 internal_a
.text_start
= text_start
&~ (round
- 1);
3140 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
3141 internal_a
.data_start
= data_start
&~ (round
- 1);
3145 internal_a
.tsize
= text_size
;
3146 internal_a
.text_start
= text_start
;
3147 internal_a
.dsize
= data_size
;
3148 internal_a
.data_start
= data_start
;
3151 /* On Ultrix, the initial portions of the .sbss and .bss segments
3152 are at the end of the data section. The bsize field in the
3153 optional header records how many bss bytes are required beyond
3154 those in the data section. The value is not rounded to a page
3156 if (bss_size
< internal_a
.dsize
- data_size
)
3159 bss_size
-= internal_a
.dsize
- data_size
;
3160 internal_a
.bsize
= bss_size
;
3161 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3163 internal_a
.entry
= bfd_get_start_address (abfd
);
3165 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3167 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3168 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
3169 for (i
= 0; i
< 4; i
++)
3170 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3172 /* Write out the file header and the optional header. */
3174 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3177 buff
= (PTR
) alloca (filhsz
);
3178 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
3179 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
3182 buff
= (PTR
) alloca (aoutsz
);
3183 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
3184 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
3187 /* Write out the relocs. */
3188 for (current
= abfd
->sections
;
3189 current
!= (asection
*) NULL
;
3190 current
= current
->next
)
3192 arelent
**reloc_ptr_ptr
;
3193 arelent
**reloc_end
;
3196 if (current
->reloc_count
== 0)
3199 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
3202 bfd_error
= no_memory
;
3206 reloc_ptr_ptr
= current
->orelocation
;
3207 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3208 out_ptr
= (char *) buff
;
3210 reloc_ptr_ptr
< reloc_end
;
3211 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
3215 struct internal_reloc in
;
3217 memset (&in
, 0, sizeof in
);
3219 reloc
= *reloc_ptr_ptr
;
3220 sym
= *reloc
->sym_ptr_ptr
;
3222 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3223 in
.r_type
= reloc
->howto
->type
;
3225 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3227 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3234 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3235 if (strcmp (name
, ".text") == 0)
3236 in
.r_symndx
= RELOC_SECTION_TEXT
;
3237 else if (strcmp (name
, ".rdata") == 0)
3238 in
.r_symndx
= RELOC_SECTION_RDATA
;
3239 else if (strcmp (name
, ".data") == 0)
3240 in
.r_symndx
= RELOC_SECTION_DATA
;
3241 else if (strcmp (name
, ".sdata") == 0)
3242 in
.r_symndx
= RELOC_SECTION_SDATA
;
3243 else if (strcmp (name
, ".sbss") == 0)
3244 in
.r_symndx
= RELOC_SECTION_SBSS
;
3245 else if (strcmp (name
, ".bss") == 0)
3246 in
.r_symndx
= RELOC_SECTION_BSS
;
3247 else if (strcmp (name
, ".init") == 0)
3248 in
.r_symndx
= RELOC_SECTION_INIT
;
3249 else if (strcmp (name
, ".lit8") == 0)
3250 in
.r_symndx
= RELOC_SECTION_LIT8
;
3251 else if (strcmp (name
, ".lit4") == 0)
3252 in
.r_symndx
= RELOC_SECTION_LIT4
;
3258 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
3261 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3263 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
3264 != external_reloc_size
* current
->reloc_count
)
3266 bfd_release (abfd
, buff
);
3269 /* Write out the symbolic debugging information. */
3270 if (bfd_get_symcount (abfd
) > 0)
3273 unsigned long sym_offset
;
3275 /* Set up the offsets in the symbolic header. */
3276 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3277 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ external_hdr_size
;
3279 #define SET(offset, size, ptr) \
3280 if (symhdr->size == 0) \
3281 symhdr->offset = 0; \
3283 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3284 - (char *) ecoff_data (abfd)->raw_syments) \
3287 SET (cbLineOffset
, cbLine
, line
);
3288 SET (cbDnOffset
, idnMax
, external_dnr
);
3289 SET (cbPdOffset
, ipdMax
, external_pdr
);
3290 SET (cbSymOffset
, isymMax
, external_sym
);
3291 SET (cbOptOffset
, ioptMax
, external_opt
);
3292 SET (cbAuxOffset
, iauxMax
, external_aux
);
3293 SET (cbSsOffset
, issMax
, ss
);
3294 SET (cbSsExtOffset
, issExtMax
, ssext
);
3295 SET (cbFdOffset
, ifdMax
, external_fdr
);
3296 SET (cbRfdOffset
, crfd
, external_rfd
);
3297 SET (cbExtOffset
, iextMax
, external_ext
);
3300 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3303 buff
= (PTR
) alloca (external_hdr_size
);
3304 (*backend
->swap_hdr_out
) (abfd
, &ecoff_data (abfd
)->symbolic_header
,
3306 if (bfd_write (buff
, 1, external_hdr_size
, abfd
) != external_hdr_size
)
3308 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3309 ecoff_data (abfd
)->raw_size
, abfd
)
3310 != ecoff_data (abfd
)->raw_size
)
3313 else if ((abfd
->flags
& EXEC_P
) != 0
3314 && (abfd
->flags
& D_PAGED
) != 0)
3318 /* A demand paged executable must occupy an even number of
3320 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3323 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3325 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3328 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3335 /* Archive handling. ECOFF uses what appears to be a unique type of
3336 archive header (which I call an armap). The byte ordering of the
3337 armap and the contents are encoded in the name of the armap itself.
3338 At least for now, we only support archives with the same byte
3339 ordering in the armap and the contents.
3341 The first four bytes in the armap are the number of symbol
3342 definitions. This is always a power of two.
3344 This is followed by the symbol definitions. Each symbol definition
3345 occupies 8 bytes. The first four bytes are the offset from the
3346 start of the armap strings to the null-terminated string naming
3347 this symbol. The second four bytes are the file offset to the
3348 archive member which defines this symbol. If the second four bytes
3349 are 0, then this is not actually a symbol definition, and it should
3352 The symbols are hashed into the armap with a closed hashing scheme.
3353 See the functions below for the details of the algorithm.
3355 We could use the hash table when looking up symbols in a library.
3356 This would require a new BFD target entry point to replace the
3357 bfd_get_next_mapent function used by the linker.
3359 After the symbol definitions comes four bytes holding the size of
3360 the string table, followed by the string table itself. */
3362 /* The name of an archive headers looks like this:
3363 __________E[BL]E[BL]_ (with a trailing space).
3364 The trailing space is changed to an X if the archive is changed to
3365 indicate that the armap is out of date.
3367 The Alpha seems to use ________64E[BL]E[BL]_. */
3369 #define ARMAP_BIG_ENDIAN 'B'
3370 #define ARMAP_LITTLE_ENDIAN 'L'
3371 #define ARMAP_MARKER 'E'
3372 #define ARMAP_START_LENGTH 10
3373 #define ARMAP_HEADER_MARKER_INDEX 10
3374 #define ARMAP_HEADER_ENDIAN_INDEX 11
3375 #define ARMAP_OBJECT_MARKER_INDEX 12
3376 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3377 #define ARMAP_END_INDEX 14
3378 #define ARMAP_END "_ "
3380 /* This is a magic number used in the hashing algorithm. */
3381 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3383 /* This returns the hash value to use for a string. It also sets
3384 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3385 is the number of entries in the hash table, and HLOG is the log
3389 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3391 unsigned int *rehash
;
3399 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3400 hash
*= ARMAP_HASH_MAGIC
;
3401 *rehash
= (hash
& (size
- 1)) | 1;
3402 return hash
>> (32 - hlog
);
3405 /* Read in the armap. */
3408 ecoff_slurp_armap (abfd
)
3413 struct areltdata
*mapdata
;
3414 bfd_size_type parsed_size
;
3416 struct artdata
*ardata
;
3419 struct symdef
*symdef_ptr
;
3422 /* Get the name of the first element. */
3423 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3429 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3431 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3432 standard COFF armap. We could move the ECOFF armap stuff into
3433 bfd_slurp_armap, but that seems inappropriate since no other
3434 target uses this format. Instead, we check directly for a COFF
3436 if (strncmp (nextname
, "/ ", 16) == 0)
3437 return bfd_slurp_armap (abfd
);
3439 /* See if the first element is an armap. */
3440 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3441 ARMAP_START_LENGTH
) != 0
3442 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3443 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3444 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3445 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3446 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3447 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3448 || strncmp (nextname
+ ARMAP_END_INDEX
,
3449 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3451 bfd_has_map (abfd
) = false;
3455 /* Make sure we have the right byte ordering. */
3456 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3457 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3458 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3459 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3461 bfd_error
= wrong_format
;
3465 /* Read in the armap. */
3466 ardata
= bfd_ardata (abfd
);
3467 mapdata
= snarf_ar_hdr (abfd
);
3468 if (mapdata
== (struct areltdata
*) NULL
)
3470 parsed_size
= mapdata
->parsed_size
;
3471 bfd_release (abfd
, (PTR
) mapdata
);
3473 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3474 if (raw_armap
== (char *) NULL
)
3476 bfd_error
= no_memory
;
3480 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3482 bfd_error
= malformed_archive
;
3483 bfd_release (abfd
, (PTR
) raw_armap
);
3487 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3489 ardata
->symdef_count
= 0;
3490 ardata
->cache
= (struct ar_cache
*) NULL
;
3492 /* This code used to overlay the symdefs over the raw archive data,
3493 but that doesn't work on a 64 bit host. */
3495 stringbase
= raw_armap
+ count
* (2 * LONG_SIZE
) + 2 * LONG_SIZE
;
3497 #ifdef CHECK_ARMAP_HASH
3501 /* Double check that I have the hashing algorithm right by making
3502 sure that every symbol can be looked up successfully. */
3504 for (i
= 1; i
< count
; i
<<= 1)
3506 BFD_ASSERT (i
== count
);
3508 raw_ptr
= raw_armap
+ LONG_SIZE
;
3509 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3511 unsigned int name_offset
, file_offset
;
3512 unsigned int hash
, rehash
, srch
;
3514 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3515 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3516 if (file_offset
== 0)
3518 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3523 /* See if we can rehash to this location. */
3524 for (srch
= (hash
+ rehash
) & (count
- 1);
3525 srch
!= hash
&& srch
!= i
;
3526 srch
= (srch
+ rehash
) & (count
- 1))
3527 BFD_ASSERT (bfd_h_get_32 (abfd
,
3530 + (srch
* 2 * LONG_SIZE
)
3533 BFD_ASSERT (srch
== i
);
3537 #endif /* CHECK_ARMAP_HASH */
3539 raw_ptr
= raw_armap
+ LONG_SIZE
;
3540 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3541 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
)) != 0)
3542 ++ardata
->symdef_count
;
3544 symdef_ptr
= ((struct symdef
*)
3546 ardata
->symdef_count
* sizeof (struct symdef
)));
3547 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3549 raw_ptr
= raw_armap
+ LONG_SIZE
;
3550 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3552 unsigned int name_offset
, file_offset
;
3554 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3555 if (file_offset
== 0)
3557 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3558 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3559 symdef_ptr
->file_offset
= file_offset
;
3563 ardata
->first_file_filepos
= bfd_tell (abfd
);
3564 /* Pad to an even boundary. */
3565 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3567 bfd_has_map (abfd
) = true;
3572 /* Write out an armap. */
3575 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3577 unsigned int elength
;
3579 unsigned int orl_count
;
3582 unsigned int hashsize
, hashlog
;
3583 unsigned int symdefsize
;
3585 unsigned int stringsize
;
3586 unsigned int mapsize
;
3589 struct stat statbuf
;
3591 bfd_byte temp
[LONG_SIZE
];
3592 bfd_byte
*hashtable
;
3596 /* Ultrix appears to use as a hash table size the least power of two
3597 greater than twice the number of entries. */
3598 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3600 hashsize
= 1 << hashlog
;
3602 symdefsize
= hashsize
* 2 * LONG_SIZE
;
3604 stringsize
= stridx
+ padit
;
3606 /* Include 8 bytes to store symdefsize and stringsize in output. */
3607 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
3609 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3611 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3613 /* Work out the ECOFF armap name. */
3614 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3615 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3616 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3617 (abfd
->xvec
->header_byteorder_big_p
3619 : ARMAP_LITTLE_ENDIAN
);
3620 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3621 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3622 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3623 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3625 /* Write the timestamp of the archive header to be just a little bit
3626 later than the timestamp of the file, otherwise the linker will
3627 complain that the index is out of date. Actually, the Ultrix
3628 linker just checks the archive name; the GNU linker may check the
3630 stat (abfd
->filename
, &statbuf
);
3631 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3633 /* The DECstation uses zeroes for the uid, gid and mode of the
3635 hdr
.ar_uid
[0] = '0';
3636 hdr
.ar_gid
[0] = '0';
3637 hdr
.ar_mode
[0] = '0';
3639 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3641 hdr
.ar_fmag
[0] = '`';
3642 hdr
.ar_fmag
[1] = '\n';
3644 /* Turn all null bytes in the header into spaces. */
3645 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3646 if (((char *)(&hdr
))[i
] == '\0')
3647 (((char *)(&hdr
))[i
]) = ' ';
3649 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3650 != sizeof (struct ar_hdr
))
3653 bfd_h_put_32 (abfd
, hashsize
, temp
);
3654 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3657 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3659 current
= abfd
->archive_head
;
3661 for (i
= 0; i
< orl_count
; i
++)
3663 unsigned int hash
, rehash
;
3665 /* Advance firstreal to the file position of this archive
3667 if (((bfd
*) map
[i
].pos
) != last_elt
)
3671 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3672 firstreal
+= firstreal
% 2;
3673 current
= current
->next
;
3675 while (current
!= (bfd
*) map
[i
].pos
);
3680 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3681 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3682 + (hash
* 2 * LONG_SIZE
)
3688 /* The desired slot is already taken. */
3689 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3691 srch
= (srch
+ rehash
) & (hashsize
- 1))
3692 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3693 + (srch
* 2 * LONG_SIZE
)
3698 BFD_ASSERT (srch
!= hash
);
3703 bfd_h_put_32 (abfd
, map
[i
].namidx
,
3704 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
3705 bfd_h_put_32 (abfd
, firstreal
,
3706 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
3709 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3712 bfd_release (abfd
, hashtable
);
3714 /* Now write the strings. */
3715 bfd_h_put_32 (abfd
, stringsize
, temp
);
3716 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3718 for (i
= 0; i
< orl_count
; i
++)
3722 len
= strlen (*map
[i
].name
) + 1;
3723 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3727 /* The spec sez this should be a newline. But in order to be
3728 bug-compatible for DECstation ar we use a null. */
3731 if (bfd_write ("\0", 1, 1, abfd
) != 1)
3738 /* See whether this BFD is an archive. If it is, read in the armap
3739 and the extended name table. */
3742 ecoff_archive_p (abfd
)
3745 char armag
[SARMAG
+ 1];
3747 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3748 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3750 bfd_error
= wrong_format
;
3751 return (bfd_target
*) NULL
;
3754 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3755 involves a cast, we can't do it as the left operand of
3757 abfd
->tdata
.aout_ar_data
=
3758 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3760 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3762 bfd_error
= no_memory
;
3763 return (bfd_target
*) NULL
;
3766 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3768 if (ecoff_slurp_armap (abfd
) == false
3769 || ecoff_slurp_extended_name_table (abfd
) == false)
3771 bfd_release (abfd
, bfd_ardata (abfd
));
3772 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3773 return (bfd_target
*) NULL
;