Untitled Document: Reading Symbols

Next: Writing Symbols, Previous: Symbols, Up: Symbols [Contents][Index]

#### 2.7.1 Reading symbols

There are two stages to reading a symbol table from a BFD: allocating storage, and the actual reading process. This is an excerpt from an application which reads the symbol table:

             long storage_needed;
             asymbol **symbol_table;
             long number_of_symbols;
             long i;

             storage_needed = bfd_get_symtab_upper_bound (abfd);

             if (storage_needed < 0)
               FAIL

             if (storage_needed == 0)
               return;

             symbol_table = xmalloc (storage_needed);
               ...
             number_of_symbols =
                bfd_canonicalize_symtab (abfd, symbol_table);

             if (number_of_symbols < 0)
               FAIL

             for (i = 0; i < number_of_symbols; i++)
               process_symbol (symbol_table[i]);

All storage for the symbols themselves is in an objalloc connected to the BFD; it is freed when the BFD is closed.