Deleted Added
full compact
ecofflink.c (104834) ecofflink.c (130561)
1/* Routines to link ECOFF debugging information.
1/* Routines to link ECOFF debugging information.
2 Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002
2 Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
5
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
5
6This file is part of BFD, the Binary File Descriptor library.
6 This file is part of BFD, the Binary File Descriptor library.
7
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "bfdlink.h"
25#include "libbfd.h"
26#include "objalloc.h"
27#include "aout/stab_gnu.h"
28#include "coff/internal.h"
29#include "coff/sym.h"
30#include "coff/symconst.h"
31#include "coff/ecoff.h"
32#include "libcoff.h"
33#include "libecoff.h"
34
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "bfdlink.h"
25#include "libbfd.h"
26#include "objalloc.h"
27#include "aout/stab_gnu.h"
28#include "coff/internal.h"
29#include "coff/sym.h"
30#include "coff/symconst.h"
31#include "coff/ecoff.h"
32#include "libcoff.h"
33#include "libecoff.h"
34
35static boolean ecoff_add_bytes PARAMS ((char **buf, char **bufend,
36 size_t need));
35static bfd_boolean ecoff_add_bytes
36 PARAMS ((char **buf, char **bufend, size_t need));
37static struct bfd_hash_entry *string_hash_newfunc
38 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
39 const char *));
37static struct bfd_hash_entry *string_hash_newfunc
38 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
39 const char *));
40static void ecoff_align_debug PARAMS ((bfd *abfd,
41 struct ecoff_debug_info *debug,
42 const struct ecoff_debug_swap *swap));
43static boolean ecoff_write_symhdr PARAMS ((bfd *, struct ecoff_debug_info *,
44 const struct ecoff_debug_swap *,
45 file_ptr where));
46static int cmp_fdrtab_entry PARAMS ((const PTR, const PTR));
47static boolean mk_fdrtab PARAMS ((bfd *,
48 struct ecoff_debug_info * const,
49 const struct ecoff_debug_swap * const,
50 struct ecoff_find_line *));
51static long fdrtab_lookup PARAMS ((struct ecoff_find_line *, bfd_vma));
52static boolean lookup_line
40static void ecoff_align_debug
41 PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
42 const struct ecoff_debug_swap *swap));
43static bfd_boolean ecoff_write_symhdr
44 PARAMS ((bfd *, struct ecoff_debug_info *, const struct ecoff_debug_swap *,
45 file_ptr where));
46static int cmp_fdrtab_entry
47 PARAMS ((const PTR, const PTR));
48static bfd_boolean mk_fdrtab
53 PARAMS ((bfd *, struct ecoff_debug_info * const,
54 const struct ecoff_debug_swap * const, struct ecoff_find_line *));
49 PARAMS ((bfd *, struct ecoff_debug_info * const,
50 const struct ecoff_debug_swap * const, struct ecoff_find_line *));
51static long fdrtab_lookup
52 PARAMS ((struct ecoff_find_line *, bfd_vma));
53static bfd_boolean lookup_line
54 PARAMS ((bfd *, struct ecoff_debug_info * const,
55 const struct ecoff_debug_swap * const, struct ecoff_find_line *));
55
56/* Routines to swap auxiliary information in and out. I am assuming
57 that the auxiliary information format is always going to be target
58 independent. */
59
60/* Swap in a type information record.
61 BIGEND says whether AUX symbols are big-endian or little-endian; this
62 info comes from the file header record (fh-fBigendian). */

--- 185 unchanged lines hidden (view full) ---

248#endif
249}
250
251/* The minimum amount of data to allocate. */
252#define ALLOC_SIZE (4064)
253
254/* Add bytes to a buffer. Return success. */
255
56
57/* Routines to swap auxiliary information in and out. I am assuming
58 that the auxiliary information format is always going to be target
59 independent. */
60
61/* Swap in a type information record.
62 BIGEND says whether AUX symbols are big-endian or little-endian; this
63 info comes from the file header record (fh-fBigendian). */

--- 185 unchanged lines hidden (view full) ---

