1 /* BFD back-end for MIPS Extended-Coff files.
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"
38 #undef obj_sym_filepos
40 #include "coff/mips.h"
41 #include "coff/internal.h"
43 #include "coff/symconst.h"
44 #include "coff/ecoff-ext.h"
48 /* Each canonical asymbol really looks like this. */
50 typedef struct ecoff_symbol_struct
52 /* The actual symbol which the rest of BFD works with */
55 /* The fdr for this symbol. */
58 /* true if this is a local symbol rather than an external one. */
61 /* A pointer to the unswapped hidden information for this symbol */
64 struct sym_ext
*lnative
;
65 struct ext_ext
*enative
;
70 /* We take the address of the first element of a asymbol to ensure that the
71 macro is only ever applied to an asymbol. */
72 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
74 /* The page boundary used to align sections in the executable file. */
75 #define ROUND_SIZE 0x1000
77 /* The linker needs a section to hold small common variables while
78 linking. There is no convenient way to create it when the linker
79 needs it, so we always create one for each BFD. We then avoid
81 #define SCOMMON ".scommon"
83 /* MIPS ECOFF has COFF sections, but the debugging information is
84 stored in a completely different format. This files uses the some
85 of the swapping routines from coffswap.h, and some of the generic
86 COFF routines in coffgen.c, but, unlike the real COFF targets, does
87 not use coffcode.h itself. */
89 /* Prototypes for static functions. */
91 static boolean ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
92 static asection
*ecoff_make_section_hook
PARAMS ((bfd
*abfd
, char *name
));
93 static boolean ecoff_new_section_hook
PARAMS ((bfd
*abfd
, asection
*section
));
94 static boolean ecoff_mkobject
PARAMS ((bfd
*abfd
));
95 static PTR ecoff_mkobject_hook
PARAMS ((bfd
*abfd
, PTR filehdr
, PTR aouthdr
));
96 static boolean ecoff_set_arch_mach_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
97 static long ecoff_sec_to_styp_flags
PARAMS ((CONST
char *name
,
99 static flagword ecoff_styp_to_sec_flags
PARAMS ((bfd
*abfd
, PTR hdr
));
100 static asymbol
*ecoff_make_empty_symbol
PARAMS ((bfd
*abfd
));
101 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
102 asymbol
*asym
, int ext
,
103 asymbol
**indirect_ptr_ptr
));
104 static boolean ecoff_slurp_symbol_table
PARAMS ((bfd
*abfd
));
105 static unsigned int ecoff_get_symtab_upper_bound
PARAMS ((bfd
*abfd
));
106 static unsigned int ecoff_get_symtab
PARAMS ((bfd
*abfd
,
107 asymbol
**alocation
));
108 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
109 RNDXR
*rndx
, long isym
,
111 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
112 int indx
, int bigendian
));
113 static void ecoff_print_symbol
PARAMS ((bfd
*abfd
, PTR filep
,
115 bfd_print_symbol_type how
));
116 static void ecoff_get_symbol_info
PARAMS ((bfd
*abfd
,
119 static void ecoff_swap_reloc_in
PARAMS ((bfd
*abfd
, RELOC
*ext
,
120 struct internal_reloc
*intern
));
121 static unsigned int ecoff_swap_reloc_out
PARAMS ((bfd
*abfd
, PTR src
,
123 static bfd_reloc_status_type ecoff_generic_reloc
PARAMS ((bfd
*abfd
,
129 static bfd_reloc_status_type ecoff_refhi_reloc
PARAMS ((bfd
*abfd
,
135 static bfd_reloc_status_type ecoff_reflo_reloc
PARAMS ((bfd
*abfd
,
141 static bfd_reloc_status_type ecoff_gprel_reloc
PARAMS ((bfd
*abfd
,
147 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
149 static unsigned int ecoff_canonicalize_reloc
PARAMS ((bfd
*abfd
,
153 static CONST
struct reloc_howto_struct
*ecoff_bfd_reloc_type_lookup
154 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
155 static boolean ecoff_find_nearest_line
PARAMS ((bfd
*abfd
,
159 CONST
char **filename_ptr
,
160 CONST
char **fnname_ptr
,
161 unsigned int *retline_ptr
));
162 static void ecoff_clear_output_flags
PARAMS ((bfd
*abfd
));
163 static boolean ecoff_rel
PARAMS ((bfd
*output_bfd
, bfd_seclet_type
*seclet
,
164 asection
*output_section
, PTR data
,
165 boolean relocateable
));
166 static boolean ecoff_dump_seclet
PARAMS ((bfd
*abfd
, bfd_seclet_type
*seclet
,
167 asection
*section
, PTR data
,
168 boolean relocateable
));
169 static long ecoff_add_string
PARAMS ((bfd
*output_bfd
, FDR
*fdr
,
170 CONST
char *string
, boolean external
));
171 static boolean ecoff_get_debug
PARAMS ((bfd
*output_bfd
,
172 bfd_seclet_type
*seclet
,
174 boolean relocateable
));
175 static boolean ecoff_bfd_seclet_link
PARAMS ((bfd
*abfd
, PTR data
,
176 boolean relocateable
));
177 static boolean ecoff_set_arch_mach
PARAMS ((bfd
*abfd
,
178 enum bfd_architecture arch
,
179 unsigned long machine
));
180 static int ecoff_sizeof_headers
PARAMS ((bfd
*abfd
, boolean reloc
));
181 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
182 static boolean ecoff_set_section_contents
PARAMS ((bfd
*abfd
,
186 bfd_size_type count
));
187 static boolean ecoff_write_object_contents
PARAMS ((bfd
*abfd
));
188 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
189 unsigned int *rehash
,
192 static boolean ecoff_slurp_armap
PARAMS ((bfd
*abfd
));
193 static boolean ecoff_write_armap
PARAMS ((bfd
*abfd
, unsigned int elength
,
195 unsigned int orl_count
,
197 static bfd_target
*ecoff_archive_p
PARAMS ((bfd
*abfd
));
199 /* Get the generic COFF swapping routines, except for the reloc,
200 symbol, and lineno ones. Give them ecoff names. */
202 #define NO_COFF_RELOCS
203 #define NO_COFF_SYMBOLS
204 #define NO_COFF_LINENOS
205 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
206 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
207 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
208 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
209 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
210 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
211 #include "coffswap.h"
213 /* How to process the various relocs types. */
215 static reloc_howto_type ecoff_howto_table
[] =
217 /* Reloc type 0 is ignored. The reloc reading code ensures that
218 this is a reference to the .abs section, which will cause
219 bfd_perform_relocation to do nothing. */
220 HOWTO (ECOFF_R_IGNORE
, /* type */
222 0, /* size (0 = byte, 1 = short, 2 = long) */
223 8, /* bitsize (obsolete) */
224 false, /* pc_relative */
226 false, /* absolute (obsolete) */
227 false, /* complain_on_overflow */
228 0, /* special_function */
230 false, /* partial_inplace */
233 false), /* pcrel_offset */
235 /* A 16 bit reference to a symbol, normally from a data section. */
236 HOWTO (ECOFF_R_REFHALF
, /* type */
238 1, /* size (0 = byte, 1 = short, 2 = long) */
239 16, /* bitsize (obsolete) */
240 false, /* pc_relative */
242 false, /* absolute (obsolete) */
243 true, /* complain_on_overflow */
244 ecoff_generic_reloc
, /* special_function */
245 "REFHALF", /* name */
246 true, /* partial_inplace */
247 0xffff, /* src_mask */
248 0xffff, /* dst_mask */
249 false), /* pcrel_offset */
251 /* A 32 bit reference to a symbol, normally from a data section. */
252 HOWTO (ECOFF_R_REFWORD
, /* type */
254 2, /* size (0 = byte, 1 = short, 2 = long) */
255 32, /* bitsize (obsolete) */
256 false, /* pc_relative */
258 false, /* absolute (obsolete) */
259 true, /* complain_on_overflow */
260 ecoff_generic_reloc
, /* special_function */
261 "REFWORD", /* name */
262 true, /* partial_inplace */
263 0xffffffff, /* src_mask */
264 0xffffffff, /* dst_mask */
265 false), /* pcrel_offset */
267 /* A 26 bit absolute jump address. */
268 HOWTO (ECOFF_R_JMPADDR
, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
271 32, /* bitsize (obsolete) */
272 false, /* pc_relative */
274 false, /* absolute (obsolete) */
275 true, /* complain_on_overflow */
276 ecoff_generic_reloc
, /* special_function */
277 "JMPADDR", /* name */
278 true, /* partial_inplace */
279 0x3ffffff, /* src_mask */
280 0x3ffffff, /* dst_mask */
281 false), /* pcrel_offset */
283 /* The high 16 bits of a symbol value. Handled by the function
284 ecoff_refhi_reloc. */
285 HOWTO (ECOFF_R_REFHI
, /* type */
287 2, /* size (0 = byte, 1 = short, 2 = long) */
288 32, /* bitsize (obsolete) */
289 false, /* pc_relative */
291 false, /* absolute (obsolete) */
292 true, /* complain_on_overflow */
293 ecoff_refhi_reloc
, /* special_function */
295 true, /* partial_inplace */
296 0xffff, /* src_mask */
297 0xffff, /* dst_mask */
298 false), /* pcrel_offset */
300 /* The low 16 bits of a symbol value. */
301 HOWTO (ECOFF_R_REFLO
, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
304 32, /* bitsize (obsolete) */
305 false, /* pc_relative */
307 false, /* absolute (obsolete) */
308 true, /* complain_on_overflow */
309 ecoff_reflo_reloc
, /* special_function */
311 true, /* partial_inplace */
312 0xffff, /* src_mask */
313 0xffff, /* dst_mask */
314 false), /* pcrel_offset */
316 /* A reference to an offset from the gp register. Handled by the
317 function ecoff_gprel_reloc. */
318 HOWTO (ECOFF_R_GPREL
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
321 32, /* bitsize (obsolete) */
322 false, /* pc_relative */
324 false, /* absolute (obsolete) */
325 true, /* complain_on_overflow */
326 ecoff_gprel_reloc
, /* special_function */
328 true, /* partial_inplace */
329 0xffff, /* src_mask */
330 0xffff, /* dst_mask */
331 false), /* pcrel_offset */
333 /* A reference to a literal using an offset from the gp register.
334 Handled by the function ecoff_gprel_reloc. */
335 HOWTO (ECOFF_R_LITERAL
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
338 32, /* bitsize (obsolete) */
339 false, /* pc_relative */
341 false, /* absolute (obsolete) */
342 true, /* complain_on_overflow */
343 ecoff_gprel_reloc
, /* special_function */
344 "LITERAL", /* name */
345 true, /* partial_inplace */
346 0xffff, /* src_mask */
347 0xffff, /* dst_mask */
348 false) /* pcrel_offset */
351 #define ECOFF_HOWTO_COUNT \
352 (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0])
354 /* This stuff is somewhat copied from coffcode.h. */
356 static asection bfd_debug_section
= { "*DEBUG*" };
358 /* See whether the magic number matches. */
361 ecoff_bad_format_hook (abfd
, filehdr
)
365 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
367 if (ECOFFBADMAG (*internal_f
))
373 /* This is a hook needed by SCO COFF, but we have nothing to do. */
376 ecoff_make_section_hook (abfd
, name
)
380 return (asection
*) NULL
;
383 /* Initialize a new section. */
386 ecoff_new_section_hook (abfd
, section
)
390 section
->alignment_power
= abfd
->xvec
->align_power_min
;
392 if (strcmp (section
->name
, _TEXT
) == 0)
393 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
394 else if (strcmp (section
->name
, _DATA
) == 0
395 || strcmp (section
->name
, _SDATA
) == 0)
396 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
397 else if (strcmp (section
->name
, _RDATA
) == 0
398 || strcmp (section
->name
, _LIT8
) == 0
399 || strcmp (section
->name
, _LIT4
) == 0)
400 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
401 else if (strcmp (section
->name
, _BSS
) == 0
402 || strcmp (section
->name
, _SBSS
) == 0)
403 section
->flags
|= SEC_ALLOC
;
405 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
406 uncertain about .init on some systems and I don't know how shared
412 /* Set the alignment of a section; we have nothing to do. */
414 #define ecoff_set_alignment_hook \
415 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
417 /* Create an ECOFF object. */
420 ecoff_mkobject (abfd
)
423 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
424 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
425 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
427 bfd_error
= no_memory
;
431 /* Always create a .scommon section for every BFD. This is a hack so
432 that the linker has something to attach scSCommon symbols to. */
433 bfd_make_section (abfd
, SCOMMON
);
438 /* Create the ECOFF backend specific information. */
441 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
446 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
447 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
448 ecoff_data_type
*ecoff
;
450 if (ecoff_mkobject (abfd
) == false)
453 ecoff
= ecoff_data (abfd
);
455 ecoff
->sym_filepos
= internal_f
->f_symptr
;
457 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
461 ecoff
->text_start
= internal_a
->text_start
;
462 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
463 ecoff
->gp
= internal_a
->gp_value
;
464 ecoff
->gprmask
= internal_a
->gprmask
;
465 for (i
= 0; i
< 4; i
++)
466 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
467 if (internal_a
->magic
== ZMAGIC
)
468 abfd
->flags
|= D_PAGED
;
474 /* Determine the machine architecture and type. */
477 ecoff_set_arch_mach_hook (abfd
, filehdr
)
481 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
482 enum bfd_architecture arch
;
484 switch (internal_f
->f_magic
)
487 case MIPS_MAGIC_LITTLE
:
489 arch
= bfd_arch_mips
;
493 arch
= bfd_arch_obscure
;
497 bfd_default_set_arch_mach (abfd
, arch
, (unsigned long) 0);
502 /* Get the section s_flags to use for a section. */
505 ecoff_sec_to_styp_flags (name
, flags
)
513 if (strcmp (name
, _TEXT
) == 0)
515 else if (strcmp (name
, _DATA
) == 0)
517 else if (strcmp (name
, _SDATA
) == 0)
519 else if (strcmp (name
, _RDATA
) == 0)
521 else if (strcmp (name
, _LIT8
) == 0)
523 else if (strcmp (name
, _LIT4
) == 0)
525 else if (strcmp (name
, _BSS
) == 0)
527 else if (strcmp (name
, _SBSS
) == 0)
529 else if (strcmp (name
, _INIT
) == 0)
530 styp
= STYP_MIPS_INIT
;
531 else if (flags
& SEC_CODE
)
533 else if (flags
& SEC_DATA
)
535 else if (flags
& SEC_READONLY
)
537 else if (flags
& SEC_LOAD
)
542 if (flags
& SEC_NEVER_LOAD
)
548 /* Get the BFD flags to use for a section. */
551 ecoff_styp_to_sec_flags (abfd
, hdr
)
555 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
556 long styp_flags
= internal_s
->s_flags
;
557 flagword sec_flags
=0;
559 if (styp_flags
& STYP_NOLOAD
)
560 sec_flags
|= SEC_NEVER_LOAD
;
562 /* For 386 COFF, at least, an unloadable text or data section is
563 actually a shared library section. */
564 if ((styp_flags
& STYP_TEXT
)
565 || (styp_flags
& STYP_MIPS_INIT
))
567 if (sec_flags
& SEC_NEVER_LOAD
)
568 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
570 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
572 else if ((styp_flags
& STYP_DATA
)
573 || (styp_flags
& STYP_RDATA
)
574 || (styp_flags
& STYP_SDATA
))
576 if (sec_flags
& SEC_NEVER_LOAD
)
577 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
579 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
580 if (styp_flags
& STYP_RDATA
)
581 sec_flags
|= SEC_READONLY
;
583 else if ((styp_flags
& STYP_BSS
)
584 || (styp_flags
& STYP_SBSS
))
586 sec_flags
|= SEC_ALLOC
;
588 else if (styp_flags
& STYP_INFO
)
590 sec_flags
|= SEC_NEVER_LOAD
;
592 else if ((styp_flags
& STYP_LIT8
)
593 || (styp_flags
& STYP_LIT4
))
595 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
599 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
605 /* Read in and swap the important symbolic information for an ECOFF
606 object file. FIXME: This is called by gdb. If there is ever
607 another ECOFF target, it should be moved into some sort of target
608 specific structure. */
611 ecoff_slurp_symbolic_info (abfd
)
614 struct hdr_ext external_symhdr
;
615 HDRR
*internal_symhdr
;
616 bfd_size_type raw_base
;
617 bfd_size_type raw_size
;
619 struct fdr_ext
*fraw_src
;
620 struct fdr_ext
*fraw_end
;
623 /* Check whether we've already gotten it, and whether there's any to
625 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
627 if (ecoff_data (abfd
)->sym_filepos
== 0)
629 bfd_get_symcount (abfd
) = 0;
633 /* At this point bfd_get_symcount (abfd) holds the number of symbols
634 as read from the file header, but on ECOFF this is always the
635 size of the symbolic information header. It would be cleaner to
636 handle this when we first read the file in coffgen.c. */
637 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
639 bfd_error
= bad_value
;
643 /* Read the symbolic information header. */
644 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
645 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
646 != sizeof (external_symhdr
)))
648 bfd_error
= system_call_error
;
651 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
652 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
654 if (internal_symhdr
->magic
!= magicSym
)
656 bfd_error
= bad_value
;
660 /* Now we can get the correct number of symbols. */
661 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
662 + internal_symhdr
->iextMax
);
664 /* Read all the symbolic information at once. */
665 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
667 if (internal_symhdr
->cbExtOffset
!= 0)
668 raw_size
= (internal_symhdr
->cbExtOffset
670 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
673 long cbline
, issmax
, issextmax
;
675 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 3;
676 issmax
= (internal_symhdr
->issMax
+ 3) &~ 3;
677 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 3;
678 raw_size
= (cbline
* sizeof (unsigned char)
679 + internal_symhdr
->idnMax
* sizeof (struct dnr_ext
)
680 + internal_symhdr
->ipdMax
* sizeof (struct pdr_ext
)
681 + internal_symhdr
->isymMax
* sizeof (struct sym_ext
)
682 + internal_symhdr
->ioptMax
* sizeof (struct opt_ext
)
683 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
684 + issmax
* sizeof (char)
685 + issextmax
* sizeof (char)
686 + internal_symhdr
->ifdMax
* sizeof (struct fdr_ext
)
687 + internal_symhdr
->crfd
* sizeof (struct rfd_ext
)
688 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
693 ecoff_data (abfd
)->sym_filepos
= 0;
696 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
699 bfd_error
= no_memory
;
702 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
704 bfd_error
= system_call_error
;
705 bfd_release (abfd
, raw
);
709 ecoff_data (abfd
)->raw_size
= raw_size
;
710 ecoff_data (abfd
)->raw_syments
= raw
;
712 /* Get pointers for the numeric offsets in the HDRR structure. */
713 #define FIX(off1, off2, type) \
714 if (internal_symhdr->off1 == 0) \
715 ecoff_data (abfd)->off2 = (type *) NULL; \
717 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
718 + internal_symhdr->off1 \
720 FIX (cbLineOffset
, line
, unsigned char);
721 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
722 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
723 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
724 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
725 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
726 FIX (cbSsOffset
, ss
, char);
727 FIX (cbSsExtOffset
, ssext
, char);
728 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
729 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
730 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
733 /* I don't want to always swap all the data, because it will just
734 waste time and most programs will never look at it. The only
735 time the linker needs most of the debugging information swapped
736 is when linking big-endian and little-endian MIPS object files
737 together, which is not a common occurrence.
739 We need to look at the fdr to deal with a lot of information in
740 the symbols, so we swap them here. */
741 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
742 (internal_symhdr
->ifdMax
*
743 sizeof (struct fdr
)));
744 if (ecoff_data (abfd
)->fdr
== NULL
)
746 bfd_error
= no_memory
;
749 fdr_ptr
= ecoff_data (abfd
)->fdr
;
750 fraw_src
= ecoff_data (abfd
)->external_fdr
;
751 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
752 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
753 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
758 /* ECOFF symbol table routines. The ECOFF symbol table is described
759 in gcc/mips-tfile.c. */
761 /* ECOFF uses two common sections. One is the usual one, and the
762 other is for small objects. All the small objects are kept
763 together, and then referenced via the gp pointer, which yields
764 faster assembler code. This is what we use for the small common
766 static asection ecoff_scom_section
;
767 static asymbol ecoff_scom_symbol
;
768 static asymbol
*ecoff_scom_symbol_ptr
;
770 /* Create an empty symbol. */
773 ecoff_make_empty_symbol (abfd
)
776 ecoff_symbol_type
*new;
778 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
779 if (new == (ecoff_symbol_type
*) NULL
)
781 bfd_error
= no_memory
;
782 return (asymbol
*) NULL
;
784 memset (new, 0, sizeof *new);
785 new->symbol
.section
= (asection
*) NULL
;
786 new->fdr
= (FDR
*) NULL
;
788 new->native
.lnative
= (struct sym_ext
*) NULL
;
789 new->symbol
.the_bfd
= abfd
;
793 /* Set the BFD flags and section for an ECOFF symbol. */
796 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
801 asymbol
**indirect_ptr_ptr
;
803 asym
->the_bfd
= abfd
;
804 asym
->value
= ecoff_sym
->value
;
805 asym
->section
= &bfd_debug_section
;
808 /* An indirect symbol requires two consecutive stabs symbols. */
809 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
811 BFD_ASSERT (MIPS_IS_STAB (ecoff_sym
));
812 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
813 asym
->flags
= BSF_DEBUGGING
;
814 asym
->section
= &bfd_und_section
;
815 *indirect_ptr_ptr
= NULL
;
819 if (MIPS_IS_STAB (ecoff_sym
)
820 && (MIPS_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
822 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
823 asym
->section
= &bfd_ind_section
;
824 /* Pass this symbol on to the next call to this function. */
825 *indirect_ptr_ptr
= asym
;
829 /* Most symbol types are just for debugging. */
830 switch (ecoff_sym
->st
)
839 if (MIPS_IS_STAB (ecoff_sym
))
841 asym
->flags
= BSF_DEBUGGING
;
846 asym
->flags
= BSF_DEBUGGING
;
851 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
853 asym
->flags
= BSF_LOCAL
;
854 switch (ecoff_sym
->sc
)
857 /* Used for compiler generated labels. Leave them in the
858 debugging section, and mark them as local. If BSF_DEBUGGING
859 is set, then nm does not display them for some reason. If no
860 flags are set then the linker whines about them. */
861 asym
->flags
= BSF_LOCAL
;
864 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
865 asym
->value
-= asym
->section
->vma
;
868 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
869 asym
->value
-= asym
->section
->vma
;
874 asym
->section
= &bfd_com_section
;
879 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
880 asym
->value
-= asym
->section
->vma
;
884 asym
->flags
= BSF_DEBUGGING
;
887 asym
->section
= &bfd_abs_section
;
890 asym
->section
= &bfd_und_section
;
900 asym
->flags
= BSF_DEBUGGING
;
903 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
904 asym
->value
-= asym
->section
->vma
;
907 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
909 asym
->value
-= asym
->section
->vma
;
912 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
913 asym
->value
-= asym
->section
->vma
;
916 asym
->flags
= BSF_DEBUGGING
;
919 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
921 asym
->section
= &bfd_com_section
;
927 if (ecoff_scom_section
.name
== NULL
)
929 /* Initialize the small common section. */
930 ecoff_scom_section
.name
= SCOMMON
;
931 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
932 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
933 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
934 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
935 ecoff_scom_symbol
.name
= SCOMMON
;
936 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
937 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
938 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
940 asym
->section
= &ecoff_scom_section
;
945 asym
->flags
= BSF_DEBUGGING
;
948 asym
->section
= &bfd_und_section
;
953 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
954 asym
->value
-= asym
->section
->vma
;
959 asym
->flags
= BSF_DEBUGGING
;
962 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
963 asym
->value
-= asym
->section
->vma
;
969 /* Look for special constructors symbols and make relocation entries
970 in a special construction section. These are produced by the
971 -fgnu-linker argument to g++. */
972 if (MIPS_IS_STAB (ecoff_sym
))
974 switch (MIPS_UNMARK_STAB (ecoff_sym
->index
))
986 arelent_chain
*reloc_chain
;
988 /* Get a section with the same name as the symbol (usually
989 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
990 name ___CTOR_LIST (three underscores). We need
991 __CTOR_LIST (two underscores), since ECOFF doesn't use
992 a leading underscore. This should be handled by gcc,
993 but instead we do it here. Actually, this should all
994 be done differently anyhow. */
995 name
= bfd_asymbol_name (asym
);
996 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1001 section
= bfd_get_section_by_name (abfd
, name
);
1002 if (section
== (asection
*) NULL
)
1006 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1007 strcpy (copy
, name
);
1008 section
= bfd_make_section (abfd
, copy
);
1011 /* Build a reloc pointing to this constructor. */
1012 reloc_chain
= (arelent_chain
*) bfd_alloc (abfd
,
1013 sizeof (arelent_chain
));
1014 reloc_chain
->relent
.sym_ptr_ptr
=
1015 bfd_get_section (asym
)->symbol_ptr_ptr
;
1016 reloc_chain
->relent
.address
= section
->_raw_size
;
1017 reloc_chain
->relent
.addend
= asym
->value
;
1019 /* FIXME: Assumes 32 bit __CTOR_LIST__ entries. */
1020 reloc_chain
->relent
.howto
= ecoff_howto_table
+ ECOFF_R_REFWORD
;
1022 /* Set up the constructor section to hold the reloc. */
1023 section
->flags
= SEC_CONSTRUCTOR
;
1024 ++section
->reloc_count
;
1026 /* Constructor sections must be rounded to a four byte
1027 boundary (FIXME: assuming 32 bit entries). These are
1028 not real sections--they are handled specially by the
1029 linker--so the ECOFF 16 byte alignment restriction does
1031 section
->alignment_power
= 2;
1033 reloc_chain
->next
= section
->constructor_chain
;
1034 section
->constructor_chain
= reloc_chain
;
1036 /* FIXME: Assumes 32 bit __CTOR_LIST__ entries. */
1037 section
->_raw_size
+= 4;
1039 /* Mark the symbol as a constructor. */
1040 asym
->flags
|= BSF_CONSTRUCTOR
;
1047 /* Read an ECOFF symbol table. */
1050 ecoff_slurp_symbol_table (abfd
)
1053 bfd_size_type internal_size
;
1054 ecoff_symbol_type
*internal
;
1055 ecoff_symbol_type
*internal_ptr
;
1056 asymbol
*indirect_ptr
;
1057 struct ext_ext
*eraw_src
;
1058 struct ext_ext
*eraw_end
;
1062 /* If we've already read in the symbol table, do nothing. */
1063 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1066 /* Get the symbolic information. */
1067 if (ecoff_slurp_symbolic_info (abfd
) == false)
1069 if (bfd_get_symcount (abfd
) == 0)
1072 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1073 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1074 if (internal
== NULL
)
1076 bfd_error
= no_memory
;
1080 internal_ptr
= internal
;
1081 indirect_ptr
= NULL
;
1082 eraw_src
= ecoff_data (abfd
)->external_ext
;
1083 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
1084 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
1088 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
1089 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
1090 + internal_esym
.asym
.iss
);
1091 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1092 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1093 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
1094 internal_ptr
->local
= false;
1095 internal_ptr
->native
.enative
= eraw_src
;
1097 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1099 /* The local symbols must be accessed via the fdr's, because the
1100 string and aux indices are relative to the fdr information. */
1101 fdr_ptr
= ecoff_data (abfd
)->fdr
;
1102 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1103 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1105 struct sym_ext
*lraw_src
;
1106 struct sym_ext
*lraw_end
;
1108 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
1109 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
1110 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
1114 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
1115 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
1117 + internal_sym
.iss
);
1118 ecoff_set_symbol_info (abfd
, &internal_sym
,
1119 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1120 internal_ptr
->fdr
= fdr_ptr
;
1121 internal_ptr
->local
= true;
1122 internal_ptr
->native
.lnative
= lraw_src
;
1125 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1127 ecoff_data (abfd
)->canonical_symbols
= internal
;
1133 ecoff_get_symtab_upper_bound (abfd
)
1136 if (ecoff_slurp_symbolic_info (abfd
) == false
1137 || bfd_get_symcount (abfd
) == 0)
1140 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1144 ecoff_get_symtab (abfd
, alocation
)
1146 asymbol
**alocation
;
1148 unsigned int counter
= 0;
1149 ecoff_symbol_type
*symbase
;
1150 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1152 if (ecoff_slurp_symbol_table (abfd
) == false
1153 || bfd_get_symcount (abfd
) == 0)
1156 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1157 while (counter
< bfd_get_symcount (abfd
))
1159 *(location
++) = symbase
++;
1162 *location
++ = (ecoff_symbol_type
*) NULL
;
1163 return bfd_get_symcount (abfd
);
1166 /* Turn ECOFF type information into a printable string.
1167 ecoff_emit_aggregate and ecoff_type_to_string are from
1168 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1170 /* Write aggregate information to a string. */
1173 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1180 int ifd
= rndx
->rfd
;
1181 int indx
= rndx
->index
;
1182 int sym_base
, ss_base
;
1188 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
1189 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
1191 if (indx
== indexNil
)
1192 name
= "/* no name */";
1198 ecoff_swap_sym_in (abfd
,
1199 ecoff_data (abfd
)->external_sym
+ indx
,
1201 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
1205 "%s %s { ifd = %d, index = %d }",
1207 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
1210 /* Convert the type information to string format. */
1213 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1215 union aux_ext
*aux_ptr
;
1227 unsigned int basic_type
;
1229 static char buffer1
[1024];
1230 static char buffer2
[1024];
1235 for (i
= 0; i
< 7; i
++)
1237 qualifiers
[i
].low_bound
= 0;
1238 qualifiers
[i
].high_bound
= 0;
1239 qualifiers
[i
].stride
= 0;
1242 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1243 return "-1 (no type)";
1244 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1246 basic_type
= u
.ti
.bt
;
1247 qualifiers
[0].type
= u
.ti
.tq0
;
1248 qualifiers
[1].type
= u
.ti
.tq1
;
1249 qualifiers
[2].type
= u
.ti
.tq2
;
1250 qualifiers
[3].type
= u
.ti
.tq3
;
1251 qualifiers
[4].type
= u
.ti
.tq4
;
1252 qualifiers
[5].type
= u
.ti
.tq5
;
1253 qualifiers
[6].type
= tqNil
;
1256 * Go get the basic type.
1260 case btNil
: /* undefined */
1264 case btAdr
: /* address - integer same size as pointer */
1265 strcpy (p1
, "address");
1268 case btChar
: /* character */
1269 strcpy (p1
, "char");
1272 case btUChar
: /* unsigned character */
1273 strcpy (p1
, "unsigned char");
1276 case btShort
: /* short */
1277 strcpy (p1
, "short");
1280 case btUShort
: /* unsigned short */
1281 strcpy (p1
, "unsigned short");
1284 case btInt
: /* int */
1288 case btUInt
: /* unsigned int */
1289 strcpy (p1
, "unsigned int");
1292 case btLong
: /* long */
1293 strcpy (p1
, "long");
1296 case btULong
: /* unsigned long */
1297 strcpy (p1
, "unsigned long");
1300 case btFloat
: /* float (real) */
1301 strcpy (p1
, "float");
1304 case btDouble
: /* Double (real) */
1305 strcpy (p1
, "double");
1308 /* Structures add 1-2 aux words:
1309 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1310 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1312 case btStruct
: /* Structure (Record) */
1313 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1314 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1315 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1317 indx
++; /* skip aux words */
1320 /* Unions add 1-2 aux words:
1321 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1322 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1324 case btUnion
: /* Union */
1325 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1326 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1327 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1329 indx
++; /* skip aux words */
1332 /* Enumerations add 1-2 aux words:
1333 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1334 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1336 case btEnum
: /* Enumeration */
1337 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1338 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1339 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1341 indx
++; /* skip aux words */
1344 case btTypedef
: /* defined via a typedef, isymRef points */
1345 strcpy (p1
, "typedef");
1348 case btRange
: /* subrange of int */
1349 strcpy (p1
, "subrange");
1352 case btSet
: /* pascal sets */
1356 case btComplex
: /* fortran complex */
1357 strcpy (p1
, "complex");
1360 case btDComplex
: /* fortran double complex */
1361 strcpy (p1
, "double complex");
1364 case btIndirect
: /* forward or unnamed typedef */
1365 strcpy (p1
, "forward/unamed typedef");
1368 case btFixedDec
: /* Fixed Decimal */
1369 strcpy (p1
, "fixed decimal");
1372 case btFloatDec
: /* Float Decimal */
1373 strcpy (p1
, "float decimal");
1376 case btString
: /* Varying Length Character String */
1377 strcpy (p1
, "string");
1380 case btBit
: /* Aligned Bit String */
1384 case btPicture
: /* Picture */
1385 strcpy (p1
, "picture");
1388 case btVoid
: /* Void */
1389 strcpy (p1
, "void");
1393 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1397 p1
+= strlen (buffer1
);
1400 * If this is a bitfield, get the bitsize.
1406 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1407 sprintf (p1
, " : %d", bitsize
);
1408 p1
+= strlen (buffer1
);
1413 * Deal with any qualifiers.
1415 if (qualifiers
[0].type
!= tqNil
)
1418 * Snarf up any array bounds in the correct order. Arrays
1419 * store 5 successive words in the aux. table:
1420 * word 0 RNDXR to type of the bounds (ie, int)
1421 * word 1 Current file descriptor index
1423 * word 3 high bound (or -1 if [])
1424 * word 4 stride size in bits
1426 for (i
= 0; i
< 7; i
++)
1428 if (qualifiers
[i
].type
== tqArray
)
1430 qualifiers
[i
].low_bound
=
1431 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1432 qualifiers
[i
].high_bound
=
1433 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1434 qualifiers
[i
].stride
=
1435 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1441 * Now print out the qualifiers.
1443 for (i
= 0; i
< 6; i
++)
1445 switch (qualifiers
[i
].type
)
1452 strcpy (p2
, "ptr to ");
1453 p2
+= sizeof ("ptr to ")-1;
1457 strcpy (p2
, "volatile ");
1458 p2
+= sizeof ("volatile ")-1;
1462 strcpy (p2
, "far ");
1463 p2
+= sizeof ("far ")-1;
1467 strcpy (p2
, "func. ret. ");
1468 p2
+= sizeof ("func. ret. ");
1473 int first_array
= i
;
1476 /* Print array bounds reversed (ie, in the order the C
1477 programmer writes them). C is such a fun language.... */
1479 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1482 for (j
= i
; j
>= first_array
; j
--)
1484 strcpy (p2
, "array [");
1485 p2
+= sizeof ("array [")-1;
1486 if (qualifiers
[j
].low_bound
!= 0)
1488 "%ld:%ld {%ld bits}",
1489 (long) qualifiers
[j
].low_bound
,
1490 (long) qualifiers
[j
].high_bound
,
1491 (long) qualifiers
[j
].stride
);
1493 else if (qualifiers
[j
].high_bound
!= -1)
1496 (long) (qualifiers
[j
].high_bound
+ 1),
1497 (long) (qualifiers
[j
].stride
));
1500 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1503 strcpy (p2
, "] of ");
1504 p2
+= sizeof ("] of ")-1;
1512 strcpy (p2
, buffer1
);
1516 /* Return information about ECOFF symbol SYMBOL in RET. */
1519 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1520 bfd
*abfd
; /* Ignored. */
1524 bfd_symbol_info (symbol
, ret
);
1527 /* Print information about an ECOFF symbol. */
1530 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1534 bfd_print_symbol_type how
;
1536 FILE *file
= (FILE *)filep
;
1540 case bfd_print_symbol_name
:
1541 fprintf (file
, "%s", symbol
->name
);
1543 case bfd_print_symbol_more
:
1544 if (ecoffsymbol (symbol
)->local
)
1548 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1550 fprintf (file
, "ecoff local %lx %x %x",
1551 (unsigned long) ecoff_sym
.value
,
1552 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1558 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1560 fprintf (file
, "ecoff extern %lx %x %x",
1561 (unsigned long) ecoff_ext
.asym
.value
,
1562 (unsigned) ecoff_ext
.asym
.st
,
1563 (unsigned) ecoff_ext
.asym
.sc
);
1566 case bfd_print_symbol_all
:
1567 /* Print out the symbols in a reasonable way */
1576 if (ecoffsymbol (symbol
)->local
)
1578 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1581 pos
= (ecoffsymbol (symbol
)->native
.lnative
1582 - ecoff_data (abfd
)->external_sym
1583 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1590 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1593 pos
= (ecoffsymbol (symbol
)->native
.enative
1594 - ecoff_data (abfd
)->external_ext
);
1595 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1596 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1597 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1600 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1601 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1602 (unsigned) ecoff_ext
.asym
.st
,
1603 (unsigned) ecoff_ext
.asym
.sc
,
1604 (unsigned) ecoff_ext
.asym
.index
,
1605 jmptbl
, cobol_main
, weakext
,
1608 if (ecoffsymbol (symbol
)->fdr
!= NULL
1609 && ecoff_ext
.asym
.index
!= indexNil
)
1614 union aux_ext
*aux_base
;
1616 indx
= ecoff_ext
.asym
.index
;
1618 /* sym_base is used to map the fdr relative indices which
1619 appear in the file to the position number which we are
1621 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1622 if (ecoffsymbol (symbol
)->local
)
1623 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1625 /* aux_base is the start of the aux entries for this file;
1626 asym.index is an offset from this. */
1627 aux_base
= (ecoff_data (abfd
)->external_aux
1628 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1630 /* The aux entries are stored in host byte order; the
1631 order is indicated by a bit in the fdr. */
1632 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1634 /* This switch is basically from gcc/mips-tdump.c */
1635 switch (ecoff_ext
.asym
.st
)
1643 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1647 if (ecoff_ext
.asym
.sc
== scText
1648 || ecoff_ext
.asym
.sc
== scInfo
)
1649 printf ("\n First symbol: %ld", indx
+ sym_base
);
1651 printf ("\n First symbol: %ld",
1652 (long) (AUX_GET_ISYM (bigendian
,
1653 &aux_base
[ecoff_ext
.asym
.index
])
1659 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1661 else if (ecoffsymbol (symbol
)->local
)
1662 printf ("\n End+1 symbol: %-7ld Type: %s",
1663 (long) (AUX_GET_ISYM (bigendian
,
1664 &aux_base
[ecoff_ext
.asym
.index
])
1666 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1669 printf ("\n Local symbol: %d",
1672 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1676 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1677 printf ("\n Type: %s",
1678 ecoff_type_to_string (abfd
, aux_base
, indx
,
1688 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1689 external form. They use a bit which indicates whether the symbol
1692 /* Swap a reloc in. */
1695 ecoff_swap_reloc_in (abfd
, ext
, intern
)
1698 struct internal_reloc
*intern
;
1700 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
1701 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1703 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1704 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
1705 | ((int) ext
->r_bits
[1]
1706 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
1707 | ((int) ext
->r_bits
[2]
1708 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
1709 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
1710 >> RELOC_BITS3_TYPE_SH_BIG
);
1711 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
1715 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1716 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
1717 | ((int) ext
->r_bits
[1]
1718 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
1719 | ((int) ext
->r_bits
[2]
1720 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
1721 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
1722 >> RELOC_BITS3_TYPE_SH_LITTLE
);
1723 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
1727 /* Swap a reloc out. */
1730 ecoff_swap_reloc_out (abfd
, src
, dst
)
1735 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
1736 RELOC
*ext
= (RELOC
*) dst
;
1738 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
1739 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1741 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
1742 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
1743 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
1744 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
1745 & RELOC_BITS3_TYPE_BIG
)
1746 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
1750 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
1751 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
1752 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
1753 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
1754 & RELOC_BITS3_TYPE_LITTLE
)
1755 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
1761 /* ECOFF relocs are either against external symbols, or against
1762 sections. If we are producing relocateable output, and the reloc
1763 is against an external symbol, and nothing has given us any
1764 additional addend, the resulting reloc will also be against the
1765 same symbol. In such a case, we don't want to change anything
1766 about the way the reloc is handled, since it will all be done at
1767 final link time. Rather than put special case code into
1768 bfd_perform_relocation, all the reloc types use this howto
1769 function. It just short circuits the reloc if producing
1770 relocateable output against an external symbol. */
1772 static bfd_reloc_status_type
1773 ecoff_generic_reloc (abfd
,
1780 arelent
*reloc_entry
;
1783 asection
*input_section
;
1786 if (output_bfd
!= (bfd
*) NULL
1787 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1788 && reloc_entry
->addend
== 0)
1790 reloc_entry
->address
+= input_section
->output_offset
;
1791 return bfd_reloc_ok
;
1794 return bfd_reloc_continue
;
1797 /* Do a REFHI relocation. This has to be done in combination with a
1798 REFLO reloc, because there is a carry from the REFLO to the REFHI.
1799 Here we just save the information we need; we do the actual
1800 relocation when we see the REFLO. ECOFF requires that the REFLO
1801 immediately follow the REFHI, so this ought to work. */
1803 static bfd_byte
*ecoff_refhi_addr
;
1804 static bfd_vma ecoff_refhi_addend
;
1806 static bfd_reloc_status_type
1807 ecoff_refhi_reloc (abfd
,
1814 arelent
*reloc_entry
;
1817 asection
*input_section
;
1820 bfd_reloc_status_type ret
;
1823 /* If we're relocating, and this an external symbol, we don't want
1824 to change anything. */
1825 if (output_bfd
!= (bfd
*) NULL
1826 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1827 && reloc_entry
->addend
== 0)
1829 reloc_entry
->address
+= input_section
->output_offset
;
1830 return bfd_reloc_ok
;
1834 if (symbol
->section
== &bfd_und_section
1835 && output_bfd
== (bfd
*) NULL
)
1836 ret
= bfd_reloc_undefined
;
1838 if (bfd_is_com_section (symbol
->section
))
1841 relocation
= symbol
->value
;
1843 relocation
+= symbol
->section
->output_section
->vma
;
1844 relocation
+= symbol
->section
->output_offset
;
1845 relocation
+= reloc_entry
->addend
;
1847 if (reloc_entry
->address
> input_section
->_cooked_size
)
1848 return bfd_reloc_outofrange
;
1850 /* Save the information, and let REFLO do the actual relocation. */
1851 ecoff_refhi_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1852 ecoff_refhi_addend
= relocation
;
1854 if (output_bfd
!= (bfd
*) NULL
)
1855 reloc_entry
->address
+= input_section
->output_offset
;
1860 /* Do a REFLO relocation. This is a straightforward 16 bit inplace
1861 relocation; this function exists in order to do the REFHI
1862 relocation described above. */
1864 static bfd_reloc_status_type
1865 ecoff_reflo_reloc (abfd
,
1872 arelent
*reloc_entry
;
1875 asection
*input_section
;
1878 if (ecoff_refhi_addr
!= (bfd_byte
*) NULL
)
1882 unsigned long vallo
;
1884 /* Do the REFHI relocation. Note that we actually don't need to
1885 know anything about the REFLO itself, except where to find
1886 the low 16 bits of the addend needed by the REFHI. */
1887 insn
= bfd_get_32 (abfd
, ecoff_refhi_addr
);
1888 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1890 val
= ((insn
& 0xffff) << 16) + vallo
;
1891 val
+= ecoff_refhi_addend
;
1893 /* The low order 16 bits are always treated as a signed value.
1894 Therefore, a negative value in the low order bits requires an
1895 adjustment in the high order bits. We need to make this
1896 adjustment in two ways: once for the bits we took from the
1897 data, and once for the bits we are putting back in to the
1899 if ((vallo
& 0x8000) != 0)
1901 if ((val
& 0x8000) != 0)
1904 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1905 bfd_put_32 (abfd
, insn
, ecoff_refhi_addr
);
1907 ecoff_refhi_addr
= (bfd_byte
*) NULL
;
1910 /* Now do the REFLO reloc in the usual way. */
1911 return ecoff_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1912 input_section
, output_bfd
);
1915 /* Do a GPREL relocation. This is a 16 bit value which must become
1916 the offset from the gp register. */
1918 static bfd_reloc_status_type
1919 ecoff_gprel_reloc (abfd
,
1926 arelent
*reloc_entry
;
1929 asection
*input_section
;
1932 boolean relocateable
;
1937 /* If we're relocating, and this is an external symbol with no
1938 addend, we don't want to change anything. We will only have an
1939 addend if this is a newly created reloc, not read from an ECOFF
1941 if (output_bfd
!= (bfd
*) NULL
1942 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1943 && reloc_entry
->addend
== 0)
1945 reloc_entry
->address
+= input_section
->output_offset
;
1946 return bfd_reloc_ok
;
1949 if (output_bfd
!= (bfd
*) NULL
)
1950 relocateable
= true;
1953 relocateable
= false;
1954 output_bfd
= symbol
->section
->output_section
->owner
;
1957 if (symbol
->section
== &bfd_und_section
1958 && relocateable
== false)
1959 return bfd_reloc_undefined
;
1961 /* We have to figure out the gp value, so that we can adjust the
1962 symbol value correctly. We look up the symbol _gp in the output
1963 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1964 target data. We don't need to adjust the symbol value for an
1965 external symbol if we are producing relocateable output. */
1966 if (ecoff_data (output_bfd
)->gp
== 0
1967 && (relocateable
== false
1968 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1970 if (relocateable
!= false)
1972 /* Make up a value. */
1973 ecoff_data (output_bfd
)->gp
=
1974 symbol
->section
->output_section
->vma
+ 0x4000;
1982 count
= bfd_get_symcount (output_bfd
);
1983 sym
= bfd_get_outsymbols (output_bfd
);
1985 /* We should do something more friendly here, but we don't
1986 have a good reloc status to return. */
1987 if (sym
== (asymbol
**) NULL
)
1990 for (i
= 0; i
< count
; i
++, sym
++)
1992 register CONST
char *name
;
1994 name
= bfd_asymbol_name (*sym
);
1995 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1997 ecoff_data (output_bfd
)->gp
= bfd_asymbol_value (*sym
);
2002 /* We should do something more friendly here, but we don't have
2003 a good reloc status to return. */
2009 if (bfd_is_com_section (symbol
->section
))
2012 relocation
= symbol
->value
;
2014 relocation
+= symbol
->section
->output_section
->vma
;
2015 relocation
+= symbol
->section
->output_offset
;
2017 if (reloc_entry
->address
> input_section
->_cooked_size
)
2018 return bfd_reloc_outofrange
;
2020 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2022 /* Set val to the offset into the section or symbol. */
2023 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
2027 /* Adjust val for the final section location and GP value. If we
2028 are producing relocateable output, we don't want to do this for
2029 an external symbol. */
2030 if (relocateable
== false
2031 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2032 val
+= relocation
- ecoff_data (output_bfd
)->gp
;
2034 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
2035 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
2037 if (relocateable
!= false)
2038 reloc_entry
->address
+= input_section
->output_offset
;
2040 /* Make sure it fit in 16 bits. */
2041 if (val
>= 0x8000 && val
< 0xffff8000)
2042 return bfd_reloc_outofrange
;
2044 return bfd_reloc_ok
;
2047 /* Read in the relocs for a section. */
2050 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
2055 RELOC
*external_relocs
;
2056 arelent
*internal_relocs
;
2060 if (section
->relocation
!= (arelent
*) NULL
2061 || section
->reloc_count
== 0
2062 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
2065 if (ecoff_slurp_symbol_table (abfd
) == false)
2068 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
2070 * section
->reloc_count
));
2071 external_relocs
= (RELOC
*) bfd_alloc (abfd
, RELSZ
* section
->reloc_count
);
2072 if (internal_relocs
== (arelent
*) NULL
2073 || external_relocs
== (RELOC
*) NULL
)
2075 bfd_error
= no_memory
;
2078 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
2080 if (bfd_read (external_relocs
, 1, RELSZ
* section
->reloc_count
, abfd
)
2081 != RELSZ
* section
->reloc_count
)
2083 bfd_error
= system_call_error
;
2087 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
2089 struct internal_reloc intern
;
2091 ecoff_swap_reloc_in (abfd
, external_relocs
+ i
, &intern
);
2093 if (intern
.r_type
> ECOFF_R_LITERAL
)
2096 if (intern
.r_extern
)
2098 /* r_symndx is an index into the external symbols. */
2099 BFD_ASSERT (intern
.r_symndx
>= 0
2101 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
2102 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
2107 CONST
char *sec_name
;
2110 /* r_symndx is a section key. */
2111 switch (intern
.r_symndx
)
2113 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
2114 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
2115 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
2116 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
2117 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
2118 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
2119 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
2120 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
2121 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
2125 sec
= bfd_get_section_by_name (abfd
, sec_name
);
2126 if (sec
== (asection
*) NULL
)
2128 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
2130 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
2131 if (intern
.r_type
== ECOFF_R_GPREL
2132 || intern
.r_type
== ECOFF_R_LITERAL
)
2133 rptr
->addend
+= ecoff_data (abfd
)->gp
;
2136 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
2137 rptr
->howto
= &ecoff_howto_table
[intern
.r_type
];
2139 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
2140 to the absolute section so that the reloc is ignored. */
2141 if (intern
.r_type
== ECOFF_R_IGNORE
)
2142 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
2145 bfd_release (abfd
, external_relocs
);
2147 section
->relocation
= internal_relocs
;
2152 /* Get a canonical list of relocs. */
2155 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
2163 if (section
->flags
& SEC_CONSTRUCTOR
)
2165 arelent_chain
*chain
;
2167 /* This section has relocs made up by us, not the file, so take
2168 them out of their chain and place them into the data area
2170 for (count
= 0, chain
= section
->constructor_chain
;
2171 count
< section
->reloc_count
;
2172 count
++, chain
= chain
->next
)
2173 *relptr
++ = &chain
->relent
;
2179 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
2182 tblptr
= section
->relocation
;
2183 if (tblptr
== (arelent
*) NULL
)
2186 for (count
= 0; count
< section
->reloc_count
; count
++)
2187 *relptr
++ = tblptr
++;
2190 *relptr
= (arelent
*) NULL
;
2192 return section
->reloc_count
;
2195 /* Get the howto structure for a generic reloc type. */
2197 static CONST
struct reloc_howto_struct
*
2198 ecoff_bfd_reloc_type_lookup (abfd
, code
)
2200 bfd_reloc_code_real_type code
;
2207 ecoff_type
= ECOFF_R_REFHALF
;
2210 ecoff_type
= ECOFF_R_REFWORD
;
2212 case BFD_RELOC_MIPS_JMP
:
2213 ecoff_type
= ECOFF_R_JMPADDR
;
2215 case BFD_RELOC_HI16_S
:
2216 ecoff_type
= ECOFF_R_REFHI
;
2218 case BFD_RELOC_LO16
:
2219 ecoff_type
= ECOFF_R_REFLO
;
2221 case BFD_RELOC_MIPS_GPREL
:
2222 ecoff_type
= ECOFF_R_GPREL
;
2225 return (CONST
struct reloc_howto_struct
*) NULL
;
2228 return &ecoff_howto_table
[ecoff_type
];
2231 /* Provided a BFD, a section and an offset into the section, calculate
2232 and return the name of the source file and the line nearest to the
2236 ecoff_find_nearest_line (abfd
,
2245 asymbol
**ignore_symbols
;
2247 CONST
char **filename_ptr
;
2248 CONST
char **functionname_ptr
;
2249 unsigned int *retline_ptr
;
2255 struct pdr_ext
*pdr_ptr
;
2256 struct pdr_ext
*pdr_end
;
2258 unsigned char *line_ptr
;
2259 unsigned char *line_end
;
2262 /* If we're not in the .text section, we don't have any line
2264 if (strcmp (section
->name
, _TEXT
) != 0
2265 || offset
< ecoff_data (abfd
)->text_start
2266 || offset
>= ecoff_data (abfd
)->text_end
)
2269 /* Make sure we have the FDR's. */
2270 if (ecoff_slurp_symbolic_info (abfd
) == false
2271 || bfd_get_symcount (abfd
) == 0)
2274 /* Each file descriptor (FDR) has a memory address. Here we track
2275 down which FDR we want. The FDR's are stored in increasing
2276 memory order. If speed is ever important, this can become a
2277 binary search. We must ignore FDR's with no PDR entries; they
2278 will have the adr of the FDR before or after them. */
2279 fdr_start
= ecoff_data (abfd
)->fdr
;
2280 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
2281 fdr_hold
= (FDR
*) NULL
;
2282 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2284 if (fdr_ptr
->cpd
== 0)
2286 if (offset
< fdr_ptr
->adr
)
2290 if (fdr_hold
== (FDR
*) NULL
)
2294 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2295 have an address, which is relative to the FDR address, and are
2296 also stored in increasing memory order. */
2297 offset
-= fdr_ptr
->adr
;
2298 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
2299 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
2300 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2302 /* The address of the first PDR is an offset which applies to the
2303 addresses of all the PDR's. */
2306 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
2308 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2309 if (offset
< pdr
.adr
)
2313 /* Now we can look for the actual line number. The line numbers are
2314 stored in a very funky format, which I won't try to describe.
2315 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2316 we want; we need this to compute line_end. */
2317 line_end
= ecoff_data (abfd
)->line
;
2318 if (pdr_ptr
== pdr_end
)
2319 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2321 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2323 /* Now change pdr and pdr_ptr to the one we want. */
2325 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2329 line_ptr
= (ecoff_data (abfd
)->line
2330 + fdr_ptr
->cbLineOffset
2331 + pdr
.cbLineOffset
);
2332 while (line_ptr
< line_end
)
2337 delta
= *line_ptr
>> 4;
2340 count
= (*line_ptr
& 0xf) + 1;
2344 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2345 if (delta
>= 0x8000)
2350 if (offset
< count
* 4)
2352 offset
-= count
* 4;
2355 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2356 at least according to gdb/mipsread.c. */
2357 if (fdr_ptr
->rss
== -1)
2359 *filename_ptr
= NULL
;
2361 *functionname_ptr
= NULL
;
2366 ecoff_swap_ext_in (abfd
,
2367 (ecoff_data (abfd
)->external_ext
2370 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2377 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2378 ecoff_swap_sym_in (abfd
,
2379 (ecoff_data (abfd
)->external_sym
2383 *functionname_ptr
= (ecoff_data (abfd
)->ss
2387 *retline_ptr
= lineno
;
2391 /* We can't use the generic linking routines for ECOFF, because we
2392 have to handle all the debugging information. The generic link
2393 routine just works out the section contents and attaches a list of
2396 We link by looping over all the seclets. We make two passes. On
2397 the first we set the actual section contents and determine the size
2398 of the debugging information. On the second we accumulate the
2399 debugging information and write it out.
2401 This currently always accumulates the debugging information, which
2402 is incorrect, because it ignores the -s and -S options of the
2403 linker. The linker needs to be modified to give us that
2404 information in a more useful format (currently it just provides a
2405 list of symbols which should appear in the output file). */
2407 /* Clear the output_has_begun flag for all the input BFD's. We use it
2408 to avoid linking in the debugging information for a BFD more than
2412 ecoff_clear_output_flags (abfd
)
2415 register asection
*o
;
2416 register bfd_seclet_type
*p
;
2418 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2419 for (p
= o
->seclets_head
;
2420 p
!= (bfd_seclet_type
*) NULL
;
2422 if (p
->type
== bfd_indirect_seclet
)
2423 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2426 /* Handle an indirect seclet on the first pass. Set the contents of
2427 the output section, and accumulate the debugging information if
2431 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
2433 bfd_seclet_type
*seclet
;
2434 asection
*output_section
;
2436 boolean relocateable
;
2439 HDRR
*output_symhdr
;
2442 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2443 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2444 && (output_section
->flags
& SEC_LOAD
)
2447 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2451 if (bfd_set_section_contents (output_bfd
,
2462 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2464 /* We want to figure out how much space will be required to
2465 incorporate all the debugging information from input_bfd. We use
2466 the output_has_begun field to avoid adding it in more than once.
2467 The actual incorporation is done in the second pass, in
2468 ecoff_get_debug. The code has to parallel that code in its
2469 manipulations of output_symhdr. */
2471 if (input_bfd
->output_has_begun
)
2473 input_bfd
->output_has_begun
= true;
2475 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2477 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2483 /* We just accumulate local symbols from a non-ECOFF BFD. The
2484 external symbols are handled separately. */
2486 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2487 get_symtab_upper_bound (input_bfd
));
2488 if (symbols
== (asymbol
**) NULL
)
2490 bfd_error
= no_memory
;
2493 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2495 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2499 len
= strlen ((*sym_ptr
)->name
);
2500 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2502 ++output_symhdr
->isymMax
;
2503 output_symhdr
->issMax
+= len
+ 1;
2507 bfd_release (output_bfd
, (PTR
) symbols
);
2509 ++output_symhdr
->ifdMax
;
2514 /* We simply add in the information from another ECOFF BFD. First
2515 we make sure we have the symbolic information. */
2516 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2518 if (bfd_get_symcount (input_bfd
) == 0)
2521 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2523 /* Figure out how much information we are going to be putting in.
2524 The external symbols are handled separately. */
2525 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2526 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2527 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2528 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2529 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2530 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2531 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2532 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2533 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2535 /* The RFD's are special, since we create them if needed. */
2536 if (input_symhdr
->crfd
> 0)
2537 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2539 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2544 /* Handle an arbitrary seclet on the first pass. */
2547 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2549 bfd_seclet_type
*seclet
;
2552 boolean relocateable
;
2554 switch (seclet
->type
)
2556 case bfd_indirect_seclet
:
2557 /* The contents of this section come from another one somewhere
2559 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2561 case bfd_fill_seclet
:
2562 /* Fill in the section with fill.value. This is used to pad out
2563 sections, but we must avoid padding the .bss section. */
2564 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2566 if (seclet
->u
.fill
.value
!= 0)
2571 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2575 for (i
= 0; i
< seclet
->size
; i
+=2)
2576 d
[i
] = seclet
->u
.fill
.value
>> 8;
2577 for (i
= 1; i
< seclet
->size
; i
+=2)
2578 d
[i
] = seclet
->u
.fill
.value
;
2579 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2581 bfd_release (abfd
, (PTR
) d
);
2593 /* Add a string to the debugging information we are accumulating for a
2594 file. Return the offset from the fdr string base or from the
2595 external string base. */
2598 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2608 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2609 len
= strlen (string
);
2612 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2613 ret
= symhdr
->issExtMax
;
2614 symhdr
->issExtMax
+= len
+ 1;
2618 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2620 symhdr
->issMax
+= len
+ 1;
2621 fdr
->cbSs
+= len
+ 1;
2626 /* Accumulate the debugging information from an input section. */
2629 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2631 bfd_seclet_type
*seclet
;
2633 boolean relocateable
;
2636 HDRR
*output_symhdr
;
2638 ecoff_data_type
*output_ecoff
;
2639 ecoff_data_type
*input_ecoff
;
2641 struct sym_ext
*sym_out
;
2642 ecoff_symbol_type
*esym_ptr
;
2643 ecoff_symbol_type
*esym_end
;
2646 struct fdr_ext
*fdr_out
;
2648 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2650 /* Don't get the information more than once. */
2651 if (input_bfd
->output_has_begun
)
2653 input_bfd
->output_has_begun
= true;
2655 output_ecoff
= ecoff_data (output_bfd
);
2656 output_symhdr
= &output_ecoff
->symbolic_header
;
2658 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2665 /* This is not an ECOFF BFD. Just gather the symbols. */
2667 memset (&fdr
, 0, sizeof fdr
);
2669 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2670 fdr
.issBase
= output_symhdr
->issMax
;
2672 fdr
.rss
= ecoff_add_string (output_bfd
,
2674 bfd_get_filename (input_bfd
),
2676 fdr
.isymBase
= output_symhdr
->isymMax
;
2678 /* Get the local symbols from the input BFD. */
2679 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2680 get_symtab_upper_bound (input_bfd
));
2681 if (symbols
== (asymbol
**) NULL
)
2683 bfd_error
= no_memory
;
2686 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2688 /* Handle the local symbols. Any external symbols are handled
2691 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2695 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2697 memset (&internal_sym
, 0, sizeof internal_sym
);
2698 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2703 if (bfd_is_com_section ((*sym_ptr
)->section
)
2704 || (*sym_ptr
)->section
== &bfd_und_section
)
2705 internal_sym
.value
= (*sym_ptr
)->value
;
2707 internal_sym
.value
= ((*sym_ptr
)->value
2708 + (*sym_ptr
)->section
->output_offset
2709 + (*sym_ptr
)->section
->output_section
->vma
);
2710 internal_sym
.st
= stNil
;
2711 internal_sym
.sc
= scUndefined
;
2712 internal_sym
.index
= indexNil
;
2713 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
2714 (output_ecoff
->external_sym
2715 + output_symhdr
->isymMax
));
2717 ++output_symhdr
->isymMax
;
2720 bfd_release (output_bfd
, (PTR
) symbols
);
2722 /* Leave everything else in the FDR zeroed out. This will cause
2723 the lang field to be langC. The fBigendian field will
2724 indicate little endian format, but it doesn't matter because
2725 it only applies to aux fields and there are none. */
2727 ecoff_swap_fdr_out (output_bfd
, &fdr
,
2728 (output_ecoff
->external_fdr
2729 + output_symhdr
->ifdMax
));
2730 ++output_symhdr
->ifdMax
;
2734 /* This is an ECOFF BFD. We want to grab the information from
2735 input_bfd and attach it to output_bfd. */
2736 count
= bfd_get_symcount (input_bfd
);
2739 input_ecoff
= ecoff_data (input_bfd
);
2740 input_symhdr
= &input_ecoff
->symbolic_header
;
2742 /* I think that it is more efficient to simply copy the debugging
2743 information from the input BFD to the output BFD. Because ECOFF
2744 uses relative pointers for most of the debugging information,
2745 only a little of it has to be changed at all. */
2747 /* Swap in the local symbols, adjust their values, and swap them out
2748 again. The external symbols are handled separately. */
2749 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
2751 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2752 esym_end
= esym_ptr
+ count
;
2753 for (; esym_ptr
< esym_end
; esym_ptr
++)
2755 if (esym_ptr
->local
)
2759 ecoff_swap_sym_in (input_bfd
, esym_ptr
->native
.lnative
, &sym
);
2761 /* If we're producing an executable, move common symbols
2763 if (relocateable
== false)
2765 if (sym
.sc
== scCommon
)
2767 else if (sym
.sc
== scSCommon
)
2771 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2772 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2773 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2774 sym
.value
= (esym_ptr
->symbol
.value
2775 + esym_ptr
->symbol
.section
->output_offset
2776 + esym_ptr
->symbol
.section
->output_section
->vma
);
2777 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
2782 /* That should have accounted for all the local symbols in
2784 BFD_ASSERT ((sym_out
- output_ecoff
->external_sym
) - output_symhdr
->isymMax
2785 == input_symhdr
->isymMax
);
2787 /* Copy the information that does not need swapping. */
2788 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2790 input_symhdr
->cbLine
* sizeof (unsigned char));
2791 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2792 input_ecoff
->external_aux
,
2793 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2794 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2796 input_symhdr
->issMax
* sizeof (char));
2798 /* Some of the information may need to be swapped. */
2799 if (output_bfd
->xvec
->header_byteorder_big_p
2800 == input_bfd
->xvec
->header_byteorder_big_p
)
2802 /* The two BFD's have the same endianness, so memcpy will
2804 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
2805 input_ecoff
->external_dnr
,
2806 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
2807 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
2808 input_ecoff
->external_pdr
,
2809 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
2810 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
2811 input_ecoff
->external_opt
,
2812 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
2816 struct dnr_ext
*dnr_in
;
2817 struct dnr_ext
*dnr_end
;
2818 struct dnr_ext
*dnr_out
;
2819 struct pdr_ext
*pdr_in
;
2820 struct pdr_ext
*pdr_end
;
2821 struct pdr_ext
*pdr_out
;
2822 struct opt_ext
*opt_in
;
2823 struct opt_ext
*opt_end
;
2824 struct opt_ext
*opt_out
;
2826 /* The two BFD's have different endianness, so we must swap
2827 everything in and out. This code would always work, but it
2828 would be slow in the normal case. */
2829 dnr_in
= input_ecoff
->external_dnr
;
2830 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
2831 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
2832 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
2836 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
2837 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
2839 pdr_in
= input_ecoff
->external_pdr
;
2840 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
2841 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
2842 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
2846 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
2847 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
2849 opt_in
= input_ecoff
->external_opt
;
2850 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
2851 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
2852 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
2856 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
2857 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
2861 /* Set ifdbase so that the external symbols know how to adjust their
2863 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2865 fdr_ptr
= input_ecoff
->fdr
;
2866 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2867 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
2868 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
2871 unsigned long pdr_off
;
2875 /* The memory address for this fdr is the address for the seclet
2876 plus the offset to this fdr within input_bfd. For some
2877 reason the offset of the first procedure pointer is also
2885 ecoff_swap_pdr_in (input_bfd
,
2886 input_ecoff
->external_pdr
+ fdr
.ipdFirst
,
2890 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2892 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2895 fdr
.issBase
+= output_symhdr
->issMax
;
2896 fdr
.isymBase
+= output_symhdr
->isymMax
;
2897 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2898 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2899 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2900 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2901 fdr
.rfdBase
+= output_symhdr
->crfd
;
2903 /* If there are no RFD's, we are going to add some. We don't
2904 want to adjust irfd for this, so that all the FDR's can share
2906 if (input_symhdr
->crfd
== 0)
2907 fdr
.crfd
= input_symhdr
->ifdMax
;
2909 if (fdr
.cbLine
!= 0)
2910 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2912 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
2915 if (input_symhdr
->crfd
> 0)
2917 struct rfd_ext
*rfd_in
;
2918 struct rfd_ext
*rfd_end
;
2919 struct rfd_ext
*rfd_out
;
2921 /* Swap and adjust the RFD's. RFD's are only created by the
2922 linker, so this will only be necessary if one of the input
2923 files is the result of a partial link. Presumably all
2924 necessary RFD's are present. */
2925 rfd_in
= input_ecoff
->external_rfd
;
2926 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
2927 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2928 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
2932 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
2933 rfd
+= output_symhdr
->ifdMax
;
2934 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2936 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2940 struct rfd_ext
*rfd_out
;
2941 struct rfd_ext
*rfd_end
;
2944 /* Create RFD's. Some of the debugging information includes
2945 relative file indices. These indices are taken as indices to
2946 the RFD table if there is one, or to the global table if
2947 there is not. If we did not create RFD's, we would have to
2948 parse and adjust all the debugging information which contains
2950 rfd
= output_symhdr
->ifdMax
;
2951 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2952 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
2953 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
2954 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2955 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2958 /* Combine the register masks. */
2962 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2963 for (i
= 0; i
< 4; i
++)
2964 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2967 /* Update the counts. */
2968 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2969 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2970 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2971 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2972 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2973 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2974 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2975 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2976 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2981 /* This is the actual link routine. It makes two passes over all the
2985 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2988 boolean relocateable
;
2992 register asection
*o
;
2993 register bfd_seclet_type
*p
;
2994 asymbol
**sym_ptr_ptr
;
2998 /* We accumulate the debugging information counts in the symbolic
3000 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3001 symhdr
->magic
= magicSym
;
3002 /* FIXME: What should the version stamp be? */
3004 symhdr
->ilineMax
= 0;
3008 symhdr
->isymMax
= 0;
3009 symhdr
->ioptMax
= 0;
3010 symhdr
->iauxMax
= 0;
3012 symhdr
->issExtMax
= 0;
3015 symhdr
->iextMax
= 0;
3017 /* We need to copy over the debugging symbols from each input BFD.
3018 When we do this copying, we have to adjust the text address in
3019 the FDR structures, so we have to know the text address used for
3020 the input BFD. Since we only want to copy the symbols once per
3021 input BFD, but we are going to look at each input BFD multiple
3022 times (once for each section it provides), we arrange to always
3023 look at the text section first. That means that when we copy the
3024 debugging information, we always know the text address. So we
3025 actually do each pass in two sub passes; first the text sections,
3026 then the non-text sections. We use the output_has_begun flag to
3027 determine whether we have copied over the debugging information
3030 /* Do the first pass: set the output section contents and count the
3031 debugging information. */
3032 ecoff_clear_output_flags (abfd
);
3033 for (ipass
= 0; ipass
< 2; ipass
++)
3035 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3037 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
3038 so they are done on pass 0. For other sections the
3039 expression is true, so they are done on pass 1. */
3040 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
3043 for (p
= o
->seclets_head
;
3044 p
!= (bfd_seclet_type
*) NULL
;
3047 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
3054 /* We handle the external symbols differently. We use the ones
3055 attached to the output_bfd. The linker will have already
3056 determined which symbols are to be attached. Here we just
3057 determine how much space we will need for them. */
3058 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
3059 if (sym_ptr_ptr
!= NULL
)
3063 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
3064 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
3066 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
3067 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
3070 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
3075 /* Adjust the counts so that structures are longword aligned. */
3076 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
3077 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
3078 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
3080 /* Now the counts in symhdr are the correct size for the debugging
3081 information. We allocate the right amount of space, and reset
3082 the counts so that the second pass can use them as indices. It
3083 would be possible to output the debugging information directly to
3084 the file in pass 2, rather than to build it in memory and then
3085 write it out. Outputting to the file would require a lot of
3086 seeks and small writes, though, and I think this approach is
3088 size
= (symhdr
->cbLine
* sizeof (unsigned char)
3089 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
3090 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
3091 + symhdr
->isymMax
* sizeof (struct sym_ext
)
3092 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
3093 + symhdr
->iauxMax
* sizeof (union aux_ext
)
3094 + symhdr
->issMax
* sizeof (char)
3095 + symhdr
->issExtMax
* sizeof (char)
3096 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
3097 + symhdr
->crfd
* sizeof (struct rfd_ext
)
3098 + symhdr
->iextMax
* sizeof (struct ext_ext
));
3099 raw
= (char *) bfd_alloc (abfd
, size
);
3100 if (raw
== (char *) NULL
)
3102 bfd_error
= no_memory
;
3105 ecoff_data (abfd
)->raw_size
= size
;
3106 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
3108 /* Initialize the raw pointers. */
3109 #define SET(field, count, type) \
3110 ecoff_data (abfd)->field = (type *) raw; \
3111 raw += symhdr->count * sizeof (type)
3113 SET (line
, cbLine
, unsigned char);
3114 SET (external_dnr
, idnMax
, struct dnr_ext
);
3115 SET (external_pdr
, ipdMax
, struct pdr_ext
);
3116 SET (external_sym
, isymMax
, struct sym_ext
);
3117 SET (external_opt
, ioptMax
, struct opt_ext
);
3118 SET (external_aux
, iauxMax
, union aux_ext
);
3119 SET (ss
, issMax
, char);
3120 SET (ssext
, issExtMax
, char);
3121 SET (external_fdr
, ifdMax
, struct fdr_ext
);
3122 SET (external_rfd
, crfd
, struct rfd_ext
);
3123 SET (external_ext
, iextMax
, struct ext_ext
);
3126 /* Reset the counts so the second pass can use them to know how far
3128 symhdr
->ilineMax
= 0;
3132 symhdr
->isymMax
= 0;
3133 symhdr
->ioptMax
= 0;
3134 symhdr
->iauxMax
= 0;
3136 symhdr
->issExtMax
= 0;
3139 symhdr
->iextMax
= 0;
3141 /* Do the second pass: accumulate the debugging information. */
3142 ecoff_clear_output_flags (abfd
);
3143 for (ipass
= 0; ipass
< 2; ipass
++)
3145 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3147 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
3149 for (p
= o
->seclets_head
;
3150 p
!= (bfd_seclet_type
*) NULL
;
3153 if (p
->type
== bfd_indirect_seclet
)
3155 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
3162 /* Put in the external symbols. */
3163 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
3164 if (sym_ptr_ptr
!= NULL
)
3167 struct ext_ext
*external_ext
;
3169 ssext
= ecoff_data (abfd
)->ssext
;
3170 external_ext
= ecoff_data (abfd
)->external_ext
;
3171 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
3176 sym_ptr
= *sym_ptr_ptr
;
3178 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
3179 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
3182 /* The enative pointer can be NULL for a symbol created by
3183 the linker via ecoff_make_empty_symbol. */
3184 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
3185 || (((ecoff_symbol_type
*) sym_ptr
)->native
.enative
3186 == (struct ext_ext
*) NULL
))
3189 esym
.cobol_main
= 0;
3193 /* FIXME: we can do better than this for st and sc. */
3194 esym
.asym
.st
= stGlobal
;
3195 esym
.asym
.sc
= scAbs
;
3196 esym
.asym
.reserved
= 0;
3197 esym
.asym
.index
= indexNil
;
3201 ecoff_symbol_type
*ecoff_sym_ptr
;
3203 ecoff_sym_ptr
= (ecoff_symbol_type
*) sym_ptr
;
3204 if (ecoff_sym_ptr
->local
)
3206 ecoff_swap_ext_in (abfd
, ecoff_sym_ptr
->native
.enative
, &esym
);
3208 /* If we're producing an executable, move common symbols
3210 if (relocateable
== false)
3212 if (esym
.asym
.sc
== scCommon
)
3213 esym
.asym
.sc
= scBss
;
3214 else if (esym
.asym
.sc
== scSCommon
)
3215 esym
.asym
.sc
= scSBss
;
3218 /* Adjust the FDR index for the symbol by that used for
3220 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
3223 esym
.asym
.iss
= symhdr
->issExtMax
;
3225 if (bfd_is_com_section (sym_ptr
->section
)
3226 || sym_ptr
->section
== &bfd_und_section
)
3227 esym
.asym
.value
= sym_ptr
->value
;
3229 esym
.asym
.value
= (sym_ptr
->value
3230 + sym_ptr
->section
->output_offset
3231 + sym_ptr
->section
->output_section
->vma
);
3233 ecoff_swap_ext_out (abfd
, &esym
, external_ext
+ symhdr
->iextMax
);
3235 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
3239 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
3240 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
3244 /* Adjust the counts so that structures are longword aligned. */
3245 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
3246 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
3247 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
3252 /* Set the architecture. The only architecture we support here is
3253 mips. We set the architecture anyhow, since many callers ignore
3254 the return value. */
3257 ecoff_set_arch_mach (abfd
, arch
, machine
)
3259 enum bfd_architecture arch
;
3260 unsigned long machine
;
3262 bfd_default_set_arch_mach (abfd
, arch
, machine
);
3263 return arch
== bfd_arch_mips
;
3266 /* Get the size of the section headers. We do not output the .scommon
3267 section which we created in ecoff_mkobject. */
3270 ecoff_sizeof_headers (abfd
, reloc
)
3274 return FILHSZ
+ AOUTSZ
+ (abfd
->section_count
- 1) * SCNHSZ
;
3277 /* Calculate the file position for each section, and set
3281 ecoff_compute_section_file_positions (abfd
)
3289 if (bfd_get_start_address (abfd
))
3290 abfd
->flags
|= EXEC_P
;
3292 sofar
= ecoff_sizeof_headers (abfd
, false);
3295 for (current
= abfd
->sections
;
3296 current
!= (asection
*) NULL
;
3297 current
= current
->next
)
3299 /* Only deal with sections which have contents */
3300 if (! (current
->flags
& SEC_HAS_CONTENTS
)
3301 || strcmp (current
->name
, SCOMMON
) == 0)
3304 /* On Ultrix, the data sections in an executable file must be
3305 aligned to a page boundary within the file. This does not
3306 affect the section size, though. FIXME: Does this work for
3308 if ((abfd
->flags
& EXEC_P
) != 0
3309 && (abfd
->flags
& D_PAGED
) != 0
3310 && first_data
!= false
3311 && (current
->flags
& SEC_CODE
) == 0)
3313 sofar
= (sofar
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3317 /* Align the sections in the file to the same boundary on
3318 which they are aligned in virtual memory. */
3320 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3322 current
->filepos
= sofar
;
3324 sofar
+= current
->_raw_size
;
3326 /* make sure that this section is of the right size too */
3328 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3329 current
->_raw_size
+= sofar
- old_sofar
;
3332 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3335 /* Set the contents of a section. */
3338 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
3343 bfd_size_type count
;
3345 if (abfd
->output_has_begun
== false)
3346 ecoff_compute_section_file_positions (abfd
);
3348 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3351 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3356 /* Write out an ECOFF file. */
3359 ecoff_write_object_contents (abfd
)
3365 file_ptr reloc_base
;
3367 unsigned long reloc_size
;
3368 unsigned long text_size
;
3369 unsigned long text_start
;
3370 unsigned long data_size
;
3371 unsigned long data_start
;
3372 unsigned long bss_size
;
3373 struct internal_filehdr internal_f
;
3374 struct internal_aouthdr internal_a
;
3377 bfd_error
= system_call_error
;
3379 if(abfd
->output_has_begun
== false)
3380 ecoff_compute_section_file_positions(abfd
);
3382 if (abfd
->sections
!= (asection
*) NULL
)
3383 scn_base
= abfd
->sections
->filepos
;
3386 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3390 for (current
= abfd
->sections
;
3391 current
!= (asection
*)NULL
;
3392 current
= current
->next
)
3394 if (strcmp (current
->name
, SCOMMON
) == 0)
3396 current
->target_index
= count
;
3398 if (current
->reloc_count
!= 0)
3400 bfd_size_type relsize
;
3402 current
->rel_filepos
= reloc_base
;
3403 relsize
= current
->reloc_count
* RELSZ
;
3404 reloc_size
+= relsize
;
3405 reloc_base
+= relsize
;
3408 current
->rel_filepos
= 0;
3411 sym_base
= reloc_base
+ reloc_size
;
3413 /* At least on Ultrix, the symbol table of an executable file must
3414 be aligned to a page boundary. FIXME: Is this true on other
3416 if ((abfd
->flags
& EXEC_P
) != 0
3417 && (abfd
->flags
& D_PAGED
) != 0)
3418 sym_base
= (sym_base
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3420 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3422 if ((abfd
->flags
& D_PAGED
) != 0)
3423 text_size
= ecoff_sizeof_headers (abfd
, false);
3431 /* Write section headers to the file. */
3433 internal_f
.f_nscns
= 0;
3434 if (bfd_seek (abfd
, (file_ptr
) (FILHSZ
+ AOUTSZ
), SEEK_SET
) != 0)
3436 for (current
= abfd
->sections
;
3437 current
!= (asection
*) NULL
;
3438 current
= current
->next
)
3440 struct internal_scnhdr section
;
3443 if (strcmp (current
->name
, SCOMMON
) == 0)
3445 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3446 && current
->reloc_count
== 0);
3450 ++internal_f
.f_nscns
;
3452 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3454 /* FIXME: is this correct for shared libraries? I think it is
3455 but I have no platform to check. Ian Lance Taylor. */
3456 vma
= bfd_get_section_vma (abfd
, current
);
3457 if (strcmp (current
->name
, _LIB
) == 0)
3458 section
.s_vaddr
= 0;
3460 section
.s_vaddr
= vma
;
3462 section
.s_paddr
= vma
;
3463 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3465 /* If this section has no size or is unloadable then the scnptr
3467 if (current
->_raw_size
== 0
3468 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3469 section
.s_scnptr
= 0;
3471 section
.s_scnptr
= current
->filepos
;
3472 section
.s_relptr
= current
->rel_filepos
;
3474 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3475 object file produced by the assembler is supposed to point to
3476 information about how much room is required by objects of
3477 various different sizes. I think this only matters if we
3478 want the linker to compute the best size to use, or
3479 something. I don't know what happens if the information is
3481 section
.s_lnnoptr
= 0;
3483 section
.s_nreloc
= current
->reloc_count
;
3484 section
.s_nlnno
= 0;
3485 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3491 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
3492 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
3496 if ((section
.s_flags
& STYP_TEXT
) != 0)
3498 text_size
+= bfd_get_section_size_before_reloc (current
);
3499 if (text_start
== 0 || text_start
> vma
)
3502 else if ((section
.s_flags
& STYP_RDATA
) != 0
3503 || (section
.s_flags
& STYP_DATA
) != 0
3504 || (section
.s_flags
& STYP_LIT8
) != 0
3505 || (section
.s_flags
& STYP_LIT4
) != 0
3506 || (section
.s_flags
& STYP_SDATA
) != 0)
3508 data_size
+= bfd_get_section_size_before_reloc (current
);
3509 if (data_start
== 0 || data_start
> vma
)
3512 else if ((section
.s_flags
& STYP_BSS
) != 0
3513 || (section
.s_flags
& STYP_SBSS
) != 0)
3514 bss_size
+= bfd_get_section_size_before_reloc (current
);
3517 /* Set up the file header. */
3519 if (abfd
->xvec
->header_byteorder_big_p
!= false)
3520 internal_f
.f_magic
= MIPS_MAGIC_BIG
;
3522 internal_f
.f_magic
= MIPS_MAGIC_LITTLE
;
3525 We will NOT put a fucking timestamp in the header here. Every time you
3526 put it back, I will come in and take it out again. I'm sorry. This
3527 field does not belong here. We fill it with a 0 so it compares the
3528 same but is not a reasonable time. -- gnu@cygnus.com
3530 internal_f
.f_timdat
= 0;
3532 if (bfd_get_symcount (abfd
) != 0)
3534 /* The ECOFF f_nsyms field is not actually the number of
3535 symbols, it's the size of symbolic information header. */
3536 internal_f
.f_nsyms
= sizeof (struct hdr_ext
);
3537 internal_f
.f_symptr
= sym_base
;
3541 internal_f
.f_nsyms
= 0;
3542 internal_f
.f_symptr
= 0;
3545 internal_f
.f_opthdr
= AOUTSZ
;
3547 internal_f
.f_flags
= F_LNNO
;
3548 if (reloc_size
== 0)
3549 internal_f
.f_flags
|= F_RELFLG
;
3550 if (bfd_get_symcount (abfd
) == 0)
3551 internal_f
.f_flags
|= F_LSYMS
;
3552 if (abfd
->flags
& EXEC_P
)
3553 internal_f
.f_flags
|= F_EXEC
;
3555 if (! abfd
->xvec
->byteorder_big_p
)
3556 internal_f
.f_flags
|= F_AR32WR
;
3558 internal_f
.f_flags
|= F_AR32W
;
3560 /* Set up the ``optional'' header. */
3561 if ((abfd
->flags
& D_PAGED
) != 0)
3562 internal_a
.magic
= ZMAGIC
;
3564 internal_a
.magic
= OMAGIC
;
3566 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3567 linker happy. But, is it right? */
3568 internal_a
.vstamp
= 0x20a;
3570 /* At least on Ultrix, these have to be rounded to page boundaries.
3571 FIXME: Is this true on other platforms? */
3572 if ((abfd
->flags
& D_PAGED
) != 0)
3574 internal_a
.tsize
= (text_size
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3575 internal_a
.text_start
= text_start
&~ (ROUND_SIZE
- 1);
3576 internal_a
.dsize
= (data_size
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3577 internal_a
.data_start
= data_start
&~ (ROUND_SIZE
- 1);
3581 internal_a
.tsize
= text_size
;
3582 internal_a
.text_start
= text_start
;
3583 internal_a
.dsize
= data_size
;
3584 internal_a
.data_start
= data_start
;
3587 /* On Ultrix, the initial portions of the .sbss and .bss segments
3588 are at the end of the data section. The bsize field in the
3589 optional header records how many bss bytes are required beyond
3590 those in the data section. The value is not rounded to a page
3592 if (bss_size
< internal_a
.dsize
- data_size
)
3595 bss_size
-= internal_a
.dsize
- data_size
;
3596 internal_a
.bsize
= bss_size
;
3597 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3599 internal_a
.entry
= bfd_get_start_address (abfd
);
3601 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3603 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3604 for (i
= 0; i
< 4; i
++)
3605 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3607 /* Write out the file header and the optional header. */
3609 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3614 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
3615 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
3622 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
3623 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
3627 /* Write out the relocs. */
3628 for (current
= abfd
->sections
;
3629 current
!= (asection
*) NULL
;
3630 current
= current
->next
)
3633 arelent
**reloc_ptr_ptr
;
3634 arelent
**reloc_end
;
3637 if (current
->reloc_count
== 0)
3640 buff
= (RELOC
*) bfd_alloc (abfd
, current
->reloc_count
* RELSZ
);
3641 if (buff
== (RELOC
*) NULL
)
3643 bfd_error
= no_memory
;
3647 reloc_ptr_ptr
= current
->orelocation
;
3648 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3650 for (; reloc_ptr_ptr
< reloc_end
; reloc_ptr_ptr
++, out_ptr
++)
3654 struct internal_reloc in
;
3656 memset (&in
, 0, sizeof in
);
3658 reloc
= *reloc_ptr_ptr
;
3659 sym
= *reloc
->sym_ptr_ptr
;
3661 /* This must be an ECOFF reloc. */
3662 BFD_ASSERT (reloc
->howto
!= (reloc_howto_type
*) NULL
3663 && reloc
->howto
>= ecoff_howto_table
3665 < (ecoff_howto_table
+ ECOFF_HOWTO_COUNT
)));
3667 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3668 in
.r_type
= reloc
->howto
->type
;
3670 /* If this is a REFHI reloc, the next one must be a REFLO
3671 reloc for the same symbol. */
3672 BFD_ASSERT (in
.r_type
!= ECOFF_R_REFHI
3673 || (reloc_ptr_ptr
< reloc_end
3674 && (reloc_ptr_ptr
[1]->howto
3675 != (reloc_howto_type
*) NULL
)
3676 && (reloc_ptr_ptr
[1]->howto
->type
3678 && (sym
== *reloc_ptr_ptr
[1]->sym_ptr_ptr
)));
3680 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3682 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3689 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3690 if (strcmp (name
, ".text") == 0)
3691 in
.r_symndx
= RELOC_SECTION_TEXT
;
3692 else if (strcmp (name
, ".rdata") == 0)
3693 in
.r_symndx
= RELOC_SECTION_RDATA
;
3694 else if (strcmp (name
, ".data") == 0)
3695 in
.r_symndx
= RELOC_SECTION_DATA
;
3696 else if (strcmp (name
, ".sdata") == 0)
3697 in
.r_symndx
= RELOC_SECTION_SDATA
;
3698 else if (strcmp (name
, ".sbss") == 0)
3699 in
.r_symndx
= RELOC_SECTION_SBSS
;
3700 else if (strcmp (name
, ".bss") == 0)
3701 in
.r_symndx
= RELOC_SECTION_BSS
;
3702 else if (strcmp (name
, ".init") == 0)
3703 in
.r_symndx
= RELOC_SECTION_INIT
;
3704 else if (strcmp (name
, ".lit8") == 0)
3705 in
.r_symndx
= RELOC_SECTION_LIT8
;
3706 else if (strcmp (name
, ".lit4") == 0)
3707 in
.r_symndx
= RELOC_SECTION_LIT4
;
3713 ecoff_swap_reloc_out (abfd
, (PTR
) &in
, (PTR
) out_ptr
);
3716 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3718 if (bfd_write ((PTR
) buff
, RELSZ
, current
->reloc_count
, abfd
)
3719 != RELSZ
* current
->reloc_count
)
3721 bfd_release (abfd
, (PTR
) buff
);
3724 /* Write out the symbolic debugging information. */
3725 if (bfd_get_symcount (abfd
) > 0)
3728 unsigned long sym_offset
;
3729 struct hdr_ext buff
;
3731 /* Set up the offsets in the symbolic header. */
3732 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3733 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
3735 #define SET(offset, size, ptr) \
3736 if (symhdr->size == 0) \
3737 symhdr->offset = 0; \
3739 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3740 - (char *) ecoff_data (abfd)->raw_syments) \
3743 SET (cbLineOffset
, cbLine
, line
);
3744 SET (cbDnOffset
, idnMax
, external_dnr
);
3745 SET (cbPdOffset
, ipdMax
, external_pdr
);
3746 SET (cbSymOffset
, isymMax
, external_sym
);
3747 SET (cbOptOffset
, ioptMax
, external_opt
);
3748 SET (cbAuxOffset
, iauxMax
, external_aux
);
3749 SET (cbSsOffset
, issMax
, ss
);
3750 SET (cbSsExtOffset
, issExtMax
, ssext
);
3751 SET (cbFdOffset
, ifdMax
, external_fdr
);
3752 SET (cbRfdOffset
, crfd
, external_rfd
);
3753 SET (cbExtOffset
, iextMax
, external_ext
);
3756 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3759 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
3760 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
3762 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3763 ecoff_data (abfd
)->raw_size
, abfd
)
3764 != ecoff_data (abfd
)->raw_size
)
3767 else if ((abfd
->flags
& EXEC_P
) != 0
3768 && (abfd
->flags
& D_PAGED
) != 0)
3772 /* A demand paged executable must occupy an even number of
3774 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3777 if (bfd_read (&c
, 1, 1, abfd
) == 0)
3779 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
3782 if (bfd_write (&c
, 1, 1, abfd
) != 1)
3789 /* Archive handling. ECOFF uses what appears to be a unique type of
3790 archive header (which I call an armap). The byte ordering of the
3791 armap and the contents are encoded in the name of the armap itself.
3792 At least for now, we only support archives with the same byte
3793 ordering in the armap and the contents.
3795 The first four bytes in the armap are the number of symbol
3796 definitions. This is always a power of two.
3798 This is followed by the symbol definitions. Each symbol definition
3799 occupies 8 bytes. The first four bytes are the offset from the
3800 start of the armap strings to the null-terminated string naming
3801 this symbol. The second four bytes are the file offset to the
3802 archive member which defines this symbol. If the second four bytes
3803 are 0, then this is not actually a symbol definition, and it should
3806 The symbols are hashed into the armap with a closed hashing scheme.
3807 See the functions below for the details of the algorithm.
3809 We could use the hash table when looking up symbols in a library.
3810 This would require a new BFD target entry point to replace the
3811 bfd_get_next_mapent function used by the linker.
3813 After the symbol definitions comes four bytes holding the size of
3814 the string table, followed by the string table itself. */
3816 /* The name of an archive headers looks like this:
3817 __________E[BL]E[BL]_ (with a trailing space).
3818 The trailing space is changed to an X if the archive is changed to
3819 indicate that the armap is out of date. */
3821 #define ARMAP_BIG_ENDIAN 'B'
3822 #define ARMAP_LITTLE_ENDIAN 'L'
3823 #define ARMAP_MARKER 'E'
3824 #define ARMAP_START "__________"
3825 #define ARMAP_HEADER_MARKER_INDEX 10
3826 #define ARMAP_HEADER_ENDIAN_INDEX 11
3827 #define ARMAP_OBJECT_MARKER_INDEX 12
3828 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3829 #define ARMAP_END_INDEX 14
3830 #define ARMAP_END "_ "
3832 /* This is a magic number used in the hashing algorithm. */
3833 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3835 /* This returns the hash value to use for a string. It also sets
3836 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3837 is the number of entries in the hash table, and HLOG is the log
3841 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3843 unsigned int *rehash
;
3851 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3852 hash
*= ARMAP_HASH_MAGIC
;
3853 *rehash
= (hash
& (size
- 1)) | 1;
3854 return hash
>> (32 - hlog
);
3857 /* Read in the armap. */
3860 ecoff_slurp_armap (abfd
)
3865 struct areltdata
*mapdata
;
3866 bfd_size_type parsed_size
;
3868 struct artdata
*ardata
;
3871 struct symdef
*symdef_ptr
;
3874 /* Get the name of the first element. */
3875 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3881 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3883 /* See if the first element is an armap. */
3884 if (strncmp (nextname
, ARMAP_START
, sizeof ARMAP_START
- 1) != 0
3885 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3886 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3887 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3888 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3889 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3890 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3891 || strncmp (nextname
+ ARMAP_END_INDEX
,
3892 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3894 bfd_has_map (abfd
) = false;
3898 /* Make sure we have the right byte ordering. */
3899 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3900 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3901 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3902 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3904 bfd_error
= wrong_format
;
3908 /* Read in the armap. */
3909 ardata
= bfd_ardata (abfd
);
3910 mapdata
= snarf_ar_hdr (abfd
);
3911 if (mapdata
== (struct areltdata
*) NULL
)
3913 parsed_size
= mapdata
->parsed_size
;
3914 bfd_release (abfd
, (PTR
) mapdata
);
3916 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3917 if (raw_armap
== (char *) NULL
)
3919 bfd_error
= no_memory
;
3923 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3925 bfd_error
= malformed_archive
;
3926 bfd_release (abfd
, (PTR
) raw_armap
);
3930 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3932 ardata
->symdef_count
= 0;
3933 ardata
->cache
= (struct ar_cache
*) NULL
;
3935 /* Hack: overlay the symdefs on top of the raw archive data. This
3936 is the way do_slurp_bsd_armap works. */
3937 raw_ptr
= raw_armap
+ LONG_SIZE
;
3938 symdef_ptr
= (struct symdef
*) raw_ptr
;
3939 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3940 stringbase
= raw_ptr
+ count
* (2 * LONG_SIZE
) + LONG_SIZE
;
3942 #ifdef CHECK_ARMAP_HASH
3946 /* Double check that I have the hashing algorithm right by making
3947 sure that every symbol can be looked up successfully. */
3949 for (i
= 1; i
< count
; i
<<= 1)
3951 BFD_ASSERT (i
== count
);
3953 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3955 unsigned int name_offset
, file_offset
;
3956 unsigned int hash
, rehash
, srch
;
3958 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3959 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3960 if (file_offset
== 0)
3962 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3967 /* See if we can rehash to this location. */
3968 for (srch
= (hash
+ rehash
) & (count
- 1);
3969 srch
!= hash
&& srch
!= i
;
3970 srch
= (srch
+ rehash
) & (count
- 1))
3971 BFD_ASSERT (bfd_h_get_32 (abfd
,
3974 + (srch
* 2 * LONG_SIZE
)
3977 BFD_ASSERT (srch
== i
);
3981 raw_ptr
= raw_armap
+ LONG_SIZE
;
3982 #endif /* CHECK_ARMAP_HASH */
3984 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3986 unsigned int name_offset
, file_offset
;
3988 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3989 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3990 if (file_offset
== 0)
3992 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3993 symdef_ptr
->file_offset
= file_offset
;
3995 ++ardata
->symdef_count
;
3998 ardata
->first_file_filepos
= bfd_tell (abfd
);
3999 /* Pad to an even boundary. */
4000 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
4002 bfd_has_map (abfd
) = true;
4007 /* Write out an armap. */
4010 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
4012 unsigned int elength
;
4014 unsigned int orl_count
;
4017 unsigned int hashsize
, hashlog
;
4018 unsigned int symdefsize
;
4020 unsigned int stringsize
;
4021 unsigned int mapsize
;
4024 struct stat statbuf
;
4026 bfd_byte temp
[LONG_SIZE
];
4027 bfd_byte
*hashtable
;
4031 /* Ultrix appears to use as a hash table size the least power of two
4032 greater than twice the number of entries. */
4033 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
4035 hashsize
= 1 << hashlog
;
4037 symdefsize
= hashsize
* 2 * LONG_SIZE
;
4039 stringsize
= stridx
+ padit
;
4041 /* Include 8 bytes to store symdefsize and stringsize in output. */
4042 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
4044 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
4046 memset ((PTR
) &hdr
, 0, sizeof hdr
);
4048 /* Work out the ECOFF armap name. */
4049 strcpy (hdr
.ar_name
, ARMAP_START
);
4050 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
4051 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
4052 (abfd
->xvec
->header_byteorder_big_p
4054 : ARMAP_LITTLE_ENDIAN
);
4055 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
4056 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
4057 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
4058 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
4060 /* Write the timestamp of the archive header to be just a little bit
4061 later than the timestamp of the file, otherwise the linker will
4062 complain that the index is out of date. Actually, the Ultrix
4063 linker just checks the archive name; the GNU linker may check the
4065 stat (abfd
->filename
, &statbuf
);
4066 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
4068 /* The DECstation uses zeroes for the uid, gid and mode of the
4070 hdr
.ar_uid
[0] = '0';
4071 hdr
.ar_gid
[0] = '0';
4072 hdr
.ar_mode
[0] = '0';
4074 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
4076 hdr
.ar_fmag
[0] = '`';
4077 hdr
.ar_fmag
[1] = '\n';
4079 /* Turn all null bytes in the header into spaces. */
4080 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
4081 if (((char *)(&hdr
))[i
] == '\0')
4082 (((char *)(&hdr
))[i
]) = ' ';
4084 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
4085 != sizeof (struct ar_hdr
))
4088 bfd_h_put_32 (abfd
, hashsize
, temp
);
4089 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
4092 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
4094 current
= abfd
->archive_head
;
4096 for (i
= 0; i
< orl_count
; i
++)
4098 unsigned int hash
, rehash
;
4100 /* Advance firstreal to the file position of this archive
4102 if (((bfd
*) map
[i
].pos
) != last_elt
)
4106 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
4107 firstreal
+= firstreal
% 2;
4108 current
= current
->next
;
4110 while (current
!= (bfd
*) map
[i
].pos
);
4115 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
4116 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
4117 + (hash
* 2 * LONG_SIZE
)
4123 /* The desired slot is already taken. */
4124 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
4126 srch
= (srch
+ rehash
) & (hashsize
- 1))
4127 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
4128 + (srch
* 2 * LONG_SIZE
)
4133 BFD_ASSERT (srch
!= hash
);
4138 bfd_h_put_32 (abfd
, map
[i
].namidx
,
4139 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
4140 bfd_h_put_32 (abfd
, firstreal
,
4141 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
4144 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
4147 bfd_release (abfd
, hashtable
);
4149 /* Now write the strings. */
4150 bfd_h_put_32 (abfd
, stringsize
, temp
);
4151 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
4153 for (i
= 0; i
< orl_count
; i
++)
4157 len
= strlen (*map
[i
].name
) + 1;
4158 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
4162 /* The spec sez this should be a newline. But in order to be
4163 bug-compatible for DECstation ar we use a null. */
4166 if (bfd_write ("\0", 1, 1, abfd
) != 1)
4173 /* We just use the generic extended name support. This is a GNU
4175 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
4177 /* See whether this BFD is an archive. If it is, read in the armap
4178 and the extended name table. */
4181 ecoff_archive_p (abfd
)
4184 char armag
[SARMAG
+ 1];
4186 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
4187 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
4189 bfd_error
= wrong_format
;
4190 return (bfd_target
*) NULL
;
4193 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
4194 involves a cast, we can't do it as the left operand of
4196 abfd
->tdata
.aout_ar_data
=
4197 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
4199 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
4201 bfd_error
= no_memory
;
4202 return (bfd_target
*) NULL
;
4205 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
4207 if (ecoff_slurp_armap (abfd
) == false
4208 || ecoff_slurp_extended_name_table (abfd
) == false)
4210 bfd_release (abfd
, bfd_ardata (abfd
));
4211 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
4212 return (bfd_target
*) NULL
;
4220 #include <core.out.h>
4222 struct sgi_core_struct
4225 char cmd
[CORE_NAMESIZE
];
4228 #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
4229 #define core_signal(bfd) (core_hdr(bfd)->sig)
4230 #define core_command(bfd) (core_hdr(bfd)->cmd)
4233 make_bfd_asection (abfd
, name
, flags
, _raw_size
, vma
, filepos
)
4237 bfd_size_type _raw_size
;
4243 asect
= bfd_make_section (abfd
, name
);
4247 asect
->flags
= flags
;
4248 asect
->_raw_size
= _raw_size
;
4250 asect
->filepos
= filepos
;
4251 asect
->alignment_power
= 4;
4257 ecoff_core_file_p (abfd
)
4263 struct coreout coreout
;
4264 struct idesc
*idg
, *idf
, *ids
;
4266 val
= bfd_read ((PTR
)&coreout
, 1, sizeof coreout
, abfd
);
4267 if (val
!= sizeof coreout
)
4270 if (coreout
.c_magic
!= CORE_MAGIC
4271 || coreout
.c_version
!= CORE_VERSION1
)
4274 core_hdr (abfd
) = (struct sgi_core_struct
*) bfd_zalloc (abfd
, sizeof (struct sgi_core_struct
));
4275 if (!core_hdr (abfd
))
4278 strncpy (core_command (abfd
), coreout
.c_name
, CORE_NAMESIZE
);
4279 core_signal (abfd
) = coreout
.c_sigcause
;
4281 bfd_seek (abfd
, coreout
.c_vmapoffset
, SEEK_SET
);
4283 for (i
= 0; i
< coreout
.c_nvmap
; i
++)
4287 val
= bfd_read ((PTR
)&vmap
, 1, sizeof vmap
, abfd
);
4288 if (val
!= sizeof vmap
)
4291 switch (vmap
.v_type
)
4303 if (!make_bfd_asection (abfd
, secname
,
4304 SEC_ALLOC
+SEC_LOAD
+SEC_HAS_CONTENTS
,
4312 /* Make sure that the regs are contiguous within the core file. */
4314 idg
= &coreout
.c_idesc
[I_GPREGS
];
4315 idf
= &coreout
.c_idesc
[I_FPREGS
];
4316 ids
= &coreout
.c_idesc
[I_SPECREGS
];
4318 if (idg
->i_offset
+ idg
->i_len
!= idf
->i_offset
4319 || idf
->i_offset
+ idf
->i_len
!= ids
->i_offset
)
4320 return 0; /* Can't deal with non-contig regs */
4322 bfd_seek (abfd
, idg
->i_offset
, SEEK_SET
);
4324 make_bfd_asection (abfd
, ".reg",
4325 SEC_ALLOC
+SEC_HAS_CONTENTS
,
4326 idg
->i_len
+ idf
->i_len
+ ids
->i_len
,
4330 /* OK, we believe you. You're a core file (sure, sure). */
4336 ecoff_core_file_failing_command (abfd
)
4339 return core_command (abfd
);
4343 ecoff_core_file_failing_signal (abfd
)
4346 return core_signal (abfd
);
4350 ecoff_core_file_matches_executable_p (core_bfd
, exec_bfd
)
4351 bfd
*core_bfd
, *exec_bfd
;
4353 return true; /* XXX - FIXME */
4355 #else /* not def HOST_IRIX4 */
4356 #define ecoff_core_file_p _bfd_dummy_target
4357 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4358 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4359 #define ecoff_core_file_matches_executable_p \
4360 _bfd_dummy_core_file_matches_executable_p
4363 /* This is the COFF backend structure. The backend_data field of the
4364 bfd_target structure is set to this. The section reading code in
4365 coffgen.c uses this structure. */
4367 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
4368 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
4369 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
4370 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
4371 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
4372 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
4373 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
4374 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
4375 ecoff_swap_scnhdr_out
,
4376 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
4377 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
4378 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
4379 ecoff_styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
4380 ecoff_slurp_symbol_table
4383 /* get_lineno could be written for ECOFF, but it would currently only
4384 be useful for linking ECOFF and COFF files together, which doesn't
4386 #define ecoff_get_lineno \
4387 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4389 /* These bfd_target functions are defined in other files. */
4391 #define ecoff_truncate_arname bfd_dont_truncate_arname
4392 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4393 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4394 #define ecoff_get_section_contents bfd_generic_get_section_contents
4395 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4396 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4397 #define ecoff_bfd_debug_info_start bfd_void
4398 #define ecoff_bfd_debug_info_end bfd_void
4399 #define ecoff_bfd_debug_info_accumulate \
4400 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4401 #define ecoff_bfd_get_relocated_section_contents \
4402 bfd_generic_get_relocated_section_contents
4403 #define ecoff_bfd_relax_section bfd_generic_relax_section
4404 #define ecoff_bfd_make_debug_symbol \
4405 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4407 bfd_target ecoff_little_vec
=
4409 "ecoff-littlemips", /* name */
4410 bfd_target_ecoff_flavour
,
4411 false, /* data byte order is little */
4412 false, /* header byte order is little */
4414 (HAS_RELOC
| EXEC_P
| /* object flags */
4415 HAS_LINENO
| HAS_DEBUG
|
4416 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
4418 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
4420 0, /* leading underscore */
4421 ' ', /* ar_pad_char */
4422 15, /* ar_max_namelen */
4423 4, /* minimum alignment power */
4424 _do_getl64
, _do_getl_signed_64
, _do_putl64
,
4425 _do_getl32
, _do_getl_signed_32
, _do_putl32
,
4426 _do_getl16
, _do_getl_signed_16
, _do_putl16
, /* data */
4427 _do_getl64
, _do_getl_signed_64
, _do_putl64
,
4428 _do_getl32
, _do_getl_signed_32
, _do_putl32
,
4429 _do_getl16
, _do_getl_signed_16
, _do_putl16
, /* hdrs */
4431 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
4432 ecoff_archive_p
, _bfd_dummy_target
},
4433 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
4435 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
4436 _bfd_write_archive_contents
, bfd_false
},
4438 (PTR
) &bfd_ecoff_std_swap_table
4441 bfd_target ecoff_big_vec
=
4443 "ecoff-bigmips", /* name */
4444 bfd_target_ecoff_flavour
,
4445 true, /* data byte order is big */
4446 true, /* header byte order is big */
4448 (HAS_RELOC
| EXEC_P
| /* object flags */
4449 HAS_LINENO
| HAS_DEBUG
|
4450 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
4452 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect flags */
4453 0, /* leading underscore */
4454 ' ', /* ar_pad_char */
4455 15, /* ar_max_namelen */
4456 4, /* minimum alignment power */
4457 _do_getb64
, _do_getb_signed_64
, _do_putb64
,
4458 _do_getb32
, _do_getb_signed_32
, _do_putb32
,
4459 _do_getb16
, _do_getb_signed_16
, _do_putb16
,
4460 _do_getb64
, _do_getb_signed_64
, _do_putb64
,
4461 _do_getb32
, _do_getb_signed_32
, _do_putb32
,
4462 _do_getb16
, _do_getb_signed_16
, _do_putb16
,
4463 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
4464 ecoff_archive_p
, ecoff_core_file_p
},
4465 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
4467 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
4468 _bfd_write_archive_contents
, bfd_false
},
4470 (PTR
) &bfd_ecoff_std_swap_table
4471 /* Note that there is another bfd_target just above this one. If
4472 you are adding initializers here, you should be adding them there