[llvm-commits] ELFReader.cpp update - Add support for References.
Michael Spencer
bigcheesegs at gmail.com
Tue Sep 11 11:46:55 PDT 2012
On Tue, Sep 11, 2012 at 11:21 AM, Sid Manning <sidneym at codeaurora.org> wrote:
> On 09/07/12 16:45, Michael Spencer wrote:
>>
>> On Fri, Sep 7, 2012 at 8:41 AM, Sid Manning<sidneym at codeaurora.org>
>> wrote:
>>>
>>>
> ....
>>
>>
>>> + (reinterpret_cast<const Elf_Rela
>>> *>(contents.data()));
>>> +
>>> + // Get rid of the leading .rela so Atoms can use their own
>>> section
>>> + // name to find the relocs.
>>> + sectionName = sectionName.drop_front(5);
>>> +
>>> + auto&ref = RelocationAddendReferences[sectionName];
>>
>>
>> Ref.
>>
>>> + for (unsigned int i=0; i<section->getEntityCount(); i++) {
>>> + ref.push_back(relocs+i);
>>
>>
>> This is still wrong. The offset to use for each relocation entry is based
>> on
>> sh_entsize. See the getRel and getEntry templates in Object/ELF.h. We can
>> expose
>> these, or better yet, proper iterators to them. I dislike duplicating the
>> work
>> of file format parsing.
>>
>
> OK I can push this up to ELF.h by adding a new interface,
> getELFRelaVector(Elf_Shdr *) that returns relocations in a vector. The
> above for loop would be replaced by an assignment like this:
>
> RelocationAddendReferences[SectionName] = Obj->getELFRelaVector(Section);
>
> If this seems reasonable then I will clean things up and post the whole
> patch.
>
> Thanks.
>
>
>
>>
>> - Michael Spencer
>
>
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by
> The Linux Foundation
While this would work, it's not really the best interface as it
requires memory allocation that cannot be controlled by the user. I
believe the interface should be:
unspecified-iterator-type beginELFRel(const Elf_Shdr*) const;
unspecified-iterator-type endELFRel(const Elf_Shdr*) const;
unspecified-iterator-type beginELFRela(const Elf_Shdr*) const;
unspecified-iterator-type endELFRela(const Elf_Shdr*) const;
Where unspecified-iterator-type is a forward iterator with
decltype(*it) of const Elf_Rel{a}&
The iterator just needs to store its current location and the
Elf_Shdr* to use sh_entsize to increment to the next entry.
- Michael Spencer
More information about the llvm-commits
mailing list