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: create relocation entry from scratch


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


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