mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Thread Expected<...> up from libObject’s getName() for symbols to allow llvm-objdump to produce a good error message.
Produce another specific error message for a malformed Mach-O file when a symbol’s string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test for macho-invalid-symbol-name-past-eof now reports the error with the message indicating that a symbol at a specific index has a bad sting index and that bad string index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. There is some code for this that could be factored into a routine but I would like to leave that for the code owners post-commit to do as they want for handling an llvm::Error. An example of how this could be done is shown in the diff in lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine already for std::error_code so I added one like it for llvm::Error . Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values. So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there fixes needed to lld that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 266919
This commit is contained in:
parent
d8b3e72047
commit
92582f2b18
@ -158,10 +158,12 @@ private:
|
|||||||
for (auto &Symbol : getObject(*Obj).symbols()) {
|
for (auto &Symbol : getObject(*Obj).symbols()) {
|
||||||
if (Symbol.getFlags() & object::SymbolRef::SF_Undefined)
|
if (Symbol.getFlags() & object::SymbolRef::SF_Undefined)
|
||||||
continue;
|
continue;
|
||||||
ErrorOr<StringRef> SymbolName = Symbol.getName();
|
Expected<StringRef> SymbolName = Symbol.getName();
|
||||||
// FIXME: Raise an error for bad symbols.
|
// FIXME: Raise an error for bad symbols.
|
||||||
if (!SymbolName)
|
if (!SymbolName) {
|
||||||
|
consumeError(SymbolName.takeError());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol);
|
auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol);
|
||||||
SymbolTable.insert(
|
SymbolTable.insert(
|
||||||
std::make_pair(*SymbolName, RuntimeDyld::SymbolInfo(0, Flags)));
|
std::make_pair(*SymbolName, RuntimeDyld::SymbolInfo(0, Flags)));
|
||||||
|
@ -679,7 +679,7 @@ public:
|
|||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void moveSymbolNext(DataRefImpl &Symb) const override;
|
void moveSymbolNext(DataRefImpl &Symb) const override;
|
||||||
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
|
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
|
||||||
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
|
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
|
||||||
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
|
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
|
||||||
|
@ -192,7 +192,7 @@ protected:
|
|||||||
ArrayRef<Elf_Word> ShndxTable;
|
ArrayRef<Elf_Word> ShndxTable;
|
||||||
|
|
||||||
void moveSymbolNext(DataRefImpl &Symb) const override;
|
void moveSymbolNext(DataRefImpl &Symb) const override;
|
||||||
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
|
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
|
||||||
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
|
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
|
||||||
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
|
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
|
||||||
@ -349,7 +349,7 @@ void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
|
Expected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
|
||||||
const Elf_Sym *ESym = getSymbol(Sym);
|
const Elf_Sym *ESym = getSymbol(Sym);
|
||||||
const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a);
|
const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a);
|
||||||
const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link);
|
const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link);
|
||||||
@ -483,11 +483,14 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
|
|||||||
Result |= SymbolRef::SF_FormatSpecific;
|
Result |= SymbolRef::SF_FormatSpecific;
|
||||||
|
|
||||||
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
|
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
|
||||||
if (ErrorOr<StringRef> NameOrErr = getSymbolName(Sym)) {
|
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
if (Name.startswith("$d") || Name.startswith("$t") ||
|
if (Name.startswith("$d") || Name.startswith("$t") ||
|
||||||
Name.startswith("$a"))
|
Name.startswith("$a"))
|
||||||
Result |= SymbolRef::SF_FormatSpecific;
|
Result |= SymbolRef::SF_FormatSpecific;
|
||||||
|
} else {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(NameOrErr.takeError());
|
||||||
}
|
}
|
||||||
if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
|
if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
|
||||||
Result |= SymbolRef::SF_Thumb;
|
Result |= SymbolRef::SF_Thumb;
|
||||||
|
@ -257,14 +257,14 @@ struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {
|
|||||||
return getBinding() != ELF::STB_LOCAL;
|
return getBinding() != ELF::STB_LOCAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> getName(StringRef StrTab) const;
|
Expected<StringRef> getName(StringRef StrTab) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
ErrorOr<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {
|
Expected<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {
|
||||||
uint32_t Offset = this->st_name;
|
uint32_t Offset = this->st_name;
|
||||||
if (Offset >= StrTab.size())
|
if (Offset >= StrTab.size())
|
||||||
return object_error::parse_failed;
|
return errorCodeToError(object_error::parse_failed);
|
||||||
return StringRef(StrTab.data() + Offset);
|
return StringRef(StrTab.data() + Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +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;
|
||||||
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
|
||||||
|
|
||||||
// MachO specific.
|
// MachO specific.
|
||||||
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
|
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
|
||||||
@ -252,6 +252,7 @@ public:
|
|||||||
|
|
||||||
// MachO specific.
|
// MachO specific.
|
||||||
basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
|
basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
|
||||||
|
uint64_t getSymbolIndex(DataRefImpl Symb) const;
|
||||||
|
|
||||||
section_iterator section_begin() const override;
|
section_iterator section_begin() const override;
|
||||||
section_iterator section_end() const override;
|
section_iterator section_end() const override;
|
||||||
|
@ -130,7 +130,7 @@ public:
|
|||||||
assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
|
assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> getName() const;
|
Expected<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).
|
||||||
ErrorOr<uint64_t> getAddress() const;
|
ErrorOr<uint64_t> getAddress() const;
|
||||||
@ -193,7 +193,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 ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
|
virtual Expected<StringRef> getSymbolName(DataRefImpl Symb) 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 ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
|
virtual ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
|
||||||
@ -304,7 +304,7 @@ public:
|
|||||||
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
||||||
: BasicSymbolRef(SymbolP, Owner) {}
|
: BasicSymbolRef(SymbolP, Owner) {}
|
||||||
|
|
||||||
inline ErrorOr<StringRef> SymbolRef::getName() const {
|
inline Expected<StringRef> SymbolRef::getName() const {
|
||||||
return getObject()->getSymbolName(getRawDataRefImpl());
|
return getObject()->getSymbolName(getRawDataRefImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +141,9 @@ std::error_code SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol,
|
|||||||
OpdExtractor->isValidOffsetForAddress(OpdOffset32))
|
OpdExtractor->isValidOffsetForAddress(OpdOffset32))
|
||||||
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
|
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
|
||||||
}
|
}
|
||||||
ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName();
|
Expected<StringRef> SymbolNameOrErr = Symbol.getName();
|
||||||
if (auto EC = SymbolNameOrErr.getError())
|
if (!SymbolNameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(SymbolNameOrErr.takeError());
|
||||||
StringRef SymbolName = *SymbolNameOrErr;
|
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] == '_')
|
||||||
|
@ -174,8 +174,8 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||||||
object::SymbolRef::Type SymType = *SymTypeOrErr;
|
object::SymbolRef::Type SymType = *SymTypeOrErr;
|
||||||
|
|
||||||
// Get symbol name.
|
// Get symbol name.
|
||||||
ErrorOr<StringRef> NameOrErr = I->getName();
|
Expected<StringRef> NameOrErr = I->getName();
|
||||||
Check(NameOrErr.getError());
|
Check(NameOrErr.takeError());
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
|
|
||||||
// Compute JIT symbol flags.
|
// Compute JIT symbol flags.
|
||||||
@ -496,8 +496,8 @@ 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) {
|
||||||
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
Expected<StringRef> NameOrErr = Sym.getName();
|
||||||
Check(NameOrErr.getError());
|
Check(NameOrErr.takeError());
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
|
|
||||||
// Skip common symbols already elsewhere.
|
// Skip common symbols already elsewhere.
|
||||||
@ -533,8 +533,14 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
|
|||||||
for (auto &Sym : SymbolsToAllocate) {
|
for (auto &Sym : SymbolsToAllocate) {
|
||||||
uint32_t Align = Sym.getAlignment();
|
uint32_t Align = Sym.getAlignment();
|
||||||
uint64_t Size = Sym.getCommonSize();
|
uint64_t Size = Sym.getCommonSize();
|
||||||
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
Expected<StringRef> NameOrErr = Sym.getName();
|
||||||
Check(NameOrErr.getError());
|
if (!NameOrErr) {
|
||||||
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
if (Align) {
|
if (Align) {
|
||||||
// This symbol has an alignment requirement.
|
// This symbol has an alignment requirement.
|
||||||
|
@ -1175,9 +1175,14 @@ 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()) {
|
||||||
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
Expected<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
if (std::error_code EC = TargetNameOrErr.getError())
|
if (!TargetNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
TargetName = *TargetNameOrErr;
|
TargetName = *TargetNameOrErr;
|
||||||
}
|
}
|
||||||
DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend
|
DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend
|
||||||
|
@ -43,6 +43,15 @@ inline std::error_code Check(std::error_code Err) {
|
|||||||
}
|
}
|
||||||
return Err;
|
return Err;
|
||||||
}
|
}
|
||||||
|
inline void Check(llvm::Error Err) {
|
||||||
|
if (Err) {
|
||||||
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(std::move(Err), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Twine;
|
class Twine;
|
||||||
|
|
||||||
|
@ -99,9 +99,14 @@ 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();
|
||||||
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
Expected<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
if (std::error_code EC = TargetNameOrErr.getError())
|
if (!TargetNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef TargetName = *TargetNameOrErr;
|
StringRef TargetName = *TargetNameOrErr;
|
||||||
RTDyldSymbolTable::const_iterator SI =
|
RTDyldSymbolTable::const_iterator SI =
|
||||||
GlobalSymbolTable.find(TargetName.data());
|
GlobalSymbolTable.find(TargetName.data());
|
||||||
@ -191,9 +196,14 @@ 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);
|
||||||
ErrorOr<StringRef> IndirectSymbolNameOrErr = SI->getName();
|
Expected<StringRef> IndirectSymbolNameOrErr = SI->getName();
|
||||||
if (std::error_code EC = IndirectSymbolNameOrErr.getError())
|
if (!IndirectSymbolNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(IndirectSymbolNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef IndirectSymbolName = *IndirectSymbolNameOrErr;
|
StringRef IndirectSymbolName = *IndirectSymbolNameOrErr;
|
||||||
DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
|
DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
|
||||||
<< ", PT offset: " << PTEntryOffset << "\n");
|
<< ", PT offset: " << PTEntryOffset << "\n");
|
||||||
|
@ -43,9 +43,14 @@ public:
|
|||||||
if (Symbol == Obj.symbol_end())
|
if (Symbol == Obj.symbol_end())
|
||||||
report_fatal_error("Unknown symbol in relocation");
|
report_fatal_error("Unknown symbol in relocation");
|
||||||
|
|
||||||
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
Expected<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
if (auto EC = TargetNameOrErr.getError())
|
if (!TargetNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef TargetName = *TargetNameOrErr;
|
StringRef TargetName = *TargetNameOrErr;
|
||||||
|
|
||||||
auto Section = *Symbol->getSection();
|
auto Section = *Symbol->getSection();
|
||||||
|
@ -151,9 +151,14 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
Expected<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
if (std::error_code EC = TargetNameOrErr.getError())
|
if (!TargetNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef TargetName = *TargetNameOrErr;
|
StringRef TargetName = *TargetNameOrErr;
|
||||||
|
|
||||||
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
|
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
|
||||||
|
@ -424,9 +424,14 @@ private:
|
|||||||
uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
|
uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
|
||||||
unsigned NumBytes = 1 << Size;
|
unsigned NumBytes = 1 << Size;
|
||||||
|
|
||||||
ErrorOr<StringRef> SubtrahendNameOrErr = RelI->getSymbol()->getName();
|
Expected<StringRef> SubtrahendNameOrErr = RelI->getSymbol()->getName();
|
||||||
if (auto EC = SubtrahendNameOrErr.getError())
|
if (!SubtrahendNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SubtrahendNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
|
auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
|
||||||
unsigned SectionBID = SubtrahendI->second.getSectionID();
|
unsigned SectionBID = SubtrahendI->second.getSectionID();
|
||||||
uint64_t SectionBOffset = SubtrahendI->second.getOffset();
|
uint64_t SectionBOffset = SubtrahendI->second.getOffset();
|
||||||
@ -434,9 +439,14 @@ private:
|
|||||||
SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
|
SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
|
||||||
|
|
||||||
++RelI;
|
++RelI;
|
||||||
ErrorOr<StringRef> MinuendNameOrErr = RelI->getSymbol()->getName();
|
Expected<StringRef> MinuendNameOrErr = RelI->getSymbol()->getName();
|
||||||
if (auto EC = MinuendNameOrErr.getError())
|
if (!MinuendNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(MinuendNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
|
auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
|
||||||
unsigned SectionAID = MinuendI->second.getSectionID();
|
unsigned SectionAID = MinuendI->second.getSectionID();
|
||||||
uint64_t SectionAOffset = MinuendI->second.getOffset();
|
uint64_t SectionAOffset = MinuendI->second.getOffset();
|
||||||
|
@ -204,9 +204,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);
|
||||||
ErrorOr<StringRef> IndirectSymbolName = SI->getName();
|
Expected<StringRef> IndirectSymbolName = SI->getName();
|
||||||
if (std::error_code EC = IndirectSymbolName.getError())
|
if (!IndirectSymbolName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(IndirectSymbolName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
|
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
|
||||||
createStubFunction(JTEntryAddr);
|
createStubFunction(JTEntryAddr);
|
||||||
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
|
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
|
||||||
|
@ -157,9 +157,14 @@ private:
|
|||||||
uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
|
uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
|
||||||
unsigned NumBytes = 1 << Size;
|
unsigned NumBytes = 1 << Size;
|
||||||
|
|
||||||
ErrorOr<StringRef> SubtrahendNameOrErr = RelI->getSymbol()->getName();
|
Expected<StringRef> SubtrahendNameOrErr = RelI->getSymbol()->getName();
|
||||||
if (auto EC = SubtrahendNameOrErr.getError())
|
if (!SubtrahendNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SubtrahendNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
|
auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
|
||||||
unsigned SectionBID = SubtrahendI->second.getSectionID();
|
unsigned SectionBID = SubtrahendI->second.getSectionID();
|
||||||
uint64_t SectionBOffset = SubtrahendI->second.getOffset();
|
uint64_t SectionBOffset = SubtrahendI->second.getOffset();
|
||||||
@ -167,9 +172,14 @@ private:
|
|||||||
SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
|
SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
|
||||||
|
|
||||||
++RelI;
|
++RelI;
|
||||||
ErrorOr<StringRef> MinuendNameOrErr = RelI->getSymbol()->getName();
|
Expected<StringRef> MinuendNameOrErr = RelI->getSymbol()->getName();
|
||||||
if (auto EC = MinuendNameOrErr.getError())
|
if (!MinuendNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(MinuendNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
|
auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
|
||||||
unsigned SectionAID = MinuendI->second.getSectionID();
|
unsigned SectionAID = MinuendI->second.getSectionID();
|
||||||
uint64_t SectionAOffset = MinuendI->second.getOffset();
|
uint64_t SectionAOffset = MinuendI->second.getOffset();
|
||||||
|
@ -144,12 +144,12 @@ void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
|
Expected<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
|
||||||
COFFSymbolRef Symb = getCOFFSymbol(Ref);
|
COFFSymbolRef Symb = getCOFFSymbol(Ref);
|
||||||
StringRef Result;
|
StringRef Result;
|
||||||
std::error_code EC = getSymbolName(Symb, Result);
|
std::error_code EC = getSymbolName(Symb, Result);
|
||||||
if (EC)
|
if (EC)
|
||||||
return EC;
|
return errorCodeToError(EC);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,11 @@ malformedError(std::string FileName, std::string Msg,
|
|||||||
ECOverride);
|
ECOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME: Remove ECOverride once Error has been plumbed down to obj tool code.
|
// FIXME: Remove ECOverride once Error has been plumbed down to obj tool code.
|
||||||
static Error
|
static Error
|
||||||
malformedError(const MachOObjectFile &Obj, std::string Msg,
|
malformedError(const MachOObjectFile &Obj, Twine Msg,
|
||||||
object_error ECOverride = object_error::parse_failed) {
|
object_error ECOverride = object_error::parse_failed) {
|
||||||
return malformedError(Obj.getFileName(), std::move(Msg), ECOverride);
|
return malformedError(Obj.getFileName(), std::move(Msg.str()), ECOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Replace all uses of this function with getStructOrErr.
|
// FIXME: Replace all uses of this function with getStructOrErr.
|
||||||
@ -444,12 +443,16 @@ void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
|
|||||||
Symb.p += SymbolTableEntrySize;
|
Symb.p += SymbolTableEntrySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
|
Expected<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) 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()) {
|
||||||
return object_error::parse_failed;
|
return malformedError(*this, Twine("truncated or malformed object (bad "
|
||||||
|
"string index: ") + Twine(Entry.n_strx) + Twine(" for "
|
||||||
|
"symbol at index ") + Twine(getSymbolIndex(Symb)) +
|
||||||
|
Twine(")"));
|
||||||
|
}
|
||||||
return StringRef(Start);
|
return StringRef(Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,6 +1111,18 @@ basic_symbol_iterator MachOObjectFile::getSymbolByIndex(unsigned Index) const {
|
|||||||
return basic_symbol_iterator(SymbolRef(DRI, this));
|
return basic_symbol_iterator(SymbolRef(DRI, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t MachOObjectFile::getSymbolIndex(DataRefImpl Symb) const {
|
||||||
|
MachO::symtab_command Symtab = getSymtabLoadCommand();
|
||||||
|
if (!SymtabLoadCmd)
|
||||||
|
report_fatal_error("getSymbolIndex() called with no symbol table symbol");
|
||||||
|
unsigned SymbolTableEntrySize =
|
||||||
|
is64Bit() ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist);
|
||||||
|
DataRefImpl DRIstart;
|
||||||
|
DRIstart.p = reinterpret_cast<uintptr_t>(getPtr(this, Symtab.symoff));
|
||||||
|
uint64_t Index = (Symb.p - DRIstart.p) / SymbolTableEntrySize;
|
||||||
|
return Index;
|
||||||
|
}
|
||||||
|
|
||||||
section_iterator MachOObjectFile::section_begin() const {
|
section_iterator MachOObjectFile::section_begin() const {
|
||||||
DataRefImpl DRI;
|
DataRefImpl DRI;
|
||||||
return section_iterator(SectionRef(DRI, this));
|
return section_iterator(SectionRef(DRI, this));
|
||||||
|
@ -178,9 +178,14 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
|
|||||||
|
|
||||||
// SymbolRef accessors
|
// SymbolRef accessors
|
||||||
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
||||||
ErrorOr<StringRef> Ret = (*unwrap(SI))->getName();
|
Expected<StringRef> Ret = (*unwrap(SI))->getName();
|
||||||
if (std::error_code EC = Ret.getError())
|
if (!Ret) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(Ret.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
return Ret->data();
|
return Ret->data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const {
|
|||||||
|
|
||||||
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
|
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
|
||||||
DataRefImpl Symb) const {
|
DataRefImpl Symb) const {
|
||||||
ErrorOr<StringRef> Name = getSymbolName(Symb);
|
Expected<StringRef> Name = getSymbolName(Symb);
|
||||||
if (std::error_code EC = Name.getError())
|
if (!Name)
|
||||||
return EC;
|
return errorToErrorCode(Name.takeError());
|
||||||
OS << *Name;
|
OS << *Name;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ ZERO-NSYMS: SYMBOL TABLE
|
|||||||
|
|
||||||
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
||||||
RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
|
RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
|
||||||
NAME-PAST-EOF: error reading file: Invalid data was encountered while parsing the file.
|
NAME-PAST-EOF: truncated or malformed object (bad string index: 4261412866 for symbol at index 0)
|
||||||
RUN: llvm-nm -pa %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
RUN: llvm-nm -pa %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
||||||
RUN: | FileCheck -check-prefix NAME-PAST-EOF-nm-pa %s
|
RUN: | FileCheck -check-prefix NAME-PAST-EOF-nm-pa %s
|
||||||
NAME-PAST-EOF-nm-pa: 0000000000000000 - 00 0000 SO bad string index
|
NAME-PAST-EOF-nm-pa: 0000000000000000 - 00 0000 SO bad string index
|
||||||
|
@ -228,10 +228,14 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
|
|||||||
// 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()) {
|
||||||
uint64_t Address = Sym.getValue();
|
uint64_t Address = Sym.getValue();
|
||||||
ErrorOr<StringRef> Name = Sym.getName();
|
Expected<StringRef> Name = Sym.getName();
|
||||||
if (!Name ||
|
if (!Name ||
|
||||||
(Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common)))
|
(Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common))) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
if (!Name)
|
||||||
|
consumeError(Name.takeError());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
SymbolAddresses[*Name] = Address;
|
SymbolAddresses[*Name] = Address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1951,8 +1951,9 @@ findValidRelocsMachO(const object::SectionRef &Section,
|
|||||||
|
|
||||||
auto Sym = Reloc.getSymbol();
|
auto Sym = Reloc.getSymbol();
|
||||||
if (Sym != Obj.symbol_end()) {
|
if (Sym != Obj.symbol_end()) {
|
||||||
ErrorOr<StringRef> SymbolName = Sym->getName();
|
Expected<StringRef> SymbolName = Sym->getName();
|
||||||
if (!SymbolName) {
|
if (!SymbolName) {
|
||||||
|
consumeError(SymbolName.takeError());
|
||||||
Linker.reportWarning("error getting relocation symbol name.");
|
Linker.reportWarning("error getting relocation symbol name.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -402,9 +402,12 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols(
|
|||||||
|
|
||||||
for (auto Sym : Obj.symbols()) {
|
for (auto Sym : Obj.symbols()) {
|
||||||
uint64_t Addr = Sym.getValue();
|
uint64_t Addr = Sym.getValue();
|
||||||
ErrorOr<StringRef> Name = Sym.getName();
|
Expected<StringRef> Name = Sym.getName();
|
||||||
if (!Name)
|
if (!Name) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(Name.takeError());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
// The value of some categories of symbols isn't meaningful. For
|
// The value of some categories of symbols isn't meaningful. For
|
||||||
// example common symbols store their size in the value field, not
|
// example common symbols store their size in the value field, not
|
||||||
// their address. Absolute symbols have a fixed address that can
|
// their address. Absolute symbols have a fixed address that can
|
||||||
@ -457,9 +460,12 @@ void MachODebugMapParser::loadMainBinarySymbols(
|
|||||||
if (Section == MainBinary.section_end() || Section->isText())
|
if (Section == MainBinary.section_end() || Section->isText())
|
||||||
continue;
|
continue;
|
||||||
uint64_t Addr = Sym.getValue();
|
uint64_t Addr = Sym.getValue();
|
||||||
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
Expected<StringRef> NameOrErr = Sym.getName();
|
||||||
if (!NameOrErr)
|
if (!NameOrErr) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(NameOrErr.takeError());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
if (Name.size() == 0 || Name[0] == '\0')
|
if (Name.size() == 0 || Name[0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
|
@ -79,8 +79,8 @@ static void 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;
|
||||||
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
|
Expected<StringRef> RelocSymName = RelocSymI->getName();
|
||||||
error(RelocSymName.getError());
|
error(errorToErrorCode(RelocSymName.takeError()));
|
||||||
uint64_t Offset = Reloc.getOffset();
|
uint64_t Offset = Reloc.getOffset();
|
||||||
if (Offset >= SymOffset && Offset < SymEnd) {
|
if (Offset >= SymOffset && Offset < SymEnd) {
|
||||||
*I = *RelocSymName;
|
*I = *RelocSymName;
|
||||||
@ -101,8 +101,8 @@ static void 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;
|
||||||
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
|
Expected<StringRef> RelocSymName = RelocSymI->getName();
|
||||||
error(RelocSymName.getError());
|
error(errorToErrorCode(RelocSymName.takeError()));
|
||||||
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;
|
||||||
@ -175,8 +175,8 @@ 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;
|
||||||
ErrorOr<StringRef> SymNameOrErr = Sym.getName();
|
Expected<StringRef> SymNameOrErr = Sym.getName();
|
||||||
error(SymNameOrErr.getError());
|
error(errorToErrorCode(SymNameOrErr.takeError()));
|
||||||
StringRef SymName = *SymNameOrErr;
|
StringRef SymName = *SymNameOrErr;
|
||||||
ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection();
|
ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection();
|
||||||
error(SecIOrErr.getError());
|
error(SecIOrErr.getError());
|
||||||
|
@ -724,9 +724,11 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SymI->getELFType() == ELF::STT_SECTION) {
|
if (SymI->getELFType() == ELF::STT_SECTION) {
|
||||||
ErrorOr<StringRef> Name = SymI->getName();
|
Expected<StringRef> Name = SymI->getName();
|
||||||
if (error(Name.getError()))
|
if (!Name) {
|
||||||
|
consumeError(Name.takeError());
|
||||||
return '?';
|
return '?';
|
||||||
|
}
|
||||||
return StringSwitch<char>(*Name)
|
return StringSwitch<char>(*Name)
|
||||||
.StartsWith(".debug", 'N')
|
.StartsWith(".debug", 'N')
|
||||||
.StartsWith(".note", 'n')
|
.StartsWith(".note", 'n')
|
||||||
@ -741,9 +743,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);
|
||||||
|
|
||||||
ErrorOr<StringRef> Name = SymI->getName();
|
Expected<StringRef> Name = SymI->getName();
|
||||||
if (error(Name.getError()))
|
if (!Name) {
|
||||||
|
consumeError(Name.takeError());
|
||||||
return '?';
|
return '?';
|
||||||
|
}
|
||||||
|
|
||||||
char Ret = StringSwitch<char>(*Name)
|
char Ret = StringSwitch<char>(*Name)
|
||||||
.StartsWith(".debug", 'N')
|
.StartsWith(".debug", 'N')
|
||||||
|
@ -215,9 +215,9 @@ 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;
|
||||||
ErrorOr<StringRef> NameOrErr = Sym.getName();
|
Expected<StringRef> NameOrErr = Sym.getName();
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!NameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(NameOrErr.takeError());
|
||||||
Name = *NameOrErr;
|
Name = *NameOrErr;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
@ -273,9 +273,14 @@ 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()) {
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
if (!SymName->startswith("ltmp"))
|
if (!SymName->startswith("ltmp"))
|
||||||
Symbols.push_back(Symbol);
|
Symbols.push_back(Symbol);
|
||||||
}
|
}
|
||||||
@ -353,9 +358,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
outs() << *SymName;
|
outs() << *SymName;
|
||||||
} else {
|
} else {
|
||||||
outs() << "?";
|
outs() << "?";
|
||||||
@ -587,9 +597,14 @@ static void CreateSymbolAddressMap(MachOObjectFile *O,
|
|||||||
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
|
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
|
||||||
ST == SymbolRef::ST_Other) {
|
ST == SymbolRef::ST_Other) {
|
||||||
uint64_t Address = Symbol.getValue();
|
uint64_t Address = Symbol.getValue();
|
||||||
ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
|
Expected<StringRef> SymNameOrErr = Symbol.getName();
|
||||||
if (std::error_code EC = SymNameOrErr.getError())
|
if (!SymNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef SymName = *SymNameOrErr;
|
StringRef SymName = *SymNameOrErr;
|
||||||
if (!SymName.startswith(".objc"))
|
if (!SymName.startswith(".objc"))
|
||||||
(*AddrMap)[Address] = SymName;
|
(*AddrMap)[Address] = SymName;
|
||||||
@ -823,9 +838,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = RelocSym->getName();
|
Expected<StringRef> SymName = RelocSym->getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
outs() << "external relocation entry for symbol:" << *SymName << "\n";
|
outs() << "external relocation entry for symbol:" << *SymName << "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1778,9 +1798,14 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reloc_found && isExtern) {
|
if (reloc_found && isExtern) {
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
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;
|
||||||
@ -1848,9 +1873,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
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) {
|
||||||
@ -1865,9 +1895,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymNameNext = Symbol.getName();
|
Expected<StringRef> SymNameNext = Symbol.getName();
|
||||||
if (std::error_code EC = SymNameNext.getError())
|
if (!SymNameNext) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymNameNext.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
name = SymNameNext->data();
|
name = SymNameNext->data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1938,9 +1973,14 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isExtern) {
|
if (isExtern) {
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
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;
|
||||||
@ -2058,9 +2098,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = Reloc->getSymbol()->getName();
|
Expected<StringRef> SymName = Reloc->getSymbol()->getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
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;
|
||||||
@ -2188,9 +2233,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
const char *name = SymName->data();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -2223,9 +2273,14 @@ 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;
|
||||||
ErrorOr<StringRef> SymName = Symbol.getName();
|
Expected<StringRef> SymName = Symbol.getName();
|
||||||
if (std::error_code EC = SymName.getError())
|
if (!SymName) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymName.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
const char *name = SymName->data();
|
const char *name = SymName->data();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -2452,9 +2507,14 @@ static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
|
|||||||
const char *SymbolName = nullptr;
|
const char *SymbolName = nullptr;
|
||||||
if (reloc_found && isExtern) {
|
if (reloc_found && isExtern) {
|
||||||
n_value = Symbol.getValue();
|
n_value = Symbol.getValue();
|
||||||
ErrorOr<StringRef> NameOrError = Symbol.getName();
|
Expected<StringRef> NameOrError = Symbol.getName();
|
||||||
if (std::error_code EC = NameOrError.getError())
|
if (!NameOrError) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(NameOrError.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef Name = *NameOrError;
|
StringRef Name = *NameOrError;
|
||||||
if (!Name.empty()) {
|
if (!Name.empty()) {
|
||||||
SymbolName = Name.data();
|
SymbolName = Name.data();
|
||||||
@ -6100,9 +6160,14 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
|||||||
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
|
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
|
||||||
ST == SymbolRef::ST_Other) {
|
ST == SymbolRef::ST_Other) {
|
||||||
uint64_t Address = Symbol.getValue();
|
uint64_t Address = Symbol.getValue();
|
||||||
ErrorOr<StringRef> SymNameOrErr = Symbol.getName();
|
Expected<StringRef> SymNameOrErr = Symbol.getName();
|
||||||
if (std::error_code EC = SymNameOrErr.getError())
|
if (!SymNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef SymName = *SymNameOrErr;
|
StringRef SymName = *SymNameOrErr;
|
||||||
AddrMap[Address] = SymName;
|
AddrMap[Address] = SymName;
|
||||||
if (!DisSymName.empty() && DisSymName == SymName)
|
if (!DisSymName.empty() && DisSymName == SymName)
|
||||||
@ -6142,9 +6207,14 @@ 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++) {
|
||||||
ErrorOr<StringRef> SymNameOrErr = Symbols[SymIdx].getName();
|
Expected<StringRef> SymNameOrErr = Symbols[SymIdx].getName();
|
||||||
if (std::error_code EC = SymNameOrErr.getError())
|
if (!SymNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
StringRef SymName = *SymNameOrErr;
|
StringRef SymName = *SymNameOrErr;
|
||||||
|
|
||||||
ErrorOr<SymbolRef::Type> STOrErr = Symbols[SymIdx].getType();
|
ErrorOr<SymbolRef::Type> STOrErr = Symbols[SymIdx].getType();
|
||||||
@ -6412,9 +6482,14 @@ 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()) {
|
||||||
ErrorOr<StringRef> NameOrErr = Reloc.getSymbol()->getName();
|
Expected<StringRef> NameOrErr = Reloc.getSymbol()->getName();
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!NameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
Name = *NameOrErr;
|
Name = *NameOrErr;
|
||||||
Addend = Addr;
|
Addend = Addr;
|
||||||
return;
|
return;
|
||||||
@ -6440,9 +6515,14 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
|
|||||||
section_iterator SymSection = *Sym->second.getSection();
|
section_iterator SymSection = *Sym->second.getSection();
|
||||||
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.
|
||||||
ErrorOr<StringRef> NameOrErr = Sym->second.getName();
|
Expected<StringRef> NameOrErr = Sym->second.getName();
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!NameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
Name = *NameOrErr;
|
Name = *NameOrErr;
|
||||||
Addend = Addr - Sym->first;
|
Addend = Addr - Sym->first;
|
||||||
return;
|
return;
|
||||||
|
@ -494,9 +494,9 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
|||||||
return EC;
|
return EC;
|
||||||
Target = *SecName;
|
Target = *SecName;
|
||||||
} else {
|
} else {
|
||||||
ErrorOr<StringRef> SymName = symb->getName(StrTab);
|
Expected<StringRef> SymName = symb->getName(StrTab);
|
||||||
if (!SymName)
|
if (!SymName)
|
||||||
return SymName.getError();
|
return errorToErrorCode(SymName.takeError());
|
||||||
Target = *SymName;
|
Target = *SymName;
|
||||||
}
|
}
|
||||||
switch (EF.getHeader()->e_machine) {
|
switch (EF.getHeader()->e_machine) {
|
||||||
@ -586,9 +586,9 @@ 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();
|
||||||
ErrorOr<StringRef> SymNameOrErr = SymI->getName();
|
Expected<StringRef> SymNameOrErr = SymI->getName();
|
||||||
if (std::error_code EC = SymNameOrErr.getError())
|
if (!SymNameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(SymNameOrErr.takeError());
|
||||||
StringRef SymName = *SymNameOrErr;
|
StringRef SymName = *SymNameOrErr;
|
||||||
Result.append(SymName.begin(), SymName.end());
|
Result.append(SymName.begin(), SymName.end());
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
@ -613,9 +613,14 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
report_fatal_error(ec.message());
|
report_fatal_error(ec.message());
|
||||||
if (*Addr != Val)
|
if (*Addr != Val)
|
||||||
continue;
|
continue;
|
||||||
ErrorOr<StringRef> Name = Symbol.getName();
|
Expected<StringRef> Name = Symbol.getName();
|
||||||
if (std::error_code EC = Name.getError())
|
if (!Name) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(Name.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
fmt << *Name;
|
fmt << *Name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -646,8 +651,8 @@ 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);
|
||||||
ErrorOr<StringRef> SOrErr = SI->getName();
|
Expected<StringRef> SOrErr = SI->getName();
|
||||||
error(SOrErr.getError());
|
error(errorToErrorCode(SOrErr.takeError()));
|
||||||
S = *SOrErr;
|
S = *SOrErr;
|
||||||
} else {
|
} else {
|
||||||
section_iterator SI = O->section_begin();
|
section_iterator SI = O->section_begin();
|
||||||
@ -952,8 +957,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
error(AddressOrErr.getError());
|
error(AddressOrErr.getError());
|
||||||
uint64_t Address = *AddressOrErr;
|
uint64_t Address = *AddressOrErr;
|
||||||
|
|
||||||
ErrorOr<StringRef> Name = Symbol.getName();
|
Expected<StringRef> Name = Symbol.getName();
|
||||||
error(Name.getError());
|
error(errorToErrorCode(Name.takeError()));
|
||||||
if (Name->empty())
|
if (Name->empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1358,8 +1363,9 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
|
|||||||
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 {
|
} else {
|
||||||
ErrorOr<StringRef> NameOrErr = Symbol.getName();
|
Expected<StringRef> NameOrErr = Symbol.getName();
|
||||||
error(NameOrErr.getError());
|
if (!NameOrErr)
|
||||||
|
report_error(o->getFileName(), NameOrErr.takeError());
|
||||||
Name = *NameOrErr;
|
Name = *NameOrErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,8 +355,15 @@ PrinterContext<ET>::FunctionAtAddress(unsigned Section,
|
|||||||
|
|
||||||
for (const Elf_Sym &Sym : ELF->symbols(Symtab))
|
for (const Elf_Sym &Sym : ELF->symbols(Symtab))
|
||||||
if (Sym.st_shndx == Section && Sym.st_value == Address &&
|
if (Sym.st_shndx == Section && Sym.st_value == Address &&
|
||||||
Sym.getType() == ELF::STT_FUNC)
|
Sym.getType() == ELF::STT_FUNC) {
|
||||||
return Sym.getName(StrTable);
|
auto NameOrErr = Sym.getName(StrTable);
|
||||||
|
if (!NameOrErr) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(NameOrErr.takeError());
|
||||||
|
return readobj_error::unknown_symbol;
|
||||||
|
}
|
||||||
|
return *NameOrErr;
|
||||||
|
}
|
||||||
return readobj_error::unknown_symbol;
|
return readobj_error::unknown_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,9 +570,14 @@ bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF,
|
|||||||
if (!Symbol)
|
if (!Symbol)
|
||||||
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
|
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
|
||||||
|
|
||||||
ErrorOr<StringRef> Name = Symbol->getName();
|
Expected<StringRef> Name = Symbol->getName();
|
||||||
if (std::error_code EC = Name.getError())
|
if (!Name) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
llvm::raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(Name.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
|
|
||||||
ListScope EHS(SW, "ExceptionHandler");
|
ListScope EHS(SW, "ExceptionHandler");
|
||||||
SW.printString("Routine", formatSymbol(*Name, Address));
|
SW.printString("Routine", formatSymbol(*Name, Address));
|
||||||
@ -604,9 +609,14 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||||||
StringRef FunctionName;
|
StringRef FunctionName;
|
||||||
uint64_t FunctionAddress;
|
uint64_t FunctionAddress;
|
||||||
if (Function) {
|
if (Function) {
|
||||||
ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
|
Expected<StringRef> FunctionNameOrErr = Function->getName();
|
||||||
if (std::error_code EC = FunctionNameOrErr.getError())
|
if (!FunctionNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
llvm::raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
FunctionName = *FunctionNameOrErr;
|
FunctionName = *FunctionNameOrErr;
|
||||||
ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
|
ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
|
||||||
if (std::error_code EC = FunctionAddressOrErr.getError())
|
if (std::error_code EC = FunctionAddressOrErr.getError())
|
||||||
@ -622,9 +632,14 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||||||
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
|
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
|
||||||
|
|
||||||
if (XDataRecord) {
|
if (XDataRecord) {
|
||||||
ErrorOr<StringRef> Name = XDataRecord->getName();
|
Expected<StringRef> Name = XDataRecord->getName();
|
||||||
if (std::error_code EC = Name.getError())
|
if (!Name) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
llvm::raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(Name.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<uint64_t> AddressOrErr = XDataRecord->getAddress();
|
ErrorOr<uint64_t> AddressOrErr = XDataRecord->getAddress();
|
||||||
if (std::error_code EC = AddressOrErr.getError())
|
if (std::error_code EC = AddressOrErr.getError())
|
||||||
@ -671,9 +686,14 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
|
|||||||
StringRef FunctionName;
|
StringRef FunctionName;
|
||||||
uint64_t FunctionAddress;
|
uint64_t FunctionAddress;
|
||||||
if (Function) {
|
if (Function) {
|
||||||
ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
|
Expected<StringRef> FunctionNameOrErr = Function->getName();
|
||||||
if (std::error_code EC = FunctionNameOrErr.getError())
|
if (!FunctionNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
llvm::raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
FunctionName = *FunctionNameOrErr;
|
FunctionName = *FunctionNameOrErr;
|
||||||
ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
|
ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
|
||||||
FunctionAddress = *FunctionAddressOrErr;
|
FunctionAddress = *FunctionAddressOrErr;
|
||||||
|
@ -187,9 +187,9 @@ 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;
|
||||||
ErrorOr<StringRef> NameOrErr = Symbol.getName();
|
Expected<StringRef> NameOrErr = Symbol.getName();
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!NameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(NameOrErr.takeError());
|
||||||
Name = *NameOrErr;
|
Name = *NameOrErr;
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
@ -2605,8 +2605,8 @@ void COFFDumper::printRelocation(const SectionRef &Section,
|
|||||||
Reloc.getTypeName(RelocName);
|
Reloc.getTypeName(RelocName);
|
||||||
symbol_iterator Symbol = Reloc.getSymbol();
|
symbol_iterator Symbol = Reloc.getSymbol();
|
||||||
if (Symbol != Obj->symbol_end()) {
|
if (Symbol != Obj->symbol_end()) {
|
||||||
ErrorOr<StringRef> SymbolNameOrErr = Symbol->getName();
|
Expected<StringRef> SymbolNameOrErr = Symbol->getName();
|
||||||
error(SymbolNameOrErr.getError());
|
error(errorToErrorCode(SymbolNameOrErr.takeError()));
|
||||||
SymbolName = *SymbolNameOrErr;
|
SymbolName = *SymbolNameOrErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,8 +541,9 @@ 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()) {
|
||||||
ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
|
Expected<StringRef> TargetNameOrErr = Symbol->getName();
|
||||||
error(TargetNameOrErr.getError());
|
if (!TargetNameOrErr)
|
||||||
|
error(errorToErrorCode(TargetNameOrErr.takeError()));
|
||||||
TargetName = *TargetNameOrErr;
|
TargetName = *TargetNameOrErr;
|
||||||
}
|
}
|
||||||
} else if (!IsScattered) {
|
} else if (!IsScattered) {
|
||||||
@ -605,7 +606,11 @@ void MachODumper::printDynamicSymbols() {
|
|||||||
|
|
||||||
void MachODumper::printSymbol(const SymbolRef &Symbol) {
|
void MachODumper::printSymbol(const SymbolRef &Symbol) {
|
||||||
StringRef SymbolName;
|
StringRef SymbolName;
|
||||||
if (ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName())
|
Expected<StringRef> SymbolNameOrErr = Symbol.getName();
|
||||||
|
if (!SymbolNameOrErr) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(SymbolNameOrErr.takeError());
|
||||||
|
} else
|
||||||
SymbolName = *SymbolNameOrErr;
|
SymbolName = *SymbolNameOrErr;
|
||||||
|
|
||||||
MachOSymbol MOSymbol;
|
MachOSymbol MOSymbol;
|
||||||
|
@ -120,13 +120,17 @@ static std::string formatSymbol(const Dumper::Context &Ctx,
|
|||||||
|
|
||||||
SymbolRef Symbol;
|
SymbolRef Symbol;
|
||||||
if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
|
if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
|
||||||
if (ErrorOr<StringRef> Name = Symbol.getName()) {
|
Expected<StringRef> Name = Symbol.getName();
|
||||||
|
if (Name) {
|
||||||
OS << *Name;
|
OS << *Name;
|
||||||
if (Displacement > 0)
|
if (Displacement > 0)
|
||||||
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
|
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
|
||||||
else
|
else
|
||||||
OS << format(" (0x%" PRIX64 ")", Offset);
|
OS << format(" (0x%" PRIX64 ")", Offset);
|
||||||
return OS.str();
|
return OS.str();
|
||||||
|
} else {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(Name.takeError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/ErrorOr.h"
|
#include "llvm/Support/ErrorOr.h"
|
||||||
|
#include "llvm/Support/Error.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -28,6 +29,15 @@ namespace llvm {
|
|||||||
return *EO;
|
return *EO;
|
||||||
reportError(EO.getError().message());
|
reportError(EO.getError().message());
|
||||||
}
|
}
|
||||||
|
template <class T> T unwrapOrError(Expected<T> EO) {
|
||||||
|
if (EO)
|
||||||
|
return *EO;
|
||||||
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(EO.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
reportError(Buf);
|
||||||
|
}
|
||||||
bool relocAddressLess(object::RelocationRef A,
|
bool relocAddressLess(object::RelocationRef A,
|
||||||
object::RelocationRef B);
|
object::RelocationRef B);
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
@ -340,9 +340,12 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
|
|||||||
continue;
|
continue;
|
||||||
SymbolRef::Type Type = *TypeOrErr;
|
SymbolRef::Type Type = *TypeOrErr;
|
||||||
if (Type == object::SymbolRef::ST_Function) {
|
if (Type == object::SymbolRef::ST_Function) {
|
||||||
ErrorOr<StringRef> Name = Sym.getName();
|
Expected<StringRef> Name = Sym.getName();
|
||||||
if (!Name)
|
if (!Name) {
|
||||||
|
// TODO: Actually report errors helpfully.
|
||||||
|
consumeError(Name.takeError());
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
ErrorOr<uint64_t> AddrOrErr = Sym.getAddress();
|
ErrorOr<uint64_t> AddrOrErr = Sym.getAddress();
|
||||||
if (!AddrOrErr)
|
if (!AddrOrErr)
|
||||||
continue;
|
continue;
|
||||||
|
@ -121,9 +121,14 @@ 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();
|
||||||
ErrorOr<StringRef> SymbolNameOrErr = Sym->getName();
|
Expected<StringRef> SymbolNameOrErr = Sym->getName();
|
||||||
if (std::error_code EC = SymbolNameOrErr.getError())
|
if (!SymbolNameOrErr) {
|
||||||
report_fatal_error(EC.message());
|
std::string Buf;
|
||||||
|
raw_string_ostream OS(Buf);
|
||||||
|
logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS, "");
|
||||||
|
OS.flush();
|
||||||
|
report_fatal_error(Buf);
|
||||||
|
}
|
||||||
Rel.SymbolName = *SymbolNameOrErr;
|
Rel.SymbolName = *SymbolNameOrErr;
|
||||||
Rel.VirtualAddress = reloc->VirtualAddress;
|
Rel.VirtualAddress = reloc->VirtualAddress;
|
||||||
Rel.Type = reloc->Type;
|
Rel.Type = reloc->Type;
|
||||||
|
@ -179,10 +179,10 @@ ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
|
|||||||
S.Size = Sym->st_size;
|
S.Size = Sym->st_size;
|
||||||
S.Other = Sym->st_other;
|
S.Other = Sym->st_other;
|
||||||
|
|
||||||
ErrorOr<StringRef> NameOrErr = Sym->getName(StrTable);
|
Expected<StringRef> SymbolNameOrErr = Sym->getName(StrTable);
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!SymbolNameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(SymbolNameOrErr.takeError());
|
||||||
S.Name = NameOrErr.get();
|
S.Name = SymbolNameOrErr.get();
|
||||||
|
|
||||||
ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
|
ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
|
||||||
if (std::error_code EC = ShdrOrErr.getError())
|
if (std::error_code EC = ShdrOrErr.getError())
|
||||||
@ -191,7 +191,7 @@ ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
|
|||||||
if (!Shdr)
|
if (!Shdr)
|
||||||
return obj2yaml_error::success;
|
return obj2yaml_error::success;
|
||||||
|
|
||||||
NameOrErr = Obj.getSectionName(Shdr);
|
ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr);
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (std::error_code EC = NameOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
S.Section = NameOrErr.get();
|
S.Section = NameOrErr.get();
|
||||||
@ -217,9 +217,9 @@ std::error_code ELFDumper<ELFT>::dumpRelocation(const RelT *Rel,
|
|||||||
return EC;
|
return EC;
|
||||||
StringRef StrTab = *StrTabOrErr;
|
StringRef StrTab = *StrTabOrErr;
|
||||||
|
|
||||||
ErrorOr<StringRef> NameOrErr = Sym->getName(StrTab);
|
Expected<StringRef> NameOrErr = Sym->getName(StrTab);
|
||||||
if (std::error_code EC = NameOrErr.getError())
|
if (!NameOrErr)
|
||||||
return EC;
|
return errorToErrorCode(NameOrErr.takeError());
|
||||||
R.Symbol = NameOrErr.get();
|
R.Symbol = NameOrErr.get();
|
||||||
|
|
||||||
return obj2yaml_error::success;
|
return obj2yaml_error::success;
|
||||||
@ -368,9 +368,9 @@ ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
|
|||||||
auto sectionContents = Obj.getSectionContents(Shdr);
|
auto sectionContents = Obj.getSectionContents(Shdr);
|
||||||
if (std::error_code ec = sectionContents.getError())
|
if (std::error_code ec = sectionContents.getError())
|
||||||
return ec;
|
return ec;
|
||||||
ErrorOr<StringRef> symbolName = symbol->getName(StrTab);
|
Expected<StringRef> symbolName = symbol->getName(StrTab);
|
||||||
if (std::error_code EC = symbolName.getError())
|
if (!symbolName)
|
||||||
return EC;
|
return errorToErrorCode(symbolName.takeError());
|
||||||
S->Info = *symbolName;
|
S->Info = *symbolName;
|
||||||
const Elf_Word *groupMembers =
|
const Elf_Word *groupMembers =
|
||||||
reinterpret_cast<const Elf_Word *>(sectionContents->data());
|
reinterpret_cast<const Elf_Word *>(sectionContents->data());
|
||||||
|
@ -314,8 +314,8 @@ findSanitizerCovFunctions(const object::ObjectFile &O) {
|
|||||||
ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
|
ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
|
||||||
FailIfError(AddressOrErr);
|
FailIfError(AddressOrErr);
|
||||||
|
|
||||||
ErrorOr<StringRef> NameOrErr = Symbol.getName();
|
Expected<StringRef> NameOrErr = Symbol.getName();
|
||||||
FailIfError(NameOrErr);
|
FailIfError(errorToErrorCode(NameOrErr.takeError()));
|
||||||
StringRef Name = NameOrErr.get();
|
StringRef Name = NameOrErr.get();
|
||||||
|
|
||||||
if (Name == "__sanitizer_cov" || Name == "__sanitizer_cov_with_check" ||
|
if (Name == "__sanitizer_cov" || Name == "__sanitizer_cov_with_check" ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user