mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Return ErrorOr from SymbolRef::getName.
This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297
This commit is contained in:
parent
8da856ce76
commit
165a342cde
@ -647,8 +647,7 @@ public:
|
|||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void moveSymbolNext(DataRefImpl &Symb) const override;
|
void moveSymbolNext(DataRefImpl &Symb) const override;
|
||||||
std::error_code getSymbolName(DataRefImpl Symb,
|
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
StringRef &Res) const override;
|
|
||||||
std::error_code getSymbolAddress(DataRefImpl Symb,
|
std::error_code getSymbolAddress(DataRefImpl Symb,
|
||||||
uint64_t &Res) const override;
|
uint64_t &Res) const override;
|
||||||
uint64_t getSymbolValue(DataRefImpl Symb) const override;
|
uint64_t getSymbolValue(DataRefImpl Symb) const override;
|
||||||
|
@ -195,8 +195,7 @@ protected:
|
|||||||
ELFFile<ELFT> EF;
|
ELFFile<ELFT> EF;
|
||||||
|
|
||||||
void moveSymbolNext(DataRefImpl &Symb) const override;
|
void moveSymbolNext(DataRefImpl &Symb) const override;
|
||||||
std::error_code getSymbolName(DataRefImpl Symb,
|
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
StringRef &Res) const override;
|
|
||||||
std::error_code getSymbolAddress(DataRefImpl Symb,
|
std::error_code getSymbolAddress(DataRefImpl Symb,
|
||||||
uint64_t &Res) const override;
|
uint64_t &Res) const override;
|
||||||
uint64_t getSymbolValue(DataRefImpl Symb) const override;
|
uint64_t getSymbolValue(DataRefImpl Symb) const override;
|
||||||
@ -349,14 +348,9 @@ void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
std::error_code ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym,
|
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
|
||||||
StringRef &Result) const {
|
|
||||||
const Elf_Sym *ESym = toELFSymIter(Sym);
|
const Elf_Sym *ESym = toELFSymIter(Sym);
|
||||||
ErrorOr<StringRef> Name = EF.getSymbolName(ESym, Sym.p & 1);
|
return EF.getSymbolName(ESym, Sym.p & 1);
|
||||||
if (!Name)
|
|
||||||
return Name.getError();
|
|
||||||
Result = *Name;
|
|
||||||
return std::error_code();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -199,8 +199,7 @@ public:
|
|||||||
void moveSymbolNext(DataRefImpl &Symb) const override;
|
void moveSymbolNext(DataRefImpl &Symb) const override;
|
||||||
|
|
||||||
uint64_t getNValue(DataRefImpl Sym) const;
|
uint64_t getNValue(DataRefImpl Sym) const;
|
||||||
std::error_code getSymbolName(DataRefImpl Symb,
|
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
StringRef &Res) const override;
|
|
||||||
|
|
||||||
// MachO specific.
|
// MachO specific.
|
||||||
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
|
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
|
||||||
|
@ -132,7 +132,7 @@ public:
|
|||||||
assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
|
assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code getName(StringRef &Result) const;
|
ErrorOr<StringRef> getName() const;
|
||||||
/// Returns the symbol virtual address (i.e. address at which it will be
|
/// Returns the symbol virtual address (i.e. address at which it will be
|
||||||
/// mapped).
|
/// mapped).
|
||||||
std::error_code getAddress(uint64_t &Result) const;
|
std::error_code getAddress(uint64_t &Result) const;
|
||||||
@ -195,8 +195,7 @@ protected:
|
|||||||
// Implementations assume that the DataRefImpl is valid and has not been
|
// Implementations assume that the DataRefImpl is valid and has not been
|
||||||
// modified externally. It's UB otherwise.
|
// modified externally. It's UB otherwise.
|
||||||
friend class SymbolRef;
|
friend class SymbolRef;
|
||||||
virtual std::error_code getSymbolName(DataRefImpl Symb,
|
virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
|
||||||
StringRef &Res) const = 0;
|
|
||||||
std::error_code printSymbolName(raw_ostream &OS,
|
std::error_code printSymbolName(raw_ostream &OS,
|
||||||
DataRefImpl Symb) const override;
|
DataRefImpl Symb) const override;
|
||||||
virtual std::error_code getSymbolAddress(DataRefImpl Symb,
|
virtual std::error_code getSymbolAddress(DataRefImpl Symb,
|
||||||
@ -305,8 +304,8 @@ public:
|
|||||||
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
||||||
: BasicSymbolRef(SymbolP, Owner) {}
|
: BasicSymbolRef(SymbolP, Owner) {}
|
||||||
|
|
||||||
inline std::error_code SymbolRef::getName(StringRef &Result) const {
|
inline ErrorOr<StringRef> SymbolRef::getName() const {
|
||||||
return getObject()->getSymbolName(getRawDataRefImpl(), Result);
|
return getObject()->getSymbolName(getRawDataRefImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
|
inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
|
||||||
|
@ -181,9 +181,10 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||||||
SymType == object::SymbolRef::ST_Data ||
|
SymType == object::SymbolRef::ST_Data ||
|
||||||
SymType == object::SymbolRef::ST_Unknown) {
|
SymType == object::SymbolRef::ST_Unknown) {
|
||||||
|
|
||||||
StringRef Name;
|
ErrorOr<StringRef> NameOrErr = I->getName();
|
||||||
|
Check(NameOrErr.getError());
|
||||||
|
StringRef Name = *NameOrErr;
|
||||||
uint64_t SectOffset;
|
uint64_t SectOffset;
|
||||||
Check(I->getName(Name));
|
|
||||||
Check(getOffset(*I, SectOffset));
|
Check(getOffset(*I, SectOffset));
|
||||||
section_iterator SI = Obj.section_end();
|
section_iterator SI = Obj.section_end();
|
||||||
Check(I->getSection(SI));
|
Check(I->getSection(SI));
|
||||||
@ -481,8 +482,9 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
|
|||||||
DEBUG(dbgs() << "Processing common symbols...\n");
|
DEBUG(dbgs() << "Processing common symbols...\n");
|
||||||
|
|
||||||
for (const auto &Sym : CommonSymbols) {
|
for (const auto &Sym : CommonSymbols) {
|
||||||
StringRef Name;
|
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
||||||
Check(Sym.getName(Name));
|
Check(NameOrErr.getError());
|
||||||
|
StringRef Name = *NameOrErr;
|
||||||
|
|
||||||
// Skip common symbols already elsewhere.
|
// Skip common symbols already elsewhere.
|
||||||
if (GlobalSymbolTable.count(Name) ||
|
if (GlobalSymbolTable.count(Name) ||
|
||||||
@ -515,9 +517,10 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
|
|||||||
// Assign the address of each symbol
|
// Assign the address of each symbol
|
||||||
for (auto &Sym : SymbolsToAllocate) {
|
for (auto &Sym : SymbolsToAllocate) {
|
||||||
uint32_t Align = Sym.getAlignment();
|
uint32_t Align = Sym.getAlignment();
|
||||||
StringRef Name;
|
|
||||||
uint64_t Size = Sym.getCommonSize();
|
uint64_t Size = Sym.getCommonSize();
|
||||||
Check(Sym.getName(Name));
|
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
||||||
|
Check(NameOrErr.getError());
|
||||||
|
StringRef Name = *NameOrErr;
|
||||||
if (Align) {
|
if (Align) {
|
||||||
// This symbol has an alignment requirement.
|
// This symbol has an alignment requirement.
|
||||||
uint64_t AlignOffset = OffsetToAlignment((uint64_t)Addr, Align);
|
uint64_t AlignOffset = OffsetToAlignment((uint64_t)Addr, Align);
|
||||||
|
@ -1064,8 +1064,12 @@ relocation_iterator RuntimeDyldELF::processRelocationRef(
|
|||||||
|
|
||||||
// Obtain the symbol name which is referenced in the relocation
|
// Obtain the symbol name which is referenced in the relocation
|
||||||
StringRef TargetName;
|
StringRef TargetName;
|
||||||
if (Symbol != Obj.symbol_end())
|
if (Symbol != Obj.symbol_end()) {
|
||||||
Symbol->getName(TargetName);
|
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
|
if (std::error_code EC = TargetNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
TargetName = *TargetNameOrErr;
|
||||||
|
}
|
||||||
DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend
|
DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend
|
||||||
<< " TargetName: " << TargetName << "\n");
|
<< " TargetName: " << TargetName << "\n");
|
||||||
RelocationValueRef Value;
|
RelocationValueRef Value;
|
||||||
|
@ -63,8 +63,10 @@ RelocationValueRef RuntimeDyldMachO::getRelocationValueRef(
|
|||||||
bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
|
bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
|
||||||
if (IsExternal) {
|
if (IsExternal) {
|
||||||
symbol_iterator Symbol = RI->getSymbol();
|
symbol_iterator Symbol = RI->getSymbol();
|
||||||
StringRef TargetName;
|
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
Symbol->getName(TargetName);
|
if (std::error_code EC = TargetNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef TargetName = *TargetNameOrErr;
|
||||||
RTDyldSymbolTable::const_iterator SI =
|
RTDyldSymbolTable::const_iterator SI =
|
||||||
GlobalSymbolTable.find(TargetName.data());
|
GlobalSymbolTable.find(TargetName.data());
|
||||||
if (SI != GlobalSymbolTable.end()) {
|
if (SI != GlobalSymbolTable.end()) {
|
||||||
@ -162,8 +164,10 @@ void RuntimeDyldMachO::populateIndirectSymbolPointersSection(
|
|||||||
unsigned SymbolIndex =
|
unsigned SymbolIndex =
|
||||||
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
|
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
|
||||||
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
|
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
|
||||||
StringRef IndirectSymbolName;
|
ErrorOr<StringRef> IndirectSymbolNameOrErr = SI->getName();
|
||||||
SI->getName(IndirectSymbolName);
|
if (std::error_code EC = IndirectSymbolNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef IndirectSymbolName = *IndirectSymbolNameOrErr;
|
||||||
DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
|
DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
|
||||||
<< ", PT offset: " << PTEntryOffset << "\n");
|
<< ", PT offset: " << PTEntryOffset << "\n");
|
||||||
RelocationEntry RE(PTSectionID, PTEntryOffset,
|
RelocationEntry RE(PTSectionID, PTEntryOffset,
|
||||||
|
@ -155,8 +155,10 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef TargetName;
|
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
Symbol->getName(TargetName);
|
if (std::error_code EC = TargetNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef TargetName = *TargetNameOrErr;
|
||||||
|
|
||||||
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
|
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
|
||||||
<< " RelType: " << RelType << " TargetName: " << TargetName
|
<< " RelType: " << RelType << " TargetName: " << TargetName
|
||||||
|
@ -240,13 +240,14 @@ private:
|
|||||||
unsigned SymbolIndex =
|
unsigned SymbolIndex =
|
||||||
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
|
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
|
||||||
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
|
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
|
||||||
StringRef IndirectSymbolName;
|
ErrorOr<StringRef> IndirectSymbolName = SI->getName();
|
||||||
SI->getName(IndirectSymbolName);
|
if (std::error_code EC = IndirectSymbolName.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
|
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
|
||||||
createStubFunction(JTEntryAddr);
|
createStubFunction(JTEntryAddr);
|
||||||
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
|
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
|
||||||
MachO::GENERIC_RELOC_VANILLA, 0, true, 2);
|
MachO::GENERIC_RELOC_VANILLA, 0, true, 2);
|
||||||
addRelocationForSymbol(RE, IndirectSymbolName);
|
addRelocationForSymbol(RE, *IndirectSymbolName);
|
||||||
JTEntryOffset += JTEntrySize;
|
JTEntryOffset += JTEntrySize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,13 @@ void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
|
ErrorOr<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
|
||||||
StringRef &Result) const {
|
|
||||||
COFFSymbolRef Symb = getCOFFSymbol(Ref);
|
COFFSymbolRef Symb = getCOFFSymbol(Ref);
|
||||||
return getSymbolName(Symb, Result);
|
StringRef Result;
|
||||||
|
std::error_code EC = getSymbolName(Symb, Result);
|
||||||
|
if (EC)
|
||||||
|
return EC;
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
|
uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
|
||||||
|
@ -327,16 +327,14 @@ void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
|
|||||||
Symb.p += SymbolTableEntrySize;
|
Symb.p += SymbolTableEntrySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
|
ErrorOr<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
|
||||||
StringRef &Res) const {
|
|
||||||
StringRef StringTable = getStringTableData();
|
StringRef StringTable = getStringTableData();
|
||||||
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
|
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
|
||||||
const char *Start = &StringTable.data()[Entry.n_strx];
|
const char *Start = &StringTable.data()[Entry.n_strx];
|
||||||
if (Start < getData().begin() || Start >= getData().end())
|
if (Start < getData().begin() || Start >= getData().end())
|
||||||
report_fatal_error(
|
report_fatal_error(
|
||||||
"Symbol name entry points before beginning or past end of file.");
|
"Symbol name entry points before beginning or past end of file.");
|
||||||
Res = StringRef(Start);
|
return StringRef(Start);
|
||||||
return std::error_code();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
|
unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
|
||||||
|
@ -173,10 +173,10 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
|
|||||||
|
|
||||||
// SymbolRef accessors
|
// SymbolRef accessors
|
||||||
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
||||||
StringRef ret;
|
ErrorOr<StringRef> Ret = (*unwrap(SI))->getName();
|
||||||
if (std::error_code ec = (*unwrap(SI))->getName(ret))
|
if (std::error_code EC = Ret.getError())
|
||||||
report_fatal_error(ec.message());
|
report_fatal_error(EC.message());
|
||||||
return ret.data();
|
return Ret->data();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
|
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
|
||||||
|
@ -37,10 +37,10 @@ bool SectionRef::containsSymbol(SymbolRef S) const {
|
|||||||
|
|
||||||
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
|
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
|
||||||
DataRefImpl Symb) const {
|
DataRefImpl Symb) const {
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = getSymbolName(Symb);
|
||||||
if (std::error_code EC = getSymbolName(Symb, Name))
|
if (std::error_code EC = Name.getError())
|
||||||
return EC;
|
return EC;
|
||||||
OS << Name;
|
OS << *Name;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,11 @@ public:
|
|||||||
uint64_t RelType = Rel.getType();
|
uint64_t RelType = Rel.getType();
|
||||||
elf_symbol_iterator SymI = Rel.getSymbol();
|
elf_symbol_iterator SymI = Rel.getSymbol();
|
||||||
|
|
||||||
StringRef SymName; SymI->getName(SymName);
|
ErrorOr<StringRef> SymNameOrErr = SymI->getName();
|
||||||
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
|
|
||||||
uint64_t SymAddr; SymI->getAddress(SymAddr);
|
uint64_t SymAddr; SymI->getAddress(SymAddr);
|
||||||
uint64_t SymSize = SymI->getSize();
|
uint64_t SymSize = SymI->getSize();
|
||||||
int64_t Addend = *ELFRelocationRef(Rel).getAddend();
|
int64_t Addend = *ELFRelocationRef(Rel).getAddend();
|
||||||
|
@ -30,7 +30,10 @@ public:
|
|||||||
uint64_t RelType = Rel.getType();
|
uint64_t RelType = Rel.getType();
|
||||||
symbol_iterator SymI = Rel.getSymbol();
|
symbol_iterator SymI = Rel.getSymbol();
|
||||||
|
|
||||||
StringRef SymName; SymI->getName(SymName);
|
ErrorOr<StringRef> SymNameOrErr = SymI->getName();
|
||||||
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
uint64_t SymAddr; SymI->getAddress(SymAddr);
|
uint64_t SymAddr; SymI->getAddress(SymAddr);
|
||||||
|
|
||||||
any_relocation_info RE = Obj->getRelocation(Rel.getRawDataRefImpl());
|
any_relocation_info RE = Obj->getRelocation(Rel.getRawDataRefImpl());
|
||||||
@ -89,10 +92,11 @@ public:
|
|||||||
symbol_iterator RSymI = Rel.getSymbol();
|
symbol_iterator RSymI = Rel.getSymbol();
|
||||||
uint64_t RSymAddr;
|
uint64_t RSymAddr;
|
||||||
RSymI->getAddress(RSymAddr);
|
RSymI->getAddress(RSymAddr);
|
||||||
StringRef RSymName;
|
ErrorOr<StringRef> RSymName = RSymI->getName();
|
||||||
RSymI->getName(RSymName);
|
if (std::error_code EC = RSymName.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
|
||||||
MCSymbol *RSym = Ctx.getOrCreateSymbol(RSymName);
|
MCSymbol *RSym = Ctx.getOrCreateSymbol(*RSymName);
|
||||||
if (!RSym->isVariable())
|
if (!RSym->isVariable())
|
||||||
RSym->setVariableValue(MCConstantExpr::create(RSymAddr, Ctx));
|
RSym->setVariableValue(MCConstantExpr::create(RSymAddr, Ctx));
|
||||||
|
|
||||||
|
@ -216,11 +216,13 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
|
|||||||
// during the test, we can't hardcode the symbols addresses, so
|
// during the test, we can't hardcode the symbols addresses, so
|
||||||
// look them up here and rewrite them.
|
// look them up here and rewrite them.
|
||||||
for (const auto &Sym : ErrOrObjectFile->symbols()) {
|
for (const auto &Sym : ErrOrObjectFile->symbols()) {
|
||||||
StringRef Name;
|
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
if (Sym.getName(Name) || Sym.getAddress(Address))
|
if (Sym.getAddress(Address))
|
||||||
continue;
|
continue;
|
||||||
SymbolAddresses[Name] = Address;
|
ErrorOr<StringRef> Name = Sym.getName();
|
||||||
|
if (!Name)
|
||||||
|
continue;
|
||||||
|
SymbolAddresses[*Name] = Address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1462,12 +1462,12 @@ void DwarfLinker::findValidRelocsMachO(const object::SectionRef &Section,
|
|||||||
|
|
||||||
auto Sym = Reloc.getSymbol();
|
auto Sym = Reloc.getSymbol();
|
||||||
if (Sym != Obj.symbol_end()) {
|
if (Sym != Obj.symbol_end()) {
|
||||||
StringRef SymbolName;
|
ErrorOr<StringRef> SymbolName = Sym->getName();
|
||||||
if (Sym->getName(SymbolName)) {
|
if (!SymbolName) {
|
||||||
reportWarning("error getting relocation symbol name.");
|
reportWarning("error getting relocation symbol name.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (const auto *Mapping = DMO.lookupSymbol(SymbolName))
|
if (const auto *Mapping = DMO.lookupSymbol(*SymbolName))
|
||||||
ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
|
ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
|
||||||
} else if (const auto *Mapping = DMO.lookupObjectAddress(Addend)) {
|
} else if (const auto *Mapping = DMO.lookupObjectAddress(Addend)) {
|
||||||
// Do not store the addend. The addend was the address of the
|
// Do not store the addend. The addend was the address of the
|
||||||
|
@ -197,11 +197,14 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols() {
|
|||||||
CurrentObjectAddresses.clear();
|
CurrentObjectAddresses.clear();
|
||||||
|
|
||||||
for (auto Sym : CurrentObjectHolder.Get().symbols()) {
|
for (auto Sym : CurrentObjectHolder.Get().symbols()) {
|
||||||
StringRef Name;
|
|
||||||
uint64_t Addr;
|
uint64_t Addr;
|
||||||
if (Sym.getAddress(Addr) || Addr == UnknownAddress || Sym.getName(Name))
|
if (Sym.getAddress(Addr) || Addr == UnknownAddress)
|
||||||
continue;
|
continue;
|
||||||
CurrentObjectAddresses[Name] = Addr;
|
ErrorOr<StringRef> Name = Sym.getName();
|
||||||
|
if (!Name)
|
||||||
|
continue;
|
||||||
|
CurrentObjectAddresses[*Name] = Addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +228,6 @@ void MachODebugMapParser::loadMainBinarySymbols() {
|
|||||||
// Skip undefined and STAB entries.
|
// Skip undefined and STAB entries.
|
||||||
if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
|
if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
|
||||||
continue;
|
continue;
|
||||||
StringRef Name;
|
|
||||||
uint64_t Addr;
|
uint64_t Addr;
|
||||||
// The only symbols of interest are the global variables. These
|
// The only symbols of interest are the global variables. These
|
||||||
// are the only ones that need to be queried because the address
|
// are the only ones that need to be queried because the address
|
||||||
@ -233,8 +235,13 @@ void MachODebugMapParser::loadMainBinarySymbols() {
|
|||||||
// addresses should be fetched for the debug map.
|
// addresses should be fetched for the debug map.
|
||||||
if (Sym.getAddress(Addr) || Addr == UnknownAddress ||
|
if (Sym.getAddress(Addr) || Addr == UnknownAddress ||
|
||||||
!(Sym.getFlags() & SymbolRef::SF_Global) || Sym.getSection(Section) ||
|
!(Sym.getFlags() & SymbolRef::SF_Global) || Sym.getSection(Section) ||
|
||||||
Section->isText() || Sym.getName(Name) || Name.size() == 0 ||
|
Section->isText())
|
||||||
Name[0] == '\0')
|
continue;
|
||||||
|
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
||||||
|
if (!NameOrErr)
|
||||||
|
continue;
|
||||||
|
StringRef Name = *NameOrErr;
|
||||||
|
if (Name.size() == 0 || Name[0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
MainBinarySymbolAddresses[Name] = Addr;
|
MainBinarySymbolAddresses[Name] = Addr;
|
||||||
}
|
}
|
||||||
|
@ -97,12 +97,12 @@ static bool collectRelocatedSymbols(const ObjectFile *Obj,
|
|||||||
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
||||||
if (RelocSymI == Obj->symbol_end())
|
if (RelocSymI == Obj->symbol_end())
|
||||||
continue;
|
continue;
|
||||||
StringRef RelocSymName;
|
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
|
||||||
if (error(RelocSymI->getName(RelocSymName)))
|
if (error(RelocSymName.getError()))
|
||||||
return true;
|
return true;
|
||||||
uint64_t Offset = Reloc.getOffset();
|
uint64_t Offset = Reloc.getOffset();
|
||||||
if (Offset >= SymOffset && Offset < SymEnd) {
|
if (Offset >= SymOffset && Offset < SymEnd) {
|
||||||
*I = RelocSymName;
|
*I = *RelocSymName;
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,12 +121,12 @@ static bool collectRelocationOffsets(
|
|||||||
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
||||||
if (RelocSymI == Obj->symbol_end())
|
if (RelocSymI == Obj->symbol_end())
|
||||||
continue;
|
continue;
|
||||||
StringRef RelocSymName;
|
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
|
||||||
if (error(RelocSymI->getName(RelocSymName)))
|
if (error(RelocSymName.getError()))
|
||||||
return true;
|
return true;
|
||||||
uint64_t Offset = Reloc.getOffset();
|
uint64_t Offset = Reloc.getOffset();
|
||||||
if (Offset >= SymOffset && Offset < SymEnd)
|
if (Offset >= SymOffset && Offset < SymEnd)
|
||||||
Collection[std::make_pair(SymName, Offset - SymOffset)] = RelocSymName;
|
Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -190,9 +190,10 @@ static void dumpCXXData(const ObjectFile *Obj) {
|
|||||||
for (auto &P : SymAddr) {
|
for (auto &P : SymAddr) {
|
||||||
object::SymbolRef Sym = P.first;
|
object::SymbolRef Sym = P.first;
|
||||||
uint64_t SymSize = P.second;
|
uint64_t SymSize = P.second;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymNameOrErr = Sym.getName();
|
||||||
if (error(Sym.getName(SymName)))
|
if (error(SymNameOrErr.getError()))
|
||||||
return;
|
return;
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
object::section_iterator SecI(Obj->section_begin());
|
object::section_iterator SecI(Obj->section_begin());
|
||||||
if (error(Sym.getSection(SecI)))
|
if (error(Sym.getSection(SecI)))
|
||||||
return;
|
return;
|
||||||
|
@ -653,10 +653,10 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SymI->getELFType() == ELF::STT_SECTION) {
|
if (SymI->getELFType() == ELF::STT_SECTION) {
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = SymI->getName();
|
||||||
if (error(SymI->getName(Name)))
|
if (error(Name.getError()))
|
||||||
return '?';
|
return '?';
|
||||||
return StringSwitch<char>(Name)
|
return StringSwitch<char>(*Name)
|
||||||
.StartsWith(".debug", 'N')
|
.StartsWith(".debug", 'N')
|
||||||
.StartsWith(".note", 'n')
|
.StartsWith(".note", 'n')
|
||||||
.Default('?');
|
.Default('?');
|
||||||
@ -670,11 +670,11 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
|
|||||||
// OK, this is COFF.
|
// OK, this is COFF.
|
||||||
symbol_iterator SymI(I);
|
symbol_iterator SymI(I);
|
||||||
|
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = SymI->getName();
|
||||||
if (error(SymI->getName(Name)))
|
if (error(Name.getError()))
|
||||||
return '?';
|
return '?';
|
||||||
|
|
||||||
char Ret = StringSwitch<char>(Name)
|
char Ret = StringSwitch<char>(*Name)
|
||||||
.StartsWith(".debug", 'N')
|
.StartsWith(".debug", 'N')
|
||||||
.StartsWith(".sxdata", 'N')
|
.StartsWith(".sxdata", 'N')
|
||||||
.Default('?');
|
.Default('?');
|
||||||
|
@ -213,8 +213,10 @@ static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
|
|||||||
SymbolRef Sym;
|
SymbolRef Sym;
|
||||||
if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
|
if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
|
||||||
return EC;
|
return EC;
|
||||||
if (std::error_code EC = Sym.getName(Name))
|
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
||||||
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
|
Name = *NameOrErr;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,9 +282,10 @@ static void getSectionsAndSymbols(MachOObjectFile *MachOObj,
|
|||||||
SmallVectorImpl<uint64_t> &FoundFns,
|
SmallVectorImpl<uint64_t> &FoundFns,
|
||||||
uint64_t &BaseSegmentAddress) {
|
uint64_t &BaseSegmentAddress) {
|
||||||
for (const SymbolRef &Symbol : MachOObj->symbols()) {
|
for (const SymbolRef &Symbol : MachOObj->symbols()) {
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
if (!SymName.startswith("ltmp"))
|
report_fatal_error(EC.message());
|
||||||
|
if (!SymName->startswith("ltmp"))
|
||||||
Symbols.push_back(Symbol);
|
Symbols.push_back(Symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,9 +362,10 @@ static void PrintIndirectSymbolTable(MachOObjectFile *O, bool verbose,
|
|||||||
if (indirect_symbol < Symtab.nsyms) {
|
if (indirect_symbol < Symtab.nsyms) {
|
||||||
symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
|
symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
|
||||||
SymbolRef Symbol = *Sym;
|
SymbolRef Symbol = *Sym;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
outs() << SymName;
|
report_fatal_error(EC.message());
|
||||||
|
outs() << *SymName;
|
||||||
} else {
|
} else {
|
||||||
outs() << "?";
|
outs() << "?";
|
||||||
}
|
}
|
||||||
@ -592,8 +594,10 @@ static void CreateSymbolAddressMap(MachOObjectFile *O,
|
|||||||
ST == SymbolRef::ST_Other) {
|
ST == SymbolRef::ST_Other) {
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
Symbol.getAddress(Address);
|
Symbol.getAddress(Address);
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
if (!SymName.startswith(".objc"))
|
if (!SymName.startswith(".objc"))
|
||||||
(*AddrMap)[Address] = SymName;
|
(*AddrMap)[Address] = SymName;
|
||||||
}
|
}
|
||||||
@ -830,9 +834,10 @@ static void DumpLiteralPointerSection(MachOObjectFile *O,
|
|||||||
[&](const std::pair<uint64_t, SymbolRef> &P) { return P.first == i; });
|
[&](const std::pair<uint64_t, SymbolRef> &P) { return P.first == i; });
|
||||||
if (Reloc != Relocs.end()) {
|
if (Reloc != Relocs.end()) {
|
||||||
symbol_iterator RelocSym = Reloc->second;
|
symbol_iterator RelocSym = Reloc->second;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = RelocSym->getName();
|
||||||
RelocSym->getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
outs() << "external relocation entry for symbol:" << SymName << "\n";
|
report_fatal_error(EC.message());
|
||||||
|
outs() << "external relocation entry for symbol:" << *SymName << "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1793,9 +1798,10 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reloc_found && isExtern) {
|
if (reloc_found && isExtern) {
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
op_info->AddSymbol.Present = 1;
|
op_info->AddSymbol.Present = 1;
|
||||||
op_info->AddSymbol.Name = name;
|
op_info->AddSymbol.Name = name;
|
||||||
// For i386 extern relocation entries the value in the instruction is
|
// For i386 extern relocation entries the value in the instruction is
|
||||||
@ -1859,9 +1865,10 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
// is the offset from the external symbol.
|
// is the offset from the external symbol.
|
||||||
if (info->O->getAnyRelocationPCRel(RE))
|
if (info->O->getAnyRelocationPCRel(RE))
|
||||||
op_info->Value -= Pc + Offset + Size;
|
op_info->Value -= Pc + Offset + Size;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
unsigned Type = info->O->getAnyRelocationType(RE);
|
unsigned Type = info->O->getAnyRelocationType(RE);
|
||||||
if (Type == MachO::X86_64_RELOC_SUBTRACTOR) {
|
if (Type == MachO::X86_64_RELOC_SUBTRACTOR) {
|
||||||
DataRefImpl RelNext = Rel;
|
DataRefImpl RelNext = Rel;
|
||||||
@ -1875,9 +1882,10 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
op_info->SubtractSymbol.Name = name;
|
op_info->SubtractSymbol.Name = name;
|
||||||
symbol_iterator RelocSymNext = info->O->getSymbolByIndex(SymbolNum);
|
symbol_iterator RelocSymNext = info->O->getSymbolByIndex(SymbolNum);
|
||||||
Symbol = *RelocSymNext;
|
Symbol = *RelocSymNext;
|
||||||
StringRef SymNameNext;
|
ErrorOr<StringRef> SymNameNext = Symbol.getName();
|
||||||
Symbol.getName(SymNameNext);
|
if (std::error_code EC = SymNameNext.getError())
|
||||||
name = SymNameNext.data();
|
report_fatal_error(EC.message());
|
||||||
|
name = SymNameNext->data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: add the VariantKinds to op_info->VariantKind for relocation types
|
// TODO: add the VariantKinds to op_info->VariantKind for relocation types
|
||||||
@ -1944,9 +1952,10 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isExtern) {
|
if (isExtern) {
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
op_info->AddSymbol.Present = 1;
|
op_info->AddSymbol.Present = 1;
|
||||||
op_info->AddSymbol.Name = name;
|
op_info->AddSymbol.Name = name;
|
||||||
switch (r_type) {
|
switch (r_type) {
|
||||||
@ -2056,9 +2065,10 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
// NOTE: Scattered relocations don't exist on arm64.
|
// NOTE: Scattered relocations don't exist on arm64.
|
||||||
if (!info->O->getPlainRelocationExternal(RE))
|
if (!info->O->getPlainRelocationExternal(RE))
|
||||||
return 0;
|
return 0;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Reloc->getSymbol()->getName();
|
||||||
Reloc->getSymbol()->getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
op_info->AddSymbol.Present = 1;
|
op_info->AddSymbol.Present = 1;
|
||||||
op_info->AddSymbol.Name = name;
|
op_info->AddSymbol.Name = name;
|
||||||
|
|
||||||
@ -2185,9 +2195,10 @@ static const char *GuessIndirectSymbol(uint64_t ReferenceValue,
|
|||||||
if (indirect_symbol < Symtab.nsyms) {
|
if (indirect_symbol < Symtab.nsyms) {
|
||||||
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
|
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
|
||||||
SymbolRef Symbol = *Sym;
|
SymbolRef Symbol = *Sym;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2219,9 +2230,10 @@ static const char *GuessIndirectSymbol(uint64_t ReferenceValue,
|
|||||||
if (indirect_symbol < Symtab.nsyms) {
|
if (indirect_symbol < Symtab.nsyms) {
|
||||||
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
|
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
|
||||||
SymbolRef Symbol = *Sym;
|
SymbolRef Symbol = *Sym;
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymName = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymName.getError())
|
||||||
const char *name = SymName.data();
|
report_fatal_error(EC.message());
|
||||||
|
const char *name = SymName->data();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2447,10 +2459,12 @@ static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
|
|||||||
Symbol.getAddress(n_value);
|
Symbol.getAddress(n_value);
|
||||||
if (n_value == UnknownAddress)
|
if (n_value == UnknownAddress)
|
||||||
n_value = 0;
|
n_value = 0;
|
||||||
StringRef name;
|
ErrorOr<StringRef> NameOrError = Symbol.getName();
|
||||||
Symbol.getName(name);
|
if (std::error_code EC = NameOrError.getError())
|
||||||
if (!name.empty()) {
|
report_fatal_error(EC.message());
|
||||||
SymbolName = name.data();
|
StringRef Name = *NameOrError;
|
||||||
|
if (!Name.empty()) {
|
||||||
|
SymbolName = Name.data();
|
||||||
return SymbolName;
|
return SymbolName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6119,8 +6133,10 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
|||||||
ST == SymbolRef::ST_Other) {
|
ST == SymbolRef::ST_Other) {
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
Symbol.getAddress(Address);
|
Symbol.getAddress(Address);
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
|
||||||
Symbol.getName(SymName);
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
AddrMap[Address] = SymName;
|
AddrMap[Address] = SymName;
|
||||||
if (!DisSymName.empty() && DisSymName == SymName)
|
if (!DisSymName.empty() && DisSymName == SymName)
|
||||||
DisSymNameFound = true;
|
DisSymNameFound = true;
|
||||||
@ -6159,8 +6175,10 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
|||||||
|
|
||||||
// Disassemble symbol by symbol.
|
// Disassemble symbol by symbol.
|
||||||
for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
|
for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymNameOrErr = Symbols[SymIdx].getName();
|
||||||
Symbols[SymIdx].getName(SymName);
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
|
|
||||||
SymbolRef::Type ST = Symbols[SymIdx].getType();
|
SymbolRef::Type ST = Symbols[SymIdx].getType();
|
||||||
if (ST != SymbolRef::ST_Function)
|
if (ST != SymbolRef::ST_Function)
|
||||||
@ -6423,7 +6441,10 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
|
|||||||
const RelocationRef &Reloc, uint64_t Addr,
|
const RelocationRef &Reloc, uint64_t Addr,
|
||||||
StringRef &Name, uint64_t &Addend) {
|
StringRef &Name, uint64_t &Addend) {
|
||||||
if (Reloc.getSymbol() != Obj->symbol_end()) {
|
if (Reloc.getSymbol() != Obj->symbol_end()) {
|
||||||
Reloc.getSymbol()->getName(Name);
|
ErrorOr<StringRef> NameOrErr = Reloc.getSymbol()->getName();
|
||||||
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
Name = *NameOrErr;
|
||||||
Addend = Addr;
|
Addend = Addr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -6449,7 +6470,10 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
|
|||||||
Sym->second.getSection(SymSection);
|
Sym->second.getSection(SymSection);
|
||||||
if (RelocSection == *SymSection) {
|
if (RelocSection == *SymSection) {
|
||||||
// There's a valid symbol in the same section before this reference.
|
// There's a valid symbol in the same section before this reference.
|
||||||
Sym->second.getName(Name);
|
ErrorOr<StringRef> NameOrErr = Sym->second.getName();
|
||||||
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
Name = *NameOrErr;
|
||||||
Addend = Addr - Sym->first;
|
Addend = Addr - Sym->first;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -433,9 +433,10 @@ static std::error_code getRelocationValueString(const COFFObjectFile *Obj,
|
|||||||
const RelocationRef &Rel,
|
const RelocationRef &Rel,
|
||||||
SmallVectorImpl<char> &Result) {
|
SmallVectorImpl<char> &Result) {
|
||||||
symbol_iterator SymI = Rel.getSymbol();
|
symbol_iterator SymI = Rel.getSymbol();
|
||||||
StringRef SymName;
|
ErrorOr<StringRef> SymNameOrErr = SymI->getName();
|
||||||
if (std::error_code EC = SymI->getName(SymName))
|
if (std::error_code EC = SymNameOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
|
StringRef SymName = *SymNameOrErr;
|
||||||
Result.append(SymName.begin(), SymName.end());
|
Result.append(SymName.begin(), SymName.end());
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
@ -455,15 +456,15 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
for (const SymbolRef &Symbol : O->symbols()) {
|
for (const SymbolRef &Symbol : O->symbols()) {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
uint64_t Addr;
|
uint64_t Addr;
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = Symbol.getName();
|
||||||
|
|
||||||
if ((ec = Symbol.getAddress(Addr)))
|
if ((ec = Symbol.getAddress(Addr)))
|
||||||
report_fatal_error(ec.message());
|
report_fatal_error(ec.message());
|
||||||
if (Addr != Val)
|
if (Addr != Val)
|
||||||
continue;
|
continue;
|
||||||
if ((ec = Symbol.getName(Name)))
|
if (std::error_code EC = Name.getError())
|
||||||
report_fatal_error(ec.message());
|
report_fatal_error(EC.message());
|
||||||
fmt << Name;
|
fmt << *Name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +494,9 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
if (isExtern) {
|
if (isExtern) {
|
||||||
symbol_iterator SI = O->symbol_begin();
|
symbol_iterator SI = O->symbol_begin();
|
||||||
advance(SI, Val);
|
advance(SI, Val);
|
||||||
SI->getName(S);
|
ErrorOr<StringRef> SOrErr = SI->getName();
|
||||||
|
if (!error(SOrErr.getError()))
|
||||||
|
S = *SOrErr;
|
||||||
} else {
|
} else {
|
||||||
section_iterator SI = O->section_begin();
|
section_iterator SI = O->section_begin();
|
||||||
// Adjust for the fact that sections are 1-indexed.
|
// Adjust for the fact that sections are 1-indexed.
|
||||||
@ -830,10 +833,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
if (Address >= SectSize)
|
if (Address >= SectSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = Symbol.getName();
|
||||||
if (error(Symbol.getName(Name)))
|
if (error(Name.getError()))
|
||||||
break;
|
break;
|
||||||
Symbols.push_back(std::make_pair(Address, Name));
|
Symbols.push_back(std::make_pair(Address, *Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,8 +1124,11 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
|
|||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
|
if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
|
||||||
Section->getName(Name);
|
Section->getName(Name);
|
||||||
} else if (error(Symbol.getName(Name))) {
|
} else {
|
||||||
continue;
|
ErrorOr<StringRef> NameOrErr = Symbol.getName();
|
||||||
|
if (error(NameOrErr.getError()))
|
||||||
|
continue;
|
||||||
|
Name = *NameOrErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Global = Flags & SymbolRef::SF_Global;
|
bool Global = Flags & SymbolRef::SF_Global;
|
||||||
|
@ -567,12 +567,12 @@ bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF,
|
|||||||
if (!Symbol)
|
if (!Symbol)
|
||||||
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
|
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
|
||||||
|
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = Symbol->getName();
|
||||||
if (Symbol)
|
if (std::error_code EC = Name.getError())
|
||||||
Symbol->getName(Name);
|
report_fatal_error(EC.message());
|
||||||
|
|
||||||
ListScope EHS(SW, "ExceptionHandler");
|
ListScope EHS(SW, "ExceptionHandler");
|
||||||
SW.printString("Routine", formatSymbol(Name, Address));
|
SW.printString("Routine", formatSymbol(*Name, Address));
|
||||||
SW.printHex("Parameter", Parameter);
|
SW.printHex("Parameter", Parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +601,10 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||||||
StringRef FunctionName;
|
StringRef FunctionName;
|
||||||
uint64_t FunctionAddress;
|
uint64_t FunctionAddress;
|
||||||
if (Function) {
|
if (Function) {
|
||||||
Function->getName(FunctionName);
|
ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
|
||||||
|
if (std::error_code EC = FunctionNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
FunctionName = *FunctionNameOrErr;
|
||||||
Function->getAddress(FunctionAddress);
|
Function->getAddress(FunctionAddress);
|
||||||
} else {
|
} else {
|
||||||
const pe32_header *PEHeader;
|
const pe32_header *PEHeader;
|
||||||
@ -613,13 +616,14 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||||||
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
|
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
|
||||||
|
|
||||||
if (XDataRecord) {
|
if (XDataRecord) {
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = XDataRecord->getName();
|
||||||
uint64_t Address;
|
if (std::error_code EC = Name.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
|
||||||
XDataRecord->getName(Name);
|
uint64_t Address;
|
||||||
XDataRecord->getAddress(Address);
|
XDataRecord->getAddress(Address);
|
||||||
|
|
||||||
SW.printString("ExceptionRecord", formatSymbol(Name, Address));
|
SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
|
||||||
|
|
||||||
section_iterator SI = COFF.section_end();
|
section_iterator SI = COFF.section_end();
|
||||||
if (XDataRecord->getSection(SI))
|
if (XDataRecord->getSection(SI))
|
||||||
@ -658,7 +662,10 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
|
|||||||
StringRef FunctionName;
|
StringRef FunctionName;
|
||||||
uint64_t FunctionAddress;
|
uint64_t FunctionAddress;
|
||||||
if (Function) {
|
if (Function) {
|
||||||
Function->getName(FunctionName);
|
ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
|
||||||
|
if (std::error_code EC = FunctionNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
FunctionName = *FunctionNameOrErr;
|
||||||
Function->getAddress(FunctionAddress);
|
Function->getAddress(FunctionAddress);
|
||||||
} else {
|
} else {
|
||||||
const pe32_header *PEHeader;
|
const pe32_header *PEHeader;
|
||||||
|
@ -139,8 +139,10 @@ std::error_code COFFDumper::resolveSymbolName(const coff_section *Section,
|
|||||||
SymbolRef Symbol;
|
SymbolRef Symbol;
|
||||||
if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
|
if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
|
||||||
return EC;
|
return EC;
|
||||||
if (std::error_code EC = Symbol.getName(Name))
|
ErrorOr<StringRef> NameOrErr = Symbol.getName();
|
||||||
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
|
Name = *NameOrErr;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,8 +811,12 @@ void COFFDumper::printRelocation(const SectionRef &Section,
|
|||||||
StringRef SymbolName;
|
StringRef SymbolName;
|
||||||
Reloc.getTypeName(RelocName);
|
Reloc.getTypeName(RelocName);
|
||||||
symbol_iterator Symbol = Reloc.getSymbol();
|
symbol_iterator Symbol = Reloc.getSymbol();
|
||||||
if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
|
if (Symbol != Obj->symbol_end()) {
|
||||||
return;
|
ErrorOr<StringRef> SymbolNameOrErr = Symbol->getName();
|
||||||
|
if (error(SymbolNameOrErr.getError()))
|
||||||
|
return;
|
||||||
|
SymbolName = *SymbolNameOrErr;
|
||||||
|
}
|
||||||
|
|
||||||
if (opts::ExpandRelocs) {
|
if (opts::ExpandRelocs) {
|
||||||
DictScope Group(W, "Relocation");
|
DictScope Group(W, "Relocation");
|
||||||
|
@ -474,8 +474,10 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
|
|||||||
if (IsExtern) {
|
if (IsExtern) {
|
||||||
symbol_iterator Symbol = Reloc.getSymbol();
|
symbol_iterator Symbol = Reloc.getSymbol();
|
||||||
if (Symbol != Obj->symbol_end()) {
|
if (Symbol != Obj->symbol_end()) {
|
||||||
if (error(Symbol->getName(TargetName)))
|
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
|
if (error(TargetNameOrErr.getError()))
|
||||||
return;
|
return;
|
||||||
|
TargetName = *TargetNameOrErr;
|
||||||
}
|
}
|
||||||
} else if (!IsScattered) {
|
} else if (!IsScattered) {
|
||||||
section_iterator SecI = Obj->getRelocationSection(DR);
|
section_iterator SecI = Obj->getRelocationSection(DR);
|
||||||
@ -538,8 +540,8 @@ void MachODumper::printDynamicSymbols() {
|
|||||||
|
|
||||||
void MachODumper::printSymbol(const SymbolRef &Symbol) {
|
void MachODumper::printSymbol(const SymbolRef &Symbol) {
|
||||||
StringRef SymbolName;
|
StringRef SymbolName;
|
||||||
if (Symbol.getName(SymbolName))
|
if (ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName())
|
||||||
SymbolName = "";
|
SymbolName = *SymbolNameOrErr;
|
||||||
|
|
||||||
MachOSymbol MOSymbol;
|
MachOSymbol MOSymbol;
|
||||||
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
|
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
|
||||||
|
@ -118,19 +118,19 @@ static std::string formatSymbol(const Dumper::Context &Ctx,
|
|||||||
std::string Buffer;
|
std::string Buffer;
|
||||||
raw_string_ostream OS(Buffer);
|
raw_string_ostream OS(Buffer);
|
||||||
|
|
||||||
StringRef Name;
|
|
||||||
SymbolRef Symbol;
|
SymbolRef Symbol;
|
||||||
if (Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData) ||
|
if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
|
||||||
Symbol.getName(Name)) {
|
if (ErrorOr<StringRef> Name = Symbol.getName()) {
|
||||||
OS << format(" (0x%" PRIX64 ")", Offset);
|
OS << *Name;
|
||||||
return OS.str();
|
if (Displacement > 0)
|
||||||
|
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
|
||||||
|
else
|
||||||
|
OS << format(" (0x%" PRIX64 ")", Offset);
|
||||||
|
return OS.str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << Name;
|
OS << format(" (0x%" PRIX64 ")", Offset);
|
||||||
if (Displacement > 0)
|
|
||||||
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
|
|
||||||
else
|
|
||||||
OS << format(" (0x%" PRIX64 ")", Offset);
|
|
||||||
return OS.str();
|
return OS.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,10 +266,10 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
|
|||||||
for (const auto &P : SymAddr) {
|
for (const auto &P : SymAddr) {
|
||||||
object::SymbolRef Sym = P.first;
|
object::SymbolRef Sym = P.first;
|
||||||
if (Sym.getType() == object::SymbolRef::ST_Function) {
|
if (Sym.getType() == object::SymbolRef::ST_Function) {
|
||||||
StringRef Name;
|
ErrorOr<StringRef> Name = Sym.getName();
|
||||||
uint64_t Addr;
|
if (!Name)
|
||||||
if (Sym.getName(Name))
|
|
||||||
continue;
|
continue;
|
||||||
|
uint64_t Addr;
|
||||||
if (Sym.getAddress(Addr))
|
if (Sym.getAddress(Addr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -288,7 +288,8 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
|
|||||||
Addr += SectionLoadAddress - Sec->getAddress();
|
Addr += SectionLoadAddress - Sec->getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
outs() << "Function: " << Name << ", Size = " << Size << ", Addr = " << Addr << "\n";
|
outs() << "Function: " << *Name << ", Size = " << Size
|
||||||
|
<< ", Addr = " << Addr << "\n";
|
||||||
|
|
||||||
DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
|
DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
|
||||||
DILineInfoTable::iterator Begin = Lines.begin();
|
DILineInfoTable::iterator Begin = Lines.begin();
|
||||||
|
@ -100,9 +100,10 @@ void ModuleInfo::addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
|
|||||||
OpdExtractor->isValidOffsetForAddress(OpdOffset32))
|
OpdExtractor->isValidOffsetForAddress(OpdOffset32))
|
||||||
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
|
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
|
||||||
}
|
}
|
||||||
StringRef SymbolName;
|
ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName();
|
||||||
if (error(Symbol.getName(SymbolName)))
|
if (error(SymbolNameOrErr.getError()))
|
||||||
return;
|
return;
|
||||||
|
StringRef SymbolName = *SymbolNameOrErr;
|
||||||
// Mach-O symbol table names have leading underscore, skip it.
|
// Mach-O symbol table names have leading underscore, skip it.
|
||||||
if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
|
if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
|
||||||
SymbolName = SymbolName.drop_front();
|
SymbolName = SymbolName.drop_front();
|
||||||
|
@ -120,7 +120,10 @@ void COFFDumper::dumpSections(unsigned NumSections) {
|
|||||||
const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
|
const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
|
||||||
COFFYAML::Relocation Rel;
|
COFFYAML::Relocation Rel;
|
||||||
object::symbol_iterator Sym = Reloc.getSymbol();
|
object::symbol_iterator Sym = Reloc.getSymbol();
|
||||||
Sym->getName(Rel.SymbolName);
|
ErrorOr<StringRef> SymbolNameOrErr = Sym->getName();
|
||||||
|
if (std::error_code EC = SymbolNameOrErr.getError())
|
||||||
|
report_fatal_error(EC.message());
|
||||||
|
Rel.SymbolName = *SymbolNameOrErr;
|
||||||
Rel.VirtualAddress = reloc->VirtualAddress;
|
Rel.VirtualAddress = reloc->VirtualAddress;
|
||||||
Rel.Type = reloc->Type;
|
Rel.Type = reloc->Type;
|
||||||
Relocations.push_back(Rel);
|
Relocations.push_back(Rel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user