1 /* Routines to link ECOFF debugging information.
2 Copyright 1993 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "aout/stab_gnu.h"
27 #include "coff/internal.h"
29 #include "coff/symconst.h"
30 #include "coff/ecoff.h"
32 static boolean ecoff_add_bytes PARAMS ((char **buf, char **bufend,
34 static struct bfd_hash_entry *string_hash_newfunc
35 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
37 static void ecoff_align_debug PARAMS ((bfd *abfd,
38 struct ecoff_debug_info *debug,
39 const struct ecoff_debug_swap *swap));
40 static boolean ecoff_write_symhdr PARAMS ((bfd *, struct ecoff_debug_info *,
41 const struct ecoff_debug_swap *,
43 static int cmp_fdrtab_entry PARAMS ((const PTR, const PTR));
44 static boolean mk_fdrtab PARAMS ((bfd *,
45 struct ecoff_debug_info * const,
46 const struct ecoff_debug_swap * const,
47 struct ecoff_find_line *));
48 static long fdrtab_lookup PARAMS ((struct ecoff_find_line *, bfd_vma));
50 /* Obstack allocation and deallocation routines. */
51 #define obstack_chunk_alloc malloc
52 #define obstack_chunk_free free
54 /* Routines to swap auxiliary information in and out. I am assuming
55 that the auxiliary information format is always going to be target
58 /* Swap in a type information record.
59 BIGEND says whether AUX symbols are big-endian or little-endian; this
60 info comes from the file header record (fh-fBigendian). */
63 _bfd_ecoff_swap_tir_in (bigend, ext_copy, intern)
65 const struct tir_ext *ext_copy;
68 struct tir_ext ext[1];
70 *ext = *ext_copy; /* Make it reasonable to do in-place. */
72 /* now the fun stuff... */
74 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
75 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
76 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
77 >> TIR_BITS1_BT_SH_BIG;
78 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
79 >> TIR_BITS_TQ4_SH_BIG;
80 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
81 >> TIR_BITS_TQ5_SH_BIG;
82 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
83 >> TIR_BITS_TQ0_SH_BIG;
84 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
85 >> TIR_BITS_TQ1_SH_BIG;
86 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
87 >> TIR_BITS_TQ2_SH_BIG;
88 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
89 >> TIR_BITS_TQ3_SH_BIG;
91 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
92 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
93 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
94 >> TIR_BITS1_BT_SH_LITTLE;
95 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
96 >> TIR_BITS_TQ4_SH_LITTLE;
97 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
98 >> TIR_BITS_TQ5_SH_LITTLE;
99 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
100 >> TIR_BITS_TQ0_SH_LITTLE;
101 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
102 >> TIR_BITS_TQ1_SH_LITTLE;
103 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
104 >> TIR_BITS_TQ2_SH_LITTLE;
105 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
106 >> TIR_BITS_TQ3_SH_LITTLE;
110 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
115 /* Swap out a type information record.
116 BIGEND says whether AUX symbols are big-endian or little-endian; this
117 info comes from the file header record (fh-fBigendian). */
120 _bfd_ecoff_swap_tir_out (bigend, intern_copy, ext)
122 const TIR *intern_copy;
127 *intern = *intern_copy; /* Make it reasonable to do in-place. */
129 /* now the fun stuff... */
131 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
132 | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
133 | ((intern->bt << TIR_BITS1_BT_SH_BIG)
134 & TIR_BITS1_BT_BIG));
135 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_BIG)
137 | ((intern->tq5 << TIR_BITS_TQ5_SH_BIG)
138 & TIR_BITS_TQ5_BIG));
139 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_BIG)
141 | ((intern->tq1 << TIR_BITS_TQ1_SH_BIG)
142 & TIR_BITS_TQ1_BIG));
143 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_BIG)
145 | ((intern->tq3 << TIR_BITS_TQ3_SH_BIG)
146 & TIR_BITS_TQ3_BIG));
148 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_LITTLE : 0)
149 | (intern->continued ? TIR_BITS1_CONTINUED_LITTLE : 0)
150 | ((intern->bt << TIR_BITS1_BT_SH_LITTLE)
151 & TIR_BITS1_BT_LITTLE));
152 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_LITTLE)
153 & TIR_BITS_TQ4_LITTLE)
154 | ((intern->tq5 << TIR_BITS_TQ5_SH_LITTLE)
155 & TIR_BITS_TQ5_LITTLE));
156 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_LITTLE)
157 & TIR_BITS_TQ0_LITTLE)
158 | ((intern->tq1 << TIR_BITS_TQ1_SH_LITTLE)
159 & TIR_BITS_TQ1_LITTLE));
160 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_LITTLE)
161 & TIR_BITS_TQ2_LITTLE)
162 | ((intern->tq3 << TIR_BITS_TQ3_SH_LITTLE)
163 & TIR_BITS_TQ3_LITTLE));
167 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
172 /* Swap in a relative symbol record. BIGEND says whether it is in
173 big-endian or little-endian format.*/
176 _bfd_ecoff_swap_rndx_in (bigend, ext_copy, intern)
178 const struct rndx_ext *ext_copy;
181 struct rndx_ext ext[1];
183 *ext = *ext_copy; /* Make it reasonable to do in-place. */
185 /* now the fun stuff... */
187 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
188 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
189 >> RNDX_BITS1_RFD_SH_BIG);
190 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
191 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
192 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
193 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
195 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
196 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
197 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
198 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
199 >> RNDX_BITS1_INDEX_SH_LITTLE)
200 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
201 | ((unsigned int) ext->r_bits[3]
202 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
206 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
211 /* Swap out a relative symbol record. BIGEND says whether it is in
212 big-endian or little-endian format.*/
215 _bfd_ecoff_swap_rndx_out (bigend, intern_copy, ext)
217 const RNDXR *intern_copy;
218 struct rndx_ext *ext;
222 *intern = *intern_copy; /* Make it reasonable to do in-place. */
224 /* now the fun stuff... */
226 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
227 ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
228 & RNDX_BITS1_RFD_BIG)
229 | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
230 & RNDX_BITS1_INDEX_BIG));
231 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
232 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
234 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
235 ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
236 & RNDX_BITS1_RFD_LITTLE)
237 | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
238 & RNDX_BITS1_INDEX_LITTLE));
239 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
240 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
244 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
249 /* The minimum amount of data to allocate. */
250 #define ALLOC_SIZE (4064)
252 /* Add bytes to a buffer. Return success. */
255 ecoff_add_bytes (buf, bufend, need)
264 have = *bufend - *buf;
270 if (want < ALLOC_SIZE)
274 newbuf = (char *) malloc (have + want);
276 newbuf = (char *) realloc (*buf, have + want);
279 bfd_set_error (bfd_error_no_memory);
283 *bufend = *buf + have + want;
287 /* We keep a hash table which maps strings to numbers. We use it to
288 map FDR names to indices in the output file, and to map local
289 strings when combining stabs debugging information. */
291 struct string_hash_entry
293 struct bfd_hash_entry root;
294 /* FDR index or string table offset. */
296 /* Next entry in string table. */
297 struct string_hash_entry *next;
300 struct string_hash_table
302 struct bfd_hash_table table;
305 /* Routine to create an entry in a string hash table. */
307 static struct bfd_hash_entry *
308 string_hash_newfunc (entry, table, string)
309 struct bfd_hash_entry *entry;
310 struct bfd_hash_table *table;
313 struct string_hash_entry *ret = (struct string_hash_entry *) entry;
315 /* Allocate the structure if it has not already been allocated by a
317 if (ret == (struct string_hash_entry *) NULL)
318 ret = ((struct string_hash_entry *)
319 bfd_hash_allocate (table, sizeof (struct string_hash_entry)));
320 if (ret == (struct string_hash_entry *) NULL)
322 bfd_set_error (bfd_error_no_memory);
326 /* Call the allocation method of the superclass. */
327 ret = ((struct string_hash_entry *)
328 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
332 /* Initialize the local fields. */
337 return (struct bfd_hash_entry *) ret;
340 /* Look up an entry in an string hash table. */
342 #define string_hash_lookup(t, string, create, copy) \
343 ((struct string_hash_entry *) \
344 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
346 /* We can't afford to read in all the debugging information when we do
347 a link. Instead, we build a list of these structures to show how
348 different parts of the input file map to the output file. */
352 /* The next entry in this linked list. */
353 struct shuffle *next;
354 /* The length of the information. */
356 /* Whether this information comes from a file or not. */
362 /* The BFD the data comes from. */
364 /* The offset within input_bfd. */
367 /* The data to be written out. */
372 /* This structure holds information across calls to
373 bfd_ecoff_debug_accumulate. */
377 /* The FDR hash table. */
378 struct string_hash_table fdr_hash;
379 /* The strings hash table. */
380 struct string_hash_table str_hash;
381 /* Linked lists describing how to shuffle the input debug
382 information into the output file. We keep a pointer to both the
383 head and the tail. */
384 struct shuffle *line;
385 struct shuffle *line_end;
387 struct shuffle *pdr_end;
389 struct shuffle *sym_end;
391 struct shuffle *opt_end;
393 struct shuffle *aux_end;
395 struct shuffle *ss_end;
396 struct string_hash_entry *ss_hash;
397 struct string_hash_entry *ss_hash_end;
399 struct shuffle *fdr_end;
401 struct shuffle *rfd_end;
402 /* The size of the largest file shuffle. */
403 unsigned long largest_file_shuffle;
404 /* An obstack for debugging information. */
405 struct obstack memory;
408 /* Add a file entry to a shuffle list. */
410 static boolean add_file_shuffle PARAMS ((struct accumulate *,
412 struct shuffle **, bfd *, file_ptr,
416 add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
417 struct accumulate *ainfo;
418 struct shuffle **head;
419 struct shuffle **tail;
426 if (*tail != (struct shuffle *) NULL
428 && (*tail)->u.file.input_bfd == input_bfd
429 && (*tail)->u.file.offset + (*tail)->size == (unsigned long) offset)
431 /* Just merge this entry onto the existing one. */
432 (*tail)->size += size;
433 if ((*tail)->size > ainfo->largest_file_shuffle)
434 ainfo->largest_file_shuffle = (*tail)->size;
438 n = (struct shuffle *) obstack_alloc (&ainfo->memory,
439 sizeof (struct shuffle));
442 bfd_set_error (bfd_error_no_memory);
448 n->u.file.input_bfd = input_bfd;
449 n->u.file.offset = offset;
450 if (*head == (struct shuffle *) NULL)
452 if (*tail != (struct shuffle *) NULL)
455 if (size > ainfo->largest_file_shuffle)
456 ainfo->largest_file_shuffle = size;
460 /* Add a memory entry to a shuffle list. */
462 static boolean add_memory_shuffle PARAMS ((struct accumulate *,
463 struct shuffle **head,
464 struct shuffle **tail,
465 bfd_byte *data, unsigned long size));
468 add_memory_shuffle (ainfo, head, tail, data, size)
469 struct accumulate *ainfo;
470 struct shuffle **head;
471 struct shuffle **tail;
477 n = (struct shuffle *) obstack_alloc (&ainfo->memory,
478 sizeof (struct shuffle));
481 bfd_set_error (bfd_error_no_memory);
487 n->u.memory = (PTR) data;
488 if (*head == (struct shuffle *) NULL)
490 if (*tail != (struct shuffle *) NULL)
496 /* Initialize the FDR hash table. This returns a handle which is then
497 passed in to bfd_ecoff_debug_accumulate, et. al. */
501 bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
503 struct ecoff_debug_info *output_debug;
504 const struct ecoff_debug_swap *output_swap;
505 struct bfd_link_info *info;
507 struct accumulate *ainfo;
509 ainfo = (struct accumulate *) malloc (sizeof (struct accumulate));
512 bfd_set_error (bfd_error_no_memory);
515 if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
520 ainfo->line_end = NULL;
522 ainfo->pdr_end = NULL;
524 ainfo->sym_end = NULL;
526 ainfo->opt_end = NULL;
528 ainfo->aux_end = NULL;
530 ainfo->ss_end = NULL;
531 ainfo->ss_hash = NULL;
532 ainfo->ss_hash_end = NULL;
534 ainfo->fdr_end = NULL;
536 ainfo->rfd_end = NULL;
538 ainfo->largest_file_shuffle = 0;
540 if (! info->relocateable)
542 if (! bfd_hash_table_init (&ainfo->str_hash.table, string_hash_newfunc))
545 /* The first entry in the string table is the empty string. */
546 output_debug->symbolic_header.issMax = 1;
549 if (!obstack_begin (&ainfo->memory, 4050))
551 bfd_set_error (bfd_error_no_memory);
558 /* Free the accumulated debugging information. */
562 bfd_ecoff_debug_free (handle, output_bfd, output_debug, output_swap, info)
565 struct ecoff_debug_info *output_debug;
566 const struct ecoff_debug_swap *output_swap;
567 struct bfd_link_info *info;
569 struct accumulate *ainfo = (struct accumulate *) handle;
571 bfd_hash_table_free (&ainfo->fdr_hash.table);
573 if (! info->relocateable)
574 bfd_hash_table_free (&ainfo->str_hash.table);
576 obstack_free (&ainfo->memory, (PTR) NULL);
581 /* Accumulate the debugging information from INPUT_BFD into
582 OUTPUT_BFD. The INPUT_DEBUG argument points to some ECOFF
583 debugging information which we want to link into the information
584 pointed to by the OUTPUT_DEBUG argument. OUTPUT_SWAP and
585 INPUT_SWAP point to the swapping information needed. INFO is the
586 linker information structure. HANDLE is returned by
587 bfd_ecoff_debug_init. */
591 bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
592 input_bfd, input_debug, input_swap,
596 struct ecoff_debug_info *output_debug;
597 const struct ecoff_debug_swap *output_swap;
599 struct ecoff_debug_info *input_debug;
600 const struct ecoff_debug_swap *input_swap;
601 struct bfd_link_info *info;
603 struct accumulate *ainfo = (struct accumulate *) handle;
604 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
605 = input_swap->swap_sym_in;
606 void (* const swap_rfd_in) PARAMS ((bfd *, PTR, RFDT *))
607 = input_swap->swap_rfd_in;
608 void (* const swap_sym_out) PARAMS ((bfd *, const SYMR *, PTR))
609 = output_swap->swap_sym_out;
610 void (* const swap_fdr_out) PARAMS ((bfd *, const FDR *, PTR))
611 = output_swap->swap_fdr_out;
612 void (* const swap_rfd_out) PARAMS ((bfd *, const RFDT *, PTR))
613 = output_swap->swap_rfd_out;
614 bfd_size_type external_pdr_size = output_swap->external_pdr_size;
615 bfd_size_type external_sym_size = output_swap->external_sym_size;
616 bfd_size_type external_opt_size = output_swap->external_opt_size;
617 bfd_size_type external_fdr_size = output_swap->external_fdr_size;
618 bfd_size_type external_rfd_size = output_swap->external_rfd_size;
619 HDRR * const output_symhdr = &output_debug->symbolic_header;
620 HDRR * const input_symhdr = &input_debug->symbolic_header;
621 bfd_vma section_adjust[scMax];
626 bfd_size_type fdr_add;
637 /* Use section_adjust to hold the value to add to a symbol in a
638 particular section. */
639 memset ((PTR) section_adjust, 0, sizeof section_adjust);
641 #define SET(name, indx) \
642 sec = bfd_get_section_by_name (input_bfd, name); \
644 section_adjust[indx] = (sec->output_section->vma \
645 + sec->output_offset \
648 SET (".text", scText);
649 SET (".data", scData);
651 SET (".sdata", scSData);
652 SET (".sbss", scSBss);
653 /* scRdata section may be either .rdata or .rodata. */
654 SET (".rdata", scRData);
655 SET (".rodata", scRData);
656 SET (".init", scInit);
657 SET (".fini", scFini);
658 SET (".rconst", scRConst);
662 /* Find all the debugging information based on the FDR's. We need
663 to handle them whether they are swapped or not. */
664 if (input_debug->fdr != (FDR *) NULL)
666 fdr_start = (bfd_byte *) input_debug->fdr;
667 fdr_add = sizeof (FDR);
671 fdr_start = (bfd_byte *) input_debug->external_fdr;
672 fdr_add = input_swap->external_fdr_size;
674 fdr_end = fdr_start + input_symhdr->ifdMax * fdr_add;
676 input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd,
677 (input_symhdr->ifdMax
680 sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
681 rfd_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
682 if (!input_debug->ifdmap || !rfd_out)
684 bfd_set_error (bfd_error_no_memory);
687 if (!add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz))
692 /* Look through the FDR's to see which ones we are going to include
693 in the final output. We do not want duplicate FDR information
694 for header files, because ECOFF debugging is often very large.
695 When we find an FDR with no line information which can be merged,
696 we look it up in a hash table to ensure that we only include it
697 once. We keep a table mapping FDR numbers to the final number
698 they get with the BFD, so that we can refer to it when we write
699 out the external symbols. */
700 for (fdr_ptr = fdr_start, i = 0;
702 fdr_ptr += fdr_add, i++, rfd_out += external_rfd_size)
706 if (input_debug->fdr != (FDR *) NULL)
707 fdr = *(FDR *) fdr_ptr;
709 (*input_swap->swap_fdr_in) (input_bfd, (PTR) fdr_ptr, &fdr);
711 /* See if this FDR can be merged with an existing one. */
712 if (fdr.cbLine == 0 && fdr.rss != -1 && fdr.fMerge)
716 struct string_hash_entry *fh;
718 /* We look up a string formed from the file name and the
719 number of symbols. Sometimes an include file will
720 conditionally define a typedef or something based on the
721 order of include files. Using the number of symbols as a
722 hash reduces the chance that we will merge symbol
723 information that should not be merged. */
724 name = input_debug->ss + fdr.issBase + fdr.rss;
726 lookup = (char *) malloc (strlen (name) + 20);
729 bfd_set_error (bfd_error_no_memory);
732 sprintf (lookup, "%s %lx", name, fdr.csym);
734 fh = string_hash_lookup (&ainfo->fdr_hash, lookup, true, true);
736 if (fh == (struct string_hash_entry *) NULL)
741 input_debug->ifdmap[i] = fh->val;
742 (*swap_rfd_out) (output_bfd, input_debug->ifdmap + i,
745 /* Don't copy this FDR. */
749 fh->val = output_symhdr->ifdMax + copied;
752 input_debug->ifdmap[i] = output_symhdr->ifdMax + copied;
753 (*swap_rfd_out) (output_bfd, input_debug->ifdmap + i, (PTR) rfd_out);
757 newrfdbase = output_symhdr->crfd;
758 output_symhdr->crfd += input_symhdr->ifdMax;
760 /* Copy over any existing RFD's. RFD's are only created by the
761 linker, so this will only happen for input files which are the
762 result of a partial link. */
763 rfd_in = (bfd_byte *) input_debug->external_rfd;
764 rfd_end = rfd_in + input_symhdr->crfd * input_swap->external_rfd_size;
767 rfd_in += input_swap->external_rfd_size)
771 (*swap_rfd_in) (input_bfd, (PTR) rfd_in, &rfd);
772 BFD_ASSERT (rfd >= 0 && rfd < input_symhdr->ifdMax);
773 rfd = input_debug->ifdmap[rfd];
774 (*swap_rfd_out) (output_bfd, &rfd, (PTR) rfd_out);
775 rfd_out += external_rfd_size;
778 oldrfdbase = output_symhdr->crfd;
779 output_symhdr->crfd += input_symhdr->crfd;
781 /* Look through the FDR's and copy over all associated debugging
783 sz = copied * external_fdr_size;
784 fdr_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
787 bfd_set_error (bfd_error_no_memory);
790 if (!add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz))
792 for (fdr_ptr = fdr_start, i = 0;
794 fdr_ptr += fdr_add, i++)
801 boolean fgotfilename;
803 if (input_debug->ifdmap[i] < output_symhdr->ifdMax)
805 /* We are not copying this FDR. */
809 if (input_debug->fdr != (FDR *) NULL)
810 fdr = *(FDR *) fdr_ptr;
812 (*input_swap->swap_fdr_in) (input_bfd, (PTR) fdr_ptr, &fdr);
816 /* Adjust the FDR address for any changes that may have been
818 if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
820 struct ecoff_value_adjust *adjust;
822 for (adjust = input_debug->adjust;
823 adjust != (struct ecoff_value_adjust *) NULL;
824 adjust = adjust->next)
825 if (fdr_adr >= adjust->start
826 && fdr_adr < adjust->end)
827 fdr.adr += adjust->adjust;
830 /* FIXME: It is conceivable that this FDR points to the .init or
831 .fini section, in which case this will not do the right
833 fdr.adr += section_adjust[scText];
835 /* Swap in the local symbols, adjust their values, and swap them
837 fgotfilename = false;
838 sz = fdr.csym * external_sym_size;
839 sym_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
842 bfd_set_error (bfd_error_no_memory);
845 if (!add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out,
848 lraw_src = ((bfd_byte *) input_debug->external_sym
849 + fdr.isymBase * input_swap->external_sym_size);
850 lraw_end = lraw_src + fdr.csym * input_swap->external_sym_size;
851 for (; lraw_src < lraw_end; lraw_src += input_swap->external_sym_size)
855 (*swap_sym_in) (input_bfd, (PTR) lraw_src, &internal_sym);
857 BFD_ASSERT (internal_sym.sc != scCommon
858 && internal_sym.sc != scSCommon);
860 /* Adjust the symbol value if appropriate. */
861 switch (internal_sym.st)
864 if (ECOFF_IS_STAB (&internal_sym))
872 if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
875 struct ecoff_value_adjust *adjust;
877 value = internal_sym.value;
878 for (adjust = input_debug->adjust;
879 adjust != (struct ecoff_value_adjust *) NULL;
880 adjust = adjust->next)
881 if (value >= adjust->start
882 && value < adjust->end)
883 internal_sym.value += adjust->adjust;
885 internal_sym.value += section_adjust[internal_sym.sc];
892 /* If we are doing a final link, we hash all the strings in
893 the local symbol table together. This reduces the amount
894 of space required by debugging information. We don't do
895 this when performing a relocateable link because it would
896 prevent us from easily merging different FDR's. */
897 if (! info->relocateable)
902 if (! fgotfilename && internal_sym.iss == fdr.rss)
907 /* Hash the name into the string table. */
908 name = input_debug->ss + fdr.issBase + internal_sym.iss;
910 internal_sym.iss = 0;
913 struct string_hash_entry *sh;
915 sh = string_hash_lookup (&ainfo->str_hash, name, true, true);
916 if (sh == (struct string_hash_entry *) NULL)
920 sh->val = output_symhdr->issMax;
921 output_symhdr->issMax += strlen (name) + 1;
922 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
924 if (ainfo->ss_hash_end
925 != (struct string_hash_entry *) NULL)
926 ainfo->ss_hash_end->next = sh;
927 ainfo->ss_hash_end = sh;
929 internal_sym.iss = sh->val;
934 fdr.rss = internal_sym.iss;
939 (*swap_sym_out) (output_bfd, &internal_sym, sym_out);
940 sym_out += external_sym_size;
943 fdr.isymBase = output_symhdr->isymMax;
944 output_symhdr->isymMax += fdr.csym;
946 /* Copy the information that does not need swapping. */
948 /* FIXME: If we are relaxing, we need to adjust the line
949 numbers. Frankly, forget it. Anybody using stabs debugging
950 information will not use this line number information, and
951 stabs are adjusted correctly. */
954 if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
956 input_symhdr->cbLineOffset + fdr.cbLineOffset,
959 fdr.ilineBase = output_symhdr->ilineMax;
960 fdr.cbLineOffset = output_symhdr->cbLine;
961 output_symhdr->ilineMax += fdr.cline;
962 output_symhdr->cbLine += fdr.cbLine;
966 if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
968 (input_symhdr->cbAuxOffset
969 + fdr.iauxBase * sizeof (union aux_ext)),
970 fdr.caux * sizeof (union aux_ext)))
972 fdr.iauxBase = output_symhdr->iauxMax;
973 output_symhdr->iauxMax += fdr.caux;
975 if (! info->relocateable)
978 /* When are are hashing strings, we lie about the number of
979 strings attached to each FDR. We need to set cbSs
980 because some versions of dbx apparently use it to decide
981 how much of the string table to read in. */
983 fdr.cbSs = output_symhdr->issMax;
985 else if (fdr.cbSs > 0)
987 if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
989 input_symhdr->cbSsOffset + fdr.issBase,
992 fdr.issBase = output_symhdr->issMax;
993 output_symhdr->issMax += fdr.cbSs;
996 if ((output_bfd->xvec->header_byteorder_big_p
997 == input_bfd->xvec->header_byteorder_big_p)
998 && input_debug->adjust == (struct ecoff_value_adjust *) NULL)
1000 /* The two BFD's have the same endianness, and we don't have
1001 to adjust the PDR addresses, so simply copying the
1002 information will suffice. */
1003 BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
1006 if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
1008 (input_symhdr->cbPdOffset
1009 + fdr.ipdFirst * external_pdr_size),
1010 fdr.cpd * external_pdr_size))
1013 BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
1016 if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
1018 (input_symhdr->cbOptOffset
1019 + fdr.ioptBase * external_opt_size),
1020 fdr.copt * external_opt_size))
1026 bfd_size_type outsz, insz;
1031 /* The two BFD's have different endianness, so we must swap
1032 everything in and out. This code would always work, but
1033 it would be unnecessarily slow in the normal case. */
1034 outsz = external_pdr_size;
1035 insz = input_swap->external_pdr_size;
1036 in = ((bfd_byte *) input_debug->external_pdr
1037 + fdr.ipdFirst * insz);
1038 end = in + fdr.cpd * insz;
1039 sz = fdr.cpd * outsz;
1040 out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
1043 bfd_set_error (bfd_error_no_memory);
1046 if (!add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out,
1049 for (; in < end; in += insz, out += outsz)
1053 (*input_swap->swap_pdr_in) (input_bfd, (PTR) in, &pdr);
1055 /* If we have been relaxing, we may have to adjust the
1057 if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
1060 struct ecoff_value_adjust *adjust;
1062 adr = fdr_adr + pdr.adr;
1063 for (adjust = input_debug->adjust;
1064 adjust != (struct ecoff_value_adjust *) NULL;
1065 adjust = adjust->next)
1066 if (adr >= adjust->start
1067 && adr < adjust->end)
1068 pdr.adr += adjust->adjust;
1071 (*output_swap->swap_pdr_out) (output_bfd, &pdr, (PTR) out);
1074 /* Swap over the optimization information. */
1075 outsz = external_opt_size;
1076 insz = input_swap->external_opt_size;
1077 in = ((bfd_byte *) input_debug->external_opt
1078 + fdr.ioptBase * insz);
1079 end = in + fdr.copt * insz;
1080 sz = fdr.copt * outsz;
1081 out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
1084 bfd_set_error (bfd_error_no_memory);
1087 if (!add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out,
1090 for (; in < end; in += insz, out += outsz)
1094 (*input_swap->swap_opt_in) (input_bfd, (PTR) in, &opt);
1095 (*output_swap->swap_opt_out) (output_bfd, &opt, (PTR) out);
1099 fdr.ipdFirst = output_symhdr->ipdMax;
1100 output_symhdr->ipdMax += fdr.cpd;
1101 fdr.ioptBase = output_symhdr->ioptMax;
1102 output_symhdr->ioptMax += fdr.copt;
1106 /* Point this FDR at the table of RFD's we created. */
1107 fdr.rfdBase = newrfdbase;
1108 fdr.crfd = input_symhdr->ifdMax;
1112 /* Point this FDR at the remapped RFD's. */
1113 fdr.rfdBase += oldrfdbase;
1116 (*swap_fdr_out) (output_bfd, &fdr, fdr_out);
1117 fdr_out += external_fdr_size;
1118 ++output_symhdr->ifdMax;
1124 /* Add a string to the debugging information we are accumulating.
1125 Return the offset from the fdr string base. */
1127 static long ecoff_add_string PARAMS ((struct accumulate *,
1128 struct bfd_link_info *,
1129 struct ecoff_debug_info *,
1130 FDR *fdr, const char *string));
1133 ecoff_add_string (ainfo, info, debug, fdr, string)
1134 struct accumulate *ainfo;
1135 struct bfd_link_info *info;
1136 struct ecoff_debug_info *debug;
1144 symhdr = &debug->symbolic_header;
1145 len = strlen (string);
1146 if (info->relocateable)
1148 if (!add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
1151 ret = symhdr->issMax;
1152 symhdr->issMax += len + 1;
1153 fdr->cbSs += len + 1;
1157 struct string_hash_entry *sh;
1159 sh = string_hash_lookup (&ainfo->str_hash, string, true, true);
1160 if (sh == (struct string_hash_entry *) NULL)
1164 sh->val = symhdr->issMax;
1165 symhdr->issMax += len + 1;
1166 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
1167 ainfo->ss_hash = sh;
1168 if (ainfo->ss_hash_end
1169 != (struct string_hash_entry *) NULL)
1170 ainfo->ss_hash_end->next = sh;
1171 ainfo->ss_hash_end = sh;
1179 /* Add debugging information from a non-ECOFF file. */
1182 bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
1183 output_swap, input_bfd, info)
1186 struct ecoff_debug_info *output_debug;
1187 const struct ecoff_debug_swap *output_swap;
1189 struct bfd_link_info *info;
1191 struct accumulate *ainfo = (struct accumulate *) handle;
1192 void (* const swap_sym_out) PARAMS ((bfd *, const SYMR *, PTR))
1193 = output_swap->swap_sym_out;
1194 HDRR *output_symhdr = &output_debug->symbolic_header;
1204 memset ((PTR) &fdr, 0, sizeof fdr);
1206 sec = bfd_get_section_by_name (input_bfd, ".text");
1208 fdr.adr = sec->output_section->vma + sec->output_offset;
1211 /* FIXME: What about .init or .fini? */
1215 fdr.issBase = output_symhdr->issMax;
1217 fdr.rss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1218 bfd_get_filename (input_bfd));
1221 fdr.isymBase = output_symhdr->isymMax;
1223 /* Get the local symbols from the input BFD. */
1224 symsize = bfd_get_symtab_upper_bound (input_bfd);
1227 symbols = (asymbol **) bfd_alloc (output_bfd, symsize);
1228 if (symbols == (asymbol **) NULL)
1230 bfd_set_error (bfd_error_no_memory);
1233 symcount = bfd_canonicalize_symtab (input_bfd, symbols);
1236 sym_end = symbols + symcount;
1238 /* Handle the local symbols. Any external symbols are handled
1241 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
1246 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
1248 memset ((PTR) &internal_sym, 0, sizeof internal_sym);
1249 internal_sym.iss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1252 if (internal_sym.iss == -1)
1254 if (bfd_is_com_section ((*sym_ptr)->section)
1255 || bfd_is_und_section ((*sym_ptr)->section))
1256 internal_sym.value = (*sym_ptr)->value;
1258 internal_sym.value = ((*sym_ptr)->value
1259 + (*sym_ptr)->section->output_offset
1260 + (*sym_ptr)->section->output_section->vma);
1261 internal_sym.st = stNil;
1262 internal_sym.sc = scUndefined;
1263 internal_sym.index = indexNil;
1265 external_sym = (PTR) obstack_alloc (&ainfo->memory,
1266 output_swap->external_sym_size);
1269 bfd_set_error (bfd_error_no_memory);
1272 (*swap_sym_out) (output_bfd, &internal_sym, external_sym);
1273 add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
1274 external_sym, output_swap->external_sym_size);
1276 ++output_symhdr->isymMax;
1279 bfd_release (output_bfd, (PTR) symbols);
1281 /* Leave everything else in the FDR zeroed out. This will cause
1282 the lang field to be langC. The fBigendian field will
1283 indicate little endian format, but it doesn't matter because
1284 it only applies to aux fields and there are none. */
1285 external_fdr = (PTR) obstack_alloc (&ainfo->memory,
1286 output_swap->external_fdr_size);
1289 bfd_set_error (bfd_error_no_memory);
1292 (*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
1293 add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
1294 external_fdr, output_swap->external_fdr_size);
1296 ++output_symhdr->ifdMax;
1301 /* Set up ECOFF debugging information for the external symbols.
1302 FIXME: This is done using a memory buffer, but it should be
1303 probably be changed to use a shuffle structure. The assembler uses
1304 this interface, so that must be changed to do something else. */
1307 bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
1310 struct ecoff_debug_info *debug;
1311 const struct ecoff_debug_swap *swap;
1312 boolean relocateable;
1313 boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
1314 void (*set_index) PARAMS ((asymbol *, bfd_size_type));
1316 HDRR * const symhdr = &debug->symbolic_header;
1317 asymbol **sym_ptr_ptr;
1320 sym_ptr_ptr = bfd_get_outsymbols (abfd);
1321 if (sym_ptr_ptr == NULL)
1324 for (c = bfd_get_symcount (abfd); c > 0; c--, sym_ptr_ptr++)
1329 sym_ptr = *sym_ptr_ptr;
1331 /* Get the external symbol information. */
1332 if ((*get_extr) (sym_ptr, &esym) == false)
1335 /* If we're producing an executable, move common symbols into
1337 if (relocateable == false)
1339 if (esym.asym.sc == scCommon)
1340 esym.asym.sc = scBss;
1341 else if (esym.asym.sc == scSCommon)
1342 esym.asym.sc = scSBss;
1345 if (bfd_is_com_section (sym_ptr->section)
1346 || bfd_is_und_section (sym_ptr->section)
1347 || sym_ptr->section->output_section == (asection *) NULL)
1349 /* FIXME: gas does not keep the value of a small undefined
1350 symbol in the symbol itself, because of relocation
1352 if (esym.asym.sc != scSUndefined
1353 || esym.asym.value == 0
1354 || sym_ptr->value != 0)
1355 esym.asym.value = sym_ptr->value;
1358 esym.asym.value = (sym_ptr->value
1359 + sym_ptr->section->output_offset
1360 + sym_ptr->section->output_section->vma);
1363 (*set_index) (sym_ptr, (bfd_size_type) symhdr->iextMax);
1365 if (! bfd_ecoff_debug_one_external (abfd, debug, swap,
1366 sym_ptr->name, &esym))
1373 /* Add a single external symbol to the debugging information. */
1376 bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
1378 struct ecoff_debug_info *debug;
1379 const struct ecoff_debug_swap *swap;
1383 const bfd_size_type external_ext_size = swap->external_ext_size;
1384 void (* const swap_ext_out) PARAMS ((bfd *, const EXTR *, PTR))
1385 = swap->swap_ext_out;
1386 HDRR * const symhdr = &debug->symbolic_header;
1389 namelen = strlen (name);
1391 if ((size_t) (debug->ssext_end - debug->ssext)
1392 < symhdr->issExtMax + namelen + 1)
1394 if (ecoff_add_bytes ((char **) &debug->ssext,
1395 (char **) &debug->ssext_end,
1396 symhdr->issExtMax + namelen + 1)
1400 if ((size_t) ((char *) debug->external_ext_end
1401 - (char *) debug->external_ext)
1402 < (symhdr->iextMax + 1) * external_ext_size)
1404 if (ecoff_add_bytes ((char **) &debug->external_ext,
1405 (char **) &debug->external_ext_end,
1406 (symhdr->iextMax + 1) * external_ext_size)
1411 esym->asym.iss = symhdr->issExtMax;
1413 (*swap_ext_out) (abfd, esym,
1414 ((char *) debug->external_ext
1415 + symhdr->iextMax * swap->external_ext_size));
1419 strcpy (debug->ssext + symhdr->issExtMax, name);
1420 symhdr->issExtMax += namelen + 1;
1425 /* Align the ECOFF debugging information. */
1429 ecoff_align_debug (abfd, debug, swap)
1431 struct ecoff_debug_info *debug;
1432 const struct ecoff_debug_swap *swap;
1434 HDRR * const symhdr = &debug->symbolic_header;
1435 bfd_size_type debug_align, aux_align, rfd_align;
1438 /* Adjust the counts so that structures are aligned. */
1439 debug_align = swap->debug_align;
1440 aux_align = debug_align / sizeof (union aux_ext);
1441 rfd_align = debug_align / swap->external_rfd_size;
1443 add = debug_align - (symhdr->cbLine & (debug_align - 1));
1444 if (add != debug_align)
1446 if (debug->line != (unsigned char *) NULL)
1447 memset ((PTR) (debug->line + symhdr->cbLine), 0, add);
1448 symhdr->cbLine += add;
1451 add = debug_align - (symhdr->issMax & (debug_align - 1));
1452 if (add != debug_align)
1454 if (debug->ss != (char *) NULL)
1455 memset ((PTR) (debug->ss + symhdr->issMax), 0, add);
1456 symhdr->issMax += add;
1459 add = debug_align - (symhdr->issExtMax & (debug_align - 1));
1460 if (add != debug_align)
1462 if (debug->ssext != (char *) NULL)
1463 memset ((PTR) (debug->ssext + symhdr->issExtMax), 0, add);
1464 symhdr->issExtMax += add;
1467 add = aux_align - (symhdr->iauxMax & (aux_align - 1));
1468 if (add != aux_align)
1470 if (debug->external_aux != (union aux_ext *) NULL)
1471 memset ((PTR) (debug->external_aux + symhdr->iauxMax), 0,
1472 add * sizeof (union aux_ext));
1473 symhdr->iauxMax += add;
1476 add = rfd_align - (symhdr->crfd & (rfd_align - 1));
1477 if (add != rfd_align)
1479 if (debug->external_rfd != (PTR) NULL)
1480 memset ((PTR) ((char *) debug->external_rfd
1481 + symhdr->crfd * swap->external_rfd_size),
1482 0, (size_t) (add * swap->external_rfd_size));
1483 symhdr->crfd += add;
1487 /* Return the size required by the ECOFF debugging information. */
1490 bfd_ecoff_debug_size (abfd, debug, swap)
1492 struct ecoff_debug_info *debug;
1493 const struct ecoff_debug_swap *swap;
1497 ecoff_align_debug (abfd, debug, swap);
1498 tot = swap->external_hdr_size;
1500 #define ADD(count, size) \
1501 tot += debug->symbolic_header.count * size
1503 ADD (cbLine, sizeof (unsigned char));
1504 ADD (idnMax, swap->external_dnr_size);
1505 ADD (ipdMax, swap->external_pdr_size);
1506 ADD (isymMax, swap->external_sym_size);
1507 ADD (ioptMax, swap->external_opt_size);
1508 ADD (iauxMax, sizeof (union aux_ext));
1509 ADD (issMax, sizeof (char));
1510 ADD (issExtMax, sizeof (char));
1511 ADD (ifdMax, swap->external_fdr_size);
1512 ADD (crfd, swap->external_rfd_size);
1513 ADD (iextMax, swap->external_ext_size);
1520 /* Write out the ECOFF symbolic header, given the file position it is
1521 going to be placed at. This assumes that the counts are set
1525 ecoff_write_symhdr (abfd, debug, swap, where)
1527 struct ecoff_debug_info *debug;
1528 const struct ecoff_debug_swap *swap;
1531 HDRR * const symhdr = &debug->symbolic_header;
1534 ecoff_align_debug (abfd, debug, swap);
1536 /* Go to the right location in the file. */
1537 if (bfd_seek (abfd, where, SEEK_SET) != 0)
1540 where += swap->external_hdr_size;
1542 symhdr->magic = swap->sym_magic;
1544 /* Fill in the file offsets. */
1545 #define SET(offset, count, size) \
1546 if (symhdr->count == 0) \
1547 symhdr->offset = 0; \
1550 symhdr->offset = where; \
1551 where += symhdr->count * size; \
1554 SET (cbLineOffset, cbLine, sizeof (unsigned char));
1555 SET (cbDnOffset, idnMax, swap->external_dnr_size);
1556 SET (cbPdOffset, ipdMax, swap->external_pdr_size);
1557 SET (cbSymOffset, isymMax, swap->external_sym_size);
1558 SET (cbOptOffset, ioptMax, swap->external_opt_size);
1559 SET (cbAuxOffset, iauxMax, sizeof (union aux_ext));
1560 SET (cbSsOffset, issMax, sizeof (char));
1561 SET (cbSsExtOffset, issExtMax, sizeof (char));
1562 SET (cbFdOffset, ifdMax, swap->external_fdr_size);
1563 SET (cbRfdOffset, crfd, swap->external_rfd_size);
1564 SET (cbExtOffset, iextMax, swap->external_ext_size);
1567 buff = (PTR) malloc ((size_t) swap->external_hdr_size);
1568 if (buff == NULL && swap->external_hdr_size != 0)
1570 bfd_set_error (bfd_error_no_memory);
1574 (*swap->swap_hdr_out) (abfd, symhdr, buff);
1575 if (bfd_write (buff, 1, swap->external_hdr_size, abfd)
1576 != swap->external_hdr_size)
1588 /* Write out the ECOFF debugging information. This function assumes
1589 that the information (the pointers and counts) in *DEBUG have been
1590 set correctly. WHERE is the position in the file to write the
1591 information to. This function fills in the file offsets in the
1595 bfd_ecoff_write_debug (abfd, debug, swap, where)
1597 struct ecoff_debug_info *debug;
1598 const struct ecoff_debug_swap *swap;
1601 HDRR * const symhdr = &debug->symbolic_header;
1603 if (! ecoff_write_symhdr (abfd, debug, swap, where))
1606 #define WRITE(ptr, count, size, offset) \
1607 BFD_ASSERT (symhdr->offset == 0 \
1608 || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
1609 if (bfd_write ((PTR) debug->ptr, size, symhdr->count, abfd) \
1610 != size * symhdr->count) \
1613 WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);
1614 WRITE (external_dnr, idnMax, swap->external_dnr_size, cbDnOffset);
1615 WRITE (external_pdr, ipdMax, swap->external_pdr_size, cbPdOffset);
1616 WRITE (external_sym, isymMax, swap->external_sym_size, cbSymOffset);
1617 WRITE (external_opt, ioptMax, swap->external_opt_size, cbOptOffset);
1618 WRITE (external_aux, iauxMax, sizeof (union aux_ext), cbAuxOffset);
1619 WRITE (ss, issMax, sizeof (char), cbSsOffset);
1620 WRITE (ssext, issExtMax, sizeof (char), cbSsExtOffset);
1621 WRITE (external_fdr, ifdMax, swap->external_fdr_size, cbFdOffset);
1622 WRITE (external_rfd, crfd, swap->external_rfd_size, cbRfdOffset);
1623 WRITE (external_ext, iextMax, swap->external_ext_size, cbExtOffset);
1629 /* Write out a shuffle list. */
1631 static boolean ecoff_write_shuffle PARAMS ((bfd *,
1632 const struct ecoff_debug_swap *,
1633 struct shuffle *, PTR space));
1636 ecoff_write_shuffle (abfd, swap, shuffle, space)
1638 const struct ecoff_debug_swap *swap;
1639 struct shuffle *shuffle;
1642 register struct shuffle *l;
1643 unsigned long total;
1646 for (l = shuffle; l != (struct shuffle *) NULL; l = l->next)
1650 if (bfd_write (l->u.memory, 1, l->size, abfd) != l->size)
1655 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
1656 || bfd_read (space, 1, l->size, l->u.file.input_bfd) != l->size
1657 || bfd_write (space, 1, l->size, abfd) != l->size)
1663 if ((total & (swap->debug_align - 1)) != 0)
1668 i = swap->debug_align - (total & (swap->debug_align - 1));
1669 s = (bfd_byte *) malloc (i);
1670 if (s == NULL && i != 0)
1672 bfd_set_error (bfd_error_no_memory);
1676 memset ((PTR) s, 0, i);
1677 if (bfd_write ((PTR) s, 1, i, abfd) != i)
1688 /* Write out debugging information using accumulated linker
1692 bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
1695 struct ecoff_debug_info *debug;
1696 const struct ecoff_debug_swap *swap;
1697 struct bfd_link_info *info;
1700 struct accumulate *ainfo = (struct accumulate *) handle;
1703 if (! ecoff_write_symhdr (abfd, debug, swap, where))
1706 space = (PTR) malloc (ainfo->largest_file_shuffle);
1707 if (space == NULL && ainfo->largest_file_shuffle != 0)
1709 bfd_set_error (bfd_error_no_memory);
1713 if (! ecoff_write_shuffle (abfd, swap, ainfo->line, space)
1714 || ! ecoff_write_shuffle (abfd, swap, ainfo->pdr, space)
1715 || ! ecoff_write_shuffle (abfd, swap, ainfo->sym, space)
1716 || ! ecoff_write_shuffle (abfd, swap, ainfo->opt, space)
1717 || ! ecoff_write_shuffle (abfd, swap, ainfo->aux, space))
1720 /* The string table is written out from the hash table if this is a
1722 if (info->relocateable)
1724 BFD_ASSERT (ainfo->ss_hash == (struct string_hash_entry *) NULL);
1725 if (! ecoff_write_shuffle (abfd, swap, ainfo->ss, space))
1730 unsigned long total;
1732 struct string_hash_entry *sh;
1734 BFD_ASSERT (ainfo->ss == (struct shuffle *) NULL);
1736 if (bfd_write ((PTR) &null, 1, 1, abfd) != 1)
1739 BFD_ASSERT (ainfo->ss_hash == NULL || ainfo->ss_hash->val == 1);
1740 for (sh = ainfo->ss_hash;
1741 sh != (struct string_hash_entry *) NULL;
1746 len = strlen (sh->root.string);
1747 if (bfd_write ((PTR) sh->root.string, 1, len + 1, abfd) != len + 1)
1752 if ((total & (swap->debug_align - 1)) != 0)
1757 i = swap->debug_align - (total & (swap->debug_align - 1));
1758 s = (bfd_byte *) malloc (i);
1759 if (s == NULL && i != 0)
1761 bfd_set_error (bfd_error_no_memory);
1764 memset ((PTR) s, 0, i);
1765 if (bfd_write ((PTR) s, 1, i, abfd) != i)
1774 /* The external strings and symbol are not converted over to using
1775 shuffles. FIXME: They probably should be. */
1776 if (bfd_write (debug->ssext, 1, debug->symbolic_header.issExtMax, abfd)
1777 != (bfd_size_type) debug->symbolic_header.issExtMax)
1779 if ((debug->symbolic_header.issExtMax & (swap->debug_align - 1)) != 0)
1784 i = (swap->debug_align
1785 - (debug->symbolic_header.issExtMax & (swap->debug_align - 1)));
1786 s = (bfd_byte *) malloc (i);
1787 if (s == NULL && i != 0)
1789 bfd_set_error (bfd_error_no_memory);
1792 memset ((PTR) s, 0, i);
1793 if (bfd_write ((PTR) s, 1, i, abfd) != i)
1801 if (! ecoff_write_shuffle (abfd, swap, ainfo->fdr, space)
1802 || ! ecoff_write_shuffle (abfd, swap, ainfo->rfd, space))
1805 BFD_ASSERT (debug->symbolic_header.cbExtOffset == 0
1806 || (debug->symbolic_header.cbExtOffset
1807 == (bfd_vma) bfd_tell (abfd)));
1809 if (bfd_write (debug->external_ext, swap->external_ext_size,
1810 debug->symbolic_header.iextMax, abfd)
1811 != debug->symbolic_header.iextMax * swap->external_ext_size)
1824 /* Handle the find_nearest_line function for both ECOFF and MIPS ELF
1827 /* Compare FDR entries. This is called via qsort. */
1830 cmp_fdrtab_entry (leftp, rightp)
1834 const struct ecoff_fdrtab_entry *lp =
1835 (const struct ecoff_fdrtab_entry *) leftp;
1836 const struct ecoff_fdrtab_entry *rp =
1837 (const struct ecoff_fdrtab_entry *) rightp;
1839 if (lp->base_addr < rp->base_addr)
1841 if (lp->base_addr > rp->base_addr)
1846 /* Each file descriptor (FDR) has a memory address, to simplify
1847 looking up an FDR by address, we build a table covering all FDRs
1848 that have a least one procedure descriptor in them. The final
1849 table will be sorted by address so we can look it up via binary
1853 mk_fdrtab (abfd, debug_info, debug_swap, line_info)
1855 struct ecoff_debug_info * const debug_info;
1856 const struct ecoff_debug_swap * const debug_swap;
1857 struct ecoff_find_line *line_info;
1859 struct ecoff_fdrtab_entry *tab;
1866 fdr_start = debug_info->fdr;
1867 fdr_end = fdr_start + debug_info->symbolic_header.ifdMax;
1869 /* First, let's see how long the table needs to be: */
1870 for (len = 0, fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1872 if (fdr_ptr->cpd == 0) /* skip FDRs that have no PDRs */
1877 /* Now, create and fill in the table: */
1879 line_info->fdrtab = ((struct ecoff_fdrtab_entry*)
1881 len * sizeof (struct ecoff_fdrtab_entry)));
1882 if (line_info->fdrtab == NULL)
1884 bfd_set_error (bfd_error_no_memory);
1887 line_info->fdrtab_len = len;
1889 tab = line_info->fdrtab;
1890 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1892 if (fdr_ptr->cpd == 0)
1895 /* Check whether this file has stabs debugging information. In
1896 a file with stabs debugging information, the second local
1897 symbol is named @stabs. */
1899 if (fdr_ptr->csym >= 2)
1904 sym_ptr = ((char *) debug_info->external_sym
1905 + (fdr_ptr->isymBase + 1)*debug_swap->external_sym_size);
1906 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
1907 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
1914 bfd_size_type external_pdr_size;
1918 external_pdr_size = debug_swap->external_pdr_size;
1920 pdr_ptr = ((char *) debug_info->external_pdr
1921 + fdr_ptr->ipdFirst * external_pdr_size);
1922 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1923 /* The address of the first PDR is the offset of that
1924 procedure relative to the beginning of file FDR. */
1925 tab->base_addr = fdr_ptr->adr - pdr.adr;
1929 /* XXX I don't know about stabs, so this is a guess
1930 (davidm@cs.arizona.edu): */
1931 tab->base_addr = fdr_ptr->adr;
1937 /* Finally, the table is sorted in increasing memory-address order.
1938 The table is mostly sorted already, but there are cases (e.g.,
1939 static functions in include files), where this does not hold.
1940 Use "odump -PFv" to verify... */
1941 qsort ((PTR) line_info->fdrtab, len,
1942 sizeof (struct ecoff_fdrtab_entry), cmp_fdrtab_entry);
1947 /* Return index of first FDR that covers to OFFSET. */
1950 fdrtab_lookup (line_info, offset)
1951 struct ecoff_find_line *line_info;
1954 long low, high, len;
1956 struct ecoff_fdrtab_entry *tab;
1958 len = line_info->fdrtab_len;
1962 tab = line_info->fdrtab;
1963 for (low = 0, high = len - 1 ; low != high ;)
1965 mid = (high + low) / 2;
1966 if (offset >= tab[mid].base_addr && offset < tab[mid + 1].base_addr)
1969 if (tab[mid].base_addr > offset)
1976 /* last entry is catch-all for all higher addresses: */
1977 if (offset < tab[mid].base_addr)
1982 while (mid > 0 && tab[mid - 1].base_addr == tab[mid].base_addr)
1988 /* Do the work of find_nearest_line. */
1991 _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
1992 line_info, filename_ptr, functionname_ptr, retline_ptr)
1996 struct ecoff_debug_info * const debug_info;
1997 const struct ecoff_debug_swap * const debug_swap;
1998 struct ecoff_find_line *line_info;
1999 const char **filename_ptr;
2000 const char **functionname_ptr;
2001 unsigned int *retline_ptr;
2003 struct ecoff_fdrtab_entry *tab;
2008 offset += section->vma;
2010 /* Build FDR table (sorted by object file's base-address) if we
2011 don't have it already. */
2012 if (line_info->fdrtab == NULL
2013 && !mk_fdrtab (abfd, debug_info, debug_swap, line_info))
2016 tab = line_info->fdrtab;
2018 /* find first FDR for address OFFSET */
2019 i = fdrtab_lookup (line_info, offset);
2021 return false; /* no FDR, no fun... */
2022 fdr_ptr = tab[i].fdr;
2024 /* Check whether this file has stabs debugging information. In a
2025 file with stabs debugging information, the second local symbol is
2028 if (fdr_ptr->csym >= 2)
2033 sym_ptr = ((char *) debug_info->external_sym
2034 + (fdr_ptr->isymBase + 1) * debug_swap->external_sym_size);
2035 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
2036 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
2043 bfd_size_type external_pdr_size;
2045 char *best_pdr = NULL;
2047 bfd_vma best_dist = ~0;
2049 unsigned char *line_ptr;
2050 unsigned char *line_end;
2052 /* This file uses ECOFF debugging information. Each FDR has a
2053 list of procedure descriptors (PDR). The address in the FDR
2054 is the absolute address of the first procedure. The address
2055 in the first PDR gives the offset of that procedure relative
2056 to the object file's base-address. The addresses in
2057 subsequent PDRs specify each procedure's address relative to
2058 the object file's base-address. To make things more juicy,
2059 whenever the PROF bit in the PDR is set, the real entry point
2060 of the procedure may be 16 bytes below what would normally be
2061 the procedure's entry point. Instead, DEC came up with a
2062 wicked scheme to create profiled libraries "on the fly":
2063 instead of shipping a regular and a profiled version of each
2064 library, they insert 16 bytes of unused space in front of
2065 each procedure and set the "prof" bit in the PDR to indicate
2066 that there is a gap there (this is done automagically by "as"
2067 when option "-pg" is specified). Thus, normally, you link
2068 against such a library and, except for lots of 16 byte gaps
2069 between functions, things will behave as usual. However,
2070 when invoking "ld" with option "-pg", it will fill those gaps
2071 with code that calls mcount(). It then moves the function's
2072 entry point down by 16 bytes, and out pops a binary that has
2073 all functions profiled.
2075 NOTE: Neither FDRs nor PDRs are strictly sorted in memory
2076 order. For example, when including header-files that
2077 define functions, the FDRs follow behind the including
2078 file, even though their code may have been generated at
2079 a lower address. File coff-alpha.c from libbfd
2080 illustrates this (use "odump -PFv" to look at a file's
2081 FDR/PDR). Similarly, PDRs are sometimes out of order
2082 as well. An example of this is OSF/1 v3.0 libc's
2083 malloc.c. I'm not sure why this happens, but it could
2084 be due to optimizations that reorder a function's
2085 position within an object-file.
2089 On the first call to this function, we build a table of FDRs
2090 that is sorted by the base-address of the object-file the FDR
2091 is referring to. Notice that each object-file may contain
2092 code from multiple source files (e.g., due to code defined in
2093 include files). Thus, for any given base-address, there may
2094 be multiple FDRs (but this case is, fortunately, uncommon).
2095 lookup(addr) guarantees to return the first FDR that applies
2096 to address ADDR. Thus, after invoking lookup(), we have a
2097 list of FDRs that may contain the PDR for ADDR. Next, we
2098 walk through the PDRs of these FDRs and locate the one that
2099 is closest to ADDR (i.e., for which the difference between
2100 ADDR and the PDR's entry point is positive and minimal).
2101 Once, the right FDR and PDR are located, we simply walk
2102 through the line-number table to lookup the line-number that
2103 best matches ADDR. Obviously, things could be sped up by
2104 keeping a sorted list of PDRs instead of a sorted list of
2105 FDRs. However, this would increase space requirements
2106 considerably, which is undesirable. */
2107 external_pdr_size = debug_swap->external_pdr_size;
2109 /* Make offset relative to object file's start-address: */
2110 offset -= tab[i].base_addr;
2111 /* Search FDR list starting at tab[i] for the PDR that best matches
2112 OFFSET. Normally, the FDR list is only one entry long. */
2116 bfd_vma dist, min_dist = 0;
2120 fdr_ptr = tab[i].fdr;
2122 pdr_ptr = ((char *) debug_info->external_pdr
2123 + fdr_ptr->ipdFirst * external_pdr_size);
2124 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
2125 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2126 /* Find PDR that is closest to OFFSET. If pdr.prof is set,
2127 the procedure entry-point *may* be 0x10 below pdr.adr. We
2128 simply pretend that pdr.prof *implies* a lower entry-point.
2129 This is safe because it just means that may identify 4 NOPs
2130 in front of the function as belonging to the function. */
2131 for (pdr_hold = NULL;
2133 (pdr_ptr += external_pdr_size,
2134 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr)))
2136 if (offset >= (pdr.adr - 0x10 * pdr.prof))
2138 dist = offset - (pdr.adr - 0x10 * pdr.prof);
2139 if (!pdr_hold || dist < min_dist)
2147 if (!best_pdr || min_dist < best_dist)
2149 best_dist = min_dist;
2151 best_pdr = pdr_hold;
2153 /* continue looping until base_addr of next entry is different: */
2155 while (++i < line_info->fdrtab_len
2156 && tab[i].base_addr == tab[i - 1].base_addr);
2158 if (!best_fdr || !best_pdr)
2159 return false; /* shouldn't happen... */
2161 /* phew, finally we got something that we can hold onto: */
2164 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2165 /* Now we can look for the actual line number. The line numbers
2166 are stored in a very funky format, which I won't try to
2167 describe. The search is bounded by the end of the FDRs line
2169 line_end = debug_info->line + fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2171 /* Make offset relative to procedure entry: */
2172 offset -= pdr.adr - 0x10 * pdr.prof;
2174 line_ptr = debug_info->line + fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2175 while (line_ptr < line_end)
2180 delta = *line_ptr >> 4;
2183 count = (*line_ptr & 0xf) + 1;
2187 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2188 if (delta >= 0x8000)
2193 if (offset < count * 4)
2195 offset -= count * 4;
2198 /* If fdr_ptr->rss is -1, then this file does not have full
2199 symbols, at least according to gdb/mipsread.c. */
2200 if (fdr_ptr->rss == -1)
2202 *filename_ptr = NULL;
2204 *functionname_ptr = NULL;
2209 (*debug_swap->swap_ext_in)
2211 ((char *) debug_info->external_ext
2212 + pdr.isym * debug_swap->external_ext_size),
2214 *functionname_ptr = debug_info->ssext + proc_ext.asym.iss;
2221 *filename_ptr = debug_info->ss + fdr_ptr->issBase + fdr_ptr->rss;
2222 (*debug_swap->swap_sym_in)
2224 ((char *) debug_info->external_sym
2225 + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),
2227 *functionname_ptr = debug_info->ss + fdr_ptr->issBase + proc_sym.iss;
2229 if (lineno == ilineNil)
2231 *retline_ptr = lineno;
2235 bfd_size_type external_sym_size;
2236 const char *directory_name;
2237 const char *main_file_name;
2238 const char *current_file_name;
2239 const char *function_name;
2240 const char *line_file_name;
2241 bfd_vma low_func_vma;
2242 bfd_vma low_line_vma;
2245 char *sym_ptr, *sym_ptr_end;
2246 size_t len, funclen;
2247 char *buffer = NULL;
2249 /* This file uses stabs debugging information. When gcc is not
2250 optimizing, it will put the line number information before
2251 the function name stabs entry. When gcc is optimizing, it
2252 will put the stabs entry for all the function first, followed
2253 by the line number information. (This appears to happen
2254 because of the two output files used by the -mgpopt switch,
2255 which is implied by -O). This means that we must keep
2256 looking through the symbols until we find both a line number
2257 and a function name which are beyond the address we want. */
2259 *filename_ptr = NULL;
2260 *functionname_ptr = NULL;
2263 directory_name = NULL;
2264 main_file_name = NULL;
2265 current_file_name = NULL;
2266 function_name = NULL;
2267 line_file_name = NULL;
2273 external_sym_size = debug_swap->external_sym_size;
2275 sym_ptr = ((char *) debug_info->external_sym
2276 + (fdr_ptr->isymBase + 2) * external_sym_size);
2277 sym_ptr_end = sym_ptr + (fdr_ptr->csym - 2) * external_sym_size;
2279 sym_ptr < sym_ptr_end && (! past_line || ! past_fn);
2280 sym_ptr += external_sym_size)
2284 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
2286 if (ECOFF_IS_STAB (&sym))
2288 switch (ECOFF_UNMARK_STAB (sym.index))
2291 main_file_name = current_file_name =
2292 debug_info->ss + fdr_ptr->issBase + sym.iss;
2294 /* Check the next symbol to see if it is also an
2296 if (sym_ptr + external_sym_size < sym_ptr_end)
2300 (*debug_swap->swap_sym_in) (abfd,
2301 sym_ptr + external_sym_size,
2303 if (ECOFF_IS_STAB (&nextsym)
2304 && ECOFF_UNMARK_STAB (nextsym.index) == N_SO)
2306 directory_name = current_file_name;
2307 main_file_name = current_file_name =
2308 debug_info->ss + fdr_ptr->issBase + nextsym.iss;
2309 sym_ptr += external_sym_size;
2316 debug_info->ss + fdr_ptr->issBase + sym.iss;
2320 if (sym.value > offset)
2322 else if (sym.value >= low_func_vma)
2324 low_func_vma = sym.value;
2326 debug_info->ss + fdr_ptr->issBase + sym.iss;
2331 else if (sym.st == stLabel && sym.index != indexNil)
2333 if (sym.value > offset)
2335 else if (sym.value >= low_line_vma)
2337 low_line_vma = sym.value;
2338 line_file_name = current_file_name;
2339 *retline_ptr = sym.index;
2344 if (*retline_ptr != 0)
2345 main_file_name = line_file_name;
2347 /* We need to remove the stuff after the colon in the function
2348 name. We also need to put the directory name and the file
2350 if (function_name == NULL)
2353 len = funclen = strlen (function_name) + 1;
2355 if (main_file_name != NULL
2356 && directory_name != NULL
2357 && main_file_name[0] != '/')
2358 len += strlen (directory_name) + strlen (main_file_name) + 1;
2362 if (line_info->find_buffer != NULL)
2363 free (line_info->find_buffer);
2364 buffer = (char *) malloc (len);
2367 bfd_set_error (bfd_error_no_memory);
2370 line_info->find_buffer = buffer;
2373 if (function_name != NULL)
2377 strcpy (buffer, function_name);
2378 colon = strchr (buffer, ':');
2381 *functionname_ptr = buffer;
2384 if (main_file_name != NULL)
2386 if (directory_name == NULL || main_file_name[0] == '/')
2387 *filename_ptr = main_file_name;
2390 sprintf (buffer + funclen, "%s%s", directory_name,
2392 *filename_ptr = buffer + funclen;
2400 /* These routines copy symbolic information into a memory buffer.
2402 FIXME: The whole point of the shuffle code is to avoid storing
2403 everything in memory, since the linker is such a memory hog. This
2404 code makes that effort useless. It is only called by the MIPS ELF
2405 code when generating a shared library, so it is not that big a
2406 deal, but it should be fixed eventually. */
2408 /* Collect a shuffle into a memory buffer. */
2410 static boolean ecoff_collect_shuffle PARAMS ((struct shuffle *, bfd_byte *));
2413 ecoff_collect_shuffle (l, buff)
2417 unsigned long total;
2420 for (; l != (struct shuffle *) NULL; l = l->next)
2423 memcpy (buff, l->u.memory, l->size);
2426 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
2427 || bfd_read (buff, 1, l->size, l->u.file.input_bfd) != l->size)
2437 /* Copy PDR information into a memory buffer. */
2440 _bfd_ecoff_get_accumulated_pdr (handle, buff)
2444 struct accumulate *ainfo = (struct accumulate *) handle;
2446 return ecoff_collect_shuffle (ainfo->pdr, buff);
2449 /* Copy symbol information into a memory buffer. */
2452 _bfd_ecoff_get_accumulated_sym (handle, buff)
2456 struct accumulate *ainfo = (struct accumulate *) handle;
2458 return ecoff_collect_shuffle (ainfo->sym, buff);
2461 /* Copy the string table into a memory buffer. */
2464 _bfd_ecoff_get_accumulated_ss (handle, buff)
2468 struct accumulate *ainfo = (struct accumulate *) handle;
2469 struct string_hash_entry *sh;
2470 unsigned long total;
2472 /* The string table is written out from the hash table if this is a
2474 BFD_ASSERT (ainfo->ss == (struct shuffle *) NULL);
2477 BFD_ASSERT (ainfo->ss_hash == NULL || ainfo->ss_hash->val == 1);
2478 for (sh = ainfo->ss_hash;
2479 sh != (struct string_hash_entry *) NULL;
2484 len = strlen (sh->root.string);
2485 memcpy (buff, (PTR) sh->root.string, len + 1);