249#endif
250}
251
252/* The minimum amount of data to allocate. */
253#define ALLOC_SIZE (4064)
254
255/* Add bytes to a buffer. Return success. */
256
256static boolean
257static bfd_boolean
257ecoff_add_bytes (buf, bufend, need)
258 char **buf;
259 char **bufend;
260 size_t need;
261{
262 size_t have;
263 size_t want;
264 char *newbuf;

--- 4 unchanged lines hidden (view full) ---

269 else
270 {
271 want = need - have;
272 if (want < ALLOC_SIZE)
273 want = ALLOC_SIZE;
274 }
275 newbuf = (char *) bfd_realloc (*buf, (bfd_size_type) have + want);
276 if (newbuf == NULL)
258ecoff_add_bytes (buf, bufend, need)
259 char **buf;
260 char **bufend;
261 size_t need;
262{
263 size_t have;
264 size_t want;
265 char *newbuf;

--- 4 unchanged lines hidden (view full) ---

270 else
271 {
272 want = need - have;
273 if (want < ALLOC_SIZE)
274 want = ALLOC_SIZE;
275 }
276 newbuf = (char *) bfd_realloc (*buf, (bfd_size_type) have + want);
277 if (newbuf == NULL)
277 return false;
278 return FALSE;
278 *buf = newbuf;
279 *bufend = *buf + have + want;
279 *buf = newbuf;
280 *bufend = *buf + have + want;
280 return true;
281 return TRUE;
281}
282
283/* We keep a hash table which maps strings to numbers. We use it to
284 map FDR names to indices in the output file, and to map local
285 strings when combining stabs debugging information. */
286
287struct string_hash_entry
288{

--- 53 unchanged lines hidden (view full) ---

342
343struct shuffle
344{
345 /* The next entry in this linked list. */
346 struct shuffle *next;
347 /* The length of the information. */
348 unsigned long size;
349 /* Whether this information comes from a file or not. */
282}
283
284/* We keep a hash table which maps strings to numbers. We use it to
285 map FDR names to indices in the output file, and to map local
286 strings when combining stabs debugging information. */
287
288struct string_hash_entry
289{

--- 53 unchanged lines hidden (view full) ---

343
344struct shuffle
345{
346 /* The next entry in this linked list. */
347 struct shuffle *next;
348 /* The length of the information. */
349 unsigned long size;
350 /* Whether this information comes from a file or not. */
350 boolean filep;
351 bfd_boolean filep;
351 union
352 {
353 struct
354 {
355 /* The BFD the data comes from. */
356 bfd *input_bfd;
357 /* The offset within input_bfd. */
358 file_ptr offset;

--- 36 unchanged lines hidden (view full) ---

395 /* The size of the largest file shuffle. */
396 unsigned long largest_file_shuffle;
397 /* An objalloc for debugging information. */
398 struct objalloc *memory;
399};
400
401/* Add a file entry to a shuffle list. */
402
352 union
353 {
354 struct
355 {
356 /* The BFD the data comes from. */
357 bfd *input_bfd;
358 /* The offset within input_bfd. */
359 file_ptr offset;

--- 36 unchanged lines hidden (view full) ---

396 /* The size of the largest file shuffle. */
397 unsigned long largest_file_shuffle;
398 /* An objalloc for debugging information. */
399 struct objalloc *memory;
400};
401
402/* Add a file entry to a shuffle list. */
403
403static boolean add_file_shuffle PARAMS ((struct accumulate *,
404 struct shuffle **,
405 struct shuffle **, bfd *, file_ptr,
406 unsigned long));
404static bfd_boolean add_file_shuffle
405 PARAMS ((struct accumulate *, struct shuffle **, struct shuffle **,
406 bfd *, file_ptr, unsigned long));
407
407
408static boolean
408static bfd_boolean
409add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
410 struct accumulate *ainfo;
411 struct shuffle **head;
412 struct shuffle **tail;
413 bfd *input_bfd;
414 file_ptr offset;
415 unsigned long size;
416{
417 struct shuffle *n;
418
419 if (*tail != (struct shuffle *) NULL
420 && (*tail)->filep
421 && (*tail)->u.file.input_bfd == input_bfd
422 && (*tail)->u.file.offset + (*tail)->size == (unsigned long) offset)
423 {
424 /* Just merge this entry onto the existing one. */
425 (*tail)->size += size;
426 if ((*tail)->size > ainfo->largest_file_shuffle)
427 ainfo->largest_file_shuffle = (*tail)->size;
409add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
410 struct accumulate *ainfo;
411 struct shuffle **head;
412 struct shuffle **tail;
413 bfd *input_bfd;
414 file_ptr offset;
415 unsigned long size;
416{
417 struct shuffle *n;
418
419 if (*tail != (struct shuffle *) NULL
420 && (*tail)->filep
421 && (*tail)->u.file.input_bfd == input_bfd
422 && (*tail)->u.file.offset + (*tail)->size == (unsigned long) offset)
423 {
424 /* Just merge this entry onto the existing one. */
425 (*tail)->size += size;
426 if ((*tail)->size > ainfo->largest_file_shuffle)
427 ainfo->largest_file_shuffle = (*tail)->size;
428 return true;
428 return TRUE;
429 }
430
431 n = (struct shuffle *) objalloc_alloc (ainfo->memory,
432 sizeof (struct shuffle));
433 if (!n)
434 {
435 bfd_set_error (bfd_error_no_memory);
429 }
430
431 n = (struct shuffle *) objalloc_alloc (ainfo->memory,
432 sizeof (struct shuffle));
433 if (!n)
434 {
435 bfd_set_error (bfd_error_no_memory);
436 return false;
436 return FALSE;
437 }
438 n->next = NULL;
439 n->size = size;
437 }
438 n->next = NULL;
439 n->size = size;
440 n->filep = true;
440 n->filep = TRUE;
441 n->u.file.input_bfd = input_bfd;
442 n->u.file.offset = offset;
443 if (*head == (struct shuffle *) NULL)
444 *head = n;
445 if (*tail != (struct shuffle *) NULL)
446 (*tail)->next = n;
447 *tail = n;
448 if (size > ainfo->largest_file_shuffle)
449 ainfo->largest_file_shuffle = size;
441 n->u.file.input_bfd = input_bfd;
442 n->u.file.offset = offset;
443 if (*head == (struct shuffle *) NULL)
444 *head = n;
445 if (*tail != (struct shuffle *) NULL)
446 (*tail)->next = n;
447 *tail = n;
448 if (size > ainfo->largest_file_shuffle)
449 ainfo->largest_file_shuffle = size;
450 return true;
450 return TRUE;
451}
452
453/* Add a memory entry to a shuffle list. */
454
451}
452
453/* Add a memory entry to a shuffle list. */
454
455static boolean add_memory_shuffle PARAMS ((struct accumulate *,
456 struct shuffle **head,
457 struct shuffle **tail,
458 bfd_byte *data, unsigned long size));
455static bfd_boolean add_memory_shuffle
456 PARAMS ((struct accumulate *, struct shuffle **head, struct shuffle **tail,
457 bfd_byte *data, unsigned long size));
459
458
460static boolean
459static bfd_boolean
461add_memory_shuffle (ainfo, head, tail, data, size)
462 struct accumulate *ainfo;
463 struct shuffle **head;
464 struct shuffle **tail;
465 bfd_byte *data;
466 unsigned long size;
467{
468 struct shuffle *n;
469
470 n = (struct shuffle *) objalloc_alloc (ainfo->memory,
471 sizeof (struct shuffle));
472 if (!n)
473 {
474 bfd_set_error (bfd_error_no_memory);
460add_memory_shuffle (ainfo, head, tail, data, size)
461 struct accumulate *ainfo;
462 struct shuffle **head;
463 struct shuffle **tail;
464 bfd_byte *data;
465 unsigned long size;
466{
467 struct shuffle *n;
468
469 n = (struct shuffle *) objalloc_alloc (ainfo->memory,
470 sizeof (struct shuffle));
471 if (!n)
472 {
473 bfd_set_error (bfd_error_no_memory);
475 return false;
474 return FALSE;
476 }
477 n->next = NULL;
478 n->size = size;
475 }
476 n->next = NULL;
477 n->size = size;
479 n->filep = false;
478 n->filep = FALSE;
480 n->u.memory = (PTR) data;
481 if (*head == (struct shuffle *) NULL)
482 *head = n;
483 if (*tail != (struct shuffle *) NULL)
484 (*tail)->next = n;
485 *tail = n;
479 n->u.memory = (PTR) data;
480 if (*head == (struct shuffle *) NULL)
481 *head = n;
482 if (*tail != (struct shuffle *) NULL)
483 (*tail)->next = n;
484 *tail = n;
486 return true;
485 return TRUE;
487}
488
489/* Initialize the FDR hash table. This returns a handle which is then
490 passed in to bfd_ecoff_debug_accumulate, et. al. */
491
492PTR
493bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
494 bfd *output_bfd ATTRIBUTE_UNUSED;

--- 27 unchanged lines hidden (view full) ---

522 ainfo->ss_hash_end = NULL;
523 ainfo->fdr = NULL;
524 ainfo->fdr_end = NULL;
525 ainfo->rfd = NULL;
526 ainfo->rfd_end = NULL;
527
528 ainfo->largest_file_shuffle = 0;
529
486}
487
488/* Initialize the FDR hash table. This returns a handle which is then
489 passed in to bfd_ecoff_debug_accumulate, et. al. */
490
491PTR
492bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
493 bfd *output_bfd ATTRIBUTE_UNUSED;

--- 27 unchanged lines hidden (view full) ---

521 ainfo->ss_hash_end = NULL;
522 ainfo->fdr = NULL;
523 ainfo->fdr_end = NULL;
524 ainfo->rfd = NULL;
525 ainfo->rfd_end = NULL;
526
527 ainfo->largest_file_shuffle = 0;
528
530 if (! info->relocateable)
529 if (! info->relocatable)
531 {
532 if (! bfd_hash_table_init (&ainfo->str_hash.table, string_hash_newfunc))
533 return NULL;
534
535 /* The first entry in the string table is the empty string. */
536 output_debug->symbolic_header.issMax = 1;
537 }
538

--- 16 unchanged lines hidden (view full) ---

555 struct ecoff_debug_info *output_debug ATTRIBUTE_UNUSED;
556 const struct ecoff_debug_swap *output_swap ATTRIBUTE_UNUSED;
557 struct bfd_link_info *info;
558{
559 struct accumulate *ainfo = (struct accumulate *) handle;
560
561 bfd_hash_table_free (&ainfo->fdr_hash.table);
562
530 {
531 if (! bfd_hash_table_init (&ainfo->str_hash.table, string_hash_newfunc))
532 return NULL;
533
534 /* The first entry in the string table is the empty string. */
535 output_debug->symbolic_header.issMax = 1;
536 }
537

--- 16 unchanged lines hidden (view full) ---

554 struct ecoff_debug_info *output_debug ATTRIBUTE_UNUSED;
555 const struct ecoff_debug_swap *output_swap ATTRIBUTE_UNUSED;
556 struct bfd_link_info *info;
557{
558 struct accumulate *ainfo = (struct accumulate *) handle;
559
560 bfd_hash_table_free (&ainfo->fdr_hash.table);
561
563 if (! info->relocateable)
562 if (! info->relocatable)
564 bfd_hash_table_free (&ainfo->str_hash.table);
565
566 objalloc_free (ainfo->memory);
567
568 free (ainfo);
569}
570
571/* Accumulate the debugging information from INPUT_BFD into
572 OUTPUT_BFD. The INPUT_DEBUG argument points to some ECOFF
573 debugging information which we want to link into the information
574 pointed to by the OUTPUT_DEBUG argument. OUTPUT_SWAP and
575 INPUT_SWAP point to the swapping information needed. INFO is the
576 linker information structure. HANDLE is returned by
577 bfd_ecoff_debug_init. */
578
563 bfd_hash_table_free (&ainfo->str_hash.table);
564
565 objalloc_free (ainfo->memory);
566
567 free (ainfo);
568}
569
570/* Accumulate the debugging information from INPUT_BFD into
571 OUTPUT_BFD. The INPUT_DEBUG argument points to some ECOFF
572 debugging information which we want to link into the information
573 pointed to by the OUTPUT_DEBUG argument. OUTPUT_SWAP and
574 INPUT_SWAP point to the swapping information needed. INFO is the
575 linker information structure. HANDLE is returned by
576 bfd_ecoff_debug_init. */
577
579boolean
578bfd_boolean
580bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
581 input_bfd, input_debug, input_swap,
582 info)
583 PTR handle;
584 bfd *output_bfd;
585 struct ecoff_debug_info *output_debug;
586 const struct ecoff_debug_swap *output_swap;
587 bfd *input_bfd;

--- 79 unchanged lines hidden (view full) ---

667 amt *= sizeof (RFDT);
668 input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd, amt);
669
670 sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
671 rfd_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
672 if (!input_debug->ifdmap || !rfd_out)
673 {
674 bfd_set_error (bfd_error_no_memory);
579bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
580 input_bfd, input_debug, input_swap,
581 info)
582 PTR handle;
583 bfd *output_bfd;
584 struct ecoff_debug_info *output_debug;
585 const struct ecoff_debug_swap *output_swap;
586 bfd *input_bfd;

--- 79 unchanged lines hidden (view full) ---

666 amt *= sizeof (RFDT);
667 input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd, amt);
668
669 sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
670 rfd_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
671 if (!input_debug->ifdmap || !rfd_out)
672 {
673 bfd_set_error (bfd_error_no_memory);
675 return false;
674 return FALSE;
676 }
677 if (!add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz))
675 }
676 if (!add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz))
678 return false;
677 return FALSE;
679
680 copied = 0;
681
682 /* Look through the FDR's to see which ones we are going to include
683 in the final output. We do not want duplicate FDR information
684 for header files, because ECOFF debugging is often very large.
685 When we find an FDR with no line information which can be merged,
686 we look it up in a hash table to ensure that we only include it

--- 24 unchanged lines hidden (view full) ---

711 based on the order of include files. Using the number of
712 symbols and aux entries as a hash reduces the chance that
713 we will merge symbol information that should not be
714 merged. */
715 name = input_debug->ss + fdr.issBase + fdr.rss;
716
717 lookup = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 20);
718 if (lookup == NULL)
678
679 copied = 0;
680
681 /* Look through the FDR's to see which ones we are going to include
682 in the final output. We do not want duplicate FDR information
683 for header files, because ECOFF debugging is often very large.
684 When we find an FDR with no line information which can be merged,
685 we look it up in a hash table to ensure that we only include it

--- 24 unchanged lines hidden (view full) ---

710 based on the order of include files. Using the number of
711 symbols and aux entries as a hash reduces the chance that
712 we will merge symbol information that should not be
713 merged. */
714 name = input_debug->ss + fdr.issBase + fdr.rss;
715
716 lookup = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 20);
717 if (lookup == NULL)
719 return false;
718 return FALSE;
720 sprintf (lookup, "%s %lx %lx", name, fdr.csym, fdr.caux);
721
719 sprintf (lookup, "%s %lx %lx", name, fdr.csym, fdr.caux);
720
722 fh = string_hash_lookup (&ainfo->fdr_hash, lookup, true, true);
721 fh = string_hash_lookup (&ainfo->fdr_hash, lookup, TRUE, TRUE);
723 free (lookup);
724 if (fh == (struct string_hash_entry *) NULL)
722 free (lookup);
723 if (fh == (struct string_hash_entry *) NULL)
725 return false;
724 return FALSE;
726
727 if (fh->val != -1)
728 {
729 input_debug->ifdmap[i] = fh->val;
730 (*swap_rfd_out) (output_bfd, input_debug->ifdmap + i,
731 (PTR) rfd_out);
732
733 /* Don't copy this FDR. */

--- 34 unchanged lines hidden (view full) ---

768
769 /* Look through the FDR's and copy over all associated debugging
770 information. */
771 sz = copied * external_fdr_size;
772 fdr_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
773 if (!fdr_out)
774 {
775 bfd_set_error (bfd_error_no_memory);
725
726 if (fh->val != -1)
727 {
728 input_debug->ifdmap[i] = fh->val;
729 (*swap_rfd_out) (output_bfd, input_debug->ifdmap + i,
730 (PTR) rfd_out);
731
732 /* Don't copy this FDR. */

--- 34 unchanged lines hidden (view full) ---

767
768 /* Look through the FDR's and copy over all associated debugging
769 information. */
770 sz = copied * external_fdr_size;
771 fdr_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
772 if (!fdr_out)
773 {
774 bfd_set_error (bfd_error_no_memory);
776 return false;
775 return FALSE;
777 }
778 if (!add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz))
776 }
777 if (!add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz))
779 return false;
778 return FALSE;
780 for (fdr_ptr = fdr_start, i = 0;
781 fdr_ptr < fdr_end;
782 fdr_ptr += fdr_add, i++)
783 {
784 FDR fdr;
785 bfd_vma fdr_adr;
786 bfd_byte *sym_out;
787 bfd_byte *lraw_src;
788 bfd_byte *lraw_end;
779 for (fdr_ptr = fdr_start, i = 0;
780 fdr_ptr < fdr_end;
781 fdr_ptr += fdr_add, i++)
782 {
783 FDR fdr;
784 bfd_vma fdr_adr;
785 bfd_byte *sym_out;
786 bfd_byte *lraw_src;
787 bfd_byte *lraw_end;
789 boolean fgotfilename;
788 bfd_boolean fgotfilename;
790
791 if (input_debug->ifdmap[i] < output_symhdr->ifdMax)
792 {
793 /* We are not copying this FDR. */
794 continue;
795 }
796
797 if (input_debug->fdr != (FDR *) NULL)

--- 19 unchanged lines hidden (view full) ---

817
818 /* FIXME: It is conceivable that this FDR points to the .init or
819 .fini section, in which case this will not do the right
820 thing. */
821 fdr.adr += section_adjust[scText];
822
823 /* Swap in the local symbols, adjust their values, and swap them
824 out again. */
789
790 if (input_debug->ifdmap[i] < output_symhdr->ifdMax)
791 {
792 /* We are not copying this FDR. */
793 continue;
794 }
795
796 if (input_debug->fdr != (FDR *) NULL)

--- 19 unchanged lines hidden (view full) ---

816
817 /* FIXME: It is conceivable that this FDR points to the .init or
818 .fini section, in which case this will not do the right
819 thing. */
820 fdr.adr += section_adjust[scText];
821
822 /* Swap in the local symbols, adjust their values, and swap them
823 out again. */
825 fgotfilename = false;
824 fgotfilename = FALSE;
826 sz = fdr.csym * external_sym_size;
827 sym_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
828 if (!sym_out)
829 {
830 bfd_set_error (bfd_error_no_memory);
825 sz = fdr.csym * external_sym_size;
826 sym_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
827 if (!sym_out)
828 {
829 bfd_set_error (bfd_error_no_memory);
831 return false;
830 return FALSE;
832 }
833 if (!add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out,
834 sz))
831 }
832 if (!add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out,
833 sz))
835 return false;
834 return FALSE;
836 lraw_src = ((bfd_byte *) input_debug->external_sym
837 + fdr.isymBase * input_swap->external_sym_size);
838 lraw_end = lraw_src + fdr.csym * input_swap->external_sym_size;
839 for (; lraw_src < lraw_end; lraw_src += input_swap->external_sym_size)
840 {
841 SYMR internal_sym;
842
843 (*swap_sym_in) (input_bfd, (PTR) lraw_src, &internal_sym);

--- 31 unchanged lines hidden (view full) ---

875
876 default:
877 break;
878 }
879
880 /* If we are doing a final link, we hash all the strings in
881 the local symbol table together. This reduces the amount
882 of space required by debugging information. We don't do
835 lraw_src = ((bfd_byte *) input_debug->external_sym
836 + fdr.isymBase * input_swap->external_sym_size);
837 lraw_end = lraw_src + fdr.csym * input_swap->external_sym_size;
838 for (; lraw_src < lraw_end; lraw_src += input_swap->external_sym_size)
839 {
840 SYMR internal_sym;
841
842 (*swap_sym_in) (input_bfd, (PTR) lraw_src, &internal_sym);

--- 31 unchanged lines hidden (view full) ---

874
875 default:
876 break;
877 }
878
879 /* If we are doing a final link, we hash all the strings in
880 the local symbol table together. This reduces the amount
881 of space required by debugging information. We don't do
883 this when performing a relocateable link because it would
882 this when performing a relocatable link because it would
884 prevent us from easily merging different FDR's. */
883 prevent us from easily merging different FDR's. */
885 if (! info->relocateable)
884 if (! info->relocatable)
886 {
885 {
887 boolean ffilename;
886 bfd_boolean ffilename;
888 const char *name;
889
890 if (! fgotfilename && internal_sym.iss == fdr.rss)
887 const char *name;
888
889 if (! fgotfilename && internal_sym.iss == fdr.rss)
891 ffilename = true;
890 ffilename = TRUE;
892 else
891 else
893 ffilename = false;
892 ffilename = FALSE;
894
895 /* Hash the name into the string table. */
896 name = input_debug->ss + fdr.issBase + internal_sym.iss;
897 if (*name == '\0')
898 internal_sym.iss = 0;
899 else
900 {
901 struct string_hash_entry *sh;
902
893
894 /* Hash the name into the string table. */
895 name = input_debug->ss + fdr.issBase + internal_sym.iss;
896 if (*name == '\0')
897 internal_sym.iss = 0;
898 else
899 {
900 struct string_hash_entry *sh;
901
903 sh = string_hash_lookup (&ainfo->str_hash, name, true, true);
902 sh = string_hash_lookup (&ainfo->str_hash, name, TRUE, TRUE);
904 if (sh == (struct string_hash_entry *) NULL)
903 if (sh == (struct string_hash_entry *) NULL)
905 return false;
904 return FALSE;
906 if (sh->val == -1)
907 {
908 sh->val = output_symhdr->issMax;
909 output_symhdr->issMax += strlen (name) + 1;
910 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
911 ainfo->ss_hash = sh;
912 if (ainfo->ss_hash_end
913 != (struct string_hash_entry *) NULL)
914 ainfo->ss_hash_end->next = sh;
915 ainfo->ss_hash_end = sh;
916 }
917 internal_sym.iss = sh->val;
918 }
919
920 if (ffilename)
921 {
922 fdr.rss = internal_sym.iss;
905 if (sh->val == -1)
906 {
907 sh->val = output_symhdr->issMax;
908 output_symhdr->issMax += strlen (name) + 1;
909 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
910 ainfo->ss_hash = sh;
911 if (ainfo->ss_hash_end
912 != (struct string_hash_entry *) NULL)
913 ainfo->ss_hash_end->next = sh;
914 ainfo->ss_hash_end = sh;
915 }
916 internal_sym.iss = sh->val;
917 }
918
919 if (ffilename)
920 {
921 fdr.rss = internal_sym.iss;
923 fgotfilename = true;
922 fgotfilename = TRUE;
924 }
925 }
926
927 (*swap_sym_out) (output_bfd, &internal_sym, sym_out);
928 sym_out += external_sym_size;
929 }
930
931 fdr.isymBase = output_symhdr->isymMax;

--- 5 unchanged lines hidden (view full) ---

937 numbers. Frankly, forget it. Anybody using stabs debugging
938 information will not use this line number information, and
939 stabs are adjusted correctly. */
940 if (fdr.cbLine > 0)
941 {
942 file_ptr pos = input_symhdr->cbLineOffset + fdr.cbLineOffset;
943 if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
944 input_bfd, pos, (unsigned long) fdr.cbLine))
923 }
924 }
925
926 (*swap_sym_out) (output_bfd, &internal_sym, sym_out);
927 sym_out += external_sym_size;
928 }
929
930 fdr.isymBase = output_symhdr->isymMax;

