This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

"Create a symbol table"


Hi

  I was trying to create a symbol table at the linking time. Here
is what I did:
___________________________________________________________________
#define MY_OBJ          "foo_obj.o"
#define MY_SEC          "foo_sec"
#define SectionFlags    (SEC_HAS_CONTENTS|SEC_ALLOC|SEC_LOAD|SEC_KEEP)
#define SectionSize     4

static bfd *create_dummy_bfd()
{
   bfd       *abfd;
   asection  *sec;

   { // Create a bfd
     abfd = bfd_openw(MY_OBJ, "elf32-osp192");
     bfd_set_format(abfd, bfd_object);
   }

   { // Create a section
     char *sec_mem;
     sec = bfd_make_section_old_way(abfd, MY_SEC);
     if (!bfd_set_section_flags(abfd, sec, SectionFlags))
       abort();
     if (!bfd_set_section_size(abfd, sec, SectionSize))
       abort();
     if (!bfd_set_section_alignment (abfd, sec, 2))
       abort();

     sec_mem = (char *) xmalloc(SectionSize);
     *((int *) sec_mem) = 0x1234;

     if (!bfd_set_section_contents(abfd, sec, sec_mem, 0, SectionSize))
        abort();

   }

   { //* Create a symbol

     asymbol   **symtab, *new;
     symtab  = (asymbol **) xmalloc(2*sizeof(asymbol *));
     new = bfd_make_empty_symbol(abfd);
     new->name  = "foo_symbol";
     new->flags = BSF_GLOBAL | BSF_DEBUGGING;
     new->value = 0xFFFF;
     new->section = sec;
     symtab[0]  = new;
     symtab[1]  = NULL;
     if (!bfd_set_symtab(abfd, symtab, 1))
       abort();
   }

   if (!bfd_close(abfd))
      abort();
__________________________________________________________________

  Basically the symbol table has only one symbol, "foo_symbol".
However, once using `objdump' to dump the symbol table, it says
no symbols.

__________________________________________
>./objdump -t foo_obj.o

foo_obj.o:     file format elf32-little

./objdump: foo_obj.o: no symbols
_______________________________________

 What did go wrong?

Thanks


-- 
Dr. Xinan Tang                    Member of Technical Staff
EMail: xinant@cognigine.com  	  Cognigine Corp.
Voice: 510.743.4930               6120 Stevenson Boulevard
Fax:   510.743.4910               Fremont, CA  94538


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]