Add a SymbolRef::getValue.

This returns either the symbol offset or address. Since it is not defined which
one, it never has to lookup the section and so never fails.

I will add users in the next commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240569 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-06-24 19:11:10 +00:00
parent 234c5890e7
commit 9fa0ab3335
6 changed files with 59 additions and 27 deletions

View File

@ -150,25 +150,29 @@ std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
return getSymbolName(Symb, Result);
}
uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
COFFSymbolRef Sym = getCOFFSymbol(Ref);
if (Sym.isAnyUndefined() || Sym.isCommon())
return UnknownAddress;
return Sym.getValue();
}
std::error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref,
uint64_t &Result) const {
Result = getSymbolValue(Ref);
COFFSymbolRef Symb = getCOFFSymbol(Ref);
if (Symb.isAnyUndefined() || Symb.isCommon()) {
Result = UnknownAddress;
return std::error_code();
}
int32_t SectionNumber = Symb.getSectionNumber();
if (COFF::isReservedSectionNumber(SectionNumber)) {
Result = Symb.getValue();
if (Symb.isAnyUndefined() || Symb.isCommon() ||
COFF::isReservedSectionNumber(SectionNumber))
return std::error_code();
}
const coff_section *Section = nullptr;
if (std::error_code EC = getSection(SectionNumber, Section))
return EC;
Result = Section->VirtualAddress + Symb.getValue();
Result += Section->VirtualAddress;
return std::error_code();
}