--- 5 unchanged lines hidden (view full) ---

936 numbers. Frankly, forget it. Anybody using stabs debugging
937 information will not use this line number information, and
938 stabs are adjusted correctly. */
939 if (fdr.cbLine > 0)
940 {
941 file_ptr pos = input_symhdr->cbLineOffset + fdr.cbLineOffset;
942 if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
943 input_bfd, pos, (unsigned long) fdr.cbLine))
945 return false;
944 return FALSE;
946 fdr.ilineBase = output_symhdr->ilineMax;
947 fdr.cbLineOffset = output_symhdr->cbLine;
948 output_symhdr->ilineMax += fdr.cline;
949 output_symhdr->cbLine += fdr.cbLine;
950 }
951 if (fdr.caux > 0)
952 {
953 file_ptr pos = (input_symhdr->cbAuxOffset
954 + fdr.iauxBase * sizeof (union aux_ext));
955 if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
956 input_bfd, pos,
957 fdr.caux * sizeof (union aux_ext)))
945 fdr.ilineBase = output_symhdr->ilineMax;
946 fdr.cbLineOffset = output_symhdr->cbLine;
947 output_symhdr->ilineMax += fdr.cline;
948 output_symhdr->cbLine += fdr.cbLine;
949 }
950 if (fdr.caux > 0)
951 {
952 file_ptr pos = (input_symhdr->cbAuxOffset
953 + fdr.iauxBase * sizeof (union aux_ext));
954 if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
955 input_bfd, pos,
956 fdr.caux * sizeof (union aux_ext)))
958 return false;
957 return FALSE;
959 fdr.iauxBase = output_symhdr->iauxMax;
960 output_symhdr->iauxMax += fdr.caux;
961 }
958 fdr.iauxBase = output_symhdr->iauxMax;
959 output_symhdr->iauxMax += fdr.caux;
960 }
962 if (! info->relocateable)
961 if (! info->relocatable)
963 {
964
965 /* When are are hashing strings, we lie about the number of
966 strings attached to each FDR. We need to set cbSs
967 because some versions of dbx apparently use it to decide
968 how much of the string table to read in. */
969 fdr.issBase = 0;
970 fdr.cbSs = output_symhdr->issMax;
971 }
972 else if (fdr.cbSs > 0)
973 {
974 file_ptr pos = input_symhdr->cbSsOffset + fdr.issBase;
975 if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
976 input_bfd, pos, (unsigned long) fdr.cbSs))
962 {
963
964 /* When are are hashing strings, we lie about the number of
965 strings attached to each FDR. We need to set cbSs
966 because some versions of dbx apparently use it to decide
967 how much of the string table to read in. */
968 fdr.issBase = 0;
969 fdr.cbSs = output_symhdr->issMax;
970 }
971 else if (fdr.cbSs > 0)
972 {
973 file_ptr pos = input_symhdr->cbSsOffset + fdr.issBase;
974 if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
975 input_bfd, pos, (unsigned long) fdr.cbSs))
977 return false;
976 return FALSE;
978 fdr.issBase = output_symhdr->issMax;
979 output_symhdr->issMax += fdr.cbSs;
980 }
981
982 if ((output_bfd->xvec->header_byteorder
983 == input_bfd->xvec->header_byteorder)
984 && input_debug->adjust == (struct ecoff_value_adjust *) NULL)
985 {
986 /* The two BFD's have the same endianness, and we don't have
987 to adjust the PDR addresses, so simply copying the
988 information will suffice. */
989 BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
990 if (fdr.cpd > 0)
991 {
992 file_ptr pos = (input_symhdr->cbPdOffset
993 + fdr.ipdFirst * external_pdr_size);
994 unsigned long size = fdr.cpd * external_pdr_size;
995 if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
996 input_bfd, pos, size))
977 fdr.issBase = output_symhdr->issMax;
978 output_symhdr->issMax += fdr.cbSs;
979 }
980
981 if ((output_bfd->xvec->header_byteorder
982 == input_bfd->xvec->header_byteorder)
983 && input_debug->adjust == (struct ecoff_value_adjust *) NULL)
984 {
985 /* The two BFD's have the same endianness, and we don't have
986 to adjust the PDR addresses, so simply copying the
987 information will suffice. */
988 BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
989 if (fdr.cpd > 0)
990 {
991 file_ptr pos = (input_symhdr->cbPdOffset
992 + fdr.ipdFirst * external_pdr_size);
993 unsigned long size = fdr.cpd * external_pdr_size;
994 if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
995 input_bfd, pos, size))
997 return false;
996 return FALSE;
998 }
999 BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
1000 if (fdr.copt > 0)
1001 {
1002 file_ptr pos = (input_symhdr->cbOptOffset
1003 + fdr.ioptBase * external_opt_size);
1004 unsigned long size = fdr.copt * external_opt_size;
1005 if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
1006 input_bfd, pos, size))
997 }
998 BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
999 if (fdr.copt > 0)
1000 {
1001 file_ptr pos = (input_symhdr->cbOptOffset
1002 + fdr.ioptBase * external_opt_size);
1003 unsigned long size = fdr.copt * external_opt_size;
1004 if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
1005 input_bfd, pos, size))
1007 return false;
1006 return FALSE;
1008 }
1009 }
1010 else
1011 {
1012 bfd_size_type outsz, insz;
1013 bfd_byte *in;
1014 bfd_byte *end;
1015 bfd_byte *out;

--- 6 unchanged lines hidden (view full) ---

1022 in = ((bfd_byte *) input_debug->external_pdr
1023 + fdr.ipdFirst * insz);
1024 end = in + fdr.cpd * insz;
1025 sz = fdr.cpd * outsz;
1026 out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
1027 if (!out)
1028 {
1029 bfd_set_error (bfd_error_no_memory);
1007 }
1008 }
1009 else
1010 {
1011 bfd_size_type outsz, insz;
1012 bfd_byte *in;
1013 bfd_byte *end;
1014 bfd_byte *out;

--- 6 unchanged lines hidden (view full) ---

1021 in = ((bfd_byte *) input_debug->external_pdr
1022 + fdr.ipdFirst * insz);
1023 end = in + fdr.cpd * insz;
1024 sz = fdr.cpd * outsz;
1025 out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
1026 if (!out)
1027 {
1028 bfd_set_error (bfd_error_no_memory);
1030 return false;
1029 return FALSE;
1031 }
1032 if (!add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out,
1033 sz))
1030 }
1031 if (!add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out,
1032 sz))
1034 return false;
1033 return FALSE;
1035 for (; in < end; in += insz, out += outsz)
1036 {
1037 PDR pdr;
1038
1039 (*input_swap->swap_pdr_in) (input_bfd, (PTR) in, &pdr);
1040
1041 /* If we have been relaxing, we may have to adjust the
1042 address. */

--- 20 unchanged lines hidden (view full) ---

1063 in = ((bfd_byte *) input_debug->external_opt
1064 + fdr.ioptBase * insz);
1065 end = in + fdr.copt * insz;
1066 sz = fdr.copt * outsz;
1067 out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
1068 if (!out)
1069 {
1070 bfd_set_error (bfd_error_no_memory);
1034 for (; in < end; in += insz, out += outsz)
1035 {
1036 PDR pdr;
1037
1038 (*input_swap->swap_pdr_in) (input_bfd, (PTR) in, &pdr);
1039
1040 /* If we have been relaxing, we may have to adjust the
1041 address. */

--- 20 unchanged lines hidden (view full) ---

1062 in = ((bfd_byte *) input_debug->external_opt
1063 + fdr.ioptBase * insz);
1064 end = in + fdr.copt * insz;
1065 sz = fdr.copt * outsz;
1066 out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
1067 if (!out)
1068 {
1069 bfd_set_error (bfd_error_no_memory);
1071 return false;
1070 return FALSE;
1072 }
1073 if (!add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out,
1074 sz))
1071 }
1072 if (!add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out,
1073 sz))
1075 return false;
1074 return FALSE;
1076 for (; in < end; in += insz, out += outsz)
1077 {
1078 OPTR opt;
1079
1080 (*input_swap->swap_opt_in) (input_bfd, (PTR) in, &opt);
1081 (*output_swap->swap_opt_out) (output_bfd, &opt, (PTR) out);
1082 }
1083 }

--- 15 unchanged lines hidden (view full) ---

1099 fdr.rfdBase += oldrfdbase;
1100 }
1101
1102 (*swap_fdr_out) (output_bfd, &fdr, fdr_out);
1103 fdr_out += external_fdr_size;
1104 ++output_symhdr->ifdMax;
1105 }
1106
1075 for (; in < end; in += insz, out += outsz)
1076 {
1077 OPTR opt;
1078
1079 (*input_swap->swap_opt_in) (input_bfd, (PTR) in, &opt);
1080 (*output_swap->swap_opt_out) (output_bfd, &opt, (PTR) out);
1081 }
1082 }

--- 15 unchanged lines hidden (view full) ---

1098 fdr.rfdBase += oldrfdbase;
1099 }
1100
1101 (*swap_fdr_out) (output_bfd, &fdr, fdr_out);
1102 fdr_out += external_fdr_size;
1103 ++output_symhdr->ifdMax;
1104 }
1105
1107 return true;
1106 return TRUE;
1108}
1109
1110/* Add a string to the debugging information we are accumulating.
1111 Return the offset from the fdr string base. */
1112
1107}
1108
1109/* Add a string to the debugging information we are accumulating.
1110 Return the offset from the fdr string base. */
1111
1113static long ecoff_add_string PARAMS ((struct accumulate *,
1114 struct bfd_link_info *,
1115 struct ecoff_debug_info *,
1116 FDR *fdr, const char *string));
1112static long ecoff_add_string
1113 PARAMS ((struct accumulate *, struct bfd_link_info *,
1114 struct ecoff_debug_info *, FDR *fdr, const char *string));
1117
1118static long
1119ecoff_add_string (ainfo, info, debug, fdr, string)
1120 struct accumulate *ainfo;
1121 struct bfd_link_info *info;
1122 struct ecoff_debug_info *debug;
1123 FDR *fdr;
1124 const char *string;
1125{
1126 HDRR *symhdr;
1127 size_t len;
1128 bfd_size_type ret;
1129
1130 symhdr = &debug->symbolic_header;
1131 len = strlen (string);
1115
1116static long
1117ecoff_add_string (ainfo, info, debug, fdr, string)
1118 struct accumulate *ainfo;
1119 struct bfd_link_info *info;
1120 struct ecoff_debug_info *debug;
1121 FDR *fdr;
1122 const char *string;
1123{
1124 HDRR *symhdr;
1125 size_t len;
1126 bfd_size_type ret;
1127
1128 symhdr = &debug->symbolic_header;
1129 len = strlen (string);
1132 if (info->relocateable)
1130 if (info->relocatable)
1133 {
1134 if (!add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
1135 len + 1))
1136 return -1;
1137 ret = symhdr->issMax;
1138 symhdr->issMax += len + 1;
1139 fdr->cbSs += len + 1;
1140 }
1141 else
1142 {
1143 struct string_hash_entry *sh;
1144
1131 {
1132 if (!add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
1133 len + 1))
1134 return -1;
1135 ret = symhdr->issMax;
1136 symhdr->issMax += len + 1;
1137 fdr->cbSs += len + 1;
1138 }
1139 else
1140 {
1141 struct string_hash_entry *sh;
1142
1145 sh = string_hash_lookup (&ainfo->str_hash, string, true, true);
1143 sh = string_hash_lookup (&ainfo->str_hash, string, TRUE, TRUE);
1146 if (sh == (struct string_hash_entry *) NULL)
1147 return -1;
1148 if (sh->val == -1)
1149 {
1150 sh->val = symhdr->issMax;
1151 symhdr->issMax += len + 1;
1152 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
1153 ainfo->ss_hash = sh;

--- 5 unchanged lines hidden (view full) ---

1159 ret = sh->val;
1160 }
1161
1162 return ret;
1163}
1164
1165/* Add debugging information from a non-ECOFF file. */
1166
1144 if (sh == (struct string_hash_entry *) NULL)
1145 return -1;
1146 if (sh->val == -1)
1147 {
1148 sh->val = symhdr->issMax;
1149 symhdr->issMax += len + 1;
1150 if (ainfo->ss_hash == (struct string_hash_entry *) NULL)
1151 ainfo->ss_hash = sh;

--- 5 unchanged lines hidden (view full) ---

1157 ret = sh->val;
1158 }
1159
1160 return ret;
1161}
1162
1163/* Add debugging information from a non-ECOFF file. */
1164
1167boolean
1165bfd_boolean
1168bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
1169 output_swap, input_bfd, info)
1170 PTR handle;
1171 bfd *output_bfd;
1172 struct ecoff_debug_info *output_debug;
1173 const struct ecoff_debug_swap *output_swap;
1174 bfd *input_bfd;
1175 struct bfd_link_info *info;

--- 22 unchanged lines hidden (view full) ---

