This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
create relocation entry from scratch
- From: peter matula <xmatul01 at stud dot fit dot vutbr dot cz>
- To: binutils at sourceware dot org
- Date: Thu, 15 Jul 2010 14:19:11 +0200
- Subject: create relocation entry from scratch
Hello,
I'm using BFD to transform our internal binary format to ELF. I have
already successfully made transformation of executable files which can
be described like this:
CreateBfd(); // create BFD file
GetArch(); // convert arch and mach info from our format to BFD
CreateSections(); // create sections in BFD
GetSymtab(); // create and fill symbol table
GetSectionData(); // copy data from out format to BFD
CloeBfd(); // write and close BFD
Now i would like to add relocation conversion. Until now everything went
well but i stuck on this. When should I add relocations ? During section
creation in CreateSections(), after GetSymTab() or somewhen else ?
And how should i create relocation entry from scratch ? I found few
examples like this:
relpp = (arelent **) xmalloc(get_reloc_upper_bound(ibfd, isec));
relcount = bfd_canonicalize_reloc(ibfd, isec, relpp, sympp);
bfd_set_reloc(obfd, osec, relpp, relcount);
But I can not use bfd_canonicalize_reloc() to get info from out format
and I have to fill each reloc entry manually. Is this the right way or
should I use something like this:
arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd,
sizeof(arelent_chain));
...
rel_section->constructor_chain = reloc;
Problem is, there is not function bfd_alloc() in my bfd.h and I did not
find it in latest binutils either. What happend to it ?
Thanks for advices.
Peter Matula