public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Sun compiler, value field in stab is zero
@ 2003-04-15 16:52 Gabriel Marin
  2003-04-18  7:54 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Gabriel Marin @ 2003-04-15 16:52 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 750 bytes --]

Hi,

The code in _bfd_stab_section_find_nearest_line() expects to find the
absolute start address of routines in the value field of the stab's
N_FUN
entries.
Sun compiler does not generate these values, hence these fields are
always zero in binaries compiled with the Sun compiler.
As a result, bfd_find_nearest_line does not find the source line info
correctly.
This patch searches the symbol table for the routine symbols and compute
their absolute start address from there.

ChangeLog:
2003-04-15  Gabriel Marin <mgabi@rice.edu>

    * syms.c (_bfd_stab_section_find_nearest_line): Sun compiler
    does not set the 'value' field for the N_FUN entries of the stab.
    Compute the values of these entries using the symbol table
    information.



[-- Attachment #2: syms.c.patch --]
[-- Type: text/plain, Size: 2656 bytes --]

Index: bfd/syms.c
===================================================================
RCS file: /cvs/src/src/bfd/syms.c,v
retrieving revision 1.29
diff -c -3 -p -r1.29 syms.c
*** bfd/syms.c	28 Feb 2003 23:43:35 -0000	1.29
--- bfd/syms.c	15 Apr 2003 16:17:57 -0000
*************** _bfd_stab_section_find_nearest_line (abf
*** 1220,1227 ****
        ++i;
  
        info->indextablesize = i;
!       qsort (info->indextable, (size_t) i, sizeof (struct indexentry),
! 	     cmpindexentry);
  
        *pinfo = (PTR) info;
      }
--- 1220,1267 ----
        ++i;
  
        info->indextablesize = i;
! 
!       /* For binaries produced by the Sun compiler the field 'value'
!        * in stabs is zero for all N_FUN entries. In this case the 
!        * find_nearest_line always returns the last N_SLINE entry in the stabs
!        * because the binary search will always stop just at the end of the 
!        * table, before the last entry which has a special value (0xFFFFFFFF)
!        * and after all the other entries with a value zero.
!        * Try to find the value for each entry by searching in the symbols 
!        * array. This search is done only once so we can live with a linear,
!        * unoptimized search. It is also possible to organize the symbols in
!        * another data structure using the name as a key (hashtable or sorted
!        * list). 
!        * In stabs, the function name has this format: symbolName:F... or 
!        * symbolName:P.... We are interested only in the entries
!        * with the first format.
!        */
!        for (i=0 ; i<info->indextablesize ; i++)
!          {
!            char* pos;
!            int k;
!            asymbol *sym;
!            if (info->indextable[i].val==0 && info->indextable[i].function_name
!               && ((pos=strchr(info->indextable[i].function_name, ':'))==NULL
!                  || *(pos+1)=='F') )
!              {
!                if (pos) *pos = '\0';
!                /* search for the symbol with this name */
!                for (k=0 ; symbols[k] != NULL ; k++)
!                  {
!                    sym = symbols[k];
!                    if (!strcmp(info->indextable[i].function_name, sym->name))
!                      {
!                        info->indextable[i].val = 
!                                   sym->value + sym->section->vma;
!                        break;
!                      }
!                  }
!                if (pos) *pos = ':';
!              }
!          }
!       qsort (info->indextable, (size_t) info->indextablesize, 
!               sizeof (struct indexentry), cmpindexentry);
  
        *pinfo = (PTR) info;
      }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Sun compiler, value field in stab is zero
  2003-04-15 16:52 Sun compiler, value field in stab is zero Gabriel Marin
@ 2003-04-18  7:54 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2003-04-18  7:54 UTC (permalink / raw)
  To: Gabriel Marin; +Cc: binutils

Hi Gabriel,

> The code in _bfd_stab_section_find_nearest_line() expects to find
> the absolute start address of routines in the value field of the
> stab's N_FUN entries.  Sun compiler does not generate these values,
> hence these fields are always zero in binaries compiled with the Sun
> compiler.

> 2003-04-15  Gabriel Marin <mgabi@rice.edu>
> 
>     * syms.c (_bfd_stab_section_find_nearest_line): Sun compiler
>     does not set the 'value' field for the N_FUN entries of the stab.
>     Compute the values of these entries using the symbol table
>     information.

Thanks very much for submitting this patch.  Do you have a binutils
copyright assignment on file with the FSF ?  We will need such an
assignment before we can accept the patch.

The patch itself looks OK, although the formatting will need sprucing
up to conform to GNU coding standards.  The linear search of the symbol
table for each zero valued NFUN entry does look rather worrying
however.  For a large executable I suspect that this could generate a
significant delay the first time a source line is looked up.

Would it be possible to change the code to use a hash table ?  Or
maybe a lazy evaluation scheme, such that zero valued NFUN stabs are
only looked up as needed ?

Cheers
        Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-18  7:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-15 16:52 Sun compiler, value field in stab is zero Gabriel Marin
2003-04-18  7:54 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).