1198 fdr.adr = 0;
1199 }
1200
1201 fdr.issBase = output_symhdr->issMax;
1202 fdr.cbSs = 0;
1203 fdr.rss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1204 bfd_archive_filename (input_bfd));
1205 if (fdr.rss == -1)
1166bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
1167 output_swap, input_bfd, info)
1168 PTR handle;
1169 bfd *output_bfd;
1170 struct ecoff_debug_info *output_debug;
1171 const struct ecoff_debug_swap *output_swap;
1172 bfd *input_bfd;
1173 struct bfd_link_info *info;

--- 22 unchanged lines hidden (view full) ---

1196 fdr.adr = 0;
1197 }
1198
1199 fdr.issBase = output_symhdr->issMax;
1200 fdr.cbSs = 0;
1201 fdr.rss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1202 bfd_archive_filename (input_bfd));
1203 if (fdr.rss == -1)
1206 return false;
1204 return FALSE;
1207 fdr.isymBase = output_symhdr->isymMax;
1208
1209 /* Get the local symbols from the input BFD. */
1210 symsize = bfd_get_symtab_upper_bound (input_bfd);
1211 if (symsize < 0)
1205 fdr.isymBase = output_symhdr->isymMax;
1206
1207 /* Get the local symbols from the input BFD. */
1208 symsize = bfd_get_symtab_upper_bound (input_bfd);
1209 if (symsize < 0)
1212 return false;
1210 return FALSE;
1213 symbols = (asymbol **) bfd_alloc (output_bfd, (bfd_size_type) symsize);
1214 if (symbols == (asymbol **) NULL)
1211 symbols = (asymbol **) bfd_alloc (output_bfd, (bfd_size_type) symsize);
1212 if (symbols == (asymbol **) NULL)
1215 return false;
1213 return FALSE;
1216 symcount = bfd_canonicalize_symtab (input_bfd, symbols);
1217 if (symcount < 0)
1214 symcount = bfd_canonicalize_symtab (input_bfd, symbols);
1215 if (symcount < 0)
1218 return false;
1216 return FALSE;
1219 sym_end = symbols + symcount;
1220
1221 /* Handle the local symbols. Any external symbols are handled
1222 separately. */
1223 fdr.csym = 0;
1224 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
1225 {
1226 SYMR internal_sym;
1227 PTR external_sym;
1228
1229 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
1230 continue;
1231 memset ((PTR) &internal_sym, 0, sizeof internal_sym);
1232 internal_sym.iss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1233 (*sym_ptr)->name);
1234
1235 if (internal_sym.iss == -1)
1217 sym_end = symbols + symcount;
1218
1219 /* Handle the local symbols. Any external symbols are handled
1220 separately. */
1221 fdr.csym = 0;
1222 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
1223 {
1224 SYMR internal_sym;
1225 PTR external_sym;
1226
1227 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
1228 continue;
1229 memset ((PTR) &internal_sym, 0, sizeof internal_sym);
1230 internal_sym.iss = ecoff_add_string (ainfo, info, output_debug, &fdr,
1231 (*sym_ptr)->name);
1232
1233 if (internal_sym.iss == -1)
1236 return false;
1234 return FALSE;
1237 if (bfd_is_com_section ((*sym_ptr)->section)
1238 || bfd_is_und_section ((*sym_ptr)->section))
1239 internal_sym.value = (*sym_ptr)->value;
1240 else
1241 internal_sym.value = ((*sym_ptr)->value
1242 + (*sym_ptr)->section->output_offset
1243 + (*sym_ptr)->section->output_section->vma);
1244 internal_sym.st = stNil;
1245 internal_sym.sc = scUndefined;
1246 internal_sym.index = indexNil;
1247
1248 external_sym = (PTR) objalloc_alloc (ainfo->memory,
1249 output_swap->external_sym_size);
1250 if (!external_sym)
1251 {
1252 bfd_set_error (bfd_error_no_memory);
1235 if (bfd_is_com_section ((*sym_ptr)->section)
1236 || bfd_is_und_section ((*sym_ptr)->section))
1237 internal_sym.value = (*sym_ptr)->value;
1238 else
1239 internal_sym.value = ((*sym_ptr)->value
1240 + (*sym_ptr)->section->output_offset
1241 + (*sym_ptr)->section->output_section->vma);
1242 internal_sym.st = stNil;
1243 internal_sym.sc = scUndefined;
1244 internal_sym.index = indexNil;
1245
1246 external_sym = (PTR) objalloc_alloc (ainfo->memory,
1247 output_swap->external_sym_size);
1248 if (!external_sym)
1249 {
1250 bfd_set_error (bfd_error_no_memory);
1253 return false;
1251 return FALSE;
1254 }
1255 (*swap_sym_out) (output_bfd, &internal_sym, external_sym);
1256 add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
1257 external_sym,
1258 (unsigned long) output_swap->external_sym_size);
1259 ++fdr.csym;
1260 ++output_symhdr->isymMax;
1261 }

--- 4 unchanged lines hidden (view full) ---

1266 the lang field to be langC. The fBigendian field will
1267 indicate little endian format, but it doesn't matter because
1268 it only applies to aux fields and there are none. */
1269 external_fdr = (PTR) objalloc_alloc (ainfo->memory,
1270 output_swap->external_fdr_size);
1271 if (!external_fdr)
1272 {
1273 bfd_set_error (bfd_error_no_memory);
1252 }
1253 (*swap_sym_out) (output_bfd, &internal_sym, external_sym);
1254 add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
1255 external_sym,
1256 (unsigned long) output_swap->external_sym_size);
1257 ++fdr.csym;
1258 ++output_symhdr->isymMax;
1259 }

--- 4 unchanged lines hidden (view full) ---

1264 the lang field to be langC. The fBigendian field will
1265 indicate little endian format, but it doesn't matter because
1266 it only applies to aux fields and there are none. */
1267 external_fdr = (PTR) objalloc_alloc (ainfo->memory,
1268 output_swap->external_fdr_size);
1269 if (!external_fdr)
1270 {
1271 bfd_set_error (bfd_error_no_memory);
1274 return false;
1272 return FALSE;
1275 }
1276 (*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
1277 add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
1278 external_fdr,
1279 (unsigned long) output_swap->external_fdr_size);
1280
1281 ++output_symhdr->ifdMax;
1282
1273 }
1274 (*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
1275 add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
1276 external_fdr,
1277 (unsigned long) output_swap->external_fdr_size);
1278
1279 ++output_symhdr->ifdMax;
1280
1283 return true;
1281 return TRUE;
1284}
1285
1286/* Set up ECOFF debugging information for the external symbols.
1287 FIXME: This is done using a memory buffer, but it should be
1288 probably be changed to use a shuffle structure. The assembler uses
1289 this interface, so that must be changed to do something else. */
1290
1282}
1283
1284/* Set up ECOFF debugging information for the external symbols.
1285 FIXME: This is done using a memory buffer, but it should be
1286 probably be changed to use a shuffle structure. The assembler uses
1287 this interface, so that must be changed to do something else. */
1288
1291boolean
1292bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
1289bfd_boolean
1290bfd_ecoff_debug_externals (abfd, debug, swap, relocatable, get_extr,
1293 set_index)
1294 bfd *abfd;
1295 struct ecoff_debug_info *debug;
1296 const struct ecoff_debug_swap *swap;
1291 set_index)
1292 bfd *abfd;
1293 struct ecoff_debug_info *debug;
1294 const struct ecoff_debug_swap *swap;
1297 boolean relocateable;
1298 boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
1295 bfd_boolean relocatable;
1296 bfd_boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
1299 void (*set_index) PARAMS ((asymbol *, bfd_size_type));
1300{
1301 HDRR * const symhdr = &debug->symbolic_header;
1302 asymbol **sym_ptr_ptr;
1303 size_t c;
1304
1305 sym_ptr_ptr = bfd_get_outsymbols (abfd);
1306 if (sym_ptr_ptr == NULL)
1297 void (*set_index) PARAMS ((asymbol *, bfd_size_type));
1298{
1299 HDRR * const symhdr = &debug->symbolic_header;
1300 asymbol **sym_ptr_ptr;
1301 size_t c;
1302
1303 sym_ptr_ptr = bfd_get_outsymbols (abfd);
1304 if (sym_ptr_ptr == NULL)
1307 return true;
1305 return TRUE;
1308
1309 for (c = bfd_get_symcount (abfd); c > 0; c--, sym_ptr_ptr++)
1310 {
1311 asymbol *sym_ptr;
1312 EXTR esym;
1313
1314 sym_ptr = *sym_ptr_ptr;
1315
1316 /* Get the external symbol information. */
1317 if (! (*get_extr) (sym_ptr, &esym))
1318 continue;
1319
1320 /* If we're producing an executable, move common symbols into
1321 bss. */
1306
1307 for (c = bfd_get_symcount (abfd); c > 0; c--, sym_ptr_ptr++)
1308 {
1309 asymbol *sym_ptr;
1310 EXTR esym;
1311
1312 sym_ptr = *sym_ptr_ptr;
1313
1314 /* Get the external symbol information. */
1315 if (! (*get_extr) (sym_ptr, &esym))
1316 continue;
1317
1318 /* If we're producing an executable, move common symbols into
1319 bss. */
1322 if (! relocateable)
1320 if (! relocatable)
1323 {
1324 if (esym.asym.sc == scCommon)
1325 esym.asym.sc = scBss;
1326 else if (esym.asym.sc == scSCommon)
1327 esym.asym.sc = scSBss;
1328 }
1329
1330 if (bfd_is_com_section (sym_ptr->section)

--- 13 unchanged lines hidden (view full) ---

1344 + sym_ptr->section->output_offset
1345 + sym_ptr->section->output_section->vma);
1346
1347 if (set_index)
1348 (*set_index) (sym_ptr, (bfd_size_type) symhdr->iextMax);
1349
1350 if (! bfd_ecoff_debug_one_external (abfd, debug, swap,
1351 sym_ptr->name, &esym))
1321 {
1322 if (esym.asym.sc == scCommon)
1323 esym.asym.sc = scBss;
1324 else if (esym.asym.sc == scSCommon)
1325 esym.asym.sc = scSBss;
1326 }
1327
1328 if (bfd_is_com_section (sym_ptr->section)

--- 13 unchanged lines hidden (view full) ---

1342 + sym_ptr->section->output_offset
1343 + sym_ptr->section->output_section->vma);
1344
1345 if (set_index)
1346 (*set_index) (sym_ptr, (bfd_size_type) symhdr->iextMax);
1347
1348 if (! bfd_ecoff_debug_one_external (abfd, debug, swap,
1349 sym_ptr->name, &esym))
1352 return false;
1350 return FALSE;
1353 }
1354
1351 }
1352
1355 return true;
1353 return TRUE;
1356}
1357
1358/* Add a single external symbol to the debugging information. */
1359
1354}
1355
1356/* Add a single external symbol to the debugging information. */
1357
1360boolean
1358bfd_boolean
1361bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
1362 bfd *abfd;
1363 struct ecoff_debug_info *debug;
1364 const struct ecoff_debug_swap *swap;
1365 const char *name;
1366 EXTR *esym;
1367{
1368 const bfd_size_type external_ext_size = swap->external_ext_size;

--- 5 unchanged lines hidden (view full) ---

1374 namelen = strlen (name);
1375
1376 if ((size_t) (debug->ssext_end - debug->ssext)
1377 < symhdr->issExtMax + namelen + 1)
1378 {
1379 if (! ecoff_add_bytes ((char **) &debug->ssext,
1380 (char **) &debug->ssext_end,
1381 symhdr->issExtMax + namelen + 1))
1359bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
1360 bfd *abfd;
1361 struct ecoff_debug_info *debug;
1362 const struct ecoff_debug_swap *swap;
1363 const char *name;
1364 EXTR *esym;
1365{
1366 const bfd_size_type external_ext_size = swap->external_ext_size;

--- 5 unchanged lines hidden (view full) ---

1372 namelen = strlen (name);
1373
1374 if ((size_t) (debug->ssext_end - debug->ssext)
1375 < symhdr->issExtMax + namelen + 1)
1376 {
1377 if (! ecoff_add_bytes ((char **) &debug->ssext,
1378 (char **) &debug->ssext_end,
1379 symhdr->issExtMax + namelen + 1))
1382 return false;
1380 return FALSE;
1383 }
1384 if ((size_t) ((char *) debug->external_ext_end
1385 - (char *) debug->external_ext)
1386 < (symhdr->iextMax + 1) * external_ext_size)
1387 {
1388 if (! ecoff_add_bytes ((char **) &debug->external_ext,
1389 (char **) &debug->external_ext_end,
1390 (symhdr->iextMax + 1) * (size_t) external_ext_size))
1381 }
1382 if ((size_t) ((char *) debug->external_ext_end
1383 - (char *) debug->external_ext)
1384 < (symhdr->iextMax + 1) * external_ext_size)
1385 {
1386 if (! ecoff_add_bytes ((char **) &debug->external_ext,
1387 (char **) &debug->external_ext_end,
1388 (symhdr->iextMax + 1) * (size_t) external_ext_size))
1391 return false;
1389 return FALSE;
1392 }
1393
1394 esym->asym.iss = symhdr->issExtMax;
1395
1396 (*swap_ext_out) (abfd, esym,
1397 ((char *) debug->external_ext
1398 + symhdr->iextMax * swap->external_ext_size));
1399
1400 ++symhdr->iextMax;
1401
1402 strcpy (debug->ssext + symhdr->issExtMax, name);
1403 symhdr->issExtMax += namelen + 1;
1404
1390 }
1391
1392 esym->asym.iss = symhdr->issExtMax;
1393
1394 (*swap_ext_out) (abfd, esym,
1395 ((char *) debug->external_ext
1396 + symhdr->iextMax * swap->external_ext_size));
1397
1398 ++symhdr->iextMax;
1399
1400 strcpy (debug->ssext + symhdr->issExtMax, name);
1401 symhdr->issExtMax += namelen + 1;
1402
1405 return true;
1403 return TRUE;
1406}
1407
1408/* Align the ECOFF debugging information. */
1409
1410static void
1411ecoff_align_debug (abfd, debug, swap)
1412 bfd *abfd ATTRIBUTE_UNUSED;
1413 struct ecoff_debug_info *debug;

--- 84 unchanged lines hidden (view full) ---

1498
1499 return tot;
1500}
1501
1502/* Write out the ECOFF symbolic header, given the file position it is
1503 going to be placed at. This assumes that the counts are set
1504 correctly. */
1505
1404}
1405
1406/* Align the ECOFF debugging information. */
1407
1408static void
1409ecoff_align_debug (abfd, debug, swap)
1410 bfd *abfd ATTRIBUTE_UNUSED;
1411 struct ecoff_debug_info *debug;

