diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-24 19:11:10 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-24 19:11:10 +0000 |
commit | 991af666f1520359175f1ca0e0fb4dbc6161ce73 (patch) | |
tree | d47c6312bf13fb9df1231db4d8a57d5f54480976 /llvm/lib/Object/COFFObjectFile.cpp | |
parent | 5815b1fd56ad91501c3ea83f897fc0e19676acdc (diff) | |
download | llvm-991af666f1520359175f1ca0e0fb4dbc6161ce73.zip llvm-991af666f1520359175f1ca0e0fb4dbc6161ce73.tar.gz llvm-991af666f1520359175f1ca0e0fb4dbc6161ce73.tar.bz2 |
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.
llvm-svn: 240569
Diffstat (limited to 'llvm/lib/Object/COFFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index c497b13..07f9d6e 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -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(); } |