}
protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
- std::error_code getSymbolName(DataRefImpl Symb,
- StringRef &Res) const override;
+ ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
ELFFile<ELFT> EF;
void moveSymbolNext(DataRefImpl &Symb) const override;
- std::error_code getSymbolName(DataRefImpl Symb,
- StringRef &Res) const override;
+ ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
}
template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym,
- StringRef &Result) const {
+ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
const Elf_Sym *ESym = toELFSymIter(Sym);
- ErrorOr<StringRef> Name = EF.getSymbolName(ESym, Sym.p & 1);
- if (!Name)
- return Name.getError();
- Result = *Name;
- return std::error_code();
+ return EF.getSymbolName(ESym, Sym.p & 1);
}
template <class ELFT>
void moveSymbolNext(DataRefImpl &Symb) const override;
uint64_t getNValue(DataRefImpl Sym) const;
- std::error_code getSymbolName(DataRefImpl Symb,
- StringRef &Res) const override;
+ ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
// MachO specific.
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
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
/// mapped).
std::error_code getAddress(uint64_t &Result) const;
// Implementations assume that the DataRefImpl is valid and has not been
// modified externally. It's UB otherwise.
friend class SymbolRef;
- virtual std::error_code getSymbolName(DataRefImpl Symb,
- StringRef &Res) const = 0;
+ virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
std::error_code printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const override;
virtual std::error_code getSymbolAddress(DataRefImpl Symb,
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
: BasicSymbolRef(SymbolP, Owner) {}
-inline std::error_code SymbolRef::getName(StringRef &Result) const {
- return getObject()->getSymbolName(getRawDataRefImpl(), Result);
+inline ErrorOr<StringRef> SymbolRef::getName() const {
+ return getObject()->getSymbolName(getRawDataRefImpl());
}
inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
SymType == object::SymbolRef::ST_Data ||
SymType == object::SymbolRef::ST_Unknown) {
- StringRef Name;
+ ErrorOr<StringRef> NameOrErr = I->getName();
+ Check(NameOrErr.getError());
+ StringRef Name = *NameOrErr;
uint64_t SectOffset;
- Check(I->getName(Name));
Check(getOffset(*I, SectOffset));
section_iterator SI = Obj.section_end();
Check(I->getSection(SI));
DEBUG(dbgs() << "Processing common symbols...\n");
for (const auto &Sym : CommonSymbols) {
- StringRef Name;
- Check(Sym.getName(Name));
+ ErrorOr<StringRef> NameOrErr = Sym.getName();
+ Check(NameOrErr.getError());
+ StringRef Name = *NameOrErr;
// Skip common symbols already elsewhere.
if (GlobalSymbolTable.count(Name) ||
// Assign the address of each symbol
for (auto &Sym : SymbolsToAllocate) {
uint32_t Align = Sym.getAlignment();
- StringRef Name;
uint64_t Size = Sym.getCommonSize();
- Check(Sym.getName(Name));
+ ErrorOr<StringRef> NameOrErr = Sym.getName();
+ Check(NameOrErr.getError());
+ StringRef Name = *NameOrErr;
if (Align) {
// This symbol has an alignment requirement.
uint64_t AlignOffset = OffsetToAlignment((uint64_t)Addr, Align);
// Obtain the symbol name which is referenced in the relocation
StringRef TargetName;
- if (Symbol != Obj.symbol_end())
- Symbol->getName(TargetName);
+ if (Symbol != Obj.symbol_end()) {
+ 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
<< " TargetName: " << TargetName << "\n");
RelocationValueRef Value;
bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
if (IsExternal) {
symbol_iterator Symbol = RI->getSymbol();
- StringRef TargetName;
- Symbol->getName(TargetName);
+ ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
+ if (std::error_code EC = TargetNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef TargetName = *TargetNameOrErr;
RTDyldSymbolTable::const_iterator SI =
GlobalSymbolTable.find(TargetName.data());
if (SI != GlobalSymbolTable.end()) {
unsigned SymbolIndex =
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
- StringRef IndirectSymbolName;
- SI->getName(IndirectSymbolName);
+ ErrorOr<StringRef> IndirectSymbolNameOrErr = SI->getName();
+ if (std::error_code EC = IndirectSymbolNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef IndirectSymbolName = *IndirectSymbolNameOrErr;
DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
<< ", PT offset: " << PTEntryOffset << "\n");
RelocationEntry RE(PTSectionID, PTEntryOffset,
break;
}
- StringRef TargetName;
- Symbol->getName(TargetName);
+ ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
+ if (std::error_code EC = TargetNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef TargetName = *TargetNameOrErr;
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
<< " RelType: " << RelType << " TargetName: " << TargetName
unsigned SymbolIndex =
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
- StringRef IndirectSymbolName;
- SI->getName(IndirectSymbolName);
+ ErrorOr<StringRef> IndirectSymbolName = SI->getName();
+ if (std::error_code EC = IndirectSymbolName.getError())
+ report_fatal_error(EC.message());
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
createStubFunction(JTEntryAddr);
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
MachO::GENERIC_RELOC_VANILLA, 0, true, 2);
- addRelocationForSymbol(RE, IndirectSymbolName);
+ addRelocationForSymbol(RE, *IndirectSymbolName);
JTEntryOffset += JTEntrySize;
}
}
}
}
-std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
- StringRef &Result) const {
+ErrorOr<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
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 {
Symb.p += SymbolTableEntrySize;
}
-std::error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
- StringRef &Res) const {
+ErrorOr<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
StringRef StringTable = getStringTableData();
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
const char *Start = &StringTable.data()[Entry.n_strx];
if (Start < getData().begin() || Start >= getData().end())
report_fatal_error(
"Symbol name entry points before beginning or past end of file.");
- Res = StringRef(Start);
- return std::error_code();
+ return StringRef(Start);
}
unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
// SymbolRef accessors
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
- StringRef ret;
- if (std::error_code ec = (*unwrap(SI))->getName(ret))
- report_fatal_error(ec.message());
- return ret.data();
+ ErrorOr<StringRef> Ret = (*unwrap(SI))->getName();
+ if (std::error_code EC = Ret.getError())
+ report_fatal_error(EC.message());
+ return Ret->data();
}
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const {
- StringRef Name;
- if (std::error_code EC = getSymbolName(Symb, Name))
+ ErrorOr<StringRef> Name = getSymbolName(Symb);
+ if (std::error_code EC = Name.getError())
return EC;
- OS << Name;
+ OS << *Name;
return std::error_code();
}
uint64_t RelType = Rel.getType();
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 SymSize = SymI->getSize();
int64_t Addend = *ELFRelocationRef(Rel).getAddend();
uint64_t RelType = Rel.getType();
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);
any_relocation_info RE = Obj->getRelocation(Rel.getRawDataRefImpl());
symbol_iterator RSymI = Rel.getSymbol();
uint64_t RSymAddr;
RSymI->getAddress(RSymAddr);
- StringRef RSymName;
- RSymI->getName(RSymName);
+ ErrorOr<StringRef> RSymName = RSymI->getName();
+ 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())
RSym->setVariableValue(MCConstantExpr::create(RSymAddr, Ctx));
// during the test, we can't hardcode the symbols addresses, so
// look them up here and rewrite them.
for (const auto &Sym : ErrOrObjectFile->symbols()) {
- StringRef Name;
uint64_t Address;
- if (Sym.getName(Name) || Sym.getAddress(Address))
+ if (Sym.getAddress(Address))
continue;
- SymbolAddresses[Name] = Address;
+ ErrorOr<StringRef> Name = Sym.getName();
+ if (!Name)
+ continue;
+ SymbolAddresses[*Name] = Address;
}
}
auto Sym = Reloc.getSymbol();
if (Sym != Obj.symbol_end()) {
- StringRef SymbolName;
- if (Sym->getName(SymbolName)) {
+ ErrorOr<StringRef> SymbolName = Sym->getName();
+ if (!SymbolName) {
reportWarning("error getting relocation symbol name.");
continue;
}
- if (const auto *Mapping = DMO.lookupSymbol(SymbolName))
+ if (const auto *Mapping = DMO.lookupSymbol(*SymbolName))
ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
} else if (const auto *Mapping = DMO.lookupObjectAddress(Addend)) {
// Do not store the addend. The addend was the address of the
CurrentObjectAddresses.clear();
for (auto Sym : CurrentObjectHolder.Get().symbols()) {
- StringRef Name;
+
uint64_t Addr;
- if (Sym.getAddress(Addr) || Addr == UnknownAddress || Sym.getName(Name))
+ if (Sym.getAddress(Addr) || Addr == UnknownAddress)
+ continue;
+ ErrorOr<StringRef> Name = Sym.getName();
+ if (!Name)
continue;
- CurrentObjectAddresses[Name] = Addr;
+ CurrentObjectAddresses[*Name] = Addr;
}
}
// Skip undefined and STAB entries.
if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
continue;
- StringRef Name;
uint64_t Addr;
// The only symbols of interest are the global variables. These
// are the only ones that need to be queried because the address
// addresses should be fetched for the debug map.
if (Sym.getAddress(Addr) || Addr == UnknownAddress ||
!(Sym.getFlags() & SymbolRef::SF_Global) || Sym.getSection(Section) ||
- Section->isText() || Sym.getName(Name) || Name.size() == 0 ||
- Name[0] == '\0')
+ Section->isText())
+ continue;
+ ErrorOr<StringRef> NameOrErr = Sym.getName();
+ if (!NameOrErr)
+ continue;
+ StringRef Name = *NameOrErr;
+ if (Name.size() == 0 || Name[0] == '\0')
continue;
MainBinarySymbolAddresses[Name] = Addr;
}
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
if (RelocSymI == Obj->symbol_end())
continue;
- StringRef RelocSymName;
- if (error(RelocSymI->getName(RelocSymName)))
+ ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
+ if (error(RelocSymName.getError()))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd) {
- *I = RelocSymName;
+ *I = *RelocSymName;
++I;
}
}
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
if (RelocSymI == Obj->symbol_end())
continue;
- StringRef RelocSymName;
- if (error(RelocSymI->getName(RelocSymName)))
+ ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
+ if (error(RelocSymName.getError()))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd)
- Collection[std::make_pair(SymName, Offset - SymOffset)] = RelocSymName;
+ Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
}
}
return false;
for (auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
uint64_t SymSize = P.second;
- StringRef SymName;
- if (error(Sym.getName(SymName)))
+ ErrorOr<StringRef> SymNameOrErr = Sym.getName();
+ if (error(SymNameOrErr.getError()))
return;
+ StringRef SymName = *SymNameOrErr;
object::section_iterator SecI(Obj->section_begin());
if (error(Sym.getSection(SecI)))
return;
}
if (SymI->getELFType() == ELF::STT_SECTION) {
- StringRef Name;
- if (error(SymI->getName(Name)))
+ ErrorOr<StringRef> Name = SymI->getName();
+ if (error(Name.getError()))
return '?';
- return StringSwitch<char>(Name)
+ return StringSwitch<char>(*Name)
.StartsWith(".debug", 'N')
.StartsWith(".note", 'n')
.Default('?');
// OK, this is COFF.
symbol_iterator SymI(I);
- StringRef Name;
- if (error(SymI->getName(Name)))
+ ErrorOr<StringRef> Name = SymI->getName();
+ if (error(Name.getError()))
return '?';
- char Ret = StringSwitch<char>(Name)
+ char Ret = StringSwitch<char>(*Name)
.StartsWith(".debug", 'N')
.StartsWith(".sxdata", 'N')
.Default('?');
SymbolRef Sym;
if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
return EC;
- if (std::error_code EC = Sym.getName(Name))
+ ErrorOr<StringRef> NameOrErr = Sym.getName();
+ if (std::error_code EC = NameOrErr.getError())
return EC;
+ Name = *NameOrErr;
return std::error_code();
}
SmallVectorImpl<uint64_t> &FoundFns,
uint64_t &BaseSegmentAddress) {
for (const SymbolRef &Symbol : MachOObj->symbols()) {
- StringRef SymName;
- Symbol.getName(SymName);
- if (!SymName.startswith("ltmp"))
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ if (!SymName->startswith("ltmp"))
Symbols.push_back(Symbol);
}
if (indirect_symbol < Symtab.nsyms) {
symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
SymbolRef Symbol = *Sym;
- StringRef SymName;
- Symbol.getName(SymName);
- outs() << SymName;
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ outs() << *SymName;
} else {
outs() << "?";
}
ST == SymbolRef::ST_Other) {
uint64_t Address;
Symbol.getAddress(Address);
- StringRef SymName;
- Symbol.getName(SymName);
+ ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
+ if (std::error_code EC = SymNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef SymName = *SymNameOrErr;
if (!SymName.startswith(".objc"))
(*AddrMap)[Address] = SymName;
}
[&](const std::pair<uint64_t, SymbolRef> &P) { return P.first == i; });
if (Reloc != Relocs.end()) {
symbol_iterator RelocSym = Reloc->second;
- StringRef SymName;
- RelocSym->getName(SymName);
- outs() << "external relocation entry for symbol:" << SymName << "\n";
+ ErrorOr<StringRef> SymName = RelocSym->getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ outs() << "external relocation entry for symbol:" << *SymName << "\n";
continue;
}
}
}
if (reloc_found && isExtern) {
- StringRef SymName;
- Symbol.getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
op_info->AddSymbol.Present = 1;
op_info->AddSymbol.Name = name;
// For i386 extern relocation entries the value in the instruction is
// is the offset from the external symbol.
if (info->O->getAnyRelocationPCRel(RE))
op_info->Value -= Pc + Offset + Size;
- StringRef SymName;
- Symbol.getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
unsigned Type = info->O->getAnyRelocationType(RE);
if (Type == MachO::X86_64_RELOC_SUBTRACTOR) {
DataRefImpl RelNext = Rel;
op_info->SubtractSymbol.Name = name;
symbol_iterator RelocSymNext = info->O->getSymbolByIndex(SymbolNum);
Symbol = *RelocSymNext;
- StringRef SymNameNext;
- Symbol.getName(SymNameNext);
- name = SymNameNext.data();
+ ErrorOr<StringRef> SymNameNext = Symbol.getName();
+ if (std::error_code EC = SymNameNext.getError())
+ report_fatal_error(EC.message());
+ name = SymNameNext->data();
}
}
// TODO: add the VariantKinds to op_info->VariantKind for relocation types
}
if (isExtern) {
- StringRef SymName;
- Symbol.getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
op_info->AddSymbol.Present = 1;
op_info->AddSymbol.Name = name;
switch (r_type) {
// NOTE: Scattered relocations don't exist on arm64.
if (!info->O->getPlainRelocationExternal(RE))
return 0;
- StringRef SymName;
- Reloc->getSymbol()->getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Reloc->getSymbol()->getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
op_info->AddSymbol.Present = 1;
op_info->AddSymbol.Name = name;
if (indirect_symbol < Symtab.nsyms) {
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
SymbolRef Symbol = *Sym;
- StringRef SymName;
- Symbol.getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
return name;
}
}
if (indirect_symbol < Symtab.nsyms) {
symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
SymbolRef Symbol = *Sym;
- StringRef SymName;
- Symbol.getName(SymName);
- const char *name = SymName.data();
+ ErrorOr<StringRef> SymName = Symbol.getName();
+ if (std::error_code EC = SymName.getError())
+ report_fatal_error(EC.message());
+ const char *name = SymName->data();
return name;
}
}
Symbol.getAddress(n_value);
if (n_value == UnknownAddress)
n_value = 0;
- StringRef name;
- Symbol.getName(name);
- if (!name.empty()) {
- SymbolName = name.data();
+ ErrorOr<StringRef> NameOrError = Symbol.getName();
+ if (std::error_code EC = NameOrError.getError())
+ report_fatal_error(EC.message());
+ StringRef Name = *NameOrError;
+ if (!Name.empty()) {
+ SymbolName = Name.data();
return SymbolName;
}
}
ST == SymbolRef::ST_Other) {
uint64_t Address;
Symbol.getAddress(Address);
- StringRef SymName;
- Symbol.getName(SymName);
+ ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
+ if (std::error_code EC = SymNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef SymName = *SymNameOrErr;
AddrMap[Address] = SymName;
if (!DisSymName.empty() && DisSymName == SymName)
DisSymNameFound = true;
// Disassemble symbol by symbol.
for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
- StringRef SymName;
- Symbols[SymIdx].getName(SymName);
+ ErrorOr<StringRef> SymNameOrErr = Symbols[SymIdx].getName();
+ if (std::error_code EC = SymNameOrErr.getError())
+ report_fatal_error(EC.message());
+ StringRef SymName = *SymNameOrErr;
SymbolRef::Type ST = Symbols[SymIdx].getType();
if (ST != SymbolRef::ST_Function)
const RelocationRef &Reloc, uint64_t Addr,
StringRef &Name, uint64_t &Addend) {
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;
return;
}
Sym->second.getSection(SymSection);
if (RelocSection == *SymSection) {
// 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;
return;
}
const RelocationRef &Rel,
SmallVectorImpl<char> &Result) {
symbol_iterator SymI = Rel.getSymbol();
- StringRef SymName;
- if (std::error_code EC = SymI->getName(SymName))
+ ErrorOr<StringRef> SymNameOrErr = SymI->getName();
+ if (std::error_code EC = SymNameOrErr.getError())
return EC;
+ StringRef SymName = *SymNameOrErr;
Result.append(SymName.begin(), SymName.end());
return std::error_code();
}
for (const SymbolRef &Symbol : O->symbols()) {
std::error_code ec;
uint64_t Addr;
- StringRef Name;
+ ErrorOr<StringRef> Name = Symbol.getName();
if ((ec = Symbol.getAddress(Addr)))
report_fatal_error(ec.message());
if (Addr != Val)
continue;
- if ((ec = Symbol.getName(Name)))
- report_fatal_error(ec.message());
- fmt << Name;
+ if (std::error_code EC = Name.getError())
+ report_fatal_error(EC.message());
+ fmt << *Name;
return;
}
if (isExtern) {
symbol_iterator SI = O->symbol_begin();
advance(SI, Val);
- SI->getName(S);
+ ErrorOr<StringRef> SOrErr = SI->getName();
+ if (!error(SOrErr.getError()))
+ S = *SOrErr;
} else {
section_iterator SI = O->section_begin();
// Adjust for the fact that sections are 1-indexed.
if (Address >= SectSize)
continue;
- StringRef Name;
- if (error(Symbol.getName(Name)))
+ ErrorOr<StringRef> Name = Symbol.getName();
+ if (error(Name.getError()))
break;
- Symbols.push_back(std::make_pair(Address, Name));
+ Symbols.push_back(std::make_pair(Address, *Name));
}
}
StringRef Name;
if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
Section->getName(Name);
- } else if (error(Symbol.getName(Name))) {
- continue;
+ } else {
+ ErrorOr<StringRef> NameOrErr = Symbol.getName();
+ if (error(NameOrErr.getError()))
+ continue;
+ Name = *NameOrErr;
}
bool Global = Flags & SymbolRef::SF_Global;
if (!Symbol)
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
- StringRef Name;
- if (Symbol)
- Symbol->getName(Name);
+ ErrorOr<StringRef> Name = Symbol->getName();
+ if (std::error_code EC = Name.getError())
+ report_fatal_error(EC.message());
ListScope EHS(SW, "ExceptionHandler");
- SW.printString("Routine", formatSymbol(Name, Address));
+ SW.printString("Routine", formatSymbol(*Name, Address));
SW.printHex("Parameter", Parameter);
}
StringRef FunctionName;
uint64_t FunctionAddress;
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);
} else {
const pe32_header *PEHeader;
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
if (XDataRecord) {
- StringRef Name;
- uint64_t Address;
+ ErrorOr<StringRef> Name = XDataRecord->getName();
+ if (std::error_code EC = Name.getError())
+ report_fatal_error(EC.message());
- XDataRecord->getName(Name);
+ uint64_t Address;
XDataRecord->getAddress(Address);
- SW.printString("ExceptionRecord", formatSymbol(Name, Address));
+ SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
section_iterator SI = COFF.section_end();
if (XDataRecord->getSection(SI))
StringRef FunctionName;
uint64_t FunctionAddress;
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);
} else {
const pe32_header *PEHeader;
SymbolRef Symbol;
if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
return EC;
- if (std::error_code EC = Symbol.getName(Name))
+ ErrorOr<StringRef> NameOrErr = Symbol.getName();
+ if (std::error_code EC = NameOrErr.getError())
return EC;
+ Name = *NameOrErr;
return std::error_code();
}
StringRef SymbolName;
Reloc.getTypeName(RelocName);
symbol_iterator Symbol = Reloc.getSymbol();
- if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
- return;
+ if (Symbol != Obj->symbol_end()) {
+ ErrorOr<StringRef> SymbolNameOrErr = Symbol->getName();
+ if (error(SymbolNameOrErr.getError()))
+ return;
+ SymbolName = *SymbolNameOrErr;
+ }
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
if (IsExtern) {
symbol_iterator Symbol = Reloc.getSymbol();
if (Symbol != Obj->symbol_end()) {
- if (error(Symbol->getName(TargetName)))
+ ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
+ if (error(TargetNameOrErr.getError()))
return;
+ TargetName = *TargetNameOrErr;
}
} else if (!IsScattered) {
section_iterator SecI = Obj->getRelocationSection(DR);
void MachODumper::printSymbol(const SymbolRef &Symbol) {
StringRef SymbolName;
- if (Symbol.getName(SymbolName))
- SymbolName = "";
+ if (ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName())
+ SymbolName = *SymbolNameOrErr;
MachOSymbol MOSymbol;
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
std::string Buffer;
raw_string_ostream OS(Buffer);
- StringRef Name;
SymbolRef Symbol;
- if (Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData) ||
- Symbol.getName(Name)) {
- OS << format(" (0x%" PRIX64 ")", Offset);
- return OS.str();
+ if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
+ if (ErrorOr<StringRef> Name = Symbol.getName()) {
+ OS << *Name;
+ if (Displacement > 0)
+ OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
+ else
+ OS << format(" (0x%" PRIX64 ")", Offset);
+ return OS.str();
+ }
}
- OS << Name;
- if (Displacement > 0)
- OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
- else
- OS << format(" (0x%" PRIX64 ")", Offset);
+ OS << format(" (0x%" PRIX64 ")", Offset);
return OS.str();
}
for (const auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
if (Sym.getType() == object::SymbolRef::ST_Function) {
- StringRef Name;
- uint64_t Addr;
- if (Sym.getName(Name))
+ ErrorOr<StringRef> Name = Sym.getName();
+ if (!Name)
continue;
+ uint64_t Addr;
if (Sym.getAddress(Addr))
continue;
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::iterator Begin = Lines.begin();
OpdExtractor->isValidOffsetForAddress(OpdOffset32))
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
}
- StringRef SymbolName;
- if (error(Symbol.getName(SymbolName)))
+ ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName();
+ if (error(SymbolNameOrErr.getError()))
return;
+ StringRef SymbolName = *SymbolNameOrErr;
// Mach-O symbol table names have leading underscore, skip it.
if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
SymbolName = SymbolName.drop_front();
const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
COFFYAML::Relocation Rel;
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.Type = reloc->Type;
Relocations.push_back(Rel);