* mips-tdep.c (mips_frame_chain): If frame size zero, return zero.
[deliverable/binutils-gdb.git] / bfd / ecoff.c
CommitLineData
dae31cf5
ILT
1/* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25#include "seclet.h"
26#include "aout/ar.h"
27#include "aout/ranlib.h"
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 N_ABS
35#undef exec_hdr
36#undef obj_sym_filepos
37
38#include "coff/internal.h"
39#include "coff/sym.h"
40#include "coff/symconst.h"
41#include "coff/ecoff.h"
42#include "libcoff.h"
43#include "libecoff.h"
44\f
45/* Prototypes for static functions. */
46
47static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
48 asymbol *asym, int ext,
49 asymbol **indirect_ptr_ptr));
50static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
51 RNDXR *rndx, long isym,
52 CONST char *which));
53static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
54 unsigned int indx, int bigendian));
dae31cf5
ILT
55static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
56 asymbol **symbols));
57static void ecoff_clear_output_flags PARAMS ((bfd *abfd));
58static boolean ecoff_rel PARAMS ((bfd *output_bfd, bfd_seclet_type *seclet,
59 asection *output_section, PTR data,
60 boolean relocateable));
61static boolean ecoff_dump_seclet PARAMS ((bfd *abfd, bfd_seclet_type *seclet,
62 asection *section, PTR data,
63 boolean relocateable));
64static long ecoff_add_string PARAMS ((bfd *output_bfd, FDR *fdr,
65 CONST char *string, boolean external));
66static boolean ecoff_get_debug PARAMS ((bfd *output_bfd,
67 bfd_seclet_type *seclet,
68 asection *section,
69 boolean relocateable));
70static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
71static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
72 unsigned int *rehash,
73 unsigned int size,
74 unsigned int hlog));
75\f
dae31cf5
ILT
76/* This stuff is somewhat copied from coffcode.h. */
77
78static asection bfd_debug_section = { "*DEBUG*" };
79
48edba81
ILT
80/* Create an ECOFF object. */
81
82boolean
83ecoff_mkobject (abfd)
84 bfd *abfd;
85{
86 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
87 bfd_zalloc (abfd, sizeof (ecoff_data_type)));
88 if (abfd->tdata.ecoff_obj_data == NULL)
89 {
90 bfd_error = no_memory;
91 return false;
92 }
93
94 /* Always create a .scommon section for every BFD. This is a hack so
95 that the linker has something to attach scSCommon symbols to. */
96 bfd_make_section (abfd, SCOMMON);
97
98 return true;
99}
100
dae31cf5
ILT
101/* This is a hook needed by SCO COFF, but we have nothing to do. */
102
103asection *
104ecoff_make_section_hook (abfd, name)
105 bfd *abfd;
106 char *name;
107{
108 return (asection *) NULL;
109}
110
111/* Initialize a new section. */
112
113boolean
114ecoff_new_section_hook (abfd, section)
115 bfd *abfd;
116 asection *section;
117{
118 section->alignment_power = abfd->xvec->align_power_min;
119
120 if (strcmp (section->name, _TEXT) == 0)
121 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
122 else if (strcmp (section->name, _DATA) == 0
123 || strcmp (section->name, _SDATA) == 0)
124 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
125 else if (strcmp (section->name, _RDATA) == 0
126 || strcmp (section->name, _LIT8) == 0
127 || strcmp (section->name, _LIT4) == 0)
128 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
129 else if (strcmp (section->name, _BSS) == 0
130 || strcmp (section->name, _SBSS) == 0)
131 section->flags |= SEC_ALLOC;
132
133 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
134 uncertain about .init on some systems and I don't know how shared
135 libraries work. */
136
137 return true;
138}
139
140/* Determine the machine architecture and type. */
141
142boolean
143ecoff_set_arch_mach_hook (abfd, filehdr)
144 bfd *abfd;
145 PTR filehdr;
146{
147 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
148 enum bfd_architecture arch;
149
150 switch (internal_f->f_magic)
151 {
152 case MIPS_MAGIC_1:
153 case MIPS_MAGIC_LITTLE:
154 case MIPS_MAGIC_BIG:
155 arch = bfd_arch_mips;
156 break;
157
158 case ALPHA_MAGIC:
159 arch = bfd_arch_alpha;
160 break;
161
162 default:
163 arch = bfd_arch_obscure;
164 break;
165 }
166
167 bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
168
169 return true;
170}
171
172/* Get the section s_flags to use for a section. */
173
174long
175ecoff_sec_to_styp_flags (name, flags)
176 CONST char *name;
177 flagword flags;
178{
179 long styp;
180
181 styp = 0;
182
183 if (strcmp (name, _TEXT) == 0)
184 styp = STYP_TEXT;
185 else if (strcmp (name, _DATA) == 0)
186 styp = STYP_DATA;
187 else if (strcmp (name, _SDATA) == 0)
188 styp = STYP_SDATA;
189 else if (strcmp (name, _RDATA) == 0)
190 styp = STYP_RDATA;
191 else if (strcmp (name, _LIT8) == 0)
192 styp = STYP_LIT8;
193 else if (strcmp (name, _LIT4) == 0)
194 styp = STYP_LIT4;
195 else if (strcmp (name, _BSS) == 0)
196 styp = STYP_BSS;
197 else if (strcmp (name, _SBSS) == 0)
198 styp = STYP_SBSS;
199 else if (strcmp (name, _INIT) == 0)
200 styp = STYP_ECOFF_INIT;
201 else if (flags & SEC_CODE)
202 styp = STYP_TEXT;
203 else if (flags & SEC_DATA)
204 styp = STYP_DATA;
205 else if (flags & SEC_READONLY)
206 styp = STYP_RDATA;
207 else if (flags & SEC_LOAD)
208 styp = STYP_REG;
209 else
210 styp = STYP_BSS;
211
212 if (flags & SEC_NEVER_LOAD)
213 styp |= STYP_NOLOAD;
214
215 return styp;
216}
217
218/* Get the BFD flags to use for a section. */
219
220flagword
221ecoff_styp_to_sec_flags (abfd, hdr)
222 bfd *abfd;
223 PTR hdr;
224{
225 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
226 long styp_flags = internal_s->s_flags;
227 flagword sec_flags=0;
228
229 if (styp_flags & STYP_NOLOAD)
230 sec_flags |= SEC_NEVER_LOAD;
231
232 /* For 386 COFF, at least, an unloadable text or data section is
233 actually a shared library section. */
234 if ((styp_flags & STYP_TEXT)
235 || (styp_flags & STYP_ECOFF_INIT))
236 {
237 if (sec_flags & SEC_NEVER_LOAD)
238 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
239 else
240 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
241 }
242 else if ((styp_flags & STYP_DATA)
243 || (styp_flags & STYP_RDATA)
244 || (styp_flags & STYP_SDATA))
245 {
246 if (sec_flags & SEC_NEVER_LOAD)
247 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
248 else
249 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
250 if (styp_flags & STYP_RDATA)
251 sec_flags |= SEC_READONLY;
252 }
253 else if ((styp_flags & STYP_BSS)
254 || (styp_flags & STYP_SBSS))
255 {
256 sec_flags |= SEC_ALLOC;
257 }
258 else if (styp_flags & STYP_INFO)
259 {
260 sec_flags |= SEC_NEVER_LOAD;
261 }
262 else if ((styp_flags & STYP_LIT8)
263 || (styp_flags & STYP_LIT4))
264 {
265 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
266 }
267 else
268 {
269 sec_flags |= SEC_ALLOC | SEC_LOAD;
270 }
271
272 return sec_flags;
273}
274\f
275/* Routines to swap auxiliary information in and out. I am assuming
276 that the auxiliary information format is always going to be target
277 independent. */
278
279/* Swap in a type information record.
280 BIGEND says whether AUX symbols are big-endian or little-endian; this
281 info comes from the file header record (fh-fBigendian). */
282
283void
284ecoff_swap_tir_in (bigend, ext_copy, intern)
285 int bigend;
286 struct tir_ext *ext_copy;
287 TIR *intern;
288{
289 struct tir_ext ext[1];
290
291 *ext = *ext_copy; /* Make it reasonable to do in-place. */
292
293 /* now the fun stuff... */
294 if (bigend) {
295 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
296 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
297 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
298 >> TIR_BITS1_BT_SH_BIG;
299 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
300 >> TIR_BITS_TQ4_SH_BIG;
301 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
302 >> TIR_BITS_TQ5_SH_BIG;
303 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
304 >> TIR_BITS_TQ0_SH_BIG;
305 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
306 >> TIR_BITS_TQ1_SH_BIG;
307 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
308 >> TIR_BITS_TQ2_SH_BIG;
309 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
310 >> TIR_BITS_TQ3_SH_BIG;
311 } else {
312 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
313 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
314 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
315 >> TIR_BITS1_BT_SH_LITTLE;
316 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
317 >> TIR_BITS_TQ4_SH_LITTLE;
318 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
319 >> TIR_BITS_TQ5_SH_LITTLE;
320 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
321 >> TIR_BITS_TQ0_SH_LITTLE;
322 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
323 >> TIR_BITS_TQ1_SH_LITTLE;
324 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
325 >> TIR_BITS_TQ2_SH_LITTLE;
326 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
327 >> TIR_BITS_TQ3_SH_LITTLE;
328 }
329
330#ifdef TEST
331 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
332 abort();
333#endif
334}
335
336/* Swap out a type information record.
337 BIGEND says whether AUX symbols are big-endian or little-endian; this
338 info comes from the file header record (fh-fBigendian). */
339
340void
341ecoff_swap_tir_out (bigend, intern_copy, ext)
342 int bigend;
343 TIR *intern_copy;
344 struct tir_ext *ext;
345{
346 TIR intern[1];
347
348 *intern = *intern_copy; /* Make it reasonable to do in-place. */
349
350 /* now the fun stuff... */
351 if (bigend) {
352 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
353 | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
354 | ((intern->bt << TIR_BITS1_BT_SH_BIG)
355 & TIR_BITS1_BT_BIG));
356 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_BIG)
357 & TIR_BITS_TQ4_BIG)
358 | ((intern->tq5 << TIR_BITS_TQ5_SH_BIG)
359 & TIR_BITS_TQ5_BIG));
360 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_BIG)
361 & TIR_BITS_TQ0_BIG)
362 | ((intern->tq1 << TIR_BITS_TQ1_SH_BIG)
363 & TIR_BITS_TQ1_BIG));
364 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_BIG)
365 & TIR_BITS_TQ2_BIG)
366 | ((intern->tq3 << TIR_BITS_TQ3_SH_BIG)
367 & TIR_BITS_TQ3_BIG));
368 } else {
369 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_LITTLE : 0)
370 | (intern->continued ? TIR_BITS1_CONTINUED_LITTLE : 0)
371 | ((intern->bt << TIR_BITS1_BT_SH_LITTLE)
372 & TIR_BITS1_BT_LITTLE));
373 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_LITTLE)
374 & TIR_BITS_TQ4_LITTLE)
375 | ((intern->tq5 << TIR_BITS_TQ5_SH_LITTLE)
376 & TIR_BITS_TQ5_LITTLE));
377 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_LITTLE)
378 & TIR_BITS_TQ0_LITTLE)
379 | ((intern->tq1 << TIR_BITS_TQ1_SH_LITTLE)
380 & TIR_BITS_TQ1_LITTLE));
381 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_LITTLE)
382 & TIR_BITS_TQ2_LITTLE)
383 | ((intern->tq3 << TIR_BITS_TQ3_SH_LITTLE)
384 & TIR_BITS_TQ3_LITTLE));
385 }
386
387#ifdef TEST
388 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
389 abort();
390#endif
391}
392
393/* Swap in a relative symbol record. BIGEND says whether it is in
394 big-endian or little-endian format.*/
395
396void
397ecoff_swap_rndx_in (bigend, ext_copy, intern)
398 int bigend;
399 struct rndx_ext *ext_copy;
400 RNDXR *intern;
401{
402 struct rndx_ext ext[1];
403
404 *ext = *ext_copy; /* Make it reasonable to do in-place. */
405
406 /* now the fun stuff... */
407 if (bigend) {
408 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
409 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
410 >> RNDX_BITS1_RFD_SH_BIG);
411 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
412 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
413 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
414 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
415 } else {
416 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
417 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
418 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
419 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
420 >> RNDX_BITS1_INDEX_SH_LITTLE)
421 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
422 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
423 }
424
425#ifdef TEST
426 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
427 abort();
428#endif
429}
430
431/* Swap out a relative symbol record. BIGEND says whether it is in
432 big-endian or little-endian format.*/
433
434void
435ecoff_swap_rndx_out (bigend, intern_copy, ext)
436 int bigend;
437 RNDXR *intern_copy;
438 struct rndx_ext *ext;
439{
440 RNDXR intern[1];
441
442 *intern = *intern_copy; /* Make it reasonable to do in-place. */
443
444 /* now the fun stuff... */
445 if (bigend) {
446 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
447 ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
448 & RNDX_BITS1_RFD_BIG)
449 | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
450 & RNDX_BITS1_INDEX_BIG));
451 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
452 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
453 } else {
454 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
455 ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
456 & RNDX_BITS1_RFD_LITTLE)
457 | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
458 & RNDX_BITS1_INDEX_LITTLE));
459 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
460 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
461 }
462
463#ifdef TEST
464 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
465 abort();
466#endif
467}
468\f
469/* Read in and swap the important symbolic information for an ECOFF
470 object file. This is called by gdb. */
471
472boolean
473ecoff_slurp_symbolic_info (abfd)
474 bfd *abfd;
475{
476 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
477 bfd_size_type external_hdr_size;
478 HDRR *internal_symhdr;
479 bfd_size_type raw_base;
480 bfd_size_type raw_size;
481 PTR raw;
482 bfd_size_type external_fdr_size;
483 char *fraw_src;
484 char *fraw_end;
485 struct fdr *fdr_ptr;
486
487 /* Check whether we've already gotten it, and whether there's any to
488 get. */
489 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
490 return true;
491 if (ecoff_data (abfd)->sym_filepos == 0)
492 {
493 bfd_get_symcount (abfd) = 0;
494 return true;
495 }
496
497 /* At this point bfd_get_symcount (abfd) holds the number of symbols
498 as read from the file header, but on ECOFF this is always the
499 size of the symbolic information header. It would be cleaner to
500 handle this when we first read the file in coffgen.c. */
501 external_hdr_size = backend->external_hdr_size;
502 if (bfd_get_symcount (abfd) != external_hdr_size)
503 {
504 bfd_error = bad_value;
505 return false;
506 }
507
508 /* Read the symbolic information header. */
509 raw = (PTR) alloca (external_hdr_size);
510 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
511 || (bfd_read (raw, external_hdr_size, 1, abfd)
512 != external_hdr_size))
513 {
514 bfd_error = system_call_error;
515 return false;
516 }
517 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
518 (*backend->swap_hdr_in) (abfd, raw, internal_symhdr);
519
48edba81 520 if (internal_symhdr->magic != backend->sym_magic)
dae31cf5
ILT
521 {
522 bfd_error = bad_value;
523 return false;
524 }
525
526 /* Now we can get the correct number of symbols. */
527 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
528 + internal_symhdr->iextMax);
529
530 /* Read all the symbolic information at once. */
531 raw_base = ecoff_data (abfd)->sym_filepos + external_hdr_size;
532
533 if (internal_symhdr->cbExtOffset != 0)
534 raw_size = (internal_symhdr->cbExtOffset
535 - raw_base
536 + internal_symhdr->iextMax * backend->external_ext_size);
537 else
538 {
539 long cbline, issmax, issextmax;
540
541 cbline = (internal_symhdr->cbLine + 3) &~ 3;
542 issmax = (internal_symhdr->issMax + 3) &~ 3;
543 issextmax = (internal_symhdr->issExtMax + 3) &~ 3;
544 raw_size = (cbline * sizeof (unsigned char)
545 + internal_symhdr->idnMax * backend->external_dnr_size
546 + internal_symhdr->ipdMax * backend->external_pdr_size
547 + internal_symhdr->isymMax * backend->external_sym_size
548 + internal_symhdr->ioptMax * backend->external_opt_size
549 + internal_symhdr->iauxMax * sizeof (union aux_ext)
550 + issmax * sizeof (char)
551 + issextmax * sizeof (char)
552 + internal_symhdr->ifdMax * backend->external_fdr_size
553 + internal_symhdr->crfd * backend->external_rfd_size
554 + internal_symhdr->iextMax * backend->external_ext_size);
555 }
556
557 if (raw_size == 0)
558 {
559 ecoff_data (abfd)->sym_filepos = 0;
560 return true;
561 }
562 raw = (PTR) bfd_alloc (abfd, raw_size);
563 if (raw == NULL)
564 {
565 bfd_error = no_memory;
566 return false;
567 }
568 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
569 {
570 bfd_error = system_call_error;
571 bfd_release (abfd, raw);
572 return false;
573 }
574
575 ecoff_data (abfd)->raw_size = raw_size;
576 ecoff_data (abfd)->raw_syments = raw;
577
578 /* Get pointers for the numeric offsets in the HDRR structure. */
579#define FIX(off1, off2, type) \
580 if (internal_symhdr->off1 == 0) \
581 ecoff_data (abfd)->off2 = (type) NULL; \
582 else \
583 ecoff_data (abfd)->off2 = (type) ((char *) raw \
584 + internal_symhdr->off1 \
585 - raw_base)
586 FIX (cbLineOffset, line, unsigned char *);
587 FIX (cbDnOffset, external_dnr, PTR);
588 FIX (cbPdOffset, external_pdr, PTR);
589 FIX (cbSymOffset, external_sym, PTR);
590 FIX (cbOptOffset, external_opt, PTR);
591 FIX (cbAuxOffset, external_aux, union aux_ext *);
592 FIX (cbSsOffset, ss, char *);
593 FIX (cbSsExtOffset, ssext, char *);
594 FIX (cbFdOffset, external_fdr, PTR);
595 FIX (cbRfdOffset, external_rfd, PTR);
596 FIX (cbExtOffset, external_ext, PTR);
597#undef FIX
598
599 /* I don't want to always swap all the data, because it will just
600 waste time and most programs will never look at it. The only
601 time the linker needs most of the debugging information swapped
602 is when linking big-endian and little-endian MIPS object files
603 together, which is not a common occurrence.
604
605 We need to look at the fdr to deal with a lot of information in
606 the symbols, so we swap them here. */
607 ecoff_data (abfd)->fdr =
608 (struct fdr *) bfd_alloc (abfd,
609 (internal_symhdr->ifdMax *
610 sizeof (struct fdr)));
611 if (ecoff_data (abfd)->fdr == NULL)
612 {
613 bfd_error = no_memory;
614 return false;
615 }
616 external_fdr_size = backend->external_fdr_size;
617 fdr_ptr = ecoff_data (abfd)->fdr;
618 fraw_src = (char *) ecoff_data (abfd)->external_fdr;
619 fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
620 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
621 (*backend->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
622
623 return true;
624}
625\f
626/* ECOFF symbol table routines. The ECOFF symbol table is described
627 in gcc/mips-tfile.c. */
628
629/* ECOFF uses two common sections. One is the usual one, and the
630 other is for small objects. All the small objects are kept
631 together, and then referenced via the gp pointer, which yields
632 faster assembler code. This is what we use for the small common
633 section. */
634static asection ecoff_scom_section;
635static asymbol ecoff_scom_symbol;
636static asymbol *ecoff_scom_symbol_ptr;
637
638/* Create an empty symbol. */
639
640asymbol *
641ecoff_make_empty_symbol (abfd)
642 bfd *abfd;
643{
644 ecoff_symbol_type *new;
645
646 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
647 if (new == (ecoff_symbol_type *) NULL)
648 {
649 bfd_error = no_memory;
650 return (asymbol *) NULL;
651 }
652 memset (new, 0, sizeof *new);
653 new->symbol.section = (asection *) NULL;
654 new->fdr = (FDR *) NULL;
655 new->local = false;
656 new->native = NULL;
657 new->symbol.the_bfd = abfd;
658 return &new->symbol;
659}
660
661/* Set the BFD flags and section for an ECOFF symbol. */
662
663static void
664ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
665 bfd *abfd;
666 SYMR *ecoff_sym;
667 asymbol *asym;
668 int ext;
669 asymbol **indirect_ptr_ptr;
670{
671 asym->the_bfd = abfd;
672 asym->value = ecoff_sym->value;
673 asym->section = &bfd_debug_section;
674 asym->udata = NULL;
675
676 /* An indirect symbol requires two consecutive stabs symbols. */
677 if (*indirect_ptr_ptr != (asymbol *) NULL)
678 {
679 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym));
680
681 /* @@ Stuffing pointers into integers is a no-no.
682 We can usually get away with it if the integer is
683 large enough though. */
684 if (sizeof (asym) > sizeof (bfd_vma))
685 abort ();
686 (*indirect_ptr_ptr)->value = (bfd_vma) asym;
687
688 asym->flags = BSF_DEBUGGING;
689 asym->section = &bfd_und_section;
690 *indirect_ptr_ptr = NULL;
691 return;
692 }
693
694 if (ECOFF_IS_STAB (ecoff_sym)
695 && (ECOFF_UNMARK_STAB (ecoff_sym->index) | N_EXT) == (N_INDR | N_EXT))
696 {
697 asym->flags = BSF_DEBUGGING | BSF_INDIRECT;
698 asym->section = &bfd_ind_section;
699 /* Pass this symbol on to the next call to this function. */
700 *indirect_ptr_ptr = asym;
701 return;
702 }
703
704 /* Most symbol types are just for debugging. */
705 switch (ecoff_sym->st)
706 {
707 case stGlobal:
708 case stStatic:
709 case stLabel:
710 case stProc:
711 case stStaticProc:
712 break;
713 case stNil:
714 if (ECOFF_IS_STAB (ecoff_sym))
715 {
716 asym->flags = BSF_DEBUGGING;
717 return;
718 }
719 break;
720 default:
721 asym->flags = BSF_DEBUGGING;
722 return;
723 }
724
725 if (ext)
726 asym->flags = BSF_EXPORT | BSF_GLOBAL;
727 else
728 asym->flags = BSF_LOCAL;
729 switch (ecoff_sym->sc)
730 {
731 case scNil:
732 /* Used for compiler generated labels. Leave them in the
733 debugging section, and mark them as local. If BSF_DEBUGGING
734 is set, then nm does not display them for some reason. If no
735 flags are set then the linker whines about them. */
736 asym->flags = BSF_LOCAL;
737 break;
738 case scText:
739 asym->section = bfd_make_section_old_way (abfd, ".text");
740 asym->value -= asym->section->vma;
741 break;
742 case scData:
743 asym->section = bfd_make_section_old_way (abfd, ".data");
744 asym->value -= asym->section->vma;
745 break;
746 case scBss:
70bec8b8
ILT
747 asym->section = bfd_make_section_old_way (abfd, ".bss");
748 asym->value -= asym->section->vma;
dae31cf5
ILT
749 break;
750 case scRegister:
751 asym->flags = BSF_DEBUGGING;
752 break;
753 case scAbs:
754 asym->section = &bfd_abs_section;
755 break;
756 case scUndefined:
757 asym->section = &bfd_und_section;
758 asym->flags = 0;
759 asym->value = 0;
760 break;
761 case scCdbLocal:
762 case scBits:
763 case scCdbSystem:
764 case scRegImage:
765 case scInfo:
766 case scUserStruct:
767 asym->flags = BSF_DEBUGGING;
768 break;
769 case scSData:
770 asym->section = bfd_make_section_old_way (abfd, ".sdata");
771 asym->value -= asym->section->vma;
772 break;
773 case scSBss:
774 asym->section = bfd_make_section_old_way (abfd, ".sbss");
70bec8b8 775 asym->value -= asym->section->vma;
dae31cf5
ILT
776 break;
777 case scRData:
778 asym->section = bfd_make_section_old_way (abfd, ".rdata");
779 asym->value -= asym->section->vma;
780 break;
781 case scVar:
782 asym->flags = BSF_DEBUGGING;
783 break;
784 case scCommon:
785 if (asym->value > ecoff_data (abfd)->gp_size)
786 {
787 asym->section = &bfd_com_section;
788 asym->flags = 0;
789 break;
790 }
791 /* Fall through. */
792 case scSCommon:
793 if (ecoff_scom_section.name == NULL)
794 {
795 /* Initialize the small common section. */
796 ecoff_scom_section.name = SCOMMON;
797 ecoff_scom_section.flags = SEC_IS_COMMON;
798 ecoff_scom_section.output_section = &ecoff_scom_section;
799 ecoff_scom_section.symbol = &ecoff_scom_symbol;
800 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
801 ecoff_scom_symbol.name = SCOMMON;
802 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
803 ecoff_scom_symbol.section = &ecoff_scom_section;
804 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
805 }
806 asym->section = &ecoff_scom_section;
807 asym->flags = 0;
808 break;
809 case scVarRegister:
810 case scVariant:
811 asym->flags = BSF_DEBUGGING;
812 break;
813 case scSUndefined:
814 asym->section = &bfd_und_section;
815 asym->flags = 0;
816 asym->value = 0;
817 break;
818 case scInit:
819 asym->section = bfd_make_section_old_way (abfd, ".init");
820 asym->value -= asym->section->vma;
821 break;
822 case scBasedVar:
823 case scXData:
824 case scPData:
825 asym->flags = BSF_DEBUGGING;
826 break;
827 case scFini:
828 asym->section = bfd_make_section_old_way (abfd, ".fini");
829 asym->value -= asym->section->vma;
830 break;
831 default:
832 break;
833 }
834
835 /* Look for special constructors symbols and make relocation entries
836 in a special construction section. These are produced by the
837 -fgnu-linker argument to g++. */
838 if (ECOFF_IS_STAB (ecoff_sym))
839 {
840 switch (ECOFF_UNMARK_STAB (ecoff_sym->index))
841 {
842 default:
843 break;
844
845 case N_SETA:
846 case N_SETT:
847 case N_SETD:
848 case N_SETB:
849 {
850 const char *name;
851 asection *section;
852 arelent_chain *reloc_chain;
853 unsigned int bitsize;
dae31cf5
ILT
854
855 /* Get a section with the same name as the symbol (usually
856 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
857 name ___CTOR_LIST (three underscores). We need
858 __CTOR_LIST (two underscores), since ECOFF doesn't use
859 a leading underscore. This should be handled by gcc,
860 but instead we do it here. Actually, this should all
861 be done differently anyhow. */
862 name = bfd_asymbol_name (asym);
863 if (name[0] == '_' && name[1] == '_' && name[2] == '_')
864 {
865 ++name;
866 asym->name = name;
867 }
868 section = bfd_get_section_by_name (abfd, name);
869 if (section == (asection *) NULL)
870 {
871 char *copy;
872
873 copy = (char *) bfd_alloc (abfd, strlen (name) + 1);
874 strcpy (copy, name);
875 section = bfd_make_section (abfd, copy);
876 }
877
878 /* Build a reloc pointing to this constructor. */
879 reloc_chain =
880 (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
881 reloc_chain->relent.sym_ptr_ptr =
882 bfd_get_section (asym)->symbol_ptr_ptr;
883 reloc_chain->relent.address = section->_raw_size;
884 reloc_chain->relent.addend = asym->value;
8f46bac8
ILT
885 reloc_chain->relent.howto =
886 ecoff_backend (abfd)->constructor_reloc;
dae31cf5
ILT
887
888 /* Set up the constructor section to hold the reloc. */
889 section->flags = SEC_CONSTRUCTOR;
890 ++section->reloc_count;
891
892 /* Constructor sections must be rounded to a boundary
893 based on the bitsize. These are not real sections--
894 they are handled specially by the linker--so the ECOFF
895 16 byte alignment restriction does not apply. */
8f46bac8 896 bitsize = ecoff_backend (abfd)->constructor_bitsize;
dae31cf5
ILT
897 section->alignment_power = 1;
898 while ((1 << section->alignment_power) < bitsize / 8)
899 ++section->alignment_power;
900
901 reloc_chain->next = section->constructor_chain;
902 section->constructor_chain = reloc_chain;
903 section->_raw_size += bitsize / 8;
904
905 /* Mark the symbol as a constructor. */
906 asym->flags |= BSF_CONSTRUCTOR;
907 }
908 break;
909 }
910 }
911}
912
913/* Read an ECOFF symbol table. */
914
915boolean
916ecoff_slurp_symbol_table (abfd)
917 bfd *abfd;
918{
919 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
920 const bfd_size_type external_ext_size = backend->external_ext_size;
921 const bfd_size_type external_sym_size = backend->external_sym_size;
922 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
923 = backend->swap_ext_in;
924 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
925 = backend->swap_sym_in;
926 bfd_size_type internal_size;
927 ecoff_symbol_type *internal;
928 ecoff_symbol_type *internal_ptr;
929 asymbol *indirect_ptr;
930 char *eraw_src;
931 char *eraw_end;
932 FDR *fdr_ptr;
933 FDR *fdr_end;
934
935 /* If we've already read in the symbol table, do nothing. */
936 if (ecoff_data (abfd)->canonical_symbols != NULL)
937 return true;
938
939 /* Get the symbolic information. */
940 if (ecoff_slurp_symbolic_info (abfd) == false)
941 return false;
942 if (bfd_get_symcount (abfd) == 0)
943 return true;
944
945 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
946 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
947 if (internal == NULL)
948 {
949 bfd_error = no_memory;
950 return false;
951 }
952
953 internal_ptr = internal;
954 indirect_ptr = NULL;
955 eraw_src = (char *) ecoff_data (abfd)->external_ext;
956 eraw_end = (eraw_src
957 + (ecoff_data (abfd)->symbolic_header.iextMax
958 * external_ext_size));
959 for (; eraw_src < eraw_end; eraw_src += external_ext_size, internal_ptr++)
960 {
961 EXTR internal_esym;
962
963 (*swap_ext_in) (abfd, (PTR) eraw_src, &internal_esym);
964 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
965 + internal_esym.asym.iss);
966 ecoff_set_symbol_info (abfd, &internal_esym.asym,
967 &internal_ptr->symbol, 1, &indirect_ptr);
48edba81
ILT
968 /* The alpha uses a negative ifd field for section symbols. */
969 if (internal_esym.ifd >= 0)
970 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
971 else
972 internal_ptr->fdr = NULL;
dae31cf5
ILT
973 internal_ptr->local = false;
974 internal_ptr->native = (PTR) eraw_src;
975 }
976 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
977
978 /* The local symbols must be accessed via the fdr's, because the
979 string and aux indices are relative to the fdr information. */
980 fdr_ptr = ecoff_data (abfd)->fdr;
981 fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax;
982 for (; fdr_ptr < fdr_end; fdr_ptr++)
983 {
984 char *lraw_src;
985 char *lraw_end;
986
987 lraw_src = ((char *) ecoff_data (abfd)->external_sym
988 + fdr_ptr->isymBase * external_sym_size);
989 lraw_end = lraw_src + fdr_ptr->csym * external_sym_size;
990 for (;
991 lraw_src < lraw_end;
992 lraw_src += external_sym_size, internal_ptr++)
993 {
994 SYMR internal_sym;
995
996 (*swap_sym_in) (abfd, (PTR) lraw_src, &internal_sym);
997 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
998 + fdr_ptr->issBase
999 + internal_sym.iss);
1000 ecoff_set_symbol_info (abfd, &internal_sym,
1001 &internal_ptr->symbol, 0, &indirect_ptr);
1002 internal_ptr->fdr = fdr_ptr;
1003 internal_ptr->local = true;
1004 internal_ptr->native = (PTR) lraw_src;
1005 }
1006 }
1007 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
1008
1009 ecoff_data (abfd)->canonical_symbols = internal;
1010
1011 return true;
1012}
1013
1014/* Return the amount of space needed for the canonical symbols. */
1015
1016unsigned int
1017ecoff_get_symtab_upper_bound (abfd)
1018 bfd *abfd;
1019{
1020 if (ecoff_slurp_symbolic_info (abfd) == false
1021 || bfd_get_symcount (abfd) == 0)
1022 return 0;
1023
1024 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
1025}
1026
1027/* Get the canonicals symbols. */
1028
1029unsigned int
1030ecoff_get_symtab (abfd, alocation)
1031 bfd *abfd;
1032 asymbol **alocation;
1033{
1034 unsigned int counter = 0;
1035 ecoff_symbol_type *symbase;
1036 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
1037
1038 if (ecoff_slurp_symbol_table (abfd) == false
1039 || bfd_get_symcount (abfd) == 0)
1040 return 0;
1041
1042 symbase = ecoff_data (abfd)->canonical_symbols;
1043 while (counter < bfd_get_symcount (abfd))
1044 {
1045 *(location++) = symbase++;
1046 counter++;
1047 }
1048 *location++ = (ecoff_symbol_type *) NULL;
1049 return bfd_get_symcount (abfd);
1050}
1051
1052/* Turn ECOFF type information into a printable string.
1053 ecoff_emit_aggregate and ecoff_type_to_string are from
1054 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1055
1056/* Write aggregate information to a string. */
1057
1058static void
1059ecoff_emit_aggregate (abfd, string, rndx, isym, which)
1060 bfd *abfd;
1061 char *string;
1062 RNDXR *rndx;
1063 long isym;
1064 CONST char *which;
1065{
1066 int ifd = rndx->rfd;
1067 int indx = rndx->index;
1068 int sym_base, ss_base;
1069 CONST char *name;
1070
1071 if (ifd == 0xfff)
1072 ifd = isym;
1073
1074 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
1075 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
1076
1077 if (indx == indexNil)
1078 name = "/* no name */";
1079 else
1080 {
1081 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1082 SYMR sym;
1083
1084 indx += sym_base;
1085 (*backend->swap_sym_in) (abfd,
1086 ((char *) ecoff_data (abfd)->external_sym
1087 + indx * backend->external_sym_size),
1088 &sym);
1089 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
1090 }
1091
1092 sprintf (string,
1093 "%s %s { ifd = %d, index = %d }",
1094 which, name, ifd,
1095 indx + ecoff_data (abfd)->symbolic_header.iextMax);
1096}
1097
1098/* Convert the type information to string format. */
1099
1100static char *
1101ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
1102 bfd *abfd;
1103 union aux_ext *aux_ptr;
1104 unsigned int indx;
1105 int bigendian;
1106{
1107 AUXU u;
1108 struct qual {
1109 unsigned int type;
1110 int low_bound;
1111 int high_bound;
1112 int stride;
1113 } qualifiers[7];
1114
1115 unsigned int basic_type;
1116 int i;
1117 static char buffer1[1024];
1118 static char buffer2[1024];
1119 char *p1 = buffer1;
1120 char *p2 = buffer2;
1121 RNDXR rndx;
1122
1123 for (i = 0; i < 7; i++)
1124 {
1125 qualifiers[i].low_bound = 0;
1126 qualifiers[i].high_bound = 0;
1127 qualifiers[i].stride = 0;
1128 }
1129
1130 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
1131 return "-1 (no type)";
1132 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
1133
1134 basic_type = u.ti.bt;
1135 qualifiers[0].type = u.ti.tq0;
1136 qualifiers[1].type = u.ti.tq1;
1137 qualifiers[2].type = u.ti.tq2;
1138 qualifiers[3].type = u.ti.tq3;
1139 qualifiers[4].type = u.ti.tq4;
1140 qualifiers[5].type = u.ti.tq5;
1141 qualifiers[6].type = tqNil;
1142
1143 /*
1144 * Go get the basic type.
1145 */
1146 switch (basic_type)
1147 {
1148 case btNil: /* undefined */
1149 strcpy (p1, "nil");
1150 break;
1151
1152 case btAdr: /* address - integer same size as pointer */
1153 strcpy (p1, "address");
1154 break;
1155
1156 case btChar: /* character */
1157 strcpy (p1, "char");
1158 break;
1159
1160 case btUChar: /* unsigned character */
1161 strcpy (p1, "unsigned char");
1162 break;
1163
1164 case btShort: /* short */
1165 strcpy (p1, "short");
1166 break;
1167
1168 case btUShort: /* unsigned short */
1169 strcpy (p1, "unsigned short");
1170 break;
1171
1172 case btInt: /* int */
1173 strcpy (p1, "int");
1174 break;
1175
1176 case btUInt: /* unsigned int */
1177 strcpy (p1, "unsigned int");
1178 break;
1179
1180 case btLong: /* long */
1181 strcpy (p1, "long");
1182 break;
1183
1184 case btULong: /* unsigned long */
1185 strcpy (p1, "unsigned long");
1186 break;
1187
1188 case btFloat: /* float (real) */
1189 strcpy (p1, "float");
1190 break;
1191
1192 case btDouble: /* Double (real) */
1193 strcpy (p1, "double");
1194 break;
1195
1196 /* Structures add 1-2 aux words:
1197 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1198 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1199
1200 case btStruct: /* Structure (Record) */
1201 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1202 ecoff_emit_aggregate (abfd, p1, &rndx,
1203 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1204 "struct");
1205 indx++; /* skip aux words */
1206 break;
1207
1208 /* Unions add 1-2 aux words:
1209 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1210 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1211
1212 case btUnion: /* Union */
1213 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1214 ecoff_emit_aggregate (abfd, p1, &rndx,
1215 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1216 "union");
1217 indx++; /* skip aux words */
1218 break;
1219
1220 /* Enumerations add 1-2 aux words:
1221 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1222 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1223
1224 case btEnum: /* Enumeration */
1225 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1226 ecoff_emit_aggregate (abfd, p1, &rndx,
1227 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1228 "enum");
1229 indx++; /* skip aux words */
1230 break;
1231
1232 case btTypedef: /* defined via a typedef, isymRef points */
1233 strcpy (p1, "typedef");
1234 break;
1235
1236 case btRange: /* subrange of int */
1237 strcpy (p1, "subrange");
1238 break;
1239
1240 case btSet: /* pascal sets */
1241 strcpy (p1, "set");
1242 break;
1243
1244 case btComplex: /* fortran complex */
1245 strcpy (p1, "complex");
1246 break;
1247
1248 case btDComplex: /* fortran double complex */
1249 strcpy (p1, "double complex");
1250 break;
1251
1252 case btIndirect: /* forward or unnamed typedef */
1253 strcpy (p1, "forward/unamed typedef");
1254 break;
1255
1256 case btFixedDec: /* Fixed Decimal */
1257 strcpy (p1, "fixed decimal");
1258 break;
1259
1260 case btFloatDec: /* Float Decimal */
1261 strcpy (p1, "float decimal");
1262 break;
1263
1264 case btString: /* Varying Length Character String */
1265 strcpy (p1, "string");
1266 break;
1267
1268 case btBit: /* Aligned Bit String */
1269 strcpy (p1, "bit");
1270 break;
1271
1272 case btPicture: /* Picture */
1273 strcpy (p1, "picture");
1274 break;
1275
1276 case btVoid: /* Void */
1277 strcpy (p1, "void");
1278 break;
1279
1280 default:
1281 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1282 break;
1283 }
1284
1285 p1 += strlen (buffer1);
1286
1287 /*
1288 * If this is a bitfield, get the bitsize.
1289 */
1290 if (u.ti.fBitfield)
1291 {
1292 int bitsize;
1293
1294 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1295 sprintf (p1, " : %d", bitsize);
1296 p1 += strlen (buffer1);
1297 }
1298
1299
1300 /*
1301 * Deal with any qualifiers.
1302 */
1303 if (qualifiers[0].type != tqNil)
1304 {
1305 /*
1306 * Snarf up any array bounds in the correct order. Arrays
1307 * store 5 successive words in the aux. table:
1308 * word 0 RNDXR to type of the bounds (ie, int)
1309 * word 1 Current file descriptor index
1310 * word 2 low bound
1311 * word 3 high bound (or -1 if [])
1312 * word 4 stride size in bits
1313 */
1314 for (i = 0; i < 7; i++)
1315 {
1316 if (qualifiers[i].type == tqArray)
1317 {
1318 qualifiers[i].low_bound =
1319 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1320 qualifiers[i].high_bound =
1321 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1322 qualifiers[i].stride =
1323 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1324 indx += 5;
1325 }
1326 }
1327
1328 /*
1329 * Now print out the qualifiers.
1330 */
1331 for (i = 0; i < 6; i++)
1332 {
1333 switch (qualifiers[i].type)
1334 {
1335 case tqNil:
1336 case tqMax:
1337 break;
1338
1339 case tqPtr:
1340 strcpy (p2, "ptr to ");
1341 p2 += sizeof ("ptr to ")-1;
1342 break;
1343
1344 case tqVol:
1345 strcpy (p2, "volatile ");
1346 p2 += sizeof ("volatile ")-1;
1347 break;
1348
1349 case tqFar:
1350 strcpy (p2, "far ");
1351 p2 += sizeof ("far ")-1;
1352 break;
1353
1354 case tqProc:
1355 strcpy (p2, "func. ret. ");
1356 p2 += sizeof ("func. ret. ");
1357 break;
1358
1359 case tqArray:
1360 {
1361 int first_array = i;
1362 int j;
1363
1364 /* Print array bounds reversed (ie, in the order the C
1365 programmer writes them). C is such a fun language.... */
1366
1367 while (i < 5 && qualifiers[i+1].type == tqArray)
1368 i++;
1369
1370 for (j = i; j >= first_array; j--)
1371 {
1372 strcpy (p2, "array [");
1373 p2 += sizeof ("array [")-1;
1374 if (qualifiers[j].low_bound != 0)
1375 sprintf (p2,
1376 "%ld:%ld {%ld bits}",
1377 (long) qualifiers[j].low_bound,
1378 (long) qualifiers[j].high_bound,
1379 (long) qualifiers[j].stride);
1380
1381 else if (qualifiers[j].high_bound != -1)
1382 sprintf (p2,
1383 "%ld {%ld bits}",
1384 (long) (qualifiers[j].high_bound + 1),
1385 (long) (qualifiers[j].stride));
1386
1387 else
1388 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1389
1390 p2 += strlen (p2);
1391 strcpy (p2, "] of ");
1392 p2 += sizeof ("] of ")-1;
1393 }
1394 }
1395 break;
1396 }
1397 }
1398 }
1399
1400 strcpy (p2, buffer1);
1401 return buffer2;
1402}
1403
1404/* Return information about ECOFF symbol SYMBOL in RET. */
1405
1406void
1407ecoff_get_symbol_info (abfd, symbol, ret)
1408 bfd *abfd; /* Ignored. */
1409 asymbol *symbol;
1410 symbol_info *ret;
1411{
1412 bfd_symbol_info (symbol, ret);
1413}
1414
1415/* Print information about an ECOFF symbol. */
1416
1417void
1418ecoff_print_symbol (abfd, filep, symbol, how)
1419 bfd *abfd;
1420 PTR filep;
1421 asymbol *symbol;
1422 bfd_print_symbol_type how;
1423{
1424 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1425 FILE *file = (FILE *)filep;
1426
1427 switch (how)
1428 {
1429 case bfd_print_symbol_name:
1430 fprintf (file, "%s", symbol->name);
1431 break;
1432 case bfd_print_symbol_more:
1433 if (ecoffsymbol (symbol)->local)
1434 {
1435 SYMR ecoff_sym;
1436
1437 (*backend->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1438 &ecoff_sym);
1439 fprintf (file, "ecoff local ");
1440 fprintf_vma (file, (bfd_vma) ecoff_sym.value);
1441 fprintf (file, " %x %x", (unsigned) ecoff_sym.st,
1442 (unsigned) ecoff_sym.sc);
1443 }
1444 else
1445 {
1446 EXTR ecoff_ext;
1447
1448 (*backend->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1449 &ecoff_ext);
1450 fprintf (file, "ecoff extern ");
1451 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1452 fprintf (file, " %x %x", (unsigned) ecoff_ext.asym.st,
1453 (unsigned) ecoff_ext.asym.sc);
1454 }
1455 break;
1456 case bfd_print_symbol_all:
1457 /* Print out the symbols in a reasonable way */
1458 {
1459 char type;
1460 int pos;
1461 EXTR ecoff_ext;
1462 char jmptbl;
1463 char cobol_main;
1464 char weakext;
1465
1466 if (ecoffsymbol (symbol)->local)
1467 {
1468 (*backend->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1469 &ecoff_ext.asym);
1470 type = 'l';
1471 pos = ((((char *) ecoffsymbol (symbol)->native
1472 - (char *) ecoff_data (abfd)->external_sym)
1473 / backend->external_sym_size)
1474 + ecoff_data (abfd)->symbolic_header.iextMax);
1475 jmptbl = ' ';
1476 cobol_main = ' ';
1477 weakext = ' ';
1478 }
1479 else
1480 {
1481 (*backend->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1482 &ecoff_ext);
1483 type = 'e';
1484 pos = (((char *) ecoffsymbol (symbol)->native
1485 - (char *) ecoff_data (abfd)->external_ext)
1486 / backend->external_ext_size);
1487 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1488 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1489 weakext = ecoff_ext.weakext ? 'w' : ' ';
1490 }
1491
1492 fprintf (file, "[%3d] %c ",
1493 pos, type);
1494 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1495 fprintf (file, " st %x sc %x indx %x %c%c%c %s",
1496 (unsigned) ecoff_ext.asym.st,
1497 (unsigned) ecoff_ext.asym.sc,
1498 (unsigned) ecoff_ext.asym.index,
1499 jmptbl, cobol_main, weakext,
1500 symbol->name);
1501
1502 if (ecoffsymbol (symbol)->fdr != NULL
1503 && ecoff_ext.asym.index != indexNil)
1504 {
1505 unsigned int indx;
1506 int bigendian;
1507 bfd_size_type sym_base;
1508 union aux_ext *aux_base;
1509
1510 indx = ecoff_ext.asym.index;
1511
1512 /* sym_base is used to map the fdr relative indices which
1513 appear in the file to the position number which we are
1514 using. */
1515 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1516 if (ecoffsymbol (symbol)->local)
1517 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1518
1519 /* aux_base is the start of the aux entries for this file;
1520 asym.index is an offset from this. */
1521 aux_base = (ecoff_data (abfd)->external_aux
1522 + ecoffsymbol (symbol)->fdr->iauxBase);
1523
1524 /* The aux entries are stored in host byte order; the
1525 order is indicated by a bit in the fdr. */
1526 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1527
1528 /* This switch is basically from gcc/mips-tdump.c */
1529 switch (ecoff_ext.asym.st)
1530 {
1531 case stNil:
1532 case stLabel:
1533 break;
1534
1535 case stFile:
1536 case stBlock:
1537 fprintf (file, "\n End+1 symbol: %ld",
1538 (long) (indx + sym_base));
1539 break;
1540
1541 case stEnd:
1542 if (ecoff_ext.asym.sc == scText
1543 || ecoff_ext.asym.sc == scInfo)
1544 fprintf (file, "\n First symbol: %ld",
1545 (long) (indx + sym_base));
1546 else
1547 fprintf (file, "\n First symbol: %ld",
1548 (long) (AUX_GET_ISYM (bigendian,
1549 &aux_base[ecoff_ext.asym.index])
1550 + sym_base));
1551 break;
1552
1553 case stProc:
1554 case stStaticProc:
1555 if (ECOFF_IS_STAB (&ecoff_ext.asym))
1556 ;
1557 else if (ecoffsymbol (symbol)->local)
1558 fprintf (file, "\n End+1 symbol: %-7ld Type: %s",
1559 (long) (AUX_GET_ISYM (bigendian,
1560 &aux_base[ecoff_ext.asym.index])
1561 + sym_base),
1562 ecoff_type_to_string (abfd, aux_base, indx + 1,
1563 bigendian));
1564 else
1565 fprintf (file, "\n Local symbol: %d",
1566 (indx
1567 + sym_base
1568 + ecoff_data (abfd)->symbolic_header.iextMax));
1569 break;
1570
1571 default:
1572 if (! ECOFF_IS_STAB (&ecoff_ext.asym))
1573 fprintf (file, "\n Type: %s",
1574 ecoff_type_to_string (abfd, aux_base, indx,
1575 bigendian));
1576 break;
1577 }
1578 }
1579 }
1580 break;
1581 }
1582}
1583\f
dae31cf5
ILT
1584/* Read in the relocs for a section. */
1585
1586static boolean
1587ecoff_slurp_reloc_table (abfd, section, symbols)
1588 bfd *abfd;
1589 asection *section;
1590 asymbol **symbols;
1591{
1592 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1593 arelent *internal_relocs;
1594 bfd_size_type external_reloc_size;
1595 bfd_size_type external_relocs_size;
1596 char *external_relocs;
1597 arelent *rptr;
1598 unsigned int i;
1599
1600 if (section->relocation != (arelent *) NULL
1601 || section->reloc_count == 0
1602 || (section->flags & SEC_CONSTRUCTOR) != 0)
1603 return true;
1604
1605 if (ecoff_slurp_symbol_table (abfd) == false)
1606 return false;
1607
1608 internal_relocs = (arelent *) bfd_alloc (abfd,
1609 (sizeof (arelent)
1610 * section->reloc_count));
1611 external_reloc_size = backend->external_reloc_size;
1612 external_relocs_size = external_reloc_size * section->reloc_count;
1613 external_relocs = (char *) bfd_alloc (abfd, external_relocs_size);
1614 if (internal_relocs == (arelent *) NULL
1615 || external_relocs == (char *) NULL)
1616 {
1617 bfd_error = no_memory;
1618 return false;
1619 }
1620 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1621 return false;
1622 if (bfd_read (external_relocs, 1, external_relocs_size, abfd)
1623 != external_relocs_size)
1624 {
1625 bfd_error = system_call_error;
1626 return false;
1627 }
1628
1629 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1630 {
1631 struct internal_reloc intern;
1632
1633 (*backend->swap_reloc_in) (abfd,
1634 external_relocs + i * external_reloc_size,
1635 &intern);
1636
dae31cf5
ILT
1637 if (intern.r_extern)
1638 {
1639 /* r_symndx is an index into the external symbols. */
1640 BFD_ASSERT (intern.r_symndx >= 0
1641 && (intern.r_symndx
1642 < ecoff_data (abfd)->symbolic_header.iextMax));
1643 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1644 rptr->addend = 0;
1645 }
1646 else
1647 {
1648 CONST char *sec_name;
1649 asection *sec;
1650
1651 /* r_symndx is a section key. */
1652 switch (intern.r_symndx)
1653 {
1654 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1655 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1656 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1657 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1658 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1659 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1660 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1661 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1662 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
8f46bac8
ILT
1663 case RELOC_SECTION_XDATA: sec_name = ".xdata"; break;
1664 case RELOC_SECTION_PDATA: sec_name = ".pdata"; break;
1665 case RELOC_SECTION_LITA: sec_name = ".lita"; break;
1666 case RELOC_SECTION_ABS: sec_name = ".abs"; break;
dae31cf5
ILT
1667 default: abort ();
1668 }
1669
1670 sec = bfd_get_section_by_name (abfd, sec_name);
1671 if (sec == (asection *) NULL)
8f46bac8 1672 sec = bfd_make_section (abfd, sec_name);
dae31cf5
ILT
1673 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
1674
1675 rptr->addend = - bfd_get_section_vma (abfd, sec);
dae31cf5
ILT
1676 }
1677
1678 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
dae31cf5 1679
8f46bac8
ILT
1680 /* Let the backend select the howto field and do any other
1681 required processing. */
1682 (*backend->finish_reloc) (abfd, &intern, rptr);
dae31cf5
ILT
1683 }
1684
1685 bfd_release (abfd, external_relocs);
1686
1687 section->relocation = internal_relocs;
1688
1689 return true;
1690}
1691
1692/* Get a canonical list of relocs. */
1693
1694unsigned int
1695ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
1696 bfd *abfd;
1697 asection *section;
1698 arelent **relptr;
1699 asymbol **symbols;
1700{
1701 unsigned int count;
1702
1703 if (section->flags & SEC_CONSTRUCTOR)
1704 {
1705 arelent_chain *chain;
1706
1707 /* This section has relocs made up by us, not the file, so take
1708 them out of their chain and place them into the data area
1709 provided. */
1710 for (count = 0, chain = section->constructor_chain;
1711 count < section->reloc_count;
1712 count++, chain = chain->next)
1713 *relptr++ = &chain->relent;
1714 }
1715 else
1716 {
1717 arelent *tblptr;
1718
1719 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
1720 return 0;
1721
1722 tblptr = section->relocation;
1723 if (tblptr == (arelent *) NULL)
1724 return 0;
1725
1726 for (count = 0; count < section->reloc_count; count++)
1727 *relptr++ = tblptr++;
1728 }
1729
1730 *relptr = (arelent *) NULL;
1731
1732 return section->reloc_count;
1733}
dae31cf5
ILT
1734\f
1735/* Provided a BFD, a section and an offset into the section, calculate
1736 and return the name of the source file and the line nearest to the
1737 wanted location. */
1738
1739boolean
1740ecoff_find_nearest_line (abfd,
1741 section,
1742 ignore_symbols,
1743 offset,
1744 filename_ptr,
1745 functionname_ptr,
1746 retline_ptr)
1747 bfd *abfd;
1748 asection *section;
1749 asymbol **ignore_symbols;
1750 bfd_vma offset;
1751 CONST char **filename_ptr;
1752 CONST char **functionname_ptr;
1753 unsigned int *retline_ptr;
1754{
1755 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1756 FDR *fdr_ptr;
1757 FDR *fdr_start;
1758 FDR *fdr_end;
1759 FDR *fdr_hold;
1760 bfd_size_type external_pdr_size;
1761 char *pdr_ptr;
1762 char *pdr_end;
1763 PDR pdr;
1764 unsigned char *line_ptr;
1765 unsigned char *line_end;
1766 int lineno;
1767
1768 /* If we're not in the .text section, we don't have any line
1769 numbers. */
1770 if (strcmp (section->name, _TEXT) != 0
1771 || offset < ecoff_data (abfd)->text_start
1772 || offset >= ecoff_data (abfd)->text_end)
1773 return false;
1774
1775 /* Make sure we have the FDR's. */
1776 if (ecoff_slurp_symbolic_info (abfd) == false
1777 || bfd_get_symcount (abfd) == 0)
1778 return false;
1779
1780 /* Each file descriptor (FDR) has a memory address. Here we track
1781 down which FDR we want. The FDR's are stored in increasing
1782 memory order. If speed is ever important, this can become a
1783 binary search. We must ignore FDR's with no PDR entries; they
1784 will have the adr of the FDR before or after them. */
1785 fdr_start = ecoff_data (abfd)->fdr;
1786 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
1787 fdr_hold = (FDR *) NULL;
1788 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1789 {
1790 if (fdr_ptr->cpd == 0)
1791 continue;
1792 if (offset < fdr_ptr->adr)
1793 break;
1794 fdr_hold = fdr_ptr;
1795 }
1796 if (fdr_hold == (FDR *) NULL)
1797 return false;
1798 fdr_ptr = fdr_hold;
1799
1800 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1801 have an address, which is relative to the FDR address, and are
1802 also stored in increasing memory order. */
1803 offset -= fdr_ptr->adr;
1804 external_pdr_size = backend->external_pdr_size;
1805 pdr_ptr = ((char *) ecoff_data (abfd)->external_pdr
1806 + fdr_ptr->ipdFirst * external_pdr_size);
1807 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
1808 (*backend->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1809
1810 /* The address of the first PDR is an offset which applies to the
1811 addresses of all the PDR's. */
1812 offset += pdr.adr;
1813
1814 for (pdr_ptr += external_pdr_size;
1815 pdr_ptr < pdr_end;
1816 pdr_ptr += external_pdr_size)
1817 {
1818 (*backend->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1819 if (offset < pdr.adr)
1820 break;
1821 }
1822
1823 /* Now we can look for the actual line number. The line numbers are
1824 stored in a very funky format, which I won't try to describe.
1825 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1826 we want; we need this to compute line_end. */
1827 line_end = ecoff_data (abfd)->line;
1828 if (pdr_ptr == pdr_end)
1829 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
1830 else
1831 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
1832
1833 /* Now change pdr and pdr_ptr to the one we want. */
1834 pdr_ptr -= external_pdr_size;
1835 (*backend->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1836
1837 offset -= pdr.adr;
1838 lineno = pdr.lnLow;
1839 line_ptr = (ecoff_data (abfd)->line
1840 + fdr_ptr->cbLineOffset
1841 + pdr.cbLineOffset);
1842 while (line_ptr < line_end)
1843 {
1844 int delta;
1845 int count;
1846
1847 delta = *line_ptr >> 4;
1848 if (delta >= 0x8)
1849 delta -= 0x10;
1850 count = (*line_ptr & 0xf) + 1;
1851 ++line_ptr;
1852 if (delta == -8)
1853 {
1854 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
1855 if (delta >= 0x8000)
1856 delta -= 0x10000;
1857 line_ptr += 2;
1858 }
1859 lineno += delta;
1860 if (offset < count * 4)
1861 break;
1862 offset -= count * 4;
1863 }
1864
1865 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
1866 at least according to gdb/mipsread.c. */
1867 if (fdr_ptr->rss == -1)
1868 {
1869 *filename_ptr = NULL;
1870 if (pdr.isym == -1)
1871 *functionname_ptr = NULL;
1872 else
1873 {
1874 EXTR proc_ext;
1875
1876 (*backend->swap_ext_in) (abfd,
1877 ((char *) ecoff_data (abfd)->external_ext
1878 + pdr.isym * backend->external_ext_size),
1879 &proc_ext);
1880 *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss;
1881 }
1882 }
1883 else
1884 {
1885 SYMR proc_sym;
1886
1887 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
1888 (*backend->swap_sym_in) (abfd,
1889 ((char *) ecoff_data (abfd)->external_sym
1890 + ((fdr_ptr->isymBase + pdr.isym)
1891 * backend->external_sym_size)),
1892 &proc_sym);
1893 *functionname_ptr = (ecoff_data (abfd)->ss
1894 + fdr_ptr->issBase
1895 + proc_sym.iss);
1896 }
1897 if (lineno == ilineNil)
1898 lineno = 0;
1899 *retline_ptr = lineno;
1900 return true;
1901}
1902\f
1903/* We can't use the generic linking routines for ECOFF, because we
1904 have to handle all the debugging information. The generic link
1905 routine just works out the section contents and attaches a list of
1906 symbols.
1907
1908 We link by looping over all the seclets. We make two passes. On
1909 the first we set the actual section contents and determine the size
1910 of the debugging information. On the second we accumulate the
1911 debugging information and write it out.
1912
1913 This currently always accumulates the debugging information, which
1914 is incorrect, because it ignores the -s and -S options of the
1915 linker. The linker needs to be modified to give us that
1916 information in a more useful format (currently it just provides a
1917 list of symbols which should appear in the output file). */
1918
1919/* Clear the output_has_begun flag for all the input BFD's. We use it
1920 to avoid linking in the debugging information for a BFD more than
1921 once. */
1922
1923static void
1924ecoff_clear_output_flags (abfd)
1925 bfd *abfd;
1926{
1927 register asection *o;
1928 register bfd_seclet_type *p;
1929
1930 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
1931 for (p = o->seclets_head;
1932 p != (bfd_seclet_type *) NULL;
1933 p = p->next)
1934 if (p->type == bfd_indirect_seclet)
1935 p->u.indirect.section->owner->output_has_begun = false;
1936}
1937
1938/* Handle an indirect seclet on the first pass. Set the contents of
1939 the output section, and accumulate the debugging information if
1940 any. */
1941
1942static boolean
1943ecoff_rel (output_bfd, seclet, output_section, data, relocateable)
1944 bfd *output_bfd;
1945 bfd_seclet_type *seclet;
1946 asection *output_section;
1947 PTR data;
1948 boolean relocateable;
1949{
1950 bfd *input_bfd;
1951 HDRR *output_symhdr;
1952 HDRR *input_symhdr;
1953
1954 if ((output_section->flags & SEC_HAS_CONTENTS)
1955 && !(output_section->flags & SEC_NEVER_LOAD)
1956 && (output_section->flags & SEC_LOAD)
1957 && seclet->size)
1958 {
1959 data = (PTR) bfd_get_relocated_section_contents (output_bfd,
1960 seclet,
1961 data,
1962 relocateable);
1963 if (bfd_set_section_contents (output_bfd,
1964 output_section,
1965 data,
1966 seclet->offset,
1967 seclet->size)
1968 == false)
1969 {
1970 abort();
1971 }
1972 }
1973
1974 input_bfd = seclet->u.indirect.section->owner;
1975
1976 /* We want to figure out how much space will be required to
1977 incorporate all the debugging information from input_bfd. We use
1978 the output_has_begun field to avoid adding it in more than once.
1979 The actual incorporation is done in the second pass, in
1980 ecoff_get_debug. The code has to parallel that code in its
1981 manipulations of output_symhdr. */
1982
1983 if (input_bfd->output_has_begun)
1984 return true;
1985 input_bfd->output_has_begun = true;
1986
1987 output_symhdr = &ecoff_data (output_bfd)->symbolic_header;
1988
1989 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
1990 {
1991 asymbol **symbols;
1992 asymbol **sym_ptr;
1993 asymbol **sym_end;
1994
1995 /* We just accumulate local symbols from a non-ECOFF BFD. The
1996 external symbols are handled separately. */
1997
1998 symbols = (asymbol **) bfd_alloc (output_bfd,
1999 get_symtab_upper_bound (input_bfd));
2000 if (symbols == (asymbol **) NULL)
2001 {
2002 bfd_error = no_memory;
2003 return false;
2004 }
2005 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2006
2007 for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++)
2008 {
2009 size_t len;
2010
2011 len = strlen ((*sym_ptr)->name);
2012 if (((*sym_ptr)->flags & BSF_EXPORT) == 0)
2013 {
2014 ++output_symhdr->isymMax;
2015 output_symhdr->issMax += len + 1;
2016 }
2017 }
2018
2019 bfd_release (output_bfd, (PTR) symbols);
2020
2021 ++output_symhdr->ifdMax;
2022
2023 return true;
2024 }
2025
2026 /* We simply add in the information from another ECOFF BFD. First
2027 we make sure we have the symbolic information. */
2028 if (ecoff_slurp_symbol_table (input_bfd) == false)
2029 return false;
2030 if (bfd_get_symcount (input_bfd) == 0)
2031 return true;
2032
2033 input_symhdr = &ecoff_data (input_bfd)->symbolic_header;
2034
2035 /* Figure out how much information we are going to be putting in.
2036 The external symbols are handled separately. */
2037 output_symhdr->ilineMax += input_symhdr->ilineMax;
2038 output_symhdr->cbLine += input_symhdr->cbLine;
2039 output_symhdr->idnMax += input_symhdr->idnMax;
2040 output_symhdr->ipdMax += input_symhdr->ipdMax;
2041 output_symhdr->isymMax += input_symhdr->isymMax;
2042 output_symhdr->ioptMax += input_symhdr->ioptMax;
2043 output_symhdr->iauxMax += input_symhdr->iauxMax;
2044 output_symhdr->issMax += input_symhdr->issMax;
2045 output_symhdr->ifdMax += input_symhdr->ifdMax;
2046
2047 /* The RFD's are special, since we create them if needed. */
2048 if (input_symhdr->crfd > 0)
2049 output_symhdr->crfd += input_symhdr->crfd;
2050 else
2051 output_symhdr->crfd += input_symhdr->ifdMax;
2052
2053 return true;
2054}
2055
2056/* Handle an arbitrary seclet on the first pass. */
2057
2058static boolean
2059ecoff_dump_seclet (abfd, seclet, section, data, relocateable)
2060 bfd *abfd;
2061 bfd_seclet_type *seclet;
2062 asection *section;
2063 PTR data;
2064 boolean relocateable;
2065{
2066 switch (seclet->type)
2067 {
2068 case bfd_indirect_seclet:
2069 /* The contents of this section come from another one somewhere
2070 else. */
2071 return ecoff_rel (abfd, seclet, section, data, relocateable);
2072
2073 case bfd_fill_seclet:
2074 /* Fill in the section with fill.value. This is used to pad out
2075 sections, but we must avoid padding the .bss section. */
2076 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2077 {
2078 if (seclet->u.fill.value != 0)
2079 abort ();
2080 }
2081 else
2082 {
2083 char *d = (char *) bfd_alloc (abfd, seclet->size);
2084 unsigned int i;
2085 boolean ret;
2086
2087 for (i = 0; i < seclet->size; i+=2)
2088 d[i] = seclet->u.fill.value >> 8;
2089 for (i = 1; i < seclet->size; i+=2)
2090 d[i] = seclet->u.fill.value;
2091 ret = bfd_set_section_contents (abfd, section, d, seclet->offset,
2092 seclet->size);
2093 bfd_release (abfd, (PTR) d);
2094 return ret;
2095 }
2096 break;
2097
2098 default:
2099 abort();
2100 }
2101
2102 return true;
2103}
2104
2105/* Add a string to the debugging information we are accumulating for a
2106 file. Return the offset from the fdr string base or from the
2107 external string base. */
2108
2109static long
2110ecoff_add_string (output_bfd, fdr, string, external)
2111 bfd *output_bfd;
2112 FDR *fdr;
2113 CONST char *string;
2114 boolean external;
2115{
2116 HDRR *symhdr;
2117 size_t len;
2118 long ret;
2119
2120 symhdr = &ecoff_data (output_bfd)->symbolic_header;
2121 len = strlen (string);
2122 if (external)
2123 {
2124 strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string);
2125 ret = symhdr->issExtMax;
2126 symhdr->issExtMax += len + 1;
2127 }
2128 else
2129 {
2130 strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string);
2131 ret = fdr->cbSs;
2132 symhdr->issMax += len + 1;
2133 fdr->cbSs += len + 1;
2134 }
2135 return ret;
2136}
2137
2138/* Accumulate the debugging information from an input section. */
2139
2140static boolean
2141ecoff_get_debug (output_bfd, seclet, section, relocateable)
2142 bfd *output_bfd;
2143 bfd_seclet_type *seclet;
2144 asection *section;
2145 boolean relocateable;
2146{
2147 const struct ecoff_backend_data * const backend = ecoff_backend (output_bfd);
2148 const bfd_size_type external_sym_size = backend->external_sym_size;
2149 const bfd_size_type external_pdr_size = backend->external_pdr_size;
2150 const bfd_size_type external_fdr_size = backend->external_fdr_size;
2151 const bfd_size_type external_rfd_size = backend->external_rfd_size;
2152 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
2153 = backend->swap_sym_in;
2154 void (* const swap_sym_out) PARAMS ((bfd *, const SYMR *, PTR))
2155 = backend->swap_sym_out;
2156 void (* const swap_pdr_in) PARAMS ((bfd *, PTR, PDR *))
2157 = backend->swap_pdr_in;
2158 void (* const swap_fdr_out) PARAMS ((bfd *, const FDR *, PTR))
2159 = backend->swap_fdr_out;
2160 void (* const swap_rfd_out) PARAMS ((bfd *, const RFDT *, PTR))
2161 = backend->swap_rfd_out;
2162 bfd *input_bfd;
2163 HDRR *output_symhdr;
2164 HDRR *input_symhdr;
2165 ecoff_data_type *output_ecoff;
2166 ecoff_data_type *input_ecoff;
2167 unsigned int count;
2168 char *sym_out;
2169 ecoff_symbol_type *esym_ptr;
2170 ecoff_symbol_type *esym_end;
2171 FDR *fdr_ptr;
2172 FDR *fdr_end;
2173 char *fdr_out;
2174
2175 input_bfd = seclet->u.indirect.section->owner;
2176
2177 /* Don't get the information more than once. */
2178 if (input_bfd->output_has_begun)
2179 return true;
2180 input_bfd->output_has_begun = true;
2181
2182 output_ecoff = ecoff_data (output_bfd);
2183 output_symhdr = &output_ecoff->symbolic_header;
2184
2185 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2186 {
2187 FDR fdr;
2188 asymbol **symbols;
2189 asymbol **sym_ptr;
2190 asymbol **sym_end;
2191
2192 /* This is not an ECOFF BFD. Just gather the symbols. */
2193
2194 memset (&fdr, 0, sizeof fdr);
2195
2196 fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset;
2197 fdr.issBase = output_symhdr->issMax;
2198 fdr.cbSs = 0;
2199 fdr.rss = ecoff_add_string (output_bfd,
2200 &fdr,
2201 bfd_get_filename (input_bfd),
2202 false);
2203 fdr.isymBase = output_symhdr->isymMax;
2204
2205 /* Get the local symbols from the input BFD. */
2206 symbols = (asymbol **) bfd_alloc (output_bfd,
2207 get_symtab_upper_bound (input_bfd));
2208 if (symbols == (asymbol **) NULL)
2209 {
2210 bfd_error = no_memory;
2211 return false;
2212 }
2213 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2214
2215 /* Handle the local symbols. Any external symbols are handled
2216 separately. */
2217 fdr.csym = 0;
2218 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
2219 {
2220 SYMR internal_sym;
2221
2222 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
2223 continue;
2224 memset (&internal_sym, 0, sizeof internal_sym);
2225 internal_sym.iss = ecoff_add_string (output_bfd,
2226 &fdr,
2227 (*sym_ptr)->name,
2228 false);
2229
2230 if (bfd_is_com_section ((*sym_ptr)->section)
2231 || (*sym_ptr)->section == &bfd_und_section)
2232 internal_sym.value = (*sym_ptr)->value;
2233 else
2234 internal_sym.value = ((*sym_ptr)->value
2235 + (*sym_ptr)->section->output_offset
2236 + (*sym_ptr)->section->output_section->vma);
2237 internal_sym.st = stNil;
2238 internal_sym.sc = scUndefined;
2239 internal_sym.index = indexNil;
2240 (*swap_sym_out) (output_bfd, &internal_sym,
2241 ((char *) output_ecoff->external_sym
2242 + output_symhdr->isymMax * external_sym_size));
2243 ++fdr.csym;
2244 ++output_symhdr->isymMax;
2245 }
2246
2247 bfd_release (output_bfd, (PTR) symbols);
2248
2249 /* Leave everything else in the FDR zeroed out. This will cause
2250 the lang field to be langC. The fBigendian field will
2251 indicate little endian format, but it doesn't matter because
2252 it only applies to aux fields and there are none. */
2253
2254 (*swap_fdr_out) (output_bfd, &fdr,
2255 ((char *) output_ecoff->external_fdr
2256 + output_symhdr->ifdMax * external_fdr_size));
2257 ++output_symhdr->ifdMax;
2258 return true;
2259 }
2260
2261 /* This is an ECOFF BFD. We want to grab the information from
2262 input_bfd and attach it to output_bfd. */
2263 count = bfd_get_symcount (input_bfd);
2264 if (count == 0)
2265 return true;
2266 input_ecoff = ecoff_data (input_bfd);
2267 input_symhdr = &input_ecoff->symbolic_header;
2268
2269 /* I think that it is more efficient to simply copy the debugging
2270 information from the input BFD to the output BFD. Because ECOFF
2271 uses relative pointers for most of the debugging information,
2272 only a little of it has to be changed at all. */
2273
2274 /* Swap in the local symbols, adjust their values, and swap them out
2275 again. The external symbols are handled separately. */
2276 sym_out = ((char *) output_ecoff->external_sym
2277 + output_symhdr->isymMax * external_sym_size);
2278
2279 esym_ptr = ecoff_data (input_bfd)->canonical_symbols;
2280 esym_end = esym_ptr + count;
2281 for (; esym_ptr < esym_end; esym_ptr++)
2282 {
2283 if (esym_ptr->local)
2284 {
2285 SYMR sym;
2286
2287 (*swap_sym_in) (input_bfd, esym_ptr->native, &sym);
2288
2289 /* If we're producing an executable, move common symbols
2290 into bss. */
2291 if (relocateable == false)
2292 {
2293 if (sym.sc == scCommon)
2294 sym.sc = scBss;
2295 else if (sym.sc == scSCommon)
2296 sym.sc = scSBss;
2297 }
2298
2299 if (! bfd_is_com_section (esym_ptr->symbol.section)
2300 && (esym_ptr->symbol.flags & BSF_DEBUGGING) == 0
2301 && esym_ptr->symbol.section != &bfd_und_section)
2302 sym.value = (esym_ptr->symbol.value
2303 + esym_ptr->symbol.section->output_offset
2304 + esym_ptr->symbol.section->output_section->vma);
2305 (*swap_sym_out) (output_bfd, &sym, sym_out);
2306 sym_out += external_sym_size;
2307 }
2308 }
2309
2310 /* That should have accounted for all the local symbols in
2311 input_bfd. */
2312
2313 /* Copy the information that does not need swapping. */
2314 memcpy (output_ecoff->line + output_symhdr->cbLine,
2315 input_ecoff->line,
2316 input_symhdr->cbLine * sizeof (unsigned char));
2317 memcpy (output_ecoff->external_aux + output_symhdr->iauxMax,
2318 input_ecoff->external_aux,
2319 input_symhdr->iauxMax * sizeof (union aux_ext));
2320 memcpy (output_ecoff->ss + output_symhdr->issMax,
2321 input_ecoff->ss,
2322 input_symhdr->issMax * sizeof (char));
2323
2324 /* Some of the information may need to be swapped. */
2325 if (output_bfd->xvec->header_byteorder_big_p
2326 == input_bfd->xvec->header_byteorder_big_p)
2327 {
2328 /* The two BFD's have the same endianness, so memcpy will
2329 suffice. */
2330 if (input_symhdr->idnMax > 0)
2331 memcpy (((char *) output_ecoff->external_dnr
2332 + output_symhdr->idnMax * backend->external_dnr_size),
2333 input_ecoff->external_dnr,
2334 input_symhdr->idnMax * backend->external_dnr_size);
2335 if (input_symhdr->ipdMax > 0)
2336 memcpy (((char *) output_ecoff->external_pdr
2337 + output_symhdr->ipdMax * external_pdr_size),
2338 input_ecoff->external_pdr,
2339 input_symhdr->ipdMax * external_pdr_size);
2340 if (input_symhdr->ioptMax > 0)
2341 memcpy (((char *) output_ecoff->external_opt
2342 + output_symhdr->ioptMax * backend->external_opt_size),
2343 input_ecoff->external_opt,
2344 input_symhdr->ioptMax * backend->external_opt_size);
2345 }
2346 else
2347 {
2348 bfd_size_type sz;
2349 char *in;
2350 char *end;
2351 char *out;
2352
2353 /* The two BFD's have different endianness, so we must swap
2354 everything in and out. This code would always work, but it
2355 would be slow in the normal case. */
2356 sz = backend->external_dnr_size;
2357 in = (char *) input_ecoff->external_dnr;
2358 end = in + input_symhdr->idnMax * sz;
2359 out = (char *) output_ecoff->external_dnr + output_symhdr->idnMax * sz;
2360 for (; in < end; in += sz, out += sz)
2361 {
2362 DNR dnr;
2363
2364 (*backend->swap_dnr_in) (input_bfd, in, &dnr);
2365 (*backend->swap_dnr_out) (output_bfd, &dnr, out);
2366 }
2367
2368 sz = external_pdr_size;
2369 in = (char *) input_ecoff->external_pdr;
2370 end = in + input_symhdr->ipdMax * sz;
2371 out = (char *) output_ecoff->external_pdr + output_symhdr->ipdMax * sz;
2372 for (; in < end; in += sz, out += sz)
2373 {
2374 PDR pdr;
2375
2376 (*swap_pdr_in) (input_bfd, in, &pdr);
2377 (*backend->swap_pdr_out) (output_bfd, &pdr, out);
2378 }
2379
2380 sz = backend->external_opt_size;
2381 in = (char *) input_ecoff->external_opt;
2382 end = in + input_symhdr->ioptMax * sz;
2383 out = (char *) output_ecoff->external_opt + output_symhdr->ioptMax * sz;
2384 for (; in < end; in += sz, out += sz)
2385 {
2386 OPTR opt;
2387
2388 (*backend->swap_opt_in) (input_bfd, in, &opt);
2389 (*backend->swap_opt_out) (output_bfd, &opt, out);
2390 }
2391 }
2392
2393 /* Set ifdbase so that the external symbols know how to adjust their
2394 ifd values. */
2395 input_ecoff->ifdbase = output_symhdr->ifdMax;
2396
2397 fdr_ptr = input_ecoff->fdr;
2398 fdr_end = fdr_ptr + input_symhdr->ifdMax;
2399 fdr_out = ((char *) output_ecoff->external_fdr
2400 + output_symhdr->ifdMax * external_fdr_size);
2401 for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out += external_fdr_size)
2402 {
2403 FDR fdr;
2404 unsigned long pdr_off;
2405
2406 fdr = *fdr_ptr;
2407
2408 /* The memory address for this fdr is the address for the seclet
2409 plus the offset to this fdr within input_bfd. For some
2410 reason the offset of the first procedure pointer is also
2411 added in. */
2412 if (fdr.cpd == 0)
2413 pdr_off = 0;
2414 else
2415 {
2416 PDR pdr;
2417
2418 (*swap_pdr_in) (input_bfd,
2419 ((char *) input_ecoff->external_pdr
2420 + fdr.ipdFirst * external_pdr_size),
2421 &pdr);
2422 pdr_off = pdr.adr;
2423 }
2424 fdr.adr = (bfd_get_section_vma (output_bfd, section)
2425 + seclet->offset
2426 + (fdr_ptr->adr - input_ecoff->fdr->adr)
2427 + pdr_off);
2428
2429 fdr.issBase += output_symhdr->issMax;
2430 fdr.isymBase += output_symhdr->isymMax;
2431 fdr.ilineBase += output_symhdr->ilineMax;
2432 fdr.ioptBase += output_symhdr->ioptMax;
2433 fdr.ipdFirst += output_symhdr->ipdMax;
2434 fdr.iauxBase += output_symhdr->iauxMax;
2435 fdr.rfdBase += output_symhdr->crfd;
2436
2437 /* If there are no RFD's, we are going to add some. We don't
2438 want to adjust irfd for this, so that all the FDR's can share
2439 the RFD's. */
2440 if (input_symhdr->crfd == 0)
2441 fdr.crfd = input_symhdr->ifdMax;
2442
2443 if (fdr.cbLine != 0)
2444 fdr.cbLineOffset += output_symhdr->cbLine;
2445
2446 (*swap_fdr_out) (output_bfd, &fdr, fdr_out);
2447 }
2448
2449 if (input_symhdr->crfd > 0)
2450 {
2451 void (* const swap_rfd_in) PARAMS ((bfd *, PTR, RFDT *))
2452 = backend->swap_rfd_in;
2453 char *rfd_in;
2454 char *rfd_end;
2455 char *rfd_out;
2456
2457 /* Swap and adjust the RFD's. RFD's are only created by the
2458 linker, so this will only be necessary if one of the input
2459 files is the result of a partial link. Presumably all
2460 necessary RFD's are present. */
2461 rfd_in = (char *) input_ecoff->external_rfd;
2462 rfd_end = rfd_in + input_symhdr->crfd * external_rfd_size;
2463 rfd_out = ((char *) output_ecoff->external_rfd
2464 + output_symhdr->crfd * external_rfd_size);
2465 for (;
2466 rfd_in < rfd_end;
2467 rfd_in += external_rfd_size, rfd_out += external_rfd_size)
2468 {
2469 RFDT rfd;
2470
2471 (*swap_rfd_in) (input_bfd, rfd_in, &rfd);
2472 rfd += output_symhdr->ifdMax;
2473 (*swap_rfd_out) (output_bfd, &rfd, rfd_out);
2474 }
2475 output_symhdr->crfd += input_symhdr->crfd;
2476 }
2477 else
2478 {
2479 char *rfd_out;
2480 char *rfd_end;
2481 RFDT rfd;
2482
2483 /* Create RFD's. Some of the debugging information includes
2484 relative file indices. These indices are taken as indices to
2485 the RFD table if there is one, or to the global table if
2486 there is not. If we did not create RFD's, we would have to
2487 parse and adjust all the debugging information which contains
2488 file indices. */
2489 rfd = output_symhdr->ifdMax;
2490 rfd_out = ((char *) output_ecoff->external_rfd
2491 + output_symhdr->crfd * external_rfd_size);
2492 rfd_end = rfd_out + input_symhdr->ifdMax * external_rfd_size;
2493 for (; rfd_out < rfd_end; rfd_out += external_rfd_size, rfd++)
2494 (*swap_rfd_out) (output_bfd, &rfd, rfd_out);
2495 output_symhdr->crfd += input_symhdr->ifdMax;
2496 }
2497
48edba81
ILT
2498 /* Combine the register masks. Not all of these are used on all
2499 targets, but that's OK because only the relevant ones will be
2500 swapped in and out. */
dae31cf5
ILT
2501 {
2502 int i;
2503
2504 output_ecoff->gprmask |= input_ecoff->gprmask;
48edba81 2505 output_ecoff->fprmask |= input_ecoff->fprmask;
dae31cf5
ILT
2506 for (i = 0; i < 4; i++)
2507 output_ecoff->cprmask[i] |= input_ecoff->cprmask[i];
2508 }
2509
2510 /* Update the counts. */
2511 output_symhdr->ilineMax += input_symhdr->ilineMax;
2512 output_symhdr->cbLine += input_symhdr->cbLine;
2513 output_symhdr->idnMax += input_symhdr->idnMax;
2514 output_symhdr->ipdMax += input_symhdr->ipdMax;
2515 output_symhdr->isymMax += input_symhdr->isymMax;
2516 output_symhdr->ioptMax += input_symhdr->ioptMax;
2517 output_symhdr->iauxMax += input_symhdr->iauxMax;
2518 output_symhdr->issMax += input_symhdr->issMax;
2519 output_symhdr->ifdMax += input_symhdr->ifdMax;
2520
2521 return true;
2522}
2523
2524/* This is the actual link routine. It makes two passes over all the
2525 seclets. */
2526
2527boolean
2528ecoff_bfd_seclet_link (abfd, data, relocateable)
2529 bfd *abfd;
2530 PTR data;
2531 boolean relocateable;
2532{
2533 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
2534 HDRR *symhdr;
2535 int ipass;
2536 register asection *o;
2537 register bfd_seclet_type *p;
2538 asymbol **sym_ptr_ptr;
2539 bfd_size_type debug_align;
2540 bfd_size_type size;
2541 char *raw;
2542
2543 /* We accumulate the debugging information counts in the symbolic
2544 header. */
2545 symhdr = &ecoff_data (abfd)->symbolic_header;
48edba81 2546 symhdr->magic = backend->sym_magic;
dae31cf5
ILT
2547 /* FIXME: What should the version stamp be? */
2548 symhdr->vstamp = 0;
2549 symhdr->ilineMax = 0;
2550 symhdr->cbLine = 0;
2551 symhdr->idnMax = 0;
2552 symhdr->ipdMax = 0;
2553 symhdr->isymMax = 0;
2554 symhdr->ioptMax = 0;
2555 symhdr->iauxMax = 0;
2556 symhdr->issMax = 0;
2557 symhdr->issExtMax = 0;
2558 symhdr->ifdMax = 0;
2559 symhdr->crfd = 0;
2560 symhdr->iextMax = 0;
2561
2562 /* We need to copy over the debugging symbols from each input BFD.
2563 When we do this copying, we have to adjust the text address in
2564 the FDR structures, so we have to know the text address used for
2565 the input BFD. Since we only want to copy the symbols once per
2566 input BFD, but we are going to look at each input BFD multiple
2567 times (once for each section it provides), we arrange to always
2568 look at the text section first. That means that when we copy the
2569 debugging information, we always know the text address. So we
2570 actually do each pass in two sub passes; first the text sections,
2571 then the non-text sections. We use the output_has_begun flag to
2572 determine whether we have copied over the debugging information
2573 yet. */
2574
2575 /* Do the first pass: set the output section contents and count the
2576 debugging information. */
2577 ecoff_clear_output_flags (abfd);
2578 for (ipass = 0; ipass < 2; ipass++)
2579 {
2580 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2581 {
2582 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2583 so they are done on pass 0. For other sections the
2584 expression is true, so they are done on pass 1. */
2585 if (((o->flags & SEC_CODE) == 0) != ipass)
2586 continue;
2587
2588 for (p = o->seclets_head;
2589 p != (bfd_seclet_type *) NULL;
2590 p = p->next)
2591 {
2592 if (ecoff_dump_seclet (abfd, p, o, data, relocateable)
2593 == false)
2594 return false;
2595 }
2596 }
2597 }
2598
2599 /* We handle the external symbols differently. We use the ones
2600 attached to the output_bfd. The linker will have already
2601 determined which symbols are to be attached. Here we just
2602 determine how much space we will need for them. */
2603 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2604 if (sym_ptr_ptr != NULL)
2605 {
2606 asymbol **sym_end;
2607
2608 sym_end = sym_ptr_ptr + bfd_get_symcount (abfd);
2609 for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++)
2610 {
2611 if (((*sym_ptr_ptr)->flags & BSF_DEBUGGING) == 0
2612 && ((*sym_ptr_ptr)->flags & BSF_LOCAL) == 0)
2613 {
2614 ++symhdr->iextMax;
2615 symhdr->issExtMax += strlen ((*sym_ptr_ptr)->name) + 1;
2616 }
2617 }
2618 }
2619
2620 /* Adjust the counts so that structures are longword aligned. */
2621 debug_align = backend->debug_align;
2622 --debug_align;
2623 symhdr->cbLine = (symhdr->cbLine + debug_align) &~ debug_align;
2624 symhdr->issMax = (symhdr->issMax + debug_align) &~ debug_align;
2625 symhdr->issExtMax = (symhdr->issExtMax + debug_align) &~ debug_align;
2626
2627 /* Now the counts in symhdr are the correct size for the debugging
2628 information. We allocate the right amount of space, and reset
2629 the counts so that the second pass can use them as indices. It
2630 would be possible to output the debugging information directly to
2631 the file in pass 2, rather than to build it in memory and then
2632 write it out. Outputting to the file would require a lot of
2633 seeks and small writes, though, and I think this approach is
2634 faster. */
2635 size = (symhdr->cbLine * sizeof (unsigned char)
2636 + symhdr->idnMax * backend->external_dnr_size
2637 + symhdr->ipdMax * backend->external_pdr_size
2638 + symhdr->isymMax * backend->external_sym_size
2639 + symhdr->ioptMax * backend->external_opt_size
2640 + symhdr->iauxMax * sizeof (union aux_ext)
2641 + symhdr->issMax * sizeof (char)
2642 + symhdr->issExtMax * sizeof (char)
2643 + symhdr->ifdMax * backend->external_fdr_size
2644 + symhdr->crfd * backend->external_rfd_size
2645 + symhdr->iextMax * backend->external_ext_size);
2646 raw = (char *) bfd_alloc (abfd, size);
2647 if (raw == (char *) NULL)
2648 {
2649 bfd_error = no_memory;
2650 return false;
2651 }
2652 ecoff_data (abfd)->raw_size = size;
2653 ecoff_data (abfd)->raw_syments = (PTR) raw;
2654
2655 /* Initialize the raw pointers. */
2656#define SET(field, count, type, size) \
2657 ecoff_data (abfd)->field = (type) raw; \
2658 raw += symhdr->count * size
2659
2660 SET (line, cbLine, unsigned char *, sizeof (unsigned char));
2661 SET (external_dnr, idnMax, PTR, backend->external_dnr_size);
2662 SET (external_pdr, ipdMax, PTR, backend->external_pdr_size);
2663 SET (external_sym, isymMax, PTR, backend->external_sym_size);
2664 SET (external_opt, ioptMax, PTR, backend->external_opt_size);
2665 SET (external_aux, iauxMax, union aux_ext *, sizeof (union aux_ext));
2666 SET (ss, issMax, char *, sizeof (char));
2667 SET (ssext, issExtMax, char *, sizeof (char));
2668 SET (external_fdr, ifdMax, PTR, backend->external_fdr_size);
2669 SET (external_rfd, crfd, PTR, backend->external_rfd_size);
2670 SET (external_ext, iextMax, PTR, backend->external_ext_size);
2671#undef SET
2672
2673 /* Reset the counts so the second pass can use them to know how far
2674 it has gotten. */
2675 symhdr->ilineMax = 0;
2676 symhdr->cbLine = 0;
2677 symhdr->idnMax = 0;
2678 symhdr->ipdMax = 0;
2679 symhdr->isymMax = 0;
2680 symhdr->ioptMax = 0;
2681 symhdr->iauxMax = 0;
2682 symhdr->issMax = 0;
2683 symhdr->issExtMax = 0;
2684 symhdr->ifdMax = 0;
2685 symhdr->crfd = 0;
2686 symhdr->iextMax = 0;
2687
2688 /* Do the second pass: accumulate the debugging information. */
2689 ecoff_clear_output_flags (abfd);
2690 for (ipass = 0; ipass < 2; ipass++)
2691 {
2692 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2693 {
2694 if (((o->flags & SEC_CODE) == 0) != ipass)
2695 continue;
2696 for (p = o->seclets_head;
2697 p != (bfd_seclet_type *) NULL;
2698 p = p->next)
2699 {
2700 if (p->type == bfd_indirect_seclet)
2701 {
2702 if (ecoff_get_debug (abfd, p, o, relocateable) == false)
2703 return false;
2704 }
2705 }
2706 }
2707 }
2708
2709 /* Put in the external symbols. */
2710 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2711 if (sym_ptr_ptr != NULL)
2712 {
2713 const bfd_size_type external_ext_size = backend->external_ext_size;
2714 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
2715 = backend->swap_ext_in;
2716 void (* const swap_ext_out) PARAMS ((bfd *, const EXTR *, PTR))
2717 = backend->swap_ext_out;
2718 char *ssext;
2719 char *external_ext;
2720
2721 ssext = ecoff_data (abfd)->ssext;
2722 external_ext = (char *) ecoff_data (abfd)->external_ext;
2723 for (; *sym_ptr_ptr != NULL; sym_ptr_ptr++)
2724 {
2725 asymbol *sym_ptr;
2726 EXTR esym;
2727
2728 sym_ptr = *sym_ptr_ptr;
2729
2730 if ((sym_ptr->flags & BSF_DEBUGGING) != 0
2731 || (sym_ptr->flags & BSF_LOCAL) != 0)
2732 continue;
2733
2734 /* The native pointer can be NULL for a symbol created by
2735 the linker via ecoff_make_empty_symbol. */
2736 if (bfd_asymbol_flavour (sym_ptr) != bfd_target_ecoff_flavour
2737 || ecoffsymbol (sym_ptr)->native == NULL)
2738 {
2739 esym.jmptbl = 0;
2740 esym.cobol_main = 0;
2741 esym.weakext = 0;
2742 esym.reserved = 0;
2743 esym.ifd = ifdNil;
2744 /* FIXME: we can do better than this for st and sc. */
2745 esym.asym.st = stGlobal;
2746 esym.asym.sc = scAbs;
2747 esym.asym.reserved = 0;
2748 esym.asym.index = indexNil;
2749 }
2750 else
2751 {
2752 ecoff_symbol_type *ecoff_sym_ptr;
2753
2754 ecoff_sym_ptr = ecoffsymbol (sym_ptr);
2755 if (ecoff_sym_ptr->local)
2756 abort ();
2757 (*swap_ext_in) (abfd, ecoff_sym_ptr->native, &esym);
2758
2759 /* If we're producing an executable, move common symbols
2760 into bss. */
2761 if (relocateable == false)
2762 {
2763 if (esym.asym.sc == scCommon)
2764 esym.asym.sc = scBss;
2765 else if (esym.asym.sc == scSCommon)
2766 esym.asym.sc = scSBss;
2767 }
2768
2769 /* Adjust the FDR index for the symbol by that used for
2770 the input BFD. */
2771 esym.ifd += ecoff_data (bfd_asymbol_bfd (sym_ptr))->ifdbase;
2772 }
2773
2774 esym.asym.iss = symhdr->issExtMax;
2775
2776 if (bfd_is_com_section (sym_ptr->section)
2777 || sym_ptr->section == &bfd_und_section)
2778 esym.asym.value = sym_ptr->value;
2779 else
2780 esym.asym.value = (sym_ptr->value
2781 + sym_ptr->section->output_offset
2782 + sym_ptr->section->output_section->vma);
2783
2784 (*swap_ext_out) (abfd, &esym, external_ext);
2785
2786 ecoff_set_sym_index (sym_ptr, symhdr->iextMax);
2787
2788 external_ext += external_ext_size;
2789 ++symhdr->iextMax;
2790
2791 strcpy (ssext + symhdr->issExtMax, sym_ptr->name);
2792 symhdr->issExtMax += strlen (sym_ptr->name) + 1;
2793 }
2794 }
2795
2796 /* Adjust the counts so that structures are longword aligned. */
2797 symhdr->cbLine = (symhdr->cbLine + debug_align) &~ debug_align;
2798 symhdr->issMax = (symhdr->issMax + debug_align) &~ debug_align;
2799 symhdr->issExtMax = (symhdr->issExtMax + debug_align) &~ debug_align;
2800
2801 return true;
2802}
2803\f
2804/* Set the architecture. The supported architecture is stored in the
2805 backend pointer. We always set the architecture anyhow, since many
2806 callers ignore the return value. */
2807
2808boolean
2809ecoff_set_arch_mach (abfd, arch, machine)
2810 bfd *abfd;
2811 enum bfd_architecture arch;
2812 unsigned long machine;
2813{
2814 bfd_default_set_arch_mach (abfd, arch, machine);
2815 return arch == ecoff_backend (abfd)->arch;
2816}
2817
2818/* Get the size of the section headers. We do not output the .scommon
2819 section which we created in ecoff_mkobject. */
2820
2821int
2822ecoff_sizeof_headers (abfd, reloc)
2823 bfd *abfd;
2824 boolean reloc;
2825{
2826 return (bfd_coff_filhsz (abfd)
2827 + bfd_coff_aoutsz (abfd)
2828 + (abfd->section_count - 1) * bfd_coff_scnhsz (abfd));
2829}
2830
2831/* Calculate the file position for each section, and set
2832 reloc_filepos. */
2833
2834static void
2835ecoff_compute_section_file_positions (abfd)
2836 bfd *abfd;
2837{
2838 asection *current;
2839 file_ptr sofar;
2840 file_ptr old_sofar;
2841 boolean first_data;
2842
2843 if (bfd_get_start_address (abfd))
2844 abfd->flags |= EXEC_P;
2845
2846 sofar = ecoff_sizeof_headers (abfd, false);
2847
2848 first_data = true;
2849 for (current = abfd->sections;
2850 current != (asection *) NULL;
2851 current = current->next)
2852 {
2853 /* Only deal with sections which have contents */
2854 if (! (current->flags & SEC_HAS_CONTENTS)
2855 || strcmp (current->name, SCOMMON) == 0)
2856 continue;
2857
2858 /* On Ultrix, the data sections in an executable file must be
2859 aligned to a page boundary within the file. This does not
2860 affect the section size, though. FIXME: Does this work for
2861 other platforms? */
2862 if ((abfd->flags & EXEC_P) != 0
2863 && (abfd->flags & D_PAGED) != 0
2864 && first_data != false
2865 && (current->flags & SEC_CODE) == 0)
2866 {
2867 const bfd_vma round = ecoff_backend (abfd)->round;
2868
2869 sofar = (sofar + round - 1) &~ (round - 1);
2870 first_data = false;
2871 }
2872
2873 /* Align the sections in the file to the same boundary on
2874 which they are aligned in virtual memory. */
2875 old_sofar = sofar;
2876 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2877
2878 current->filepos = sofar;
2879
2880 sofar += current->_raw_size;
2881
2882 /* make sure that this section is of the right size too */
2883 old_sofar = sofar;
2884 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2885 current->_raw_size += sofar - old_sofar;
2886 }
2887
2888 ecoff_data (abfd)->reloc_filepos = sofar;
2889}
2890
2891/* Set the contents of a section. */
2892
2893boolean
2894ecoff_set_section_contents (abfd, section, location, offset, count)
2895 bfd *abfd;
2896 asection *section;
2897 PTR location;
2898 file_ptr offset;
2899 bfd_size_type count;
2900{
2901 if (abfd->output_has_begun == false)
2902 ecoff_compute_section_file_positions (abfd);
2903
2904 bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
2905
2906 if (count != 0)
2907 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
2908
2909 return true;
2910}
2911
2912/* Write out an ECOFF file. */
2913
2914boolean
2915ecoff_write_object_contents (abfd)
2916 bfd *abfd;
2917{
2918 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
2919 const bfd_vma round = backend->round;
2920 const bfd_size_type filhsz = bfd_coff_filhsz (abfd);
2921 const bfd_size_type aoutsz = bfd_coff_aoutsz (abfd);
2922 const bfd_size_type scnhsz = bfd_coff_scnhsz (abfd);
2923 const bfd_size_type external_hdr_size = backend->external_hdr_size;
2924 const bfd_size_type external_reloc_size = backend->external_reloc_size;
2925 void (* const swap_reloc_out) PARAMS ((bfd *,
2926 const struct internal_reloc *,
2927 PTR))
2928 = backend->swap_reloc_out;
2929 asection *current;
2930 unsigned int count;
2931 file_ptr scn_base;
2932 file_ptr reloc_base;
2933 file_ptr sym_base;
2934 unsigned long reloc_size;
2935 unsigned long text_size;
2936 unsigned long text_start;
2937 unsigned long data_size;
2938 unsigned long data_start;
2939 unsigned long bss_size;
2940 PTR buff;
2941 struct internal_filehdr internal_f;
2942 struct internal_aouthdr internal_a;
2943 int i;
2944
2945 bfd_error = system_call_error;
2946
2947 if(abfd->output_has_begun == false)
2948 ecoff_compute_section_file_positions(abfd);
2949
2950 if (abfd->sections != (asection *) NULL)
2951 scn_base = abfd->sections->filepos;
2952 else
2953 scn_base = 0;
2954 reloc_base = ecoff_data (abfd)->reloc_filepos;
2955
2956 count = 1;
2957 reloc_size = 0;
2958 for (current = abfd->sections;
2959 current != (asection *)NULL;
2960 current = current->next)
2961 {
2962 if (strcmp (current->name, SCOMMON) == 0)
2963 continue;
2964 current->target_index = count;
2965 ++count;
2966 if (current->reloc_count != 0)
2967 {
2968 bfd_size_type relsize;
2969
2970 current->rel_filepos = reloc_base;
2971 relsize = current->reloc_count * external_reloc_size;
2972 reloc_size += relsize;
2973 reloc_base += relsize;
2974 }
2975 else
2976 current->rel_filepos = 0;
2977 }
2978
2979 sym_base = reloc_base + reloc_size;
2980
2981 /* At least on Ultrix, the symbol table of an executable file must
2982 be aligned to a page boundary. FIXME: Is this true on other
2983 platforms? */
2984 if ((abfd->flags & EXEC_P) != 0
2985 && (abfd->flags & D_PAGED) != 0)
2986 sym_base = (sym_base + round - 1) &~ (round - 1);
2987
2988 ecoff_data (abfd)->sym_filepos = sym_base;
2989
2990 if ((abfd->flags & D_PAGED) != 0)
2991 text_size = ecoff_sizeof_headers (abfd, false);
2992 else
2993 text_size = 0;
2994 text_start = 0;
2995 data_size = 0;
2996 data_start = 0;
2997 bss_size = 0;
2998
2999 /* Write section headers to the file. */
3000
3001 buff = (PTR) alloca (scnhsz);
3002 internal_f.f_nscns = 0;
3003 if (bfd_seek (abfd, (file_ptr) (filhsz + aoutsz), SEEK_SET) != 0)
3004 return false;
3005 for (current = abfd->sections;
3006 current != (asection *) NULL;
3007 current = current->next)
3008 {
3009 struct internal_scnhdr section;
3010 bfd_vma vma;
3011
3012 if (strcmp (current->name, SCOMMON) == 0)
3013 {
3014 BFD_ASSERT (bfd_get_section_size_before_reloc (current) == 0
3015 && current->reloc_count == 0);
3016 continue;
3017 }
3018
3019 ++internal_f.f_nscns;
3020
3021 strncpy (section.s_name, current->name, sizeof section.s_name);
3022
3023 /* FIXME: is this correct for shared libraries? I think it is
3024 but I have no platform to check. Ian Lance Taylor. */
3025 vma = bfd_get_section_vma (abfd, current);
3026 if (strcmp (current->name, _LIB) == 0)
3027 section.s_vaddr = 0;
3028 else
3029 section.s_vaddr = vma;
3030
3031 section.s_paddr = vma;
3032 section.s_size = bfd_get_section_size_before_reloc (current);
3033
3034 /* If this section has no size or is unloadable then the scnptr
3035 will be 0 too. */
3036 if (current->_raw_size == 0
3037 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3038 section.s_scnptr = 0;
3039 else
3040 section.s_scnptr = current->filepos;
3041 section.s_relptr = current->rel_filepos;
3042
3043 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3044 object file produced by the assembler is supposed to point to
3045 information about how much room is required by objects of
3046 various different sizes. I think this only matters if we
3047 want the linker to compute the best size to use, or
3048 something. I don't know what happens if the information is
3049 not present. */
3050 section.s_lnnoptr = 0;
3051
3052 section.s_nreloc = current->reloc_count;
3053 section.s_nlnno = 0;
3054 section.s_flags = ecoff_sec_to_styp_flags (current->name,
3055 current->flags);
3056
3057 bfd_coff_swap_scnhdr_out (abfd, (PTR) &section, buff);
3058 if (bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
3059 return false;
3060
3061 if ((section.s_flags & STYP_TEXT) != 0)
3062 {
3063 text_size += bfd_get_section_size_before_reloc (current);
3064 if (text_start == 0 || text_start > vma)
3065 text_start = vma;
3066 }
3067 else if ((section.s_flags & STYP_RDATA) != 0
3068 || (section.s_flags & STYP_DATA) != 0
3069 || (section.s_flags & STYP_LIT8) != 0
3070 || (section.s_flags & STYP_LIT4) != 0
3071 || (section.s_flags & STYP_SDATA) != 0)
3072 {
3073 data_size += bfd_get_section_size_before_reloc (current);
3074 if (data_start == 0 || data_start > vma)
3075 data_start = vma;
3076 }
3077 else if ((section.s_flags & STYP_BSS) != 0
3078 || (section.s_flags & STYP_SBSS) != 0)
3079 bss_size += bfd_get_section_size_before_reloc (current);
3080 }
3081
3082 /* Set up the file header. */
3083
3084 if (abfd->xvec->header_byteorder_big_p != false)
3085 internal_f.f_magic = backend->big_magic;
3086 else
3087 internal_f.f_magic = backend->little_magic;
3088
3089 /* We will NOT put a fucking timestamp in the header here. Every
3090 time you put it back, I will come in and take it out again. I'm
3091 sorry. This field does not belong here. We fill it with a 0 so
3092 it compares the same but is not a reasonable time. --
3093 gnu@cygnus.com. */
3094 internal_f.f_timdat = 0;
3095
3096 if (bfd_get_symcount (abfd) != 0)
3097 {
3098 /* The ECOFF f_nsyms field is not actually the number of
3099 symbols, it's the size of symbolic information header. */
3100 internal_f.f_nsyms = external_hdr_size;
3101 internal_f.f_symptr = sym_base;
3102 }
3103 else
3104 {
3105 internal_f.f_nsyms = 0;
3106 internal_f.f_symptr = 0;
3107 }
3108
3109 internal_f.f_opthdr = aoutsz;
3110
3111 internal_f.f_flags = F_LNNO;
3112 if (reloc_size == 0)
3113 internal_f.f_flags |= F_RELFLG;
3114 if (bfd_get_symcount (abfd) == 0)
3115 internal_f.f_flags |= F_LSYMS;
3116 if (abfd->flags & EXEC_P)
3117 internal_f.f_flags |= F_EXEC;
3118
3119 if (! abfd->xvec->byteorder_big_p)
3120 internal_f.f_flags |= F_AR32WR;
3121 else
3122 internal_f.f_flags |= F_AR32W;
3123
3124 /* Set up the ``optional'' header. */
3125 if ((abfd->flags & D_PAGED) != 0)
3126 internal_a.magic = ECOFF_AOUT_ZMAGIC;
3127 else
3128 internal_a.magic = ECOFF_AOUT_OMAGIC;
3129
3130 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3131 linker happy. But, is it right? */
3132 internal_a.vstamp = 0x20a;
3133
3134 /* At least on Ultrix, these have to be rounded to page boundaries.
3135 FIXME: Is this true on other platforms? */
3136 if ((abfd->flags & D_PAGED) != 0)
3137 {
3138 internal_a.tsize = (text_size + round - 1) &~ (round - 1);
3139 internal_a.text_start = text_start &~ (round - 1);
3140 internal_a.dsize = (data_size + round - 1) &~ (round - 1);
3141 internal_a.data_start = data_start &~ (round - 1);
3142 }
3143 else
3144 {
3145 internal_a.tsize = text_size;
3146 internal_a.text_start = text_start;
3147 internal_a.dsize = data_size;
3148 internal_a.data_start = data_start;
3149 }
3150
3151 /* On Ultrix, the initial portions of the .sbss and .bss segments
3152 are at the end of the data section. The bsize field in the
3153 optional header records how many bss bytes are required beyond
3154 those in the data section. The value is not rounded to a page
3155 boundary. */
3156 if (bss_size < internal_a.dsize - data_size)
3157 bss_size = 0;
3158 else
3159 bss_size -= internal_a.dsize - data_size;
3160 internal_a.bsize = bss_size;
3161 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
3162
3163 internal_a.entry = bfd_get_start_address (abfd);
3164
3165 internal_a.gp_value = ecoff_data (abfd)->gp;
3166
3167 internal_a.gprmask = ecoff_data (abfd)->gprmask;
48edba81 3168 internal_a.fprmask = ecoff_data (abfd)->fprmask;
dae31cf5
ILT
3169 for (i = 0; i < 4; i++)
3170 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
3171
3172 /* Write out the file header and the optional header. */
3173
3174 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3175 return false;
3176
3177 buff = (PTR) alloca (filhsz);
3178 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, buff);
3179 if (bfd_write (buff, 1, filhsz, abfd) != filhsz)
3180 return false;
3181
3182 buff = (PTR) alloca (aoutsz);
3183 bfd_coff_swap_aouthdr_out (abfd, (PTR) &internal_a, buff);
3184 if (bfd_write (buff, 1, aoutsz, abfd) != aoutsz)
3185 return false;
3186
3187 /* Write out the relocs. */
3188 for (current = abfd->sections;
3189 current != (asection *) NULL;
3190 current = current->next)
3191 {
3192 arelent **reloc_ptr_ptr;
3193 arelent **reloc_end;
3194 char *out_ptr;
3195
3196 if (current->reloc_count == 0)
3197 continue;
3198
3199 buff = bfd_alloc (abfd, current->reloc_count * external_reloc_size);
3200 if (buff == NULL)
3201 {
3202 bfd_error = no_memory;
3203 return false;
3204 }
3205
3206 reloc_ptr_ptr = current->orelocation;
3207 reloc_end = reloc_ptr_ptr + current->reloc_count;
3208 out_ptr = (char *) buff;
3209 for (;
3210 reloc_ptr_ptr < reloc_end;
3211 reloc_ptr_ptr++, out_ptr += external_reloc_size)
3212 {
3213 arelent *reloc;
3214 asymbol *sym;
3215 struct internal_reloc in;
3216
3217 memset (&in, 0, sizeof in);
3218
3219 reloc = *reloc_ptr_ptr;
3220 sym = *reloc->sym_ptr_ptr;
3221
dae31cf5
ILT
3222 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
3223 in.r_type = reloc->howto->type;
3224
dae31cf5
ILT
3225 if ((sym->flags & BSF_SECTION_SYM) == 0)
3226 {
3227 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
3228 in.r_extern = 1;
3229 }
3230 else
3231 {
3232 CONST char *name;
3233
3234 name = bfd_get_section_name (abfd, bfd_get_section (sym));
3235 if (strcmp (name, ".text") == 0)
3236 in.r_symndx = RELOC_SECTION_TEXT;
3237 else if (strcmp (name, ".rdata") == 0)
3238 in.r_symndx = RELOC_SECTION_RDATA;
3239 else if (strcmp (name, ".data") == 0)
3240 in.r_symndx = RELOC_SECTION_DATA;
3241 else if (strcmp (name, ".sdata") == 0)
3242 in.r_symndx = RELOC_SECTION_SDATA;
3243 else if (strcmp (name, ".sbss") == 0)
3244 in.r_symndx = RELOC_SECTION_SBSS;
3245 else if (strcmp (name, ".bss") == 0)
3246 in.r_symndx = RELOC_SECTION_BSS;
3247 else if (strcmp (name, ".init") == 0)
3248 in.r_symndx = RELOC_SECTION_INIT;
3249 else if (strcmp (name, ".lit8") == 0)
3250 in.r_symndx = RELOC_SECTION_LIT8;
3251 else if (strcmp (name, ".lit4") == 0)
3252 in.r_symndx = RELOC_SECTION_LIT4;
3253 else
3254 abort ();
3255 in.r_extern = 0;
3256 }
3257
3258 (*swap_reloc_out) (abfd, &in, (PTR) out_ptr);
3259 }
3260
3261 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3262 return false;
3263 if (bfd_write (buff, external_reloc_size, current->reloc_count, abfd)
3264 != external_reloc_size * current->reloc_count)
3265 return false;
3266 bfd_release (abfd, buff);
3267 }
3268
3269 /* Write out the symbolic debugging information. */
3270 if (bfd_get_symcount (abfd) > 0)
3271 {
3272 HDRR *symhdr;
3273 unsigned long sym_offset;
3274
3275 /* Set up the offsets in the symbolic header. */
3276 symhdr = &ecoff_data (abfd)->symbolic_header;
3277 sym_offset = ecoff_data (abfd)->sym_filepos + external_hdr_size;
3278
3279#define SET(offset, size, ptr) \
3280 if (symhdr->size == 0) \
3281 symhdr->offset = 0; \
3282 else \
3283 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3284 - (char *) ecoff_data (abfd)->raw_syments) \
3285 + sym_offset);
3286
3287 SET (cbLineOffset, cbLine, line);
3288 SET (cbDnOffset, idnMax, external_dnr);
3289 SET (cbPdOffset, ipdMax, external_pdr);
3290 SET (cbSymOffset, isymMax, external_sym);
3291 SET (cbOptOffset, ioptMax, external_opt);
3292 SET (cbAuxOffset, iauxMax, external_aux);
3293 SET (cbSsOffset, issMax, ss);
3294 SET (cbSsExtOffset, issExtMax, ssext);
3295 SET (cbFdOffset, ifdMax, external_fdr);
3296 SET (cbRfdOffset, crfd, external_rfd);
3297 SET (cbExtOffset, iextMax, external_ext);
3298#undef SET
3299
3300 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos,
3301 SEEK_SET) != 0)
3302 return false;
3303 buff = (PTR) alloca (external_hdr_size);
3304 (*backend->swap_hdr_out) (abfd, &ecoff_data (abfd)->symbolic_header,
3305 buff);
3306 if (bfd_write (buff, 1, external_hdr_size, abfd) != external_hdr_size)
3307 return false;
3308 if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1,
3309 ecoff_data (abfd)->raw_size, abfd)
3310 != ecoff_data (abfd)->raw_size)
3311 return false;
3312 }
3313 else if ((abfd->flags & EXEC_P) != 0
3314 && (abfd->flags & D_PAGED) != 0)
3315 {
3316 char c;
3317
3318 /* A demand paged executable must occupy an even number of
3319 pages. */
3320 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
3321 SEEK_SET) != 0)
3322 return false;
3323 if (bfd_read (&c, 1, 1, abfd) == 0)
3324 c = 0;
3325 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
3326 SEEK_SET) != 0)
3327 return false;
3328 if (bfd_write (&c, 1, 1, abfd) != 1)
3329 return false;
3330 }
3331
3332 return true;
3333}
3334\f
3335/* Archive handling. ECOFF uses what appears to be a unique type of
3336 archive header (which I call an armap). The byte ordering of the
3337 armap and the contents are encoded in the name of the armap itself.
3338 At least for now, we only support archives with the same byte
3339 ordering in the armap and the contents.
3340
3341 The first four bytes in the armap are the number of symbol
3342 definitions. This is always a power of two.
3343
3344 This is followed by the symbol definitions. Each symbol definition
3345 occupies 8 bytes. The first four bytes are the offset from the
3346 start of the armap strings to the null-terminated string naming
3347 this symbol. The second four bytes are the file offset to the
3348 archive member which defines this symbol. If the second four bytes
3349 are 0, then this is not actually a symbol definition, and it should
3350 be ignored.
3351
3352 The symbols are hashed into the armap with a closed hashing scheme.
3353 See the functions below for the details of the algorithm.
3354
3355 We could use the hash table when looking up symbols in a library.
3356 This would require a new BFD target entry point to replace the
3357 bfd_get_next_mapent function used by the linker.
3358
3359 After the symbol definitions comes four bytes holding the size of
3360 the string table, followed by the string table itself. */
3361
3362/* The name of an archive headers looks like this:
3363 __________E[BL]E[BL]_ (with a trailing space).
3364 The trailing space is changed to an X if the archive is changed to
48edba81
ILT
3365 indicate that the armap is out of date.
3366
3367 The Alpha seems to use ________64E[BL]E[BL]_. */
dae31cf5
ILT
3368
3369#define ARMAP_BIG_ENDIAN 'B'
3370#define ARMAP_LITTLE_ENDIAN 'L'
3371#define ARMAP_MARKER 'E'
48edba81 3372#define ARMAP_START_LENGTH 10
dae31cf5
ILT
3373#define ARMAP_HEADER_MARKER_INDEX 10
3374#define ARMAP_HEADER_ENDIAN_INDEX 11
3375#define ARMAP_OBJECT_MARKER_INDEX 12
3376#define ARMAP_OBJECT_ENDIAN_INDEX 13
3377#define ARMAP_END_INDEX 14
3378#define ARMAP_END "_ "
3379
3380/* This is a magic number used in the hashing algorithm. */
3381#define ARMAP_HASH_MAGIC 0x9dd68ab5
3382
3383/* This returns the hash value to use for a string. It also sets
3384 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3385 is the number of entries in the hash table, and HLOG is the log
3386 base 2 of SIZE. */
3387
3388static unsigned int
3389ecoff_armap_hash (s, rehash, size, hlog)
3390 CONST char *s;
3391 unsigned int *rehash;
3392 unsigned int size;
3393 unsigned int hlog;
3394{
3395 unsigned int hash;
3396
3397 hash = *s++;
3398 while (*s != '\0')
3399 hash = ((hash >> 27) | (hash << 5)) + *s++;
3400 hash *= ARMAP_HASH_MAGIC;
3401 *rehash = (hash & (size - 1)) | 1;
3402 return hash >> (32 - hlog);
3403}
3404
3405/* Read in the armap. */
3406
3407boolean
3408ecoff_slurp_armap (abfd)
3409 bfd *abfd;
3410{
3411 char nextname[17];
3412 unsigned int i;
3413 struct areltdata *mapdata;
3414 bfd_size_type parsed_size;
3415 char *raw_armap;
3416 struct artdata *ardata;
3417 unsigned int count;
3418 char *raw_ptr;
3419 struct symdef *symdef_ptr;
3420 char *stringbase;
3421
3422 /* Get the name of the first element. */
3423 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3424 if (i == 0)
3425 return true;
3426 if (i != 16)
3427 return false;
3428
3429 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
3430
8c11363a
ILT
3431 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3432 standard COFF armap. We could move the ECOFF armap stuff into
3433 bfd_slurp_armap, but that seems inappropriate since no other
3434 target uses this format. Instead, we check directly for a COFF
3435 armap. */
3436 if (strncmp (nextname, "/ ", 16) == 0)
3437 return bfd_slurp_armap (abfd);
3438
dae31cf5 3439 /* See if the first element is an armap. */
48edba81
ILT
3440 if (strncmp (nextname, ecoff_backend (abfd)->armap_start,
3441 ARMAP_START_LENGTH) != 0
dae31cf5
ILT
3442 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3443 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3444 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3445 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3446 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3447 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3448 || strncmp (nextname + ARMAP_END_INDEX,
3449 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3450 {
3451 bfd_has_map (abfd) = false;
3452 return true;
3453 }
3454
3455 /* Make sure we have the right byte ordering. */
3456 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3457 ^ (abfd->xvec->header_byteorder_big_p != false))
3458 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3459 ^ (abfd->xvec->byteorder_big_p != false)))
3460 {
3461 bfd_error = wrong_format;
3462 return false;
3463 }
3464
3465 /* Read in the armap. */
3466 ardata = bfd_ardata (abfd);
3467 mapdata = snarf_ar_hdr (abfd);
3468 if (mapdata == (struct areltdata *) NULL)
3469 return false;
3470 parsed_size = mapdata->parsed_size;
3471 bfd_release (abfd, (PTR) mapdata);
3472
3473 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3474 if (raw_armap == (char *) NULL)
3475 {
3476 bfd_error = no_memory;
3477 return false;
3478 }
3479
3480 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3481 {
3482 bfd_error = malformed_archive;
3483 bfd_release (abfd, (PTR) raw_armap);
3484 return false;
3485 }
3486
3487 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3488
3489 ardata->symdef_count = 0;
3490 ardata->cache = (struct ar_cache *) NULL;
3491
48edba81
ILT
3492 /* This code used to overlay the symdefs over the raw archive data,
3493 but that doesn't work on a 64 bit host. */
3494
3036933a 3495 stringbase = raw_armap + count * (2 * LONG_SIZE) + 2 * LONG_SIZE;
dae31cf5
ILT
3496
3497#ifdef CHECK_ARMAP_HASH
3498 {
3499 unsigned int hlog;
3500
3501 /* Double check that I have the hashing algorithm right by making
3502 sure that every symbol can be looked up successfully. */
3503 hlog = 0;
3504 for (i = 1; i < count; i <<= 1)
3505 hlog++;
3506 BFD_ASSERT (i == count);
3507
48edba81 3508 raw_ptr = raw_armap + LONG_SIZE;
dae31cf5
ILT
3509 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3510 {
3511 unsigned int name_offset, file_offset;
3512 unsigned int hash, rehash, srch;
3513
3514 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3515 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3516 if (file_offset == 0)
3517 continue;
3518 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3519 hlog);
3520 if (hash == i)
3521 continue;
3522
3523 /* See if we can rehash to this location. */
3524 for (srch = (hash + rehash) & (count - 1);
3525 srch != hash && srch != i;
3526 srch = (srch + rehash) & (count - 1))
3527 BFD_ASSERT (bfd_h_get_32 (abfd,
3528 (PTR) (raw_armap
3529 + LONG_SIZE
3530 + (srch * 2 * LONG_SIZE)
3531 + LONG_SIZE))
3532 != 0);
3533 BFD_ASSERT (srch == i);
3534 }
3535 }
3536
dae31cf5
ILT
3537#endif /* CHECK_ARMAP_HASH */
3538
48edba81
ILT
3539 raw_ptr = raw_armap + LONG_SIZE;
3540 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3541 if (bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE)) != 0)
3542 ++ardata->symdef_count;
3543
3544 symdef_ptr = ((struct symdef *)
3545 bfd_alloc (abfd,
3546 ardata->symdef_count * sizeof (struct symdef)));
3547 ardata->symdefs = (carsym *) symdef_ptr;
3548
3549 raw_ptr = raw_armap + LONG_SIZE;
dae31cf5
ILT
3550 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3551 {
3552 unsigned int name_offset, file_offset;
3553
dae31cf5
ILT
3554 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3555 if (file_offset == 0)
3556 continue;
48edba81 3557 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
dae31cf5
ILT
3558 symdef_ptr->s.name = stringbase + name_offset;
3559 symdef_ptr->file_offset = file_offset;
3560 ++symdef_ptr;
dae31cf5
ILT
3561 }
3562
3563 ardata->first_file_filepos = bfd_tell (abfd);
3564 /* Pad to an even boundary. */
3565 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3566
3567 bfd_has_map (abfd) = true;
3568
3569 return true;
3570}
3571
3572/* Write out an armap. */
3573
3574boolean
3575ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3576 bfd *abfd;
3577 unsigned int elength;
3578 struct orl *map;
3579 unsigned int orl_count;
3580 int stridx;
3581{
3582 unsigned int hashsize, hashlog;
3583 unsigned int symdefsize;
3584 int padit;
3585 unsigned int stringsize;
3586 unsigned int mapsize;
3587 file_ptr firstreal;
3588 struct ar_hdr hdr;
3589 struct stat statbuf;
3590 unsigned int i;
3591 bfd_byte temp[LONG_SIZE];
3592 bfd_byte *hashtable;
3593 bfd *current;
3594 bfd *last_elt;
3595
3596 /* Ultrix appears to use as a hash table size the least power of two
3597 greater than twice the number of entries. */
3598 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3599 ;
3600 hashsize = 1 << hashlog;
3601
3602 symdefsize = hashsize * 2 * LONG_SIZE;
3603 padit = stridx % 2;
3604 stringsize = stridx + padit;
3605
3606 /* Include 8 bytes to store symdefsize and stringsize in output. */
3607 mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE;
3608
3609 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3610
3611 memset ((PTR) &hdr, 0, sizeof hdr);
3612
3613 /* Work out the ECOFF armap name. */
48edba81 3614 strcpy (hdr.ar_name, ecoff_backend (abfd)->armap_start);
dae31cf5
ILT
3615 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3616 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3617 (abfd->xvec->header_byteorder_big_p
3618 ? ARMAP_BIG_ENDIAN
3619 : ARMAP_LITTLE_ENDIAN);
3620 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3621 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3622 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3623 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3624
3625 /* Write the timestamp of the archive header to be just a little bit
3626 later than the timestamp of the file, otherwise the linker will
3627 complain that the index is out of date. Actually, the Ultrix
3628 linker just checks the archive name; the GNU linker may check the
3629 date. */
3630 stat (abfd->filename, &statbuf);
3631 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3632
3633 /* The DECstation uses zeroes for the uid, gid and mode of the
3634 armap. */
3635 hdr.ar_uid[0] = '0';
3636 hdr.ar_gid[0] = '0';
3637 hdr.ar_mode[0] = '0';
3638
3639 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3640
3641 hdr.ar_fmag[0] = '`';
3642 hdr.ar_fmag[1] = '\n';
3643
3644 /* Turn all null bytes in the header into spaces. */
3645 for (i = 0; i < sizeof (struct ar_hdr); i++)
3646 if (((char *)(&hdr))[i] == '\0')
3647 (((char *)(&hdr))[i]) = ' ';
3648
3649 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3650 != sizeof (struct ar_hdr))
3651 return false;
3652
3653 bfd_h_put_32 (abfd, hashsize, temp);
3654 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3655 return false;
3656
3657 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3658
3659 current = abfd->archive_head;
3660 last_elt = current;
3661 for (i = 0; i < orl_count; i++)
3662 {
3663 unsigned int hash, rehash;
3664
3665 /* Advance firstreal to the file position of this archive
3666 element. */
3667 if (((bfd *) map[i].pos) != last_elt)
3668 {
3669 do
3670 {
3671 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3672 firstreal += firstreal % 2;
3673 current = current->next;
3674 }
3675 while (current != (bfd *) map[i].pos);
3676 }
3677
3678 last_elt = current;
3679
3680 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3681 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3682 + (hash * 2 * LONG_SIZE)
3683 + LONG_SIZE))
3684 != 0)
3685 {
3686 unsigned int srch;
3687
3688 /* The desired slot is already taken. */
3689 for (srch = (hash + rehash) & (hashsize - 1);
3690 srch != hash;
3691 srch = (srch + rehash) & (hashsize - 1))
3692 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3693 + (srch * 2 * LONG_SIZE)
3694 + LONG_SIZE))
3695 == 0)
3696 break;
3697
3698 BFD_ASSERT (srch != hash);
3699
3700 hash = srch;
3701 }
3702
3703 bfd_h_put_32 (abfd, map[i].namidx,
3704 (PTR) (hashtable + hash * 2 * LONG_SIZE));
3705 bfd_h_put_32 (abfd, firstreal,
3706 (PTR) (hashtable + hash * 2 * LONG_SIZE + LONG_SIZE));
3707 }
3708
3709 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3710 return false;
3711
3712 bfd_release (abfd, hashtable);
3713
3714 /* Now write the strings. */
3715 bfd_h_put_32 (abfd, stringsize, temp);
3716 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3717 return false;
3718 for (i = 0; i < orl_count; i++)
3719 {
3720 bfd_size_type len;
3721
3722 len = strlen (*map[i].name) + 1;
3723 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3724 return false;
3725 }
3726
3727 /* The spec sez this should be a newline. But in order to be
3728 bug-compatible for DECstation ar we use a null. */
3729 if (padit)
3730 {
3731 if (bfd_write ("\0", 1, 1, abfd) != 1)
3732 return false;
3733 }
3734
3735 return true;
3736}
3737
3738/* See whether this BFD is an archive. If it is, read in the armap
3739 and the extended name table. */
3740
3741bfd_target *
3742ecoff_archive_p (abfd)
3743 bfd *abfd;
3744{
3745 char armag[SARMAG + 1];
3746
3747 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3748 || strncmp (armag, ARMAG, SARMAG) != 0)
3749 {
3750 bfd_error = wrong_format;
3751 return (bfd_target *) NULL;
3752 }
3753
3754 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3755 involves a cast, we can't do it as the left operand of
3756 assignment. */
3757 abfd->tdata.aout_ar_data =
3758 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3759
3760 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3761 {
3762 bfd_error = no_memory;
3763 return (bfd_target *) NULL;
3764 }
3765
3766 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3767
3768 if (ecoff_slurp_armap (abfd) == false
3769 || ecoff_slurp_extended_name_table (abfd) == false)
3770 {
3771 bfd_release (abfd, bfd_ardata (abfd));
3772 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3773 return (bfd_target *) NULL;
3774 }
3775
3776 return abfd->xvec;
3777}
This page took 0.162097 seconds and 4 git commands to generate.