[llvm] r241297 - Return ErrorOr from SymbolRef::getName.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jul 2 13:55:22 PDT 2015
Author: rafael
Date: Thu Jul 2 15:55:21 2015
New Revision: 241297
URL: http://llvm.org/viewvc/llvm-project?rev=241297&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/lib/Object/Object.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp
llvm/trunk/tools/dsymutil/DebugMap.cpp
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-objdump/MachODump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/tools/llvm-readobj/MachODumper.cpp
llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp
llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
llvm/trunk/tools/obj2yaml/coff2yaml.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Thu Jul 2 15:55:21 2015
@@ -647,8 +647,7 @@ public:
}
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;
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu Jul 2 15:55:21 2015
@@ -195,8 +195,7 @@ protected:
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;
@@ -349,14 +348,9 @@ void ELFObjectFile<ELFT>::moveSymbolNext
}
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>
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Thu Jul 2 15:55:21 2015
@@ -199,8 +199,7 @@ public:
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;
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Thu Jul 2 15:55:21 2015
@@ -132,7 +132,7 @@ public:
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;
@@ -195,8 +195,7 @@ protected:
// 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,
@@ -305,8 +304,8 @@ public:
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 {
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Thu Jul 2 15:55:21 2015
@@ -181,9 +181,10 @@ RuntimeDyldImpl::loadObjectImpl(const ob
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));
@@ -481,8 +482,9 @@ void RuntimeDyldImpl::emitCommonSymbols(
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) ||
@@ -515,9 +517,10 @@ void RuntimeDyldImpl::emitCommonSymbols(
// 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);
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Thu Jul 2 15:55:21 2015
@@ -1064,8 +1064,12 @@ relocation_iterator RuntimeDyldELF::proc
// 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;
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Thu Jul 2 15:55:21 2015
@@ -63,8 +63,10 @@ RelocationValueRef RuntimeDyldMachO::get
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()) {
@@ -162,8 +164,10 @@ void RuntimeDyldMachO::populateIndirectS
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,
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h Thu Jul 2 15:55:21 2015
@@ -155,8 +155,10 @@ public:
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
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h Thu Jul 2 15:55:21 2015
@@ -240,13 +240,14 @@ private:
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;
}
}
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Jul 2 15:55:21 2015
@@ -145,10 +145,13 @@ void COFFObjectFile::moveSymbolNext(Data
}
}
-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 {
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Thu Jul 2 15:55:21 2015
@@ -327,16 +327,14 @@ void MachOObjectFile::moveSymbolNext(Dat
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 {
Modified: llvm/trunk/lib/Object/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Object.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Object.cpp (original)
+++ llvm/trunk/lib/Object/Object.cpp Thu Jul 2 15:55:21 2015
@@ -173,10 +173,10 @@ void LLVMMoveToNextRelocation(LLVMReloca
// 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) {
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Thu Jul 2 15:55:21 2015
@@ -37,10 +37,10 @@ bool SectionRef::containsSymbol(SymbolRe
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();
}
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp Thu Jul 2 15:55:21 2015
@@ -29,7 +29,11 @@ public:
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();
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp Thu Jul 2 15:55:21 2015
@@ -30,7 +30,10 @@ public:
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());
@@ -89,10 +92,11 @@ public:
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));
Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Thu Jul 2 15:55:21 2015
@@ -216,11 +216,13 @@ MappingTraits<dsymutil::DebugMapObject>:
// 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;
}
}
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Thu Jul 2 15:55:21 2015
@@ -1462,12 +1462,12 @@ void DwarfLinker::findValidRelocsMachO(c
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
Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Thu Jul 2 15:55:21 2015
@@ -197,11 +197,14 @@ void MachODebugMapParser::loadCurrentObj
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;
}
}
@@ -225,7 +228,6 @@ void MachODebugMapParser::loadMainBinary
// 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
@@ -233,8 +235,13 @@ void MachODebugMapParser::loadMainBinary
// 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;
}
Modified: llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp (original)
+++ llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp Thu Jul 2 15:55:21 2015
@@ -97,12 +97,12 @@ static bool collectRelocatedSymbols(cons
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;
}
}
@@ -121,12 +121,12 @@ static bool collectRelocationOffsets(
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;
@@ -190,9 +190,10 @@ static void dumpCXXData(const ObjectFile
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;
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Thu Jul 2 15:55:21 2015
@@ -653,10 +653,10 @@ static char getSymbolNMTypeChar(ELFObjec
}
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('?');
@@ -670,11 +670,11 @@ static char getSymbolNMTypeChar(COFFObje
// 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('?');
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Thu Jul 2 15:55:21 2015
@@ -213,8 +213,10 @@ static std::error_code resolveSymbolName
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();
}
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Thu Jul 2 15:55:21 2015
@@ -282,9 +282,10 @@ static void getSectionsAndSymbols(MachOO
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);
}
@@ -361,9 +362,10 @@ static void PrintIndirectSymbolTable(Mac
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() << "?";
}
@@ -592,8 +594,10 @@ static void CreateSymbolAddressMap(MachO
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;
}
@@ -830,9 +834,10 @@ static void DumpLiteralPointerSection(Ma
[&](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;
}
@@ -1793,9 +1798,10 @@ static int SymbolizerGetOpInfo(void *Dis
}
}
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
@@ -1859,9 +1865,10 @@ static int SymbolizerGetOpInfo(void *Dis
// 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;
@@ -1875,9 +1882,10 @@ static int SymbolizerGetOpInfo(void *Dis
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
@@ -1944,9 +1952,10 @@ static int SymbolizerGetOpInfo(void *Dis
}
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) {
@@ -2056,9 +2065,10 @@ static int SymbolizerGetOpInfo(void *Dis
// 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;
@@ -2185,9 +2195,10 @@ static const char *GuessIndirectSymbol(u
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;
}
}
@@ -2219,9 +2230,10 @@ static const char *GuessIndirectSymbol(u
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;
}
}
@@ -2447,10 +2459,12 @@ static const char *get_symbol_64(uint32_
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;
}
}
@@ -6119,8 +6133,10 @@ static void DisassembleMachO(StringRef F
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;
@@ -6159,8 +6175,10 @@ static void DisassembleMachO(StringRef F
// 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)
@@ -6423,7 +6441,10 @@ static void findUnwindRelocNameAddend(co
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;
}
@@ -6449,7 +6470,10 @@ static void findUnwindRelocNameAddend(co
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;
}
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Thu Jul 2 15:55:21 2015
@@ -433,9 +433,10 @@ static std::error_code getRelocationValu
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();
}
@@ -455,15 +456,15 @@ static void printRelocationTargetName(co
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;
}
@@ -493,7 +494,9 @@ static void printRelocationTargetName(co
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.
@@ -830,10 +833,10 @@ static void DisassembleObject(const Obje
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));
}
}
@@ -1121,8 +1124,11 @@ void llvm::PrintSymbolTable(const Object
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;
Modified: llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp Thu Jul 2 15:55:21 2015
@@ -567,12 +567,12 @@ bool Decoder::dumpXDataRecord(const COFF
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);
}
@@ -601,7 +601,10 @@ bool Decoder::dumpUnpackedEntry(const CO
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;
@@ -613,13 +616,14 @@ bool Decoder::dumpUnpackedEntry(const CO
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))
@@ -658,7 +662,10 @@ bool Decoder::dumpPackedEntry(const obje
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;
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Thu Jul 2 15:55:21 2015
@@ -139,8 +139,10 @@ std::error_code COFFDumper::resolveSymbo
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();
}
@@ -809,8 +811,12 @@ void COFFDumper::printRelocation(const S
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");
Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/MachODumper.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Thu Jul 2 15:55:21 2015
@@ -474,8 +474,10 @@ void MachODumper::printRelocation(const
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);
@@ -538,8 +540,8 @@ void MachODumper::printDynamicSymbols()
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);
Modified: llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp Thu Jul 2 15:55:21 2015
@@ -118,19 +118,19 @@ static std::string formatSymbol(const Du
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();
}
Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Thu Jul 2 15:55:21 2015
@@ -266,10 +266,10 @@ static int printLineInfoForInput(bool Lo
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;
@@ -288,7 +288,8 @@ static int printLineInfoForInput(bool Lo
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();
Modified: llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp Thu Jul 2 15:55:21 2015
@@ -100,9 +100,10 @@ void ModuleInfo::addSymbol(const SymbolR
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();
Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=241297&r1=241296&r2=241297&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Thu Jul 2 15:55:21 2015
@@ -120,7 +120,10 @@ void COFFDumper::dumpSections(unsigned N
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);
More information about the llvm-commits
mailing list