/[gcl]/gcl/binutils/bfd/syms.c
ViewVC logotype

Diff of /gcl/binutils/bfd/syms.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by camm, Fri Aug 9 05:35:48 2002 UTC revision 1.1.1.1.20.1 by camm, Fri Sep 30 02:09:07 2005 UTC
# Line 1  Line 1 
1  /* Generic symbol-table support for the BFD library.  /* Generic symbol-table support for the BFD library.
2     Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,     Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3     2000, 2001, 2002     2000, 2001, 2002, 2003, 2004
4     Free Software Foundation, Inc.     Free Software Foundation, Inc.
5     Written by Cygnus Support.     Written by Cygnus Support.
6    
7  This file is part of BFD, the Binary File Descriptor library.     This file is part of BFD, the Binary File Descriptor library.
8    
9  This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.     (at your option) any later version.
13    
14  This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.     GNU General Public License for more details.
18    
19  You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22    
23  /*  /*
24  SECTION  SECTION
# Line 74  SUBSECTION Line 74  SUBSECTION
74  |         if (storage_needed < 0)  |         if (storage_needed < 0)
75  |           FAIL  |           FAIL
76  |  |
77  |         if (storage_needed == 0) {  |         if (storage_needed == 0)
78  |            return ;  |           return;
79  |         }  |        
80  |         symbol_table = (asymbol **) xmalloc (storage_needed);  |         symbol_table = xmalloc (storage_needed);
81  |           ...  |           ...
82  |         number_of_symbols =  |         number_of_symbols =
83  |            bfd_canonicalize_symtab (abfd, symbol_table);  |            bfd_canonicalize_symtab (abfd, symbol_table);
# Line 85  SUBSECTION Line 85  SUBSECTION
85  |         if (number_of_symbols < 0)  |         if (number_of_symbols < 0)
86  |           FAIL  |           FAIL
87  |  |
88  |         for (i = 0; i < number_of_symbols; i++) {  |         for (i = 0; i < number_of_symbols; i++)
89  |            process_symbol (symbol_table[i]);  |           process_symbol (symbol_table[i]);
 |         }  
90    
91          All storage for the symbols themselves is in an objalloc          All storage for the symbols themselves is in an objalloc
92          connected to the BFD; it is freed when the BFD is closed.          connected to the BFD; it is freed when the BFD is closed.
# Line 108  SUBSECTION Line 107  SUBSECTION
107          example showing the creation of a symbol table with only one element:          example showing the creation of a symbol table with only one element:
108    
109  |       #include "bfd.h"  |       #include "bfd.h"
110  |       main()  |       int main (void)
111  |       {  |       {
112  |         bfd *abfd;  |         bfd *abfd;
113  |         asymbol *ptrs[2];  |         asymbol *ptrs[2];
114  |         asymbol *new;  |         asymbol *new;
115  |  |
116  |         abfd = bfd_openw("foo","a.out-sunos-big");  |         abfd = bfd_openw ("foo","a.out-sunos-big");
117  |         bfd_set_format(abfd, bfd_object);  |         bfd_set_format (abfd, bfd_object);
118  |         new = bfd_make_empty_symbol(abfd);  |         new = bfd_make_empty_symbol (abfd);
119  |         new->name = "dummy_symbol";  |         new->name = "dummy_symbol";
120  |         new->section = bfd_make_section_old_way(abfd, ".text");  |         new->section = bfd_make_section_old_way (abfd, ".text");
121  |         new->flags = BSF_GLOBAL;  |         new->flags = BSF_GLOBAL;
122  |         new->value = 0x12345;  |         new->value = 0x12345;
123  |  |
124  |         ptrs[0] = new;  |         ptrs[0] = new;
125  |         ptrs[1] = (asymbol *)0;  |         ptrs[1] = 0;
126  |  |
127  |         bfd_set_symtab(abfd, ptrs, 1);  |         bfd_set_symtab (abfd, ptrs, 1);
128  |         bfd_close(abfd);  |         bfd_close (abfd);
129    |         return 0;
130  |       }  |       }
131  |  |
132  |       ./makesym  |       ./makesym
133  |       nm foo  |       nm foo
134  |       00012345 A dummy_symbol  |       00012345 A dummy_symbol
135    
136          Many formats cannot represent arbitary symbol information; for          Many formats cannot represent arbitrary symbol information; for
137          instance, the <<a.out>> object format does not allow an          instance, the <<a.out>> object format does not allow an
138          arbitary number of sections. A symbol pointing to a section          arbitrary number of sections. A symbol pointing to a section
139          which is not one  of <<.text>>, <<.data>> or <<.bss>> cannot          which is not one  of <<.text>>, <<.data>> or <<.bss>> cannot
140          be described.          be described.
141    
# Line 181  SUBSECTION Line 181  SUBSECTION
181  CODE_FRAGMENT  CODE_FRAGMENT
182    
183  .  .
184  .typedef struct symbol_cache_entry  .typedef struct bfd_symbol
185  .{  .{
186  .  {* A pointer to the BFD which owns the symbol. This information  .  {* A pointer to the BFD which owns the symbol. This information
187  .     is necessary so that a back end can work out what additional  .     is necessary so that a back end can work out what additional
# Line 192  CODE_FRAGMENT Line 192  CODE_FRAGMENT
192  .     instead, except that some symbols point to the global sections  .     instead, except that some symbols point to the global sections
193  .     bfd_{abs,com,und}_section.  This could be fixed by making  .     bfd_{abs,com,und}_section.  This could be fixed by making
194  .     these globals be per-bfd (or per-target-flavor).  FIXME.  *}  .     these globals be per-bfd (or per-target-flavor).  FIXME.  *}
195  .  struct _bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field.  *}  .  struct bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field.  *}
196  .  .
197  .  {* The text of the symbol. The name is left alone, and not copied; the  .  {* The text of the symbol. The name is left alone, and not copied; the
198  .     application may not alter it.  *}  .     application may not alter it.  *}
# Line 222  CODE_FRAGMENT Line 222  CODE_FRAGMENT
222  .     <<BSF_LOCAL>>, <<BSF_FORT_COMM>>,  <<BSF_UNDEFINED>> or  .     <<BSF_LOCAL>>, <<BSF_FORT_COMM>>,  <<BSF_UNDEFINED>> or
223  .     <<BSF_GLOBAL>>.  *}  .     <<BSF_GLOBAL>>.  *}
224  .  .
225  .  {* The symbol is a debugging record. The value has an arbitary  .  {* The symbol is a debugging record. The value has an arbitrary
226  .     meaning, unless BSF_DEBUGGING_RELOC is also set.  *}  .     meaning, unless BSF_DEBUGGING_RELOC is also set.  *}
227  .#define BSF_DEBUGGING  0x08  .#define BSF_DEBUGGING  0x08
228  .  .
# Line 293  CODE_FRAGMENT Line 293  CODE_FRAGMENT
293  .  {* A pointer to the section to which this symbol is  .  {* A pointer to the section to which this symbol is
294  .     relative.  This will always be non NULL, there are special  .     relative.  This will always be non NULL, there are special
295  .     sections for undefined and absolute symbols.  *}  .     sections for undefined and absolute symbols.  *}
296  .  struct sec *section;  .  struct bfd_section *section;
297  .  .
298  .  {* Back end special data.  *}  .  {* Back end special data.  *}
299  .  union  .  union
300  .    {  .    {
301  .      PTR p;  .      void *p;
302  .      bfd_vma i;  .      bfd_vma i;
303  .    }  .    }
304  .  udata;  .  udata;
# Line 314  CODE_FRAGMENT Line 314  CODE_FRAGMENT
314  #include "bfdlink.h"  #include "bfdlink.h"
315  #include "aout/stab_gnu.h"  #include "aout/stab_gnu.h"
316    
 static char coff_section_type PARAMS ((const char *));  
 static char decode_section_type PARAMS ((const struct sec *));  
 static int cmpindexentry PARAMS ((const PTR, const PTR));  
   
317  /*  /*
318  DOCDD  DOCDD
319  INODE  INODE
# Line 346  FUNCTION Line 342  FUNCTION
342          bfd_is_local_label          bfd_is_local_label
343    
344  SYNOPSIS  SYNOPSIS
345          boolean bfd_is_local_label(bfd *abfd, asymbol *sym);          bfd_boolean bfd_is_local_label (bfd *abfd, asymbol *sym);
346    
347  DESCRIPTION  DESCRIPTION
348          Return true if the given symbol @var{sym} in the BFD @var{abfd} is          Return TRUE if the given symbol @var{sym} in the BFD @var{abfd} is
349          a compiler generated local label, else return false.          a compiler generated local label, else return FALSE.
350  */  */
351    
352  boolean  bfd_boolean
353  bfd_is_local_label (abfd, sym)  bfd_is_local_label (bfd *abfd, asymbol *sym)
      bfd *abfd;  
      asymbol *sym;  