--- 84 unchanged lines hidden (view full) ---

1496
1497 return tot;
1498}
1499
1500/* Write out the ECOFF symbolic header, given the file position it is
1501 going to be placed at. This assumes that the counts are set
1502 correctly. */
1503
1506static boolean
1504static bfd_boolean
1507ecoff_write_symhdr (abfd, debug, swap, where)
1508 bfd *abfd;
1509 struct ecoff_debug_info *debug;
1510 const struct ecoff_debug_swap *swap;
1511 file_ptr where;
1512{
1513 HDRR * const symhdr = &debug->symbolic_header;
1514 char *buff = NULL;
1515
1516 ecoff_align_debug (abfd, debug, swap);
1517
1518 /* Go to the right location in the file. */
1519 if (bfd_seek (abfd, where, SEEK_SET) != 0)
1505ecoff_write_symhdr (abfd, debug, swap, where)
1506 bfd *abfd;
1507 struct ecoff_debug_info *debug;
1508 const struct ecoff_debug_swap *swap;
1509 file_ptr where;
1510{
1511 HDRR * const symhdr = &debug->symbolic_header;
1512 char *buff = NULL;
1513
1514 ecoff_align_debug (abfd, debug, swap);
1515
1516 /* Go to the right location in the file. */
1517 if (bfd_seek (abfd, where, SEEK_SET) != 0)
1520 return false;
1518 return FALSE;
1521
1522 where += swap->external_hdr_size;
1523
1524 symhdr->magic = swap->sym_magic;
1525
1526 /* Fill in the file offsets. */
1527#define SET(offset, count, size) \
1528 if (symhdr->count == 0) \

--- 23 unchanged lines hidden (view full) ---

1552
1553 (*swap->swap_hdr_out) (abfd, symhdr, buff);
1554 if (bfd_bwrite (buff, swap->external_hdr_size, abfd)
1555 != swap->external_hdr_size)
1556 goto error_return;
1557
1558 if (buff != NULL)
1559 free (buff);
1519
1520 where += swap->external_hdr_size;
1521
1522 symhdr->magic = swap->sym_magic;
1523
1524 /* Fill in the file offsets. */
1525#define SET(offset, count, size) \
1526 if (symhdr->count == 0) \

--- 23 unchanged lines hidden (view full) ---

1550
1551 (*swap->swap_hdr_out) (abfd, symhdr, buff);
1552 if (bfd_bwrite (buff, swap->external_hdr_size, abfd)
1553 != swap->external_hdr_size)
1554 goto error_return;
1555
1556 if (buff != NULL)
1557 free (buff);
1560 return true;
1558 return TRUE;
1561 error_return:
1562 if (buff != NULL)
1563 free (buff);
1559 error_return:
1560 if (buff != NULL)
1561 free (buff);
1564 return false;
1562 return FALSE;
1565}
1566
1567/* Write out the ECOFF debugging information. This function assumes
1568 that the information (the pointers and counts) in *DEBUG have been
1569 set correctly. WHERE is the position in the file to write the
1570 information to. This function fills in the file offsets in the
1571 symbolic header. */
1572
1563}
1564
1565/* Write out the ECOFF debugging information. This function assumes
1566 that the information (the pointers and counts) in *DEBUG have been
1567 set correctly. WHERE is the position in the file to write the
1568 information to. This function fills in the file offsets in the
1569 symbolic header. */
1570
1573boolean
1571bfd_boolean
1574bfd_ecoff_write_debug (abfd, debug, swap, where)
1575 bfd *abfd;
1576 struct ecoff_debug_info *debug;
1577 const struct ecoff_debug_swap *swap;
1578 file_ptr where;
1579{
1580 HDRR * const symhdr = &debug->symbolic_header;
1581
1582 if (! ecoff_write_symhdr (abfd, debug, swap, where))
1572bfd_ecoff_write_debug (abfd, debug, swap, where)
1573 bfd *abfd;
1574 struct ecoff_debug_info *debug;
1575 const struct ecoff_debug_swap *swap;
1576 file_ptr where;
1577{
1578 HDRR * const symhdr = &debug->symbolic_header;
1579
1580 if (! ecoff_write_symhdr (abfd, debug, swap, where))
1583 return false;
1581 return FALSE;
1584
1585#define WRITE(ptr, count, size, offset) \
1586 BFD_ASSERT (symhdr->offset == 0 \
1587 || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
1588 if (bfd_bwrite ((PTR) debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
1589 != size * symhdr->count) \
1582
1583#define WRITE(ptr, count, size, offset) \
1584 BFD_ASSERT (symhdr->offset == 0 \
1585 || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
1586 if (bfd_bwrite ((PTR) debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
1587 != size * symhdr->count) \
1590 return false;
1588 return FALSE;
1591
1592 WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);
1593 WRITE (external_dnr, idnMax, swap->external_dnr_size, cbDnOffset);
1594 WRITE (external_pdr, ipdMax, swap->external_pdr_size, cbPdOffset);
1595 WRITE (external_sym, isymMax, swap->external_sym_size, cbSymOffset);
1596 WRITE (external_opt, ioptMax, swap->external_opt_size, cbOptOffset);
1597 WRITE (external_aux, iauxMax, (bfd_size_type) sizeof (union aux_ext),
1598 cbAuxOffset);
1599 WRITE (ss, issMax, sizeof (char), cbSsOffset);
1600 WRITE (ssext, issExtMax, sizeof (char), cbSsExtOffset);
1601 WRITE (external_fdr, ifdMax, swap->external_fdr_size, cbFdOffset);
1602 WRITE (external_rfd, crfd, swap->external_rfd_size, cbRfdOffset);
1603 WRITE (external_ext, iextMax, swap->external_ext_size, cbExtOffset);
1604#undef WRITE
1605
1589
1590 WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);
1591 WRITE (external_dnr, idnMax, swap->external_dnr_size, cbDnOffset);
1592 WRITE (external_pdr, ipdMax, swap->external_pdr_size, cbPdOffset);
1593 WRITE (external_sym, isymMax, swap->external_sym_size, cbSymOffset);
1594 WRITE (external_opt, ioptMax, swap->external_opt_size, cbOptOffset);
1595 WRITE (external_aux, iauxMax, (bfd_size_type) sizeof (union aux_ext),
1596 cbAuxOffset);
1597 WRITE (ss, issMax, sizeof (char), cbSsOffset);
1598 WRITE (ssext, issExtMax, sizeof (char), cbSsExtOffset);
1599 WRITE (external_fdr, ifdMax, swap->external_fdr_size, cbFdOffset);
1600 WRITE (external_rfd, crfd, swap->external_rfd_size, cbRfdOffset);
1601 WRITE (external_ext, iextMax, swap->external_ext_size, cbExtOffset);
1602#undef WRITE
1603
1606 return true;
1604 return TRUE;
1607}
1608
1609/* Write out a shuffle list. */
1610
1605}
1606
1607/* Write out a shuffle list. */
1608
1611static boolean ecoff_write_shuffle PARAMS ((bfd *,
1612 const struct ecoff_debug_swap *,
1613 struct shuffle *, PTR space));
1609static bfd_boolean ecoff_write_shuffle
1610 PARAMS ((bfd *, const struct ecoff_debug_swap *, struct shuffle *,
1611 PTR space));
1614
1612
1615static boolean
1613static bfd_boolean
1616ecoff_write_shuffle (abfd, swap, shuffle, space)
1617 bfd *abfd;
1618 const struct ecoff_debug_swap *swap;
1619 struct shuffle *shuffle;
1620 PTR space;
1621{
1622 register struct shuffle *l;
1623 unsigned long total;
1624
1625 total = 0;
1626 for (l = shuffle; l != (struct shuffle *) NULL; l = l->next)
1627 {
1628 if (! l->filep)
1629 {
1630 if (bfd_bwrite (l->u.memory, (bfd_size_type) l->size, abfd)
1631 != l->size)
1614ecoff_write_shuffle (abfd, swap, shuffle, space)
1615 bfd *abfd;
1616 const struct ecoff_debug_swap *swap;
1617 struct shuffle *shuffle;
1618 PTR space;
1619{
1620 register struct shuffle *l;
1621 unsigned long total;
1622
1623 total = 0;
1624 for (l = shuffle; l != (struct shuffle *) NULL; l = l->next)
1625 {
1626 if (! l->filep)
1627 {
1628 if (bfd_bwrite (l->u.memory, (bfd_size_type) l->size, abfd)
1629 != l->size)
1632 return false;
1630 return FALSE;
1633 }
1634 else
1635 {
1636 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
1637 || bfd_bread (space, (bfd_size_type) l->size,
1638 l->u.file.input_bfd) != l->size
1639 || bfd_bwrite (space, (bfd_size_type) l->size, abfd) != l->size)
1631 }
1632 else
1633 {
1634 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
1635 || bfd_bread (space, (bfd_size_type) l->size,
1636 l->u.file.input_bfd) != l->size
1637 || bfd_bwrite (space, (bfd_size_type) l->size, abfd) != l->size)
1640 return false;
1638 return FALSE;
1641 }
1642 total += l->size;
1643 }
1644
1645 if ((total & (swap->debug_align - 1)) != 0)
1646 {
1647 unsigned int i;
1648 bfd_byte *s;
1649
1650 i = swap->debug_align - (total & (swap->debug_align - 1));
1651 s = (bfd_byte *) bfd_zmalloc ((bfd_size_type) i);
1652 if (s == NULL && i != 0)
1639 }
1640 total += l->size;
1641 }
1642
1643 if ((total & (swap->debug_align - 1)) != 0)
1644 {
1645 unsigned int i;
1646 bfd_byte *s;
1647
1648 i = swap->debug_align - (total & (swap->debug_align - 1));
1649 s = (bfd_byte *) bfd_zmalloc ((bfd_size_type) i);
1650 if (s == NULL && i != 0)
1653 return false;
1651 return FALSE;
1654
1655 if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
1656 {
1657 free (s);
1652
1653 if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
1654 {
1655 free (s);
1658 return false;
1656 return FALSE;
1659 }
1660 free (s);
1661 }
1662
1657 }
1658 free (s);
1659 }
1660
1663 return true;
1661 return TRUE;
1664}
1665
1666/* Write out debugging information using accumulated linker
1667 information. */
1668
1662}
1663
1664/* Write out debugging information using accumulated linker
1665 information. */
1666
1669boolean
1667bfd_boolean
1670bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
1671 PTR handle;
1672 bfd *abfd;
1673 struct ecoff_debug_info *debug;
1674 const struct ecoff_debug_swap *swap;
1675 struct bfd_link_info *info;
1676 file_ptr where;
1677{

--- 13 unchanged lines hidden (view full) ---

1691 || ! ecoff_write_shuffle (abfd, swap, ainfo->pdr, space)
1692 || ! ecoff_write_shuffle (abfd, swap, ainfo->sym, space)
1693 || ! ecoff_write_shuffle (abfd, swap, ainfo->opt, space)
1694 || ! ecoff_write_shuffle (abfd, swap, ainfo->aux, space))
1695 goto error_return;
1696
1697 /* The string table is written out from the hash table if this is a
1698 final link. */
1668bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
1669 PTR handle;
1670 bfd *abfd;
1671 struct ecoff_debug_info *debug;
1672 const struct ecoff_debug_swap *swap;
1673 struct bfd_link_info *info;
1674 file_ptr where;
1675{

--- 13 unchanged lines hidden (view full) ---

1689 || ! ecoff_write_shuffle (abfd, swap, ainfo->pdr, space)
1690 || ! ecoff_write_shuffle (abfd, swap, ainfo->sym, space)
1691 || ! ecoff_write_shuffle (abfd, swap, ainfo->opt, space)
1692 || ! ecoff_write_shuffle (abfd, swap, ainfo->aux, space))
1693 goto error_return;
1694
1695 /* The string table is written out from the hash table if this is a
1696 final link. */
1699 if (info->relocateable)
1697 if (info->relocatable)
1700 {
1701 BFD_ASSERT (ainfo->ss_hash == (struct string_hash_entry *) NULL);
1702 if (! ecoff_write_shuffle (abfd, swap, ainfo->ss, space))
1703 goto error_return;
1704 }
1705 else
1706 {
1707 unsigned long total;

--- 71 unchanged lines hidden (view full) ---

1779 == (bfd_vma) bfd_tell (abfd)));
1780
1781 amt = debug->symbolic_header.iextMax * swap->external_ext_size;
1782 if (bfd_bwrite (debug->external_ext, amt, abfd) != amt)
1783 goto error_return;
1784
1785 if (space != NULL)
1786 free (space);
1698 {
1699 BFD_ASSERT (ainfo->ss_hash == (struct string_hash_entry *) NULL);
1700 if (! ecoff_write_shuffle (abfd, swap, ainfo->ss, space))
1701 goto error_return;
1702 }
1703 else
1704 {
1705 unsigned long total;

--- 71 unchanged lines hidden (view full) ---

1777 == (bfd_vma) bfd_tell (abfd)));
1778
1779 amt = debug->symbolic_header.iextMax * swap->external_ext_size;
1780 if (bfd_bwrite (debug->external_ext, amt, abfd) != amt)
1781 goto error_return;
1782
1783 if (space != NULL)
1784 free (space);
1787 return true;
1785 return TRUE;
1788
1789 error_return:
1790 if (space != NULL)
1791 free (space);
1786
1787 error_return:
1788 if (space != NULL)
1789 free (space);
1792 return false;
1790 return FALSE;
1793}
1794
1795/* Handle the find_nearest_line function for both ECOFF and MIPS ELF
1796 files. */
1797
1798/* Compare FDR entries. This is called via qsort. */
1799
1800static int

