uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const { COFFSymbolRef Symb = getCOFFSymbol(Ref); uint32_t Result = SymbolRef::SF_None; if (Symb.isExternal() || Symb.isWeakExternal()) Result |= SymbolRef::SF_Global; if (Symb.isWeakExternal()) Result |= SymbolRef::SF_Weak; if (Symb.getSectionNumber() == COFF::IMAGE_SYM_ABSOLUTE) Result |= SymbolRef::SF_Absolute; if (Symb.isFileRecord()) Result |= SymbolRef::SF_FormatSpecific; if (Symb.isSectionDefinition()) Result |= SymbolRef::SF_FormatSpecific; if (Symb.isCommon()) Result |= SymbolRef::SF_Common; if (Symb.isAnyUndefined()) Result |= SymbolRef::SF_Undefined; return Result; }
ErrorOr<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const { uint64_t Result = getSymbolValue(Ref); COFFSymbolRef Symb = getCOFFSymbol(Ref); int32_t SectionNumber = Symb.getSectionNumber(); if (Symb.isAnyUndefined() || Symb.isCommon() || COFF::isReservedSectionNumber(SectionNumber)) return Result; const coff_section *Section = nullptr; if (std::error_code EC = getSection(SectionNumber, Section)) return EC; Result += Section->VirtualAddress; // The section VirtualAddress does not include ImageBase, and we want to // return virtual addresses. Result += getImageBase(); return Result; }
ErrorOr<SymbolRef::Type> COFFObjectFile::getSymbolType(DataRefImpl Ref) const { COFFSymbolRef Symb = getCOFFSymbol(Ref); int32_t SectionNumber = Symb.getSectionNumber(); if (Symb.getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION) return SymbolRef::ST_Function; if (Symb.isAnyUndefined()) return SymbolRef::ST_Unknown; 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; }