354  {  {
355    /* The BSF_SECTION_SYM check is needed for IA-64, where every label that    /* The BSF_SECTION_SYM check is needed for IA-64, where every label that
356       starts with '.' is local.  This would accidentally catch section names       starts with '.' is local.  This would accidentally catch section names
357       if we didn't reject them here.  */       if we didn't reject them here.  */
358    if ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_SECTION_SYM)) != 0)    if ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_FILE | BSF_SECTION_SYM)) != 0)
359      return false;      return FALSE;
360    if (sym->name == NULL)    if (sym->name == NULL)
361      return false;      return FALSE;
362    return bfd_is_local_label_name (abfd, sym->name);    return bfd_is_local_label_name (abfd, sym->name);
363  }  }
364    
# Line 373  FUNCTION Line 367  FUNCTION
367          bfd_is_local_label_name          bfd_is_local_label_name
368    
369  SYNOPSIS  SYNOPSIS
370          boolean bfd_is_local_label_name(bfd *abfd, const char *name);          bfd_boolean bfd_is_local_label_name (bfd *abfd, const char *name);
371    
372  DESCRIPTION  DESCRIPTION
373          Return true if a symbol with the name @var{name} in the BFD          Return TRUE if a symbol with the name @var{name} in the BFD
374          @var{abfd} is a compiler generated local label, else return          @var{abfd} is a compiler generated local label, else return
375          false.  This just checks whether the name has the form of a          FALSE.  This just checks whether the name has the form of a
376          local label.          local label.
377    
378  .#define bfd_is_local_label_name(abfd, name) \  .#define bfd_is_local_label_name(abfd, name) \
379  .     BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))  .  BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
380    .
381    */
382    
383    /*
384    FUNCTION
385            bfd_is_target_special_symbol
386    
387    SYNOPSIS
388            bfd_boolean bfd_is_target_special_symbol (bfd *abfd, asymbol *sym);
389    
390    DESCRIPTION
391            Return TRUE iff a symbol @var{sym} in the BFD @var{abfd} is something
392            special to the particular target represented by the BFD.  Such symbols
393            should normally not be mentioned to the user.
394    
395    .#define bfd_is_target_special_symbol(abfd, sym) \
396    .  BFD_SEND (abfd, _bfd_is_target_special_symbol, (abfd, sym))
397  .  .
398  */  */
399    
# Line 398  DESCRIPTION Line 409  DESCRIPTION
409          including the NULL.          including the NULL.
410    
411  .#define bfd_canonicalize_symtab(abfd, location) \  .#define bfd_canonicalize_symtab(abfd, location) \
412  .     BFD_SEND (abfd, _bfd_canonicalize_symtab,\  .  BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
 .                  (abfd, location))  
