Home | History | Annotate | Line # | Download | only in bfd
syms.c revision 1.8
      1  1.1  christos /* Generic symbol-table support for the BFD library.
      2  1.8  christos    Copyright (C) 1990-2022 Free Software Foundation, Inc.
      3  1.1  christos    Written by Cygnus Support.
      4  1.1  christos 
      5  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program; if not, write to the Free Software
     19  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20  1.1  christos    MA 02110-1301, USA.  */
     21  1.1  christos 
     22  1.1  christos /*
     23  1.1  christos SECTION
     24  1.1  christos 	Symbols
     25  1.1  christos 
     26  1.1  christos 	BFD tries to maintain as much symbol information as it can when
     27  1.1  christos 	it moves information from file to file. BFD passes information
     28  1.1  christos 	to applications though the <<asymbol>> structure. When the
     29  1.1  christos 	application requests the symbol table, BFD reads the table in
     30  1.1  christos 	the native form and translates parts of it into the internal
     31  1.1  christos 	format. To maintain more than the information passed to
     32  1.1  christos 	applications, some targets keep some information ``behind the
     33  1.1  christos 	scenes'' in a structure only the particular back end knows
     34  1.1  christos 	about. For example, the coff back end keeps the original
     35  1.1  christos 	symbol table structure as well as the canonical structure when
     36  1.1  christos 	a BFD is read in. On output, the coff back end can reconstruct
     37  1.1  christos 	the output symbol table so that no information is lost, even
     38  1.1  christos 	information unique to coff which BFD doesn't know or
     39  1.1  christos 	understand. If a coff symbol table were read, but were written
     40  1.1  christos 	through an a.out back end, all the coff specific information
     41  1.1  christos 	would be lost. The symbol table of a BFD
     42  1.1  christos 	is not necessarily read in until a canonicalize request is
     43  1.1  christos 	made. Then the BFD back end fills in a table provided by the
     44  1.1  christos 	application with pointers to the canonical information.  To
     45  1.1  christos 	output symbols, the application provides BFD with a table of
     46  1.1  christos 	pointers to pointers to <<asymbol>>s. This allows applications
     47  1.1  christos 	like the linker to output a symbol as it was read, since the ``behind
     48  1.1  christos 	the scenes'' information will be still available.
     49  1.1  christos @menu
     50  1.1  christos @* Reading Symbols::
     51  1.1  christos @* Writing Symbols::
     52  1.1  christos @* Mini Symbols::
     53  1.1  christos @* typedef asymbol::
     54  1.1  christos @* symbol handling functions::
     55  1.1  christos @end menu
     56  1.1  christos 
     57  1.1  christos INODE
     58  1.1  christos Reading Symbols, Writing Symbols, Symbols, Symbols
     59  1.1  christos SUBSECTION
     60  1.1  christos 	Reading symbols
     61  1.1  christos 
     62  1.1  christos 	There are two stages to reading a symbol table from a BFD:
     63  1.1  christos 	allocating storage, and the actual reading process. This is an
     64  1.1  christos 	excerpt from an application which reads the symbol table:
     65  1.1  christos 
     66  1.6  christos |         long storage_needed;
     67  1.6  christos |         asymbol **symbol_table;
     68  1.6  christos |         long number_of_symbols;
     69  1.6  christos |         long i;
     70  1.1  christos |
     71  1.6  christos |         storage_needed = bfd_get_symtab_upper_bound (abfd);
     72  1.1  christos |
     73  1.1  christos |         if (storage_needed < 0)
     74  1.1  christos |           FAIL
     75  1.1  christos |
     76  1.6  christos |         if (storage_needed == 0)
     77  1.6  christos |           return;
     78  1.3  christos |
     79  1.6  christos |         symbol_table = xmalloc (storage_needed);
     80  1.6  christos |           ...
     81  1.6  christos |         number_of_symbols =
     82  1.6  christos |            bfd_canonicalize_symtab (abfd, symbol_table);
     83  1.1  christos |
     84  1.1  christos |         if (number_of_symbols < 0)
     85  1.1  christos |           FAIL
     86  1.1  christos |
     87  1.6  christos |         for (i = 0; i < number_of_symbols; i++)
     88  1.6  christos |           process_symbol (symbol_table[i]);
     89  1.1  christos 
     90  1.1  christos 	All storage for the symbols themselves is in an objalloc
     91  1.1  christos 	connected to the BFD; it is freed when the BFD is closed.
     92  1.1  christos 
     93  1.1  christos INODE
     94  1.1  christos Writing Symbols, Mini Symbols, Reading Symbols, Symbols
     95  1.1  christos SUBSECTION
     96  1.1  christos 	Writing symbols
     97  1.1  christos 
     98  1.1  christos 	Writing of a symbol table is automatic when a BFD open for
     99  1.1  christos 	writing is closed. The application attaches a vector of
    100  1.1  christos 	pointers to pointers to symbols to the BFD being written, and
    101  1.1  christos 	fills in the symbol count. The close and cleanup code reads
    102  1.1  christos 	through the table provided and performs all the necessary
    103  1.1  christos 	operations. The BFD output code must always be provided with an
    104  1.1  christos 	``owned'' symbol: one which has come from another BFD, or one
    105  1.1  christos 	which has been created using <<bfd_make_empty_symbol>>.  Here is an
    106  1.1  christos 	example showing the creation of a symbol table with only one element:
    107  1.1  christos 
    108  1.6  christos |       #include "sysdep.h"
    109  1.6  christos |       #include "bfd.h"
    110  1.6  christos |       int main (void)
    111  1.6  christos |       {
    112  1.6  christos |         bfd *abfd;
    113  1.6  christos |         asymbol *ptrs[2];
    114  1.6  christos |         asymbol *new;
    115  1.1  christos |
    116  1.6  christos |         abfd = bfd_openw ("foo","a.out-sunos-big");
    117  1.6  christos |         bfd_set_format (abfd, bfd_object);
    118  1.6  christos |         new = bfd_make_empty_symbol (abfd);
    119  1.6  christos |         new->name = "dummy_symbol";
    120  1.6  christos |         new->section = bfd_make_section_old_way (abfd, ".text");
    121  1.6  christos |         new->flags = BSF_GLOBAL;
    122  1.6  christos |         new->value = 0x12345;
    123  1.1  christos |
    124  1.6  christos |         ptrs[0] = new;
    125  1.6  christos |         ptrs[1] = 0;
    126  1.1  christos |
    127  1.6  christos |         bfd_set_symtab (abfd, ptrs, 1);
    128  1.6  christos |         bfd_close (abfd);
    129  1.6  christos |         return 0;
    130  1.6  christos |       }
    131  1.1  christos |
    132  1.6  christos |       ./makesym
    133  1.6  christos |       nm foo
    134  1.6  christos |       00012345 A dummy_symbol
    135  1.1  christos 
    136  1.1  christos 	Many formats cannot represent arbitrary symbol information; for
    137  1.6  christos 	instance, the <<a.out>> object format does not allow an
    138  1.1  christos 	arbitrary number of sections. A symbol pointing to a section
    139  1.1  christos 	which is not one  of <<.text>>, <<.data>> or <<.bss>> cannot
    140  1.1  christos 	be described.
    141  1.1  christos 
    142  1.1  christos INODE
    143  1.1  christos Mini Symbols, typedef asymbol, Writing Symbols, Symbols
    144  1.1  christos SUBSECTION
    145  1.1  christos 	Mini Symbols
    146  1.1  christos 
    147  1.1  christos 	Mini symbols provide read-only access to the symbol table.
    148  1.1  christos 	They use less memory space, but require more time to access.
    149  1.1  christos 	They can be useful for tools like nm or objdump, which may
    150  1.1  christos 	have to handle symbol tables of extremely large executables.
    151  1.1  christos 
    152  1.1  christos 	The <<bfd_read_minisymbols>> function will read the symbols
    153  1.1  christos 	into memory in an internal form.  It will return a <<void *>>
    154  1.1  christos 	pointer to a block of memory, a symbol count, and the size of
    155  1.1  christos 	each symbol.  The pointer is allocated using <<malloc>>, and
    156  1.1  christos 	should be freed by the caller when it is no longer needed.
    157  1.1  christos 
    158  1.1  christos 	The function <<bfd_minisymbol_to_symbol>> will take a pointer
    159  1.1  christos 	to a minisymbol, and a pointer to a structure returned by
    160  1.1  christos 	<<bfd_make_empty_symbol>>, and return a <<asymbol>> structure.
    161  1.1  christos 	The return value may or may not be the same as the value from
    162  1.1  christos 	<<bfd_make_empty_symbol>> which was passed in.
    163  1.1  christos 
    164  1.1  christos */
    165  1.1  christos 
    166  1.1  christos /*
    167  1.1  christos DOCDD
    168  1.1  christos INODE
    169  1.1  christos typedef asymbol, symbol handling functions, Mini Symbols, Symbols
    170  1.1  christos 
    171  1.1  christos */
    172  1.1  christos /*
    173  1.1  christos SUBSECTION
    174  1.1  christos 	typedef asymbol
    175  1.1  christos 
    176  1.1  christos 	An <<asymbol>> has the form:
    177  1.1  christos 
    178  1.1  christos */
    179  1.1  christos 
    180  1.1  christos /*
    181  1.1  christos CODE_FRAGMENT
    182  1.1  christos 
    183  1.1  christos .
    184  1.1  christos .typedef struct bfd_symbol
    185  1.1  christos .{
    186  1.1  christos .  {* A pointer to the BFD which owns the symbol. This information
    187  1.1  christos .     is necessary so that a back end can work out what additional
    188  1.1  christos .     information (invisible to the application writer) is carried
    189  1.1  christos .     with the symbol.
    190  1.1  christos .
    191  1.1  christos .     This field is *almost* redundant, since you can use section->owner
    192  1.1  christos .     instead, except that some symbols point to the global sections
    193  1.1  christos .     bfd_{abs,com,und}_section.  This could be fixed by making
    194  1.1  christos .     these globals be per-bfd (or per-target-flavor).  FIXME.  *}
    195  1.1  christos .  struct bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field.  *}
    196  1.1  christos .
    197  1.1  christos .  {* The text of the symbol. The name is left alone, and not copied; the
    198  1.1  christos .     application may not alter it.  *}
    199  1.1  christos .  const char *name;
    200  1.1  christos .
    201  1.1  christos .  {* The value of the symbol.  This really should be a union of a
    202  1.1  christos .     numeric value with a pointer, since some flags indicate that
    203  1.1  christos .     a pointer to another symbol is stored here.  *}
    204  1.1  christos .  symvalue value;
    205  1.1  christos .
    206  1.1  christos .  {* Attributes of a symbol.  *}
    207  1.6  christos .#define BSF_NO_FLAGS            0
    208  1.1  christos .
    209  1.1  christos .  {* The symbol has local scope; <<static>> in <<C>>. The value
    210  1.1  christos .     is the offset into the section of the data.  *}
    211  1.6  christos .#define BSF_LOCAL               (1 << 0)
    212  1.1  christos .
    213  1.1  christos .  {* The symbol has global scope; initialized data in <<C>>. The
    214  1.1  christos .     value is the offset into the section of the data.  *}
    215  1.6  christos .#define BSF_GLOBAL              (1 << 1)
    216  1.1  christos .
    217  1.1  christos .  {* The symbol has global scope and is exported. The value is
    218  1.1  christos .     the offset into the section of the data.  *}
    219  1.6  christos .#define BSF_EXPORT              BSF_GLOBAL {* No real difference.  *}
    220  1.1  christos .
    221  1.1  christos .  {* A normal C symbol would be one of:
    222  1.5  christos .     <<BSF_LOCAL>>, <<BSF_UNDEFINED>> or <<BSF_GLOBAL>>.  *}
    223  1.1  christos .
    224  1.1  christos .  {* The symbol is a debugging record. The value has an arbitrary
    225  1.1  christos .     meaning, unless BSF_DEBUGGING_RELOC is also set.  *}
    226  1.6  christos .#define BSF_DEBUGGING           (1 << 2)
    227  1.1  christos .
    228  1.1  christos .  {* The symbol denotes a function entry point.  Used in ELF,
    229  1.1  christos .     perhaps others someday.  *}
    230  1.6  christos .#define BSF_FUNCTION            (1 << 3)
    231  1.1  christos .
    232  1.1  christos .  {* Used by the linker.  *}
    233  1.6  christos .#define BSF_KEEP                (1 << 5)
    234  1.5  christos .
    235  1.5  christos .  {* An ELF common symbol.  *}
    236  1.6  christos .#define BSF_ELF_COMMON          (1 << 6)
    237  1.1  christos .
    238  1.1  christos .  {* A weak global symbol, overridable without warnings by
    239  1.1  christos .     a regular global symbol of the same name.  *}
    240  1.6  christos .#define BSF_WEAK                (1 << 7)
    241  1.1  christos .
    242  1.1  christos .  {* This symbol was created to point to a section, e.g. ELF's
    243  1.1  christos .     STT_SECTION symbols.  *}
    244  1.6  christos .#define BSF_SECTION_SYM         (1 << 8)
    245  1.1  christos .
    246  1.1  christos .  {* The symbol used to be a common symbol, but now it is
    247  1.1  christos .     allocated.  *}
    248  1.6  christos .#define BSF_OLD_COMMON          (1 << 9)
    249  1.1  christos .
    250  1.1  christos .  {* In some files the type of a symbol sometimes alters its
    251  1.1  christos .     location in an output file - ie in coff a <<ISFCN>> symbol
    252  1.1  christos .     which is also <<C_EXT>> symbol appears where it was
    253  1.1  christos .     declared and not at the end of a section.  This bit is set
    254  1.1  christos .     by the target BFD part to convey this information.  *}
    255  1.6  christos .#define BSF_NOT_AT_END          (1 << 10)
    256  1.1  christos .
    257  1.1  christos .  {* Signal that the symbol is the label of constructor section.  *}
    258  1.6  christos .#define BSF_CONSTRUCTOR         (1 << 11)
    259  1.1  christos .
    260  1.1  christos .  {* Signal that the symbol is a warning symbol.  The name is a
    261  1.1  christos .     warning.  The name of the next symbol is the one to warn about;
    262  1.1  christos .     if a reference is made to a symbol with the same name as the next
    263  1.1  christos .     symbol, a warning is issued by the linker.  *}
    264  1.6  christos .#define BSF_WARNING             (1 << 12)
    265  1.1  christos .
    266  1.1  christos .  {* Signal that the symbol is indirect.  This symbol is an indirect
    267  1.1  christos .     pointer to the symbol with the same name as the next symbol.  *}
    268  1.6  christos .#define BSF_INDIRECT            (1 << 13)
    269  1.1  christos .
    270  1.1  christos .  {* BSF_FILE marks symbols that contain a file name.  This is used
    271  1.1  christos .     for ELF STT_FILE symbols.  *}
    272  1.6  christos .#define BSF_FILE                (1 << 14)
    273  1.1  christos .
    274  1.1  christos .  {* Symbol is from dynamic linking information.  *}
    275  1.6  christos .#define BSF_DYNAMIC             (1 << 15)
    276  1.1  christos .
    277  1.1  christos .  {* The symbol denotes a data object.  Used in ELF, and perhaps
    278  1.1  christos .     others someday.  *}
    279  1.6  christos .#define BSF_OBJECT              (1 << 16)
    280  1.1  christos .
    281  1.1  christos .  {* This symbol is a debugging symbol.  The value is the offset
    282  1.1  christos .     into the section of the data.  BSF_DEBUGGING should be set
    283  1.1  christos .     as well.  *}
    284  1.6  christos .#define BSF_DEBUGGING_RELOC     (1 << 17)
    285  1.1  christos .
    286  1.1  christos .  {* This symbol is thread local.  Used in ELF.  *}
    287  1.6  christos .#define BSF_THREAD_LOCAL        (1 << 18)
    288  1.1  christos .
    289  1.1  christos .  {* This symbol represents a complex relocation expression,
    290  1.1  christos .     with the expression tree serialized in the symbol name.  *}
    291  1.6  christos .#define BSF_RELC                (1 << 19)
    292  1.1  christos .
    293  1.1  christos .  {* This symbol represents a signed complex relocation expression,
    294  1.1  christos .     with the expression tree serialized in the symbol name.  *}
    295  1.6  christos .#define BSF_SRELC               (1 << 20)
    296  1.1  christos .
    297  1.1  christos .  {* This symbol was created by bfd_get_synthetic_symtab.  *}
    298  1.6  christos .#define BSF_SYNTHETIC           (1 << 21)
    299  1.1  christos .
    300  1.1  christos .  {* This symbol is an indirect code object.  Unrelated to BSF_INDIRECT.
    301  1.1  christos .     The dynamic linker will compute the value of this symbol by
    302  1.1  christos .     calling the function that it points to.  BSF_FUNCTION must
    303  1.1  christos .     also be also set.  *}
    304  1.1  christos .#define BSF_GNU_INDIRECT_FUNCTION (1 << 22)
    305  1.1  christos .  {* This symbol is a globally unique data object.  The dynamic linker
    306  1.1  christos .     will make sure that in the entire process there is just one symbol
    307  1.1  christos .     with this name and type in use.  BSF_OBJECT must also be set.  *}
    308  1.6  christos .#define BSF_GNU_UNIQUE          (1 << 23)
    309  1.1  christos .
    310  1.8  christos .  {* This section symbol should be included in the symbol table.  *}
    311  1.8  christos .#define BSF_SECTION_SYM_USED    (1 << 24)
    312  1.8  christos .
    313  1.1  christos .  flagword flags;
    314  1.1  christos .
    315  1.1  christos .  {* A pointer to the section to which this symbol is
    316  1.1  christos .     relative.  This will always be non NULL, there are special
    317  1.1  christos .     sections for undefined and absolute symbols.  *}
    318  1.1  christos .  struct bfd_section *section;
    319  1.1  christos .
    320  1.1  christos .  {* Back end special data.  *}
    321  1.1  christos .  union
    322  1.1  christos .    {
    323  1.1  christos .      void *p;
    324  1.1  christos .      bfd_vma i;
    325  1.1  christos .    }
    326  1.1  christos .  udata;
    327  1.1  christos .}
    328  1.1  christos .asymbol;
    329  1.1  christos .
    330  1.1  christos */
    331  1.1  christos 
    332  1.1  christos #include "sysdep.h"
    333  1.1  christos #include "bfd.h"
    334  1.1  christos #include "libbfd.h"
    335  1.1  christos #include "safe-ctype.h"
    336  1.1  christos #include "bfdlink.h"
    337  1.1  christos #include "aout/stab_gnu.h"
    338  1.1  christos 
    339  1.1  christos /*
    340  1.1  christos DOCDD
    341  1.1  christos INODE
    342  1.1  christos symbol handling functions,  , typedef asymbol, Symbols
    343  1.1  christos SUBSECTION
    344  1.1  christos 	Symbol handling functions
    345  1.1  christos */
    346  1.1  christos 
    347  1.1  christos /*
    348  1.1  christos FUNCTION
    349  1.1  christos 	bfd_get_symtab_upper_bound
    350  1.1  christos 
    351  1.1  christos DESCRIPTION
    352  1.1  christos 	Return the number of bytes required to store a vector of pointers
    353  1.1  christos 	to <<asymbols>> for all the symbols in the BFD @var{abfd},
    354  1.1  christos 	including a terminal NULL pointer. If there are no symbols in
    355  1.1  christos 	the BFD, then return 0.  If an error occurs, return -1.
    356  1.1  christos 
    357  1.1  christos .#define bfd_get_symtab_upper_bound(abfd) \
    358  1.6  christos .	BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
    359  1.1  christos .
    360  1.1  christos */
    361  1.1  christos 
    362  1.1  christos /*
    363  1.1  christos FUNCTION
    364  1.1  christos 	bfd_is_local_label
    365  1.1  christos 
    366  1.1  christos SYNOPSIS
    367  1.8  christos 	bool bfd_is_local_label (bfd *abfd, asymbol *sym);
    368  1.1  christos 
    369  1.1  christos DESCRIPTION
    370  1.1  christos 	Return TRUE if the given symbol @var{sym} in the BFD @var{abfd} is
    371  1.1  christos 	a compiler generated local label, else return FALSE.
    372  1.1  christos */
    373  1.1  christos 
    374  1.8  christos bool
    375  1.1  christos bfd_is_local_label (bfd *abfd, asymbol *sym)
    376  1.1  christos {
    377  1.1  christos   /* The BSF_SECTION_SYM check is needed for IA-64, where every label that
    378  1.1  christos      starts with '.' is local.  This would accidentally catch section names
    379  1.1  christos      if we didn't reject them here.  */
    380  1.1  christos   if ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_FILE | BSF_SECTION_SYM)) != 0)
    381  1.8  christos     return false;
    382  1.1  christos   if (sym->name == NULL)
    383  1.8  christos     return false;
    384  1.1  christos   return bfd_is_local_label_name (abfd, sym->name);
    385  1.1  christos }
    386  1.1  christos 
    387  1.1  christos /*
    388  1.1  christos FUNCTION
    389  1.1  christos 	bfd_is_local_label_name
    390  1.1  christos 
    391  1.1  christos SYNOPSIS
    392  1.8  christos 	bool bfd_is_local_label_name (bfd *abfd, const char *name);
    393  1.1  christos 
    394  1.1  christos DESCRIPTION
    395  1.1  christos 	Return TRUE if a symbol with the name @var{name} in the BFD
    396  1.1  christos 	@var{abfd} is a compiler generated local label, else return
    397  1.1  christos 	FALSE.  This just checks whether the name has the form of a
    398  1.1  christos 	local label.
    399  1.1  christos 
    400  1.1  christos .#define bfd_is_local_label_name(abfd, name) \
    401  1.6  christos .	BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
    402  1.1  christos .
    403  1.1  christos */
    404  1.1  christos 
    405  1.1  christos /*
    406  1.1  christos FUNCTION
    407  1.1  christos 	bfd_is_target_special_symbol
    408  1.1  christos 
    409  1.1  christos SYNOPSIS
    410  1.8  christos 	bool bfd_is_target_special_symbol (bfd *abfd, asymbol *sym);
    411  1.1  christos 
    412  1.1  christos DESCRIPTION
    413  1.1  christos 	Return TRUE iff a symbol @var{sym} in the BFD @var{abfd} is something
    414  1.1  christos 	special to the particular target represented by the BFD.  Such symbols
    415  1.1  christos 	should normally not be mentioned to the user.
    416  1.1  christos 
    417  1.1  christos .#define bfd_is_target_special_symbol(abfd, sym) \
    418  1.6  christos .	BFD_SEND (abfd, _bfd_is_target_special_symbol, (abfd, sym))
    419  1.1  christos .
    420  1.1  christos */
    421  1.1  christos 
    422  1.1  christos /*
    423  1.1  christos FUNCTION
    424  1.1  christos 	bfd_canonicalize_symtab
    425  1.1  christos 
    426  1.1  christos DESCRIPTION
    427  1.1  christos 	Read the symbols from the BFD @var{abfd}, and fills in
    428  1.1  christos 	the vector @var{location} with pointers to the symbols and
    429  1.1  christos 	a trailing NULL.
    430  1.1  christos 	Return the actual number of symbol pointers, not
    431  1.1  christos 	including the NULL.
    432  1.1  christos 
    433  1.1  christos .#define bfd_canonicalize_symtab(abfd, location) \
    434  1.6  christos .	BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
    435  1.1  christos .
    436  1.1  christos */
    437  1.1  christos 
    438  1.1  christos /*
    439  1.1  christos FUNCTION
    440  1.1  christos 	bfd_set_symtab
    441  1.1  christos 
    442  1.1  christos SYNOPSIS
    443  1.8  christos 	bool bfd_set_symtab
    444  1.1  christos 	  (bfd *abfd, asymbol **location, unsigned int count);
    445  1.1  christos 
    446  1.1  christos DESCRIPTION
    447  1.1  christos 	Arrange that when the output BFD @var{abfd} is closed,
    448  1.1  christos 	the table @var{location} of @var{count} pointers to symbols
    449  1.1  christos 	will be written.
    450  1.1  christos */
    451  1.1  christos 
    452  1.8  christos bool
    453  1.1  christos bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int symcount)
    454  1.1  christos {
    455  1.1  christos   if (abfd->format != bfd_object || bfd_read_p (abfd))
    456  1.1  christos     {
    457  1.1  christos       bfd_set_error (bfd_error_invalid_operation);
    458  1.8  christos       return false;
    459  1.1  christos     }
    460  1.1  christos 
    461  1.7  christos   abfd->outsymbols = location;
    462  1.7  christos   abfd->symcount = symcount;
    463  1.8  christos   return true;
    464  1.1  christos }
    465  1.1  christos 
    466  1.1  christos /*
    467  1.1  christos FUNCTION
    468  1.1  christos 	bfd_print_symbol_vandf
    469  1.1  christos 
    470  1.1  christos SYNOPSIS
    471  1.1  christos 	void bfd_print_symbol_vandf (bfd *abfd, void *file, asymbol *symbol);
    472  1.1  christos 
    473  1.1  christos DESCRIPTION
    474  1.1  christos 	Print the value and flags of the @var{symbol} supplied to the
    475  1.1  christos 	stream @var{file}.
    476  1.1  christos */
    477  1.1  christos void
    478  1.1  christos bfd_print_symbol_vandf (bfd *abfd, void *arg, asymbol *symbol)
    479  1.1  christos {
    480  1.1  christos   FILE *file = (FILE *) arg;
    481  1.1  christos 
    482  1.1  christos   flagword type = symbol->flags;
    483  1.1  christos 
    484  1.1  christos   if (symbol->section != NULL)
    485  1.1  christos     bfd_fprintf_vma (abfd, file, symbol->value + symbol->section->vma);
    486  1.1  christos   else
    487  1.1  christos     bfd_fprintf_vma (abfd, file, symbol->value);
    488  1.1  christos 
    489  1.1  christos   /* This presumes that a symbol can not be both BSF_DEBUGGING and
    490  1.1  christos      BSF_DYNAMIC, nor more than one of BSF_FUNCTION, BSF_FILE, and
    491  1.1  christos      BSF_OBJECT.  */
    492  1.1  christos   fprintf (file, " %c%c%c%c%c%c%c",
    493  1.1  christos 	   ((type & BSF_LOCAL)
    494  1.1  christos 	    ? (type & BSF_GLOBAL) ? '!' : 'l'
    495  1.1  christos 	    : (type & BSF_GLOBAL) ? 'g'
    496  1.1  christos 	    : (type & BSF_GNU_UNIQUE) ? 'u' : ' '),
    497  1.1  christos 	   (type & BSF_WEAK) ? 'w' : ' ',
    498  1.1  christos 	   (type & BSF_CONSTRUCTOR) ? 'C' : ' ',
    499  1.1  christos 	   (type & BSF_WARNING) ? 'W' : ' ',
    500  1.1  christos 	   (type & BSF_INDIRECT) ? 'I' : (type & BSF_GNU_INDIRECT_FUNCTION) ? 'i' : ' ',
    501  1.1  christos 	   (type & BSF_DEBUGGING) ? 'd' : (type & BSF_DYNAMIC) ? 'D' : ' ',
    502  1.1  christos 	   ((type & BSF_FUNCTION)
    503  1.1  christos 	    ? 'F'
    504  1.1  christos 	    : ((type & BSF_FILE)
    505  1.1  christos 	       ? 'f'
    506  1.1  christos 	       : ((type & BSF_OBJECT) ? 'O' : ' '))));
    507  1.1  christos }
    508  1.1  christos 
    509  1.1  christos /*
    510  1.1  christos FUNCTION
    511  1.1  christos 	bfd_make_empty_symbol
    512  1.1  christos 
    513  1.1  christos DESCRIPTION
    514  1.1  christos 	Create a new <<asymbol>> structure for the BFD @var{abfd}
    515  1.1  christos 	and return a pointer to it.
    516  1.1  christos 
    517  1.1  christos 	This routine is necessary because each back end has private
    518  1.1  christos 	information surrounding the <<asymbol>>. Building your own
    519  1.1  christos 	<<asymbol>> and pointing to it will not create the private
    520  1.1  christos 	information, and will cause problems later on.
    521  1.1  christos 
    522  1.1  christos .#define bfd_make_empty_symbol(abfd) \
    523  1.6  christos .	BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
    524  1.1  christos .
    525  1.1  christos */
    526  1.1  christos 
    527  1.1  christos /*
    528  1.1  christos FUNCTION
    529  1.1  christos 	_bfd_generic_make_empty_symbol
    530  1.1  christos 
    531  1.1  christos SYNOPSIS
    532  1.1  christos 	asymbol *_bfd_generic_make_empty_symbol (bfd *);
    533  1.1  christos 
    534  1.1  christos DESCRIPTION
    535  1.1  christos 	Create a new <<asymbol>> structure for the BFD @var{abfd}
    536  1.1  christos 	and return a pointer to it.  Used by core file routines,
    537  1.1  christos 	binary back-end and anywhere else where no private info
    538  1.1  christos 	is needed.
    539  1.1  christos */
    540  1.1  christos 
    541  1.1  christos asymbol *
    542  1.1  christos _bfd_generic_make_empty_symbol (bfd *abfd)
    543  1.1  christos {
    544  1.8  christos   size_t amt = sizeof (asymbol);
    545  1.1  christos   asymbol *new_symbol = (asymbol *) bfd_zalloc (abfd, amt);
    546  1.1  christos   if (new_symbol)
    547  1.1  christos     new_symbol->the_bfd = abfd;
    548  1.1  christos   return new_symbol;
    549  1.1  christos }
    550  1.1  christos 
    551  1.1  christos /*
    552  1.1  christos FUNCTION
    553  1.1  christos 	bfd_make_debug_symbol
    554  1.1  christos 
    555  1.1  christos DESCRIPTION
    556  1.1  christos 	Create a new <<asymbol>> structure for the BFD @var{abfd},
    557  1.1  christos 	to be used as a debugging symbol.  Further details of its use have
    558  1.1  christos 	yet to be worked out.
    559  1.1  christos 
    560  1.1  christos .#define bfd_make_debug_symbol(abfd,ptr,size) \
    561  1.6  christos .	BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
    562  1.1  christos .
    563  1.1  christos */
    564  1.1  christos 
    565  1.1  christos struct section_to_type
    566  1.1  christos {
    567  1.1  christos   const char *section;
    568  1.1  christos   char type;
    569  1.1  christos };
    570  1.1  christos 
    571  1.8  christos /* Map special section names to POSIX/BSD single-character symbol types.
    572  1.1  christos    This table is probably incomplete.  It is sorted for convenience of
    573  1.1  christos    adding entries.  Since it is so short, a linear search is used.  */
    574  1.1  christos static const struct section_to_type stt[] =
    575  1.1  christos {
    576  1.6  christos   {".drectve", 'i'},		/* MSVC's .drective section */
    577  1.6  christos   {".edata", 'e'},		/* MSVC's .edata (export) section */
    578  1.6  christos   {".idata", 'i'},		/* MSVC's .idata (import) section */
    579  1.6  christos   {".pdata", 'p'},		/* MSVC's .pdata (stack unwind) section */
    580  1.1  christos   {0, 0}
    581  1.1  christos };
    582  1.1  christos 
    583  1.1  christos /* Return the single-character symbol type corresponding to
    584  1.1  christos    section S, or '?' for an unknown COFF section.
    585  1.1  christos 
    586  1.7  christos    Check for leading strings which match, followed by a number, '.',
    587  1.8  christos    or '$' so .idata5 matches the .idata entry.  */
    588  1.1  christos 
    589  1.1  christos static char
    590  1.1  christos coff_section_type (const char *s)
    591  1.1  christos {
    592  1.1  christos   const struct section_to_type *t;
    593  1.1  christos 
    594  1.1  christos   for (t = &stt[0]; t->section; t++)
    595  1.7  christos     {
    596  1.7  christos       size_t len = strlen (t->section);
    597  1.7  christos       if (strncmp (s, t->section, len) == 0
    598  1.7  christos 	  && memchr (".$0123456789", s[len], 13) != 0)
    599  1.7  christos 	return t->type;
    600  1.7  christos     }
    601  1.1  christos 
    602  1.1  christos   return '?';
    603  1.1  christos }
    604  1.1  christos 
    605  1.1  christos /* Return the single-character symbol type corresponding to section
    606  1.1  christos    SECTION, or '?' for an unknown section.  This uses section flags to
    607  1.1  christos    identify sections.
    608  1.1  christos 
    609  1.8  christos    FIXME These types are unhandled: e, i, p.  If we handled these also,
    610  1.1  christos    we could perhaps obsolete coff_section_type.  */
    611  1.1  christos 
    612  1.1  christos static char
    613  1.1  christos decode_section_type (const struct bfd_section *section)
    614  1.1  christos {
    615  1.1  christos   if (section->flags & SEC_CODE)
    616  1.1  christos     return 't';
    617  1.1  christos   if (section->flags & SEC_DATA)
    618  1.1  christos     {
    619  1.1  christos       if (section->flags & SEC_READONLY)
    620  1.1  christos 	return 'r';
    621  1.1  christos       else if (section->flags & SEC_SMALL_DATA)
    622  1.1  christos 	return 'g';
    623  1.1  christos       else
    624  1.1  christos 	return 'd';
    625  1.1  christos     }
    626  1.1  christos   if ((section->flags & SEC_HAS_CONTENTS) == 0)
    627  1.1  christos     {
    628  1.1  christos       if (section->flags & SEC_SMALL_DATA)
    629  1.1  christos 	return 's';
    630  1.1  christos       else
    631  1.1  christos 	return 'b';
    632  1.1  christos     }
    633  1.1  christos   if (section->flags & SEC_DEBUGGING)
    634  1.1  christos     return 'N';
    635  1.1  christos   if ((section->flags & SEC_HAS_CONTENTS) && (section->flags & SEC_READONLY))
    636  1.1  christos     return 'n';
    637  1.1  christos 
    638  1.1  christos   return '?';
    639  1.1  christos }
    640  1.1  christos 
    641  1.1  christos /*
    642  1.1  christos FUNCTION
    643  1.1  christos 	bfd_decode_symclass
    644  1.1  christos 
    645  1.1  christos DESCRIPTION
    646  1.1  christos 	Return a character corresponding to the symbol
    647  1.1  christos 	class of @var{symbol}, or '?' for an unknown class.
    648  1.1  christos 
    649  1.1  christos SYNOPSIS
    650  1.1  christos 	int bfd_decode_symclass (asymbol *symbol);
    651  1.1  christos */
    652  1.1  christos int
    653  1.1  christos bfd_decode_symclass (asymbol *symbol)
    654  1.1  christos {
    655  1.1  christos   char c;
    656  1.1  christos 
    657  1.8  christos   /* Paranoia...  */
    658  1.8  christos   if (symbol == NULL || symbol->section == NULL)
    659  1.8  christos     return '?';
    660  1.8  christos 
    661  1.1  christos   if (symbol->section && bfd_is_com_section (symbol->section))
    662  1.8  christos     {
    663  1.8  christos       if (symbol->section->flags & SEC_SMALL_DATA)
    664  1.8  christos 	return 'c';
    665  1.8  christos       else
    666  1.8  christos 	return 'C';
    667  1.8  christos     }
    668  1.1  christos   if (bfd_is_und_section (symbol->section))
    669  1.1  christos     {
    670  1.1  christos       if (symbol->flags & BSF_WEAK)
    671  1.1  christos 	{
    672  1.1  christos 	  /* If weak, determine if it's specifically an object
    673  1.1  christos 	     or non-object weak.  */
    674  1.1  christos 	  if (symbol->flags & BSF_OBJECT)
    675  1.1  christos 	    return 'v';
    676  1.1  christos 	  else
    677  1.1  christos 	    return 'w';
    678  1.1  christos 	}
    679  1.1  christos       else
    680  1.1  christos 	return 'U';
    681  1.1  christos     }
    682  1.1  christos   if (bfd_is_ind_section (symbol->section))
    683  1.1  christos     return 'I';
    684  1.1  christos   if (symbol->flags & BSF_GNU_INDIRECT_FUNCTION)
    685  1.1  christos     return 'i';
    686  1.1  christos   if (symbol->flags & BSF_WEAK)
    687  1.1  christos     {
    688  1.1  christos       /* If weak, determine if it's specifically an object
    689  1.1  christos 	 or non-object weak.  */
    690  1.1  christos       if (symbol->flags & BSF_OBJECT)
    691  1.1  christos 	return 'V';
    692  1.1  christos       else
    693  1.1  christos 	return 'W';
    694  1.1  christos     }
    695  1.1  christos   if (symbol->flags & BSF_GNU_UNIQUE)
    696  1.1  christos     return 'u';
    697  1.1  christos   if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL)))
    698  1.1  christos     return '?';
    699  1.1  christos 
    700  1.1  christos   if (bfd_is_abs_section (symbol->section))
    701  1.1  christos     c = 'a';
    702  1.1  christos   else if (symbol->section)
    703  1.1  christos     {
    704  1.8  christos       c = coff_section_type (symbol->section->name);
    705  1.1  christos       if (c == '?')
    706  1.8  christos 	c = decode_section_type (symbol->section);
    707  1.1  christos     }
    708  1.1  christos   else
    709  1.1  christos     return '?';
    710  1.1  christos   if (symbol->flags & BSF_GLOBAL)
    711  1.1  christos     c = TOUPPER (c);
    712  1.1  christos   return c;
    713  1.1  christos 
    714  1.1  christos   /* We don't have to handle these cases just yet, but we will soon:
    715  1.1  christos      N_SETV: 'v';
    716  1.1  christos      N_SETA: 'l';
    717  1.1  christos      N_SETT: 'x';
    718  1.1  christos      N_SETD: 'z';
    719  1.1  christos      N_SETB: 's';
    720  1.1  christos      N_INDR: 'i';
    721  1.1  christos      */
    722  1.1  christos }
    723  1.1  christos 
    724  1.1  christos /*
    725  1.1  christos FUNCTION
    726  1.1  christos 	bfd_is_undefined_symclass
    727  1.1  christos 
    728  1.1  christos DESCRIPTION
    729  1.1  christos 	Returns non-zero if the class symbol returned by
    730  1.1  christos 	bfd_decode_symclass represents an undefined symbol.
    731  1.1  christos 	Returns zero otherwise.
    732  1.1  christos 
    733  1.1  christos SYNOPSIS
    734  1.8  christos 	bool bfd_is_undefined_symclass (int symclass);
    735  1.1  christos */
    736  1.1  christos 
    737  1.8  christos bool
    738  1.1  christos bfd_is_undefined_symclass (int symclass)
    739  1.1  christos {
    740  1.1  christos   return symclass == 'U' || symclass == 'w' || symclass == 'v';
    741  1.1  christos }
    742  1.1  christos 
    743  1.1  christos /*
    744  1.1  christos FUNCTION
    745  1.1  christos 	bfd_symbol_info
    746  1.1  christos 
    747  1.1  christos DESCRIPTION
    748  1.1  christos 	Fill in the basic info about symbol that nm needs.
    749  1.1  christos 	Additional info may be added by the back-ends after
    750  1.1  christos 	calling this function.
    751  1.1  christos 
    752  1.1  christos SYNOPSIS
    753  1.1  christos 	void bfd_symbol_info (asymbol *symbol, symbol_info *ret);
    754  1.1  christos */
    755  1.1  christos 
    756  1.1  christos void
    757  1.1  christos bfd_symbol_info (asymbol *symbol, symbol_info *ret)
    758  1.1  christos {
    759  1.1  christos   ret->type = bfd_decode_symclass (symbol);
    760  1.1  christos 
    761  1.1  christos   if (bfd_is_undefined_symclass (ret->type))
    762  1.1  christos     ret->value = 0;
    763  1.1  christos   else
    764  1.1  christos     ret->value = symbol->value + symbol->section->vma;
    765  1.1  christos 
    766  1.1  christos   ret->name = symbol->name;
    767  1.1  christos }
    768  1.1  christos 
    769  1.1  christos /*
    770  1.1  christos FUNCTION
    771  1.1  christos 	bfd_copy_private_symbol_data
    772  1.1  christos 
    773  1.1  christos SYNOPSIS
    774  1.8  christos 	bool bfd_copy_private_symbol_data
    775  1.1  christos 	  (bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
    776  1.1  christos 
    777  1.1  christos DESCRIPTION
    778  1.1  christos 	Copy private symbol information from @var{isym} in the BFD
    779  1.1  christos 	@var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.
    780  1.1  christos 	Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
    781  1.1  christos 	returns are:
    782  1.1  christos 
    783  1.1  christos 	o <<bfd_error_no_memory>> -
    784  1.1  christos 	Not enough memory exists to create private data for @var{osec}.
    785  1.1  christos 
    786  1.1  christos .#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
    787  1.6  christos .	BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
    788  1.6  christos .		  (ibfd, isymbol, obfd, osymbol))
    789  1.1  christos .
    790  1.1  christos */
    791  1.1  christos 
    792  1.1  christos /* The generic version of the function which returns mini symbols.
    793  1.1  christos    This is used when the backend does not provide a more efficient
    794  1.1  christos    version.  It just uses BFD asymbol structures as mini symbols.  */
    795  1.1  christos 
    796  1.1  christos long
    797  1.1  christos _bfd_generic_read_minisymbols (bfd *abfd,
    798  1.8  christos 			       bool dynamic,
    799  1.1  christos 			       void **minisymsp,
    800  1.1  christos 			       unsigned int *sizep)
    801  1.1  christos {
    802  1.1  christos   long storage;
    803  1.1  christos   asymbol **syms = NULL;
    804  1.1  christos   long symcount;
    805  1.1  christos 
    806  1.1  christos   if (dynamic)
    807  1.1  christos     storage = bfd_get_dynamic_symtab_upper_bound (abfd);
    808  1.1  christos   else
    809  1.1  christos     storage = bfd_get_symtab_upper_bound (abfd);
    810  1.1  christos   if (storage < 0)
    811  1.1  christos     goto error_return;
    812  1.1  christos   if (storage == 0)
    813  1.1  christos     return 0;
    814  1.1  christos 
    815  1.1  christos   syms = (asymbol **) bfd_malloc (storage);
    816  1.1  christos   if (syms == NULL)
    817  1.1  christos     goto error_return;
    818  1.1  christos 
    819  1.1  christos   if (dynamic)
    820  1.1  christos     symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
    821  1.1  christos   else
    822  1.1  christos     symcount = bfd_canonicalize_symtab (abfd, syms);
    823  1.1  christos   if (symcount < 0)
    824  1.1  christos     goto error_return;
    825  1.1  christos 
    826  1.7  christos   if (symcount == 0)
    827  1.7  christos     /* We return 0 above when storage is 0.  Exit in the same state
    828  1.7  christos        here, so as to not complicate callers with having to deal with
    829  1.7  christos        freeing memory for zero symcount.  */
    830  1.7  christos     free (syms);
    831  1.7  christos   else
    832  1.7  christos     {
    833  1.7  christos       *minisymsp = syms;
    834  1.7  christos       *sizep = sizeof (asymbol *);
    835  1.7  christos     }
    836  1.1  christos   return symcount;
    837  1.1  christos 
    838  1.1  christos  error_return:
    839  1.1  christos   bfd_set_error (bfd_error_no_symbols);
    840  1.8  christos   free (syms);
    841  1.1  christos   return -1;
    842  1.1  christos }
    843  1.1  christos 
    844  1.1  christos /* The generic version of the function which converts a minisymbol to
    845  1.1  christos    an asymbol.  We don't worry about the sym argument we are passed;
    846  1.1  christos    we just return the asymbol the minisymbol points to.  */
    847  1.1  christos 
    848  1.1  christos asymbol *
    849  1.1  christos _bfd_generic_minisymbol_to_symbol (bfd *abfd ATTRIBUTE_UNUSED,
    850  1.8  christos 				   bool dynamic ATTRIBUTE_UNUSED,
    851  1.1  christos 				   const void *minisym,
    852  1.1  christos 				   asymbol *sym ATTRIBUTE_UNUSED)
    853  1.1  christos {
    854  1.1  christos   return *(asymbol **) minisym;
    855  1.1  christos }
    856  1.1  christos 
    857  1.1  christos /* Look through stabs debugging information in .stab and .stabstr
    858  1.1  christos    sections to find the source file and line closest to a desired
    859  1.1  christos    location.  This is used by COFF and ELF targets.  It sets *pfound
    860  1.1  christos    to TRUE if it finds some information.  The *pinfo field is used to
    861  1.1  christos    pass cached information in and out of this routine; this first time
    862  1.1  christos    the routine is called for a BFD, *pinfo should be NULL.  The value
    863  1.1  christos    placed in *pinfo should be saved with the BFD, and passed back each
    864  1.1  christos    time this function is called.  */
    865  1.1  christos 
    866  1.1  christos /* We use a cache by default.  */
    867  1.1  christos 
    868  1.1  christos #define ENABLE_CACHING
    869  1.1  christos 
    870  1.1  christos /* We keep an array of indexentry structures to record where in the
    871  1.1  christos    stabs section we should look to find line number information for a
    872  1.1  christos    particular address.  */
    873  1.1  christos 
    874  1.1  christos struct indexentry
    875  1.1  christos {
    876  1.1  christos   bfd_vma val;
    877  1.1  christos   bfd_byte *stab;
    878  1.1  christos   bfd_byte *str;
    879  1.1  christos   char *directory_name;
    880  1.1  christos   char *file_name;
    881  1.1  christos   char *function_name;
    882  1.7  christos   int idx;
    883  1.1  christos };
    884  1.1  christos 
    885  1.1  christos /* Compare two indexentry structures.  This is called via qsort.  */
    886  1.1  christos 
    887  1.1  christos static int
    888  1.1  christos cmpindexentry (const void *a, const void *b)
    889  1.1  christos {
    890  1.1  christos   const struct indexentry *contestantA = (const struct indexentry *) a;
    891  1.1  christos   const struct indexentry *contestantB = (const struct indexentry *) b;
    892  1.1  christos 
    893  1.1  christos   if (contestantA->val < contestantB->val)
    894  1.1  christos     return -1;
    895  1.7  christos   if (contestantA->val > contestantB->val)
    896  1.1  christos     return 1;
    897  1.7  christos   return contestantA->idx - contestantB->idx;
    898  1.1  christos }
    899  1.1  christos 
    900  1.1  christos /* A pointer to this structure is stored in *pinfo.  */
    901  1.1  christos 
    902  1.1  christos struct stab_find_info
    903  1.1  christos {
    904  1.1  christos   /* The .stab section.  */
    905  1.1  christos   asection *stabsec;
    906  1.1  christos   /* The .stabstr section.  */
    907  1.1  christos   asection *strsec;
    908  1.1  christos   /* The contents of the .stab section.  */
    909  1.1  christos   bfd_byte *stabs;
    910  1.1  christos   /* The contents of the .stabstr section.  */
    911  1.1  christos   bfd_byte *strs;
    912  1.1  christos 
    913  1.1  christos   /* A table that indexes stabs by memory address.  */
    914  1.1  christos   struct indexentry *indextable;
    915  1.1  christos   /* The number of entries in indextable.  */
    916  1.1  christos   int indextablesize;
    917  1.1  christos 
    918  1.1  christos #ifdef ENABLE_CACHING
    919  1.1  christos   /* Cached values to restart quickly.  */
    920  1.1  christos   struct indexentry *cached_indexentry;
    921  1.1  christos   bfd_vma cached_offset;
    922  1.1  christos   bfd_byte *cached_stab;
    923  1.1  christos   char *cached_file_name;
    924  1.1  christos #endif
    925  1.1  christos 
    926  1.1  christos   /* Saved ptr to malloc'ed filename.  */
    927  1.1  christos   char *filename;
    928  1.1  christos };
    929  1.1  christos 
    930  1.8  christos bool
    931  1.1  christos _bfd_stab_section_find_nearest_line (bfd *abfd,
    932  1.1  christos 				     asymbol **symbols,
    933  1.1  christos 				     asection *section,
    934  1.1  christos 				     bfd_vma offset,
    935  1.8  christos 				     bool *pfound,
    936  1.1  christos 				     const char **pfilename,
    937  1.1  christos 				     const char **pfnname,
    938  1.1  christos 				     unsigned int *pline,
    939  1.1  christos 				     void **pinfo)
    940  1.1  christos {
    941  1.1  christos   struct stab_find_info *info;
    942  1.1  christos   bfd_size_type stabsize, strsize;
    943  1.1  christos   bfd_byte *stab, *str;
    944  1.3  christos   bfd_byte *nul_fun, *nul_str;
    945  1.1  christos   bfd_size_type stroff;
    946  1.1  christos   struct indexentry *indexentry;
    947  1.1  christos   char *file_name;
    948  1.1  christos   char *directory_name;
    949  1.8  christos   bool saw_line, saw_func;
    950  1.1  christos 
    951  1.8  christos   *pfound = false;
    952  1.1  christos   *pfilename = bfd_get_filename (abfd);
    953  1.1  christos   *pfnname = NULL;
    954  1.1  christos   *pline = 0;
    955  1.1  christos 
    956  1.1  christos   /* Stabs entries use a 12 byte format:
    957  1.1  christos        4 byte string table index
    958  1.1  christos        1 byte stab type
    959  1.1  christos        1 byte stab other field
    960  1.1  christos        2 byte stab desc field
    961  1.1  christos        4 byte stab value
    962  1.1  christos      FIXME: This will have to change for a 64 bit object format.
    963  1.1  christos 
    964  1.1  christos      The stabs symbols are divided into compilation units.  For the
    965  1.1  christos      first entry in each unit, the type of 0, the value is the length
    966  1.1  christos      of the string table for this unit, and the desc field is the
    967  1.1  christos      number of stabs symbols for this unit.  */
    968  1.1  christos 
    969  1.1  christos #define STRDXOFF (0)
    970  1.1  christos #define TYPEOFF (4)
    971  1.1  christos #define OTHEROFF (5)
    972  1.1  christos #define DESCOFF (6)
    973  1.1  christos #define VALOFF (8)
    974  1.1  christos #define STABSIZE (12)
    975  1.1  christos 
    976  1.1  christos   info = (struct stab_find_info *) *pinfo;
    977  1.1  christos   if (info != NULL)
    978  1.1  christos     {
    979  1.1  christos       if (info->stabsec == NULL || info->strsec == NULL)
    980  1.1  christos 	{
    981  1.1  christos 	  /* No stabs debugging information.  */
    982  1.8  christos 	  return true;
    983  1.1  christos 	}
    984  1.1  christos 
    985  1.1  christos       stabsize = (info->stabsec->rawsize
    986  1.1  christos 		  ? info->stabsec->rawsize
    987  1.1  christos 		  : info->stabsec->size);
    988  1.1  christos       strsize = (info->strsec->rawsize
    989  1.1  christos 		 ? info->strsec->rawsize
    990  1.1  christos 		 : info->strsec->size);
    991  1.1  christos     }
    992  1.1  christos   else
    993  1.1  christos     {
    994  1.1  christos       long reloc_size, reloc_count;
    995  1.1  christos       arelent **reloc_vector;
    996  1.1  christos       int i;
    997  1.1  christos       char *function_name;
    998  1.1  christos       bfd_size_type amt = sizeof *info;
    999  1.1  christos 
   1000  1.1  christos       info = (struct stab_find_info *) bfd_zalloc (abfd, amt);
   1001  1.1  christos       if (info == NULL)
   1002  1.8  christos 	return false;
   1003  1.1  christos 
   1004  1.1  christos       /* FIXME: When using the linker --split-by-file or
   1005  1.1  christos 	 --split-by-reloc options, it is possible for the .stab and
   1006  1.1  christos 	 .stabstr sections to be split.  We should handle that.  */
   1007  1.1  christos 
   1008  1.1  christos       info->stabsec = bfd_get_section_by_name (abfd, ".stab");
   1009  1.1  christos       info->strsec = bfd_get_section_by_name (abfd, ".stabstr");
   1010  1.1  christos 
   1011  1.1  christos       if (info->stabsec == NULL || info->strsec == NULL)
   1012  1.1  christos 	{
   1013  1.1  christos 	  /* Try SOM section names.  */
   1014  1.1  christos 	  info->stabsec = bfd_get_section_by_name (abfd, "$GDB_SYMBOLS$");
   1015  1.1  christos 	  info->strsec  = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
   1016  1.3  christos 
   1017  1.1  christos 	  if (info->stabsec == NULL || info->strsec == NULL)
   1018  1.1  christos 	    {
   1019  1.1  christos 	      /* No stabs debugging information.  Set *pinfo so that we
   1020  1.1  christos 		 can return quickly in the info != NULL case above.  */
   1021  1.1  christos 	      *pinfo = info;
   1022  1.8  christos 	      return true;
   1023  1.1  christos 	    }
   1024  1.1  christos 	}
   1025  1.1  christos 
   1026  1.1  christos       stabsize = (info->stabsec->rawsize
   1027  1.1  christos 		  ? info->stabsec->rawsize
   1028  1.1  christos 		  : info->stabsec->size);
   1029  1.3  christos       stabsize = (stabsize / STABSIZE) * STABSIZE;
   1030  1.1  christos       strsize = (info->strsec->rawsize
   1031  1.1  christos 		 ? info->strsec->rawsize
   1032  1.1  christos 		 : info->strsec->size);
   1033  1.1  christos 
   1034  1.1  christos       info->stabs = (bfd_byte *) bfd_alloc (abfd, stabsize);
   1035  1.1  christos       info->strs = (bfd_byte *) bfd_alloc (abfd, strsize);
   1036  1.1  christos       if (info->stabs == NULL || info->strs == NULL)
   1037  1.8  christos 	return false;
   1038  1.1  christos 
   1039  1.1  christos       if (! bfd_get_section_contents (abfd, info->stabsec, info->stabs,
   1040  1.1  christos 				      0, stabsize)
   1041  1.1  christos 	  || ! bfd_get_section_contents (abfd, info->strsec, info->strs,
   1042  1.1  christos 					 0, strsize))
   1043  1.8  christos 	return false;
   1044  1.1  christos 
   1045  1.7  christos       /* Stab strings ought to be nul terminated.  Ensure the last one
   1046  1.7  christos 	 is, to prevent running off the end of the buffer.  */
   1047  1.7  christos       info->strs[strsize - 1] = 0;
   1048  1.7  christos 
   1049  1.1  christos       /* If this is a relocatable object file, we have to relocate
   1050  1.1  christos 	 the entries in .stab.  This should always be simple 32 bit
   1051  1.1  christos 	 relocations against symbols defined in this object file, so
   1052  1.1  christos 	 this should be no big deal.  */
   1053  1.1  christos       reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec);
   1054  1.1  christos       if (reloc_size < 0)
   1055  1.8  christos 	return false;
   1056  1.1  christos       reloc_vector = (arelent **) bfd_malloc (reloc_size);
   1057  1.1  christos       if (reloc_vector == NULL && reloc_size != 0)
   1058  1.8  christos 	return false;
   1059  1.1  christos       reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector,
   1060  1.1  christos 					    symbols);
   1061  1.1  christos       if (reloc_count < 0)
   1062  1.1  christos 	{
   1063  1.8  christos 	  free (reloc_vector);
   1064  1.8  christos 	  return false;
   1065  1.1  christos 	}
   1066  1.1  christos       if (reloc_count > 0)
   1067  1.1  christos 	{
   1068  1.1  christos 	  arelent **pr;
   1069  1.1  christos 
   1070  1.1  christos 	  for (pr = reloc_vector; *pr != NULL; pr++)
   1071  1.1  christos 	    {
   1072  1.1  christos 	      arelent *r;
   1073  1.1  christos 	      unsigned long val;
   1074  1.1  christos 	      asymbol *sym;
   1075  1.7  christos 	      bfd_size_type octets;
   1076  1.1  christos 
   1077  1.1  christos 	      r = *pr;
   1078  1.1  christos 	      /* Ignore R_*_NONE relocs.  */
   1079  1.1  christos 	      if (r->howto->dst_mask == 0)
   1080  1.1  christos 		continue;
   1081  1.1  christos 
   1082  1.7  christos 	      octets = r->address * bfd_octets_per_byte (abfd, NULL);
   1083  1.1  christos 	      if (r->howto->rightshift != 0
   1084  1.8  christos 		  || bfd_get_reloc_size (r->howto) != 4
   1085  1.1  christos 		  || r->howto->bitsize != 32
   1086  1.1  christos 		  || r->howto->pc_relative
   1087  1.1  christos 		  || r->howto->bitpos != 0
   1088  1.7  christos 		  || r->howto->dst_mask != 0xffffffff
   1089  1.7  christos 		  || octets + 4 > stabsize)
   1090  1.1  christos 		{
   1091  1.6  christos 		  _bfd_error_handler
   1092  1.6  christos 		    (_("unsupported .stab relocation"));
   1093  1.1  christos 		  bfd_set_error (bfd_error_invalid_operation);
   1094  1.8  christos 		  free (reloc_vector);
   1095  1.8  christos 		  return false;
   1096  1.1  christos 		}
   1097  1.1  christos 
   1098  1.7  christos 	      val = bfd_get_32 (abfd, info->stabs + octets);
   1099  1.1  christos 	      val &= r->howto->src_mask;
   1100  1.1  christos 	      sym = *r->sym_ptr_ptr;
   1101  1.1  christos 	      val += sym->value + sym->section->vma + r->addend;
   1102  1.7  christos 	      bfd_put_32 (abfd, (bfd_vma) val, info->stabs + octets);
   1103  1.1  christos 	    }
   1104  1.1  christos 	}
   1105  1.1  christos 
   1106  1.8  christos       free (reloc_vector);
   1107  1.1  christos 
   1108  1.1  christos       /* First time through this function, build a table matching
   1109  1.1  christos 	 function VM addresses to stabs, then sort based on starting
   1110  1.1  christos 	 VM address.  Do this in two passes: once to count how many
   1111  1.1  christos 	 table entries we'll need, and a second to actually build the
   1112  1.1  christos 	 table.  */
   1113  1.1  christos 
   1114  1.1  christos       info->indextablesize = 0;
   1115  1.3  christos       nul_fun = NULL;
   1116  1.1  christos       for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)
   1117  1.1  christos 	{
   1118  1.1  christos 	  if (stab[TYPEOFF] == (bfd_byte) N_SO)
   1119  1.1  christos 	    {
   1120  1.1  christos 	      /* if we did not see a function def, leave space for one.  */
   1121  1.3  christos 	      if (nul_fun != NULL)
   1122  1.1  christos 		++info->indextablesize;
   1123  1.1  christos 
   1124  1.3  christos 	      /* N_SO with null name indicates EOF */
   1125  1.3  christos 	      if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)
   1126  1.3  christos 		nul_fun = NULL;
   1127  1.3  christos 	      else
   1128  1.3  christos 		{
   1129  1.3  christos 		  nul_fun = stab;
   1130  1.1  christos 
   1131  1.3  christos 		  /* two N_SO's in a row is a filename and directory. Skip */
   1132  1.3  christos 		  if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize
   1133  1.3  christos 		      && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
   1134  1.3  christos 		    stab += STABSIZE;
   1135  1.1  christos 		}
   1136  1.1  christos 	    }
   1137  1.3  christos 	  else if (stab[TYPEOFF] == (bfd_byte) N_FUN
   1138  1.3  christos 		   && bfd_get_32 (abfd, stab + STRDXOFF) != 0)
   1139  1.1  christos 	    {
   1140  1.3  christos 	      nul_fun = NULL;
   1141  1.1  christos 	      ++info->indextablesize;
   1142  1.1  christos 	    }
   1143  1.1  christos 	}
   1144  1.1  christos 
   1145  1.3  christos       if (nul_fun != NULL)
   1146  1.1  christos 	++info->indextablesize;
   1147  1.1  christos 
   1148  1.1  christos       if (info->indextablesize == 0)
   1149  1.8  christos 	return true;
   1150  1.1  christos       ++info->indextablesize;
   1151  1.1  christos 
   1152  1.1  christos       amt = info->indextablesize;
   1153  1.1  christos       amt *= sizeof (struct indexentry);
   1154  1.1  christos       info->indextable = (struct indexentry *) bfd_alloc (abfd, amt);
   1155  1.1  christos       if (info->indextable == NULL)
   1156  1.8  christos 	return false;
   1157  1.1  christos 
   1158  1.1  christos       file_name = NULL;
   1159  1.1  christos       directory_name = NULL;
   1160  1.3  christos       nul_fun = NULL;
   1161  1.3  christos       stroff = 0;
   1162  1.1  christos 
   1163  1.3  christos       for (i = 0, stab = info->stabs, nul_str = str = info->strs;
   1164  1.1  christos 	   i < info->indextablesize && stab < info->stabs + stabsize;
   1165  1.1  christos 	   stab += STABSIZE)
   1166  1.1  christos 	{
   1167  1.1  christos 	  switch (stab[TYPEOFF])
   1168  1.1  christos 	    {
   1169  1.1  christos 	    case 0:
   1170  1.1  christos 	      /* This is the first entry in a compilation unit.  */
   1171  1.1  christos 	      if ((bfd_size_type) ((info->strs + strsize) - str) < stroff)
   1172  1.1  christos 		break;
   1173  1.1  christos 	      str += stroff;
   1174  1.1  christos 	      stroff = bfd_get_32 (abfd, stab + VALOFF);
   1175  1.1  christos 	      break;
   1176  1.1  christos 
   1177  1.1  christos 	    case N_SO:
   1178  1.1  christos 	      /* The main file name.  */
   1179  1.1  christos 
   1180  1.1  christos 	      /* The following code creates a new indextable entry with
   1181  1.6  christos 		 a NULL function name if there were no N_FUNs in a file.
   1182  1.6  christos 		 Note that a N_SO without a file name is an EOF and
   1183  1.6  christos 		 there could be 2 N_SO following it with the new filename
   1184  1.6  christos 		 and directory.  */
   1185  1.3  christos 	      if (nul_fun != NULL)
   1186  1.1  christos 		{
   1187  1.3  christos 		  info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF);
   1188  1.3  christos 		  info->indextable[i].stab = nul_fun;
   1189  1.3  christos 		  info->indextable[i].str = nul_str;
   1190  1.1  christos 		  info->indextable[i].directory_name = directory_name;
   1191  1.1  christos 		  info->indextable[i].file_name = file_name;
   1192  1.1  christos 		  info->indextable[i].function_name = NULL;
   1193  1.7  christos 		  info->indextable[i].idx = i;
   1194  1.1  christos 		  ++i;
   1195  1.1  christos 		}
   1196  1.1  christos 
   1197  1.3  christos 	      directory_name = NULL;
   1198  1.1  christos 	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
   1199  1.3  christos 	      if (file_name == (char *) str)
   1200  1.1  christos 		{
   1201  1.1  christos 		  file_name = NULL;
   1202  1.3  christos 		  nul_fun = NULL;
   1203  1.1  christos 		}
   1204  1.1  christos 	      else
   1205  1.1  christos 		{
   1206  1.3  christos 		  nul_fun = stab;
   1207  1.3  christos 		  nul_str = str;
   1208  1.7  christos 		  if (file_name >= (char *) info->strs + strsize
   1209  1.7  christos 		      || file_name < (char *) str)
   1210  1.3  christos 		    file_name = NULL;
   1211  1.3  christos 		  if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize
   1212  1.3  christos 		      && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
   1213  1.1  christos 		    {
   1214  1.1  christos 		      /* Two consecutive N_SOs are a directory and a
   1215  1.1  christos 			 file name.  */
   1216  1.1  christos 		      stab += STABSIZE;
   1217  1.1  christos 		      directory_name = file_name;
   1218  1.1  christos 		      file_name = ((char *) str
   1219  1.1  christos 				   + bfd_get_32 (abfd, stab + STRDXOFF));
   1220  1.7  christos 		      if (file_name >= (char *) info->strs + strsize
   1221  1.7  christos 			  || file_name < (char *) str)
   1222  1.3  christos 			file_name = NULL;
   1223  1.1  christos 		    }
   1224  1.1  christos 		}
   1225  1.1  christos 	      break;
   1226  1.1  christos 
   1227  1.1  christos 	    case N_SOL:
   1228  1.1  christos 	      /* The name of an include file.  */
   1229  1.1  christos 	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
   1230  1.3  christos 	      /* PR 17512: file: 0c680a1f.  */
   1231  1.3  christos 	      /* PR 17512: file: 5da8aec4.  */
   1232  1.7  christos 	      if (file_name >= (char *) info->strs + strsize
   1233  1.7  christos 		  || file_name < (char *) str)
   1234  1.3  christos 		file_name = NULL;
   1235  1.1  christos 	      break;
   1236  1.1  christos 
   1237  1.1  christos 	    case N_FUN:
   1238  1.1  christos 	      /* A function name.  */
   1239  1.3  christos 	      function_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
   1240  1.3  christos 	      if (function_name == (char *) str)
   1241  1.1  christos 		continue;
   1242  1.7  christos 	      if (function_name >= (char *) info->strs + strsize
   1243  1.7  christos 		  || function_name < (char *) str)
   1244  1.3  christos 		function_name = NULL;
   1245  1.1  christos 
   1246  1.3  christos 	      nul_fun = NULL;
   1247  1.1  christos 	      info->indextable[i].val = bfd_get_32 (abfd, stab + VALOFF);
   1248  1.1  christos 	      info->indextable[i].stab = stab;
   1249  1.1  christos 	      info->indextable[i].str = str;
   1250  1.1  christos 	      info->indextable[i].directory_name = directory_name;
   1251  1.1  christos 	      info->indextable[i].file_name = file_name;
   1252  1.1  christos 	      info->indextable[i].function_name = function_name;
   1253  1.7  christos 	      info->indextable[i].idx = i;
   1254  1.1  christos 	      ++i;
   1255  1.1  christos 	      break;
   1256  1.1  christos 	    }
   1257  1.1  christos 	}
   1258  1.1  christos 
   1259  1.3  christos       if (nul_fun != NULL)
   1260  1.1  christos 	{
   1261  1.3  christos 	  info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF);
   1262  1.3  christos 	  info->indextable[i].stab = nul_fun;
   1263  1.3  christos 	  info->indextable[i].str = nul_str;
   1264  1.1  christos 	  info->indextable[i].directory_name = directory_name;
   1265  1.1  christos 	  info->indextable[i].file_name = file_name;
   1266  1.1  christos 	  info->indextable[i].function_name = NULL;
   1267  1.7  christos 	  info->indextable[i].idx = i;
   1268  1.1  christos 	  ++i;
   1269  1.1  christos 	}
   1270  1.1  christos 
   1271  1.1  christos       info->indextable[i].val = (bfd_vma) -1;
   1272  1.1  christos       info->indextable[i].stab = info->stabs + stabsize;
   1273  1.1  christos       info->indextable[i].str = str;
   1274  1.1  christos       info->indextable[i].directory_name = NULL;
   1275  1.1  christos       info->indextable[i].file_name = NULL;
   1276  1.1  christos       info->indextable[i].function_name = NULL;
   1277  1.7  christos       info->indextable[i].idx = i;
   1278  1.1  christos       ++i;
   1279  1.1  christos 
   1280  1.1  christos       info->indextablesize = i;
   1281  1.1  christos       qsort (info->indextable, (size_t) i, sizeof (struct indexentry),
   1282  1.1  christos 	     cmpindexentry);
   1283  1.1  christos 
   1284  1.1  christos       *pinfo = info;
   1285  1.1  christos     }
   1286  1.1  christos 
   1287  1.1  christos   /* We are passed a section relative offset.  The offsets in the
   1288  1.1  christos      stabs information are absolute.  */
   1289  1.7  christos   offset += bfd_section_vma (section);
   1290  1.1  christos 
   1291  1.1  christos #ifdef ENABLE_CACHING
   1292  1.1  christos   if (info->cached_indexentry != NULL
   1293  1.1  christos       && offset >= info->cached_offset
   1294  1.1  christos       && offset < (info->cached_indexentry + 1)->val)
   1295  1.1  christos     {
   1296  1.1  christos       stab = info->cached_stab;
   1297  1.1  christos       indexentry = info->cached_indexentry;
   1298  1.1  christos       file_name = info->cached_file_name;
   1299  1.1  christos     }
   1300  1.1  christos   else
   1301  1.1  christos #endif
   1302  1.1  christos     {
   1303  1.1  christos       long low, high;
   1304  1.1  christos       long mid = -1;
   1305  1.1  christos 
   1306  1.1  christos       /* Cache non-existent or invalid.  Do binary search on
   1307  1.6  christos 	 indextable.  */
   1308  1.1  christos       indexentry = NULL;
   1309  1.1  christos 
   1310  1.1  christos       low = 0;
   1311  1.1  christos       high = info->indextablesize - 1;
   1312  1.1  christos       while (low != high)
   1313  1.1  christos 	{
   1314  1.1  christos 	  mid = (high + low) / 2;
   1315  1.1  christos 	  if (offset >= info->indextable[mid].val
   1316  1.1  christos 	      && offset < info->indextable[mid + 1].val)
   1317  1.1  christos 	    {
   1318  1.1  christos 	      indexentry = &info->indextable[mid];
   1319  1.1  christos 	      break;
   1320  1.1  christos 	    }
   1321  1.1  christos 
   1322  1.1  christos 	  if (info->indextable[mid].val > offset)
   1323  1.1  christos 	    high = mid;
   1324  1.1  christos 	  else
   1325  1.1  christos 	    low = mid + 1;
   1326  1.1  christos 	}
   1327  1.1  christos 
   1328  1.1  christos       if (indexentry == NULL)
   1329  1.8  christos 	return true;
   1330  1.1  christos 
   1331  1.1  christos       stab = indexentry->stab + STABSIZE;
   1332  1.1  christos       file_name = indexentry->file_name;
   1333  1.1  christos     }
   1334  1.1  christos 
   1335  1.1  christos   directory_name = indexentry->directory_name;
   1336  1.1  christos   str = indexentry->str;
   1337  1.1  christos 
   1338  1.8  christos   saw_line = false;
   1339  1.8  christos   saw_func = false;
   1340  1.1  christos   for (; stab < (indexentry+1)->stab; stab += STABSIZE)
   1341  1.1  christos     {
   1342  1.8  christos       bool done;
   1343  1.1  christos       bfd_vma val;
   1344  1.1  christos 
   1345  1.8  christos       done = false;
   1346  1.1  christos 
   1347  1.1  christos       switch (stab[TYPEOFF])
   1348  1.1  christos 	{
   1349  1.1  christos 	case N_SOL:
   1350  1.1  christos 	  /* The name of an include file.  */
   1351  1.1  christos 	  val = bfd_get_32 (abfd, stab + VALOFF);
   1352  1.1  christos 	  if (val <= offset)
   1353  1.1  christos 	    {
   1354  1.1  christos 	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
   1355  1.7  christos 	      if (file_name >= (char *) info->strs + strsize
   1356  1.7  christos 		  || file_name < (char *) str)
   1357  1.3  christos 		file_name = NULL;
   1358  1.1  christos 	      *pline = 0;
   1359  1.1  christos 	    }
   1360  1.1  christos 	  break;
   1361  1.1  christos 
   1362  1.1  christos 	case N_SLINE:
   1363  1.1  christos 	case N_DSLINE:
   1364  1.1  christos 	case N_BSLINE:
   1365  1.1  christos 	  /* A line number.  If the function was specified, then the value
   1366  1.1  christos 	     is relative to the start of the function.  Otherwise, the
   1367  1.1  christos 	     value is an absolute address.  */
   1368  1.1  christos 	  val = ((indexentry->function_name ? indexentry->val : 0)
   1369  1.1  christos 		 + bfd_get_32 (abfd, stab + VALOFF));
   1370  1.1  christos 	  /* If this line starts before our desired offset, or if it's
   1371  1.1  christos 	     the first line we've been able to find, use it.  The
   1372  1.1  christos 	     !saw_line check works around a bug in GCC 2.95.3, which emits
   1373  1.1  christos 	     the first N_SLINE late.  */
   1374  1.1  christos 	  if (!saw_line || val <= offset)
   1375  1.1  christos 	    {
   1376  1.1  christos 	      *pline = bfd_get_16 (abfd, stab + DESCOFF);
   1377  1.1  christos 
   1378  1.1  christos #ifdef ENABLE_CACHING
   1379  1.1  christos 	      info->cached_stab = stab;
   1380  1.1  christos 	      info->cached_offset = val;
   1381  1.1  christos 	      info->cached_file_name = file_name;
   1382  1.1  christos 	      info->cached_indexentry = indexentry;
   1383  1.1  christos #endif
   1384  1.1  christos 	    }
   1385  1.1  christos 	  if (val > offset)
   1386  1.8  christos 	    done = true;
   1387  1.8  christos 	  saw_line = true;
   1388  1.1  christos 	  break;
   1389  1.1  christos 
   1390  1.1  christos 	case N_FUN:
   1391  1.1  christos 	case N_SO:
   1392  1.1  christos 	  if (saw_func || saw_line)
   1393  1.8  christos 	    done = true;
   1394  1.8  christos 	  saw_func = true;
   1395  1.1  christos 	  break;
   1396  1.1  christos 	}
   1397  1.1  christos 
   1398  1.1  christos       if (done)
   1399  1.1  christos 	break;
   1400  1.1  christos     }
   1401  1.1  christos 
   1402  1.8  christos   *pfound = true;
   1403  1.1  christos 
   1404  1.1  christos   if (file_name == NULL || IS_ABSOLUTE_PATH (file_name)
   1405  1.1  christos       || directory_name == NULL)
   1406  1.1  christos     *pfilename = file_name;
   1407  1.1  christos   else
   1408  1.1  christos     {
   1409  1.1  christos       size_t dirlen;
   1410  1.1  christos 
   1411  1.1  christos       dirlen = strlen (directory_name);
   1412  1.1  christos       if (info->filename == NULL
   1413  1.1  christos 	  || filename_ncmp (info->filename, directory_name, dirlen) != 0
   1414  1.1  christos 	  || filename_cmp (info->filename + dirlen, file_name) != 0)
   1415  1.1  christos 	{
   1416  1.1  christos 	  size_t len;
   1417  1.1  christos 
   1418  1.1  christos 	  /* Don't free info->filename here.  objdump and other
   1419  1.1  christos 	     apps keep a copy of a previously returned file name
   1420  1.1  christos 	     pointer.  */
   1421  1.1  christos 	  len = strlen (file_name) + 1;
   1422  1.1  christos 	  info->filename = (char *) bfd_alloc (abfd, dirlen + len);
   1423  1.1  christos 	  if (info->filename == NULL)
   1424  1.8  christos 	    return false;
   1425  1.1  christos 	  memcpy (info->filename, directory_name, dirlen);
   1426  1.1  christos 	  memcpy (info->filename + dirlen, file_name, len);
   1427  1.1  christos 	}
   1428  1.1  christos 
   1429  1.1  christos       *pfilename = info->filename;
   1430  1.1  christos     }
   1431  1.1  christos 
   1432  1.1  christos   if (indexentry->function_name != NULL)
   1433  1.1  christos     {
   1434  1.1  christos       char *s;
   1435  1.1  christos 
   1436  1.1  christos       /* This will typically be something like main:F(0,1), so we want
   1437  1.6  christos 	 to clobber the colon.  It's OK to change the name, since the
   1438  1.6  christos 	 string is in our own local storage anyhow.  */
   1439  1.1  christos       s = strchr (indexentry->function_name, ':');
   1440  1.1  christos       if (s != NULL)
   1441  1.1  christos 	*s = '\0';
   1442  1.1  christos 
   1443  1.1  christos       *pfnname = indexentry->function_name;
   1444  1.1  christos     }
   1445  1.1  christos 
   1446  1.8  christos   return true;
   1447  1.1  christos }
   1448  1.6  christos 
   1449  1.6  christos long
   1450  1.6  christos _bfd_nosymbols_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED,
   1451  1.6  christos 				    asymbol **location ATTRIBUTE_UNUSED)
   1452  1.6  christos {
   1453  1.6  christos   return 0;
   1454  1.6  christos }
   1455  1.6  christos 
   1456  1.6  christos void
   1457  1.6  christos _bfd_nosymbols_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
   1458  1.6  christos 			     void *afile ATTRIBUTE_UNUSED,
   1459  1.6  christos 			     asymbol *symbol ATTRIBUTE_UNUSED,
   1460  1.6  christos 			     bfd_print_symbol_type how ATTRIBUTE_UNUSED)
   1461  1.6  christos {
   1462  1.6  christos }
   1463  1.6  christos 
   1464  1.6  christos void
   1465  1.6  christos _bfd_nosymbols_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
   1466  1.6  christos 				asymbol *sym ATTRIBUTE_UNUSED,
   1467  1.6  christos 				symbol_info *ret ATTRIBUTE_UNUSED)
   1468  1.6  christos {
   1469  1.6  christos }
   1470  1.6  christos 
   1471  1.6  christos const char *
   1472  1.6  christos _bfd_nosymbols_get_symbol_version_string (bfd *abfd,
   1473  1.6  christos 					  asymbol *symbol ATTRIBUTE_UNUSED,
   1474  1.8  christos 					  bool base_p ATTRIBUTE_UNUSED,
   1475  1.8  christos 					  bool *hidden ATTRIBUTE_UNUSED)
   1476  1.6  christos {
   1477  1.6  christos   return (const char *) _bfd_ptr_bfd_null_error (abfd);
   1478  1.6  christos }
   1479  1.6  christos 
   1480  1.8  christos bool
   1481  1.6  christos _bfd_nosymbols_bfd_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
   1482  1.6  christos 					const char *name ATTRIBUTE_UNUSED)
   1483  1.6  christos {
   1484  1.8  christos   return false;
   1485  1.6  christos }
   1486  1.6  christos 
   1487  1.6  christos alent *
   1488  1.6  christos _bfd_nosymbols_get_lineno (bfd *abfd, asymbol *sym ATTRIBUTE_UNUSED)
   1489  1.6  christos {
   1490  1.6  christos   return (alent *) _bfd_ptr_bfd_null_error (abfd);
   1491  1.6  christos }
   1492  1.6  christos 
   1493  1.8  christos bool
   1494  1.6  christos _bfd_nosymbols_find_nearest_line
   1495  1.6  christos     (bfd *abfd,
   1496  1.6  christos      asymbol **symbols ATTRIBUTE_UNUSED,
   1497  1.6  christos      asection *section ATTRIBUTE_UNUSED,
   1498  1.6  christos      bfd_vma offset ATTRIBUTE_UNUSED,
   1499  1.6  christos      const char **filename_ptr ATTRIBUTE_UNUSED,
   1500  1.6  christos      const char **functionname_ptr ATTRIBUTE_UNUSED,
   1501  1.6  christos      unsigned int *line_ptr ATTRIBUTE_UNUSED,
   1502  1.6  christos      unsigned int *discriminator_ptr ATTRIBUTE_UNUSED)
   1503  1.6  christos {
   1504  1.6  christos   return _bfd_bool_bfd_false_error (abfd);
   1505  1.6  christos }
   1506  1.6  christos 
   1507  1.8  christos bool
   1508  1.6  christos _bfd_nosymbols_find_line (bfd *abfd,
   1509  1.6  christos 			  asymbol **symbols ATTRIBUTE_UNUSED,
   1510  1.6  christos 			  asymbol *symbol ATTRIBUTE_UNUSED,
   1511  1.6  christos 			  const char **filename_ptr ATTRIBUTE_UNUSED,
   1512  1.6  christos 			  unsigned int *line_ptr ATTRIBUTE_UNUSED)
   1513  1.6  christos {
   1514  1.6  christos   return _bfd_bool_bfd_false_error (abfd);
   1515  1.6  christos }
   1516  1.6  christos 
   1517  1.8  christos bool
   1518  1.6  christos _bfd_nosymbols_find_inliner_info
   1519  1.6  christos     (bfd *abfd,
   1520  1.6  christos      const char **filename_ptr ATTRIBUTE_UNUSED,
   1521  1.6  christos      const char **functionname_ptr ATTRIBUTE_UNUSED,
   1522  1.6  christos      unsigned int *line_ptr ATTRIBUTE_UNUSED)
   1523  1.6  christos {
   1524  1.6  christos   return _bfd_bool_bfd_false_error (abfd);
   1525  1.6  christos }
   1526  1.6  christos 
   1527  1.6  christos asymbol *
   1528  1.6  christos _bfd_nosymbols_bfd_make_debug_symbol (bfd *abfd,
   1529  1.6  christos 				      void *ptr ATTRIBUTE_UNUSED,
   1530  1.6  christos 				      unsigned long sz ATTRIBUTE_UNUSED)
   1531  1.6  christos {
   1532  1.6  christos   return (asymbol *) _bfd_ptr_bfd_null_error (abfd);
   1533  1.6  christos }
   1534  1.6  christos 
   1535  1.6  christos long
   1536  1.6  christos _bfd_nosymbols_read_minisymbols (bfd *abfd,
   1537  1.8  christos 				 bool dynamic ATTRIBUTE_UNUSED,
   1538  1.6  christos 				 void **minisymsp ATTRIBUTE_UNUSED,
   1539  1.6  christos 				 unsigned int *sizep ATTRIBUTE_UNUSED)
   1540  1.6  christos {
   1541  1.6  christos   return _bfd_long_bfd_n1_error (abfd);
   1542  1.6  christos }
   1543  1.6  christos 
   1544  1.6  christos asymbol *
   1545  1.6  christos _bfd_nosymbols_minisymbol_to_symbol (bfd *abfd,
   1546  1.8  christos 				     bool dynamic ATTRIBUTE_UNUSED,
   1547  1.6  christos 				     const void *minisym ATTRIBUTE_UNUSED,
   1548  1.6  christos 				     asymbol *sym ATTRIBUTE_UNUSED)
   1549  1.6  christos {
   1550  1.6  christos   return (asymbol *) _bfd_ptr_bfd_null_error (abfd);
   1551  1.6  christos }
   1552  1.6  christos 
   1553  1.6  christos long
   1554  1.6  christos _bfd_nodynamic_get_synthetic_symtab (bfd *abfd,
   1555  1.6  christos 				     long symcount ATTRIBUTE_UNUSED,
   1556  1.6  christos 				     asymbol **syms ATTRIBUTE_UNUSED,
   1557  1.6  christos 				     long dynsymcount ATTRIBUTE_UNUSED,
   1558  1.6  christos 				     asymbol **dynsyms ATTRIBUTE_UNUSED,
   1559  1.6  christos 				     asymbol **ret ATTRIBUTE_UNUSED)
   1560  1.6  christos {
   1561  1.6  christos   return _bfd_long_bfd_n1_error (abfd);
   1562  1.6  christos }
   1563