1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> getSymbolFlags().

This change enables getSymbolFlags() to return errors which benefit error reporting in clients.

Differential Revision: https://reviews.llvm.org/D77860
This commit is contained in:
vgxbj 2020-04-10 20:24:21 +08:00
parent 79fde5bd66
commit bbdc25ab11
30 changed files with 185 additions and 81 deletions

View File

@ -304,8 +304,15 @@ private:
private: private:
void buildInitialSymbolTable(const OwnedObject &Obj) { void buildInitialSymbolTable(const OwnedObject &Obj) {
for (auto &Symbol : Obj.getBinary()->symbols()) { for (auto &Symbol : Obj.getBinary()->symbols()) {
if (Symbol.getFlags() & object::SymbolRef::SF_Undefined) if (Expected<uint32_t> SymbolFlagsOrErr = Symbol.getFlags()) {
if (*SymbolFlagsOrErr & object::SymbolRef::SF_Undefined)
continue;
} else {
// FIXME: Raise an error for bad symbols.
consumeError(SymbolFlagsOrErr.takeError());
continue; continue;
}
Expected<StringRef> SymbolName = Symbol.getName(); Expected<StringRef> SymbolName = Symbol.getName();
// FIXME: Raise an error for bad symbols. // FIXME: Raise an error for bad symbols.
if (!SymbolName) { if (!SymbolName) {

View File

@ -896,7 +896,7 @@ protected:
uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
void moveSectionNext(DataRefImpl &Sec) const override; void moveSectionNext(DataRefImpl &Sec) const override;

View File

@ -43,7 +43,7 @@ public:
return Error::success(); return Error::success();
} }
uint32_t getSymbolFlags(DataRefImpl Symb) const override { Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override {
return SymbolRef::SF_Global; return SymbolRef::SF_Global;
} }

View File

@ -261,7 +261,7 @@ protected:
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
uint8_t getSymbolBinding(DataRefImpl Symb) const override; uint8_t getSymbolBinding(DataRefImpl Symb) const override;
uint8_t getSymbolOther(DataRefImpl Symb) const override; uint8_t getSymbolOther(DataRefImpl Symb) const override;
uint8_t getSymbolELFType(DataRefImpl Symb) const override; uint8_t getSymbolELFType(DataRefImpl Symb) const override;
@ -609,7 +609,7 @@ ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const {
} }
template <class ELFT> template <class ELFT>
uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const { Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
const Elf_Sym *ESym = getSymbol(Sym); const Elf_Sym *ESym = getSymbol(Sym);
uint32_t Result = SymbolRef::SF_None; uint32_t Result = SymbolRef::SF_None;
@ -626,12 +626,23 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION) if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
Result |= SymbolRef::SF_FormatSpecific; Result |= SymbolRef::SF_FormatSpecific;
auto DotSymtabSecSyms = EF.symbols(DotSymtabSec); if (Expected<typename ELFT::SymRange> SymbolsOrErr =
if (DotSymtabSecSyms && ESym == (*DotSymtabSecSyms).begin()) EF.symbols(DotSymtabSec)) {
Result |= SymbolRef::SF_FormatSpecific; // Set the SF_FormatSpecific flag for the 0-index null symbol.
auto DotDynSymSecSyms = EF.symbols(DotDynSymSec); if (ESym == SymbolsOrErr->begin())
if (DotDynSymSecSyms && ESym == (*DotDynSymSecSyms).begin()) Result |= SymbolRef::SF_FormatSpecific;
Result |= SymbolRef::SF_FormatSpecific; } else
// TODO: Test this error.
return SymbolsOrErr.takeError();
if (Expected<typename ELFT::SymRange> SymbolsOrErr =
EF.symbols(DotDynSymSec)) {
// Set the SF_FormatSpecific flag for the 0-index null symbol.
if (ESym == SymbolsOrErr->begin())
Result |= SymbolRef::SF_FormatSpecific;
} else
// TODO: Test this error.
return SymbolsOrErr.takeError();
if (EF.getHeader()->e_machine == ELF::EM_ARM) { if (EF.getHeader()->e_machine == ELF::EM_ARM) {
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) { if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {

View File

@ -38,7 +38,7 @@ public:
~IRObjectFile() override; ~IRObjectFile() override;
void moveSymbolNext(DataRefImpl &Symb) const override; void moveSymbolNext(DataRefImpl &Symb) const override;
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override; Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
basic_symbol_iterator symbol_begin() const override; basic_symbol_iterator symbol_begin() const override;
basic_symbol_iterator symbol_end() const override; basic_symbol_iterator symbol_end() const override;

View File

@ -287,7 +287,7 @@ public:
uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
unsigned getSymbolSectionID(SymbolRef Symb) const; unsigned getSymbolSectionID(SymbolRef Symb) const;
unsigned getSectionID(SectionRef Sec) const; unsigned getSectionID(SectionRef Sec) const;

View File

@ -296,7 +296,11 @@ public:
ObjectFile(const ObjectFile &other) = delete; ObjectFile(const ObjectFile &other) = delete;
uint64_t getCommonSymbolSize(DataRefImpl Symb) const { uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
assert(getSymbolFlags(Symb) & SymbolRef::SF_Common); Expected<uint32_t> SymbolFlagsOrErr = getSymbolFlags(Symb);
if (!SymbolFlagsOrErr)
// TODO: Actually report errors helpfully.
report_fatal_error(SymbolFlagsOrErr.takeError());
assert(*SymbolFlagsOrErr & SymbolRef::SF_Common);
return getCommonSymbolSizeImpl(Symb); return getCommonSymbolSizeImpl(Symb);
} }

View File

@ -129,7 +129,7 @@ public:
Error printName(raw_ostream &OS) const; Error printName(raw_ostream &OS) const;
/// Get symbol flags (bitwise OR of SymbolRef::Flags) /// Get symbol flags (bitwise OR of SymbolRef::Flags)
uint32_t getFlags() const; Expected<uint32_t> getFlags() const;
DataRefImpl getRawDataRefImpl() const; DataRefImpl getRawDataRefImpl() const;
const SymbolicFile *getObject() const; const SymbolicFile *getObject() const;
@ -147,7 +147,7 @@ public:
virtual Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const = 0; virtual Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolFlags(DataRefImpl Symb) const = 0; virtual Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const = 0;
virtual basic_symbol_iterator symbol_begin() const = 0; virtual basic_symbol_iterator symbol_begin() const = 0;
@ -196,7 +196,7 @@ inline Error BasicSymbolRef::printName(raw_ostream &OS) const {
return OwningObject->printSymbolName(OS, SymbolPimpl); return OwningObject->printSymbolName(OS, SymbolPimpl);
} }
inline uint32_t BasicSymbolRef::getFlags() const { inline Expected<uint32_t> BasicSymbolRef::getFlags() const {
return OwningObject->getSymbolFlags(SymbolPimpl); return OwningObject->getSymbolFlags(SymbolPimpl);
} }

View File

@ -33,7 +33,7 @@ public:
Error printSymbolName(raw_ostream &OS, DataRefImpl DRI) const override; Error printSymbolName(raw_ostream &OS, DataRefImpl DRI) const override;
uint32_t getSymbolFlags(DataRefImpl DRI) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl DRI) const override;
basic_symbol_iterator symbol_begin() const override; basic_symbol_iterator symbol_begin() const override;

View File

@ -154,7 +154,7 @@ public:
uint32_t getNumSections() const { return Sections.size(); } uint32_t getNumSections() const { return Sections.size(); }
void moveSymbolNext(DataRefImpl &Symb) const override; void moveSymbolNext(DataRefImpl &Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
basic_symbol_iterator symbol_begin() const override; basic_symbol_iterator symbol_begin() const override;

View File

@ -268,7 +268,7 @@ public:
// Interface inherited from base classes. // Interface inherited from base classes.
void moveSymbolNext(DataRefImpl &Symb) const override; void moveSymbolNext(DataRefImpl &Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
basic_symbol_iterator symbol_begin() const override; basic_symbol_iterator symbol_begin() const override;
basic_symbol_iterator symbol_end() const override; basic_symbol_iterator symbol_end() const override;

View File

@ -93,12 +93,17 @@ getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
SymbolFlagsMap SymbolFlags; SymbolFlagsMap SymbolFlags;
for (auto &Sym : (*Obj)->symbols()) { for (auto &Sym : (*Obj)->symbols()) {
Expected<uint32_t> SymFlagsOrErr = Sym.getFlags();
if (!SymFlagsOrErr)
// TODO: Test this error.
return SymFlagsOrErr.takeError();
// Skip symbols not defined in this object file. // Skip symbols not defined in this object file.
if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined) if (*SymFlagsOrErr & object::BasicSymbolRef::SF_Undefined)
continue; continue;
// Skip symbols that are not global. // Skip symbols that are not global.
if (!(Sym.getFlags() & object::BasicSymbolRef::SF_Global)) if (!(*SymFlagsOrErr & object::BasicSymbolRef::SF_Global))
continue; continue;
// Skip symbols that have type SF_File. // Skip symbols that have type SF_File.

View File

@ -125,8 +125,16 @@ void RTDyldObjectLinkingLayer::emit(MaterializationResponsibility R,
return; return;
} }
Expected<uint32_t> SymFlagsOrErr = Sym.getFlags();
if (!SymFlagsOrErr) {
// TODO: Test this error.
ES.reportError(SymFlagsOrErr.takeError());
R.failMaterialization();
return;
}
// Don't include symbols that aren't global. // Don't include symbols that aren't global.
if (!(Sym.getFlags() & object::BasicSymbolRef::SF_Global)) { if (!(*SymFlagsOrErr & object::BasicSymbolRef::SF_Global)) {
if (auto SymName = Sym.getName()) if (auto SymName = Sym.getName())
InternalSymbols->insert(*SymName); InternalSymbols->insert(*SymName);
else { else {
@ -200,7 +208,9 @@ Error RTDyldObjectLinkingLayer::onObjLoad(
// check whether the symbol is in a comdat section and if so mark it as // check whether the symbol is in a comdat section and if so mark it as
// weak. // weak.
for (auto &Sym : COFFObj->symbols()) { for (auto &Sym : COFFObj->symbols()) {
if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined) // getFlags() on COFF symbols can't fail.
uint32_t SymFlags = cantFail(Sym.getFlags());
if (SymFlags & object::BasicSymbolRef::SF_Undefined)
continue; continue;
auto Name = Sym.getName(); auto Name = Sym.getName();
if (!Name) if (!Name)

View File

@ -55,12 +55,17 @@ JITSymbolFlags llvm::JITSymbolFlags::fromSummary(GlobalValueSummary *S) {
Expected<JITSymbolFlags> Expected<JITSymbolFlags>
llvm::JITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) { llvm::JITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) {
Expected<uint32_t> SymbolFlagsOrErr = Symbol.getFlags();
if (!SymbolFlagsOrErr)
// TODO: Test this error.
return SymbolFlagsOrErr.takeError();
JITSymbolFlags Flags = JITSymbolFlags::None; JITSymbolFlags Flags = JITSymbolFlags::None;
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak) if (*SymbolFlagsOrErr & object::BasicSymbolRef::SF_Weak)
Flags |= JITSymbolFlags::Weak; Flags |= JITSymbolFlags::Weak;
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Common) if (*SymbolFlagsOrErr & object::BasicSymbolRef::SF_Common)
Flags |= JITSymbolFlags::Common; Flags |= JITSymbolFlags::Common;
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported) if (*SymbolFlagsOrErr & object::BasicSymbolRef::SF_Exported)
Flags |= JITSymbolFlags::Exported; Flags |= JITSymbolFlags::Exported;
auto SymbolType = Symbol.getType(); auto SymbolType = Symbol.getType();
@ -75,8 +80,12 @@ llvm::JITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) {
ARMJITSymbolFlags ARMJITSymbolFlags
llvm::ARMJITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) { llvm::ARMJITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) {
Expected<uint32_t> SymbolFlagsOrErr = Symbol.getFlags();
if (!SymbolFlagsOrErr)
// TODO: Actually report errors helpfully.
report_fatal_error(SymbolFlagsOrErr.takeError());
ARMJITSymbolFlags Flags; ARMJITSymbolFlags Flags;
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Thumb) if (*SymbolFlagsOrErr & object::BasicSymbolRef::SF_Thumb)
Flags |= ARMJITSymbolFlags::Thumb; Flags |= ARMJITSymbolFlags::Thumb;
return Flags; return Flags;
} }

View File

@ -214,8 +214,12 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
{ {
JITSymbolResolver::LookupSet Symbols; JITSymbolResolver::LookupSet Symbols;
for (auto &Sym : Obj.symbols()) { for (auto &Sym : Obj.symbols()) {
uint32_t Flags = Sym.getFlags(); Expected<uint32_t> FlagsOrErr = Sym.getFlags();
if ((Flags & SymbolRef::SF_Common) || (Flags & SymbolRef::SF_Weak)) { if (!FlagsOrErr)
// TODO: Test this error.
return FlagsOrErr.takeError();
if ((*FlagsOrErr & SymbolRef::SF_Common) ||
(*FlagsOrErr & SymbolRef::SF_Weak)) {
// Get symbol name. // Get symbol name.
if (auto NameOrErr = Sym.getName()) if (auto NameOrErr = Sym.getName())
Symbols.insert(*NameOrErr); Symbols.insert(*NameOrErr);
@ -234,10 +238,13 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
LLVM_DEBUG(dbgs() << "Parse symbols:\n"); LLVM_DEBUG(dbgs() << "Parse symbols:\n");
for (symbol_iterator I = Obj.symbol_begin(), E = Obj.symbol_end(); I != E; for (symbol_iterator I = Obj.symbol_begin(), E = Obj.symbol_end(); I != E;
++I) { ++I) {
uint32_t Flags = I->getFlags(); Expected<uint32_t> FlagsOrErr = I->getFlags();
if (!FlagsOrErr)
// TODO: Test this error.
return FlagsOrErr.takeError();
// Skip undefined symbols. // Skip undefined symbols.
if (Flags & SymbolRef::SF_Undefined) if (*FlagsOrErr & SymbolRef::SF_Undefined)
continue; continue;
// Get the symbol type. // Get the symbol type.
@ -287,7 +294,7 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
} }
} }
if (Flags & SymbolRef::SF_Absolute && if (*FlagsOrErr & SymbolRef::SF_Absolute &&
SymType != object::SymbolRef::ST_File) { SymType != object::SymbolRef::ST_File) {
uint64_t Addr = 0; uint64_t Addr = 0;
if (auto AddrOrErr = I->getAddress()) if (auto AddrOrErr = I->getAddress())
@ -300,7 +307,7 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
LLVM_DEBUG(dbgs() << "\tType: " << SymType << " (absolute) Name: " << Name LLVM_DEBUG(dbgs() << "\tType: " << SymType << " (absolute) Name: " << Name
<< " SID: " << SectionID << " SID: " << SectionID
<< " Offset: " << format("%p", (uintptr_t)Addr) << " Offset: " << format("%p", (uintptr_t)Addr)
<< " flags: " << Flags << "\n"); << " flags: " << *FlagsOrErr << "\n");
GlobalSymbolTable[Name] = SymbolTableEntry(SectionID, Addr, *JITSymFlags); GlobalSymbolTable[Name] = SymbolTableEntry(SectionID, Addr, *JITSymFlags);
} else if (SymType == object::SymbolRef::ST_Function || } else if (SymType == object::SymbolRef::ST_Function ||
SymType == object::SymbolRef::ST_Data || SymType == object::SymbolRef::ST_Data ||
@ -332,7 +339,7 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
LLVM_DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name LLVM_DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name
<< " SID: " << SectionID << " SID: " << SectionID
<< " Offset: " << format("%p", (uintptr_t)SectOffset) << " Offset: " << format("%p", (uintptr_t)SectOffset)
<< " flags: " << Flags << "\n"); << " flags: " << *FlagsOrErr << "\n");
GlobalSymbolTable[Name] = GlobalSymbolTable[Name] =
SymbolTableEntry(SectionID, SectOffset, *JITSymFlags); SymbolTableEntry(SectionID, SectOffset, *JITSymFlags);
} }
@ -592,8 +599,11 @@ Error RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj,
uint32_t CommonAlign = 1; uint32_t CommonAlign = 1;
for (symbol_iterator I = Obj.symbol_begin(), E = Obj.symbol_end(); I != E; for (symbol_iterator I = Obj.symbol_begin(), E = Obj.symbol_end(); I != E;
++I) { ++I) {
uint32_t Flags = I->getFlags(); Expected<uint32_t> FlagsOrErr = I->getFlags();
if (Flags & SymbolRef::SF_Common) { if (!FlagsOrErr)
// TODO: Test this error.
return FlagsOrErr.takeError();
if (*FlagsOrErr & SymbolRef::SF_Common) {
// Add the common symbols to a list. We'll allocate them all below. // Add the common symbols to a list. We'll allocate them all below.
uint64_t Size = I->getCommonSize(); uint64_t Size = I->getCommonSize();
uint32_t Align = I->getAlignment(); uint32_t Align = I->getAlignment();

View File

@ -264,12 +264,15 @@ static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
} }
static bool isArchiveSymbol(const object::BasicSymbolRef &S) { static bool isArchiveSymbol(const object::BasicSymbolRef &S) {
uint32_t Symflags = S.getFlags(); Expected<uint32_t> SymFlagsOrErr = S.getFlags();
if (Symflags & object::SymbolRef::SF_FormatSpecific) if (!SymFlagsOrErr)
// TODO: Actually report errors helpfully.
report_fatal_error(SymFlagsOrErr.takeError());
if (*SymFlagsOrErr & object::SymbolRef::SF_FormatSpecific)
return false; return false;
if (!(Symflags & object::SymbolRef::SF_Global)) if (!(*SymFlagsOrErr & object::SymbolRef::SF_Global))
return false; return false;
if (Symflags & object::SymbolRef::SF_Undefined) if (*SymFlagsOrErr & object::SymbolRef::SF_Undefined)
return false; return false;
return true; return true;
} }

View File

@ -209,7 +209,7 @@ Expected<SymbolRef::Type> COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
return SymbolRef::ST_Other; return SymbolRef::ST_Other;
} }
uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const { Expected<uint32_t> COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref); COFFSymbolRef Symb = getCOFFSymbol(Ref);
uint32_t Result = SymbolRef::SF_None; uint32_t Result = SymbolRef::SF_None;

View File

@ -47,7 +47,7 @@ Error IRObjectFile::printSymbolName(raw_ostream &OS, DataRefImpl Symb) const {
return Error::success(); return Error::success();
} }
uint32_t IRObjectFile::getSymbolFlags(DataRefImpl Symb) const { Expected<uint32_t> IRObjectFile::getSymbolFlags(DataRefImpl Symb) const {
return SymTab.getSymbolFlags(getSym(Symb)); return SymTab.getSymbolFlags(getSym(Symb));
} }

View File

@ -1804,8 +1804,8 @@ Expected<uint64_t> MachOObjectFile::getSymbolAddress(DataRefImpl Sym) const {
} }
uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const { uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
uint32_t flags = getSymbolFlags(DRI); uint32_t Flags = cantFail(getSymbolFlags(DRI));
if (flags & SymbolRef::SF_Common) { if (Flags & SymbolRef::SF_Common) {
MachO::nlist_base Entry = getSymbolTableEntryBase(*this, DRI); MachO::nlist_base Entry = getSymbolTableEntryBase(*this, DRI);
return 1 << MachO::GET_COMM_ALIGN(Entry.n_desc); return 1 << MachO::GET_COMM_ALIGN(Entry.n_desc);
} }
@ -1840,7 +1840,7 @@ MachOObjectFile::getSymbolType(DataRefImpl Symb) const {
return SymbolRef::ST_Other; return SymbolRef::ST_Other;
} }
uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const { Expected<uint32_t> MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(*this, DRI); MachO::nlist_base Entry = getSymbolTableEntryBase(*this, DRI);
uint8_t MachOType = Entry.n_type; uint8_t MachOType = Entry.n_type;

View File

@ -55,11 +55,14 @@ bool SectionRef::containsSymbol(SymbolRef S) const {
} }
uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const { uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const {
uint32_t Flags = getSymbolFlags(Ref); if (Expected<uint32_t> FlagsOrErr = getSymbolFlags(Ref)) {
if (Flags & SymbolRef::SF_Undefined) if (*FlagsOrErr & SymbolRef::SF_Undefined)
return 0; return 0;
if (Flags & SymbolRef::SF_Common) if (*FlagsOrErr & SymbolRef::SF_Common)
return getCommonSymbolSize(Ref); return getCommonSymbolSize(Ref);
} else
// TODO: Actually report errors helpfully.
report_fatal_error(FlagsOrErr.takeError());
return getSymbolValueImpl(Ref); return getSymbolValueImpl(Ref);
} }

View File

@ -86,7 +86,7 @@ Error TapiFile::printSymbolName(raw_ostream &OS, DataRefImpl DRI) const {
return Error::success(); return Error::success();
} }
uint32_t TapiFile::getSymbolFlags(DataRefImpl DRI) const { Expected<uint32_t> TapiFile::getSymbolFlags(DataRefImpl DRI) const {
const auto *Sym = reinterpret_cast<const Symbol *>(DRI.p); const auto *Sym = reinterpret_cast<const Symbol *>(DRI.p);
return Sym->Flags; return Sym->Flags;
} }

View File

@ -1266,7 +1266,7 @@ const wasm::WasmObjectHeader &WasmObjectFile::getHeader() const {
void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.b++; } void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.b++; }
uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const { Expected<uint32_t> WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const {
uint32_t Result = SymbolRef::SF_None; uint32_t Result = SymbolRef::SF_None;
const WasmSymbol &Sym = getWasmSymbol(Symb); const WasmSymbol &Sym = getWasmSymbol(Symb);

View File

@ -392,7 +392,7 @@ void XCOFFObjectFile::getRelocationTypeName(
Result.append(Res.begin(), Res.end()); Result.append(Res.begin(), Res.end());
} }
uint32_t XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const { Expected<uint32_t> XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const {
uint32_t Result = 0; uint32_t Result = 0;
llvm_unreachable("Not yet implemented!"); llvm_unreachable("Not yet implemented!");
return Result; return Result;

View File

@ -256,9 +256,12 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
for (const auto &Sym : Object->symbols()) { for (const auto &Sym : Object->symbols()) {
uint64_t Address = Sym.getValue(); uint64_t Address = Sym.getValue();
Expected<StringRef> Name = Sym.getName(); Expected<StringRef> Name = Sym.getName();
if (!Name || (Sym.getFlags() & Expected<uint32_t> FlagsOrErr = Sym.getFlags();
(SymbolRef::SF_Absolute | SymbolRef::SF_Common))) { if (!Name || !FlagsOrErr ||
(*FlagsOrErr & (SymbolRef::SF_Absolute | SymbolRef::SF_Common))) {
// TODO: Actually report errors helpfully. // TODO: Actually report errors helpfully.
if (!FlagsOrErr)
consumeError(FlagsOrErr.takeError());
if (!Name) if (!Name)
consumeError(Name.takeError()); consumeError(Name.takeError());
continue; continue;

View File

@ -493,7 +493,7 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols(
// relocations will use the symbol itself, and won't need an // relocations will use the symbol itself, and won't need an
// object file address. The object file address field is optional // object file address. The object file address field is optional
// in the DebugMap, leave it unassigned for these symbols. // in the DebugMap, leave it unassigned for these symbols.
uint32_t Flags = Sym.getFlags(); uint32_t Flags = cantFail(Sym.getFlags());
if (Flags & SymbolRef::SF_Absolute) { if (Flags & SymbolRef::SF_Absolute) {
CurrentObjectAddresses[*Name] = None; CurrentObjectAddresses[*Name] = None;
} else if (Flags & SymbolRef::SF_Common) { } else if (Flags & SymbolRef::SF_Common) {

View File

@ -306,13 +306,17 @@ struct NMSymbol {
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) { static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
bool ADefined; bool ADefined;
// Symbol flags have been checked in the caller.
uint32_t AFlags = cantFail(A.Sym.getFlags());
if (A.Sym.getRawDataRefImpl().p) if (A.Sym.getRawDataRefImpl().p)
ADefined = !(A.Sym.getFlags() & SymbolRef::SF_Undefined); ADefined = !(AFlags & SymbolRef::SF_Undefined);
else else
ADefined = A.TypeChar != 'U'; ADefined = A.TypeChar != 'U';
bool BDefined; bool BDefined;
// Symbol flags have been checked in the caller.
uint32_t BFlags = cantFail(B.Sym.getFlags());
if (B.Sym.getRawDataRefImpl().p) if (B.Sym.getRawDataRefImpl().p)
BDefined = !(B.Sym.getFlags() & SymbolRef::SF_Undefined); BDefined = !(BFlags & SymbolRef::SF_Undefined);
else else
BDefined = B.TypeChar != 'U'; BDefined = B.TypeChar != 'U';
return std::make_tuple(ADefined, A.Address, A.Name, A.Size) < return std::make_tuple(ADefined, A.Address, A.Name, A.Size) <
@ -366,7 +370,7 @@ static void darwinPrintSymbol(SymbolicFile &Obj, const NMSymbol &S,
uint64_t NValue = 0; uint64_t NValue = 0;
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj); MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
if (Obj.isIR()) { if (Obj.isIR()) {
uint32_t SymFlags = S.Sym.getFlags(); uint32_t SymFlags = cantFail(S.Sym.getFlags());
if (SymFlags & SymbolRef::SF_Global) if (SymFlags & SymbolRef::SF_Global)
NType |= MachO::N_EXT; NType |= MachO::N_EXT;
if (SymFlags & SymbolRef::SF_Hidden) if (SymFlags & SymbolRef::SF_Hidden)
@ -794,9 +798,15 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
if (Optional<std::string> Opt = demangle(S.Name, MachO)) if (Optional<std::string> Opt = demangle(S.Name, MachO))
Name = *Opt; Name = *Opt;
} }
if (S.Sym.getRawDataRefImpl().p) if (S.Sym.getRawDataRefImpl().p) {
SymFlags = S.Sym.getFlags(); Expected<uint32_t> SymFlagsOrErr = S.Sym.getFlags();
else if (!SymFlagsOrErr) {
// TODO: Test this error.
error(SymFlagsOrErr.takeError(), Obj.getFileName());
return;
}
SymFlags = *SymFlagsOrErr;
} else
SymFlags = S.SymFlags; SymFlags = S.SymFlags;
bool Undefined = SymFlags & SymbolRef::SF_Undefined; bool Undefined = SymFlags & SymbolRef::SF_Undefined;
@ -1037,14 +1047,14 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
} }
static char getSymbolNMTypeChar(WasmObjectFile &Obj, basic_symbol_iterator I) { static char getSymbolNMTypeChar(WasmObjectFile &Obj, basic_symbol_iterator I) {
uint32_t Flags = I->getFlags(); uint32_t Flags = cantFail(I->getFlags());
if (Flags & SymbolRef::SF_Executable) if (Flags & SymbolRef::SF_Executable)
return 't'; return 't';
return 'd'; return 'd';
} }
static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) { static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
uint32_t Flags = I->getFlags(); uint32_t Flags = cantFail(I->getFlags());
// FIXME: should we print 'b'? At the IR level we cannot be sure if this // FIXME: should we print 'b'? At the IR level we cannot be sure if this
// will be in bss or not, but we could approximate. // will be in bss or not, but we could approximate.
if (Flags & SymbolRef::SF_Executable) if (Flags & SymbolRef::SF_Executable)
@ -1076,7 +1086,8 @@ static StringRef getNMTypeName(SymbolicFile &Obj, basic_symbol_iterator I) {
// section and name, to be used in format=sysv output. // section and name, to be used in format=sysv output.
static char getNMSectionTagAndName(SymbolicFile &Obj, basic_symbol_iterator I, static char getNMSectionTagAndName(SymbolicFile &Obj, basic_symbol_iterator I,
StringRef &SecName) { StringRef &SecName) {
uint32_t Symflags = I->getFlags(); // Symbol Flags have been checked in the caller.
uint32_t Symflags = cantFail(I->getFlags());
if (ELFObjectFileBase *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj)) { if (ELFObjectFileBase *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj)) {
if (Symflags & object::SymbolRef::SF_Absolute) if (Symflags & object::SymbolRef::SF_Absolute)
SecName = "*ABS*"; SecName = "*ABS*";
@ -1205,10 +1216,15 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
} }
if (!(MachO && DyldInfoOnly)) { if (!(MachO && DyldInfoOnly)) {
for (BasicSymbolRef Sym : Symbols) { for (BasicSymbolRef Sym : Symbols) {
uint32_t SymFlags = Sym.getFlags(); Expected<uint32_t> SymFlagsOrErr = Sym.getFlags();
if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific)) if (!SymFlagsOrErr) {
// TODO: Test this error.
error(SymFlagsOrErr.takeError(), Obj.getFileName());
return;
}
if (!DebugSyms && (*SymFlagsOrErr & SymbolRef::SF_FormatSpecific))
continue; continue;
if (WithoutAliases && (SymFlags & SymbolRef::SF_Indirect)) if (WithoutAliases && (*SymFlagsOrErr & SymbolRef::SF_Indirect))
continue; continue;
// If a "-s segname sectname" option was specified and this is a Mach-O // If a "-s segname sectname" option was specified and this is a Mach-O
// file and this section appears in this file, Nsect will be non-zero then // file and this section appears in this file, Nsect will be non-zero then

View File

@ -7562,7 +7562,8 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
symbolTableWorked = true; symbolTableWorked = true;
DataRefImpl Symb = Symbols[SymIdx].getRawDataRefImpl(); DataRefImpl Symb = Symbols[SymIdx].getRawDataRefImpl();
bool IsThumb = MachOOF->getSymbolFlags(Symb) & SymbolRef::SF_Thumb; uint32_t SymbolFlags = cantFail(MachOOF->getSymbolFlags(Symb));
bool IsThumb = SymbolFlags & SymbolRef::SF_Thumb;
// We only need the dedicated Thumb target if there's a real choice // We only need the dedicated Thumb target if there's a real choice
// (i.e. we're not targeting M-class) and the function is Thumb. // (i.e. we're not targeting M-class) and the function is Thumb.

View File

@ -1929,7 +1929,8 @@ void printSymbol(const ObjectFile *O, const SymbolRef &Symbol,
return; return;
SymbolRef::Type Type = SymbolRef::Type Type =
unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName); unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName);
uint32_t Flags = Symbol.getFlags(); uint32_t Flags =
unwrapOrError(Symbol.getFlags(), FileName, ArchiveName, ArchitectureName);
// Don't ask a Mach-O STAB symbol for its section unless you know that // Don't ask a Mach-O STAB symbol for its section unless you know that
// STAB symbol's section field refers to a valid section index. Otherwise // STAB symbol's section field refers to a valid section index. Otherwise

View File

@ -196,11 +196,17 @@ static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
} }
/// Total size of all ELF common symbols /// Total size of all ELF common symbols
static uint64_t getCommonSize(ObjectFile *Obj) { static Expected<uint64_t> getCommonSize(ObjectFile *Obj) {
uint64_t TotalCommons = 0; uint64_t TotalCommons = 0;
for (auto &Sym : Obj->symbols()) for (auto &Sym : Obj->symbols()) {
if (Obj->getSymbolFlags(Sym.getRawDataRefImpl()) & SymbolRef::SF_Common) Expected<uint32_t> SymFlagsOrErr =
Obj->getSymbolFlags(Sym.getRawDataRefImpl());
if (!SymFlagsOrErr)
// TODO: Test this error.
return SymFlagsOrErr.takeError();
if (*SymFlagsOrErr & SymbolRef::SF_Common)
TotalCommons += Obj->getCommonSymbolSize(Sym.getRawDataRefImpl()); TotalCommons += Obj->getCommonSymbolSize(Sym.getRawDataRefImpl());
}
return TotalCommons; return TotalCommons;
} }
@ -435,10 +441,14 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
} }
if (ELFCommons) { if (ELFCommons) {
uint64_t CommonSize = getCommonSize(Obj); if (Expected<uint64_t> CommonSizeOrErr = getCommonSize(Obj)) {
total += CommonSize; total += *CommonSizeOrErr;
outs() << format(fmt.str().c_str(), std::string("*COM*").c_str(), outs() << format(fmt.str().c_str(), std::string("*COM*").c_str(),
CommonSize, static_cast<uint64_t>(0)); *CommonSizeOrErr, static_cast<uint64_t>(0));
} else {
error(CommonSizeOrErr.takeError(), Obj->getFileName());
return;
}
} }
// Print total. // Print total.
@ -469,8 +479,14 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
total_bss += size; total_bss += size;
} }
if (ELFCommons) if (ELFCommons) {
total_bss += getCommonSize(Obj); if (Expected<uint64_t> CommonSizeOrErr = getCommonSize(Obj))
total_bss += *CommonSizeOrErr;
else {
error(CommonSizeOrErr.takeError(), Obj->getFileName());
return;
}
}
total = total_text + total_data + total_bss; total = total_text + total_data + total_bss;

View File

@ -657,7 +657,12 @@ findSanitizerCovFunctions(const object::ObjectFile &O) {
failIfError(NameOrErr); failIfError(NameOrErr);
StringRef Name = NameOrErr.get(); StringRef Name = NameOrErr.get();
if (!(Symbol.getFlags() & object::BasicSymbolRef::SF_Undefined) && Expected<uint32_t> FlagsOrErr = Symbol.getFlags();
// TODO: Test this error.
failIfError(FlagsOrErr);
uint32_t Flags = FlagsOrErr.get();
if (!(Flags & object::BasicSymbolRef::SF_Undefined) &&
isCoveragePointSymbol(Name)) { isCoveragePointSymbol(Name)) {
Result.insert(Address); Result.insert(Address);
} }