413  .  .
414  */  */
415    
# Line 408  FUNCTION Line 418  FUNCTION
418          bfd_set_symtab          bfd_set_symtab
419    
420  SYNOPSIS  SYNOPSIS
421          boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);          bfd_boolean bfd_set_symtab
422              (bfd *abfd, asymbol **location, unsigned int count);
423    
424  DESCRIPTION  DESCRIPTION
425          Arrange that when the output BFD @var{abfd} is closed,          Arrange that when the output BFD @var{abfd} is closed,
# Line 416  DESCRIPTION Line 427  DESCRIPTION
427          will be written.          will be written.
428  */  */
429    
430  boolean  bfd_boolean
431  bfd_set_symtab (abfd, location, symcount)  bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int symcount)
      bfd *abfd;  
      asymbol **location;  
      unsigned int symcount;  
432  {  {
433    if ((abfd->format != bfd_object) || (bfd_read_p (abfd)))    if (abfd->format != bfd_object || bfd_read_p (abfd))
434      {      {
435        bfd_set_error (bfd_error_invalid_operation);        bfd_set_error (bfd_error_invalid_operation);
436        return false;        return FALSE;
437      }      }
438    
439    bfd_get_outsymbols (abfd) = location;    bfd_get_outsymbols (abfd) = location;
440    bfd_get_symcount (abfd) = symcount;    bfd_get_symcount (abfd) = symcount;
441    return true;    return TRUE;
442  }  }
443    
444  /*  /*
# Line 438  FUNCTION Line 446  FUNCTION
446          bfd_print_symbol_vandf          bfd_print_symbol_vandf
447    
448  SYNOPSIS  SYNOPSIS
449          void bfd_print_symbol_vandf(bfd *abfd, PTR file, asymbol *symbol);          void bfd_print_symbol_vandf (bfd *abfd, void *file, asymbol *symbol);
450    
451  DESCRIPTION  DESCRIPTION
452          Print the value and flags of the @var{symbol} supplied to the          Print the value and flags of the @var{symbol} supplied to the
453          stream @var{file}.          stream @var{file}.
454  */  */
455  void  void
456  bfd_print_symbol_vandf (abfd, arg, symbol)  bfd_print_symbol_vandf (bfd *abfd, void *arg, asymbol *symbol)
      bfd *abfd;  
      PTR arg;  
      asymbol *symbol;  