--- 14 unchanged lines hidden (view full) ---

1815}
1816
1817/* Each file descriptor (FDR) has a memory address, to simplify
1818 looking up an FDR by address, we build a table covering all FDRs
1819 that have a least one procedure descriptor in them. The final
1820 table will be sorted by address so we can look it up via binary
1821 search. */
1822
1791}
1792
1793/* Handle the find_nearest_line function for both ECOFF and MIPS ELF
1794 files. */
1795
1796/* Compare FDR entries. This is called via qsort. */
1797
1798static int

--- 14 unchanged lines hidden (view full) ---

1813}
1814
1815/* Each file descriptor (FDR) has a memory address, to simplify
1816 looking up an FDR by address, we build a table covering all FDRs
1817 that have a least one procedure descriptor in them. The final
1818 table will be sorted by address so we can look it up via binary
1819 search. */
1820
1823static boolean
1821static bfd_boolean
1824mk_fdrtab (abfd, debug_info, debug_swap, line_info)
1825 bfd *abfd;
1826 struct ecoff_debug_info * const debug_info;
1827 const struct ecoff_debug_swap * const debug_swap;
1828 struct ecoff_find_line *line_info;
1829{
1830 struct ecoff_fdrtab_entry *tab;
1831 FDR *fdr_ptr;
1832 FDR *fdr_start;
1833 FDR *fdr_end;
1822mk_fdrtab (abfd, debug_info, debug_swap, line_info)
1823 bfd *abfd;
1824 struct ecoff_debug_info * const debug_info;
1825 const struct ecoff_debug_swap * const debug_swap;
1826 struct ecoff_find_line *line_info;
1827{
1828 struct ecoff_fdrtab_entry *tab;
1829 FDR *fdr_ptr;
1830 FDR *fdr_start;
1831 FDR *fdr_end;
1834 boolean stabs;
1832 bfd_boolean stabs;
1835 long len;
1836 bfd_size_type amt;
1837
1838 fdr_start = debug_info->fdr;
1839 fdr_end = fdr_start + debug_info->symbolic_header.ifdMax;
1840
1833 long len;
1834 bfd_size_type amt;
1835
1836 fdr_start = debug_info->fdr;
1837 fdr_end = fdr_start + debug_info->symbolic_header.ifdMax;
1838
1841 /* First, let's see how long the table needs to be: */
1839 /* First, let's see how long the table needs to be. */
1842 for (len = 0, fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1843 {
1840 for (len = 0, fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1841 {
1844 if (fdr_ptr->cpd == 0) /* skip FDRs that have no PDRs */
1842 if (fdr_ptr->cpd == 0) /* Skip FDRs that have no PDRs. */
1845 continue;
1846 ++len;
1847 }
1848
1843 continue;
1844 ++len;
1845 }
1846
1849 /* Now, create and fill in the table: */
1850
1847 /* Now, create and fill in the table. */
1851 amt = (bfd_size_type) len * sizeof (struct ecoff_fdrtab_entry);
1852 line_info->fdrtab = (struct ecoff_fdrtab_entry*) bfd_zalloc (abfd, amt);
1853 if (line_info->fdrtab == NULL)
1848 amt = (bfd_size_type) len * sizeof (struct ecoff_fdrtab_entry);
1849 line_info->fdrtab = (struct ecoff_fdrtab_entry*) bfd_zalloc (abfd, amt);
1850 if (line_info->fdrtab == NULL)
1854 return false;
1851 return FALSE;
1855 line_info->fdrtab_len = len;
1856
1857 tab = line_info->fdrtab;
1858 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1859 {
1860 if (fdr_ptr->cpd == 0)
1861 continue;
1862
1863 /* Check whether this file has stabs debugging information. In
1864 a file with stabs debugging information, the second local
1865 symbol is named @stabs. */
1852 line_info->fdrtab_len = len;
1853
1854 tab = line_info->fdrtab;
1855 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1856 {
1857 if (fdr_ptr->cpd == 0)
1858 continue;
1859
1860 /* Check whether this file has stabs debugging information. In
1861 a file with stabs debugging information, the second local
1862 symbol is named @stabs. */
1866 stabs = false;
1863 stabs = FALSE;
1867 if (fdr_ptr->csym >= 2)
1868 {
1869 char *sym_ptr;
1870 SYMR sym;
1871
1872 sym_ptr = ((char *) debug_info->external_sym
1864 if (fdr_ptr->csym >= 2)
1865 {
1866 char *sym_ptr;
1867 SYMR sym;
1868
1869 sym_ptr = ((char *) debug_info->external_sym
1873 + (fdr_ptr->isymBase + 1)*debug_swap->external_sym_size);
1870 + (fdr_ptr->isymBase + 1) * debug_swap->external_sym_size);
1874 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
1875 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
1876 STABS_SYMBOL) == 0)
1871 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
1872 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
1873 STABS_SYMBOL) == 0)
1877 stabs = true;
1874 stabs = TRUE;
1878 }
1879
1880 if (!stabs)
1881 {
1875 }
1876
1877 if (!stabs)
1878 {
1882 bfd_size_type external_pdr_size;
1883 char *pdr_ptr;
1884 PDR pdr;
1885
1886 external_pdr_size = debug_swap->external_pdr_size;
1887
1888 pdr_ptr = ((char *) debug_info->external_pdr
1889 + fdr_ptr->ipdFirst * external_pdr_size);
1890 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1879 /* eraxxon: There are at least two problems with this computation:
1880 1) PDRs do *not* contain offsets but full vma's; and typically the
1881 address of the first PDR is the address of the FDR, which will
1882 make (most) of the results of the original computation 0!
1883 2) Once in a wacky while, the Compaq compiler generated PDR
1884 addresses do not equal the FDR vma, but they (the PDR address)
1885 are still vma's and not offsets. Cf. comments in
1886 'lookup_line'. */
1887#if 0
1888 bfd_size_type external_pdr_size;
1889 char *pdr_ptr;
1890 PDR pdr;
1891
1892 external_pdr_size = debug_swap->external_pdr_size;
1893
1894 pdr_ptr = ((char *) debug_info->external_pdr
1895 + fdr_ptr->ipdFirst * external_pdr_size);
1896 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1891 /* The address of the first PDR is the offset of that
1892 procedure relative to the beginning of file FDR. */
1897 /* The address of the first PDR is the offset of that
1898 procedure relative to the beginning of file FDR. */
1893 tab->base_addr = fdr_ptr->adr - pdr.adr;
1899 tab->base_addr = fdr_ptr->adr - pdr.adr;
1900#else
1901 /* The address of the first PDR is the offset of that
1902 procedure relative to the beginning of file FDR. */
1903 tab->base_addr = fdr_ptr->adr;
1904#endif
1894 }
1895 else
1896 {
1897 /* XXX I don't know about stabs, so this is a guess
1905 }
1906 else
1907 {
1908 /* XXX I don't know about stabs, so this is a guess
1898 (davidm@cs.arizona.edu): */
1909 (davidm@cs.arizona.edu). */
1899 tab->base_addr = fdr_ptr->adr;
1900 }
1901 tab->fdr = fdr_ptr;
1902 ++tab;
1903 }
1904
1905 /* Finally, the table is sorted in increasing memory-address order.
1906 The table is mostly sorted already, but there are cases (e.g.,
1907 static functions in include files), where this does not hold.
1908 Use "odump -PFv" to verify... */
1909 qsort ((PTR) line_info->fdrtab, (size_t) len,
1910 sizeof (struct ecoff_fdrtab_entry), cmp_fdrtab_entry);
1911
1910 tab->base_addr = fdr_ptr->adr;
1911 }
1912 tab->fdr = fdr_ptr;
1913 ++tab;
1914 }
1915
1916 /* Finally, the table is sorted in increasing memory-address order.
1917 The table is mostly sorted already, but there are cases (e.g.,
1918 static functions in include files), where this does not hold.
1919 Use "odump -PFv" to verify... */
1920 qsort ((PTR) line_info->fdrtab, (size_t) len,
1921 sizeof (struct ecoff_fdrtab_entry), cmp_fdrtab_entry);
1922
1912 return true;
1923 return TRUE;
1913}
1914
1915/* Return index of first FDR that covers to OFFSET. */
1916
1917static long
1918fdrtab_lookup (line_info, offset)
1919 struct ecoff_find_line *line_info;
1920 bfd_vma offset;

--- 13 unchanged lines hidden (view full) ---

1934 if (offset >= tab[mid].base_addr && offset < tab[mid + 1].base_addr)
1935 goto find_min;
1936
1937 if (tab[mid].base_addr > offset)
1938 high = mid;
1939 else
1940 low = mid + 1;
1941 }
1924}
1925
1926/* Return index of first FDR that covers to OFFSET. */
1927
1928static long
1929fdrtab_lookup (line_info, offset)
1930 struct ecoff_find_line *line_info;
1931 bfd_vma offset;

--- 13 unchanged lines hidden (view full) ---

