This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: objcopy - redefine dynamic symbols


Nick Clifton wrote:
> [...]
> Read the ELF spec.  Work out what you are going to have to do in order
> to rename the symbols.  

OK, I already have done that and I now understand how the result should
look like. It's rather a matter of "how can I do that by using as much
as possible from BFD ?".

> Have a look at the code in bfd/elfcode.h.  You
> will find functions here that work with the dynamic symbol table.  You
> may be able to use them, or you may have to modify them to allow you to
> do what you need to do. 

You think about elf_swap_dyn_in/out? I can find nice functions for
reading dynamic symbols, but nothing for creating/writing. Where is the
opposite of "elf_slurp_symbol_table" ?

> Also look at the code in binutils/objcopy.c and
> see how it renames ordinary symbols.

I started to implement a bit in objcopy, in the copy_object function,
before the call to bfd_set_symtab. I tried to imitate what is already
done with normal symbols, like this:
----------
{
  long dynsymsize;
  long dynsymcount;
  asymbol **idynsympp = NULL;
  asymbol **odynsympp = NULL;

  dynsymsize = bfd_get_dynamic_symtab_upper_bound (ibfd);
  idynsympp = xmalloc (dynsymsize);
  dynsymcount = bfd_canonicalize_dynamic_symtab (ibfd, idynsympp);

  odynsympp = xmalloc ((dynsymcount + 1) * sizeof (asymbol *));
  dynsymcount = filter_symbols (ibfd, obfd, odynsympp,
                                 idynsympp, dynsymcount);
  /* ... ? */
}
----------
(omitted error handling / debug printfs)

I added some printf to the filter_symbols function and I can see that my
symbol(s) are successfully renamed during this process, so I guess that
I now have what I want, but only in the internal representation of
objcopy/bfd.

But what now? Nothing of that appears in the output file. So how can I
achieve this? There seems to be nothing like "bfd_set_dynamic_symtab" as
the dynamic counterpart of bfd_set_symtab!?

Thomas


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