uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
void moveSectionNext(DataRefImpl &Sec) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
uint8_t getSymbolOther(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
section_iterator getSymbolSection(const Elf_Sym *Symb) const;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
}
template <class ELFT>
-std::error_code
-ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Result) const {
+SymbolRef::Type ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
switch (ESym->getType()) {
case ELF::STT_NOTYPE:
- Result = SymbolRef::ST_Unknown;
- break;
+ return SymbolRef::ST_Unknown;
case ELF::STT_SECTION:
- Result = SymbolRef::ST_Debug;
- break;
+ return SymbolRef::ST_Debug;
case ELF::STT_FILE:
- Result = SymbolRef::ST_File;
- break;
+ return SymbolRef::ST_File;
case ELF::STT_FUNC:
- Result = SymbolRef::ST_Function;
- break;
+ return SymbolRef::ST_Function;
case ELF::STT_OBJECT:
case ELF::STT_COMMON:
case ELF::STT_TLS:
- Result = SymbolRef::ST_Data;
- break;
+ return SymbolRef::ST_Data;
default:
- Result = SymbolRef::ST_Other;
- break;
+ return SymbolRef::ST_Other;
}
- return std::error_code();
}
template <class ELFT>
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
/// @brief Get the alignment of this symbol as the actual value (not log 2).
uint32_t getAlignment() const;
uint64_t getCommonSize() const;
- std::error_code getType(SymbolRef::Type &Result) const;
+ SymbolRef::Type getType() const;
/// @brief Get section this symbol is defined in reference to. Result is
/// end_sections() if it is undefined or is an absolute symbol.
virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
- virtual std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const = 0;
+ virtual SymbolRef::Type getSymbolType(DataRefImpl Symb) const = 0;
virtual std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const = 0;
return getObject()->getSymbolSection(getRawDataRefImpl(), Result);
}
-inline std::error_code SymbolRef::getType(SymbolRef::Type &Result) const {
- return getObject()->getSymbolType(getRawDataRefImpl(), Result);
+inline SymbolRef::Type SymbolRef::getType() const {
+ return getObject()->getSymbolType(getRawDataRefImpl());
}
inline const ObjectFile *SymbolRef::getObject() const {
if (IsCommon)
CommonSymbols.push_back(*I);
else {
- object::SymbolRef::Type SymType;
- Check(I->getType(SymType));
+ object::SymbolRef::Type SymType = I->getType();
if (SymType == object::SymbolRef::ST_Function ||
SymType == object::SymbolRef::ST_Data ||
RTDyldSymbolTable::const_iterator gsi = GlobalSymbolTable.end();
if (Symbol != Obj.symbol_end()) {
gsi = GlobalSymbolTable.find(TargetName.data());
- Symbol->getType(SymType);
+ SymType = Symbol->getType();
}
if (gsi != GlobalSymbolTable.end()) {
const auto &SymInfo = gsi->second;
return std::error_code();
}
-std::error_code COFFObjectFile::getSymbolType(DataRefImpl Ref,
- SymbolRef::Type &Result) const {
+SymbolRef::Type COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
int32_t SectionNumber = Symb.getSectionNumber();
- Result = SymbolRef::ST_Other;
-
- if (Symb.isAnyUndefined()) {
- Result = SymbolRef::ST_Unknown;
- } else if (Symb.isFunctionDefinition()) {
- Result = SymbolRef::ST_Function;
- } else if (Symb.isCommon()) {
- Result = SymbolRef::ST_Data;
- } else if (Symb.isFileRecord()) {
- Result = SymbolRef::ST_File;
- } else if (SectionNumber == COFF::IMAGE_SYM_DEBUG ||
- Symb.isSectionDefinition()) {
- // TODO: perhaps we need a new symbol type ST_Section.
- Result = SymbolRef::ST_Debug;
- } else if (!COFF::isReservedSectionNumber(SectionNumber)) {
- const coff_section *Section = nullptr;
- if (std::error_code EC = getSection(SectionNumber, Section))
- return EC;
- uint32_t Characteristics = Section->Characteristics;
- if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
- Result = SymbolRef::ST_Function;
- else if (Characteristics & (COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA))
- Result = SymbolRef::ST_Data;
- }
- return std::error_code();
+
+ if (Symb.isAnyUndefined())
+ return SymbolRef::ST_Unknown;
+ if (Symb.isFunctionDefinition())
+ return SymbolRef::ST_Function;
+ if (Symb.isCommon())
+ return SymbolRef::ST_Data;
+ if (Symb.isFileRecord())
+ return SymbolRef::ST_File;
+
+ // TODO: perhaps we need a new symbol type ST_Section.
+ if (SectionNumber == COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
+ return SymbolRef::ST_Debug;
+
+ if (!COFF::isReservedSectionNumber(SectionNumber))
+ return SymbolRef::ST_Data;
+
+ return SymbolRef::ST_Other;
}
uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
return Value;
}
-std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const {
+SymbolRef::Type MachOObjectFile::getSymbolType(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t n_type = Entry.n_type;
- Res = SymbolRef::ST_Other;
-
// If this is a STAB debugging symbol, we can do nothing more.
- if (n_type & MachO::N_STAB) {
- Res = SymbolRef::ST_Debug;
- return std::error_code();
- }
+ if (n_type & MachO::N_STAB)
+ return SymbolRef::ST_Debug;
switch (n_type & MachO::N_TYPE) {
case MachO::N_UNDF :
- Res = SymbolRef::ST_Unknown;
- break;
+ return SymbolRef::ST_Unknown;
case MachO::N_SECT :
- Res = SymbolRef::ST_Function;
- break;
+ return SymbolRef::ST_Function;
}
- return std::error_code();
+ return SymbolRef::ST_Other;
}
uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
- SymbolRef::Type ST;
- this->getSymbolType(Symb, ST);
+ SymbolRef::Type ST = getSymbolType(Symb);
if (ST == SymbolRef::ST_Unknown)
return false;
const MachOObjectFile &MainBinary = MainBinaryHolder.GetAs<MachOObjectFile>();
section_iterator Section = MainBinary.section_end();
for (const auto &Sym : MainBinary.symbols()) {
- SymbolRef::Type Type;
+ SymbolRef::Type Type = Sym.getType();
// Skip undefined and STAB entries.
- if (Sym.getType(Type) || (Type & SymbolRef::ST_Debug) ||
- (Type & SymbolRef::ST_Unknown))
+ if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
continue;
StringRef Name;
uint64_t Addr;
struct SymbolSorter {
bool operator()(const SymbolRef &A, const SymbolRef &B) {
- SymbolRef::Type AType, BType;
- A.getType(AType);
- B.getType(BType);
+ SymbolRef::Type AType = A.getType();
+ SymbolRef::Type BType = B.getType();
uint64_t AAddr, BAddr;
if (AType != SymbolRef::ST_Function)
SymbolAddressMap *AddrMap) {
// Create a map of symbol addresses to symbol names.
for (const SymbolRef &Symbol : O->symbols()) {
- SymbolRef::Type ST;
- Symbol.getType(ST);
+ SymbolRef::Type ST = Symbol.getType();
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
uint64_t Address;
SymbolAddressMap AddrMap;
bool DisSymNameFound = false;
for (const SymbolRef &Symbol : MachOOF->symbols()) {
- SymbolRef::Type ST;
- Symbol.getType(ST);
+ SymbolRef::Type ST = Symbol.getType();
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
uint64_t Address;
StringRef SymName;
Symbols[SymIdx].getName(SymName);
- SymbolRef::Type ST;
- Symbols[SymIdx].getType(ST);
+ SymbolRef::Type ST = Symbols[SymIdx].getType();
if (ST != SymbolRef::ST_Function)
continue;
uint64_t NextSym = 0;
uint64_t NextSymIdx = SymIdx + 1;
while (Symbols.size() > NextSymIdx) {
- SymbolRef::Type NextSymType;
- Symbols[NextSymIdx].getType(NextSymType);
+ SymbolRef::Type NextSymType = Symbols[NextSymIdx].getType();
if (NextSymType == SymbolRef::ST_Function) {
containsNextSym =
Sections[SectIdx].containsSymbol(Symbols[NextSymIdx]);
}
for (const SymbolRef &Symbol : o->symbols()) {
uint64_t Address;
- SymbolRef::Type Type;
+ SymbolRef::Type Type = Symbol.getType();
uint32_t Flags = Symbol.getFlags();
section_iterator Section = o->section_end();
if (error(Symbol.getAddress(Address)))
continue;
- if (error(Symbol.getType(Type)))
- continue;
if (error(Symbol.getSection(Section)))
continue;
StringRef Name;
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
uint64_t VA, bool FunctionOnly) {
for (const auto &Symbol : COFF.symbols()) {
- if (FunctionOnly) {
- SymbolRef::Type Type;
- if (std::error_code EC = Symbol.getType(Type))
- return EC;
- if (Type != SymbolRef::ST_Function)
- continue;
- }
+ if (FunctionOnly && Symbol.getType() != SymbolRef::ST_Function)
+ continue;
uint64_t Address;
if (std::error_code EC = Symbol.getAddress(Address))
// Use symbol info to iterate functions in the object.
for (const auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
- object::SymbolRef::Type SymType;
- if (Sym.getType(SymType))
- continue;
- if (SymType == object::SymbolRef::ST_Function) {
+ if (Sym.getType() == object::SymbolRef::ST_Function) {
StringRef Name;
uint64_t Addr;
if (Sym.getName(Name))
void ModuleInfo::addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
DataExtractor *OpdExtractor, uint64_t OpdAddress) {
- SymbolRef::Type SymbolType;
- if (error(Symbol.getType(SymbolType)))
- return;
+ SymbolRef::Type SymbolType = Symbol.getType();
if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
return;
uint64_t SymbolAddress;