1945 if (offset >= tab[mid].base_addr && offset < tab[mid + 1].base_addr)
1946 goto find_min;
1947
1948 if (tab[mid].base_addr > offset)
1949 high = mid;
1950 else
1951 low = mid + 1;
1952 }
1953
1954 /* eraxxon: at this point 'offset' is either lower than the lowest entry or
1955 higher than the highest entry. In the former case high = low = mid = 0;
1956 we want to return -1. In the latter case, low = high and mid = low - 1;
1957 we want to return the index of the highest entry. Only in former case
1958 will the following 'catch-all' test be true. */
1942 ++mid;
1943
1959 ++mid;
1960
1944 /* last entry is catch-all for all higher addresses: */
1961 /* Last entry is catch-all for all higher addresses. */
1945 if (offset < tab[mid].base_addr)
1946 return -1;
1947
1948 find_min:
1949
1962 if (offset < tab[mid].base_addr)
1963 return -1;
1964
1965 find_min:
1966
1967 /* eraxxon: There may be multiple FDRs in the table with the
1968 same base_addr; make sure that we are at the first one. */
1950 while (mid > 0 && tab[mid - 1].base_addr == tab[mid].base_addr)
1951 --mid;
1952
1953 return mid;
1954}
1955
1956/* Look up a line given an address, storing the information in
1957 LINE_INFO->cache. */
1958
1969 while (mid > 0 && tab[mid - 1].base_addr == tab[mid].base_addr)
1970 --mid;
1971
1972 return mid;
1973}
1974
1975/* Look up a line given an address, storing the information in
1976 LINE_INFO->cache. */
1977
1959static boolean
1978static bfd_boolean
1960lookup_line (abfd, debug_info, debug_swap, line_info)
1961 bfd *abfd;
1962 struct ecoff_debug_info * const debug_info;
1963 const struct ecoff_debug_swap * const debug_swap;
1964 struct ecoff_find_line *line_info;
1965{
1966 struct ecoff_fdrtab_entry *tab;
1967 bfd_vma offset;
1979lookup_line (abfd, debug_info, debug_swap, line_info)
1980 bfd *abfd;
1981 struct ecoff_debug_info * const debug_info;
1982 const struct ecoff_debug_swap * const debug_swap;
1983 struct ecoff_find_line *line_info;
1984{
1985 struct ecoff_fdrtab_entry *tab;
1986 bfd_vma offset;
1968 boolean stabs;
1987 bfd_boolean stabs;
1969 FDR *fdr_ptr;
1970 int i;
1971
1988 FDR *fdr_ptr;
1989 int i;
1990
1991 /* eraxxon: note that 'offset' is the full vma, not a section offset. */
1972 offset = line_info->cache.start;
1973
1974 /* Build FDR table (sorted by object file's base-address) if we
1975 don't have it already. */
1976 if (line_info->fdrtab == NULL
1977 && !mk_fdrtab (abfd, debug_info, debug_swap, line_info))
1992 offset = line_info->cache.start;
1993
1994 /* Build FDR table (sorted by object file's base-address) if we
1995 don't have it already. */
1996 if (line_info->fdrtab == NULL
1997 && !mk_fdrtab (abfd, debug_info, debug_swap, line_info))
1978 return false;
1998 return FALSE;
1979
1980 tab = line_info->fdrtab;
1981
1999
2000 tab = line_info->fdrtab;
2001
1982 /* find first FDR for address OFFSET */
2002 /* Find first FDR for address OFFSET. */
1983 i = fdrtab_lookup (line_info, offset);
1984 if (i < 0)
2003 i = fdrtab_lookup (line_info, offset);
2004 if (i < 0)
1985 return false; /* no FDR, no fun... */
2005 return FALSE; /* no FDR, no fun... */
2006
2007 /* eraxxon: 'fdrtab_lookup' doesn't give what we want, at least for Compaq's
2008 C++ compiler 6.2. Consider three FDRs with starting addresses of x, y,
2009 and z, respectively, such that x < y < z. Assume further that
2010 y < 'offset' < z. It is possible at times that the PDR for 'offset' is
2011 associated with FDR x and *not* with FDR y. Erg!!
2012
2013 From a binary dump of my C++ test case 'moo' using Compaq's coffobjanl
2014 (output format has been edited for our purposes):
2015
2016 FDR [2]: (main.C): First instruction: 0x12000207c <x>
2017 PDR [5] for File [2]: LoopTest__Xv <0x1200020a0> (a)
2018 PDR [7] for File [2]: foo__Xv <0x120002168>
2019 FDR [1]: (-1): First instruction: 0x1200020e8 <y>
2020 PDR [3] for File [1]: <0x120001ad0> (b)
2021 FDR [6]: (-1): First instruction: 0x1200026f0 <z>
2022
2023 (a) In the case of PDR5, the vma is such that the first few instructions
2024 of the procedure can be found. But since the size of this procedure is
2025 160b, the vma will soon cross into the 'address space' of FDR1 and no
2026 debugging info will be found. How repugnant!
2027
2028 (b) It is also possible for a PDR to have a *lower* vma than its associated
2029 FDR; see FDR1 and PDR3. Gross!
2030
2031 Since the FDRs that are causing so much havok (in this case) 1) do not
2032 describe actual files (fdr.rss == -1), and 2) contain only compiler
2033 generated routines, I thought a simple fix would be to exclude them from
2034 the FDR table in 'mk_fdrtab'. But, besides not knowing for certain
2035 whether this would be correct, it creates an additional problem. If we
2036 happen to ask for source file info on a compiler generated (procedure)
2037 symbol -- which is still in the symbol table -- the result can be
2038 information from a real procedure! This is because compiler generated
2039 procedures with vma's higher than the last FDR in the fdr table will be
2040 associated with a PDR from this FDR, specifically the PDR with the
2041 highest vma. This wasn't a problem before, because each procedure had a
2042 PDR. (Yes, this problem could be eliminated if we kept the size of the
2043 last PDR around, but things are already getting ugly).
2044
2045 Probably, a better solution would be to have a sorted PDR table. Each
2046 PDR would have a pointer to its FDR so file information could still be
2047 obtained. A FDR table could still be constructed if necessary -- since
2048 it only contains pointers, not much extra memory would be used -- but
2049 the PDR table would be searched to locate debugging info.
2050
2051 There is still at least one remaining issue. Sometimes a FDR can have a
2052 bogus name, but contain PDRs that should belong to another FDR with a
2053 real name. E.g:
2054
2055 FDR [3]: 0000000120001b50 (/home/.../Array.H~alt~deccxx_5E5A62AD)
2056 PDR [a] for File [3]: 0000000120001b50
2057 PDR [b] for File [3]: 0000000120001cf0
2058 PDR [c] for File [3]: 0000000120001dc8
2059 PDR [d] for File [3]: 0000000120001e40
2060 PDR [e] for File [3]: 0000000120001eb8
2061 PDR [f] for File [3]: 0000000120001f4c
2062 FDR [4]: 0000000120001b50 (/home/.../Array.H)
2063
2064 Here, FDR4 has the correct name, but should (seemingly) contain PDRa-f.
2065 The symbol table for PDR4 does contain symbols for PDRa-f, but so does
2066 the symbol table for FDR3. However the former is different; perhaps this
2067 can be detected easily. (I'm not sure at this point.) This problem only
2068 seems to be associated with files with templates. I am assuming the idea
2069 is that there is a 'fake' FDR (with PDRs) for each differently typed set
2070 of templates that must be generated. Currently, FDR4 is completely
2071 excluded from the FDR table in 'mk_fdrtab' because it contains no PDRs.
2072
2073 Since I don't have time to prepare a real fix for this right now, be
2074 prepared for 'A Horrible Hack' to force the inspection of all non-stabs
2075 FDRs. It's coming... */
1986 fdr_ptr = tab[i].fdr;
1987
1988 /* Check whether this file has stabs debugging information. In a
1989 file with stabs debugging information, the second local symbol is
1990 named @stabs. */
2076 fdr_ptr = tab[i].fdr;
2077
2078 /* Check whether this file has stabs debugging information. In a
2079 file with stabs debugging information, the second local symbol is
2080 named @stabs. */
1991 stabs = false;
2081 stabs = FALSE;
1992 if (fdr_ptr->csym >= 2)
1993 {
1994 char *sym_ptr;
1995 SYMR sym;
1996
1997 sym_ptr = ((char *) debug_info->external_sym
1998 + (fdr_ptr->isymBase + 1) * debug_swap->external_sym_size);
1999 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
2000 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
2001 STABS_SYMBOL) == 0)
2082 if (fdr_ptr->csym >= 2)
2083 {
2084 char *sym_ptr;
2085 SYMR sym;
2086
2087 sym_ptr = ((char *) debug_info->external_sym
2088 + (fdr_ptr->isymBase + 1) * debug_swap->external_sym_size);
2089 (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
2090 if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
2091 STABS_SYMBOL) == 0)
2002 stabs = true;
2092 stabs = TRUE;
2003 }
2004
2005 if (!stabs)
2006 {
2007 bfd_size_type external_pdr_size;
2008 char *pdr_ptr;
2009 char *best_pdr = NULL;
2010 FDR *best_fdr;
2093 }
2094
2095 if (!stabs)
2096 {
2097 bfd_size_type external_pdr_size;
2098 char *pdr_ptr;
2099 char *best_pdr = NULL;
2100 FDR *best_fdr;
2011 bfd_vma best_dist = ~(bfd_vma) 0;
2101 bfd_signed_vma best_dist = -1;
2012 PDR pdr;
2013 unsigned char *line_ptr;
2014 unsigned char *line_end;
2015 int lineno;
2016 /* This file uses ECOFF debugging information. Each FDR has a
2017 list of procedure descriptors (PDR). The address in the FDR
2018 is the absolute address of the first procedure. The address
2019 in the first PDR gives the offset of that procedure relative

--- 45 unchanged lines hidden (view full) ---

2065 Once, the right FDR and PDR are located, we simply walk
2066 through the line-number table to lookup the line-number that
2067 best matches ADDR. Obviously, things could be sped up by
2068 keeping a sorted list of PDRs instead of a sorted list of
2069 FDRs. However, this would increase space requirements
2070 considerably, which is undesirable. */
2071 external_pdr_size = debug_swap->external_pdr_size;
2072
2102 PDR pdr;
2103 unsigned char *line_ptr;
2104 unsigned char *line_end;
2105 int lineno;
2106 /* This file uses ECOFF debugging information. Each FDR has a
2107 list of procedure descriptors (PDR). The address in the FDR
2108 is the absolute address of the first procedure. The address
2109 in the first PDR gives the offset of that procedure relative

--- 45 unchanged lines hidden (view full) ---

2155 Once, the right FDR and PDR are located, we simply walk
2156 through the line-number table to lookup the line-number that
2157 best matches ADDR. Obviously, things could be sped up by
2158 keeping a sorted list of PDRs instead of a sorted list of
2159 FDRs. However, this would increase space requirements
2160 considerably, which is undesirable. */
2161 external_pdr_size = debug_swap->external_pdr_size;
2162
2073 /* Make offset relative to object file's start-address: */
2163#if 0 /* eraxxon: PDR addresses (pdr.adr) are not relative to FDRs!
2164 Leave 'offset' alone. */
2165 /* Make offset relative to object file's start-address. */
2074 offset -= tab[i].base_addr;
2166 offset -= tab[i].base_addr;
2167#endif
2168 /* eraxxon: The Horrible Hack: Because of the problems above, set 'i'
2169 to 0 so we look through all FDRs.
2170
2171 Because FDR's without any symbols are assumed to be non-stabs,
2172 searching through all FDRs may cause the following code to try to
2173 read stabs FDRs as ECOFF ones. However, I don't think this will
2174 harm anything. */
2175 i = 0;
2176
2075 /* Search FDR list starting at tab[i] for the PDR that best matches
2076 OFFSET. Normally, the FDR list is only one entry long. */
2077 best_fdr = NULL;
2078 do
2079 {
2177 /* Search FDR list starting at tab[i] for the PDR that best matches
2178 OFFSET. Normally, the FDR list is only one entry long. */
2179 best_fdr = NULL;
2180 do
2181 {
2080 bfd_vma dist, min_dist = 0;
2182 /* eraxxon: 'dist' and 'min_dist' can be negative now
2183 because we iterate over every FDR rather than just ones
2184 with a base address less than or equal to 'offset'. */
2185 bfd_signed_vma dist = -1, min_dist = -1;
2081 char *pdr_hold;
2082 char *pdr_end;
2083
2084 fdr_ptr = tab[i].fdr;
2085
2086 pdr_ptr = ((char *) debug_info->external_pdr
2087 + fdr_ptr->ipdFirst * external_pdr_size);
2088 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;

--- 6 unchanged lines hidden (view full) ---

2095 for (pdr_hold = NULL;
2096 pdr_ptr < pdr_end;
2097 (pdr_ptr += external_pdr_size,
2098 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr)))
2099 {
2100 if (offset >= (pdr.adr - 0x10 * pdr.prof))
2101 {
2102 dist = offset - (pdr.adr - 0x10 * pdr.prof);
2186 char *pdr_hold;
2187 char *pdr_end;
2188
2189 fdr_ptr = tab[i].fdr;
2190
2191 pdr_ptr = ((char *) debug_info->external_pdr
2192 + fdr_ptr->ipdFirst * external_pdr_size);
2193 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;

--- 6 unchanged lines hidden (view full) ---

2200 for (pdr_hold = NULL;
2201 pdr_ptr < pdr_end;
2202 (pdr_ptr += external_pdr_size,
2203 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr)))
2204 {
2205 if (offset >= (pdr.adr - 0x10 * pdr.prof))
2206 {
2207 dist = offset - (pdr.adr - 0x10 * pdr.prof);
2103 if (!pdr_hold || dist < min_dist)
2208
2209 /* eraxxon: 'dist' can be negative now. Note that
2210 'min_dist' can be negative if 'pdr_hold' below is NULL. */
2211 if (!pdr_hold || (dist >= 0 && dist < min_dist))
2104 {
2105 min_dist = dist;
2106 pdr_hold = pdr_ptr;
2107 }
2108 }
2109 }
2110
2212 {
2213 min_dist = dist;
2214 pdr_hold = pdr_ptr;
2215 }
2216 }
2217 }
2218
2111 if (!best_pdr || min_dist < best_dist)
2219 if (!best_pdr || (min_dist >= 0 && min_dist < best_dist))
2112 {
2220 {
2113 best_dist = min_dist;
2221 best_dist = (bfd_vma) min_dist;
2114 best_fdr = fdr_ptr;
2115 best_pdr = pdr_hold;
2116 }
2222 best_fdr = fdr_ptr;
2223 best_pdr = pdr_hold;
2224 }
2117 /* continue looping until base_addr of next entry is different: */
2225 /* Continue looping until base_addr of next entry is different. */
2118 }
2226 }
2119 while (++i < line_info->fdrtab_len
2120 && tab[i].base_addr == tab[i - 1].base_addr);
2227 /* eraxxon: We want to iterate over all FDRs.
2228 See previous comment about 'fdrtab_lookup'. */
2229 while (++i < line_info->fdrtab_len);
2121
2122 if (!best_fdr || !best_pdr)
2230
2231 if (!best_fdr || !best_pdr)
2123 return false; /* shouldn't happen... */
2232 return FALSE; /* Shouldn't happen... */
2124
2233
2125 /* phew, finally we got something that we can hold onto: */
2234 /* Phew, finally we got something that we can hold onto. */
2126 fdr_ptr = best_fdr;
2127 pdr_ptr = best_pdr;
2128 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2129 /* Now we can look for the actual line number. The line numbers
2130 are stored in a very funky format, which I won't try to
2131 describe. The search is bounded by the end of the FDRs line
2132 number entries. */
2133 line_end = debug_info->line + fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2134
2235 fdr_ptr = best_fdr;
2236 pdr_ptr = best_pdr;
2237 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2238 /* Now we can look for the actual line number. The line numbers
2239 are stored in a very funky format, which I won't try to
2240 describe. The search is bounded by the end of the FDRs line
2241 number entries. */
2242 line_end = debug_info->line + fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2243
2135 /* Make offset relative to procedure entry: */
2244 /* Make offset relative to procedure entry. */
2136 offset -= pdr.adr - 0x10 * pdr.prof;
2137 lineno = pdr.lnLow;
2138 line_ptr = debug_info->line + fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2139 while (line_ptr < line_end)
2140 {
2141 int delta;
2142 unsigned int count;
2143

--- 64 unchanged lines hidden (view full) ---

2208 bfd_size_type external_sym_size;
2209 const char *directory_name;
2210 const char *main_file_name;
2211 const char *current_file_name;
2212 const char *function_name;
2213 const char *line_file_name;
2214 bfd_vma low_func_vma;
2215 bfd_vma low_line_vma;
2245 offset -= pdr.adr - 0x10 * pdr.prof;
2246 lineno = pdr.lnLow;
2247 line_ptr = debug_info->line + fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2248 while (line_ptr < line_end)
2249 {
2250 int delta;
2251 unsigned int count;
2252

--- 64 unchanged lines hidden (view full) ---

2317 bfd_size_type external_sym_size;
2318 const char *directory_name;
2319 const char *main_file_name;
2320 const char *current_file_name;
2321 const char *function_name;
2322 const char *line_file_name;
2323 bfd_vma low_func_vma;
2324 bfd_vma low_line_vma;
2216 boolean past_line;
2217 boolean past_fn;
2325 bfd_boolean past_line;
2326 bfd_boolean past_fn;
2218 char *sym_ptr, *sym_ptr_end;
2219 size_t len, funclen;
2220 char *buffer = NULL;
2221
2222 /* This file uses stabs debugging information. When gcc is not
2223 optimizing, it will put the line number information before
2224 the function name stabs entry. When gcc is optimizing, it
2225 will put the stabs entry for all the function first, followed

--- 9 unchanged lines hidden (view full) ---

2235
2236 directory_name = NULL;
2237 main_file_name = NULL;
2238 current_file_name = NULL;
2239 function_name = NULL;
2240 line_file_name = NULL;
2241 low_func_vma = 0;
2242 low_line_vma = 0;
2327 char *sym_ptr, *sym_ptr_end;
2328 size_t len, funclen;
2329 char *buffer = NULL;
2330
2331 /* This file uses stabs debugging information. When gcc is not
2332 optimizing, it will put the line number information before
2333 the function name stabs entry. When gcc is optimizing, it
2334 will put the stabs entry for all the function first, followed

--- 9 unchanged lines hidden (view full) ---

2344
2345 directory_name = NULL;
2346 main_file_name = NULL;
2347 current_file_name = NULL;
2348 function_name = NULL;
2349 line_file_name = NULL;
2350 low_func_vma = 0;
2351 low_line_vma = 0;
2243 past_line = false;
2244 past_fn = false;
2352 past_line = FALSE;
2353 past_fn = FALSE;
2245
2246 external_sym_size = debug_swap->external_sym_size;
2247
2248 sym_ptr = ((char *) debug_info->external_sym
2249 + (fdr_ptr->isymBase + 2) * external_sym_size);
2250 sym_ptr_end = sym_ptr + (fdr_ptr->csym - 2) * external_sym_size;
2251 for (;
2252 sym_ptr < sym_ptr_end && (! past_line || ! past_fn);

--- 33 unchanged lines hidden (view full) ---

2286
2287 case N_SOL:
2288 current_file_name =
2289 debug_info->ss + fdr_ptr->issBase + sym.iss;
2290 break;
2291
2292 case N_FUN:
2293 if (sym.value > offset)
2354
2355 external_sym_size = debug_swap->external_sym_size;
2356
2357 sym_ptr = ((char *) debug_info->external_sym
2358 + (fdr_ptr->isymBase + 2) * external_sym_size);
2359 sym_ptr_end = sym_ptr + (fdr_ptr->csym - 2) * external_sym_size;
2360 for (;
2361 sym_ptr < sym_ptr_end && (! past_line || ! past_fn);

--- 33 unchanged lines hidden (view full) ---

2395
2396 case N_SOL:
2397 current_file_name =
2398 debug_info->ss + fdr_ptr->issBase + sym.iss;
2399 break;
2400
2401 case N_FUN:
2402 if (sym.value > offset)
2294 past_fn = true;
2403 past_fn = TRUE;
2295 else if (sym.value >= low_func_vma)
2296 {
2297 low_func_vma = sym.value;
2298 function_name =
2299 debug_info->ss + fdr_ptr->issBase + sym.iss;
2300 }
2301 break;
2302 }
2303 }
2304 else if (sym.st == stLabel && sym.index != indexNil)
2305 {
2306 if (sym.value > offset)
2404 else if (sym.value >= low_func_vma)
2405 {
2406 low_func_vma = sym.value;
2407 function_name =
2408 debug_info->ss + fdr_ptr->issBase + sym.iss;
2409 }
2410 break;
2411 }
2412 }
2413 else if (sym.st == stLabel && sym.index != indexNil)
2414 {
2415 if (sym.value > offset)
2307 past_line = true;
2416 past_line = TRUE;
2308 else if (sym.value >= low_line_vma)
2309 {
2310 low_line_vma = sym.value;
2311 line_file_name = current_file_name;
2312 line_info->cache.line_num = sym.index;
2313 }
2314 }
2315 }

--- 15 unchanged lines hidden (view full) ---

2331 len += strlen (directory_name) + strlen (main_file_name) + 1;
2332
2333 if (len != 0)
2334 {
2335 if (line_info->find_buffer != NULL)
2336 free (line_info->find_buffer);
2337 buffer = (char *) bfd_malloc ((bfd_size_type) len);
2338 if (buffer == NULL)
2417 else if (sym.value >= low_line_vma)
2418 {
2419 low_line_vma = sym.value;
2420 line_file_name = current_file_name;
2421 line_info->cache.line_num = sym.index;
2422 }
2423 }
2424 }

--- 15 unchanged lines hidden (view full) ---

2440 len += strlen (directory_name) + strlen (main_file_name) + 1;
2441
2442 if (len != 0)
2443 {
2444 if (line_info->find_buffer != NULL)
2445 free (line_info->find_buffer);
2446 buffer = (char *) bfd_malloc ((bfd_size_type) len);
2447 if (buffer == NULL)
2339 return false;
2448 return FALSE;
2340 line_info->find_buffer = buffer;
2341 }
2342
2343 if (function_name != NULL)
2344 {
2345 char *colon;
2346
2347 strcpy (buffer, function_name);

--- 11 unchanged lines hidden (view full) ---

2359 {
2360 sprintf (buffer + funclen, "%s%s", directory_name,
2361 main_file_name);
2362 line_info->cache.filename = buffer + funclen;
2363 }
2364 }
2365 }
2366
2449 line_info->find_buffer = buffer;
2450 }
2451
2452 if (function_name != NULL)
2453 {
2454 char *colon;
2455
2456 strcpy (buffer, function_name);

--- 11 unchanged lines hidden (view full) ---

2468 {
2469 sprintf (buffer + funclen, "%s%s", directory_name,
2470 main_file_name);
2471 line_info->cache.filename = buffer + funclen;
2472 }
2473 }
2474 }
2475
2367 return true;
2476 return TRUE;
2368}
2369
2370/* Do the work of find_nearest_line. */
2371
2477}
2478
2479/* Do the work of find_nearest_line. */
2480
2372boolean
2481bfd_boolean
2373_bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
2374 line_info, filename_ptr, functionname_ptr, retline_ptr)
2375 bfd *abfd;
2376 asection *section;
2377 bfd_vma offset;
2378 struct ecoff_debug_info * const debug_info;
2379 const struct ecoff_debug_swap * const debug_swap;
2380 struct ecoff_find_line *line_info;

