This is an archive of the discontinued LLVM Phabricator instance.

Add support for handling absolute symbols in ELF
ClosedPublic

Authored by tberghammer on Feb 19 2016, 8:17 AM.

Details

Summary

Add support for handling absolute symbols in ELF

Most address represented in lldb as section plus offset and handling of
absolute addresses is problematic in several location because of lack
of necessary information (e.g. Target) or because of performance issues.

This CL change the way ObjectFileELF handle the absolute symbols with
creating a pseudo section for each symbol. With this change all existing
code designed to work with addresses in the form of section plus offset
will work with absolute symbols as well.

Diff Detail

Event Timeline

tberghammer retitled this revision from to Add support for handling absolute symbols in ELF.
tberghammer updated this object.
tberghammer added reviewers: ovyalov, clayborg.
tberghammer added a subscriber: lldb-commits.
clayborg requested changes to this revision.Feb 19 2016, 1:51 PM
clayborg edited edge metadata.

We should probably make it such that if a section has the type eSectionTypeAbsoluteAddress that we do the right thing inside the following functions:

Section::GetLoadBaseAddress(...);
Section::Slide(...);

SectionLoadList::SetSectionLoadAddress(...);
SectionLoadList::GetSectionLoadAddress(...);
SectionLoadList::SetSectionUnloaded(...);
SectionLoadList::ResolveLoadAddress(...);

source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
2092

This variable has a really bad name. We should change "symbol_idx" to "section_idx" and make this const:

const Elf64_Half section_idx = symbol.st_shndx;
2291

Shouldn't this just be:

if (!symbol_section_sp && symbol.st_shndx != SHN_UNDEF  && symbol.st_size != 0)

We need to know if a symbol has an address and it only has an address if symbol.st_shndx != SHN_UNDEF. All other section types mean that the symbol actually has an address

This revision now requires changes to proceed.Feb 19 2016, 1:51 PM
tberghammer edited edge metadata.
tberghammer marked an inline comment as done.

We should probably make it such that if a section has the type eSectionTypeAbsoluteAddress that we do the right thing inside the following functions:
Section::GetLoadBaseAddress(...);
Section::Slide(...);
SectionLoadList::SetSectionLoadAddress(...);
SectionLoadList::GetSectionLoadAddress(...);
SectionLoadList::SetSectionUnloaded(...);
SectionLoadList::ResolveLoadAddress(...);

I don't think any of these function should behave differently for absolute sections. For example calling SetSectionLoadAddress on an absolute section wouldn't make too much sense but I think they should still behave the same way and the caller of them have to make sure they are not called with incorrect values (see ObjectFileELF.cpp:931). For any other function you mentioned the type of the section shouldn't matter at all. We can possibly add some assert to some of these functions to verify they are not called in incorrect scenarios but I am not sure it is a good idea (changing a soft failure to a crash)

source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
2092

Done

2291

I agree that my original condition is wrong but I think it should be the following because we want to create a virtual section for absolute symbols only:

if (symbol_section_sp == nullptr && symbol.st_shndx == SHN_ABS && symbol.st_size != 0)
clayborg accepted this revision.Feb 24 2016, 9:49 AM
clayborg edited edge metadata.
This revision is now accepted and ready to land.Feb 24 2016, 9:49 AM
This revision was automatically updated to reflect the committed changes.