* create relocation entry from scratch
@ 2010-07-15 12:19 peter matula
2010-07-15 13:29 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: peter matula @ 2010-07-15 12:19 UTC (permalink / raw)
To: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: create relocation entry from scratch
2010-07-15 12:19 create relocation entry from scratch peter matula
@ 2010-07-15 13:29 ` Ian Lance Taylor
2010-07-15 14:16 ` peter matula
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2010-07-15 13:29 UTC (permalink / raw)
To: peter matula; +Cc: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: create relocation entry from scratch
2010-07-15 13:29 ` Ian Lance Taylor
@ 2010-07-15 14:16 ` peter matula
0 siblings, 0 replies; 3+ messages in thread
From: peter matula @ 2010-07-15 14:16 UTC (permalink / raw)
To: binutils
On 15.07.2010 15:28, Ian Lance Taylor wrote:
>> 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.
>
> Ian
Alright, thanks. But when should I create relocations ? During section
creating or later when there will be symbol table ?
Peter Matula
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-15 14:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-15 12:19 create relocation entry from scratch peter matula
2010-07-15 13:29 ` Ian Lance Taylor
2010-07-15 14:16 ` peter matula
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).