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
)
323 /* Call the allocation method of the superclass. */
324 ret
= ((struct string_hash_entry
*)
325 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
329 /* Initialize the local fields. */
334 return (struct bfd_hash_entry
*) ret
;
337 /* Look up an entry in an string hash table. */
339 #define string_hash_lookup(t, string, create, copy) \
340 ((struct string_hash_entry *) \
341 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
343 /* We can't afford to read in all the debugging information when we do
344 a link. Instead, we build a list of these structures to show how
345 different parts of the input file map to the output file. */
349 /* The next entry in this linked list. */
350 struct shuffle
*next
;
351 /* The length of the information. */
353 /* Whether this information comes from a file or not. */
359 /* The BFD the data comes from. */
361 /* The offset within input_bfd. */
364 /* The data to be written out. */
369 /* This structure holds information across calls to
370 bfd_ecoff_debug_accumulate. */
374 /* The FDR hash table. */
375 struct string_hash_table fdr_hash
;
376 /* The strings hash table. */
377 struct string_hash_table str_hash
;
378 /* Linked lists describing how to shuffle the input debug
379 information into the output file. We keep a pointer to both the
380 head and the tail. */
381 struct shuffle
*line
;
382 struct shuffle
*line_end
;
384 struct shuffle
*pdr_end
;
386 struct shuffle
*sym_end
;
388 struct shuffle
*opt_end
;
390 struct shuffle
*aux_end
;
392 struct shuffle
*ss_end
;
393 struct string_hash_entry
*ss_hash
;
394 struct string_hash_entry
*ss_hash_end
;
396 struct shuffle
*fdr_end
;
398 struct shuffle
*rfd_end
;
399 /* The size of the largest file shuffle. */
400 unsigned long largest_file_shuffle
;
401 /* An obstack for debugging information. */
402 struct obstack memory
;
405 /* Add a file entry to a shuffle list. */
407 static boolean add_file_shuffle
PARAMS ((struct accumulate
*,
409 struct shuffle
**, bfd
*, file_ptr
,
413 add_file_shuffle (ainfo
, head
, tail
, input_bfd
, offset
, size
)
414 struct accumulate
*ainfo
;
415 struct shuffle
**head
;
416 struct shuffle
**tail
;
423 if (*tail
!= (struct shuffle
*) NULL
425 && (*tail
)->u
.file
.input_bfd
== input_bfd
426 && (*tail
)->u
.file
.offset
+ (*tail
)->size
== (unsigned long) offset
)
428 /* Just merge this entry onto the existing one. */
429 (*tail
)->size
+= size
;
430 if ((*tail
)->size
> ainfo
->largest_file_shuffle
)
431 ainfo
->largest_file_shuffle
= (*tail
)->size
;
435 n
= (struct shuffle
*) obstack_alloc (&ainfo
->memory
,
436 sizeof (struct shuffle
));
439 bfd_set_error (bfd_error_no_memory
);
445 n
->u
.file
.input_bfd
= input_bfd
;
446 n
->u
.file
.offset
= offset
;
447 if (*head
== (struct shuffle
*) NULL
)
449 if (*tail
!= (struct shuffle
*) NULL
)
452 if (size
> ainfo
->largest_file_shuffle
)
453 ainfo
->largest_file_shuffle
= size
;
457 /* Add a memory entry to a shuffle list. */
459 static boolean add_memory_shuffle
PARAMS ((struct accumulate
*,
460 struct shuffle
**head
,
461 struct shuffle
**tail
,
462 bfd_byte
*data
, unsigned long size
));
465 add_memory_shuffle (ainfo
, head
, tail
, data
, size
)
466 struct accumulate
*ainfo
;
467 struct shuffle
**head
;
468 struct shuffle
**tail
;
474 n
= (struct shuffle
*) obstack_alloc (&ainfo
->memory
,
475 sizeof (struct shuffle
));
478 bfd_set_error (bfd_error_no_memory
);
484 n
->u
.memory
= (PTR
) data
;
485 if (*head
== (struct shuffle
*) NULL
)
487 if (*tail
!= (struct shuffle
*) NULL
)
493 /* Initialize the FDR hash table. This returns a handle which is then
494 passed in to bfd_ecoff_debug_accumulate, et. al. */
498 bfd_ecoff_debug_init (output_bfd
, output_debug
, output_swap
, info
)
500 struct ecoff_debug_info
*output_debug
;
501 const struct ecoff_debug_swap
*output_swap
;
502 struct bfd_link_info
*info
;
504 struct accumulate
*ainfo
;
506 ainfo
= (struct accumulate
*) malloc (sizeof (struct accumulate
));
509 bfd_set_error (bfd_error_no_memory
);
512 if (! bfd_hash_table_init_n (&ainfo
->fdr_hash
.table
, string_hash_newfunc
,
517 ainfo
->line_end
= NULL
;
519 ainfo
->pdr_end
= NULL
;
521 ainfo
->sym_end
= NULL
;
523 ainfo
->opt_end
= NULL
;
525 ainfo
->aux_end
= NULL
;
527 ainfo
->ss_end
= NULL
;
528 ainfo
->ss_hash
= NULL
;
529 ainfo
->ss_hash_end
= NULL
;
531 ainfo
->fdr_end
= NULL
;
533 ainfo
->rfd_end
= NULL
;
535 ainfo
->largest_file_shuffle
= 0;
537 if (! info
->relocateable
)
539 if (! bfd_hash_table_init (&ainfo
->str_hash
.table
, string_hash_newfunc
))
542 /* The first entry in the string table is the empty string. */
543 output_debug
->symbolic_header
.issMax
= 1;
546 if (!obstack_begin (&ainfo
->memory
, 4050))
548 bfd_set_error (bfd_error_no_memory
);
555 /* Free the accumulated debugging information. */
559 bfd_ecoff_debug_free (handle
, output_bfd
, output_debug
, output_swap
, info
)
562 struct ecoff_debug_info
*output_debug
;
563 const struct ecoff_debug_swap
*output_swap
;
564 struct bfd_link_info
*info
;
566 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
568 bfd_hash_table_free (&ainfo
->fdr_hash
.table
);
570 if (! info
->relocateable
)
571 bfd_hash_table_free (&ainfo
->str_hash
.table
);
573 obstack_free (&ainfo
->memory
, (PTR
) NULL
);
578 /* Accumulate the debugging information from INPUT_BFD into
579 OUTPUT_BFD. The INPUT_DEBUG argument points to some ECOFF
580 debugging information which we want to link into the information
581 pointed to by the OUTPUT_DEBUG argument. OUTPUT_SWAP and
582 INPUT_SWAP point to the swapping information needed. INFO is the
583 linker information structure. HANDLE is returned by
584 bfd_ecoff_debug_init. */
588 bfd_ecoff_debug_accumulate (handle
, output_bfd
, output_debug
, output_swap
,
589 input_bfd
, input_debug
, input_swap
,
593 struct ecoff_debug_info
*output_debug
;
594 const struct ecoff_debug_swap
*output_swap
;
596 struct ecoff_debug_info
*input_debug
;
597 const struct ecoff_debug_swap
*input_swap
;
598 struct bfd_link_info
*info
;
600 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
601 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
602 = input_swap
->swap_sym_in
;
603 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
604 = input_swap
->swap_rfd_in
;
605 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
606 = output_swap
->swap_sym_out
;
607 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
608 = output_swap
->swap_fdr_out
;
609 void (* const swap_rfd_out
) PARAMS ((bfd
*, const RFDT
*, PTR
))
610 = output_swap
->swap_rfd_out
;
611 bfd_size_type external_pdr_size
= output_swap
->external_pdr_size
;
612 bfd_size_type external_sym_size
= output_swap
->external_sym_size
;
613 bfd_size_type external_opt_size
= output_swap
->external_opt_size
;
614 bfd_size_type external_fdr_size
= output_swap
->external_fdr_size
;
615 bfd_size_type external_rfd_size
= output_swap
->external_rfd_size
;
616 HDRR
* const output_symhdr
= &output_debug
->symbolic_header
;
617 HDRR
* const input_symhdr
= &input_debug
->symbolic_header
;
618 bfd_vma section_adjust
[scMax
];
623 bfd_size_type fdr_add
;
634 /* Use section_adjust to hold the value to add to a symbol in a
635 particular section. */
636 memset ((PTR
) section_adjust
, 0, sizeof section_adjust
);
638 #define SET(name, indx) \
639 sec = bfd_get_section_by_name (input_bfd, name); \
641 section_adjust[indx] = (sec->output_section->vma \
642 + sec->output_offset \
645 SET (".text", scText
);
646 SET (".data", scData
);
648 SET (".sdata", scSData
);
649 SET (".sbss", scSBss
);
650 /* scRdata section may be either .rdata or .rodata. */
651 SET (".rdata", scRData
);
652 SET (".rodata", scRData
);
653 SET (".init", scInit
);
654 SET (".fini", scFini
);
655 SET (".rconst", scRConst
);
659 /* Find all the debugging information based on the FDR's. We need
660 to handle them whether they are swapped or not. */
661 if (input_debug
->fdr
!= (FDR
*) NULL
)
663 fdr_start
= (bfd_byte
*) input_debug
->fdr
;
664 fdr_add
= sizeof (FDR
);
668 fdr_start
= (bfd_byte
*) input_debug
->external_fdr
;
669 fdr_add
= input_swap
->external_fdr_size
;
671 fdr_end
= fdr_start
+ input_symhdr
->ifdMax
* fdr_add
;
673 input_debug
->ifdmap
= (RFDT
*) bfd_alloc (input_bfd
,
674 (input_symhdr
->ifdMax
677 sz
= (input_symhdr
->crfd
+ input_symhdr
->ifdMax
) * external_rfd_size
;
678 rfd_out
= (bfd_byte
*) obstack_alloc (&ainfo
->memory
, sz
);
679 if (!input_debug
->ifdmap
|| !rfd_out
)
681 bfd_set_error (bfd_error_no_memory
);
684 if (!add_memory_shuffle (ainfo
, &ainfo
->rfd
, &ainfo
->rfd_end
, rfd_out
, sz
))
689 /* Look through the FDR's to see which ones we are going to include
690 in the final output. We do not want duplicate FDR information
691 for header files, because ECOFF debugging is often very large.
692 When we find an FDR with no line information which can be merged,
693 we look it up in a hash table to ensure that we only include it
694 once. We keep a table mapping FDR numbers to the final number
695 they get with the BFD, so that we can refer to it when we write
696 out the external symbols. */
697 for (fdr_ptr
= fdr_start
, i
= 0;
699 fdr_ptr
+= fdr_add
, i
++, rfd_out
+= external_rfd_size
)
703 if (input_debug
->fdr
!= (FDR
*) NULL
)
704 fdr
= *(FDR
*) fdr_ptr
;
706 (*input_swap
->swap_fdr_in
) (input_bfd
, (PTR
) fdr_ptr
, &fdr
);
708 /* See if this FDR can be merged with an existing one. */
709 if (fdr
.cbLine
== 0 && fdr
.rss
!= -1 && fdr
.fMerge
)
713 struct string_hash_entry
*fh
;
715 /* We look up a string formed from the file name and the
716 number of symbols. Sometimes an include file will
717 conditionally define a typedef or something based on the
718 order of include files. Using the number of symbols as a
719 hash reduces the chance that we will merge symbol
720 information that should not be merged. */
721 name
= input_debug
->ss
+ fdr
.issBase
+ fdr
.rss
;
723 lookup
= (char *) malloc (strlen (name
) + 20);
726 bfd_set_error (bfd_error_no_memory
);
729 sprintf (lookup
, "%s %lx", name
, fdr
.csym
);
731 fh
= string_hash_lookup (&ainfo
->fdr_hash
, lookup
, true, true);
733 if (fh
== (struct string_hash_entry
*) NULL
)
738 input_debug
->ifdmap
[i
] = fh
->val
;
739 (*swap_rfd_out
) (output_bfd
, input_debug
->ifdmap
+ i
,
742 /* Don't copy this FDR. */
746 fh
->val
= output_symhdr
->ifdMax
+ copied
;
749 input_debug
->ifdmap
[i
] = output_symhdr
->ifdMax
+ copied
;
750 (*swap_rfd_out
) (output_bfd
, input_debug
->ifdmap
+ i
, (PTR
) rfd_out
);
754 newrfdbase
= output_symhdr
->crfd
;
755 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
757 /* Copy over any existing RFD's. RFD's are only created by the
758 linker, so this will only happen for input files which are the
759 result of a partial link. */
760 rfd_in
= (bfd_byte
*) input_debug
->external_rfd
;
761 rfd_end
= rfd_in
+ input_symhdr
->crfd
* input_swap
->external_rfd_size
;
764 rfd_in
+= input_swap
->external_rfd_size
)
768 (*swap_rfd_in
) (input_bfd
, (PTR
) rfd_in
, &rfd
);
769 BFD_ASSERT (rfd
>= 0 && rfd
< input_symhdr
->ifdMax
);
770 rfd
= input_debug
->ifdmap
[rfd
];
771 (*swap_rfd_out
) (output_bfd
, &rfd
, (PTR
) rfd_out
);
772 rfd_out
+= external_rfd_size
;
775 oldrfdbase
= output_symhdr
->crfd
;
776 output_symhdr
->crfd
+= input_symhdr
->crfd
;
778 /* Look through the FDR's and copy over all associated debugging
780 sz
= copied
* external_fdr_size
;
781 fdr_out
= (bfd_byte
*) obstack_alloc (&ainfo
->memory
, sz
);
784 bfd_set_error (bfd_error_no_memory
);
787 if (!add_memory_shuffle (ainfo
, &ainfo
->fdr
, &ainfo
->fdr_end
, fdr_out
, sz
))
789 for (fdr_ptr
= fdr_start
, i
= 0;
791 fdr_ptr
+= fdr_add
, i
++)
798 boolean fgotfilename
;
800 if (input_debug
->ifdmap
[i
] < output_symhdr
->ifdMax
)
802 /* We are not copying this FDR. */
806 if (input_debug
->fdr
!= (FDR
*) NULL
)
807 fdr
= *(FDR
*) fdr_ptr
;
809 (*input_swap
->swap_fdr_in
) (input_bfd
, (PTR
) fdr_ptr
, &fdr
);
813 /* Adjust the FDR address for any changes that may have been
815 if (input_debug
->adjust
!= (struct ecoff_value_adjust
*) NULL
)
817 struct ecoff_value_adjust
*adjust
;
819 for (adjust
= input_debug
->adjust
;
820 adjust
!= (struct ecoff_value_adjust
*) NULL
;
821 adjust
= adjust
->next
)
822 if (fdr_adr
>= adjust
->start
823 && fdr_adr
< adjust
->end
)
824 fdr
.adr
+= adjust
->adjust
;
827 /* FIXME: It is conceivable that this FDR points to the .init or
828 .fini section, in which case this will not do the right
830 fdr
.adr
+= section_adjust
[scText
];
832 /* Swap in the local symbols, adjust their values, and swap them
834 fgotfilename
= false;
835 sz
= fdr
.csym
* external_sym_size
;
836 sym_out
= (bfd_byte
*) obstack_alloc (&ainfo
->memory
, sz
);
839 bfd_set_error (bfd_error_no_memory
);
842 if (!add_memory_shuffle (ainfo
, &ainfo
->sym
, &ainfo
->sym_end
, sym_out
,
845 lraw_src
= ((bfd_byte
*) input_debug
->external_sym
846 + fdr
.isymBase
* input_swap
->external_sym_size
);
847 lraw_end
= lraw_src
+ fdr
.csym
* input_swap
->external_sym_size
;
848 for (; lraw_src
< lraw_end
; lraw_src
+= input_swap
->external_sym_size
)
852 (*swap_sym_in
) (input_bfd
, (PTR
) lraw_src
, &internal_sym
);
854 BFD_ASSERT (internal_sym
.sc
!= scCommon
855 && internal_sym
.sc
!= scSCommon
);
857 /* Adjust the symbol value if appropriate. */
858 switch (internal_sym
.st
)
861 if (ECOFF_IS_STAB (&internal_sym
))
869 if (input_debug
->adjust
!= (struct ecoff_value_adjust
*) NULL
)
872 struct ecoff_value_adjust
*adjust
;
874 value
= internal_sym
.value
;
875 for (adjust
= input_debug
->adjust
;
876 adjust
!= (struct ecoff_value_adjust
*) NULL
;
877 adjust
= adjust
->next
)
878 if (value
>= adjust
->start
879 && value
< adjust
->end
)
880 internal_sym
.value
+= adjust
->adjust
;
882 internal_sym
.value
+= section_adjust
[internal_sym
.sc
];
889 /* If we are doing a final link, we hash all the strings in
890 the local symbol table together. This reduces the amount
891 of space required by debugging information. We don't do
892 this when performing a relocateable link because it would
893 prevent us from easily merging different FDR's. */
894 if (! info
->relocateable
)
899 if (! fgotfilename
&& internal_sym
.iss
== fdr
.rss
)
904 /* Hash the name into the string table. */
905 name
= input_debug
->ss
+ fdr
.issBase
+ internal_sym
.iss
;
907 internal_sym
.iss
= 0;
910 struct string_hash_entry
*sh
;
912 sh
= string_hash_lookup (&ainfo
->str_hash
, name
, true, true);
913 if (sh
== (struct string_hash_entry
*) NULL
)
917 sh
->val
= output_symhdr
->issMax
;
918 output_symhdr
->issMax
+= strlen (name
) + 1;
919 if (ainfo
->ss_hash
== (struct string_hash_entry
*) NULL
)
921 if (ainfo
->ss_hash_end
922 != (struct string_hash_entry
*) NULL
)
923 ainfo
->ss_hash_end
->next
= sh
;
924 ainfo
->ss_hash_end
= sh
;
926 internal_sym
.iss
= sh
->val
;
931 fdr
.rss
= internal_sym
.iss
;
936 (*swap_sym_out
) (output_bfd
, &internal_sym
, sym_out
);
937 sym_out
+= external_sym_size
;
940 fdr
.isymBase
= output_symhdr
->isymMax
;
941 output_symhdr
->isymMax
+= fdr
.csym
;
943 /* Copy the information that does not need swapping. */
945 /* FIXME: If we are relaxing, we need to adjust the line
946 numbers. Frankly, forget it. Anybody using stabs debugging
947 information will not use this line number information, and
948 stabs are adjusted correctly. */
951 if (!add_file_shuffle (ainfo
, &ainfo
->line
, &ainfo
->line_end
,
953 input_symhdr
->cbLineOffset
+ fdr
.cbLineOffset
,
956 fdr
.ilineBase
= output_symhdr
->ilineMax
;
957 fdr
.cbLineOffset
= output_symhdr
->cbLine
;
958 output_symhdr
->ilineMax
+= fdr
.cline
;
959 output_symhdr
->cbLine
+= fdr
.cbLine
;
963 if (!add_file_shuffle (ainfo
, &ainfo
->aux
, &ainfo
->aux_end
,
965 (input_symhdr
->cbAuxOffset
966 + fdr
.iauxBase
* sizeof (union aux_ext
)),
967 fdr
.caux
* sizeof (union aux_ext
)))
969 fdr
.iauxBase
= output_symhdr
->iauxMax
;
970 output_symhdr
->iauxMax
+= fdr
.caux
;
972 if (! info
->relocateable
)
975 /* When are are hashing strings, we lie about the number of
976 strings attached to each FDR. We need to set cbSs
977 because some versions of dbx apparently use it to decide
978 how much of the string table to read in. */
980 fdr
.cbSs
= output_symhdr
->issMax
;
982 else if (fdr
.cbSs
> 0)
984 if (!add_file_shuffle (ainfo
, &ainfo
->ss
, &ainfo
->ss_end
,
986 input_symhdr
->cbSsOffset
+ fdr
.issBase
,
989 fdr
.issBase
= output_symhdr
->issMax
;
990 output_symhdr
->issMax
+= fdr
.cbSs
;
993 if ((output_bfd
->xvec
->header_byteorder_big_p
994 == input_bfd
->xvec
->header_byteorder_big_p
)
995 && input_debug
->adjust
== (struct ecoff_value_adjust
*) NULL
)
997 /* The two BFD's have the same endianness, and we don't have
998 to adjust the PDR addresses, so simply copying the
999 information will suffice. */
1000 BFD_ASSERT (external_pdr_size
== input_swap
->external_pdr_size
);
1003 if (!add_file_shuffle (ainfo
, &ainfo
->pdr
, &ainfo
->pdr_end
,
1005 (input_symhdr
->cbPdOffset
1006 + fdr
.ipdFirst
* external_pdr_size
),
1007 fdr
.cpd
* external_pdr_size
))
1010 BFD_ASSERT (external_opt_size
== input_swap
->external_opt_size
);
1013 if (!add_file_shuffle (ainfo
, &ainfo
->opt
, &ainfo
->opt_end
,
1015 (input_symhdr
->cbOptOffset
1016 + fdr
.ioptBase
* external_opt_size
),
1017 fdr
.copt
* external_opt_size
))
1023 bfd_size_type outsz
, insz
;
1028 /* The two BFD's have different endianness, so we must swap
1029 everything in and out. This code would always work, but
1030 it would be unnecessarily slow in the normal case. */
1031 outsz
= external_pdr_size
;
1032 insz
= input_swap
->external_pdr_size
;
1033 in
= ((bfd_byte
*) input_debug
->external_pdr
1034 + fdr
.ipdFirst
* insz
);
1035 end
= in
+ fdr
.cpd
* insz
;
1036 sz
= fdr
.cpd
* outsz
;
1037 out
= (bfd_byte
*) obstack_alloc (&ainfo
->memory
, sz
);
1040 bfd_set_error (bfd_error_no_memory
);
1043 if (!add_memory_shuffle (ainfo
, &ainfo
->pdr
, &ainfo
->pdr_end
, out
,
1046 for (; in
< end
; in
+= insz
, out
+= outsz
)
1050 (*input_swap
->swap_pdr_in
) (input_bfd
, (PTR
) in
, &pdr
);
1052 /* If we have been relaxing, we may have to adjust the
1054 if (input_debug
->adjust
!= (struct ecoff_value_adjust
*) NULL
)
1057 struct ecoff_value_adjust
*adjust
;
1059 adr
= fdr_adr
+ pdr
.adr
;
1060 for (adjust
= input_debug
->adjust
;
1061 adjust
!= (struct ecoff_value_adjust
*) NULL
;
1062 adjust
= adjust
->next
)
1063 if (adr
>= adjust
->start
1064 && adr
< adjust
->end
)
1065 pdr
.adr
+= adjust
->adjust
;
1068 (*output_swap
->swap_pdr_out
) (output_bfd
, &pdr
, (PTR
) out
);
1071 /* Swap over the optimization information. */
1072 outsz
= external_opt_size
;
1073 insz
= input_swap
->external_opt_size
;
1074 in
= ((bfd_byte
*) input_debug
->external_opt
1075 + fdr
.ioptBase
* insz
);
1076 end
= in
+ fdr
.copt
* insz
;
1077 sz
= fdr
.copt
* outsz
;
1078 out
= (bfd_byte
*) obstack_alloc (&ainfo
->memory
, sz
);
1081 bfd_set_error (bfd_error_no_memory
);
1084 if (!add_memory_shuffle (ainfo
, &ainfo
->opt
, &ainfo
->opt_end
, out
,
1087 for (; in
< end
; in
+= insz
, out
+= outsz
)
1091 (*input_swap
->swap_opt_in
) (input_bfd
, (PTR
) in
, &opt
);
1092 (*output_swap
->swap_opt_out
) (output_bfd
, &opt
, (PTR
) out
);
1096 fdr
.ipdFirst
= output_symhdr
->ipdMax
;
1097 output_symhdr
->ipdMax
+= fdr
.cpd
;
1098 fdr
.ioptBase
= output_symhdr
->ioptMax
;
1099 output_symhdr
->ioptMax
+= fdr
.copt
;
1103 /* Point this FDR at the table of RFD's we created. */
1104 fdr
.rfdBase
= newrfdbase
;
1105 fdr
.crfd
= input_symhdr
->ifdMax
;
1109 /* Point this FDR at the remapped RFD's. */
1110 fdr
.rfdBase
+= oldrfdbase
;
1113 (*swap_fdr_out
) (output_bfd
, &fdr
, fdr_out
);
1114 fdr_out
+= external_fdr_size
;
1115 ++output_symhdr
->ifdMax
;
1121 /* Add a string to the debugging information we are accumulating.
1122 Return the offset from the fdr string base. */
1124 static long ecoff_add_string
PARAMS ((struct accumulate
*,
1125 struct bfd_link_info
*,
1126 struct ecoff_debug_info
*,
1127 FDR
*fdr
, const char *string
));
1130 ecoff_add_string (ainfo
, info
, debug
, fdr
, string
)
1131 struct accumulate
*ainfo
;
1132 struct bfd_link_info
*info
;
1133 struct ecoff_debug_info
*debug
;
1141 symhdr
= &debug
->symbolic_header
;
1142 len
= strlen (string
);
1143 if (info
->relocateable
)
1145 if (!add_memory_shuffle (ainfo
, &ainfo
->ss
, &ainfo
->ss_end
, (PTR
) string
,
1148 ret
= symhdr
->issMax
;
1149 symhdr
->issMax
+= len
+ 1;
1150 fdr
->cbSs
+= len
+ 1;
1154 struct string_hash_entry
*sh
;
1156 sh
= string_hash_lookup (&ainfo
->str_hash
, string
, true, true);
1157 if (sh
== (struct string_hash_entry
*) NULL
)
1161 sh
->val
= symhdr
->issMax
;
1162 symhdr
->issMax
+= len
+ 1;
1163 if (ainfo
->ss_hash
== (struct string_hash_entry
*) NULL
)
1164 ainfo
->ss_hash
= sh
;
1165 if (ainfo
->ss_hash_end
1166 != (struct string_hash_entry
*) NULL
)
1167 ainfo
->ss_hash_end
->next
= sh
;
1168 ainfo
->ss_hash_end
= sh
;
1176 /* Add debugging information from a non-ECOFF file. */
1179 bfd_ecoff_debug_accumulate_other (handle
, output_bfd
, output_debug
,
1180 output_swap
, input_bfd
, info
)
1183 struct ecoff_debug_info
*output_debug
;
1184 const struct ecoff_debug_swap
*output_swap
;
1186 struct bfd_link_info
*info
;
1188 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
1189 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
1190 = output_swap
->swap_sym_out
;
1191 HDRR
*output_symhdr
= &output_debug
->symbolic_header
;
1201 memset ((PTR
) &fdr
, 0, sizeof fdr
);
1203 sec
= bfd_get_section_by_name (input_bfd
, ".text");
1205 fdr
.adr
= sec
->output_section
->vma
+ sec
->output_offset
;
1208 /* FIXME: What about .init or .fini? */
1212 fdr
.issBase
= output_symhdr
->issMax
;
1214 fdr
.rss
= ecoff_add_string (ainfo
, info
, output_debug
, &fdr
,
1215 bfd_get_filename (input_bfd
));
1218 fdr
.isymBase
= output_symhdr
->isymMax
;
1220 /* Get the local symbols from the input BFD. */
1221 symsize
= bfd_get_symtab_upper_bound (input_bfd
);
1224 symbols
= (asymbol
**) bfd_alloc (output_bfd
, symsize
);
1225 if (symbols
== (asymbol
**) NULL
)
1227 symcount
= bfd_canonicalize_symtab (input_bfd
, symbols
);
1230 sym_end
= symbols
+ symcount
;
1232 /* Handle the local symbols. Any external symbols are handled
1235 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
1240 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
1242 memset ((PTR
) &internal_sym
, 0, sizeof internal_sym
);
1243 internal_sym
.iss
= ecoff_add_string (ainfo
, info
, output_debug
, &fdr
,
1246 if (internal_sym
.iss
== -1)
1248 if (bfd_is_com_section ((*sym_ptr
)->section
)
1249 || bfd_is_und_section ((*sym_ptr
)->section
))
1250 internal_sym
.value
= (*sym_ptr
)->value
;
1252 internal_sym
.value
= ((*sym_ptr
)->value
1253 + (*sym_ptr
)->section
->output_offset
1254 + (*sym_ptr
)->section
->output_section
->vma
);
1255 internal_sym
.st
= stNil
;
1256 internal_sym
.sc
= scUndefined
;
1257 internal_sym
.index
= indexNil
;
1259 external_sym
= (PTR
) obstack_alloc (&ainfo
->memory
,
1260 output_swap
->external_sym_size
);
1263 bfd_set_error (bfd_error_no_memory
);
1266 (*swap_sym_out
) (output_bfd
, &internal_sym
, external_sym
);
1267 add_memory_shuffle (ainfo
, &ainfo
->sym
, &ainfo
->sym_end
,
1268 external_sym
, output_swap
->external_sym_size
);
1270 ++output_symhdr
->isymMax
;
1273 bfd_release (output_bfd
, (PTR
) symbols
);
1275 /* Leave everything else in the FDR zeroed out. This will cause
1276 the lang field to be langC. The fBigendian field will
1277 indicate little endian format, but it doesn't matter because
1278 it only applies to aux fields and there are none. */
1279 external_fdr
= (PTR
) obstack_alloc (&ainfo
->memory
,
1280 output_swap
->external_fdr_size
);
1283 bfd_set_error (bfd_error_no_memory
);
1286 (*output_swap
->swap_fdr_out
) (output_bfd
, &fdr
, external_fdr
);
1287 add_memory_shuffle (ainfo
, &ainfo
->fdr
, &ainfo
->fdr_end
,
1288 external_fdr
, output_swap
->external_fdr_size
);
1290 ++output_symhdr
->ifdMax
;
1295 /* Set up ECOFF debugging information for the external symbols.
1296 FIXME: This is done using a memory buffer, but it should be
1297 probably be changed to use a shuffle structure. The assembler uses
1298 this interface, so that must be changed to do something else. */
1301 bfd_ecoff_debug_externals (abfd
, debug
, swap
, relocateable
, get_extr
,
1304 struct ecoff_debug_info
*debug
;
1305 const struct ecoff_debug_swap
*swap
;
1306 boolean relocateable
;
1307 boolean (*get_extr
) PARAMS ((asymbol
*, EXTR
*));
1308 void (*set_index
) PARAMS ((asymbol
*, bfd_size_type
));
1310 HDRR
* const symhdr
= &debug
->symbolic_header
;
1311 asymbol
**sym_ptr_ptr
;
1314 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
1315 if (sym_ptr_ptr
== NULL
)
1318 for (c
= bfd_get_symcount (abfd
); c
> 0; c
--, sym_ptr_ptr
++)
1323 sym_ptr
= *sym_ptr_ptr
;
1325 /* Get the external symbol information. */
1326 if ((*get_extr
) (sym_ptr
, &esym
) == false)
1329 /* If we're producing an executable, move common symbols into
1331 if (relocateable
== false)
1333 if (esym
.asym
.sc
== scCommon
)
1334 esym
.asym
.sc
= scBss
;
1335 else if (esym
.asym
.sc
== scSCommon
)
1336 esym
.asym
.sc
= scSBss
;
1339 if (bfd_is_com_section (sym_ptr
->section
)
1340 || bfd_is_und_section (sym_ptr
->section
)
1341 || sym_ptr
->section
->output_section
== (asection
*) NULL
)
1343 /* FIXME: gas does not keep the value of a small undefined
1344 symbol in the symbol itself, because of relocation
1346 if (esym
.asym
.sc
!= scSUndefined
1347 || esym
.asym
.value
== 0
1348 || sym_ptr
->value
!= 0)
1349 esym
.asym
.value
= sym_ptr
->value
;
1352 esym
.asym
.value
= (sym_ptr
->value
1353 + sym_ptr
->section
->output_offset
1354 + sym_ptr
->section
->output_section
->vma
);
1357 (*set_index
) (sym_ptr
, (bfd_size_type
) symhdr
->iextMax
);
1359 if (! bfd_ecoff_debug_one_external (abfd
, debug
, swap
,
1360 sym_ptr
->name
, &esym
))
1367 /* Add a single external symbol to the debugging information. */
1370 bfd_ecoff_debug_one_external (abfd
, debug
, swap
, name
, esym
)
1372 struct ecoff_debug_info
*debug
;
1373 const struct ecoff_debug_swap
*swap
;
1377 const bfd_size_type external_ext_size
= swap
->external_ext_size
;
1378 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
1379 = swap
->swap_ext_out
;
1380 HDRR
* const symhdr
= &debug
->symbolic_header
;
1383 namelen
= strlen (name
);
1385 if ((size_t) (debug
->ssext_end
- debug
->ssext
)
1386 < symhdr
->issExtMax
+ namelen
+ 1)
1388 if (ecoff_add_bytes ((char **) &debug
->ssext
,
1389 (char **) &debug
->ssext_end
,
1390 symhdr
->issExtMax
+ namelen
+ 1)
1394 if ((size_t) ((char *) debug
->external_ext_end
1395 - (char *) debug
->external_ext
)
1396 < (symhdr
->iextMax
+ 1) * external_ext_size
)
1398 if (ecoff_add_bytes ((char **) &debug
->external_ext
,
1399 (char **) &debug
->external_ext_end
,
1400 (symhdr
->iextMax
+ 1) * external_ext_size
)
1405 esym
->asym
.iss
= symhdr
->issExtMax
;
1407 (*swap_ext_out
) (abfd
, esym
,
1408 ((char *) debug
->external_ext
1409 + symhdr
->iextMax
* swap
->external_ext_size
));
1413 strcpy (debug
->ssext
+ symhdr
->issExtMax
, name
);
1414 symhdr
->issExtMax
+= namelen
+ 1;
1419 /* Align the ECOFF debugging information. */
1423 ecoff_align_debug (abfd
, debug
, swap
)
1425 struct ecoff_debug_info
*debug
;
1426 const struct ecoff_debug_swap
*swap
;
1428 HDRR
* const symhdr
= &debug
->symbolic_header
;
1429 bfd_size_type debug_align
, aux_align
, rfd_align
;
1432 /* Adjust the counts so that structures are aligned. */
1433 debug_align
= swap
->debug_align
;
1434 aux_align
= debug_align
/ sizeof (union aux_ext
);
1435 rfd_align
= debug_align
/ swap
->external_rfd_size
;
1437 add
= debug_align
- (symhdr
->cbLine
& (debug_align
- 1));
1438 if (add
!= debug_align
)
1440 if (debug
->line
!= (unsigned char *) NULL
)
1441 memset ((PTR
) (debug
->line
+ symhdr
->cbLine
), 0, add
);
1442 symhdr
->cbLine
+= add
;
1445 add
= debug_align
- (symhdr
->issMax
& (debug_align
- 1));
1446 if (add
!= debug_align
)
1448 if (debug
->ss
!= (char *) NULL
)
1449 memset ((PTR
) (debug
->ss
+ symhdr
->issMax
), 0, add
);
1450 symhdr
->issMax
+= add
;
1453 add
= debug_align
- (symhdr
->issExtMax
& (debug_align
- 1));
1454 if (add
!= debug_align
)
1456 if (debug
->ssext
!= (char *) NULL
)
1457 memset ((PTR
) (debug
->ssext
+ symhdr
->issExtMax
), 0, add
);
1458 symhdr
->issExtMax
+= add
;
1461 add
= aux_align
- (symhdr
->iauxMax
& (aux_align
- 1));
1462 if (add
!= aux_align
)
1464 if (debug
->external_aux
!= (union aux_ext
*) NULL
)
1465 memset ((PTR
) (debug
->external_aux
+ symhdr
->iauxMax
), 0,
1466 add
* sizeof (union aux_ext
));
1467 symhdr
->iauxMax
+= add
;
1470 add
= rfd_align
- (symhdr
->crfd
& (rfd_align
- 1));
1471 if (add
!= rfd_align
)
1473 if (debug
->external_rfd
!= (PTR
) NULL
)
1474 memset ((PTR
) ((char *) debug
->external_rfd
1475 + symhdr
->crfd
* swap
->external_rfd_size
),
1476 0, (size_t) (add
* swap
->external_rfd_size
));
1477 symhdr
->crfd
+= add
;
1481 /* Return the size required by the ECOFF debugging information. */
1484 bfd_ecoff_debug_size (abfd
, debug
, swap
)
1486 struct ecoff_debug_info
*debug
;
1487 const struct ecoff_debug_swap
*swap
;
1491 ecoff_align_debug (abfd
, debug
, swap
);
1492 tot
= swap
->external_hdr_size
;
1494 #define ADD(count, size) \
1495 tot += debug->symbolic_header.count * size
1497 ADD (cbLine
, sizeof (unsigned char));
1498 ADD (idnMax
, swap
->external_dnr_size
);
1499 ADD (ipdMax
, swap
->external_pdr_size
);
1500 ADD (isymMax
, swap
->external_sym_size
);
1501 ADD (ioptMax
, swap
->external_opt_size
);
1502 ADD (iauxMax
, sizeof (union aux_ext
));
1503 ADD (issMax
, sizeof (char));
1504 ADD (issExtMax
, sizeof (char));
1505 ADD (ifdMax
, swap
->external_fdr_size
);
1506 ADD (crfd
, swap
->external_rfd_size
);
1507 ADD (iextMax
, swap
->external_ext_size
);
1514 /* Write out the ECOFF symbolic header, given the file position it is
1515 going to be placed at. This assumes that the counts are set
1519 ecoff_write_symhdr (abfd
, debug
, swap
, where
)
1521 struct ecoff_debug_info
*debug
;
1522 const struct ecoff_debug_swap
*swap
;
1525 HDRR
* const symhdr
= &debug
->symbolic_header
;
1528 ecoff_align_debug (abfd
, debug
, swap
);
1530 /* Go to the right location in the file. */
1531 if (bfd_seek (abfd
, where
, SEEK_SET
) != 0)
1534 where
+= swap
->external_hdr_size
;
1536 symhdr
->magic
= swap
->sym_magic
;
1538 /* Fill in the file offsets. */
1539 #define SET(offset, count, size) \
1540 if (symhdr->count == 0) \
1541 symhdr->offset = 0; \
1544 symhdr->offset = where; \
1545 where += symhdr->count * size; \
1548 SET (cbLineOffset
, cbLine
, sizeof (unsigned char));
1549 SET (cbDnOffset
, idnMax
, swap
->external_dnr_size
);
1550 SET (cbPdOffset
, ipdMax
, swap
->external_pdr_size
);
1551 SET (cbSymOffset
, isymMax
, swap
->external_sym_size
);
1552 SET (cbOptOffset
, ioptMax
, swap
->external_opt_size
);
1553 SET (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
1554 SET (cbSsOffset
, issMax
, sizeof (char));
1555 SET (cbSsExtOffset
, issExtMax
, sizeof (char));
1556 SET (cbFdOffset
, ifdMax
, swap
->external_fdr_size
);
1557 SET (cbRfdOffset
, crfd
, swap
->external_rfd_size
);
1558 SET (cbExtOffset
, iextMax
, swap
->external_ext_size
);
1561 buff
= (PTR
) malloc ((size_t) swap
->external_hdr_size
);
1562 if (buff
== NULL
&& swap
->external_hdr_size
!= 0)
1564 bfd_set_error (bfd_error_no_memory
);
1568 (*swap
->swap_hdr_out
) (abfd
, symhdr
, buff
);
1569 if (bfd_write (buff
, 1, swap
->external_hdr_size
, abfd
)
1570 != swap
->external_hdr_size
)
1582 /* Write out the ECOFF debugging information. This function assumes
1583 that the information (the pointers and counts) in *DEBUG have been
1584 set correctly. WHERE is the position in the file to write the
1585 information to. This function fills in the file offsets in the
1589 bfd_ecoff_write_debug (abfd
, debug
, swap
, where
)
1591 struct ecoff_debug_info
*debug
;
1592 const struct ecoff_debug_swap
*swap
;
1595 HDRR
* const symhdr
= &debug
->symbolic_header
;
1597 if (! ecoff_write_symhdr (abfd
, debug
, swap
, where
))
1600 #define WRITE(ptr, count, size, offset) \
1601 BFD_ASSERT (symhdr->offset == 0 \
1602 || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
1603 if (bfd_write ((PTR) debug->ptr, size, symhdr->count, abfd) \
1604 != size * symhdr->count) \
1607 WRITE (line
, cbLine
, sizeof (unsigned char), cbLineOffset
);
1608 WRITE (external_dnr
, idnMax
, swap
->external_dnr_size
, cbDnOffset
);
1609 WRITE (external_pdr
, ipdMax
, swap
->external_pdr_size
, cbPdOffset
);
1610 WRITE (external_sym
, isymMax
, swap
->external_sym_size
, cbSymOffset
);
1611 WRITE (external_opt
, ioptMax
, swap
->external_opt_size
, cbOptOffset
);
1612 WRITE (external_aux
, iauxMax
, sizeof (union aux_ext
), cbAuxOffset
);
1613 WRITE (ss
, issMax
, sizeof (char), cbSsOffset
);
1614 WRITE (ssext
, issExtMax
, sizeof (char), cbSsExtOffset
);
1615 WRITE (external_fdr
, ifdMax
, swap
->external_fdr_size
, cbFdOffset
);
1616 WRITE (external_rfd
, crfd
, swap
->external_rfd_size
, cbRfdOffset
);
1617 WRITE (external_ext
, iextMax
, swap
->external_ext_size
, cbExtOffset
);
1623 /* Write out a shuffle list. */
1625 static boolean ecoff_write_shuffle
PARAMS ((bfd
*,
1626 const struct ecoff_debug_swap
*,
1627 struct shuffle
*, PTR space
));
1630 ecoff_write_shuffle (abfd
, swap
, shuffle
, space
)
1632 const struct ecoff_debug_swap
*swap
;
1633 struct shuffle
*shuffle
;
1636 register struct shuffle
*l
;
1637 unsigned long total
;
1640 for (l
= shuffle
; l
!= (struct shuffle
*) NULL
; l
= l
->next
)
1644 if (bfd_write (l
->u
.memory
, 1, l
->size
, abfd
) != l
->size
)
1649 if (bfd_seek (l
->u
.file
.input_bfd
, l
->u
.file
.offset
, SEEK_SET
) != 0
1650 || bfd_read (space
, 1, l
->size
, l
->u
.file
.input_bfd
) != l
->size
1651 || bfd_write (space
, 1, l
->size
, abfd
) != l
->size
)
1657 if ((total
& (swap
->debug_align
- 1)) != 0)
1662 i
= swap
->debug_align
- (total
& (swap
->debug_align
- 1));
1663 s
= (bfd_byte
*) malloc (i
);
1664 if (s
== NULL
&& i
!= 0)
1666 bfd_set_error (bfd_error_no_memory
);
1670 memset ((PTR
) s
, 0, i
);
1671 if (bfd_write ((PTR
) s
, 1, i
, abfd
) != i
)
1682 /* Write out debugging information using accumulated linker
1686 bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
, swap
, info
, where
)
1689 struct ecoff_debug_info
*debug
;
1690 const struct ecoff_debug_swap
*swap
;
1691 struct bfd_link_info
*info
;
1694 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
1697 if (! ecoff_write_symhdr (abfd
, debug
, swap
, where
))
1700 space
= (PTR
) malloc (ainfo
->largest_file_shuffle
);
1701 if (space
== NULL
&& ainfo
->largest_file_shuffle
!= 0)
1703 bfd_set_error (bfd_error_no_memory
);
1707 if (! ecoff_write_shuffle (abfd
, swap
, ainfo
->line
, space
)
1708 || ! ecoff_write_shuffle (abfd
, swap
, ainfo
->pdr
, space
)
1709 || ! ecoff_write_shuffle (abfd
, swap
, ainfo
->sym
, space
)
1710 || ! ecoff_write_shuffle (abfd
, swap
, ainfo
->opt
, space
)
1711 || ! ecoff_write_shuffle (abfd
, swap
, ainfo
->aux
, space
))
1714 /* The string table is written out from the hash table if this is a
1716 if (info
->relocateable
)
1718 BFD_ASSERT (ainfo
->ss_hash
== (struct string_hash_entry
*) NULL
);
1719 if (! ecoff_write_shuffle (abfd
, swap
, ainfo
->ss
, space
))
1724 unsigned long total
;
1726 struct string_hash_entry
*sh
;
1728 BFD_ASSERT (ainfo
->ss
== (struct shuffle
*) NULL
);
1730 if (bfd_write ((PTR
) &null
, 1, 1, abfd
) != 1)
1733 BFD_ASSERT (ainfo
->ss_hash
== NULL
|| ainfo
->ss_hash
->val
== 1);
1734 for (sh
= ainfo
->ss_hash
;
1735 sh
!= (struct string_hash_entry
*) NULL
;
1740 len
= strlen (sh
->root
.string
);
1741 if (bfd_write ((PTR
) sh
->root
.string
, 1, len
+ 1, abfd
) != len
+ 1)
1746 if ((total
& (swap
->debug_align
- 1)) != 0)
1751 i
= swap
->debug_align
- (total
& (swap
->debug_align
- 1));
1752 s
= (bfd_byte
*) malloc (i
);
1753 if (s
== NULL
&& i
!= 0)
1755 bfd_set_error (bfd_error_no_memory
);
1758 memset ((PTR
) s
, 0, i
);
1759 if (bfd_write ((PTR
) s
, 1, i
, abfd
) != i
)
1768 /* The external strings and symbol are not converted over to using
1769 shuffles. FIXME: They probably should be. */
1770 if (bfd_write (debug
->ssext
, 1, debug
->symbolic_header
.issExtMax
, abfd
)
1771 != (bfd_size_type
) debug
->symbolic_header
.issExtMax
)
1773 if ((debug
->symbolic_header
.issExtMax
& (swap
->debug_align
- 1)) != 0)
1778 i
= (swap
->debug_align
1779 - (debug
->symbolic_header
.issExtMax
& (swap
->debug_align
- 1)));
1780 s
= (bfd_byte
*) malloc (i
);
1781 if (s
== NULL
&& i
!= 0)
1783 bfd_set_error (bfd_error_no_memory
);
1786 memset ((PTR
) s
, 0, i
);
1787 if (bfd_write ((PTR
) s
, 1, i
, abfd
) != i
)
1795 if (! ecoff_write_shuffle (abfd
, swap
, ainfo
->fdr
, space
)
1796 || ! ecoff_write_shuffle (abfd
, swap
, ainfo
->rfd
, space
))
1799 BFD_ASSERT (debug
->symbolic_header
.cbExtOffset
== 0
1800 || (debug
->symbolic_header
.cbExtOffset
1801 == (bfd_vma
) bfd_tell (abfd
)));
1803 if (bfd_write (debug
->external_ext
, swap
->external_ext_size
,
1804 debug
->symbolic_header
.iextMax
, abfd
)
1805 != debug
->symbolic_header
.iextMax
* swap
->external_ext_size
)
1818 /* Handle the find_nearest_line function for both ECOFF and MIPS ELF
1821 /* Compare FDR entries. This is called via qsort. */
1824 cmp_fdrtab_entry (leftp
, rightp
)
1828 const struct ecoff_fdrtab_entry
*lp
=
1829 (const struct ecoff_fdrtab_entry
*) leftp
;
1830 const struct ecoff_fdrtab_entry
*rp
=
1831 (const struct ecoff_fdrtab_entry
*) rightp
;
1833 if (lp
->base_addr
< rp
->base_addr
)
1835 if (lp
->base_addr
> rp
->base_addr
)
1840 /* Each file descriptor (FDR) has a memory address, to simplify
1841 looking up an FDR by address, we build a table covering all FDRs
1842 that have a least one procedure descriptor in them. The final
1843 table will be sorted by address so we can look it up via binary
1847 mk_fdrtab (abfd
, debug_info
, debug_swap
, line_info
)
1849 struct ecoff_debug_info
* const debug_info
;
1850 const struct ecoff_debug_swap
* const debug_swap
;
1851 struct ecoff_find_line
*line_info
;
1853 struct ecoff_fdrtab_entry
*tab
;
1860 fdr_start
= debug_info
->fdr
;
1861 fdr_end
= fdr_start
+ debug_info
->symbolic_header
.ifdMax
;
1863 /* First, let's see how long the table needs to be: */
1864 for (len
= 0, fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1866 if (fdr_ptr
->cpd
== 0) /* skip FDRs that have no PDRs */
1871 /* Now, create and fill in the table: */
1873 line_info
->fdrtab
= ((struct ecoff_fdrtab_entry
*)
1875 len
* sizeof (struct ecoff_fdrtab_entry
)));
1876 if (line_info
->fdrtab
== NULL
)
1878 line_info
->fdrtab_len
= len
;
1880 tab
= line_info
->fdrtab
;
1881 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1883 if (fdr_ptr
->cpd
== 0)
1886 /* Check whether this file has stabs debugging information. In
1887 a file with stabs debugging information, the second local
1888 symbol is named @stabs. */
1890 if (fdr_ptr
->csym
>= 2)
1895 sym_ptr
= ((char *) debug_info
->external_sym
1896 + (fdr_ptr
->isymBase
+ 1)*debug_swap
->external_sym_size
);
1897 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
1898 if (strcmp (debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
,
1905 bfd_size_type external_pdr_size
;
1909 external_pdr_size
= debug_swap
->external_pdr_size
;
1911 pdr_ptr
= ((char *) debug_info
->external_pdr
1912 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1913 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1914 /* The address of the first PDR is the offset of that
1915 procedure relative to the beginning of file FDR. */
1916 tab
->base_addr
= fdr_ptr
->adr
- pdr
.adr
;
1920 /* XXX I don't know about stabs, so this is a guess
1921 (davidm@cs.arizona.edu): */
1922 tab
->base_addr
= fdr_ptr
->adr
;
1928 /* Finally, the table is sorted in increasing memory-address order.
1929 The table is mostly sorted already, but there are cases (e.g.,
1930 static functions in include files), where this does not hold.
1931 Use "odump -PFv" to verify... */
1932 qsort ((PTR
) line_info
->fdrtab
, len
,
1933 sizeof (struct ecoff_fdrtab_entry
), cmp_fdrtab_entry
);
1938 /* Return index of first FDR that covers to OFFSET. */
1941 fdrtab_lookup (line_info
, offset
)
1942 struct ecoff_find_line
*line_info
;
1945 long low
, high
, len
;
1947 struct ecoff_fdrtab_entry
*tab
;
1949 len
= line_info
->fdrtab_len
;
1953 tab
= line_info
->fdrtab
;
1954 for (low
= 0, high
= len
- 1 ; low
!= high
;)
1956 mid
= (high
+ low
) / 2;
1957 if (offset
>= tab
[mid
].base_addr
&& offset
< tab
[mid
+ 1].base_addr
)
1960 if (tab
[mid
].base_addr
> offset
)
1967 /* last entry is catch-all for all higher addresses: */
1968 if (offset
< tab
[mid
].base_addr
)
1973 while (mid
> 0 && tab
[mid
- 1].base_addr
== tab
[mid
].base_addr
)
1979 /* Do the work of find_nearest_line. */
1982 _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
, debug_swap
,
1983 line_info
, filename_ptr
, functionname_ptr
, retline_ptr
)
1987 struct ecoff_debug_info
* const debug_info
;
1988 const struct ecoff_debug_swap
* const debug_swap
;
1989 struct ecoff_find_line
*line_info
;
1990 const char **filename_ptr
;
1991 const char **functionname_ptr
;
1992 unsigned int *retline_ptr
;
1994 struct ecoff_fdrtab_entry
*tab
;
1999 offset
+= section
->vma
;
2001 /* Build FDR table (sorted by object file's base-address) if we
2002 don't have it already. */
2003 if (line_info
->fdrtab
== NULL
2004 && !mk_fdrtab (abfd
, debug_info
, debug_swap
, line_info
))
2007 tab
= line_info
->fdrtab
;
2009 /* find first FDR for address OFFSET */
2010 i
= fdrtab_lookup (line_info
, offset
);
2012 return false; /* no FDR, no fun... */
2013 fdr_ptr
= tab
[i
].fdr
;
2015 /* Check whether this file has stabs debugging information. In a
2016 file with stabs debugging information, the second local symbol is
2019 if (fdr_ptr
->csym
>= 2)
2024 sym_ptr
= ((char *) debug_info
->external_sym
2025 + (fdr_ptr
->isymBase
+ 1) * debug_swap
->external_sym_size
);
2026 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
2027 if (strcmp (debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
,
2034 bfd_size_type external_pdr_size
;
2036 char *best_pdr
= NULL
;
2038 bfd_vma best_dist
= ~0;
2040 unsigned char *line_ptr
;
2041 unsigned char *line_end
;
2043 /* This file uses ECOFF debugging information. Each FDR has a
2044 list of procedure descriptors (PDR). The address in the FDR
2045 is the absolute address of the first procedure. The address
2046 in the first PDR gives the offset of that procedure relative
2047 to the object file's base-address. The addresses in
2048 subsequent PDRs specify each procedure's address relative to
2049 the object file's base-address. To make things more juicy,
2050 whenever the PROF bit in the PDR is set, the real entry point
2051 of the procedure may be 16 bytes below what would normally be
2052 the procedure's entry point. Instead, DEC came up with a
2053 wicked scheme to create profiled libraries "on the fly":
2054 instead of shipping a regular and a profiled version of each
2055 library, they insert 16 bytes of unused space in front of
2056 each procedure and set the "prof" bit in the PDR to indicate
2057 that there is a gap there (this is done automagically by "as"
2058 when option "-pg" is specified). Thus, normally, you link
2059 against such a library and, except for lots of 16 byte gaps
2060 between functions, things will behave as usual. However,
2061 when invoking "ld" with option "-pg", it will fill those gaps
2062 with code that calls mcount(). It then moves the function's
2063 entry point down by 16 bytes, and out pops a binary that has
2064 all functions profiled.
2066 NOTE: Neither FDRs nor PDRs are strictly sorted in memory
2067 order. For example, when including header-files that
2068 define functions, the FDRs follow behind the including
2069 file, even though their code may have been generated at
2070 a lower address. File coff-alpha.c from libbfd
2071 illustrates this (use "odump -PFv" to look at a file's
2072 FDR/PDR). Similarly, PDRs are sometimes out of order
2073 as well. An example of this is OSF/1 v3.0 libc's
2074 malloc.c. I'm not sure why this happens, but it could
2075 be due to optimizations that reorder a function's
2076 position within an object-file.
2080 On the first call to this function, we build a table of FDRs
2081 that is sorted by the base-address of the object-file the FDR
2082 is referring to. Notice that each object-file may contain
2083 code from multiple source files (e.g., due to code defined in
2084 include files). Thus, for any given base-address, there may
2085 be multiple FDRs (but this case is, fortunately, uncommon).
2086 lookup(addr) guarantees to return the first FDR that applies
2087 to address ADDR. Thus, after invoking lookup(), we have a
2088 list of FDRs that may contain the PDR for ADDR. Next, we
2089 walk through the PDRs of these FDRs and locate the one that
2090 is closest to ADDR (i.e., for which the difference between
2091 ADDR and the PDR's entry point is positive and minimal).
2092 Once, the right FDR and PDR are located, we simply walk
2093 through the line-number table to lookup the line-number that
2094 best matches ADDR. Obviously, things could be sped up by
2095 keeping a sorted list of PDRs instead of a sorted list of
2096 FDRs. However, this would increase space requirements
2097 considerably, which is undesirable. */
2098 external_pdr_size
= debug_swap
->external_pdr_size
;
2100 /* Make offset relative to object file's start-address: */
2101 offset
-= tab
[i
].base_addr
;
2102 /* Search FDR list starting at tab[i] for the PDR that best matches
2103 OFFSET. Normally, the FDR list is only one entry long. */
2107 bfd_vma dist
, min_dist
= 0;
2111 fdr_ptr
= tab
[i
].fdr
;
2113 pdr_ptr
= ((char *) debug_info
->external_pdr
2114 + fdr_ptr
->ipdFirst
* external_pdr_size
);
2115 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
2116 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2117 /* Find PDR that is closest to OFFSET. If pdr.prof is set,
2118 the procedure entry-point *may* be 0x10 below pdr.adr. We
2119 simply pretend that pdr.prof *implies* a lower entry-point.
2120 This is safe because it just means that may identify 4 NOPs
2121 in front of the function as belonging to the function. */
2122 for (pdr_hold
= NULL
;
2124 (pdr_ptr
+= external_pdr_size
,
2125 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
)))
2127 if (offset
>= (pdr
.adr
- 0x10 * pdr
.prof
))
2129 dist
= offset
- (pdr
.adr
- 0x10 * pdr
.prof
);
2130 if (!pdr_hold
|| dist
< min_dist
)
2138 if (!best_pdr
|| min_dist
< best_dist
)
2140 best_dist
= min_dist
;
2142 best_pdr
= pdr_hold
;
2144 /* continue looping until base_addr of next entry is different: */
2146 while (++i
< line_info
->fdrtab_len
2147 && tab
[i
].base_addr
== tab
[i
- 1].base_addr
);
2149 if (!best_fdr
|| !best_pdr
)
2150 return false; /* shouldn't happen... */
2152 /* phew, finally we got something that we can hold onto: */
2155 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2156 /* Now we can look for the actual line number. The line numbers
2157 are stored in a very funky format, which I won't try to
2158 describe. The search is bounded by the end of the FDRs line
2160 line_end
= debug_info
->line
+ fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2162 /* Make offset relative to procedure entry: */
2163 offset
-= pdr
.adr
- 0x10 * pdr
.prof
;
2165 line_ptr
= debug_info
->line
+ fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2166 while (line_ptr
< line_end
)
2171 delta
= *line_ptr
>> 4;
2174 count
= (*line_ptr
& 0xf) + 1;
2178 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2179 if (delta
>= 0x8000)
2184 if (offset
< count
* 4)
2186 offset
-= count
* 4;
2189 /* If fdr_ptr->rss is -1, then this file does not have full
2190 symbols, at least according to gdb/mipsread.c. */
2191 if (fdr_ptr
->rss
== -1)
2193 *filename_ptr
= NULL
;
2195 *functionname_ptr
= NULL
;
2200 (*debug_swap
->swap_ext_in
)
2202 ((char *) debug_info
->external_ext
2203 + pdr
.isym
* debug_swap
->external_ext_size
),
2205 *functionname_ptr
= debug_info
->ssext
+ proc_ext
.asym
.iss
;
2212 *filename_ptr
= debug_info
->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2213 (*debug_swap
->swap_sym_in
)
2215 ((char *) debug_info
->external_sym
2216 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2218 *functionname_ptr
= debug_info
->ss
+ fdr_ptr
->issBase
+ proc_sym
.iss
;
2220 if (lineno
== ilineNil
)
2222 *retline_ptr
= lineno
;
2226 bfd_size_type external_sym_size
;
2227 const char *directory_name
;
2228 const char *main_file_name
;
2229 const char *current_file_name
;
2230 const char *function_name
;
2231 const char *line_file_name
;
2232 bfd_vma low_func_vma
;
2233 bfd_vma low_line_vma
;
2236 char *sym_ptr
, *sym_ptr_end
;
2237 size_t len
, funclen
;
2238 char *buffer
= NULL
;
2240 /* This file uses stabs debugging information. When gcc is not
2241 optimizing, it will put the line number information before
2242 the function name stabs entry. When gcc is optimizing, it
2243 will put the stabs entry for all the function first, followed
2244 by the line number information. (This appears to happen
2245 because of the two output files used by the -mgpopt switch,
2246 which is implied by -O). This means that we must keep
2247 looking through the symbols until we find both a line number
2248 and a function name which are beyond the address we want. */
2250 *filename_ptr
= NULL
;
2251 *functionname_ptr
= NULL
;
2254 directory_name
= NULL
;
2255 main_file_name
= NULL
;
2256 current_file_name
= NULL
;
2257 function_name
= NULL
;
2258 line_file_name
= NULL
;
2264 external_sym_size
= debug_swap
->external_sym_size
;
2266 sym_ptr
= ((char *) debug_info
->external_sym
2267 + (fdr_ptr
->isymBase
+ 2) * external_sym_size
);
2268 sym_ptr_end
= sym_ptr
+ (fdr_ptr
->csym
- 2) * external_sym_size
;
2270 sym_ptr
< sym_ptr_end
&& (! past_line
|| ! past_fn
);
2271 sym_ptr
+= external_sym_size
)
2275 (*debug_swap
->swap_sym_in
) (abfd
, sym_ptr
, &sym
);
2277 if (ECOFF_IS_STAB (&sym
))
2279 switch (ECOFF_UNMARK_STAB (sym
.index
))
2282 main_file_name
= current_file_name
=
2283 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2285 /* Check the next symbol to see if it is also an
2287 if (sym_ptr
+ external_sym_size
< sym_ptr_end
)
2291 (*debug_swap
->swap_sym_in
) (abfd
,
2292 sym_ptr
+ external_sym_size
,
2294 if (ECOFF_IS_STAB (&nextsym
)
2295 && ECOFF_UNMARK_STAB (nextsym
.index
) == N_SO
)
2297 directory_name
= current_file_name
;
2298 main_file_name
= current_file_name
=
2299 debug_info
->ss
+ fdr_ptr
->issBase
+ nextsym
.iss
;
2300 sym_ptr
+= external_sym_size
;
2307 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2311 if (sym
.value
> offset
)
2313 else if (sym
.value
>= low_func_vma
)
2315 low_func_vma
= sym
.value
;
2317 debug_info
->ss
+ fdr_ptr
->issBase
+ sym
.iss
;
2322 else if (sym
.st
== stLabel
&& sym
.index
!= indexNil
)
2324 if (sym
.value
> offset
)
2326 else if (sym
.value
>= low_line_vma
)
2328 low_line_vma
= sym
.value
;
2329 line_file_name
= current_file_name
;
2330 *retline_ptr
= sym
.index
;
2335 if (*retline_ptr
!= 0)
2336 main_file_name
= line_file_name
;
2338 /* We need to remove the stuff after the colon in the function
2339 name. We also need to put the directory name and the file
2341 if (function_name
== NULL
)
2344 len
= funclen
= strlen (function_name
) + 1;
2346 if (main_file_name
!= NULL
2347 && directory_name
!= NULL
2348 && main_file_name
[0] != '/')
2349 len
+= strlen (directory_name
) + strlen (main_file_name
) + 1;
2353 if (line_info
->find_buffer
!= NULL
)
2354 free (line_info
->find_buffer
);
2355 buffer
= (char *) malloc (len
);
2358 bfd_set_error (bfd_error_no_memory
);
2361 line_info
->find_buffer
= buffer
;
2364 if (function_name
!= NULL
)
2368 strcpy (buffer
, function_name
);
2369 colon
= strchr (buffer
, ':');
2372 *functionname_ptr
= buffer
;
2375 if (main_file_name
!= NULL
)
2377 if (directory_name
== NULL
|| main_file_name
[0] == '/')
2378 *filename_ptr
= main_file_name
;
2381 sprintf (buffer
+ funclen
, "%s%s", directory_name
,
2383 *filename_ptr
= buffer
+ funclen
;
2391 /* These routines copy symbolic information into a memory buffer.
2393 FIXME: The whole point of the shuffle code is to avoid storing
2394 everything in memory, since the linker is such a memory hog. This
2395 code makes that effort useless. It is only called by the MIPS ELF
2396 code when generating a shared library, so it is not that big a
2397 deal, but it should be fixed eventually. */
2399 /* Collect a shuffle into a memory buffer. */
2401 static boolean ecoff_collect_shuffle
PARAMS ((struct shuffle
*, bfd_byte
*));
2404 ecoff_collect_shuffle (l
, buff
)
2408 unsigned long total
;
2411 for (; l
!= (struct shuffle
*) NULL
; l
= l
->next
)
2414 memcpy (buff
, l
->u
.memory
, l
->size
);
2417 if (bfd_seek (l
->u
.file
.input_bfd
, l
->u
.file
.offset
, SEEK_SET
) != 0
2418 || bfd_read (buff
, 1, l
->size
, l
->u
.file
.input_bfd
) != l
->size
)
2428 /* Copy PDR information into a memory buffer. */
2431 _bfd_ecoff_get_accumulated_pdr (handle
, buff
)
2435 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
2437 return ecoff_collect_shuffle (ainfo
->pdr
, buff
);
2440 /* Copy symbol information into a memory buffer. */
2443 _bfd_ecoff_get_accumulated_sym (handle
, buff
)
2447 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
2449 return ecoff_collect_shuffle (ainfo
->sym
, buff
);
2452 /* Copy the string table into a memory buffer. */
2455 _bfd_ecoff_get_accumulated_ss (handle
, buff
)
2459 struct accumulate
*ainfo
= (struct accumulate
*) handle
;
2460 struct string_hash_entry
*sh
;
2461 unsigned long total
;
2463 /* The string table is written out from the hash table if this is a
2465 BFD_ASSERT (ainfo
->ss
== (struct shuffle
*) NULL
);
2468 BFD_ASSERT (ainfo
->ss_hash
== NULL
|| ainfo
->ss_hash
->val
== 1);
2469 for (sh
= ainfo
->ss_hash
;
2470 sh
!= (struct string_hash_entry
*) NULL
;
2475 len
= strlen (sh
->root
.string
);
2476 memcpy (buff
, (PTR
) sh
->root
.string
, len
+ 1);