--- 9 unchanged lines hidden (view full) ---

2390 || offset >= line_info->cache.stop)
2391 {
2392 line_info->cache.sect = section;
2393 line_info->cache.start = offset;
2394 line_info->cache.stop = offset;
2395 if (! lookup_line (abfd, debug_info, debug_swap, line_info))
2396 {
2397 line_info->cache.sect = NULL;
2482_bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
2483 line_info, filename_ptr, functionname_ptr, retline_ptr)
2484 bfd *abfd;
2485 asection *section;
2486 bfd_vma offset;
2487 struct ecoff_debug_info * const debug_info;
2488 const struct ecoff_debug_swap * const debug_swap;
2489 struct ecoff_find_line *line_info;

--- 9 unchanged lines hidden (view full) ---

2499 || offset >= line_info->cache.stop)
2500 {
2501 line_info->cache.sect = section;
2502 line_info->cache.start = offset;
2503 line_info->cache.stop = offset;
2504 if (! lookup_line (abfd, debug_info, debug_swap, line_info))
2505 {
2506 line_info->cache.sect = NULL;
2398 return false;
2507 return FALSE;
2399 }
2400 }
2401
2402 *filename_ptr = line_info->cache.filename;
2403 *functionname_ptr = line_info->cache.functionname;
2404 *retline_ptr = line_info->cache.line_num;
2405
2508 }
2509 }
2510
2511 *filename_ptr = line_info->cache.filename;
2512 *functionname_ptr = line_info->cache.functionname;
2513 *retline_ptr = line_info->cache.line_num;
2514
2406 return true;
2515 return TRUE;
2407}
2408
2409/* These routines copy symbolic information into a memory buffer.
2410
2411 FIXME: The whole point of the shuffle code is to avoid storing
2412 everything in memory, since the linker is such a memory hog. This
2413 code makes that effort useless. It is only called by the MIPS ELF
2414 code when generating a shared library, so it is not that big a
2415 deal, but it should be fixed eventually. */
2416
2417/* Collect a shuffle into a memory buffer. */
2418
2516}
2517
2518/* These routines copy symbolic information into a memory buffer.
2519
2520 FIXME: The whole point of the shuffle code is to avoid storing
2521 everything in memory, since the linker is such a memory hog. This
2522 code makes that effort useless. It is only called by the MIPS ELF
2523 code when generating a shared library, so it is not that big a
2524 deal, but it should be fixed eventually. */
2525
2526/* Collect a shuffle into a memory buffer. */
2527
2419static boolean ecoff_collect_shuffle PARAMS ((struct shuffle *, bfd_byte *));
2528static bfd_boolean ecoff_collect_shuffle
2529 PARAMS ((struct shuffle *, bfd_byte *));
2420
2530
2421static boolean
2531static bfd_boolean
2422ecoff_collect_shuffle (l, buff)
2423 struct shuffle *l;
2424 bfd_byte *buff;
2425{
2426 unsigned long total;
2427
2428 total = 0;
2429 for (; l != (struct shuffle *) NULL; l = l->next)
2430 {
2431 if (! l->filep)
2432 memcpy (buff, l->u.memory, l->size);
2433 else
2434 {
2435 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
2436 || (bfd_bread (buff, (bfd_size_type) l->size, l->u.file.input_bfd)
2437 != l->size))
2532ecoff_collect_shuffle (l, buff)
2533 struct shuffle *l;
2534 bfd_byte *buff;
2535{
2536 unsigned long total;
2537
2538 total = 0;
2539 for (; l != (struct shuffle *) NULL; l = l->next)
2540 {
2541 if (! l->filep)
2542 memcpy (buff, l->u.memory, l->size);
2543 else
2544 {
2545 if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
2546 || (bfd_bread (buff, (bfd_size_type) l->size, l->u.file.input_bfd)
2547 != l->size))
2438 return false;
2548 return FALSE;
2439 }
2440 total += l->size;
2441 buff += l->size;
2442 }
2443
2549 }
2550 total += l->size;
2551 buff += l->size;
2552 }
2553
2444 return true;
2554 return TRUE;
2445}
2446
2447/* Copy PDR information into a memory buffer. */
2448
2555}
2556
2557/* Copy PDR information into a memory buffer. */
2558
2449boolean
2559bfd_boolean
2450_bfd_ecoff_get_accumulated_pdr (handle, buff)
2451 PTR handle;
2452 bfd_byte *buff;
2453{
2454 struct accumulate *ainfo = (struct accumulate *) handle;
2455
2456 return ecoff_collect_shuffle (ainfo->pdr, buff);
2457}
2458
2459/* Copy symbol information into a memory buffer. */
2460
2560_bfd_ecoff_get_accumulated_pdr (handle, buff)
2561 PTR handle;
2562 bfd_byte *buff;
2563{
2564 struct accumulate *ainfo = (struct accumulate *) handle;
2565
2566 return ecoff_collect_shuffle (ainfo->pdr, buff);
2567}
2568
2569/* Copy symbol information into a memory buffer. */
2570
2461boolean
2571bfd_boolean
2462_bfd_ecoff_get_accumulated_sym (handle, buff)
2463 PTR handle;
2464 bfd_byte *buff;
2465{
2466 struct accumulate *ainfo = (struct accumulate *) handle;
2467
2468 return ecoff_collect_shuffle (ainfo->sym, buff);
2469}
2470
2471/* Copy the string table into a memory buffer. */
2472
2572_bfd_ecoff_get_accumulated_sym (handle, buff)
2573 PTR handle;
2574 bfd_byte *buff;
2575{
2576 struct accumulate *ainfo = (struct accumulate *) handle;
2577
2578 return ecoff_collect_shuffle (ainfo->sym, buff);
2579}
2580
2581/* Copy the string table into a memory buffer. */
2582
2473boolean
2583bfd_boolean
2474_bfd_ecoff_get_accumulated_ss (handle, buff)
2475 PTR handle;
2476 bfd_byte *buff;
2477{
2478 struct accumulate *ainfo = (struct accumulate *) handle;
2479 struct string_hash_entry *sh;
2480 unsigned long total;
2481

--- 10 unchanged lines hidden (view full) ---

2492 size_t len;
2493
2494 len = strlen (sh->root.string);
2495 memcpy (buff, (PTR) sh->root.string, len + 1);
2496 total += len + 1;
2497 buff += len + 1;
2498 }
2499
2584_bfd_ecoff_get_accumulated_ss (handle, buff)
2585 PTR handle;
2586 bfd_byte *buff;
2587{
2588 struct accumulate *ainfo = (struct accumulate *) handle;
2589 struct string_hash_entry *sh;
2590 unsigned long total;
2591

--- 10 unchanged lines hidden (view full) ---

2602 size_t len;
2603
2604 len = strlen (sh->root.string);
2605 memcpy (buff, (PTR) sh->root.string, len + 1);
2606 total += len + 1;
2607 buff += len + 1;
2608 }
2609
2500 return true;
2610 return TRUE;
2501}
2611}