diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 24 | ||||
| -rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 17 |
2 files changed, 24 insertions, 17 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index c497b13ac01..07f9d6ed232 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(); } diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index d33a64fb23f..cb98f05bfcc 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -370,14 +370,17 @@ std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb, return std::error_code(); } -std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb, - uint64_t &Res) const { - uint64_t NValue = getNValue(Symb); - MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb); +uint64_t MachOObjectFile::getSymbolValue(DataRefImpl Sym) const { + uint64_t NValue = getNValue(Sym); + MachO::nlist_base Entry = getSymbolTableEntryBase(this, Sym); if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF && NValue == 0) - Res = UnknownAddress; - else - Res = NValue; + return UnknownAddress; + return NValue; +} + +std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Sym, + uint64_t &Res) const { + Res = getSymbolValue(Sym); return std::error_code(); } |

