This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: create relocation entry from scratch
- From: Ian Lance Taylor <iant at google dot com>
- To: peter matula <xmatul01 at stud dot fit dot vutbr dot cz>
- Cc: binutils at sourceware dot org
- Date: Thu, 15 Jul 2010 06:28:50 -0700
- Subject: Re: create relocation entry from scratch
- References: <4C3EFCBF.8050503@stud.fit.vutbr.cz>
peter matula <xmatul01@stud.fit.vutbr.cz> writes:
> 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.
In the general case, this is impossible. However, it can be done if all
of the relocations in your internal format can be represented in ELF.
> 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.
This is the right way. Yes, you have to fill in each 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;
That is really just another way of doing the first one. Don't use it.
> 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 ?
bfd_alloc is an internal function declared in libbfd.h. You don't need
to use it.
Ian