457  {  {
458    FILE *file = (FILE *) arg;    FILE *file = arg;
459    
460    flagword type = symbol->flags;    flagword type = symbol->flags;
461    if (symbol->section != (asection *) NULL)  
462      {    if (symbol->section != NULL)
463        bfd_fprintf_vma (abfd, file,      bfd_fprintf_vma (abfd, file, symbol->value + symbol->section->vma);
                        symbol->value + symbol->section->vma);  
     }  
464    else    else
465      {      bfd_fprintf_vma (abfd, file, symbol->value);
       bfd_fprintf_vma (abfd, file, symbol->value);  
     }  
466    
467    /* This presumes that a symbol can not be both BSF_DEBUGGING and    /* This presumes that a symbol can not be both BSF_DEBUGGING and
468       BSF_DYNAMIC, nor more than one of BSF_FUNCTION, BSF_FILE, and       BSF_DYNAMIC, nor more than one of BSF_FUNCTION, BSF_FILE, and
# Line 495  DESCRIPTION Line 497  DESCRIPTION
497          information, and will cause problems later on.          information, and will cause problems later on.
498    
499  .#define bfd_make_empty_symbol(abfd) \  .#define bfd_make_empty_symbol(abfd) \
500  .     BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))  .  BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
501  .  .
502  */  */
503    
# Line 514  DESCRIPTION Line 516  DESCRIPTION
516  */  */
517    
518  asymbol *  asymbol *
519  _bfd_generic_make_empty_symbol (abfd)  _bfd_generic_make_empty_symbol (bfd *abfd)
      bfd *abfd;  
520  {  {
521    bfd_size_type amt = sizeof (asymbol);    bfd_size_type amt = sizeof (asymbol);
522    asymbol *new = (asymbol *) bfd_zalloc (abfd, amt);    asymbol *new = bfd_zalloc (abfd, amt);
523    if (new)    if (new)
524      new->the_bfd = abfd;      new->the_bfd = abfd;
525    return new;    return new;
# Line 534  DESCRIPTION Line 535  DESCRIPTION
535          yet to be worked out.          yet to be worked out.
536    
537  .#define bfd_make_debug_symbol(abfd,ptr,size) \  .#define bfd_make_debug_symbol(abfd,ptr,size) \
538  .        BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))  .  BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
539  .  .
540  */  */
541    
# Line 578  static const struct section_to_type stt[ Line 579  static const struct section_to_type stt[
579     't' as well as .text */     't' as well as .text */
580    
581  static char  static char
582  coff_section_type (s)  coff_section_type (const char *s)
      const char *s;  
583  {  {
584    const struct section_to_type *t;    const struct section_to_type *t;
585    
# Line 598  coff_section_type (s) Line 598  coff_section_type (s)
598     we could perhaps obsolete coff_section_type.  */     we could perhaps obsolete coff_section_type.  */
599    
600  static char  static char
601  decode_section_type (section)  decode_section_type (const struct bfd_section *section)
      const struct sec *section;  
602  {  {
603    if (section->flags & SEC_CODE)    if (section->flags & SEC_CODE)
604      return 't';      return 't';
# Line 621  decode_section_type (section) Line 620  decode_section_type (section)
620      }      }
621    if (section->flags & SEC_DEBUGGING)    if (section->flags & SEC_DEBUGGING)
622      return 'N';      return 'N';
623      if ((section->flags & SEC_HAS_CONTENTS) && (section->flags & SEC_READONLY))
624        return 'n';
625    
626    return '?';    return '?';
627  }  }
# Line 634  DESCRIPTION Line 635  DESCRIPTION
635          class of @var{symbol}, or '?' for an unknown class.          class of @var{symbol}, or '?' for an unknown class.
636    
637  SYNOPSIS  SYNOPSIS
638          int bfd_decode_symclass(asymbol *symbol);          int bfd_decode_symclass (asymbol *symbol);
639  */  */
640  int  int
641  bfd_decode_symclass (symbol)  bfd_decode_symclass (asymbol *symbol)
      asymbol *symbol;  
642  {  {
643    char c;    char c;
644    
# Line 706  DESCRIPTION Line 706  DESCRIPTION
706          Returns zero otherwise.          Returns zero otherwise.
707    
708  SYNOPSIS  SYNOPSIS
709          boolean bfd_is_undefined_symclass (int symclass);          bfd_boolean bfd_is_undefined_symclass (int symclass);
710  */  */
711    
712  boolean  bfd_boolean
713  bfd_is_undefined_symclass (symclass)  bfd_is_undefined_symclass (int symclass)
      int symclass;  
714  {  {
715    return symclass == 'U' || symclass == 'w' || symclass == 'v';    return symclass == 'U' || symclass == 'w' || symclass == 'v';
716  }  }
# Line 726  DESCRIPTION Line 725  DESCRIPTION
725          calling this function.          calling this function.
726    
727  SYNOPSIS  SYNOPSIS
728          void bfd_symbol_info(asymbol *symbol, symbol_info *ret);          void bfd_symbol_info (asymbol *symbol, symbol_info *ret);
729  */  */
730    
731  void  void
732  bfd_symbol_info (symbol, ret)  bfd_symbol_info (asymbol *symbol, symbol_info *ret)
      asymbol *symbol;  
      symbol_info *ret;  
733  {  {
734    ret->type = bfd_decode_symclass (symbol);    ret->type = bfd_decode_symclass (symbol);
735    
# Line 749  FUNCTION Line 746  FUNCTION
746          bfd_copy_private_symbol_data          bfd_copy_private_symbol_data
747    
748  SYNOPSIS  SYNOPSIS
749          boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);          bfd_boolean bfd_copy_private_symbol_data
750              (bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
751    
752  DESCRIPTION  DESCRIPTION
753          Copy private symbol information from @var{isym} in the BFD          Copy private symbol information from @var{isym} in the BFD
754          @var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.          @var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.
755          Return <<true>> on success, <<false>> on error.  Possible error          Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
756          returns are:          returns are:
757    
758          o <<bfd_error_no_memory>> -          o <<bfd_error_no_memory>> -
759          Not enough memory exists to create private data for @var{osec}.          Not enough memory exists to create private data for @var{osec}.
760    
761  .#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \  .#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
762  .     BFD_SEND (obfd, _bfd_copy_private_symbol_data, \  .  BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
763  .               (ibfd, isymbol, obfd, osymbol))  .            (ibfd, isymbol, obfd, osymbol))
764  .  .
765  */  */
766    
# Line 771  DESCRIPTION Line 769  DESCRIPTION
769     version.  It just uses BFD asymbol structures as mini symbols.  */     version.  It just uses BFD asymbol structures as mini symbols.  */
770    
771  long  long
772  _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep)  _bfd_generic_read_minisymbols (bfd *abfd,
773       bfd *abfd;                                 bfd_boolean dynamic,
774       boolean dynamic;                                 void **minisymsp,
775       PTR *minisymsp;                                 unsigned int *sizep)
      unsigned int *sizep;  
776  {  {
777    long storage;    long storage;
778    asymbol **syms = NULL;    asymbol **syms = NULL;
# Line 790  _bfd_generic_read_minisymbols (abfd, dyn Line 787  _bfd_generic_read_minisymbols (abfd, dyn
787    if (storage == 0)    if (storage == 0)
788      return 0;      return 0;
789    
790    syms = (asymbol **) bfd_malloc ((bfd_size_type) storage);    syms = bfd_malloc (storage);
791    if (syms == NULL)    if (syms == NULL)
792      goto error_return;      goto error_return;
793    
# Line 801  _bfd_generic_read_minisymbols (abfd, dyn Line 798  _bfd_generic_read_minisymbols (abfd, dyn
798    if (symcount < 0)    if (symcount < 0)
799      goto error_return;      goto error_return;
800    
801    *minisymsp = (PTR) syms;    *minisymsp = syms;
802    *sizep = sizeof (asymbol *);    *sizep = sizeof (asymbol *);
803    return symcount;    return symcount;
804    
805   error_return:   error_return:
806      bfd_set_error (bfd_error_no_symbols);
807    if (syms != NULL)    if (syms != NULL)
808      free (syms);      free (syms);
809    return -1;    return -1;
# Line 815  _bfd_generic_read_minisymbols (abfd, dyn Line 813  _bfd_generic_read_minisymbols (abfd, dyn
813     an asymbol.  We don't worry about the sym argument we are passed;     an asymbol.  We don't worry about the sym argument we are passed;
814     we just return the asymbol the minisymbol points to.  */     we just return the asymbol the minisymbol points to.  */
815    
 /*ARGSUSED*/  
816  asymbol *  asymbol *
817  _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym)  _bfd_generic_minisymbol_to_symbol (bfd *abfd ATTRIBUTE_UNUSED,
818       bfd *abfd ATTRIBUTE_UNUSED;                                     bfd_boolean dynamic ATTRIBUTE_UNUSED,
819       boolean dynamic ATTRIBUTE_UNUSED;                                     const void *minisym,
820       const PTR minisym;                                     asymbol *sym ATTRIBUTE_UNUSED)
      asymbol *sym ATTRIBUTE_UNUSED;  
821  {  {
822    return *(asymbol **) minisym;    return *(asymbol **) minisym;
823  }  }
# Line 829  _bfd_generic_minisymbol_to_symbol (abfd, Line 825  _bfd_generic_minisymbol_to_symbol (abfd,
825  /* Look through stabs debugging information in .stab and .stabstr  /* Look through stabs debugging information in .stab and .stabstr
826     sections to find the source file and line closest to a desired     sections to find the source file and line closest to a desired
827     location.  This is used by COFF and ELF targets.  It sets *pfound     location.  This is used by COFF and ELF targets.  It sets *pfound
828     to true if it finds some information.  The *pinfo field is used to     to TRUE if it finds some information.  The *pinfo field is used to
829     pass cached information in and out of this routine; this first time     pass cached information in and out of this routine; this first time
830     the routine is called for a BFD, *pinfo should be NULL.  The value     the routine is called for a BFD, *pinfo should be NULL.  The value
831     placed in *pinfo should be saved with the BFD, and passed back each     placed in *pinfo should be saved with the BFD, and passed back each
# Line 856  struct indexentry Line 852  struct indexentry
852  /* Compare two indexentry structures.  This is called via qsort.  */  /* Compare two indexentry structures.  This is called via qsort.  */
853    
854  static int  static int
855  cmpindexentry (a, b)  cmpindexentry (const void *a, const void *b)
      const PTR a;  
      const PTR b;  
856  {  {
857    const struct indexentry *contestantA = (const struct indexentry *) a;    const struct indexentry *contestantA = a;
858    const struct indexentry *contestantB = (const struct indexentry *) b;    const struct indexentry *contestantB = b;
859    
860    if (contestantA->val < contestantB->val)    if (contestantA->val < contestantB->val)
861      return -1;      return -1;
# Line 901  struct stab_find_info Line 895  struct stab_find_info
895    char *filename;    char *filename;
896  };  };
897    
898  boolean  bfd_boolean
899  _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,  _bfd_stab_section_find_nearest_line (bfd *abfd,
900                                       pfilename, pfnname, pline, pinfo)                                       asymbol **symbols,
901       bfd *abfd;                                       asection *section,
902       asymbol **symbols;                                       bfd_vma offset,
903       asection *section;                                       bfd_boolean *pfound,
904       bfd_vma offset;                                       const char **pfilename,
905       boolean *pfound;                                       const char **pfnname,
906       const char **pfilename;                                       unsigned int *pline,
907       const char **pfnname;                                       void **pinfo)
      unsigned int *pline;  
      PTR *pinfo;  
908  {  {
909    struct stab_find_info *info;    struct stab_find_info *info;
910    bfd_size_type stabsize, strsize;    bfd_size_type stabsize, strsize;
# Line 923  _bfd_stab_section_find_nearest_line (abf Line 915  _bfd_stab_section_find_nearest_line (abf
915    char *file_name;    char *file_name;
916    char *directory_name;    char *directory_name;
917    int saw_fun;    int saw_fun;
918    boolean saw_line, saw_func;    bfd_boolean saw_line, saw_func;
919    
920    *pfound = false;    *pfound = FALSE;
921    *pfilename = bfd_get_filename (abfd);    *pfilename = bfd_get_filename (abfd);
922    *pfnname = NULL;    *pfnname = NULL;
923    *pline = 0;    *pline = 0;
# Line 950  _bfd_stab_section_find_nearest_line (abf Line 942  _bfd_stab_section_find_nearest_line (abf
942  #define VALOFF (8)  #define VALOFF (8)
943  #define STABSIZE (12)  #define STABSIZE (12)
944    
945    info = (struct stab_find_info *) *pinfo;    info = *pinfo;
946    if (info != NULL)    if (info != NULL)
947      {      {
948        if (info->stabsec == NULL || info->strsec == NULL)        if (info->stabsec == NULL || info->strsec == NULL)
949          {          {
950            /* No stabs debugging information.  */            /* No stabs debugging information.  */
951            return true;            return TRUE;
952          }          }
953    
954        stabsize = info->stabsec->_raw_size;        stabsize = (info->stabsec->rawsize
955        strsize = info->strsec->_raw_size;                    ? info->stabsec->rawsize
956                      : info->stabsec->size);
957          strsize = (info->strsec->rawsize
958                     ? info->strsec->rawsize
959                     : info->strsec->size);
960      }      }
961    else    else
962      {      {
# Line 971  _bfd_stab_section_find_nearest_line (abf Line 967  _bfd_stab_section_find_nearest_line (abf
967        char *function_name;        char *function_name;
968        bfd_size_type amt = sizeof *info;        bfd_size_type amt = sizeof *info;
969    
970        info = (struct stab_find_info *) bfd_zalloc (abfd, amt);        info = bfd_zalloc (abfd, amt);
971        if (info == NULL)        if (info == NULL)
972          return false;          return FALSE;
973    
974        /* FIXME: When using the linker --split-by-file or        /* FIXME: When using the linker --split-by-file or
975           --split-by-reloc options, it is possible for the .stab and           --split-by-reloc options, it is possible for the .stab and
# Line 986  _bfd_stab_section_find_nearest_line (abf Line 982  _bfd_stab_section_find_nearest_line (abf
982          {          {
983            /* No stabs debugging information.  Set *pinfo so that we            /* No stabs debugging information.  Set *pinfo so that we
984               can return quickly in the info != NULL case above.  */               can return quickly in the info != NULL case above.  */
985            *pinfo = (PTR) info;            *pinfo = info;
986            return true;            return TRUE;
987          }          }
988    
989        stabsize = info->stabsec->_raw_size;        stabsize = (info->stabsec->rawsize
990        strsize = info->strsec->_raw_size;                    ? info->stabsec->rawsize
991                      : info->stabsec->size);
992          strsize = (info->strsec->rawsize
993                     ? info->strsec->rawsize
994                     : info->strsec->size);
995    
996        info->stabs = (bfd_byte *) bfd_alloc (abfd, stabsize);        info->stabs = bfd_alloc (abfd, stabsize);
997        info->strs = (bfd_byte *) bfd_alloc (abfd, strsize);        info->strs = bfd_alloc (abfd, strsize);
998        if (info->stabs == NULL || info->strs == NULL)        if (info->stabs == NULL || info->strs == NULL)
999          return false;          return FALSE;
1000    
1001        if (! bfd_get_section_contents (abfd, info->stabsec, info->stabs,        if (! bfd_get_section_contents (abfd, info->stabsec, info->stabs,
1002                                        (bfd_vma) 0, stabsize)                                        0, stabsize)
1003            || ! bfd_get_section_contents (abfd, info->strsec, info->strs,            || ! bfd_get_section_contents (abfd, info->strsec, info->strs,
1004                                           (bfd_vma) 0, strsize))                                           0, strsize))
1005          return false;          return FALSE;
1006    
1007        /* If this is a relocateable object file, we have to relocate        /* If this is a relocatable object file, we have to relocate
1008           the entries in .stab.  This should always be simple 32 bit           the entries in .stab.  This should always be simple 32 bit
1009           relocations against symbols defined in this object file, so           relocations against symbols defined in this object file, so
1010           this should be no big deal.  */           this should be no big deal.  */
1011        reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec);        reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec);
1012        if (reloc_size < 0)        if (reloc_size < 0)
1013          return false;          return FALSE;
1014        reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);        reloc_vector = bfd_malloc (reloc_size);
1015        if (reloc_vector == NULL && reloc_size != 0)        if (reloc_vector == NULL && reloc_size != 0)
1016          return false;          return FALSE;
1017        reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector,        reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector,
1018                                              symbols);                                              symbols);
1019        if (reloc_count < 0)        if (reloc_count < 0)
1020          {          {
1021            if (reloc_vector != NULL)            if (reloc_vector != NULL)
1022              free (reloc_vector);              free (reloc_vector);
1023            return false;            return FALSE;
1024          }          }
1025        if (reloc_count > 0)        if (reloc_count > 0)
1026          {          {
# Line 1033  _bfd_stab_section_find_nearest_line (abf Line 1033  _bfd_stab_section_find_nearest_line (abf
1033                asymbol *sym;                asymbol *sym;
1034    
1035                r = *pr;                r = *pr;
1036                  /* Ignore R_*_NONE relocs.  */
1037                  if (r->howto->dst_mask == 0)
1038                    continue;
1039    
1040                if (r->howto->rightshift != 0                if (r->howto->rightshift != 0
1041                    || r->howto->size != 2                    || r->howto->size != 2
1042                    || r->howto->bitsize != 32                    || r->howto->bitsize != 32
# Line 1045  _bfd_stab_section_find_nearest_line (abf Line 1049  _bfd_stab_section_find_nearest_line (abf
1049                    bfd_set_error (bfd_error_invalid_operation);                    bfd_set_error (bfd_error_invalid_operation);
1050                    if (reloc_vector != NULL)                    if (reloc_vector != NULL)
1051                      free (reloc_vector);                      free (reloc_vector);
1052                    return false;                    return FALSE;
1053                  }                  }
1054    
1055                val = bfd_get_32 (abfd, info->stabs + r->address);                val = bfd_get_32 (abfd, info->stabs + r->address);
# Line 1069  _bfd_stab_section_find_nearest_line (abf Line 1073  _bfd_stab_section_find_nearest_line (abf
1073        saw_fun = 1;        saw_fun = 1;
1074        for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)        for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)
1075          {          {
1076            if (stab[TYPEOFF] == N_SO)            if (stab[TYPEOFF] == (bfd_byte) N_SO)
1077              {              {
1078                /* N_SO with null name indicates EOF */                /* N_SO with null name indicates EOF */
1079                if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)                if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)
# Line 1083  _bfd_stab_section_find_nearest_line (abf Line 1087  _bfd_stab_section_find_nearest_line (abf
1087    
1088                /* two N_SO's in a row is a filename and directory. Skip */                /* two N_SO's in a row is a filename and directory. Skip */
1089                if (stab + STABSIZE < info->stabs + stabsize                if (stab + STABSIZE < info->stabs + stabsize
1090                    && *(stab + STABSIZE + TYPEOFF) == N_SO)                    && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
1091                  {                  {
1092                    stab += STABSIZE;                    stab += STABSIZE;
1093                  }                  }
1094              }              }
1095            else if (stab[TYPEOFF] == N_FUN)            else if (stab[TYPEOFF] == (bfd_byte) N_FUN)
1096              {              {
1097                saw_fun = 1;                saw_fun = 1;
1098                ++info->indextablesize;                ++info->indextablesize;
# Line 1099  _bfd_stab_section_find_nearest_line (abf Line 1103  _bfd_stab_section_find_nearest_line (abf
1103          ++info->indextablesize;          ++info->indextablesize;
1104    
1105        if (info->indextablesize == 0)        if (info->indextablesize == 0)
1106          return true;          return TRUE;
1107        ++info->indextablesize;        ++info->indextablesize;
1108    
1109        amt = info->indextablesize;        amt = info->indextablesize;
1110        amt *= sizeof (struct indexentry);        amt *= sizeof (struct indexentry);
1111        info->indextable = (struct indexentry *) bfd_alloc (abfd, amt);        info->indextable = bfd_alloc (abfd, amt);
1112        if (info->indextable == NULL)        if (info->indextable == NULL)
1113          return false;          return FALSE;
1114    
1115        file_name = NULL;        file_name = NULL;
1116        directory_name = NULL;        directory_name = NULL;
# Line 1157  _bfd_stab_section_find_nearest_line (abf Line 1161  _bfd_stab_section_find_nearest_line (abf
1161                  {                  {
1162                    last_stab = stab;                    last_stab = stab;
1163                    if (stab + STABSIZE >= info->stabs + stabsize                    if (stab + STABSIZE >= info->stabs + stabsize
1164                        || *(stab + STABSIZE + TYPEOFF) != N_SO)                        || *(stab + STABSIZE + TYPEOFF) != (bfd_byte) N_SO)
1165                      {                      {
1166                        directory_name = NULL;                        directory_name = NULL;
1167                      }                      }
# Line 1225  _bfd_stab_section_find_nearest_line (abf Line 1229  _bfd_stab_section_find_nearest_line (abf
1229        qsort (info->indextable, (size_t) i, sizeof (struct indexentry),        qsort (info->indextable, (size_t) i, sizeof (struct indexentry),
1230               cmpindexentry);               cmpindexentry);
1231    
1232        *pinfo = (PTR) info;        *pinfo = info;
1233      }      }
1234    
1235    /* We are passed a section relative offset.  The offsets in the    /* We are passed a section relative offset.  The offsets in the
# Line 1244  _bfd_stab_section_find_nearest_line (abf Line 1248  _bfd_stab_section_find_nearest_line (abf
1248    else    else
1249  #endif  #endif
1250      {      {
       /* Cache non-existant or invalid.  Do binary search on  
          indextable.  */  
   
1251        long low, high;        long low, high;
1252        long mid = -1;        long mid = -1;
1253    
1254          /* Cache non-existent or invalid.  Do binary search on
1255             indextable.  */
1256        indexentry = NULL;        indexentry = NULL;
1257    
1258        low = 0;        low = 0;
# Line 1271  _bfd_stab_section_find_nearest_line (abf Line 1274  _bfd_stab_section_find_nearest_line (abf
1274          }          }
1275    
1276        if (indexentry == NULL)        if (indexentry == NULL)
1277          return true;          return TRUE;
1278    
1279        stab = indexentry->stab + STABSIZE;        stab = indexentry->stab + STABSIZE;
1280        file_name = indexentry->file_name;        file_name = indexentry->file_name;
# Line 1280  _bfd_stab_section_find_nearest_line (abf Line 1283  _bfd_stab_section_find_nearest_line (abf
1283    directory_name = indexentry->directory_name;    directory_name = indexentry->directory_name;
1284    str = indexentry->str;    str = indexentry->str;
1285    
1286    saw_line = false;    saw_line = FALSE;
1287    saw_func = false;    saw_func = FALSE;
1288    for (; stab < (indexentry+1)->stab; stab += STABSIZE)    for (; stab < (indexentry+1)->stab; stab += STABSIZE)
1289      {      {
1290        boolean done;        bfd_boolean done;
1291        bfd_vma val;        bfd_vma val;
1292    
1293        done = false;        done = FALSE;
1294    
1295        switch (stab[TYPEOFF])        switch (stab[TYPEOFF])
1296          {          {
# Line 1304  _bfd_stab_section_find_nearest_line (abf Line 1307  _bfd_stab_section_find_nearest_line (abf
1307          case N_SLINE:          case N_SLINE:
1308          case N_DSLINE:          case N_DSLINE:
1309          case N_BSLINE:          case N_BSLINE:
1310            /* A line number.  The value is relative to the start of the            /* A line number.  If the function was specified, then the value
1311               current function.  */               is relative to the start of the function.  Otherwise, the
1312            val = indexentry->val + bfd_get_32 (abfd, stab + VALOFF);               value is an absolute address.  */
1313              val = ((indexentry->function_name ? indexentry->val : 0)
1314                     + bfd_get_32 (abfd, stab + VALOFF));
1315            /* If this line starts before our desired offset, or if it's            /* If this line starts before our desired offset, or if it's
1316               the first line we've been able to find, use it.  The               the first line we've been able to find, use it.  The
1317               !saw_line check works around a bug in GCC 2.95.3, which emits               !saw_line check works around a bug in GCC 2.95.3, which emits
# Line 1323  _bfd_stab_section_find_nearest_line (abf Line 1328  _bfd_stab_section_find_nearest_line (abf
1328  #endif  #endif
1329              }              }
1330            if (val > offset)            if (val > offset)
1331              done = true;              done = TRUE;
1332            saw_line = true;            saw_line = TRUE;
1333            break;            break;
1334    
1335          case N_FUN:          case N_FUN:
1336          case N_SO:          case N_SO:
1337            if (saw_func || saw_line)            if (saw_func || saw_line)
1338              done = true;              done = TRUE;
1339            saw_func = true;            saw_func = TRUE;
1340            break;            break;
1341          }          }
1342    
# Line 1339  _bfd_stab_section_find_nearest_line (abf Line 1344  _bfd_stab_section_find_nearest_line (abf
1344          break;          break;
1345      }      }
1346    
1347    *pfound = true;    *pfound = TRUE;
1348    
1349    if (file_name == NULL || IS_ABSOLUTE_PATH (file_name)    if (file_name == NULL || IS_ABSOLUTE_PATH (file_name)
1350        || directory_name == NULL)        || directory_name == NULL)
# Line 1358  _bfd_stab_section_find_nearest_line (abf Line 1363  _bfd_stab_section_find_nearest_line (abf
1363            if (info->filename != NULL)            if (info->filename != NULL)
1364              free (info->filename);              free (info->filename);
1365            len = strlen (file_name) + 1;            len = strlen (file_name) + 1;
1366            info->filename = (char *) bfd_malloc ((bfd_size_type) dirlen + len);            info->filename = bfd_malloc (dirlen + len);
1367            if (info->filename == NULL)            if (info->filename == NULL)
1368              return false;              return FALSE;
1369            memcpy (info->filename, directory_name, dirlen);            memcpy (info->filename, directory_name, dirlen);
1370            memcpy (info->filename + dirlen, file_name, len);            memcpy (info->filename + dirlen, file_name, len);
1371          }          }
# Line 1375  _bfd_stab_section_find_nearest_line (abf Line 1380  _bfd_stab_section_find_nearest_line (abf
1380        /* This will typically be something like main:F(0,1), so we want        /* This will typically be something like main:F(0,1), so we want
1381           to clobber the colon.  It's OK to change the name, since the           to clobber the colon.  It's OK to change the name, since the
1382           string is in our own local storage anyhow.  */           string is in our own local storage anyhow.  */
   
1383        s = strchr (indexentry->function_name, ':');        s = strchr (indexentry->function_name, ':');
1384        if (s != NULL)        if (s != NULL)
1385          *s = '\0';          *s = '\0';
# Line 1383  _bfd_stab_section_find_nearest_line (abf Line 1387  _bfd_stab_section_find_nearest_line (abf
1387        *pfnname = indexentry->function_name;        *pfnname = indexentry->function_name;
1388      }      }
1389    
1390    return true;    return TRUE;
1391  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.1.20.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26