Next: , Previous: Reading Symbols, Up: Symbols


2.7.2 Writing symbols

Writing of a symbol table is automatic when a BFD open for writing is closed. The application attaches a vector of pointers to pointers to symbols to the BFD being written, and fills in the symbol count. The close and cleanup code reads through the table provided and performs all the necessary operations. The BFD output code must always be provided with an “owned” symbol: one which has come from another BFD, or one which has been created using bfd_make_empty_symbol. Here is an example showing the creation of a symbol table with only one element:

            #include "bfd.h"
            int main (void)
            {
              bfd *abfd;
              asymbol *ptrs[2];
              asymbol *new;
     
              abfd = bfd_openw ("foo","a.out-sunos-big");
              bfd_set_format (abfd, bfd_object);
              new = bfd_make_empty_symbol (abfd);
              new->name = "dummy_symbol";
              new->section = bfd_make_section_old_way (abfd, ".text");
              new->flags = BSF_GLOBAL;
              new->value = 0x12345;
     
              ptrs[0] = new;
              ptrs[1] = 0;
     
              bfd_set_symtab (abfd, ptrs, 1);
              bfd_close (abfd);
              return 0;
            }
     
            ./makesym
            nm foo
            00012345 A dummy_symbol

Many formats cannot represent arbitrary symbol information; for instance, the a.out object format does not allow an arbitrary number of sections. A symbol pointing to a section which is not one of .text, .data or .bss cannot be described.