Commit | Line | Data |
---|---|---|
1f29e30b | 1 | /* BFD back-end for MIPS Extended-Coff files. |
f6409552 | 2 | Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
8fa0d3a0 | 3 | Original version by Per Bothner. |
f6409552 | 4 | Full support added by Ian Lance Taylor, ian@cygnus.com. |
1327fb29 | 5 | |
68b70212 | 6 | This file is part of BFD, the Binary File Descriptor library. |
23b0b558 | 7 | |
68b70212 | 8 | This program is free software; you can redistribute it and/or modify |
23b0b558 | 9 | it under the terms of the GNU General Public License as published by |
68b70212 JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
23b0b558 | 12 | |
68b70212 | 13 | This program is distributed in the hope that it will be useful, |
23b0b558 JG |
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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
68b70212 JG |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
1327fb29 | 21 | |
23b0b558 | 22 | #include "bfd.h" |
dd4646ca | 23 | #include "sysdep.h" |
1327fb29 | 24 | #include "libbfd.h" |
8fa0d3a0 | 25 | #include "seclet.h" |
c3fe0c41 ILT |
26 | #include "aout/ar.h" |
27 | #include "aout/ranlib.h" | |
de17306e ILT |
28 | |
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 | |
31 | we do want. */ | |
32 | #include "libaout.h" | |
33 | #include "aout/aout64.h" | |
34 | #undef OMAGIC | |
35 | #undef ZMAGIC | |
36 | #undef N_ABS | |
37 | #undef exec_hdr | |
38 | #undef obj_sym_filepos | |
39 | ||
294eaca4 SC |
40 | #include "coff/mips.h" |
41 | #include "coff/internal.h" | |
515c4292 ILT |
42 | #include "coff/sym.h" |
43 | #include "coff/symconst.h" | |
44 | #include "coff/ecoff-ext.h" | |
45 | #include "libcoff.h" | |
20f10b59 | 46 | #include "libecoff.h" |
515c4292 ILT |
47 | |
48 | /* Each canonical asymbol really looks like this. */ | |
49 | ||
50 | typedef struct ecoff_symbol_struct | |
51 | { | |
52 | /* The actual symbol which the rest of BFD works with */ | |
53 | asymbol symbol; | |
54 | ||
55 | /* The fdr for this symbol. */ | |
56 | FDR *fdr; | |
57 | ||
58 | /* true if this is a local symbol rather than an external one. */ | |
59 | boolean local; | |
60 | ||
61 | /* A pointer to the unswapped hidden information for this symbol */ | |
62 | union | |
63 | { | |
64 | struct sym_ext *lnative; | |
65 | struct ext_ext *enative; | |
66 | } | |
67 | native; | |
68 | } ecoff_symbol_type; | |
69 | ||
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))) | |
73 | ||
c3fe0c41 | 74 | /* The page boundary used to align sections in the executable file. */ |
14e3c2e4 | 75 | #define ROUND_SIZE 0x1000 |
c3fe0c41 | 76 | |
5e462ed9 ILT |
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 | |
80 | writing it out. */ | |
81 | #define SCOMMON ".scommon" | |
82 | ||
515c4292 ILT |
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. */ | |
f6409552 ILT |
88 | \f |
89 | /* Prototypes for static functions. */ | |
90 | ||
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, | |
98 | flagword flags)); | |
99 | static flagword ecoff_styp_to_sec_flags PARAMS ((bfd *abfd, PTR hdr)); | |
f6409552 ILT |
100 | static asymbol *ecoff_make_empty_symbol PARAMS ((bfd *abfd)); |
101 | static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym, | |
de17306e ILT |
102 | asymbol *asym, int ext, |
103 | asymbol **indirect_ptr_ptr)); | |
f6409552 ILT |
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, | |
110 | CONST char *which)); | |
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, | |
114 | asymbol *symbol, | |
115 | bfd_print_symbol_type how)); | |
de17306e ILT |
116 | static void ecoff_get_symbol_info PARAMS ((bfd *abfd, |
117 | asymbol *symbol, | |
118 | symbol_info *ret)); | |
f6409552 ILT |
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, | |
122 | PTR dst)); | |
123 | static bfd_reloc_status_type ecoff_generic_reloc PARAMS ((bfd *abfd, | |
124 | arelent *reloc, | |
125 | asymbol *symbol, | |
126 | PTR data, | |
127 | asection *section, | |
128 | bfd *output_bfd)); | |
129 | static bfd_reloc_status_type ecoff_refhi_reloc PARAMS ((bfd *abfd, | |
130 | arelent *reloc, | |
131 | asymbol *symbol, | |
132 | PTR data, | |
133 | asection *section, | |
134 | bfd *output_bfd)); | |
46bc1bf6 ILT |
135 | static bfd_reloc_status_type ecoff_reflo_reloc PARAMS ((bfd *abfd, |
136 | arelent *reloc, | |
137 | asymbol *symbol, | |
138 | PTR data, | |
139 | asection *section, | |
140 | bfd *output_bfd)); | |
f6409552 ILT |
141 | static bfd_reloc_status_type ecoff_gprel_reloc PARAMS ((bfd *abfd, |
142 | arelent *reloc, | |
143 | asymbol *symbol, | |
144 | PTR data, | |
145 | asection *section, | |
146 | bfd *output_bfd)); | |
147 | static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section, | |
148 | asymbol **symbols)); | |
149 | static unsigned int ecoff_canonicalize_reloc PARAMS ((bfd *abfd, | |
150 | asection *section, | |
151 | arelent **relptr, | |
152 | asymbol **symbols)); | |
f68d8549 ILT |
153 | static CONST struct reloc_howto_struct *ecoff_bfd_reloc_type_lookup |
154 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
f6409552 ILT |
155 | static boolean ecoff_find_nearest_line PARAMS ((bfd *abfd, |
156 | asection *section, | |
157 | asymbol **symbols, | |
158 | bfd_vma offset, | |
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, | |
173 | asection *section, | |
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, | |
183 | asection *section, | |
184 | PTR location, | |
185 | file_ptr offset, | |
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, | |
190 | unsigned int size, | |
191 | unsigned int hlog)); | |
192 | static boolean ecoff_slurp_armap PARAMS ((bfd *abfd)); | |
193 | static boolean ecoff_write_armap PARAMS ((bfd *abfd, unsigned int elength, | |
194 | struct orl *map, | |
195 | unsigned int orl_count, | |
196 | int stridx)); | |
197 | static bfd_target *ecoff_archive_p PARAMS ((bfd *abfd)); | |
198 | \f | |
8fa0d3a0 ILT |
199 | /* Get the generic COFF swapping routines, except for the reloc, |
200 | symbol, and lineno ones. Give them ecoff names. */ | |
c3fe0c41 | 201 | #define MIPSECOFF |
8fa0d3a0 | 202 | #define NO_COFF_RELOCS |
515c4292 ILT |
203 | #define NO_COFF_SYMBOLS |
204 | #define NO_COFF_LINENOS | |
515c4292 ILT |
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" | |
212 | \f | |
de17306e ILT |
213 | /* How to process the various relocs types. */ |
214 | ||
215 | static reloc_howto_type ecoff_howto_table[] = | |
216 | { | |
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 */ | |
221 | 0, /* rightshift */ | |
222 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
223 | 8, /* bitsize (obsolete) */ | |
224 | false, /* pc_relative */ | |
225 | 0, /* bitpos */ | |
226 | false, /* absolute (obsolete) */ | |
227 | false, /* complain_on_overflow */ | |
228 | 0, /* special_function */ | |
229 | "IGNORE", /* name */ | |
230 | false, /* partial_inplace */ | |
231 | 0, /* src_mask */ | |
232 | 0, /* dst_mask */ | |
233 | false), /* pcrel_offset */ | |
234 | ||
235 | /* A 16 bit reference to a symbol, normally from a data section. */ | |
236 | HOWTO (ECOFF_R_REFHALF, /* type */ | |
237 | 0, /* rightshift */ | |
238 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
239 | 16, /* bitsize (obsolete) */ | |
240 | false, /* pc_relative */ | |
241 | 0, /* bitpos */ | |
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 */ | |
250 | ||
251 | /* A 32 bit reference to a symbol, normally from a data section. */ | |
252 | HOWTO (ECOFF_R_REFWORD, /* type */ | |
253 | 0, /* rightshift */ | |
254 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
255 | 32, /* bitsize (obsolete) */ | |
256 | false, /* pc_relative */ | |
257 | 0, /* bitpos */ | |
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 */ | |
266 | ||
267 | /* A 26 bit absolute jump address. */ | |
268 | HOWTO (ECOFF_R_JMPADDR, /* type */ | |
269 | 2, /* rightshift */ | |
270 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
271 | 32, /* bitsize (obsolete) */ | |
272 | false, /* pc_relative */ | |
273 | 0, /* bitpos */ | |
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 */ | |
282 | ||
283 | /* The high 16 bits of a symbol value. Handled by the function | |
284 | ecoff_refhi_reloc. */ | |
285 | HOWTO (ECOFF_R_REFHI, /* type */ | |
286 | 16, /* rightshift */ | |
287 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
288 | 32, /* bitsize (obsolete) */ | |
289 | false, /* pc_relative */ | |
290 | 0, /* bitpos */ | |
291 | false, /* absolute (obsolete) */ | |
292 | true, /* complain_on_overflow */ | |
293 | ecoff_refhi_reloc, /* special_function */ | |
294 | "REFHI", /* name */ | |
295 | true, /* partial_inplace */ | |
296 | 0xffff, /* src_mask */ | |
297 | 0xffff, /* dst_mask */ | |
298 | false), /* pcrel_offset */ | |
299 | ||
300 | /* The low 16 bits of a symbol value. */ | |
301 | HOWTO (ECOFF_R_REFLO, /* type */ | |
302 | 0, /* rightshift */ | |
303 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
304 | 32, /* bitsize (obsolete) */ | |
305 | false, /* pc_relative */ | |
306 | 0, /* bitpos */ | |
307 | false, /* absolute (obsolete) */ | |
308 | true, /* complain_on_overflow */ | |
309 | ecoff_reflo_reloc, /* special_function */ | |
310 | "REFLO", /* name */ | |
311 | true, /* partial_inplace */ | |
312 | 0xffff, /* src_mask */ | |
313 | 0xffff, /* dst_mask */ | |
314 | false), /* pcrel_offset */ | |
315 | ||
316 | /* A reference to an offset from the gp register. Handled by the | |
317 | function ecoff_gprel_reloc. */ | |
318 | HOWTO (ECOFF_R_GPREL, /* type */ | |
319 | 0, /* rightshift */ | |
320 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
321 | 32, /* bitsize (obsolete) */ | |
322 | false, /* pc_relative */ | |
323 | 0, /* bitpos */ | |
324 | false, /* absolute (obsolete) */ | |
325 | true, /* complain_on_overflow */ | |
326 | ecoff_gprel_reloc, /* special_function */ | |
327 | "GPREL", /* name */ | |
328 | true, /* partial_inplace */ | |
329 | 0xffff, /* src_mask */ | |
330 | 0xffff, /* dst_mask */ | |
331 | false), /* pcrel_offset */ | |
332 | ||
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 */ | |
336 | 0, /* rightshift */ | |
337 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
338 | 32, /* bitsize (obsolete) */ | |
339 | false, /* pc_relative */ | |
340 | 0, /* bitpos */ | |
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 */ | |
349 | }; | |
350 | ||
351 | #define ECOFF_HOWTO_COUNT \ | |
352 | (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0]) | |
353 | \f | |
515c4292 ILT |
354 | /* This stuff is somewhat copied from coffcode.h. */ |
355 | ||
356 | static asection bfd_debug_section = { "*DEBUG*" }; | |
357 | ||
358 | /* See whether the magic number matches. */ | |
359 | ||
360 | static boolean | |
f6409552 ILT |
361 | ecoff_bad_format_hook (abfd, filehdr) |
362 | bfd *abfd; | |
363 | PTR filehdr; | |
515c4292 ILT |
364 | { |
365 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
366 | ||
367 | if (ECOFFBADMAG (*internal_f)) | |
368 | return false; | |
369 | ||
370 | return true; | |
371 | } | |
372 | ||
373 | /* This is a hook needed by SCO COFF, but we have nothing to do. */ | |
374 | ||
375 | static asection * | |
f6409552 ILT |
376 | ecoff_make_section_hook (abfd, name) |
377 | bfd *abfd; | |
378 | char *name; | |
515c4292 ILT |
379 | { |
380 | return (asection *) NULL; | |
381 | } | |
382 | ||
383 | /* Initialize a new section. */ | |
384 | ||
385 | static boolean | |
f6409552 ILT |
386 | ecoff_new_section_hook (abfd, section) |
387 | bfd *abfd; | |
388 | asection *section; | |
515c4292 ILT |
389 | { |
390 | section->alignment_power = abfd->xvec->align_power_min; | |
8fa0d3a0 ILT |
391 | |
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) | |
bf4b84bc | 403 | section->flags |= SEC_ALLOC; |
8fa0d3a0 ILT |
404 | |
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 | |
407 | libraries work. */ | |
408 | ||
515c4292 ILT |
409 | return true; |
410 | } | |
411 | ||
f6409552 ILT |
412 | /* Set the alignment of a section; we have nothing to do. */ |
413 | ||
515c4292 ILT |
414 | #define ecoff_set_alignment_hook \ |
415 | ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void) | |
416 | ||
f6409552 ILT |
417 | /* Create an ECOFF object. */ |
418 | ||
515c4292 | 419 | static boolean |
f6409552 ILT |
420 | ecoff_mkobject (abfd) |
421 | bfd *abfd; | |
515c4292 ILT |
422 | { |
423 | abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *) | |
46bc1bf6 | 424 | bfd_zalloc (abfd, sizeof (ecoff_data_type))); |
515c4292 ILT |
425 | if (abfd->tdata.ecoff_obj_data == NULL) |
426 | { | |
427 | bfd_error = no_memory; | |
428 | return false; | |
429 | } | |
430 | ||
5e462ed9 ILT |
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); | |
434 | ||
515c4292 ILT |
435 | return true; |
436 | } | |
437 | ||
f6409552 | 438 | /* Create the ECOFF backend specific information. */ |
515c4292 | 439 | |
c3fe0c41 ILT |
440 | static PTR |
441 | ecoff_mkobject_hook (abfd, filehdr, aouthdr) | |
442 | bfd *abfd; | |
443 | PTR filehdr; | |
444 | PTR aouthdr; | |
515c4292 ILT |
445 | { |
446 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
c3fe0c41 | 447 | struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr; |
515c4292 ILT |
448 | ecoff_data_type *ecoff; |
449 | ||
450 | if (ecoff_mkobject (abfd) == false) | |
451 | return NULL; | |
452 | ||
453 | ecoff = ecoff_data (abfd); | |
46bc1bf6 | 454 | ecoff->gp_size = 8; |
515c4292 | 455 | ecoff->sym_filepos = internal_f->f_symptr; |
c3fe0c41 ILT |
456 | |
457 | if (internal_a != (struct internal_aouthdr *) NULL) | |
458 | { | |
459 | int i; | |
460 | ||
6d18a99d ILT |
461 | ecoff->text_start = internal_a->text_start; |
462 | ecoff->text_end = internal_a->text_start + internal_a->tsize; | |
c3fe0c41 ILT |
463 | ecoff->gp = internal_a->gp_value; |
464 | ecoff->gprmask = internal_a->gprmask; | |
5e462ed9 | 465 | for (i = 0; i < 4; i++) |
c3fe0c41 | 466 | ecoff->cprmask[i] = internal_a->cprmask[i]; |
de17306e ILT |
467 | if (internal_a->magic == ZMAGIC) |
468 | abfd->flags |= D_PAGED; | |
c3fe0c41 ILT |
469 | } |
470 | ||
515c4292 ILT |
471 | return (PTR) ecoff; |
472 | } | |
473 | ||
474 | /* Determine the machine architecture and type. */ | |
f6409552 | 475 | |
515c4292 | 476 | static boolean |
f6409552 ILT |
477 | ecoff_set_arch_mach_hook (abfd, filehdr) |
478 | bfd *abfd; | |
479 | PTR filehdr; | |
515c4292 | 480 | { |
515c4292 | 481 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; |
f6409552 | 482 | enum bfd_architecture arch; |
515c4292 | 483 | |
f6409552 ILT |
484 | switch (internal_f->f_magic) |
485 | { | |
486 | case MIPS_MAGIC_1: | |
6d18a99d ILT |
487 | case MIPS_MAGIC_LITTLE: |
488 | case MIPS_MAGIC_BIG: | |
f6409552 ILT |
489 | arch = bfd_arch_mips; |
490 | break; | |
491 | ||
492 | default: | |
493 | arch = bfd_arch_obscure; | |
494 | break; | |
495 | } | |
496 | ||
497 | bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0); | |
515c4292 | 498 | |
515c4292 ILT |
499 | return true; |
500 | } | |
501 | ||
8fa0d3a0 ILT |
502 | /* Get the section s_flags to use for a section. */ |
503 | ||
504 | static long | |
f6409552 ILT |
505 | ecoff_sec_to_styp_flags (name, flags) |
506 | CONST char *name; | |
507 | flagword flags; | |
8fa0d3a0 ILT |
508 | { |
509 | long styp; | |
510 | ||
511 | styp = 0; | |
512 | ||
513 | if (strcmp (name, _TEXT) == 0) | |
514 | styp = STYP_TEXT; | |
515 | else if (strcmp (name, _DATA) == 0) | |
c3fe0c41 | 516 | styp = STYP_DATA; |
8fa0d3a0 | 517 | else if (strcmp (name, _SDATA) == 0) |
c3fe0c41 | 518 | styp = STYP_SDATA; |
8fa0d3a0 ILT |
519 | else if (strcmp (name, _RDATA) == 0) |
520 | styp = STYP_RDATA; | |
521 | else if (strcmp (name, _LIT8) == 0) | |
522 | styp = STYP_LIT8; | |
523 | else if (strcmp (name, _LIT4) == 0) | |
524 | styp = STYP_LIT4; | |
525 | else if (strcmp (name, _BSS) == 0) | |
526 | styp = STYP_BSS; | |
527 | else if (strcmp (name, _SBSS) == 0) | |
528 | styp = STYP_SBSS; | |
9b946448 ILT |
529 | else if (strcmp (name, _INIT) == 0) |
530 | styp = STYP_MIPS_INIT; | |
8fa0d3a0 ILT |
531 | else if (flags & SEC_CODE) |
532 | styp = STYP_TEXT; | |
533 | else if (flags & SEC_DATA) | |
534 | styp = STYP_DATA; | |
535 | else if (flags & SEC_READONLY) | |
536 | styp = STYP_RDATA; | |
537 | else if (flags & SEC_LOAD) | |
9b946448 | 538 | styp = STYP_REG; |
8fa0d3a0 ILT |
539 | else |
540 | styp = STYP_BSS; | |
541 | ||
542 | if (flags & SEC_NEVER_LOAD) | |
543 | styp |= STYP_NOLOAD; | |
544 | ||
545 | return styp; | |
546 | } | |
547 | ||
515c4292 ILT |
548 | /* Get the BFD flags to use for a section. */ |
549 | ||
550 | static flagword | |
f6409552 ILT |
551 | ecoff_styp_to_sec_flags (abfd, hdr) |
552 | bfd *abfd; | |
553 | PTR hdr; | |
515c4292 ILT |
554 | { |
555 | struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr; | |
556 | long styp_flags = internal_s->s_flags; | |
557 | flagword sec_flags=0; | |
558 | ||
559 | if (styp_flags & STYP_NOLOAD) | |
560 | sec_flags |= SEC_NEVER_LOAD; | |
561 | ||
562 | /* For 386 COFF, at least, an unloadable text or data section is | |
563 | actually a shared library section. */ | |
9b946448 | 564 | if ((styp_flags & STYP_TEXT) |
9caf15da | 565 | || (styp_flags & STYP_MIPS_INIT)) |
515c4292 ILT |
566 | { |
567 | if (sec_flags & SEC_NEVER_LOAD) | |
568 | sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY; | |
569 | else | |
570 | sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
571 | } | |
572 | else if ((styp_flags & STYP_DATA) | |
573 | || (styp_flags & STYP_RDATA) | |
574 | || (styp_flags & STYP_SDATA)) | |
575 | { | |
576 | if (sec_flags & SEC_NEVER_LOAD) | |
577 | sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY; | |
578 | else | |
579 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
580 | if (styp_flags & STYP_RDATA) | |
581 | sec_flags |= SEC_READONLY; | |
582 | } | |
583 | else if ((styp_flags & STYP_BSS) | |
584 | || (styp_flags & STYP_SBSS)) | |
585 | { | |
586 | sec_flags |= SEC_ALLOC; | |
587 | } | |
588 | else if (styp_flags & STYP_INFO) | |
589 | { | |
590 | sec_flags |= SEC_NEVER_LOAD; | |
591 | } | |
592 | else if ((styp_flags & STYP_LIT8) | |
593 | || (styp_flags & STYP_LIT4)) | |
594 | { | |
595 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY; | |
596 | } | |
597 | else | |
598 | { | |
599 | sec_flags |= SEC_ALLOC | SEC_LOAD; | |
600 | } | |
601 | ||
602 | return sec_flags; | |
603 | } | |
604 | \f | |
8fa0d3a0 | 605 | /* Read in and swap the important symbolic information for an ECOFF |
20f10b59 ILT |
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. */ | |
8fa0d3a0 | 609 | |
20f10b59 | 610 | boolean |
f6409552 ILT |
611 | ecoff_slurp_symbolic_info (abfd) |
612 | bfd *abfd; | |
8fa0d3a0 ILT |
613 | { |
614 | struct hdr_ext external_symhdr; | |
615 | HDRR *internal_symhdr; | |
616 | bfd_size_type raw_base; | |
617 | bfd_size_type raw_size; | |
618 | PTR raw; | |
619 | struct fdr_ext *fraw_src; | |
620 | struct fdr_ext *fraw_end; | |
621 | struct fdr *fdr_ptr; | |
622 | ||
623 | /* Check whether we've already gotten it, and whether there's any to | |
624 | get. */ | |
625 | if (ecoff_data (abfd)->raw_syments != (PTR) NULL) | |
626 | return true; | |
627 | if (ecoff_data (abfd)->sym_filepos == 0) | |
628 | { | |
629 | bfd_get_symcount (abfd) = 0; | |
630 | return true; | |
631 | } | |
632 | ||
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)) | |
638 | { | |
639 | bfd_error = bad_value; | |
640 | return false; | |
641 | } | |
642 | ||
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))) | |
647 | { | |
648 | bfd_error = system_call_error; | |
649 | return false; | |
650 | } | |
651 | internal_symhdr = &ecoff_data (abfd)->symbolic_header; | |
652 | ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr); | |
653 | ||
654 | if (internal_symhdr->magic != magicSym) | |
655 | { | |
656 | bfd_error = bad_value; | |
657 | return false; | |
658 | } | |
659 | ||
660 | /* Now we can get the correct number of symbols. */ | |
661 | bfd_get_symcount (abfd) = (internal_symhdr->isymMax | |
662 | + internal_symhdr->iextMax); | |
663 | ||
c3fe0c41 | 664 | /* Read all the symbolic information at once. */ |
23ba15b7 ILT |
665 | raw_base = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext); |
666 | ||
667 | if (internal_symhdr->cbExtOffset != 0) | |
668 | raw_size = (internal_symhdr->cbExtOffset | |
669 | - raw_base | |
670 | + internal_symhdr->iextMax * sizeof (struct ext_ext)); | |
671 | else | |
672 | { | |
673 | long cbline, issmax, issextmax; | |
674 | ||
6d18a99d ILT |
675 | cbline = (internal_symhdr->cbLine + 3) &~ 3; |
676 | issmax = (internal_symhdr->issMax + 3) &~ 3; | |
677 | issextmax = (internal_symhdr->issExtMax + 3) &~ 3; | |
23ba15b7 ILT |
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)); | |
689 | } | |
690 | ||
c3fe0c41 ILT |
691 | if (raw_size == 0) |
692 | { | |
693 | ecoff_data (abfd)->sym_filepos = 0; | |
694 | return true; | |
695 | } | |
8fa0d3a0 ILT |
696 | raw = (PTR) bfd_alloc (abfd, raw_size); |
697 | if (raw == NULL) | |
698 | { | |
699 | bfd_error = no_memory; | |
700 | return false; | |
701 | } | |
702 | if (bfd_read (raw, raw_size, 1, abfd) != raw_size) | |
703 | { | |
704 | bfd_error = system_call_error; | |
705 | bfd_release (abfd, raw); | |
706 | return false; | |
707 | } | |
708 | ||
709 | ecoff_data (abfd)->raw_size = raw_size; | |
710 | ecoff_data (abfd)->raw_syments = raw; | |
711 | ||
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; \ | |
716 | else \ | |
717 | ecoff_data (abfd)->off2 = (type *) ((char *) raw \ | |
718 | + internal_symhdr->off1 \ | |
719 | - raw_base) | |
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); | |
731 | #undef FIX | |
732 | ||
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. | |
738 | ||
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) | |
745 | { | |
746 | bfd_error = no_memory; | |
747 | return false; | |
748 | } | |
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); | |
754 | ||
755 | return true; | |
756 | } | |
757 | \f | |
515c4292 ILT |
758 | /* ECOFF symbol table routines. The ECOFF symbol table is described |
759 | in gcc/mips-tfile.c. */ | |
760 | ||
bf4b84bc ILT |
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 | |
765 | section. */ | |
766 | static asection ecoff_scom_section; | |
767 | static asymbol ecoff_scom_symbol; | |
768 | static asymbol *ecoff_scom_symbol_ptr; | |
769 | ||
515c4292 ILT |
770 | /* Create an empty symbol. */ |
771 | ||
772 | static asymbol * | |
f6409552 ILT |
773 | ecoff_make_empty_symbol (abfd) |
774 | bfd *abfd; | |
515c4292 ILT |
775 | { |
776 | ecoff_symbol_type *new; | |
777 | ||
778 | new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type)); | |
779 | if (new == (ecoff_symbol_type *) NULL) | |
780 | { | |
781 | bfd_error = no_memory; | |
782 | return (asymbol *) NULL; | |
783 | } | |
46bc1bf6 | 784 | memset (new, 0, sizeof *new); |
515c4292 ILT |
785 | new->symbol.section = (asection *) NULL; |
786 | new->fdr = (FDR *) NULL; | |
787 | new->local = false; | |
788 | new->native.lnative = (struct sym_ext *) NULL; | |
789 | new->symbol.the_bfd = abfd; | |
790 | return &new->symbol; | |
791 | } | |
792 | ||
793 | /* Set the BFD flags and section for an ECOFF symbol. */ | |
794 | ||
795 | static void | |
de17306e | 796 | ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr) |
f6409552 ILT |
797 | bfd *abfd; |
798 | SYMR *ecoff_sym; | |
799 | asymbol *asym; | |
800 | int ext; | |
de17306e | 801 | asymbol **indirect_ptr_ptr; |
515c4292 ILT |
802 | { |
803 | asym->the_bfd = abfd; | |
804 | asym->value = ecoff_sym->value; | |
805 | asym->section = &bfd_debug_section; | |
806 | asym->udata = NULL; | |
c3fe0c41 | 807 | |
de17306e ILT |
808 | /* An indirect symbol requires two consecutive stabs symbols. */ |
809 | if (*indirect_ptr_ptr != (asymbol *) NULL) | |
810 | { | |
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; | |
816 | return; | |
817 | } | |
818 | ||
819 | if (MIPS_IS_STAB (ecoff_sym) | |
820 | && (MIPS_UNMARK_STAB (ecoff_sym->index) | N_EXT) == (N_INDR | N_EXT)) | |
821 | { | |
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; | |
826 | return; | |
827 | } | |
828 | ||
c3fe0c41 ILT |
829 | /* Most symbol types are just for debugging. */ |
830 | switch (ecoff_sym->st) | |
831 | { | |
832 | case stGlobal: | |
833 | case stStatic: | |
834 | case stLabel: | |
835 | case stProc: | |
836 | case stStaticProc: | |
46bc1bf6 | 837 | break; |
23ba15b7 | 838 | case stNil: |
46bc1bf6 ILT |
839 | if (MIPS_IS_STAB (ecoff_sym)) |
840 | { | |
841 | asym->flags = BSF_DEBUGGING; | |
842 | return; | |
843 | } | |
c3fe0c41 ILT |
844 | break; |
845 | default: | |
846 | asym->flags = BSF_DEBUGGING; | |
847 | return; | |
848 | } | |
849 | ||
515c4292 ILT |
850 | if (ext) |
851 | asym->flags = BSF_EXPORT | BSF_GLOBAL; | |
852 | else | |
853 | asym->flags = BSF_LOCAL; | |
854 | switch (ecoff_sym->sc) | |
855 | { | |
856 | case scNil: | |
23ba15b7 ILT |
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; | |
515c4292 ILT |
862 | break; |
863 | case scText: | |
864 | asym->section = bfd_make_section_old_way (abfd, ".text"); | |
865 | asym->value -= asym->section->vma; | |
866 | break; | |
867 | case scData: | |
868 | asym->section = bfd_make_section_old_way (abfd, ".data"); | |
869 | asym->value -= asym->section->vma; | |
870 | break; | |
871 | case scBss: | |
c3fe0c41 | 872 | if (ext) |
23ba15b7 ILT |
873 | { |
874 | asym->section = &bfd_com_section; | |
875 | asym->flags = 0; | |
876 | } | |
c3fe0c41 ILT |
877 | else |
878 | { | |
879 | asym->section = bfd_make_section_old_way (abfd, ".bss"); | |
880 | asym->value -= asym->section->vma; | |
881 | } | |
515c4292 ILT |
882 | break; |
883 | case scRegister: | |
884 | asym->flags = BSF_DEBUGGING; | |
885 | break; | |
886 | case scAbs: | |
887 | asym->section = &bfd_abs_section; | |
515c4292 ILT |
888 | break; |
889 | case scUndefined: | |
890 | asym->section = &bfd_und_section; | |
23ba15b7 ILT |
891 | asym->flags = 0; |
892 | asym->value = 0; | |
515c4292 ILT |
893 | break; |
894 | case scCdbLocal: | |
895 | case scBits: | |
896 | case scCdbSystem: | |
897 | case scRegImage: | |
898 | case scInfo: | |
899 | case scUserStruct: | |
900 | asym->flags = BSF_DEBUGGING; | |
901 | break; | |
902 | case scSData: | |
903 | asym->section = bfd_make_section_old_way (abfd, ".sdata"); | |
904 | asym->value -= asym->section->vma; | |
905 | break; | |
906 | case scSBss: | |
382f2a3d | 907 | asym->section = bfd_make_section_old_way (abfd, ".sbss"); |
bf4b84bc ILT |
908 | if (! ext) |
909 | asym->value -= asym->section->vma; | |
515c4292 ILT |
910 | break; |
911 | case scRData: | |
912 | asym->section = bfd_make_section_old_way (abfd, ".rdata"); | |
913 | asym->value -= asym->section->vma; | |
914 | break; | |
915 | case scVar: | |
916 | asym->flags = BSF_DEBUGGING; | |
917 | break; | |
918 | case scCommon: | |
46bc1bf6 | 919 | if (asym->value > ecoff_data (abfd)->gp_size) |
5e462ed9 ILT |
920 | { |
921 | asym->section = &bfd_com_section; | |
46bc1bf6 | 922 | asym->flags = 0; |
5e462ed9 ILT |
923 | break; |
924 | } | |
925 | /* Fall through. */ | |
382f2a3d | 926 | case scSCommon: |
bf4b84bc ILT |
927 | if (ecoff_scom_section.name == NULL) |
928 | { | |
929 | /* Initialize the small common section. */ | |
5e462ed9 | 930 | ecoff_scom_section.name = SCOMMON; |
bf4b84bc ILT |
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; | |
5e462ed9 | 935 | ecoff_scom_symbol.name = SCOMMON; |
bf4b84bc ILT |
936 | ecoff_scom_symbol.flags = BSF_SECTION_SYM; |
937 | ecoff_scom_symbol.section = &ecoff_scom_section; | |
938 | ecoff_scom_symbol_ptr = &ecoff_scom_symbol; | |
939 | } | |
940 | asym->section = &ecoff_scom_section; | |
23ba15b7 | 941 | asym->flags = 0; |
382f2a3d | 942 | break; |
515c4292 ILT |
943 | case scVarRegister: |
944 | case scVariant: | |
945 | asym->flags = BSF_DEBUGGING; | |
946 | break; | |
947 | case scSUndefined: | |
948 | asym->section = &bfd_und_section; | |
23ba15b7 ILT |
949 | asym->flags = 0; |
950 | asym->value = 0; | |
515c4292 ILT |
951 | break; |
952 | case scInit: | |
953 | asym->section = bfd_make_section_old_way (abfd, ".init"); | |
954 | asym->value -= asym->section->vma; | |
955 | break; | |
956 | case scBasedVar: | |
957 | case scXData: | |
958 | case scPData: | |
959 | asym->flags = BSF_DEBUGGING; | |
960 | break; | |
961 | case scFini: | |
962 | asym->section = bfd_make_section_old_way (abfd, ".fini"); | |
963 | asym->value -= asym->section->vma; | |
964 | break; | |
965 | default: | |
515c4292 ILT |
966 | break; |
967 | } | |
de17306e ILT |
968 | |
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)) | |
973 | { | |
974 | switch (MIPS_UNMARK_STAB (ecoff_sym->index)) | |
975 | { | |
976 | default: | |
977 | break; | |
978 | ||
979 | case N_SETA: | |
980 | case N_SETT: | |
981 | case N_SETD: | |
982 | case N_SETB: | |
983 | { | |
984 | const char *name; | |
985 | asection *section; | |
986 | arelent_chain *reloc_chain; | |
987 | ||
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] == '_') | |
997 | { | |
998 | ++name; | |
999 | asym->name = name; | |
1000 | } | |
1001 | section = bfd_get_section_by_name (abfd, name); | |
1002 | if (section == (asection *) NULL) | |
1003 | { | |
1004 | char *copy; | |
1005 | ||
1006 | copy = (char *) bfd_alloc (abfd, strlen (name) + 1); | |
1007 | strcpy (copy, name); | |
1008 | section = bfd_make_section (abfd, copy); | |
1009 | } | |
1010 | ||
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; | |
1018 | ||
1019 | /* FIXME: Assumes 32 bit __CTOR_LIST__ entries. */ | |
1020 | reloc_chain->relent.howto = ecoff_howto_table + ECOFF_R_REFWORD; | |
1021 | ||
1022 | /* Set up the constructor section to hold the reloc. */ | |
1023 | section->flags = SEC_CONSTRUCTOR; | |
1024 | ++section->reloc_count; | |
9caf15da ILT |
1025 | |
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 | |
1030 | not apply. */ | |
1031 | section->alignment_power = 2; | |
1032 | ||
de17306e ILT |
1033 | reloc_chain->next = section->constructor_chain; |
1034 | section->constructor_chain = reloc_chain; | |
1035 | ||
1036 | /* FIXME: Assumes 32 bit __CTOR_LIST__ entries. */ | |
1037 | section->_raw_size += 4; | |
1038 | ||
1039 | /* Mark the symbol as a constructor. */ | |
1040 | asym->flags |= BSF_CONSTRUCTOR; | |
1041 | } | |
1042 | break; | |
1043 | } | |
1044 | } | |
515c4292 ILT |
1045 | } |
1046 | ||
1047 | /* Read an ECOFF symbol table. */ | |
1048 | ||
1049 | static boolean | |
f6409552 ILT |
1050 | ecoff_slurp_symbol_table (abfd) |
1051 | bfd *abfd; | |
515c4292 | 1052 | { |
515c4292 | 1053 | bfd_size_type internal_size; |
515c4292 ILT |
1054 | ecoff_symbol_type *internal; |
1055 | ecoff_symbol_type *internal_ptr; | |
de17306e | 1056 | asymbol *indirect_ptr; |
515c4292 ILT |
1057 | struct ext_ext *eraw_src; |
1058 | struct ext_ext *eraw_end; | |
8fa0d3a0 ILT |
1059 | FDR *fdr_ptr; |
1060 | FDR *fdr_end; | |
515c4292 ILT |
1061 | |
1062 | /* If we've already read in the symbol table, do nothing. */ | |
1063 | if (ecoff_data (abfd)->canonical_symbols != NULL) | |
1064 | return true; | |
1065 | ||
8fa0d3a0 ILT |
1066 | /* Get the symbolic information. */ |
1067 | if (ecoff_slurp_symbolic_info (abfd) == false) | |
1068 | return false; | |
1069 | if (bfd_get_symcount (abfd) == 0) | |
1070 | return true; | |
515c4292 ILT |
1071 | |
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) | |
1075 | { | |
1076 | bfd_error = no_memory; | |
1077 | return false; | |
1078 | } | |
1079 | ||
1080 | internal_ptr = internal; | |
de17306e | 1081 | indirect_ptr = NULL; |
515c4292 | 1082 | eraw_src = ecoff_data (abfd)->external_ext; |
8fa0d3a0 | 1083 | eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax; |
515c4292 ILT |
1084 | for (; eraw_src < eraw_end; eraw_src++, internal_ptr++) |
1085 | { | |
1086 | EXTR internal_esym; | |
1087 | ||
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, | |
de17306e | 1092 | &internal_ptr->symbol, 1, &indirect_ptr); |
515c4292 ILT |
1093 | internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd; |
1094 | internal_ptr->local = false; | |
1095 | internal_ptr->native.enative = eraw_src; | |
1096 | } | |
de17306e | 1097 | BFD_ASSERT (indirect_ptr == (asymbol *) NULL); |
515c4292 ILT |
1098 | |
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; | |
8fa0d3a0 | 1102 | fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax; |
515c4292 ILT |
1103 | for (; fdr_ptr < fdr_end; fdr_ptr++) |
1104 | { | |
1105 | struct sym_ext *lraw_src; | |
1106 | struct sym_ext *lraw_end; | |
1107 | ||
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++) | |
1111 | { | |
1112 | SYMR internal_sym; | |
1113 | ||
1114 | ecoff_swap_sym_in (abfd, lraw_src, &internal_sym); | |
1115 | internal_ptr->symbol.name = (ecoff_data (abfd)->ss | |
1116 | + fdr_ptr->issBase | |
1117 | + internal_sym.iss); | |
1118 | ecoff_set_symbol_info (abfd, &internal_sym, | |
de17306e | 1119 | &internal_ptr->symbol, 0, &indirect_ptr); |
515c4292 ILT |
1120 | internal_ptr->fdr = fdr_ptr; |
1121 | internal_ptr->local = true; | |
1122 | internal_ptr->native.lnative = lraw_src; | |
1123 | } | |
1124 | } | |
de17306e | 1125 | BFD_ASSERT (indirect_ptr == (asymbol *) NULL); |
515c4292 ILT |
1126 | |
1127 | ecoff_data (abfd)->canonical_symbols = internal; | |
1128 | ||
1129 | return true; | |
1130 | } | |
1131 | ||
1132 | static unsigned int | |
f6409552 ILT |
1133 | ecoff_get_symtab_upper_bound (abfd) |
1134 | bfd *abfd; | |
515c4292 | 1135 | { |
8fa0d3a0 ILT |
1136 | if (ecoff_slurp_symbolic_info (abfd) == false |
1137 | || bfd_get_symcount (abfd) == 0) | |
515c4292 ILT |
1138 | return 0; |
1139 | ||
1140 | return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *)); | |
1141 | } | |
1142 | ||
1143 | static unsigned int | |
f6409552 ILT |
1144 | ecoff_get_symtab (abfd, alocation) |
1145 | bfd *abfd; | |
1146 | asymbol **alocation; | |
515c4292 ILT |
1147 | { |
1148 | unsigned int counter = 0; | |
1149 | ecoff_symbol_type *symbase; | |
1150 | ecoff_symbol_type **location = (ecoff_symbol_type **) alocation; | |
1151 | ||
8fa0d3a0 ILT |
1152 | if (ecoff_slurp_symbol_table (abfd) == false |
1153 | || bfd_get_symcount (abfd) == 0) | |
515c4292 ILT |
1154 | return 0; |
1155 | ||
1156 | symbase = ecoff_data (abfd)->canonical_symbols; | |
1157 | while (counter < bfd_get_symcount (abfd)) | |
1158 | { | |
1159 | *(location++) = symbase++; | |
1160 | counter++; | |
1161 | } | |
1162 | *location++ = (ecoff_symbol_type *) NULL; | |
1163 | return bfd_get_symcount (abfd); | |
1164 | } | |
1165 | ||
1166 | /* Turn ECOFF type information into a printable string. | |
f6409552 ILT |
1167 | ecoff_emit_aggregate and ecoff_type_to_string are from |
1168 | gcc/mips-tdump.c, with swapping added and used_ptr removed. */ | |
515c4292 ILT |
1169 | |
1170 | /* Write aggregate information to a string. */ | |
1171 | ||
1172 | static void | |
f6409552 ILT |
1173 | ecoff_emit_aggregate (abfd, string, rndx, isym, which) |
1174 | bfd *abfd; | |
1175 | char *string; | |
1176 | RNDXR *rndx; | |
1177 | long isym; | |
1178 | CONST char *which; | |
515c4292 ILT |
1179 | { |
1180 | int ifd = rndx->rfd; | |
1181 | int indx = rndx->index; | |
1182 | int sym_base, ss_base; | |
1183 | CONST char *name; | |
1184 | ||
1185 | if (ifd == 0xfff) | |
1186 | ifd = isym; | |
1187 | ||
1188 | sym_base = ecoff_data (abfd)->fdr[ifd].isymBase; | |
1189 | ss_base = ecoff_data (abfd)->fdr[ifd].issBase; | |
1190 | ||
1191 | if (indx == indexNil) | |
1192 | name = "/* no name */"; | |
1193 | else | |
1194 | { | |
1195 | SYMR sym; | |
1196 | ||
1197 | indx += sym_base; | |
1198 | ecoff_swap_sym_in (abfd, | |
1199 | ecoff_data (abfd)->external_sym + indx, | |
1200 | &sym); | |
1201 | name = ecoff_data (abfd)->ss + ss_base + sym.iss; | |
1202 | } | |
1203 | ||
1204 | sprintf (string, | |
1205 | "%s %s { ifd = %d, index = %d }", | |
1206 | which, name, ifd, | |
1207 | indx + ecoff_data (abfd)->symbolic_header.iextMax); | |
1208 | } | |
1209 | ||
1210 | /* Convert the type information to string format. */ | |
1211 | ||
1212 | static char * | |
f6409552 ILT |
1213 | ecoff_type_to_string (abfd, aux_ptr, indx, bigendian) |
1214 | bfd *abfd; | |
1215 | union aux_ext *aux_ptr; | |
1216 | int indx; | |
1217 | int bigendian; | |
515c4292 ILT |
1218 | { |
1219 | AUXU u; | |
1220 | struct qual { | |
1221 | unsigned int type; | |
1222 | int low_bound; | |
1223 | int high_bound; | |
1224 | int stride; | |
1225 | } qualifiers[7]; | |
1226 | ||
1227 | unsigned int basic_type; | |
1228 | int i; | |
1229 | static char buffer1[1024]; | |
1230 | static char buffer2[1024]; | |
1231 | char *p1 = buffer1; | |
1232 | char *p2 = buffer2; | |
1233 | RNDXR rndx; | |
1234 | ||
1235 | for (i = 0; i < 7; i++) | |
1236 | { | |
1237 | qualifiers[i].low_bound = 0; | |
1238 | qualifiers[i].high_bound = 0; | |
1239 | qualifiers[i].stride = 0; | |
1240 | } | |
1241 | ||
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); | |
1245 | ||
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; | |
1254 | ||
1255 | /* | |
1256 | * Go get the basic type. | |
1257 | */ | |
1258 | switch (basic_type) | |
1259 | { | |
1260 | case btNil: /* undefined */ | |
1261 | strcpy (p1, "nil"); | |
1262 | break; | |
1263 | ||
1264 | case btAdr: /* address - integer same size as pointer */ | |
1265 | strcpy (p1, "address"); | |
1266 | break; | |
1267 | ||
1268 | case btChar: /* character */ | |
1269 | strcpy (p1, "char"); | |
1270 | break; | |
1271 | ||
1272 | case btUChar: /* unsigned character */ | |
1273 | strcpy (p1, "unsigned char"); | |
1274 | break; | |
1275 | ||
1276 | case btShort: /* short */ | |
1277 | strcpy (p1, "short"); | |
1278 | break; | |
1279 | ||
1280 | case btUShort: /* unsigned short */ | |
1281 | strcpy (p1, "unsigned short"); | |
1282 | break; | |
1283 | ||
1284 | case btInt: /* int */ | |
1285 | strcpy (p1, "int"); | |
1286 | break; | |
1287 | ||
1288 | case btUInt: /* unsigned int */ | |
1289 | strcpy (p1, "unsigned int"); | |
1290 | break; | |
1291 | ||
1292 | case btLong: /* long */ | |
1293 | strcpy (p1, "long"); | |
1294 | break; | |
1295 | ||
1296 | case btULong: /* unsigned long */ | |
1297 | strcpy (p1, "unsigned long"); | |
1298 | break; | |
1299 | ||
1300 | case btFloat: /* float (real) */ | |
1301 | strcpy (p1, "float"); | |
1302 | break; | |
1303 | ||
1304 | case btDouble: /* Double (real) */ | |
1305 | strcpy (p1, "double"); | |
1306 | break; | |
1307 | ||
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. */ | |
1311 | ||
1312 | case btStruct: /* Structure (Record) */ | |
1313 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
f6409552 ILT |
1314 | ecoff_emit_aggregate (abfd, p1, &rndx, |
1315 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
1316 | "struct"); | |
515c4292 ILT |
1317 | indx++; /* skip aux words */ |
1318 | break; | |
1319 | ||
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. */ | |
1323 | ||
1324 | case btUnion: /* Union */ | |
1325 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
f6409552 ILT |
1326 | ecoff_emit_aggregate (abfd, p1, &rndx, |
1327 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
1328 | "union"); | |
515c4292 ILT |
1329 | indx++; /* skip aux words */ |
1330 | break; | |
1331 | ||
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. */ | |
1335 | ||
1336 | case btEnum: /* Enumeration */ | |
1337 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
f6409552 ILT |
1338 | ecoff_emit_aggregate (abfd, p1, &rndx, |
1339 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
1340 | "enum"); | |
515c4292 ILT |
1341 | indx++; /* skip aux words */ |
1342 | break; | |
1343 | ||
1344 | case btTypedef: /* defined via a typedef, isymRef points */ | |
1345 | strcpy (p1, "typedef"); | |
1346 | break; | |
1347 | ||
1348 | case btRange: /* subrange of int */ | |
1349 | strcpy (p1, "subrange"); | |
1350 | break; | |
1351 | ||
1352 | case btSet: /* pascal sets */ | |
1353 | strcpy (p1, "set"); | |
1354 | break; | |
1355 | ||
1356 | case btComplex: /* fortran complex */ | |
1357 | strcpy (p1, "complex"); | |
1358 | break; | |
1359 | ||
1360 | case btDComplex: /* fortran double complex */ | |
1361 | strcpy (p1, "double complex"); | |
1362 | break; | |
1363 | ||
1364 | case btIndirect: /* forward or unnamed typedef */ | |
1365 | strcpy (p1, "forward/unamed typedef"); | |
1366 | break; | |
1367 | ||
1368 | case btFixedDec: /* Fixed Decimal */ | |
1369 | strcpy (p1, "fixed decimal"); | |
1370 | break; | |
1371 | ||
1372 | case btFloatDec: /* Float Decimal */ | |
1373 | strcpy (p1, "float decimal"); | |
1374 | break; | |
1375 | ||
1376 | case btString: /* Varying Length Character String */ | |
1377 | strcpy (p1, "string"); | |
1378 | break; | |
1379 | ||
1380 | case btBit: /* Aligned Bit String */ | |
1381 | strcpy (p1, "bit"); | |
1382 | break; | |
1383 | ||
1384 | case btPicture: /* Picture */ | |
1385 | strcpy (p1, "picture"); | |
1386 | break; | |
1387 | ||
1388 | case btVoid: /* Void */ | |
1389 | strcpy (p1, "void"); | |
1390 | break; | |
1391 | ||
1392 | default: | |
1393 | sprintf (p1, "Unknown basic type %d", (int) basic_type); | |
1394 | break; | |
1395 | } | |
1396 | ||
1397 | p1 += strlen (buffer1); | |
1398 | ||
1399 | /* | |
1400 | * If this is a bitfield, get the bitsize. | |
1401 | */ | |
1402 | if (u.ti.fBitfield) | |
1403 | { | |
1404 | int bitsize; | |
1405 | ||
1406 | bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]); | |
1407 | sprintf (p1, " : %d", bitsize); | |
1408 | p1 += strlen (buffer1); | |
1409 | } | |
1410 | ||
1411 | ||
1412 | /* | |
1413 | * Deal with any qualifiers. | |
1414 | */ | |
1415 | if (qualifiers[0].type != tqNil) | |
1416 | { | |
1417 | /* | |
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 | |
1422 | * word 2 low bound | |
1423 | * word 3 high bound (or -1 if []) | |
1424 | * word 4 stride size in bits | |
1425 | */ | |
1426 | for (i = 0; i < 7; i++) | |
1427 | { | |
1428 | if (qualifiers[i].type == tqArray) | |
1429 | { | |
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]); | |
1436 | indx += 5; | |
1437 | } | |
1438 | } | |
1439 | ||
1440 | /* | |
1441 | * Now print out the qualifiers. | |
1442 | */ | |
1443 | for (i = 0; i < 6; i++) | |
1444 | { | |
1445 | switch (qualifiers[i].type) | |
1446 | { | |
1447 | case tqNil: | |
1448 | case tqMax: | |
1449 | break; | |
1450 | ||
1451 | case tqPtr: | |
1452 | strcpy (p2, "ptr to "); | |
1453 | p2 += sizeof ("ptr to ")-1; | |
1454 | break; | |
1455 | ||
1456 | case tqVol: | |
1457 | strcpy (p2, "volatile "); | |
1458 | p2 += sizeof ("volatile ")-1; | |
1459 | break; | |
1460 | ||
1461 | case tqFar: | |
1462 | strcpy (p2, "far "); | |
1463 | p2 += sizeof ("far ")-1; | |
1464 | break; | |
1465 | ||
1466 | case tqProc: | |
1467 | strcpy (p2, "func. ret. "); | |
1468 | p2 += sizeof ("func. ret. "); | |
1469 | break; | |
1470 | ||
1471 | case tqArray: | |
1472 | { | |
1473 | int first_array = i; | |
1474 | int j; | |
1475 | ||
1476 | /* Print array bounds reversed (ie, in the order the C | |
1477 | programmer writes them). C is such a fun language.... */ | |
1478 | ||
1479 | while (i < 5 && qualifiers[i+1].type == tqArray) | |
1480 | i++; | |
1481 | ||
1482 | for (j = i; j >= first_array; j--) | |
1483 | { | |
1484 | strcpy (p2, "array ["); | |
1485 | p2 += sizeof ("array [")-1; | |
1486 | if (qualifiers[j].low_bound != 0) | |
1487 | sprintf (p2, | |
1488 | "%ld:%ld {%ld bits}", | |
1489 | (long) qualifiers[j].low_bound, | |
1490 | (long) qualifiers[j].high_bound, | |
1491 | (long) qualifiers[j].stride); | |
1492 | ||
1493 | else if (qualifiers[j].high_bound != -1) | |
1494 | sprintf (p2, | |
1495 | "%ld {%ld bits}", | |
1496 | (long) (qualifiers[j].high_bound + 1), | |
1497 | (long) (qualifiers[j].stride)); | |
1498 | ||
1499 | else | |
1500 | sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride)); | |
1501 | ||
1502 | p2 += strlen (p2); | |
1503 | strcpy (p2, "] of "); | |
1504 | p2 += sizeof ("] of ")-1; | |
1505 | } | |
1506 | } | |
1507 | break; | |
1508 | } | |
1509 | } | |
1510 | } | |
1511 | ||
1512 | strcpy (p2, buffer1); | |
1513 | return buffer2; | |
1514 | } | |
1515 | ||
de17306e ILT |
1516 | /* Return information about ECOFF symbol SYMBOL in RET. */ |
1517 | ||
1518 | static void | |
1519 | ecoff_get_symbol_info (abfd, symbol, ret) | |
1520 | bfd *abfd; /* Ignored. */ | |
1521 | asymbol *symbol; | |
1522 | symbol_info *ret; | |
1523 | { | |
1524 | bfd_symbol_info (symbol, ret); | |
1525 | } | |
1526 | ||
515c4292 ILT |
1527 | /* Print information about an ECOFF symbol. */ |
1528 | ||
1529 | static void | |
f6409552 ILT |
1530 | ecoff_print_symbol (abfd, filep, symbol, how) |
1531 | bfd *abfd; | |
1532 | PTR filep; | |
1533 | asymbol *symbol; | |
1534 | bfd_print_symbol_type how; | |
515c4292 ILT |
1535 | { |
1536 | FILE *file = (FILE *)filep; | |
1537 | ||
1538 | switch (how) | |
1539 | { | |
1540 | case bfd_print_symbol_name: | |
1541 | fprintf (file, "%s", symbol->name); | |
1542 | break; | |
1543 | case bfd_print_symbol_more: | |
1544 | if (ecoffsymbol (symbol)->local) | |
1545 | { | |
1546 | SYMR ecoff_sym; | |
1547 | ||
1548 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
1549 | &ecoff_sym); | |
1550 | fprintf (file, "ecoff local %lx %x %x", | |
1551 | (unsigned long) ecoff_sym.value, | |
1552 | (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc); | |
1553 | } | |
1554 | else | |
1555 | { | |
1556 | EXTR ecoff_ext; | |
1557 | ||
1558 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
1559 | &ecoff_ext); | |
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); | |
1564 | } | |
1565 | break; | |
515c4292 ILT |
1566 | case bfd_print_symbol_all: |
1567 | /* Print out the symbols in a reasonable way */ | |
1568 | { | |
515c4292 ILT |
1569 | char type; |
1570 | int pos; | |
1571 | EXTR ecoff_ext; | |
1572 | char jmptbl; | |
1573 | char cobol_main; | |
1574 | char weakext; | |
1575 | ||
1576 | if (ecoffsymbol (symbol)->local) | |
1577 | { | |
1578 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
1579 | &ecoff_ext.asym); | |
1580 | type = 'l'; | |
1581 | pos = (ecoffsymbol (symbol)->native.lnative | |
1582 | - ecoff_data (abfd)->external_sym | |
1583 | + ecoff_data (abfd)->symbolic_header.iextMax); | |
1584 | jmptbl = ' '; | |
1585 | cobol_main = ' '; | |
1586 | weakext = ' '; | |
1587 | } | |
1588 | else | |
1589 | { | |
1590 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
1591 | &ecoff_ext); | |
1592 | type = 'e'; | |
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' : ' '; | |
1598 | } | |
1599 | ||
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, | |
1606 | symbol->name); | |
1607 | ||
1608 | if (ecoffsymbol (symbol)->fdr != NULL | |
1609 | && ecoff_ext.asym.index != indexNil) | |
1610 | { | |
1611 | unsigned indx; | |
1612 | int bigendian; | |
1613 | long sym_base; | |
1614 | union aux_ext *aux_base; | |
1615 | ||
1616 | indx = ecoff_ext.asym.index; | |
1617 | ||
1618 | /* sym_base is used to map the fdr relative indices which | |
1619 | appear in the file to the position number which we are | |
1620 | using. */ | |
1621 | sym_base = ecoffsymbol (symbol)->fdr->isymBase; | |
1622 | if (ecoffsymbol (symbol)->local) | |
1623 | sym_base += ecoff_data (abfd)->symbolic_header.iextMax; | |
1624 | ||
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); | |
1629 | ||
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; | |
1633 | ||
1634 | /* This switch is basically from gcc/mips-tdump.c */ | |
1635 | switch (ecoff_ext.asym.st) | |
1636 | { | |
1637 | case stNil: | |
1638 | case stLabel: | |
1639 | break; | |
1640 | ||
1641 | case stFile: | |
1642 | case stBlock: | |
1643 | printf ("\n End+1 symbol: %ld", indx + sym_base); | |
1644 | break; | |
1645 | ||
1646 | case stEnd: | |
1647 | if (ecoff_ext.asym.sc == scText | |
1648 | || ecoff_ext.asym.sc == scInfo) | |
1649 | printf ("\n First symbol: %ld", indx + sym_base); | |
1650 | else | |
1651 | printf ("\n First symbol: %ld", | |
de17306e ILT |
1652 | (long) (AUX_GET_ISYM (bigendian, |
1653 | &aux_base[ecoff_ext.asym.index]) | |
1654 | + sym_base)); | |
515c4292 ILT |
1655 | break; |
1656 | ||
1657 | case stProc: | |
1658 | case stStaticProc: | |
1659 | if (MIPS_IS_STAB (&ecoff_ext.asym)) | |
1660 | ; | |
1661 | else if (ecoffsymbol (symbol)->local) | |
1662 | printf ("\n End+1 symbol: %-7ld Type: %s", | |
de17306e ILT |
1663 | (long) (AUX_GET_ISYM (bigendian, |
1664 | &aux_base[ecoff_ext.asym.index]) | |
1665 | + sym_base), | |
f6409552 ILT |
1666 | ecoff_type_to_string (abfd, aux_base, indx + 1, |
1667 | bigendian)); | |
515c4292 | 1668 | else |
b6bef862 ILT |
1669 | printf ("\n Local symbol: %d", |
1670 | (indx | |
1671 | + sym_base | |
1672 | + ecoff_data (abfd)->symbolic_header.iextMax)); | |
515c4292 ILT |
1673 | break; |
1674 | ||
1675 | default: | |
1676 | if (!MIPS_IS_STAB (&ecoff_ext.asym)) | |
1677 | printf ("\n Type: %s", | |
f6409552 ILT |
1678 | ecoff_type_to_string (abfd, aux_base, indx, |
1679 | bigendian)); | |
515c4292 ILT |
1680 | break; |
1681 | } | |
1682 | } | |
1683 | } | |
1684 | break; | |
1685 | } | |
1686 | } | |
1687 | \f | |
b6bef862 ILT |
1688 | /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in |
1689 | external form. They use a bit which indicates whether the symbol | |
1690 | is external. */ | |
1691 | ||
1692 | /* Swap a reloc in. */ | |
1693 | ||
1694 | static void | |
f6409552 ILT |
1695 | ecoff_swap_reloc_in (abfd, ext, intern) |
1696 | bfd *abfd; | |
1697 | RELOC *ext; | |
1698 | struct internal_reloc *intern; | |
b6bef862 ILT |
1699 | { |
1700 | intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr); | |
1701 | if (abfd->xvec->header_byteorder_big_p != false) | |
1702 | { | |
c3fe0c41 | 1703 | intern->r_symndx = (((int) ext->r_bits[0] |
b6bef862 | 1704 | << RELOC_BITS0_SYMNDX_SH_LEFT_BIG) |
c3fe0c41 | 1705 | | ((int) ext->r_bits[1] |
b6bef862 | 1706 | << RELOC_BITS1_SYMNDX_SH_LEFT_BIG) |
c3fe0c41 | 1707 | | ((int) ext->r_bits[2] |
b6bef862 ILT |
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; | |
1712 | } | |
1713 | else | |
1714 | { | |
c3fe0c41 | 1715 | intern->r_symndx = (((int) ext->r_bits[0] |
b6bef862 | 1716 | << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE) |
c3fe0c41 | 1717 | | ((int) ext->r_bits[1] |
b6bef862 | 1718 | << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE) |
c3fe0c41 | 1719 | | ((int) ext->r_bits[2] |
b6bef862 ILT |
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; | |
1724 | } | |
1725 | } | |
1726 | ||
1727 | /* Swap a reloc out. */ | |
1728 | ||
1729 | static unsigned int | |
f6409552 ILT |
1730 | ecoff_swap_reloc_out (abfd, src, dst) |
1731 | bfd *abfd; | |
1732 | PTR src; | |
1733 | PTR dst; | |
b6bef862 ILT |
1734 | { |
1735 | struct internal_reloc *intern = (struct internal_reloc *) src; | |
1736 | RELOC *ext = (RELOC *) dst; | |
1737 | ||
1738 | bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr); | |
1739 | if (abfd->xvec->header_byteorder_big_p != false) | |
1740 | { | |
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)); | |
1747 | } | |
1748 | else | |
1749 | { | |
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)); | |
1756 | } | |
1757 | ||
1758 | return RELSZ; | |
1759 | } | |
1760 | ||
bf4b84bc ILT |
1761 | /* ECOFF relocs are either against external symbols, or against |
1762 | sections. If we are producing relocateable output, and the reloc | |
46bc1bf6 ILT |
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 | |
bf4b84bc ILT |
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. */ | |
1771 | ||
1772 | static bfd_reloc_status_type | |
1773 | ecoff_generic_reloc (abfd, | |
1774 | reloc_entry, | |
1775 | symbol, | |
1776 | data, | |
1777 | input_section, | |
1778 | output_bfd) | |
1779 | bfd *abfd; | |
1780 | arelent *reloc_entry; | |
1781 | asymbol *symbol; | |
1782 | PTR data; | |
1783 | asection *input_section; | |
1784 | bfd *output_bfd; | |
1785 | { | |
1786 | if (output_bfd != (bfd *) NULL | |
46bc1bf6 ILT |
1787 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
1788 | && reloc_entry->addend == 0) | |
bf4b84bc ILT |
1789 | { |
1790 | reloc_entry->address += input_section->output_offset; | |
1791 | return bfd_reloc_ok; | |
1792 | } | |
1793 | ||
1794 | return bfd_reloc_continue; | |
1795 | } | |
1796 | ||
46bc1bf6 ILT |
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. */ | |
1802 | ||
1803 | static bfd_byte *ecoff_refhi_addr; | |
1804 | static bfd_vma ecoff_refhi_addend; | |
b6bef862 ILT |
1805 | |
1806 | static bfd_reloc_status_type | |
bf4b84bc ILT |
1807 | ecoff_refhi_reloc (abfd, |
1808 | reloc_entry, | |
1809 | symbol, | |
1810 | data, | |
1811 | input_section, | |
1812 | output_bfd) | |
1813 | bfd *abfd; | |
1814 | arelent *reloc_entry; | |
1815 | asymbol *symbol; | |
1816 | PTR data; | |
1817 | asection *input_section; | |
1818 | bfd *output_bfd; | |
b6bef862 ILT |
1819 | { |
1820 | bfd_reloc_status_type ret; | |
b6bef862 | 1821 | bfd_vma relocation; |
b6bef862 | 1822 | |
bf4b84bc ILT |
1823 | /* If we're relocating, and this an external symbol, we don't want |
1824 | to change anything. */ | |
1825 | if (output_bfd != (bfd *) NULL | |
46bc1bf6 ILT |
1826 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
1827 | && reloc_entry->addend == 0) | |
bf4b84bc ILT |
1828 | { |
1829 | reloc_entry->address += input_section->output_offset; | |
1830 | return bfd_reloc_ok; | |
1831 | } | |
1832 | ||
b6bef862 ILT |
1833 | ret = bfd_reloc_ok; |
1834 | if (symbol->section == &bfd_und_section | |
1835 | && output_bfd == (bfd *) NULL) | |
1836 | ret = bfd_reloc_undefined; | |
1837 | ||
382f2a3d | 1838 | if (bfd_is_com_section (symbol->section)) |
b6bef862 ILT |
1839 | relocation = 0; |
1840 | else | |
1841 | relocation = symbol->value; | |
1842 | ||
bf4b84bc ILT |
1843 | relocation += symbol->section->output_section->vma; |
1844 | relocation += symbol->section->output_offset; | |
c3fe0c41 | 1845 | relocation += reloc_entry->addend; |
b6bef862 ILT |
1846 | |
1847 | if (reloc_entry->address > input_section->_cooked_size) | |
1848 | return bfd_reloc_outofrange; | |
1849 | ||
46bc1bf6 ILT |
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; | |
b6bef862 | 1853 | |
46bc1bf6 | 1854 | if (output_bfd != (bfd *) NULL) |
c3fe0c41 ILT |
1855 | reloc_entry->address += input_section->output_offset; |
1856 | ||
b6bef862 ILT |
1857 | return ret; |
1858 | } | |
1859 | ||
46bc1bf6 ILT |
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. */ | |
1863 | ||
1864 | static bfd_reloc_status_type | |
1865 | ecoff_reflo_reloc (abfd, | |
1866 | reloc_entry, | |
1867 | symbol, | |
1868 | data, | |
1869 | input_section, | |
1870 | output_bfd) | |
1871 | bfd *abfd; | |
1872 | arelent *reloc_entry; | |
1873 | asymbol *symbol; | |
1874 | PTR data; | |
1875 | asection *input_section; | |
1876 | bfd *output_bfd; | |
1877 | { | |
1878 | if (ecoff_refhi_addr != (bfd_byte *) NULL) | |
1879 | { | |
1880 | unsigned long insn; | |
1881 | unsigned long val; | |
1882 | unsigned long vallo; | |
1883 | ||
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) | |
1889 | & 0xffff); | |
1890 | val = ((insn & 0xffff) << 16) + vallo; | |
1891 | val += ecoff_refhi_addend; | |
1892 | ||
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 | |
1898 | data. */ | |
1899 | if ((vallo & 0x8000) != 0) | |
1900 | val -= 0x10000; | |
1901 | if ((val & 0x8000) != 0) | |
1902 | val += 0x10000; | |
1903 | ||
1904 | insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff); | |
1905 | bfd_put_32 (abfd, insn, ecoff_refhi_addr); | |
1906 | ||
1907 | ecoff_refhi_addr = (bfd_byte *) NULL; | |
1908 | } | |
1909 | ||
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); | |
1913 | } | |
1914 | ||
b6bef862 ILT |
1915 | /* Do a GPREL relocation. This is a 16 bit value which must become |
1916 | the offset from the gp register. */ | |
1917 | ||
1918 | static bfd_reloc_status_type | |
bf4b84bc ILT |
1919 | ecoff_gprel_reloc (abfd, |
1920 | reloc_entry, | |
1921 | symbol, | |
1922 | data, | |
1923 | input_section, | |
1924 | output_bfd) | |
1925 | bfd *abfd; | |
1926 | arelent *reloc_entry; | |
1927 | asymbol *symbol; | |
1928 | PTR data; | |
1929 | asection *input_section; | |
1930 | bfd *output_bfd; | |
b6bef862 | 1931 | { |
c3fe0c41 | 1932 | boolean relocateable; |
b6bef862 ILT |
1933 | bfd_vma relocation; |
1934 | unsigned long val; | |
1935 | unsigned long insn; | |
1936 | ||
46bc1bf6 ILT |
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 | |
1940 | file. */ | |
bf4b84bc | 1941 | if (output_bfd != (bfd *) NULL |
46bc1bf6 ILT |
1942 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
1943 | && reloc_entry->addend == 0) | |
bf4b84bc ILT |
1944 | { |
1945 | reloc_entry->address += input_section->output_offset; | |
1946 | return bfd_reloc_ok; | |
1947 | } | |
1948 | ||
b6bef862 | 1949 | if (output_bfd != (bfd *) NULL) |
c3fe0c41 ILT |
1950 | relocateable = true; |
1951 | else | |
1952 | { | |
1953 | relocateable = false; | |
1954 | output_bfd = symbol->section->output_section->owner; | |
1955 | } | |
b6bef862 | 1956 | |
c3fe0c41 ILT |
1957 | if (symbol->section == &bfd_und_section |
1958 | && relocateable == false) | |
1959 | return bfd_reloc_undefined; | |
b6bef862 | 1960 | |
c3fe0c41 ILT |
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 | |
46bc1bf6 ILT |
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)) | |
b6bef862 | 1969 | { |
bf4b84bc | 1970 | if (relocateable != false) |
c3fe0c41 ILT |
1971 | { |
1972 | /* Make up a value. */ | |
1973 | ecoff_data (output_bfd)->gp = | |
1974 | symbol->section->output_section->vma + 0x4000; | |
1975 | } | |
1976 | else | |
1977 | { | |
1978 | unsigned int count; | |
1979 | asymbol **sym; | |
1980 | unsigned int i; | |
b6bef862 | 1981 | |
c3fe0c41 ILT |
1982 | count = bfd_get_symcount (output_bfd); |
1983 | sym = bfd_get_outsymbols (output_bfd); | |
b6bef862 | 1984 | |
c3fe0c41 ILT |
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) | |
1988 | abort (); | |
b6bef862 | 1989 | |
c3fe0c41 | 1990 | for (i = 0; i < count; i++, sym++) |
b6bef862 | 1991 | { |
c3fe0c41 ILT |
1992 | register CONST char *name; |
1993 | ||
1994 | name = bfd_asymbol_name (*sym); | |
1995 | if (*name == '_' && strcmp (name, "_gp") == 0) | |
1996 | { | |
1997 | ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym); | |
1998 | break; | |
1999 | } | |
b6bef862 | 2000 | } |
b6bef862 | 2001 | |
c3fe0c41 ILT |
2002 | /* We should do something more friendly here, but we don't have |
2003 | a good reloc status to return. */ | |
2004 | if (i >= count) | |
2005 | abort (); | |
2006 | } | |
b6bef862 ILT |
2007 | } |
2008 | ||
382f2a3d | 2009 | if (bfd_is_com_section (symbol->section)) |
b6bef862 ILT |
2010 | relocation = 0; |
2011 | else | |
2012 | relocation = symbol->value; | |
2013 | ||
2014 | relocation += symbol->section->output_section->vma; | |
2015 | relocation += symbol->section->output_offset; | |
2016 | ||
2017 | if (reloc_entry->address > input_section->_cooked_size) | |
2018 | return bfd_reloc_outofrange; | |
2019 | ||
2020 | insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); | |
c3fe0c41 | 2021 | |
46bc1bf6 | 2022 | /* Set val to the offset into the section or symbol. */ |
c3fe0c41 ILT |
2023 | val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff; |
2024 | if (val & 0x8000) | |
b6bef862 | 2025 | val -= 0x10000; |
c3fe0c41 | 2026 | |
46bc1bf6 ILT |
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; | |
c3fe0c41 | 2033 | |
b6bef862 ILT |
2034 | insn = (insn &~ 0xffff) | (val & 0xffff); |
2035 | bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); | |
2036 | ||
bf4b84bc | 2037 | if (relocateable != false) |
c3fe0c41 ILT |
2038 | reloc_entry->address += input_section->output_offset; |
2039 | ||
2040 | /* Make sure it fit in 16 bits. */ | |
2041 | if (val >= 0x8000 && val < 0xffff8000) | |
2042 | return bfd_reloc_outofrange; | |
2043 | ||
2044 | return bfd_reloc_ok; | |
b6bef862 ILT |
2045 | } |
2046 | ||
b6bef862 ILT |
2047 | /* Read in the relocs for a section. */ |
2048 | ||
2049 | static boolean | |
f6409552 ILT |
2050 | ecoff_slurp_reloc_table (abfd, section, symbols) |
2051 | bfd *abfd; | |
2052 | asection *section; | |
2053 | asymbol **symbols; | |
b6bef862 ILT |
2054 | { |
2055 | RELOC *external_relocs; | |
2056 | arelent *internal_relocs; | |
2057 | arelent *rptr; | |
2058 | unsigned int i; | |
2059 | ||
2060 | if (section->relocation != (arelent *) NULL | |
2061 | || section->reloc_count == 0 | |
2062 | || (section->flags & SEC_CONSTRUCTOR) != 0) | |
2063 | return true; | |
2064 | ||
2065 | if (ecoff_slurp_symbol_table (abfd) == false) | |
2066 | return false; | |
2067 | ||
2068 | internal_relocs = (arelent *) bfd_alloc (abfd, | |
2069 | (sizeof (arelent) | |
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) | |
2074 | { | |
2075 | bfd_error = no_memory; | |
2076 | return false; | |
2077 | } | |
2078 | if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0) | |
2079 | return false; | |
2080 | if (bfd_read (external_relocs, 1, RELSZ * section->reloc_count, abfd) | |
2081 | != RELSZ * section->reloc_count) | |
2082 | { | |
2083 | bfd_error = system_call_error; | |
2084 | return false; | |
2085 | } | |
2086 | ||
2087 | for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++) | |
2088 | { | |
2089 | struct internal_reloc intern; | |
2090 | ||
2091 | ecoff_swap_reloc_in (abfd, external_relocs + i, &intern); | |
2092 | ||
c3fe0c41 | 2093 | if (intern.r_type > ECOFF_R_LITERAL) |
b6bef862 ILT |
2094 | abort (); |
2095 | ||
2096 | if (intern.r_extern) | |
2097 | { | |
2098 | /* r_symndx is an index into the external symbols. */ | |
2099 | BFD_ASSERT (intern.r_symndx >= 0 | |
2100 | && (intern.r_symndx | |
2101 | < ecoff_data (abfd)->symbolic_header.iextMax)); | |
2102 | rptr->sym_ptr_ptr = symbols + intern.r_symndx; | |
c3fe0c41 | 2103 | rptr->addend = 0; |
b6bef862 ILT |
2104 | } |
2105 | else | |
2106 | { | |
2107 | CONST char *sec_name; | |
2108 | asection *sec; | |
2109 | ||
2110 | /* r_symndx is a section key. */ | |
2111 | switch (intern.r_symndx) | |
2112 | { | |
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; | |
2122 | default: abort (); | |
2123 | } | |
2124 | ||
2125 | sec = bfd_get_section_by_name (abfd, sec_name); | |
2126 | if (sec == (asection *) NULL) | |
2127 | abort (); | |
2128 | rptr->sym_ptr_ptr = sec->symbol_ptr_ptr; | |
c3fe0c41 ILT |
2129 | |
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; | |
b6bef862 ILT |
2134 | } |
2135 | ||
2136 | rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section); | |
b6bef862 ILT |
2137 | rptr->howto = &ecoff_howto_table[intern.r_type]; |
2138 | ||
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; | |
2143 | } | |
2144 | ||
2145 | bfd_release (abfd, external_relocs); | |
2146 | ||
2147 | section->relocation = internal_relocs; | |
2148 | ||
2149 | return true; | |
2150 | } | |
2151 | ||
2152 | /* Get a canonical list of relocs. */ | |
2153 | ||
2154 | static unsigned int | |
f6409552 ILT |
2155 | ecoff_canonicalize_reloc (abfd, section, relptr, symbols) |
2156 | bfd *abfd; | |
2157 | asection *section; | |
2158 | arelent **relptr; | |
2159 | asymbol **symbols; | |
b6bef862 ILT |
2160 | { |
2161 | unsigned int count; | |
2162 | ||
2163 | if (section->flags & SEC_CONSTRUCTOR) | |
2164 | { | |
2165 | arelent_chain *chain; | |
2166 | ||
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 | |
2169 | provided. */ | |
2170 | for (count = 0, chain = section->constructor_chain; | |
2171 | count < section->reloc_count; | |
2172 | count++, chain = chain->next) | |
2173 | *relptr++ = &chain->relent; | |
2174 | } | |
bf4b84bc | 2175 | else |
b6bef862 ILT |
2176 | { |
2177 | arelent *tblptr; | |
2178 | ||
2179 | if (ecoff_slurp_reloc_table (abfd, section, symbols) == false) | |
2180 | return 0; | |
2181 | ||
2182 | tblptr = section->relocation; | |
2183 | if (tblptr == (arelent *) NULL) | |
2184 | return 0; | |
2185 | ||
2186 | for (count = 0; count < section->reloc_count; count++) | |
2187 | *relptr++ = tblptr++; | |
2188 | } | |
2189 | ||
2190 | *relptr = (arelent *) NULL; | |
2191 | ||
2192 | return section->reloc_count; | |
2193 | } | |
f68d8549 ILT |
2194 | |
2195 | /* Get the howto structure for a generic reloc type. */ | |
2196 | ||
2197 | static CONST struct reloc_howto_struct * | |
2198 | ecoff_bfd_reloc_type_lookup (abfd, code) | |
2199 | bfd *abfd; | |
2200 | bfd_reloc_code_real_type code; | |
2201 | { | |
2202 | int ecoff_type; | |
2203 | ||
2204 | switch (code) | |
2205 | { | |
2206 | case BFD_RELOC_16: | |
2207 | ecoff_type = ECOFF_R_REFHALF; | |
2208 | break; | |
2209 | case BFD_RELOC_32: | |
2210 | ecoff_type = ECOFF_R_REFWORD; | |
2211 | break; | |
2212 | case BFD_RELOC_MIPS_JMP: | |
2213 | ecoff_type = ECOFF_R_JMPADDR; | |
2214 | break; | |
2215 | case BFD_RELOC_HI16_S: | |
2216 | ecoff_type = ECOFF_R_REFHI; | |
2217 | break; | |
2218 | case BFD_RELOC_LO16: | |
2219 | ecoff_type = ECOFF_R_REFLO; | |
2220 | break; | |
46bc1bf6 ILT |
2221 | case BFD_RELOC_MIPS_GPREL: |
2222 | ecoff_type = ECOFF_R_GPREL; | |
2223 | break; | |
f68d8549 ILT |
2224 | default: |
2225 | return (CONST struct reloc_howto_struct *) NULL; | |
2226 | } | |
2227 | ||
2228 | return &ecoff_howto_table[ecoff_type]; | |
2229 | } | |
b6bef862 | 2230 | \f |
515c4292 ILT |
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 | |
2233 | wanted location. */ | |
2234 | ||
2235 | static boolean | |
f6409552 ILT |
2236 | ecoff_find_nearest_line (abfd, |
2237 | section, | |
2238 | ignore_symbols, | |
2239 | offset, | |
2240 | filename_ptr, | |
2241 | functionname_ptr, | |
2242 | retline_ptr) | |
2243 | bfd *abfd; | |
2244 | asection *section; | |
2245 | asymbol **ignore_symbols; | |
2246 | bfd_vma offset; | |
2247 | CONST char **filename_ptr; | |
2248 | CONST char **functionname_ptr; | |
2249 | unsigned int *retline_ptr; | |
515c4292 ILT |
2250 | { |
2251 | FDR *fdr_ptr; | |
2252 | FDR *fdr_start; | |
2253 | FDR *fdr_end; | |
2254 | FDR *fdr_hold; | |
2255 | struct pdr_ext *pdr_ptr; | |
2256 | struct pdr_ext *pdr_end; | |
2257 | PDR pdr; | |
2258 | unsigned char *line_ptr; | |
2259 | unsigned char *line_end; | |
2260 | int lineno; | |
515c4292 ILT |
2261 | |
2262 | /* If we're not in the .text section, we don't have any line | |
2263 | numbers. */ | |
6d18a99d ILT |
2264 | if (strcmp (section->name, _TEXT) != 0 |
2265 | || offset < ecoff_data (abfd)->text_start | |
2266 | || offset >= ecoff_data (abfd)->text_end) | |
515c4292 ILT |
2267 | return false; |
2268 | ||
8fa0d3a0 ILT |
2269 | /* Make sure we have the FDR's. */ |
2270 | if (ecoff_slurp_symbolic_info (abfd) == false | |
2271 | || bfd_get_symcount (abfd) == 0) | |
2272 | return false; | |
2273 | ||
515c4292 ILT |
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++) | |
2283 | { | |
6d18a99d ILT |
2284 | if (fdr_ptr->cpd == 0) |
2285 | continue; | |
515c4292 ILT |
2286 | if (offset < fdr_ptr->adr) |
2287 | break; | |
6d18a99d | 2288 | fdr_hold = fdr_ptr; |
515c4292 ILT |
2289 | } |
2290 | if (fdr_hold == (FDR *) NULL) | |
2291 | return false; | |
2292 | fdr_ptr = fdr_hold; | |
2293 | ||
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); | |
14e3c2e4 JK |
2301 | |
2302 | /* The address of the first PDR is an offset which applies to the | |
2303 | addresses of all the PDR's. */ | |
2304 | offset += pdr.adr; | |
2305 | ||
515c4292 ILT |
2306 | for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++) |
2307 | { | |
2308 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
2309 | if (offset < pdr.adr) | |
2310 | break; | |
2311 | } | |
2312 | ||
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; | |
2320 | else | |
2321 | line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset; | |
2322 | ||
2323 | /* Now change pdr and pdr_ptr to the one we want. */ | |
2324 | pdr_ptr--; | |
2325 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
2326 | ||
2327 | offset -= pdr.adr; | |
2328 | lineno = pdr.lnLow; | |
2329 | line_ptr = (ecoff_data (abfd)->line | |
2330 | + fdr_ptr->cbLineOffset | |
2331 | + pdr.cbLineOffset); | |
2332 | while (line_ptr < line_end) | |
2333 | { | |
2334 | int delta; | |
2335 | int count; | |
2336 | ||
2337 | delta = *line_ptr >> 4; | |
2338 | if (delta >= 0x8) | |
2339 | delta -= 0x10; | |
2340 | count = (*line_ptr & 0xf) + 1; | |
2341 | ++line_ptr; | |
2342 | if (delta == -8) | |
2343 | { | |
2344 | delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff); | |
2345 | if (delta >= 0x8000) | |
2346 | delta -= 0x10000; | |
2347 | line_ptr += 2; | |
2348 | } | |
2349 | lineno += delta; | |
2350 | if (offset < count * 4) | |
2351 | break; | |
2352 | offset -= count * 4; | |
2353 | } | |
2354 | ||
bf4b84bc ILT |
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) | |
2358 | { | |
2359 | *filename_ptr = NULL; | |
2360 | if (pdr.isym == -1) | |
2361 | *functionname_ptr = NULL; | |
2362 | else | |
2363 | { | |
2364 | EXTR proc_ext; | |
2365 | ||
2366 | ecoff_swap_ext_in (abfd, | |
2367 | (ecoff_data (abfd)->external_ext | |
2368 | + pdr.isym), | |
2369 | &proc_ext); | |
2370 | *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss; | |
2371 | } | |
2372 | } | |
2373 | else | |
2374 | { | |
2375 | SYMR proc_sym; | |
2376 | ||
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 | |
2380 | + fdr_ptr->isymBase | |
2381 | + pdr.isym), | |
2382 | &proc_sym); | |
2383 | *functionname_ptr = (ecoff_data (abfd)->ss | |
2384 | + fdr_ptr->issBase | |
2385 | + proc_sym.iss); | |
2386 | } | |
515c4292 ILT |
2387 | *retline_ptr = lineno; |
2388 | return true; | |
2389 | } | |
2390 | \f | |
8fa0d3a0 ILT |
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 | |
2394 | symbols. | |
2395 | ||
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. | |
2400 | ||
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). */ | |
2406 | ||
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 | |
2409 | once. */ | |
2410 | ||
2411 | static void | |
f6409552 ILT |
2412 | ecoff_clear_output_flags (abfd) |
2413 | bfd *abfd; | |
8fa0d3a0 ILT |
2414 | { |
2415 | register asection *o; | |
2416 | register bfd_seclet_type *p; | |
2417 | ||
2418 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
2419 | for (p = o->seclets_head; | |
2420 | p != (bfd_seclet_type *) NULL; | |
2421 | p = p->next) | |
2422 | if (p->type == bfd_indirect_seclet) | |
2423 | p->u.indirect.section->owner->output_has_begun = false; | |
2424 | } | |
2425 | ||
2426 | /* Handle an indirect seclet on the first pass. Set the contents of | |
2427 | the output section, and accumulate the debugging information if | |
2428 | any. */ | |
2429 | ||
2430 | static boolean | |
f6409552 ILT |
2431 | ecoff_rel (output_bfd, seclet, output_section, data, relocateable) |
2432 | bfd *output_bfd; | |
2433 | bfd_seclet_type *seclet; | |
2434 | asection *output_section; | |
2435 | PTR data; | |
2436 | boolean relocateable; | |
8fa0d3a0 ILT |
2437 | { |
2438 | bfd *input_bfd; | |
2439 | HDRR *output_symhdr; | |
2440 | HDRR *input_symhdr; | |
2441 | ||
2442 | if ((output_section->flags & SEC_HAS_CONTENTS) | |
2443 | && !(output_section->flags & SEC_NEVER_LOAD) | |
2444 | && (output_section->flags & SEC_LOAD) | |
2445 | && seclet->size) | |
2446 | { | |
2447 | data = (PTR) bfd_get_relocated_section_contents (output_bfd, | |
2448 | seclet, | |
2449 | data, | |
2450 | relocateable); | |
2451 | if (bfd_set_section_contents (output_bfd, | |
2452 | output_section, | |
2453 | data, | |
2454 | seclet->offset, | |
2455 | seclet->size) | |
2456 | == false) | |
2457 | { | |
2458 | abort(); | |
2459 | } | |
2460 | } | |
2461 | ||
2462 | input_bfd = seclet->u.indirect.section->owner; | |
2463 | ||
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. */ | |
2470 | ||
2471 | if (input_bfd->output_has_begun) | |
2472 | return true; | |
2473 | input_bfd->output_has_begun = true; | |
2474 | ||
2475 | output_symhdr = &ecoff_data (output_bfd)->symbolic_header; | |
2476 | ||
2477 | if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour) | |
2478 | { | |
2479 | asymbol **symbols; | |
2480 | asymbol **sym_ptr; | |
2481 | asymbol **sym_end; | |
2482 | ||
c3fe0c41 ILT |
2483 | /* We just accumulate local symbols from a non-ECOFF BFD. The |
2484 | external symbols are handled separately. */ | |
8fa0d3a0 ILT |
2485 | |
2486 | symbols = (asymbol **) bfd_alloc (output_bfd, | |
2487 | get_symtab_upper_bound (input_bfd)); | |
2488 | if (symbols == (asymbol **) NULL) | |
2489 | { | |
2490 | bfd_error = no_memory; | |
2491 | return false; | |
2492 | } | |
2493 | sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols); | |
2494 | ||
2495 | for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++) | |
2496 | { | |
2497 | size_t len; | |
2498 | ||
2499 | len = strlen ((*sym_ptr)->name); | |
2500 | if (((*sym_ptr)->flags & BSF_EXPORT) == 0) | |
2501 | { | |
2502 | ++output_symhdr->isymMax; | |
2503 | output_symhdr->issMax += len + 1; | |
2504 | } | |
8fa0d3a0 ILT |
2505 | } |
2506 | ||
2507 | bfd_release (output_bfd, (PTR) symbols); | |
2508 | ||
2509 | ++output_symhdr->ifdMax; | |
2510 | ||
2511 | return true; | |
2512 | } | |
2513 | ||
2514 | /* We simply add in the information from another ECOFF BFD. First | |
2515 | we make sure we have the symbolic information. */ | |
c3fe0c41 | 2516 | if (ecoff_slurp_symbol_table (input_bfd) == false) |
8fa0d3a0 ILT |
2517 | return false; |
2518 | if (bfd_get_symcount (input_bfd) == 0) | |
2519 | return true; | |
2520 | ||
2521 | input_symhdr = &ecoff_data (input_bfd)->symbolic_header; | |
2522 | ||
c3fe0c41 ILT |
2523 | /* Figure out how much information we are going to be putting in. |
2524 | The external symbols are handled separately. */ | |
8fa0d3a0 ILT |
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; | |
8fa0d3a0 | 2533 | output_symhdr->ifdMax += input_symhdr->ifdMax; |
8fa0d3a0 ILT |
2534 | |
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; | |
2538 | else | |
2539 | output_symhdr->crfd += input_symhdr->ifdMax; | |
2540 | ||
2541 | return true; | |
2542 | } | |
2543 | ||
2544 | /* Handle an arbitrary seclet on the first pass. */ | |
2545 | ||
2546 | static boolean | |
f6409552 ILT |
2547 | ecoff_dump_seclet (abfd, seclet, section, data, relocateable) |
2548 | bfd *abfd; | |
2549 | bfd_seclet_type *seclet; | |
2550 | asection *section; | |
2551 | PTR data; | |
2552 | boolean relocateable; | |
8fa0d3a0 ILT |
2553 | { |
2554 | switch (seclet->type) | |
2555 | { | |
2556 | case bfd_indirect_seclet: | |
2557 | /* The contents of this section come from another one somewhere | |
2558 | else. */ | |
2559 | return ecoff_rel (abfd, seclet, section, data, relocateable); | |
2560 | ||
2561 | case bfd_fill_seclet: | |
c3fe0c41 ILT |
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) | |
2565 | { | |
2566 | if (seclet->u.fill.value != 0) | |
2567 | abort (); | |
2568 | } | |
2569 | else | |
2570 | { | |
2571 | char *d = (char *) bfd_alloc (abfd, seclet->size); | |
2572 | unsigned int i; | |
2573 | boolean ret; | |
2574 | ||
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, | |
2580 | seclet->size); | |
2581 | bfd_release (abfd, (PTR) d); | |
2582 | return ret; | |
2583 | } | |
2584 | break; | |
8fa0d3a0 ILT |
2585 | |
2586 | default: | |
2587 | abort(); | |
2588 | } | |
2589 | ||
2590 | return true; | |
2591 | } | |
2592 | ||
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. */ | |
2596 | ||
2597 | static long | |
f6409552 ILT |
2598 | ecoff_add_string (output_bfd, fdr, string, external) |
2599 | bfd *output_bfd; | |
2600 | FDR *fdr; | |
2601 | CONST char *string; | |
2602 | boolean external; | |
8fa0d3a0 ILT |
2603 | { |
2604 | HDRR *symhdr; | |
2605 | size_t len; | |
2606 | long ret; | |
2607 | ||
2608 | symhdr = &ecoff_data (output_bfd)->symbolic_header; | |
2609 | len = strlen (string); | |
2610 | if (external) | |
2611 | { | |
2612 | strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string); | |
2613 | ret = symhdr->issExtMax; | |
2614 | symhdr->issExtMax += len + 1; | |
2615 | } | |
2616 | else | |
2617 | { | |
2618 | strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string); | |
2619 | ret = fdr->cbSs; | |
2620 | symhdr->issMax += len + 1; | |
2621 | fdr->cbSs += len + 1; | |
2622 | } | |
2623 | return ret; | |
2624 | } | |
2625 | ||
2626 | /* Accumulate the debugging information from an input section. */ | |
2627 | ||
2628 | static boolean | |
f6409552 ILT |
2629 | ecoff_get_debug (output_bfd, seclet, section, relocateable) |
2630 | bfd *output_bfd; | |
2631 | bfd_seclet_type *seclet; | |
2632 | asection *section; | |
2633 | boolean relocateable; | |
8fa0d3a0 ILT |
2634 | { |
2635 | bfd *input_bfd; | |
2636 | HDRR *output_symhdr; | |
2637 | HDRR *input_symhdr; | |
2638 | ecoff_data_type *output_ecoff; | |
2639 | ecoff_data_type *input_ecoff; | |
c3fe0c41 ILT |
2640 | unsigned int count; |
2641 | struct sym_ext *sym_out; | |
c3fe0c41 ILT |
2642 | ecoff_symbol_type *esym_ptr; |
2643 | ecoff_symbol_type *esym_end; | |
8fa0d3a0 ILT |
2644 | FDR *fdr_ptr; |
2645 | FDR *fdr_end; | |
2646 | struct fdr_ext *fdr_out; | |
8fa0d3a0 ILT |
2647 | |
2648 | input_bfd = seclet->u.indirect.section->owner; | |
2649 | ||
2650 | /* Don't get the information more than once. */ | |
2651 | if (input_bfd->output_has_begun) | |
2652 | return true; | |
2653 | input_bfd->output_has_begun = true; | |
2654 | ||
2655 | output_ecoff = ecoff_data (output_bfd); | |
2656 | output_symhdr = &output_ecoff->symbolic_header; | |
2657 | ||
2658 | if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour) | |
2659 | { | |
2660 | FDR fdr; | |
2661 | asymbol **symbols; | |
2662 | asymbol **sym_ptr; | |
2663 | asymbol **sym_end; | |
2664 | ||
2665 | /* This is not an ECOFF BFD. Just gather the symbols. */ | |
2666 | ||
2667 | memset (&fdr, 0, sizeof fdr); | |
2668 | ||
2669 | fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset; | |
2670 | fdr.issBase = output_symhdr->issMax; | |
2671 | fdr.cbSs = 0; | |
2672 | fdr.rss = ecoff_add_string (output_bfd, | |
2673 | &fdr, | |
2674 | bfd_get_filename (input_bfd), | |
2675 | false); | |
2676 | fdr.isymBase = output_symhdr->isymMax; | |
2677 | ||
c3fe0c41 | 2678 | /* Get the local symbols from the input BFD. */ |
8fa0d3a0 ILT |
2679 | symbols = (asymbol **) bfd_alloc (output_bfd, |
2680 | get_symtab_upper_bound (input_bfd)); | |
2681 | if (symbols == (asymbol **) NULL) | |
2682 | { | |
2683 | bfd_error = no_memory; | |
2684 | return false; | |
2685 | } | |
2686 | sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols); | |
2687 | ||
c3fe0c41 ILT |
2688 | /* Handle the local symbols. Any external symbols are handled |
2689 | separately. */ | |
8fa0d3a0 ILT |
2690 | fdr.csym = 0; |
2691 | for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++) | |
2692 | { | |
2693 | SYMR internal_sym; | |
2694 | ||
2695 | if (((*sym_ptr)->flags & BSF_EXPORT) != 0) | |
2696 | continue; | |
2697 | memset (&internal_sym, 0, sizeof internal_sym); | |
2698 | internal_sym.iss = ecoff_add_string (output_bfd, | |
2699 | &fdr, | |
2700 | (*sym_ptr)->name, | |
2701 | false); | |
5e462ed9 ILT |
2702 | |
2703 | if (bfd_is_com_section ((*sym_ptr)->section) | |
2704 | || (*sym_ptr)->section == &bfd_und_section) | |
2705 | internal_sym.value = (*sym_ptr)->value; | |
2706 | else | |
2707 | internal_sym.value = ((*sym_ptr)->value | |
2708 | + (*sym_ptr)->section->output_offset | |
2709 | + (*sym_ptr)->section->output_section->vma); | |
8fa0d3a0 ILT |
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)); | |
2716 | ++fdr.csym; | |
2717 | ++output_symhdr->isymMax; | |
2718 | } | |
2719 | ||
8fa0d3a0 ILT |
2720 | bfd_release (output_bfd, (PTR) symbols); |
2721 | ||
c3fe0c41 ILT |
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. */ | |
8fa0d3a0 ILT |
2726 | |
2727 | ecoff_swap_fdr_out (output_bfd, &fdr, | |
2728 | (output_ecoff->external_fdr | |
2729 | + output_symhdr->ifdMax)); | |
2730 | ++output_symhdr->ifdMax; | |
2731 | return true; | |
2732 | } | |
2733 | ||
2734 | /* This is an ECOFF BFD. We want to grab the information from | |
2735 | input_bfd and attach it to output_bfd. */ | |
c3fe0c41 ILT |
2736 | count = bfd_get_symcount (input_bfd); |
2737 | if (count == 0) | |
8fa0d3a0 ILT |
2738 | return true; |
2739 | input_ecoff = ecoff_data (input_bfd); | |
2740 | input_symhdr = &input_ecoff->symbolic_header; | |
2741 | ||
c3fe0c41 ILT |
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. */ | |
2746 | ||
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; | |
2750 | ||
2751 | esym_ptr = ecoff_data (input_bfd)->canonical_symbols; | |
2752 | esym_end = esym_ptr + count; | |
2753 | for (; esym_ptr < esym_end; esym_ptr++) | |
2754 | { | |
2755 | if (esym_ptr->local) | |
2756 | { | |
2757 | SYMR sym; | |
2758 | ||
2759 | ecoff_swap_sym_in (input_bfd, esym_ptr->native.lnative, &sym); | |
5e462ed9 ILT |
2760 | |
2761 | /* If we're producing an executable, move common symbols | |
2762 | into bss. */ | |
2763 | if (relocateable == false) | |
2764 | { | |
2765 | if (sym.sc == scCommon) | |
2766 | sym.sc = scBss; | |
2767 | else if (sym.sc == scSCommon) | |
2768 | sym.sc = scSBss; | |
2769 | } | |
2770 | ||
382f2a3d | 2771 | if (! bfd_is_com_section (esym_ptr->symbol.section) |
c3fe0c41 ILT |
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); | |
2778 | ++sym_out; | |
2779 | } | |
2780 | } | |
2781 | ||
2782 | /* That should have accounted for all the local symbols in | |
2783 | input_bfd. */ | |
2784 | BFD_ASSERT ((sym_out - output_ecoff->external_sym) - output_symhdr->isymMax | |
2785 | == input_symhdr->isymMax); | |
2786 | ||
2787 | /* Copy the information that does not need swapping. */ | |
2788 | memcpy (output_ecoff->line + output_symhdr->cbLine, | |
8fa0d3a0 ILT |
2789 | input_ecoff->line, |
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, | |
2795 | input_ecoff->ss, | |
2796 | input_symhdr->issMax * sizeof (char)); | |
8fa0d3a0 ILT |
2797 | |
2798 | /* Some of the information may need to be swapped. */ | |
c3fe0c41 ILT |
2799 | if (output_bfd->xvec->header_byteorder_big_p |
2800 | == input_bfd->xvec->header_byteorder_big_p) | |
8fa0d3a0 ILT |
2801 | { |
2802 | /* The two BFD's have the same endianness, so memcpy will | |
2803 | suffice. */ | |
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)); | |
8fa0d3a0 ILT |
2810 | memcpy (output_ecoff->external_opt + output_symhdr->ioptMax, |
2811 | input_ecoff->external_opt, | |
2812 | input_symhdr->ioptMax * sizeof (struct opt_ext)); | |
2813 | } | |
2814 | else | |
2815 | { | |
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; | |
8fa0d3a0 ILT |
2822 | struct opt_ext *opt_in; |
2823 | struct opt_ext *opt_end; | |
2824 | struct opt_ext *opt_out; | |
2825 | ||
2826 | /* The two BFD's have different endianness, so we must swap | |
2827 | everything in and out. This code would always work, but it | |
c3fe0c41 | 2828 | would be slow in the normal case. */ |
8fa0d3a0 ILT |
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++) | |
2833 | { | |
2834 | DNR dnr; | |
2835 | ||
2836 | ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr); | |
2837 | ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out); | |
2838 | } | |
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++) | |
2843 | { | |
2844 | PDR pdr; | |
2845 | ||
2846 | ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr); | |
2847 | ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out); | |
2848 | } | |
8fa0d3a0 ILT |
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++) | |
2853 | { | |
2854 | OPTR opt; | |
2855 | ||
2856 | ecoff_swap_opt_in (input_bfd, opt_in, &opt); | |
2857 | ecoff_swap_opt_out (output_bfd, &opt, opt_out); | |
2858 | } | |
2859 | } | |
2860 | ||
c3fe0c41 ILT |
2861 | /* Set ifdbase so that the external symbols know how to adjust their |
2862 | ifd values. */ | |
2863 | input_ecoff->ifdbase = output_symhdr->ifdMax; | |
2864 | ||
8fa0d3a0 ILT |
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++) | |
2869 | { | |
2870 | FDR fdr; | |
de17306e | 2871 | unsigned long pdr_off; |
8fa0d3a0 ILT |
2872 | |
2873 | fdr = *fdr_ptr; | |
2874 | ||
2875 | /* The memory address for this fdr is the address for the seclet | |
20f10b59 ILT |
2876 | plus the offset to this fdr within input_bfd. For some |
2877 | reason the offset of the first procedure pointer is also | |
2878 | added in. */ | |
de17306e ILT |
2879 | if (fdr.cpd == 0) |
2880 | pdr_off = 0; | |
2881 | else | |
2882 | { | |
2883 | PDR pdr; | |
2884 | ||
2885 | ecoff_swap_pdr_in (input_bfd, | |
2886 | input_ecoff->external_pdr + fdr.ipdFirst, | |
2887 | &pdr); | |
2888 | pdr_off = pdr.adr; | |
2889 | } | |
8fa0d3a0 ILT |
2890 | fdr.adr = (bfd_get_section_vma (output_bfd, section) |
2891 | + seclet->offset | |
20f10b59 ILT |
2892 | + (fdr_ptr->adr - input_ecoff->fdr->adr) |
2893 | + pdr_off); | |
8fa0d3a0 | 2894 | |
bf4b84bc ILT |
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; | |
c3fe0c41 ILT |
2902 | |
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 | |
2905 | the RFD's. */ | |
2906 | if (input_symhdr->crfd == 0) | |
2907 | fdr.crfd = input_symhdr->ifdMax; | |
2908 | ||
2909 | if (fdr.cbLine != 0) | |
bf4b84bc | 2910 | fdr.cbLineOffset += output_symhdr->cbLine; |
8fa0d3a0 ILT |
2911 | |
2912 | ecoff_swap_fdr_out (output_bfd, &fdr, fdr_out); | |
2913 | } | |
2914 | ||
2915 | if (input_symhdr->crfd > 0) | |
2916 | { | |
2917 | struct rfd_ext *rfd_in; | |
2918 | struct rfd_ext *rfd_end; | |
2919 | struct rfd_ext *rfd_out; | |
2920 | ||
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++) | |
2929 | { | |
2930 | RFDT rfd; | |
2931 | ||
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); | |
2935 | } | |
2936 | output_symhdr->crfd += input_symhdr->crfd; | |
2937 | } | |
2938 | else | |
2939 | { | |
2940 | struct rfd_ext *rfd_out; | |
2941 | struct rfd_ext *rfd_end; | |
2942 | RFDT rfd; | |
2943 | ||
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 | |
2949 | file indices. */ | |
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; | |
2956 | } | |
2957 | ||
c3fe0c41 ILT |
2958 | /* Combine the register masks. */ |
2959 | { | |
2960 | int i; | |
8fa0d3a0 | 2961 | |
c3fe0c41 | 2962 | output_ecoff->gprmask |= input_ecoff->gprmask; |
5e462ed9 | 2963 | for (i = 0; i < 4; i++) |
c3fe0c41 ILT |
2964 | output_ecoff->cprmask[i] |= input_ecoff->cprmask[i]; |
2965 | } | |
8fa0d3a0 ILT |
2966 | |
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; | |
8fa0d3a0 | 2976 | output_symhdr->ifdMax += input_symhdr->ifdMax; |
8fa0d3a0 | 2977 | |
8fa0d3a0 ILT |
2978 | return true; |
2979 | } | |
2980 | ||
2981 | /* This is the actual link routine. It makes two passes over all the | |
2982 | seclets. */ | |
2983 | ||
2984 | static boolean | |
f6409552 ILT |
2985 | ecoff_bfd_seclet_link (abfd, data, relocateable) |
2986 | bfd *abfd; | |
2987 | PTR data; | |
2988 | boolean relocateable; | |
8fa0d3a0 ILT |
2989 | { |
2990 | HDRR *symhdr; | |
2991 | int ipass; | |
2992 | register asection *o; | |
2993 | register bfd_seclet_type *p; | |
c3fe0c41 | 2994 | asymbol **sym_ptr_ptr; |
8fa0d3a0 ILT |
2995 | bfd_size_type size; |
2996 | char *raw; | |
2997 | ||
2998 | /* We accumulate the debugging information counts in the symbolic | |
2999 | header. */ | |
3000 | symhdr = &ecoff_data (abfd)->symbolic_header; | |
c3fe0c41 ILT |
3001 | symhdr->magic = magicSym; |
3002 | /* FIXME: What should the version stamp be? */ | |
3003 | symhdr->vstamp = 0; | |
8fa0d3a0 ILT |
3004 | symhdr->ilineMax = 0; |
3005 | symhdr->cbLine = 0; | |
3006 | symhdr->idnMax = 0; | |
3007 | symhdr->ipdMax = 0; | |
3008 | symhdr->isymMax = 0; | |
3009 | symhdr->ioptMax = 0; | |
3010 | symhdr->iauxMax = 0; | |
3011 | symhdr->issMax = 0; | |
3012 | symhdr->issExtMax = 0; | |
3013 | symhdr->ifdMax = 0; | |
3014 | symhdr->crfd = 0; | |
3015 | symhdr->iextMax = 0; | |
3016 | ||
c3fe0c41 ILT |
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 | |
3028 | yet. */ | |
8fa0d3a0 ILT |
3029 | |
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++) | |
3034 | { | |
3035 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
3036 | { | |
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) | |
3041 | continue; | |
3042 | ||
3043 | for (p = o->seclets_head; | |
3044 | p != (bfd_seclet_type *) NULL; | |
3045 | p = p->next) | |
3046 | { | |
3047 | if (ecoff_dump_seclet (abfd, p, o, data, relocateable) | |
3048 | == false) | |
3049 | return false; | |
3050 | } | |
3051 | } | |
3052 | } | |
3053 | ||
c3fe0c41 ILT |
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) | |
3060 | { | |
3061 | asymbol **sym_end; | |
3062 | ||
3063 | sym_end = sym_ptr_ptr + bfd_get_symcount (abfd); | |
3064 | for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++) | |
3065 | { | |
3066 | if (((*sym_ptr_ptr)->flags & BSF_DEBUGGING) == 0 | |
3067 | && ((*sym_ptr_ptr)->flags & BSF_LOCAL) == 0) | |
3068 | { | |
3069 | ++symhdr->iextMax; | |
3070 | symhdr->issExtMax += strlen ((*sym_ptr_ptr)->name) + 1; | |
3071 | } | |
3072 | } | |
3073 | } | |
3074 | ||
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; | |
3079 | ||
8fa0d3a0 ILT |
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 | |
3087 | faster. */ | |
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) | |
3101 | { | |
3102 | bfd_error = no_memory; | |
3103 | return false; | |
3104 | } | |
3105 | ecoff_data (abfd)->raw_size = size; | |
3106 | ecoff_data (abfd)->raw_syments = (PTR) raw; | |
3107 | ||
3108 | /* Initialize the raw pointers. */ | |
3109 | #define SET(field, count, type) \ | |
3110 | ecoff_data (abfd)->field = (type *) raw; \ | |
3111 | raw += symhdr->count * sizeof (type) | |
3112 | ||
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); | |
3124 | #undef SET | |
3125 | ||
3126 | /* Reset the counts so the second pass can use them to know how far | |
3127 | it has gotten. */ | |
3128 | symhdr->ilineMax = 0; | |
3129 | symhdr->cbLine = 0; | |
3130 | symhdr->idnMax = 0; | |
3131 | symhdr->ipdMax = 0; | |
3132 | symhdr->isymMax = 0; | |
3133 | symhdr->ioptMax = 0; | |
3134 | symhdr->iauxMax = 0; | |
3135 | symhdr->issMax = 0; | |
3136 | symhdr->issExtMax = 0; | |
3137 | symhdr->ifdMax = 0; | |
3138 | symhdr->crfd = 0; | |
3139 | symhdr->iextMax = 0; | |
3140 | ||
3141 | /* Do the second pass: accumulate the debugging information. */ | |
3142 | ecoff_clear_output_flags (abfd); | |
3143 | for (ipass = 0; ipass < 2; ipass++) | |
3144 | { | |
3145 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
3146 | { | |
3147 | if (((o->flags & SEC_CODE) == 0) != ipass) | |
3148 | continue; | |
3149 | for (p = o->seclets_head; | |
3150 | p != (bfd_seclet_type *) NULL; | |
3151 | p = p->next) | |
3152 | { | |
3153 | if (p->type == bfd_indirect_seclet) | |
3154 | { | |
5e462ed9 | 3155 | if (ecoff_get_debug (abfd, p, o, relocateable) == false) |
8fa0d3a0 ILT |
3156 | return false; |
3157 | } | |
3158 | } | |
3159 | } | |
3160 | } | |
3161 | ||
c3fe0c41 ILT |
3162 | /* Put in the external symbols. */ |
3163 | sym_ptr_ptr = bfd_get_outsymbols (abfd); | |
3164 | if (sym_ptr_ptr != NULL) | |
3165 | { | |
3166 | char *ssext; | |
3167 | struct ext_ext *external_ext; | |
3168 | ||
3169 | ssext = ecoff_data (abfd)->ssext; | |
3170 | external_ext = ecoff_data (abfd)->external_ext; | |
3171 | for (; *sym_ptr_ptr != NULL; sym_ptr_ptr++) | |
3172 | { | |
3173 | asymbol *sym_ptr; | |
3174 | EXTR esym; | |
3175 | ||
3176 | sym_ptr = *sym_ptr_ptr; | |
3177 | ||
3178 | if ((sym_ptr->flags & BSF_DEBUGGING) != 0 | |
3179 | || (sym_ptr->flags & BSF_LOCAL) != 0) | |
3180 | continue; | |
3181 | ||
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)) | |
3187 | { | |
3188 | esym.jmptbl = 0; | |
3189 | esym.cobol_main = 0; | |
3190 | esym.weakext = 0; | |
3191 | esym.reserved = 0; | |
3192 | esym.ifd = ifdNil; | |
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; | |
3198 | } | |
3199 | else | |
3200 | { | |
3201 | ecoff_symbol_type *ecoff_sym_ptr; | |
3202 | ||
3203 | ecoff_sym_ptr = (ecoff_symbol_type *) sym_ptr; | |
3204 | if (ecoff_sym_ptr->local) | |
3205 | abort (); | |
3206 | ecoff_swap_ext_in (abfd, ecoff_sym_ptr->native.enative, &esym); | |
3207 | ||
5e462ed9 ILT |
3208 | /* If we're producing an executable, move common symbols |
3209 | into bss. */ | |
3210 | if (relocateable == false) | |
3211 | { | |
3212 | if (esym.asym.sc == scCommon) | |
3213 | esym.asym.sc = scBss; | |
3214 | else if (esym.asym.sc == scSCommon) | |
3215 | esym.asym.sc = scSBss; | |
3216 | } | |
3217 | ||
c3fe0c41 ILT |
3218 | /* Adjust the FDR index for the symbol by that used for |
3219 | the input BFD. */ | |
3220 | esym.ifd += ecoff_data (bfd_asymbol_bfd (sym_ptr))->ifdbase; | |
3221 | } | |
3222 | ||
3223 | esym.asym.iss = symhdr->issExtMax; | |
3224 | ||
382f2a3d | 3225 | if (bfd_is_com_section (sym_ptr->section) |
c3fe0c41 ILT |
3226 | || sym_ptr->section == &bfd_und_section) |
3227 | esym.asym.value = sym_ptr->value; | |
3228 | else | |
3229 | esym.asym.value = (sym_ptr->value | |
3230 | + sym_ptr->section->output_offset | |
3231 | + sym_ptr->section->output_section->vma); | |
3232 | ||
3233 | ecoff_swap_ext_out (abfd, &esym, external_ext + symhdr->iextMax); | |
3234 | ||
3235 | ecoff_set_sym_index (sym_ptr, symhdr->iextMax); | |
3236 | ||
3237 | ++symhdr->iextMax; | |
3238 | ||
3239 | strcpy (ssext + symhdr->issExtMax, sym_ptr->name); | |
3240 | symhdr->issExtMax += strlen (sym_ptr->name) + 1; | |
3241 | } | |
3242 | } | |
3243 | ||
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; | |
3248 | ||
8fa0d3a0 ILT |
3249 | return true; |
3250 | } | |
3251 | \f | |
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. */ | |
3255 | ||
3256 | static boolean | |
f6409552 ILT |
3257 | ecoff_set_arch_mach (abfd, arch, machine) |
3258 | bfd *abfd; | |
3259 | enum bfd_architecture arch; | |
3260 | unsigned long machine; | |
8fa0d3a0 ILT |
3261 | { |
3262 | bfd_default_set_arch_mach (abfd, arch, machine); | |
3263 | return arch == bfd_arch_mips; | |
3264 | } | |
3265 | ||
5e462ed9 ILT |
3266 | /* Get the size of the section headers. We do not output the .scommon |
3267 | section which we created in ecoff_mkobject. */ | |
3268 | ||
3269 | static int | |
3270 | ecoff_sizeof_headers (abfd, reloc) | |
3271 | bfd *abfd; | |
3272 | boolean reloc; | |
3273 | { | |
3274 | return FILHSZ + AOUTSZ + (abfd->section_count - 1) * SCNHSZ; | |
3275 | } | |
3276 | ||
8fa0d3a0 ILT |
3277 | /* Calculate the file position for each section, and set |
3278 | reloc_filepos. */ | |
3279 | ||
3280 | static void | |
f6409552 ILT |
3281 | ecoff_compute_section_file_positions (abfd) |
3282 | bfd *abfd; | |
8fa0d3a0 ILT |
3283 | { |
3284 | asection *current; | |
8fa0d3a0 ILT |
3285 | file_ptr sofar; |
3286 | file_ptr old_sofar; | |
c3fe0c41 | 3287 | boolean first_data; |
8fa0d3a0 | 3288 | |
8fa0d3a0 | 3289 | if (bfd_get_start_address (abfd)) |
c3fe0c41 | 3290 | abfd->flags |= EXEC_P; |
8fa0d3a0 | 3291 | |
5e462ed9 | 3292 | sofar = ecoff_sizeof_headers (abfd, false); |
8fa0d3a0 | 3293 | |
c3fe0c41 | 3294 | first_data = true; |
8fa0d3a0 ILT |
3295 | for (current = abfd->sections; |
3296 | current != (asection *) NULL; | |
3297 | current = current->next) | |
3298 | { | |
3299 | /* Only deal with sections which have contents */ | |
5e462ed9 ILT |
3300 | if (! (current->flags & SEC_HAS_CONTENTS) |
3301 | || strcmp (current->name, SCOMMON) == 0) | |
8fa0d3a0 ILT |
3302 | continue; |
3303 | ||
c3fe0c41 ILT |
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 | |
3307 | other platforms? */ | |
3308 | if ((abfd->flags & EXEC_P) != 0 | |
de17306e | 3309 | && (abfd->flags & D_PAGED) != 0 |
c3fe0c41 ILT |
3310 | && first_data != false |
3311 | && (current->flags & SEC_CODE) == 0) | |
3312 | { | |
14e3c2e4 | 3313 | sofar = (sofar + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1); |
c3fe0c41 ILT |
3314 | first_data = false; |
3315 | } | |
3316 | ||
8fa0d3a0 ILT |
3317 | /* Align the sections in the file to the same boundary on |
3318 | which they are aligned in virtual memory. */ | |
3319 | old_sofar = sofar; | |
3320 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
8fa0d3a0 ILT |
3321 | |
3322 | current->filepos = sofar; | |
3323 | ||
3324 | sofar += current->_raw_size; | |
3325 | ||
3326 | /* make sure that this section is of the right size too */ | |
3327 | old_sofar = sofar; | |
3328 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
3329 | current->_raw_size += sofar - old_sofar; | |
8fa0d3a0 ILT |
3330 | } |
3331 | ||
3332 | ecoff_data (abfd)->reloc_filepos = sofar; | |
3333 | } | |
3334 | ||
3335 | /* Set the contents of a section. */ | |
3336 | ||
3337 | static boolean | |
f6409552 ILT |
3338 | ecoff_set_section_contents (abfd, section, location, offset, count) |
3339 | bfd *abfd; | |
3340 | asection *section; | |
3341 | PTR location; | |
3342 | file_ptr offset; | |
3343 | bfd_size_type count; | |
8fa0d3a0 ILT |
3344 | { |
3345 | if (abfd->output_has_begun == false) | |
3346 | ecoff_compute_section_file_positions (abfd); | |
3347 | ||
3348 | bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET); | |
3349 | ||
3350 | if (count != 0) | |
3351 | return (bfd_write (location, 1, count, abfd) == count) ? true : false; | |
3352 | ||
3353 | return true; | |
3354 | } | |
3355 | ||
3356 | /* Write out an ECOFF file. */ | |
3357 | ||
3358 | static boolean | |
f6409552 ILT |
3359 | ecoff_write_object_contents (abfd) |
3360 | bfd *abfd; | |
8fa0d3a0 ILT |
3361 | { |
3362 | asection *current; | |
3363 | unsigned int count; | |
3364 | file_ptr scn_base; | |
3365 | file_ptr reloc_base; | |
3366 | file_ptr sym_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; | |
c3fe0c41 | 3375 | int i; |
8fa0d3a0 ILT |
3376 | |
3377 | bfd_error = system_call_error; | |
3378 | ||
3379 | if(abfd->output_has_begun == false) | |
3380 | ecoff_compute_section_file_positions(abfd); | |
3381 | ||
3382 | if (abfd->sections != (asection *) NULL) | |
3383 | scn_base = abfd->sections->filepos; | |
3384 | else | |
3385 | scn_base = 0; | |
3386 | reloc_base = ecoff_data (abfd)->reloc_filepos; | |
3387 | ||
3388 | count = 1; | |
3389 | reloc_size = 0; | |
3390 | for (current = abfd->sections; | |
3391 | current != (asection *)NULL; | |
3392 | current = current->next) | |
3393 | { | |
5e462ed9 ILT |
3394 | if (strcmp (current->name, SCOMMON) == 0) |
3395 | continue; | |
8fa0d3a0 ILT |
3396 | current->target_index = count; |
3397 | ++count; | |
3398 | if (current->reloc_count != 0) | |
3399 | { | |
3400 | bfd_size_type relsize; | |
3401 | ||
3402 | current->rel_filepos = reloc_base; | |
3403 | relsize = current->reloc_count * RELSZ; | |
3404 | reloc_size += relsize; | |
3405 | reloc_base += relsize; | |
3406 | } | |
3407 | else | |
3408 | current->rel_filepos = 0; | |
3409 | } | |
3410 | ||
3411 | sym_base = reloc_base + reloc_size; | |
c3fe0c41 ILT |
3412 | |
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 | |
3415 | platforms? */ | |
de17306e ILT |
3416 | if ((abfd->flags & EXEC_P) != 0 |
3417 | && (abfd->flags & D_PAGED) != 0) | |
14e3c2e4 | 3418 | sym_base = (sym_base + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1); |
c3fe0c41 | 3419 | |
8fa0d3a0 ILT |
3420 | ecoff_data (abfd)->sym_filepos = sym_base; |
3421 | ||
de17306e ILT |
3422 | if ((abfd->flags & D_PAGED) != 0) |
3423 | text_size = ecoff_sizeof_headers (abfd, false); | |
3424 | else | |
3425 | text_size = 0; | |
8fa0d3a0 ILT |
3426 | text_start = 0; |
3427 | data_size = 0; | |
3428 | data_start = 0; | |
3429 | bss_size = 0; | |
3430 | ||
3431 | /* Write section headers to the file. */ | |
3432 | ||
3433 | internal_f.f_nscns = 0; | |
c3fe0c41 | 3434 | if (bfd_seek (abfd, (file_ptr) (FILHSZ + AOUTSZ), SEEK_SET) != 0) |
8fa0d3a0 ILT |
3435 | return false; |
3436 | for (current = abfd->sections; | |
3437 | current != (asection *) NULL; | |
3438 | current = current->next) | |
3439 | { | |
3440 | struct internal_scnhdr section; | |
3441 | bfd_vma vma; | |
3442 | ||
5e462ed9 ILT |
3443 | if (strcmp (current->name, SCOMMON) == 0) |
3444 | { | |
3445 | BFD_ASSERT (bfd_get_section_size_before_reloc (current) == 0 | |
3446 | && current->reloc_count == 0); | |
3447 | continue; | |
3448 | } | |
3449 | ||
8fa0d3a0 ILT |
3450 | ++internal_f.f_nscns; |
3451 | ||
3452 | strncpy (section.s_name, current->name, sizeof section.s_name); | |
3453 | ||
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; | |
3459 | else | |
3460 | section.s_vaddr = vma; | |
3461 | ||
3462 | section.s_paddr = vma; | |
3463 | section.s_size = bfd_get_section_size_before_reloc (current); | |
3464 | ||
3465 | /* If this section has no size or is unloadable then the scnptr | |
3466 | will be 0 too. */ | |
3467 | if (current->_raw_size == 0 | |
3468 | || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) | |
3469 | section.s_scnptr = 0; | |
3470 | else | |
3471 | section.s_scnptr = current->filepos; | |
3472 | section.s_relptr = current->rel_filepos; | |
3473 | ||
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 | |
3480 | not present. */ | |
3481 | section.s_lnnoptr = 0; | |
3482 | ||
3483 | section.s_nreloc = current->reloc_count; | |
3484 | section.s_nlnno = 0; | |
f6409552 ILT |
3485 | section.s_flags = ecoff_sec_to_styp_flags (current->name, |
3486 | current->flags); | |
8fa0d3a0 ILT |
3487 | |
3488 | { | |
3489 | SCNHDR buff; | |
3490 | ||
3491 | ecoff_swap_scnhdr_out (abfd, (PTR) §ion, (PTR) &buff); | |
3492 | if (bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ) | |
3493 | return false; | |
3494 | } | |
3495 | ||
c3fe0c41 | 3496 | if ((section.s_flags & STYP_TEXT) != 0) |
8fa0d3a0 ILT |
3497 | { |
3498 | text_size += bfd_get_section_size_before_reloc (current); | |
3499 | if (text_start == 0 || text_start > vma) | |
3500 | text_start = vma; | |
3501 | } | |
c3fe0c41 ILT |
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 | |
8fa0d3a0 ILT |
3506 | || (section.s_flags & STYP_SDATA) != 0) |
3507 | { | |
3508 | data_size += bfd_get_section_size_before_reloc (current); | |
3509 | if (data_start == 0 || data_start > vma) | |
3510 | data_start = vma; | |
3511 | } | |
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); | |
3515 | } | |
3516 | ||
3517 | /* Set up the file header. */ | |
3518 | ||
6d18a99d ILT |
3519 | if (abfd->xvec->header_byteorder_big_p != false) |
3520 | internal_f.f_magic = MIPS_MAGIC_BIG; | |
3521 | else | |
3522 | internal_f.f_magic = MIPS_MAGIC_LITTLE; | |
8fa0d3a0 ILT |
3523 | |
3524 | /* | |
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 | |
3529 | */ | |
3530 | internal_f.f_timdat = 0; | |
3531 | ||
c3fe0c41 ILT |
3532 | if (bfd_get_symcount (abfd) != 0) |
3533 | { | |
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; | |
3538 | } | |
8fa0d3a0 | 3539 | else |
c3fe0c41 ILT |
3540 | { |
3541 | internal_f.f_nsyms = 0; | |
3542 | internal_f.f_symptr = 0; | |
3543 | } | |
8fa0d3a0 | 3544 | |
c3fe0c41 | 3545 | internal_f.f_opthdr = AOUTSZ; |
8fa0d3a0 | 3546 | |
c3fe0c41 | 3547 | internal_f.f_flags = F_LNNO; |
8fa0d3a0 ILT |
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; | |
3554 | ||
3555 | if (! abfd->xvec->byteorder_big_p) | |
3556 | internal_f.f_flags |= F_AR32WR; | |
3557 | else | |
3558 | internal_f.f_flags |= F_AR32W; | |
3559 | ||
c3fe0c41 | 3560 | /* Set up the ``optional'' header. */ |
de17306e ILT |
3561 | if ((abfd->flags & D_PAGED) != 0) |
3562 | internal_a.magic = ZMAGIC; | |
3563 | else | |
3564 | internal_a.magic = OMAGIC; | |
c3fe0c41 | 3565 | |
f6409552 ILT |
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; | |
c3fe0c41 ILT |
3569 | |
3570 | /* At least on Ultrix, these have to be rounded to page boundaries. | |
3571 | FIXME: Is this true on other platforms? */ | |
de17306e ILT |
3572 | if ((abfd->flags & D_PAGED) != 0) |
3573 | { | |
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); | |
3578 | } | |
3579 | else | |
3580 | { | |
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; | |
3585 | } | |
c3fe0c41 ILT |
3586 | |
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 | |
3591 | boundary. */ | |
3592 | if (bss_size < internal_a.dsize - data_size) | |
3593 | bss_size = 0; | |
3594 | else | |
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; | |
8fa0d3a0 | 3598 | |
c3fe0c41 | 3599 | internal_a.entry = bfd_get_start_address (abfd); |
8fa0d3a0 | 3600 | |
c3fe0c41 | 3601 | internal_a.gp_value = ecoff_data (abfd)->gp; |
8fa0d3a0 | 3602 | |
c3fe0c41 | 3603 | internal_a.gprmask = ecoff_data (abfd)->gprmask; |
5e462ed9 | 3604 | for (i = 0; i < 4; i++) |
c3fe0c41 | 3605 | internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i]; |
8fa0d3a0 ILT |
3606 | |
3607 | /* Write out the file header and the optional header. */ | |
3608 | ||
3609 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
3610 | return false; | |
3611 | ||
3612 | { | |
3613 | FILHDR buff; | |
3614 | ecoff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) &buff); | |
3615 | if (bfd_write ((PTR) &buff, 1, FILHSZ, abfd) != FILHSZ) | |
3616 | return false; | |
3617 | } | |
3618 | ||
c3fe0c41 ILT |
3619 | { |
3620 | AOUTHDR buff; | |
3621 | ||
3622 | ecoff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff); | |
3623 | if (bfd_write ((PTR) &buff, 1, AOUTSZ, abfd) != AOUTSZ) | |
3624 | return false; | |
3625 | } | |
3626 | ||
3627 | /* Write out the relocs. */ | |
3628 | for (current = abfd->sections; | |
3629 | current != (asection *) NULL; | |
3630 | current = current->next) | |
8fa0d3a0 | 3631 | { |
c3fe0c41 ILT |
3632 | RELOC *buff; |
3633 | arelent **reloc_ptr_ptr; | |
3634 | arelent **reloc_end; | |
3635 | RELOC *out_ptr; | |
3636 | ||
3637 | if (current->reloc_count == 0) | |
3638 | continue; | |
8fa0d3a0 | 3639 | |
c3fe0c41 ILT |
3640 | buff = (RELOC *) bfd_alloc (abfd, current->reloc_count * RELSZ); |
3641 | if (buff == (RELOC *) NULL) | |
3642 | { | |
3643 | bfd_error = no_memory; | |
3644 | return false; | |
3645 | } | |
3646 | ||
3647 | reloc_ptr_ptr = current->orelocation; | |
3648 | reloc_end = reloc_ptr_ptr + current->reloc_count; | |
3649 | out_ptr = buff; | |
3650 | for (; reloc_ptr_ptr < reloc_end; reloc_ptr_ptr++, out_ptr++) | |
3651 | { | |
3652 | arelent *reloc; | |
3653 | asymbol *sym; | |
3654 | struct internal_reloc in; | |
3655 | ||
3656 | memset (&in, 0, sizeof in); | |
3657 | ||
3658 | reloc = *reloc_ptr_ptr; | |
3659 | sym = *reloc->sym_ptr_ptr; | |
3660 | ||
f68d8549 ILT |
3661 | /* This must be an ECOFF reloc. */ |
3662 | BFD_ASSERT (reloc->howto != (reloc_howto_type *) NULL | |
3663 | && reloc->howto >= ecoff_howto_table | |
3664 | && (reloc->howto | |
3665 | < (ecoff_howto_table + ECOFF_HOWTO_COUNT))); | |
3666 | ||
c3fe0c41 ILT |
3667 | in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current); |
3668 | in.r_type = reloc->howto->type; | |
f68d8549 ILT |
3669 | |
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 | |
3677 | == ECOFF_R_REFLO) | |
3678 | && (sym == *reloc_ptr_ptr[1]->sym_ptr_ptr))); | |
3679 | ||
c3fe0c41 ILT |
3680 | if ((sym->flags & BSF_SECTION_SYM) == 0) |
3681 | { | |
3682 | in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr); | |
3683 | in.r_extern = 1; | |
3684 | } | |
3685 | else | |
3686 | { | |
3687 | CONST char *name; | |
3688 | ||
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; | |
3708 | else | |
3709 | abort (); | |
3710 | in.r_extern = 0; | |
3711 | } | |
3712 | ||
3713 | ecoff_swap_reloc_out (abfd, (PTR) &in, (PTR) out_ptr); | |
3714 | } | |
3715 | ||
3716 | if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0) | |
8fa0d3a0 | 3717 | return false; |
c3fe0c41 ILT |
3718 | if (bfd_write ((PTR) buff, RELSZ, current->reloc_count, abfd) |
3719 | != RELSZ * current->reloc_count) | |
3720 | return false; | |
3721 | bfd_release (abfd, (PTR) buff); | |
8fa0d3a0 ILT |
3722 | } |
3723 | ||
8fa0d3a0 ILT |
3724 | /* Write out the symbolic debugging information. */ |
3725 | if (bfd_get_symcount (abfd) > 0) | |
3726 | { | |
c3fe0c41 ILT |
3727 | HDRR *symhdr; |
3728 | unsigned long sym_offset; | |
8fa0d3a0 ILT |
3729 | struct hdr_ext buff; |
3730 | ||
c3fe0c41 ILT |
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); | |
3734 | ||
3735 | #define SET(offset, size, ptr) \ | |
3736 | if (symhdr->size == 0) \ | |
3737 | symhdr->offset = 0; \ | |
3738 | else \ | |
3739 | symhdr->offset = (((char *) ecoff_data (abfd)->ptr \ | |
3740 | - (char *) ecoff_data (abfd)->raw_syments) \ | |
3741 | + sym_offset); | |
3742 | ||
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); | |
3754 | #undef SET | |
3755 | ||
3756 | if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos, | |
3757 | SEEK_SET) != 0) | |
3758 | return false; | |
8fa0d3a0 ILT |
3759 | ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff); |
3760 | if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff) | |
3761 | return false; | |
3762 | if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1, | |
3763 | ecoff_data (abfd)->raw_size, abfd) | |
3764 | != ecoff_data (abfd)->raw_size) | |
3765 | return false; | |
3766 | } | |
de17306e ILT |
3767 | else if ((abfd->flags & EXEC_P) != 0 |
3768 | && (abfd->flags & D_PAGED) != 0) | |
3769 | { | |
3770 | char c; | |
3771 | ||
3772 | /* A demand paged executable must occupy an even number of | |
3773 | pages. */ | |
3774 | if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1, | |
3775 | SEEK_SET) != 0) | |
3776 | return false; | |
3777 | if (bfd_read (&c, 1, 1, abfd) == 0) | |
3778 | c = 0; | |
3779 | if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1, | |
3780 | SEEK_SET) != 0) | |
3781 | return false; | |
3782 | if (bfd_write (&c, 1, 1, abfd) != 1) | |
3783 | return false; | |
3784 | } | |
8fa0d3a0 ILT |
3785 | |
3786 | return true; | |
3787 | } | |
3788 | \f | |
c3fe0c41 ILT |
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. | |
3794 | ||
3795 | The first four bytes in the armap are the number of symbol | |
23ba15b7 | 3796 | definitions. This is always a power of two. |
c3fe0c41 ILT |
3797 | |
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 | |
3804 | be ignored. | |
3805 | ||
23ba15b7 ILT |
3806 | The symbols are hashed into the armap with a closed hashing scheme. |
3807 | See the functions below for the details of the algorithm. | |
3808 | ||
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. | |
3812 | ||
c3fe0c41 ILT |
3813 | After the symbol definitions comes four bytes holding the size of |
3814 | the string table, followed by the string table itself. */ | |
3815 | ||
3816 | /* The name of an archive headers looks like this: | |
23ba15b7 ILT |
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. */ | |
c3fe0c41 ILT |
3820 | |
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 "_ " | |
3831 | ||
23ba15b7 ILT |
3832 | /* This is a magic number used in the hashing algorithm. */ |
3833 | #define ARMAP_HASH_MAGIC 0x9dd68ab5 | |
3834 | ||
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 | |
3838 | base 2 of SIZE. */ | |
3839 | ||
3840 | static unsigned int | |
3841 | ecoff_armap_hash (s, rehash, size, hlog) | |
3842 | CONST char *s; | |
3843 | unsigned int *rehash; | |
3844 | unsigned int size; | |
3845 | unsigned int hlog; | |
3846 | { | |
3847 | unsigned int hash; | |
3848 | ||
3849 | hash = *s++; | |
3850 | while (*s != '\0') | |
3851 | hash = ((hash >> 27) | (hash << 5)) + *s++; | |
3852 | hash *= ARMAP_HASH_MAGIC; | |
3853 | *rehash = (hash & (size - 1)) | 1; | |
3854 | return hash >> (32 - hlog); | |
3855 | } | |
3856 | ||
c3fe0c41 ILT |
3857 | /* Read in the armap. */ |
3858 | ||
3859 | static boolean | |
f6409552 ILT |
3860 | ecoff_slurp_armap (abfd) |
3861 | bfd *abfd; | |
c3fe0c41 ILT |
3862 | { |
3863 | char nextname[17]; | |
3864 | unsigned int i; | |
3865 | struct areltdata *mapdata; | |
3866 | bfd_size_type parsed_size; | |
3867 | char *raw_armap; | |
3868 | struct artdata *ardata; | |
3869 | unsigned int count; | |
3870 | char *raw_ptr; | |
3871 | struct symdef *symdef_ptr; | |
3872 | char *stringbase; | |
3873 | ||
3874 | /* Get the name of the first element. */ | |
3875 | i = bfd_read ((PTR) nextname, 1, 16, abfd); | |
3876 | if (i == 0) | |
3877 | return true; | |
3878 | if (i != 16) | |
3879 | return false; | |
3880 | ||
3881 | bfd_seek (abfd, (file_ptr) -16, SEEK_CUR); | |
3882 | ||
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) | |
3893 | { | |
3894 | bfd_has_map (abfd) = false; | |
3895 | return true; | |
3896 | } | |
3897 | ||
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)) | |
6d18a99d | 3901 | || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN) |
c3fe0c41 ILT |
3902 | ^ (abfd->xvec->byteorder_big_p != false))) |
3903 | { | |
3904 | bfd_error = wrong_format; | |
3905 | return false; | |
3906 | } | |
3907 | ||
3908 | /* Read in the armap. */ | |
3909 | ardata = bfd_ardata (abfd); | |
3910 | mapdata = snarf_ar_hdr (abfd); | |
3911 | if (mapdata == (struct areltdata *) NULL) | |
3912 | return false; | |
3913 | parsed_size = mapdata->parsed_size; | |
3914 | bfd_release (abfd, (PTR) mapdata); | |
3915 | ||
3916 | raw_armap = (char *) bfd_alloc (abfd, parsed_size); | |
3917 | if (raw_armap == (char *) NULL) | |
3918 | { | |
3919 | bfd_error = no_memory; | |
3920 | return false; | |
3921 | } | |
3922 | ||
3923 | if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size) | |
3924 | { | |
3925 | bfd_error = malformed_archive; | |
3926 | bfd_release (abfd, (PTR) raw_armap); | |
3927 | return false; | |
3928 | } | |
3929 | ||
3930 | count = bfd_h_get_32 (abfd, (PTR) raw_armap); | |
3931 | ||
3932 | ardata->symdef_count = 0; | |
3933 | ardata->cache = (struct ar_cache *) NULL; | |
3934 | ||
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; | |
3941 | ||
23ba15b7 ILT |
3942 | #ifdef CHECK_ARMAP_HASH |
3943 | { | |
3944 | unsigned int hlog; | |
3945 | ||
3946 | /* Double check that I have the hashing algorithm right by making | |
3947 | sure that every symbol can be looked up successfully. */ | |
3948 | hlog = 0; | |
3949 | for (i = 1; i < count; i <<= 1) | |
3950 | hlog++; | |
3951 | BFD_ASSERT (i == count); | |
3952 | ||
3953 | for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE) | |
3954 | { | |
3955 | unsigned int name_offset, file_offset; | |
3956 | unsigned int hash, rehash, srch; | |
3957 | ||
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) | |
3961 | continue; | |
3962 | hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count, | |
3963 | hlog); | |
3964 | if (hash == i) | |
3965 | continue; | |
3966 | ||
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, | |
3972 | (PTR) (raw_armap | |
3973 | + LONG_SIZE | |
3974 | + (srch * 2 * LONG_SIZE) | |
3975 | + LONG_SIZE)) | |
3976 | != 0); | |
3977 | BFD_ASSERT (srch == i); | |
3978 | } | |
3979 | } | |
3980 | ||
3981 | raw_ptr = raw_armap + LONG_SIZE; | |
3982 | #endif /* CHECK_ARMAP_HASH */ | |
3983 | ||
c3fe0c41 ILT |
3984 | for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE) |
3985 | { | |
23ba15b7 | 3986 | unsigned int name_offset, file_offset; |
c3fe0c41 ILT |
3987 | |
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) | |
3991 | continue; | |
3992 | symdef_ptr->s.name = stringbase + name_offset; | |
3993 | symdef_ptr->file_offset = file_offset; | |
3994 | ++symdef_ptr; | |
3995 | ++ardata->symdef_count; | |
3996 | } | |
3997 | ||
3998 | ardata->first_file_filepos = bfd_tell (abfd); | |
3999 | /* Pad to an even boundary. */ | |
4000 | ardata->first_file_filepos += ardata->first_file_filepos % 2; | |
4001 | ||
4002 | bfd_has_map (abfd) = true; | |
4003 | ||
4004 | return true; | |
4005 | } | |
4006 | ||
4007 | /* Write out an armap. */ | |
4008 | ||
4009 | static boolean | |
f6409552 ILT |
4010 | ecoff_write_armap (abfd, elength, map, orl_count, stridx) |
4011 | bfd *abfd; | |
4012 | unsigned int elength; | |
4013 | struct orl *map; | |
4014 | unsigned int orl_count; | |
4015 | int stridx; | |
c3fe0c41 | 4016 | { |
23ba15b7 | 4017 | unsigned int hashsize, hashlog; |
c3fe0c41 ILT |
4018 | unsigned int symdefsize; |
4019 | int padit; | |
4020 | unsigned int stringsize; | |
4021 | unsigned int mapsize; | |
4022 | file_ptr firstreal; | |
4023 | struct ar_hdr hdr; | |
4024 | struct stat statbuf; | |
4025 | unsigned int i; | |
23ba15b7 ILT |
4026 | bfd_byte temp[LONG_SIZE]; |
4027 | bfd_byte *hashtable; | |
c3fe0c41 ILT |
4028 | bfd *current; |
4029 | bfd *last_elt; | |
4030 | ||
23ba15b7 ILT |
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++) | |
4034 | ; | |
4035 | hashsize = 1 << hashlog; | |
4036 | ||
4037 | symdefsize = hashsize * 2 * LONG_SIZE; | |
c3fe0c41 ILT |
4038 | padit = stridx % 2; |
4039 | stringsize = stridx + padit; | |
4040 | ||
4041 | /* Include 8 bytes to store symdefsize and stringsize in output. */ | |
23ba15b7 | 4042 | mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE; |
c3fe0c41 ILT |
4043 | |
4044 | firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength; | |
4045 | ||
4046 | memset ((PTR) &hdr, 0, sizeof hdr); | |
4047 | ||
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 | |
4053 | ? ARMAP_BIG_ENDIAN | |
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); | |
4059 | ||
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 | |
23ba15b7 ILT |
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 | |
4064 | date. */ | |
f6409552 | 4065 | stat (abfd->filename, &statbuf); |
c3fe0c41 ILT |
4066 | sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60)); |
4067 | ||
4068 | /* The DECstation uses zeroes for the uid, gid and mode of the | |
4069 | armap. */ | |
4070 | hdr.ar_uid[0] = '0'; | |
4071 | hdr.ar_gid[0] = '0'; | |
4072 | hdr.ar_mode[0] = '0'; | |
4073 | ||
4074 | sprintf (hdr.ar_size, "%-10d", (int) mapsize); | |
4075 | ||
4076 | hdr.ar_fmag[0] = '`'; | |
4077 | hdr.ar_fmag[1] = '\n'; | |
4078 | ||
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]) = ' '; | |
4083 | ||
23ba15b7 ILT |
4084 | if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd) |
4085 | != sizeof (struct ar_hdr)) | |
4086 | return false; | |
c3fe0c41 | 4087 | |
23ba15b7 ILT |
4088 | bfd_h_put_32 (abfd, hashsize, temp); |
4089 | if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE) | |
4090 | return false; | |
c3fe0c41 | 4091 | |
23ba15b7 ILT |
4092 | hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize); |
4093 | ||
c3fe0c41 ILT |
4094 | current = abfd->archive_head; |
4095 | last_elt = current; | |
4096 | for (i = 0; i < orl_count; i++) | |
4097 | { | |
23ba15b7 | 4098 | unsigned int hash, rehash; |
c3fe0c41 ILT |
4099 | |
4100 | /* Advance firstreal to the file position of this archive | |
4101 | element. */ | |
4102 | if (((bfd *) map[i].pos) != last_elt) | |
4103 | { | |
4104 | do | |
4105 | { | |
4106 | firstreal += arelt_size (current) + sizeof (struct ar_hdr); | |
4107 | firstreal += firstreal % 2; | |
4108 | current = current->next; | |
4109 | } | |
4110 | while (current != (bfd *) map[i].pos); | |
4111 | } | |
4112 | ||
4113 | last_elt = current; | |
4114 | ||
23ba15b7 ILT |
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) | |
4118 | + LONG_SIZE)) | |
4119 | != 0) | |
4120 | { | |
4121 | unsigned int srch; | |
4122 | ||
4123 | /* The desired slot is already taken. */ | |
4124 | for (srch = (hash + rehash) & (hashsize - 1); | |
4125 | srch != hash; | |
4126 | srch = (srch + rehash) & (hashsize - 1)) | |
4127 | if (bfd_h_get_32 (abfd, (PTR) (hashtable | |
4128 | + (srch * 2 * LONG_SIZE) | |
4129 | + LONG_SIZE)) | |
4130 | == 0) | |
4131 | break; | |
4132 | ||
4133 | BFD_ASSERT (srch != hash); | |
4134 | ||
4135 | hash = srch; | |
4136 | } | |
4137 | ||
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)); | |
c3fe0c41 ILT |
4142 | } |
4143 | ||
23ba15b7 ILT |
4144 | if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize) |
4145 | return false; | |
4146 | ||
4147 | bfd_release (abfd, hashtable); | |
4148 | ||
c3fe0c41 ILT |
4149 | /* Now write the strings. */ |
4150 | bfd_h_put_32 (abfd, stringsize, temp); | |
23ba15b7 ILT |
4151 | if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE) |
4152 | return false; | |
c3fe0c41 | 4153 | for (i = 0; i < orl_count; i++) |
23ba15b7 ILT |
4154 | { |
4155 | bfd_size_type len; | |
4156 | ||
4157 | len = strlen (*map[i].name) + 1; | |
4158 | if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len) | |
4159 | return false; | |
4160 | } | |
c3fe0c41 ILT |
4161 | |
4162 | /* The spec sez this should be a newline. But in order to be | |
4163 | bug-compatible for DECstation ar we use a null. */ | |
4164 | if (padit) | |
23ba15b7 ILT |
4165 | { |
4166 | if (bfd_write ("\0", 1, 1, abfd) != 1) | |
4167 | return false; | |
4168 | } | |
c3fe0c41 ILT |
4169 | |
4170 | return true; | |
4171 | } | |
4172 | ||
4173 | /* We just use the generic extended name support. This is a GNU | |
4174 | extension. */ | |
4175 | #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table | |
4176 | ||
4177 | /* See whether this BFD is an archive. If it is, read in the armap | |
4178 | and the extended name table. */ | |
4179 | ||
4180 | static bfd_target * | |
f6409552 ILT |
4181 | ecoff_archive_p (abfd) |
4182 | bfd *abfd; | |
c3fe0c41 ILT |
4183 | { |
4184 | char armag[SARMAG + 1]; | |
4185 | ||
4186 | if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG | |
4187 | || strncmp (armag, ARMAG, SARMAG) != 0) | |
4188 | { | |
4189 | bfd_error = wrong_format; | |
4190 | return (bfd_target *) NULL; | |
4191 | } | |
4192 | ||
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 | |
4195 | assignment. */ | |
4196 | abfd->tdata.aout_ar_data = | |
4197 | (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata)); | |
4198 | ||
4199 | if (bfd_ardata (abfd) == (struct artdata *) NULL) | |
4200 | { | |
4201 | bfd_error = no_memory; | |
4202 | return (bfd_target *) NULL; | |
4203 | } | |
4204 | ||
4205 | bfd_ardata (abfd)->first_file_filepos = SARMAG; | |
4206 | ||
4207 | if (ecoff_slurp_armap (abfd) == false | |
4208 | || ecoff_slurp_extended_name_table (abfd) == false) | |
4209 | { | |
4210 | bfd_release (abfd, bfd_ardata (abfd)); | |
4211 | abfd->tdata.aout_ar_data = (struct artdata *) NULL; | |
4212 | return (bfd_target *) NULL; | |
4213 | } | |
4214 | ||
4215 | return abfd->xvec; | |
4216 | } | |
4217 | \f | |
de17306e ILT |
4218 | #ifdef HOST_IRIX4 |
4219 | ||
4220 | #include <core.out.h> | |
4221 | ||
4222 | struct sgi_core_struct | |
4223 | { | |
4224 | int sig; | |
4225 | char cmd[CORE_NAMESIZE]; | |
4226 | }; | |
4227 | ||
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) | |
4231 | ||
4232 | static asection * | |
4233 | make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos) | |
4234 | bfd *abfd; | |
4235 | CONST char *name; | |
4236 | flagword flags; | |
4237 | bfd_size_type _raw_size; | |
4238 | bfd_vma vma; | |
4239 | file_ptr filepos; | |
4240 | { | |
4241 | asection *asect; | |
4242 | ||
4243 | asect = bfd_make_section (abfd, name); | |
4244 | if (!asect) | |
4245 | return NULL; | |
4246 | ||
4247 | asect->flags = flags; | |
4248 | asect->_raw_size = _raw_size; | |
4249 | asect->vma = vma; | |
4250 | asect->filepos = filepos; | |
4251 | asect->alignment_power = 4; | |
4252 | ||
4253 | return asect; | |
4254 | } | |
4255 | ||
4256 | static bfd_target * | |
4257 | ecoff_core_file_p (abfd) | |
4258 | bfd *abfd; | |
4259 | { | |
4260 | int val; | |
4261 | int i; | |
4262 | char *secname; | |
4263 | struct coreout coreout; | |
4264 | struct idesc *idg, *idf, *ids; | |
4265 | ||
4266 | val = bfd_read ((PTR)&coreout, 1, sizeof coreout, abfd); | |
4267 | if (val != sizeof coreout) | |
4268 | return 0; | |
4269 | ||
4270 | if (coreout.c_magic != CORE_MAGIC | |
4271 | || coreout.c_version != CORE_VERSION1) | |
4272 | return 0; | |
4273 | ||
4274 | core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, sizeof (struct sgi_core_struct)); | |
4275 | if (!core_hdr (abfd)) | |
4276 | return NULL; | |
4277 | ||
4278 | strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE); | |
4279 | core_signal (abfd) = coreout.c_sigcause; | |
4280 | ||
4281 | bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET); | |
4282 | ||
4283 | for (i = 0; i < coreout.c_nvmap; i++) | |
4284 | { | |
4285 | struct vmap vmap; | |
4286 | ||
4287 | val = bfd_read ((PTR)&vmap, 1, sizeof vmap, abfd); | |
4288 | if (val != sizeof vmap) | |
4289 | break; | |
4290 | ||
4291 | switch (vmap.v_type) | |
4292 | { | |
4293 | case VDATA: | |
4294 | secname = ".data"; | |
4295 | break; | |
4296 | case VSTACK: | |
4297 | secname = ".stack"; | |
4298 | break; | |
4299 | default: | |
4300 | continue; | |
4301 | } | |
4302 | ||
4303 | if (!make_bfd_asection (abfd, secname, | |
4304 | SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS, | |
4305 | vmap.v_len, | |
4306 | vmap.v_vaddr, | |
4307 | vmap.v_offset, | |
4308 | 2)) | |
4309 | return NULL; | |
4310 | } | |
4311 | ||
4312 | /* Make sure that the regs are contiguous within the core file. */ | |
4313 | ||
4314 | idg = &coreout.c_idesc[I_GPREGS]; | |
4315 | idf = &coreout.c_idesc[I_FPREGS]; | |
4316 | ids = &coreout.c_idesc[I_SPECREGS]; | |
4317 | ||
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 */ | |
4321 | ||
4322 | bfd_seek (abfd, idg->i_offset, SEEK_SET); | |
4323 | ||
4324 | make_bfd_asection (abfd, ".reg", | |
4325 | SEC_ALLOC+SEC_HAS_CONTENTS, | |
4326 | idg->i_len + idf->i_len + ids->i_len, | |
4327 | 0, | |
4328 | idg->i_offset); | |
4329 | ||
4330 | /* OK, we believe you. You're a core file (sure, sure). */ | |
4331 | ||
4332 | return abfd->xvec; | |
4333 | } | |
4334 | ||
4335 | static char * | |
4336 | ecoff_core_file_failing_command (abfd) | |
4337 | bfd *abfd; | |
4338 | { | |
4339 | return core_command (abfd); | |
4340 | } | |
4341 | ||
4342 | static int | |
4343 | ecoff_core_file_failing_signal (abfd) | |
4344 | bfd *abfd; | |
4345 | { | |
4346 | return core_signal (abfd); | |
4347 | } | |
4348 | ||
4349 | static boolean | |
4350 | ecoff_core_file_matches_executable_p (core_bfd, exec_bfd) | |
4351 | bfd *core_bfd, *exec_bfd; | |
4352 | { | |
4353 | return true; /* XXX - FIXME */ | |
4354 | } | |
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 | |
4361 | #endif | |
4362 | \f | |
f6409552 ILT |
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. */ | |
4366 | ||
515c4292 ILT |
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, | |
f6409552 | 4379 | ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook, |
515c4292 ILT |
4380 | ecoff_slurp_symbol_table |
4381 | }; | |
4382 | ||
515c4292 ILT |
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 | |
4385 | seem too likely. */ | |
8fa0d3a0 ILT |
4386 | #define ecoff_get_lineno \ |
4387 | ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr) | |
515c4292 | 4388 | |
f6409552 ILT |
4389 | /* These bfd_target functions are defined in other files. */ |
4390 | ||
515c4292 ILT |
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 | |
8fa0d3a0 | 4395 | #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound |
515c4292 | 4396 | #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup |
515c4292 | 4397 | #define ecoff_bfd_debug_info_start bfd_void |
8fa0d3a0 | 4398 | #define ecoff_bfd_debug_info_end bfd_void |
515c4292 | 4399 | #define ecoff_bfd_debug_info_accumulate \ |
8fa0d3a0 | 4400 | ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void) |
f6409552 ILT |
4401 | #define ecoff_bfd_get_relocated_section_contents \ |
4402 | bfd_generic_get_relocated_section_contents | |
515c4292 | 4403 | #define ecoff_bfd_relax_section bfd_generic_relax_section |
f68d8549 ILT |
4404 | #define ecoff_bfd_make_debug_symbol \ |
4405 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
c9301d7b | 4406 | |
1327fb29 | 4407 | bfd_target ecoff_little_vec = |
294eaca4 SC |
4408 | { |
4409 | "ecoff-littlemips", /* name */ | |
515c4292 | 4410 | bfd_target_ecoff_flavour, |
294eaca4 SC |
4411 | false, /* data byte order is little */ |
4412 | false, /* header byte order is little */ | |
4413 | ||
4414 | (HAS_RELOC | EXEC_P | /* object flags */ | |
4415 | HAS_LINENO | HAS_DEBUG | | |
de17306e | 4416 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), |
294eaca4 SC |
4417 | |
4418 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect | |
4419 | flags */ | |
4420 | 0, /* leading underscore */ | |
de17306e | 4421 | ' ', /* ar_pad_char */ |
294eaca4 | 4422 | 15, /* ar_max_namelen */ |
de17306e | 4423 | 4, /* minimum alignment power */ |
14e3c2e4 JK |
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 */ | |
294eaca4 | 4430 | |
515c4292 | 4431 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
c3fe0c41 ILT |
4432 | ecoff_archive_p, _bfd_dummy_target}, |
4433 | {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
4434 | bfd_false}, | |
4435 | {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */ | |
4436 | _bfd_write_archive_contents, bfd_false}, | |
515c4292 | 4437 | JUMP_TABLE (ecoff), |
515c4292 ILT |
4438 | (PTR) &bfd_ecoff_std_swap_table |
4439 | }; | |
1327fb29 SC |
4440 | |
4441 | bfd_target ecoff_big_vec = | |
294eaca4 SC |
4442 | { |
4443 | "ecoff-bigmips", /* name */ | |
515c4292 | 4444 | bfd_target_ecoff_flavour, |
294eaca4 SC |
4445 | true, /* data byte order is big */ |
4446 | true, /* header byte order is big */ | |
4447 | ||
4448 | (HAS_RELOC | EXEC_P | /* object flags */ | |
4449 | HAS_LINENO | HAS_DEBUG | | |
de17306e | 4450 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), |
294eaca4 SC |
4451 | |
4452 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */ | |
4453 | 0, /* leading underscore */ | |
4454 | ' ', /* ar_pad_char */ | |
de17306e ILT |
4455 | 15, /* ar_max_namelen */ |
4456 | 4, /* minimum alignment power */ | |
14e3c2e4 JK |
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, | |
294eaca4 | 4463 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
de17306e | 4464 | ecoff_archive_p, ecoff_core_file_p}, |
c3fe0c41 ILT |
4465 | {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ |
4466 | bfd_false}, | |
515c4292 | 4467 | {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */ |
c3fe0c41 | 4468 | _bfd_write_archive_contents, bfd_false}, |
515c4292 | 4469 | JUMP_TABLE(ecoff), |
515c4292 ILT |
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 | |
4473 | as well. */ | |
4474 | }; |