llvm.org GIT mirror llvm / 813e0cf
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266919 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 3 years ago
39 changed file(s) with 441 addition(s) and 195 deletion(s). Raw diff Collapse all Expand all
157157 for (auto &Symbol : getObject(*Obj).symbols()) {
158158 if (Symbol.getFlags() & object::SymbolRef::SF_Undefined)
159159 continue;
160 ErrorOr SymbolName = Symbol.getName();
160 Expected SymbolName = Symbol.getName();
161161 // FIXME: Raise an error for bad symbols.
162 if (!SymbolName)
162 if (!SymbolName) {
163 consumeError(SymbolName.takeError());
163164 continue;
165 }
164166 auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol);
165167 SymbolTable.insert(
166168 std::make_pair(*SymbolName, RuntimeDyld::SymbolInfo(0, Flags)));
678678 }
679679 protected:
680680 void moveSymbolNext(DataRefImpl &Symb) const override;
681 ErrorOr getSymbolName(DataRefImpl Symb) const override;
681 Expected getSymbolName(DataRefImpl Symb) const override;
682682 ErrorOr getSymbolAddress(DataRefImpl Symb) const override;
683683 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
684684 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
191191 ArrayRef ShndxTable;
192192
193193 void moveSymbolNext(DataRefImpl &Symb) const override;
194 ErrorOr getSymbolName(DataRefImpl Symb) const override;
194 Expected getSymbolName(DataRefImpl Symb) const override;
195195 ErrorOr getSymbolAddress(DataRefImpl Symb) const override;
196196 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
197197 uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
348348 }
349349
350350 template
351 ErrorOr ELFObjectFile::getSymbolName(DataRefImpl Sym) const {
351 Expected ELFObjectFile::getSymbolName(DataRefImpl Sym) const {
352352 const Elf_Sym *ESym = getSymbol(Sym);
353353 const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a);
354354 const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link);
482482 Result |= SymbolRef::SF_FormatSpecific;
483483
484484 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
485 if (ErrorOr NameOrErr = getSymbolName(Sym)) {
485 if (Expected NameOrErr = getSymbolName(Sym)) {
486486 StringRef Name = *NameOrErr;
487487 if (Name.startswith("$d") || Name.startswith("$t") ||
488488 Name.startswith("$a"))
489489 Result |= SymbolRef::SF_FormatSpecific;
490 } else {
491 // TODO: Actually report errors helpfully.
492 consumeError(NameOrErr.takeError());
490493 }
491494 if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
492495 Result |= SymbolRef::SF_Thumb;
256256 return getBinding() != ELF::STB_LOCAL;
257257 }
258258
259 ErrorOr getName(StringRef StrTab) const;
260 };
261
262 template
263 ErrorOr Elf_Sym_Impl::getName(StringRef StrTab) const {
259 Expected getName(StringRef StrTab) const;
260 };
261
262 template
263 Expected Elf_Sym_Impl::getName(StringRef StrTab) const {
264264 uint32_t Offset = this->st_name;
265265 if (Offset >= StrTab.size())
266 return object_error::parse_failed;
266 return errorCodeToError(object_error::parse_failed);
267267 return StringRef(StrTab.data() + Offset);
268268 }
269269
198198 void moveSymbolNext(DataRefImpl &Symb) const override;
199199
200200 uint64_t getNValue(DataRefImpl Sym) const;
201 ErrorOr getSymbolName(DataRefImpl Symb) const override;
201 Expected getSymbolName(DataRefImpl Symb) const override;
202202
203203 // MachO specific.
204204 std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
251251
252252 // MachO specific.
253253 basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
254 uint64_t getSymbolIndex(DataRefImpl Symb) const;
254255
255256 section_iterator section_begin() const override;
256257 section_iterator section_end() const override;
129129 assert(isa(BasicSymbolRef::getObject()));
130130 }
131131
132 ErrorOr getName() const;
132 Expected getName() const;
133133 /// Returns the symbol virtual address (i.e. address at which it will be
134134 /// mapped).
135135 ErrorOr getAddress() const;
192192 // Implementations assume that the DataRefImpl is valid and has not been
193193 // modified externally. It's UB otherwise.
194194 friend class SymbolRef;
195 virtual ErrorOr getSymbolName(DataRefImpl Symb) const = 0;
195 virtual Expected getSymbolName(DataRefImpl Symb) const = 0;
196196 std::error_code printSymbolName(raw_ostream &OS,
197197 DataRefImpl Symb) const override;
198198 virtual ErrorOr getSymbolAddress(DataRefImpl Symb) const = 0;
303303 inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
304304 : BasicSymbolRef(SymbolP, Owner) {}
305305
306 inline ErrorOr SymbolRef::getName() const {
306 inline Expected SymbolRef::getName() const {
307307 return getObject()->getSymbolName(getRawDataRefImpl());
308308 }
309309
140140 OpdExtractor->isValidOffsetForAddress(OpdOffset32))
141141 SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
142142 }
143 ErrorOr SymbolNameOrErr = Symbol.getName();
144 if (auto EC = SymbolNameOrErr.getError())
145 return EC;
143 Expected SymbolNameOrErr = Symbol.getName();
144 if (!SymbolNameOrErr)
145 return errorToErrorCode(SymbolNameOrErr.takeError());
146146 StringRef SymbolName = *SymbolNameOrErr;
147147 // Mach-O symbol table names have leading underscore, skip it.
148148 if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
173173 object::SymbolRef::Type SymType = *SymTypeOrErr;
174174
175175 // Get symbol name.
176 ErrorOr NameOrErr = I->getName();
177 Check(NameOrErr.getError());
176 Expected NameOrErr = I->getName();
177 Check(NameOrErr.takeError());
178178 StringRef Name = *NameOrErr;
179179
180180 // Compute JIT symbol flags.
495495 DEBUG(dbgs() << "Processing common symbols...\n");
496496
497497 for (const auto &Sym : CommonSymbols) {
498 ErrorOr NameOrErr = Sym.getName();
499 Check(NameOrErr.getError());
498 Expected NameOrErr = Sym.getName();
499 Check(NameOrErr.takeError());
500500 StringRef Name = *NameOrErr;
501501
502502 // Skip common symbols already elsewhere.
532532 for (auto &Sym : SymbolsToAllocate) {
533533 uint32_t Align = Sym.getAlignment();
534534 uint64_t Size = Sym.getCommonSize();
535 ErrorOr NameOrErr = Sym.getName();
536 Check(NameOrErr.getError());
535 Expected NameOrErr = Sym.getName();
536 if (!NameOrErr) {
537 std::string Buf;
538 raw_string_ostream OS(Buf);
539 logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
540 OS.flush();
541 report_fatal_error(Buf);
542 }
537543 StringRef Name = *NameOrErr;
538544 if (Align) {
539545 // This symbol has an alignment requirement.
11741174 // Obtain the symbol name which is referenced in the relocation
11751175 StringRef TargetName;
11761176 if (Symbol != Obj.symbol_end()) {
1177 ErrorOr TargetNameOrErr = Symbol->getName();
1178 if (std::error_code EC = TargetNameOrErr.getError())
1179 report_fatal_error(EC.message());
1177 Expected TargetNameOrErr = Symbol->getName();
1178 if (!TargetNameOrErr) {
1179 std::string Buf;
1180 raw_string_ostream OS(Buf);
1181 logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
1182 OS.flush();
1183 report_fatal_error(Buf);
1184 }
11801185 TargetName = *TargetNameOrErr;
11811186 }
11821187 DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend
4242 }
4343 return Err;
4444 }
45 inline void Check(llvm::Error Err) {
46 if (Err) {
47 std::string Buf;
48 raw_string_ostream OS(Buf);
49 logAllUnhandledErrors(std::move(Err), OS, "");
50 OS.flush();
51 report_fatal_error(Buf);
52 }
53 }
4554
4655 class Twine;
4756
9898 bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
9999 if (IsExternal) {
100100 symbol_iterator Symbol = RI->getSymbol();
101 ErrorOr TargetNameOrErr = Symbol->getName();
102 if (std::error_code EC = TargetNameOrErr.getError())
103 report_fatal_error(EC.message());
101 Expected TargetNameOrErr = Symbol->getName();
102 if (!TargetNameOrErr) {
103 std::string Buf;
104 raw_string_ostream OS(Buf);
105 logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
106 OS.flush();
107 report_fatal_error(Buf);
108 }
104109 StringRef TargetName = *TargetNameOrErr;
105110 RTDyldSymbolTable::const_iterator SI =
106111 GlobalSymbolTable.find(TargetName.data());
190195 unsigned SymbolIndex =
191196 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
192197 symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
193 ErrorOr IndirectSymbolNameOrErr = SI->getName();
194 if (std::error_code EC = IndirectSymbolNameOrErr.getError())
195 report_fatal_error(EC.message());
198 Expected IndirectSymbolNameOrErr = SI->getName();
199 if (!IndirectSymbolNameOrErr) {
200 std::string Buf;
201 raw_string_ostream OS(Buf);
202 logAllUnhandledErrors(IndirectSymbolNameOrErr.takeError(), OS, "");
203 OS.flush();
204 report_fatal_error(Buf);
205 }
196206 StringRef IndirectSymbolName = *IndirectSymbolNameOrErr;
197207 DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
198208 << ", PT offset: " << PTEntryOffset << "\n");
4242 if (Symbol == Obj.symbol_end())
4343 report_fatal_error("Unknown symbol in relocation");
4444
45 ErrorOr TargetNameOrErr = Symbol->getName();
46 if (auto EC = TargetNameOrErr.getError())
47 report_fatal_error(EC.message());
45 Expected TargetNameOrErr = Symbol->getName();
46 if (!TargetNameOrErr) {
47 std::string Buf;
48 raw_string_ostream OS(Buf);
49 logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
50 OS.flush();
51 report_fatal_error(Buf);
52 }
4853 StringRef TargetName = *TargetNameOrErr;
4954
5055 auto Section = *Symbol->getSection();
150150 break;
151151 }
152152
153 ErrorOr TargetNameOrErr = Symbol->getName();
154 if (std::error_code EC = TargetNameOrErr.getError())
155 report_fatal_error(EC.message());
153 Expected TargetNameOrErr = Symbol->getName();
154 if (!TargetNameOrErr) {
155 std::string Buf;
156 raw_string_ostream OS(Buf);
157 logAllUnhandledErrors(TargetNameOrErr.takeError(), OS, "");
158 OS.flush();
159 report_fatal_error(Buf);
160 }
156161 StringRef TargetName = *TargetNameOrErr;
157162
158163 DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
423423 uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
424424 unsigned NumBytes = 1 << Size;
425425
426 ErrorOr SubtrahendNameOrErr = RelI->getSymbol()->getName();
427 if (auto EC = SubtrahendNameOrErr.getError())
428 report_fatal_error(EC.message());
426 Expected SubtrahendNameOrErr = RelI->getSymbol()->getName();
427 if (!SubtrahendNameOrErr) {
428 std::string Buf;
429 raw_string_ostream OS(Buf);
430 logAllUnhandledErrors(SubtrahendNameOrErr.takeError(), OS, "");
431 OS.flush();
432 report_fatal_error(Buf);
433 }
429434 auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
430435 unsigned SectionBID = SubtrahendI->second.getSectionID();
431436 uint64_t SectionBOffset = SubtrahendI->second.getOffset();
433438 SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
434439
435440 ++RelI;
436 ErrorOr MinuendNameOrErr = RelI->getSymbol()->getName();
437 if (auto EC = MinuendNameOrErr.getError())
438 report_fatal_error(EC.message());
441 Expected MinuendNameOrErr = RelI->getSymbol()->getName();
442 if (!MinuendNameOrErr) {
443 std::string Buf;
444 raw_string_ostream OS(Buf);
445 logAllUnhandledErrors(MinuendNameOrErr.takeError(), OS, "");
446 OS.flush();
447 report_fatal_error(Buf);
448 }
439449 auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
440450 unsigned SectionAID = MinuendI->second.getSectionID();
441451 uint64_t SectionAOffset = MinuendI->second.getOffset();
203203 unsigned SymbolIndex =
204204 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
205205 symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
206 ErrorOr IndirectSymbolName = SI->getName();
207 if (std::error_code EC = IndirectSymbolName.getError())
208 report_fatal_error(EC.message());
206 Expected IndirectSymbolName = SI->getName();
207 if (!IndirectSymbolName) {
208 std::string Buf;
209 raw_string_ostream OS(Buf);
210 logAllUnhandledErrors(IndirectSymbolName.takeError(), OS, "");
211 OS.flush();
212 report_fatal_error(Buf);
213 }
209214 uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
210215 createStubFunction(JTEntryAddr);
211216 RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
156156 uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
157157 unsigned NumBytes = 1 << Size;
158158
159 ErrorOr SubtrahendNameOrErr = RelI->getSymbol()->getName();
160 if (auto EC = SubtrahendNameOrErr.getError())
161 report_fatal_error(EC.message());
159 Expected SubtrahendNameOrErr = RelI->getSymbol()->getName();
160 if (!SubtrahendNameOrErr) {
161 std::string Buf;
162 raw_string_ostream OS(Buf);
163 logAllUnhandledErrors(SubtrahendNameOrErr.takeError(), OS, "");
164 OS.flush();
165 report_fatal_error(Buf);
166 }
162167 auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
163168 unsigned SectionBID = SubtrahendI->second.getSectionID();
164169 uint64_t SectionBOffset = SubtrahendI->second.getOffset();
166171 SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
167172
168173 ++RelI;
169 ErrorOr MinuendNameOrErr = RelI->getSymbol()->getName();
170 if (auto EC = MinuendNameOrErr.getError())
171 report_fatal_error(EC.message());
174 Expected MinuendNameOrErr = RelI->getSymbol()->getName();
175 if (!MinuendNameOrErr) {
176 std::string Buf;
177 raw_string_ostream OS(Buf);
178 logAllUnhandledErrors(MinuendNameOrErr.takeError(), OS, "");
179 OS.flush();
180 report_fatal_error(Buf);
181 }
172182 auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
173183 unsigned SectionAID = MinuendI->second.getSectionID();
174184 uint64_t SectionAOffset = MinuendI->second.getOffset();
143143 }
144144 }
145145
146 ErrorOr COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
146 Expected COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
147147 COFFSymbolRef Symb = getCOFFSymbol(Ref);
148148 StringRef Result;
149149 std::error_code EC = getSymbolName(Symb, Result);
150150 if (EC)
151 return EC;
151 return errorCodeToError(EC);
152152 return Result;
153153 }
154154
4545 ECOverride);
4646 }
4747
48
4948 // FIXME: Remove ECOverride once Error has been plumbed down to obj tool code.
5049 static Error
51 malformedError(const MachOObjectFile &Obj, std::string Msg,
50 malformedError(const MachOObjectFile &Obj, Twine Msg,
5251 object_error ECOverride = object_error::parse_failed) {
53 return malformedError(Obj.getFileName(), std::move(Msg), ECOverride);
52 return malformedError(Obj.getFileName(), std::move(Msg.str()), ECOverride);
5453 }
5554
5655 // FIXME: Replace all uses of this function with getStructOrErr.
443442 Symb.p += SymbolTableEntrySize;
444443 }
445444
446 ErrorOr MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
445 Expected MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
447446 StringRef StringTable = getStringTableData();
448447 MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
449448 const char *Start = &StringTable.data()[Entry.n_strx];
450 if (Start < getData().begin() || Start >= getData().end())
451 return object_error::parse_failed;
449 if (Start < getData().begin() || Start >= getData().end()) {
450 return malformedError(*this, Twine("truncated or malformed object (bad "
451 "string index: ") + Twine(Entry.n_strx) + Twine(" for "
452 "symbol at index ") + Twine(getSymbolIndex(Symb)) +
453 Twine(")"));
454 }
452455 return StringRef(Start);
453456 }
454457
11051108 DRI.p = reinterpret_cast(getPtr(this, Symtab.symoff));
11061109 DRI.p += Index * SymbolTableEntrySize;
11071110 return basic_symbol_iterator(SymbolRef(DRI, this));
1111 }
1112
1113 uint64_t MachOObjectFile::getSymbolIndex(DataRefImpl Symb) const {
1114 MachO::symtab_command Symtab = getSymtabLoadCommand();
1115 if (!SymtabLoadCmd)
1116 report_fatal_error("getSymbolIndex() called with no symbol table symbol");
1117 unsigned SymbolTableEntrySize =
1118 is64Bit() ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist);
1119 DataRefImpl DRIstart;
1120 DRIstart.p = reinterpret_cast(getPtr(this, Symtab.symoff));
1121 uint64_t Index = (Symb.p - DRIstart.p) / SymbolTableEntrySize;
1122 return Index;
11081123 }
11091124
11101125 section_iterator MachOObjectFile::section_begin() const {
177177
178178 // SymbolRef accessors
179179 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
180 ErrorOr Ret = (*unwrap(SI))->getName();
181 if (std::error_code EC = Ret.getError())
182 report_fatal_error(EC.message());
180 Expected Ret = (*unwrap(SI))->getName();
181 if (!Ret) {
182 std::string Buf;
183 raw_string_ostream OS(Buf);
184 logAllUnhandledErrors(Ret.takeError(), OS, "");
185 OS.flush();
186 report_fatal_error(Buf);
187 }
183188 return Ret->data();
184189 }
185190
4545
4646 std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
4747 DataRefImpl Symb) const {
48 ErrorOr Name = getSymbolName(Symb);
49 if (std::error_code EC = Name.getError())
50 return EC;
48 Expected Name = getSymbolName(Symb);
49 if (!Name)
50 return errorToErrorCode(Name.takeError());
5151 OS << *Name;
5252 return std::error_code();
5353 }
3535
3636 RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
3737 RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
38 NAME-PAST-EOF: error reading file: Invalid data was encountered while parsing the file.
38 NAME-PAST-EOF: truncated or malformed object (bad string index: 4261412866 for symbol at index 0)
3939 RUN: llvm-nm -pa %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
4040 RUN: | FileCheck -check-prefix NAME-PAST-EOF-nm-pa %s
4141 NAME-PAST-EOF-nm-pa: 0000000000000000 - 00 0000 SO bad string index
227227 // look them up here and rewrite them.
228228 for (const auto &Sym : ErrOrObjectFile->symbols()) {
229229 uint64_t Address = Sym.getValue();
230 ErrorOr Name = Sym.getName();
230 Expected Name = Sym.getName();
231231 if (!Name ||
232 (Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common)))
232 (Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common))) {
233 // TODO: Actually report errors helpfully.
234 if (!Name)
235 consumeError(Name.takeError());
233236 continue;
237 }
234238 SymbolAddresses[*Name] = Address;
235239 }
236240 }
19501950
19511951 auto Sym = Reloc.getSymbol();
19521952 if (Sym != Obj.symbol_end()) {
1953 ErrorOr SymbolName = Sym->getName();
1953 Expected SymbolName = Sym->getName();
19541954 if (!SymbolName) {
1955 consumeError(SymbolName.takeError());
19551956 Linker.reportWarning("error getting relocation symbol name.");
19561957 continue;
19571958 }
401401
402402 for (auto Sym : Obj.symbols()) {
403403 uint64_t Addr = Sym.getValue();
404 ErrorOr Name = Sym.getName();
405 if (!Name)
406 continue;
404 Expected Name = Sym.getName();
405 if (!Name) {
406 // TODO: Actually report errors helpfully.
407 consumeError(Name.takeError());
408 continue;
409 }
407410 // The value of some categories of symbols isn't meaningful. For
408411 // example common symbols store their size in the value field, not
409412 // their address. Absolute symbols have a fixed address that can
456459 if (Section == MainBinary.section_end() || Section->isText())
457460 continue;
458461 uint64_t Addr = Sym.getValue();
459 ErrorOr NameOrErr = Sym.getName();
460 if (!NameOrErr)
461 continue;
462 Expected NameOrErr = Sym.getName();
463 if (!NameOrErr) {
464 // TODO: Actually report errors helpfully.
465 consumeError(NameOrErr.takeError());
466 continue;
467 }
462468 StringRef Name = *NameOrErr;
463469 if (Name.size() == 0 || Name[0] == '\0')
464470 continue;
7878 const object::symbol_iterator RelocSymI = Reloc.getSymbol();
7979 if (RelocSymI == Obj->symbol_end())
8080 continue;
81 ErrorOr RelocSymName = RelocSymI->getName();
82 error(RelocSymName.getError());
81 Expected RelocSymName = RelocSymI->getName();
82 error(errorToErrorCode(RelocSymName.takeError()));
8383 uint64_t Offset = Reloc.getOffset();
8484 if (Offset >= SymOffset && Offset < SymEnd) {
8585 *I = *RelocSymName;
100100 const object::symbol_iterator RelocSymI = Reloc.getSymbol();
101101 if (RelocSymI == Obj->symbol_end())
102102 continue;
103 ErrorOr RelocSymName = RelocSymI->getName();
104 error(RelocSymName.getError());
103 Expected RelocSymName = RelocSymI->getName();
104 error(errorToErrorCode(RelocSymName.takeError()));
105105 uint64_t Offset = Reloc.getOffset();
106106 if (Offset >= SymOffset && Offset < SymEnd)
107107 Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
174174 for (auto &P : SymAddr) {
175175 object::SymbolRef Sym = P.first;
176176 uint64_t SymSize = P.second;
177 ErrorOr SymNameOrErr = Sym.getName();
178 error(SymNameOrErr.getError());
177 Expected SymNameOrErr = Sym.getName();
178 error(errorToErrorCode(SymNameOrErr.takeError()));
179179 StringRef SymName = *SymNameOrErr;
180180 ErrorOr SecIOrErr = Sym.getSection();
181181 error(SecIOrErr.getError());
723723 }
724724
725725 if (SymI->getELFType() == ELF::STT_SECTION) {
726 ErrorOr Name = SymI->getName();
727 if (error(Name.getError()))
726 Expected Name = SymI->getName();
727 if (!Name) {
728 consumeError(Name.takeError());
728729 return '?';
730 }
729731 return StringSwitch(*Name)
730732 .StartsWith(".debug", 'N')
731733 .StartsWith(".note", 'n')
740742 // OK, this is COFF.
741743 symbol_iterator SymI(I);
742744
743 ErrorOr Name = SymI->getName();
744 if (error(Name.getError()))
745 Expected Name = SymI->getName();
746 if (!Name) {
747 consumeError(Name.takeError());
745748 return '?';
749 }
746750
747751 char Ret = StringSwitch(*Name)
748752 .StartsWith(".debug", 'N')
214214 SymbolRef Sym;
215215 if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
216216 return EC;
217 ErrorOr NameOrErr = Sym.getName();
218 if (std::error_code EC = NameOrErr.getError())
219 return EC;
217 Expected NameOrErr = Sym.getName();
218 if (!NameOrErr)
219 return errorToErrorCode(NameOrErr.takeError());
220220 Name = *NameOrErr;
221221 return std::error_code();
222222 }
272272 SmallVectorImpl &FoundFns,
273273 uint64_t &BaseSegmentAddress) {
274274 for (const SymbolRef &Symbol : MachOObj->symbols()) {
275 ErrorOr SymName = Symbol.getName();
276 if (std::error_code EC = SymName.getError())
277 report_fatal_error(EC.message());
275 Expected SymName = Symbol.getName();
276 if (!SymName) {
277 std::string Buf;
278 raw_string_ostream OS(Buf);
279 logAllUnhandledErrors(SymName.takeError(), OS, "");
280 OS.flush();
281 report_fatal_error(Buf);
282 }
278283 if (!SymName->startswith("ltmp"))
279284 Symbols.push_back(Symbol);
280285 }
352357 if (indirect_symbol < Symtab.nsyms) {
353358 symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
354359 SymbolRef Symbol = *Sym;
355 ErrorOr SymName = Symbol.getName();
356 if (std::error_code EC = SymName.getError())
357 report_fatal_error(EC.message());
360 Expected SymName = Symbol.getName();
361 if (!SymName) {
362 std::string Buf;
363 raw_string_ostream OS(Buf);
364 logAllUnhandledErrors(SymName.takeError(), OS, "");
365 OS.flush();
366 report_fatal_error(Buf);
367 }
358368 outs() << *SymName;
359369 } else {
360370 outs() << "?";
586596 if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
587597 ST == SymbolRef::ST_Other) {
588598 uint64_t Address = Symbol.getValue();
589 ErrorOr SymNameOrErr = Symbol.getName();
590 if (std::error_code EC = SymNameOrErr.getError())
591 report_fatal_error(EC.message());
599 Expected SymNameOrErr = Symbol.getName();
600 if (!SymNameOrErr) {
601 std::string Buf;
602 raw_string_ostream OS(Buf);
603 logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
604 OS.flush();
605 report_fatal_error(Buf);
606 }
592607 StringRef SymName = *SymNameOrErr;
593608 if (!SymName.startswith(".objc"))
594609 (*AddrMap)[Address] = SymName;
822837 [&](const std::pair &P) { return P.first == i; });
823838 if (Reloc != Relocs.end()) {
824839 symbol_iterator RelocSym = Reloc->second;
825 ErrorOr SymName = RelocSym->getName();
826 if (std::error_code EC = SymName.getError())
827 report_fatal_error(EC.message());
840 Expected SymName = RelocSym->getName();
841 if (!SymName) {
842 std::string Buf;
843 raw_string_ostream OS(Buf);
844 logAllUnhandledErrors(SymName.takeError(), OS, "");
845 OS.flush();
846 report_fatal_error(Buf);
847 }
828848 outs() << "external relocation entry for symbol:" << *SymName << "\n";
829849 continue;
830850 }
17771797 }
17781798 }
17791799 if (reloc_found && isExtern) {
1780 ErrorOr SymName = Symbol.getName();
1781 if (std::error_code EC = SymName.getError())
1782 report_fatal_error(EC.message());
1800 Expected SymName = Symbol.getName();
1801 if (!SymName) {
1802 std::string Buf;
1803 raw_string_ostream OS(Buf);
1804 logAllUnhandledErrors(SymName.takeError(), OS, "");
1805 OS.flush();
1806 report_fatal_error(Buf);
1807 }
17831808 const char *name = SymName->data();
17841809 op_info->AddSymbol.Present = 1;
17851810 op_info->AddSymbol.Name = name;
18471872 // is the offset from the external symbol.
18481873 if (info->O->getAnyRelocationPCRel(RE))
18491874 op_info->Value -= Pc + Offset + Size;
1850 ErrorOr SymName = Symbol.getName();
1851 if (std::error_code EC = SymName.getError())
1852 report_fatal_error(EC.message());
1875 Expected SymName = Symbol.getName();
1876 if (!SymName) {
1877 std::string Buf;
1878 raw_string_ostream OS(Buf);
1879 logAllUnhandledErrors(SymName.takeError(), OS, "");
1880 OS.flush();
1881 report_fatal_error(Buf);
1882 }
18531883 const char *name = SymName->data();
18541884 unsigned Type = info->O->getAnyRelocationType(RE);
18551885 if (Type == MachO::X86_64_RELOC_SUBTRACTOR) {
18641894 op_info->SubtractSymbol.Name = name;
18651895 symbol_iterator RelocSymNext = info->O->getSymbolByIndex(SymbolNum);
18661896 Symbol = *RelocSymNext;
1867 ErrorOr SymNameNext = Symbol.getName();
1868 if (std::error_code EC = SymNameNext.getError())
1869 report_fatal_error(EC.message());
1897 Expected SymNameNext = Symbol.getName();
1898 if (!SymNameNext) {
1899 std::string Buf;
1900 raw_string_ostream OS(Buf);
1901 logAllUnhandledErrors(SymNameNext.takeError(), OS, "");
1902 OS.flush();
1903 report_fatal_error(Buf);
1904 }
18701905 name = SymNameNext->data();
18711906 }
18721907 }
19371972 }
19381973
19391974 if (isExtern) {
1940 ErrorOr SymName = Symbol.getName();
1941 if (std::error_code EC = SymName.getError())
1942 report_fatal_error(EC.message());
1975 Expected SymName = Symbol.getName();
1976 if (!SymName) {
1977 std::string Buf;
1978 raw_string_ostream OS(Buf);
1979 logAllUnhandledErrors(SymName.takeError(), OS, "");
1980 OS.flush();
1981 report_fatal_error(Buf);
1982 }
19431983 const char *name = SymName->data();
19441984 op_info->AddSymbol.Present = 1;
19451985 op_info->AddSymbol.Name = name;
20572097 // NOTE: Scattered relocations don't exist on arm64.
20582098 if (!info->O->getPlainRelocationExternal(RE))
20592099 return 0;
2060 ErrorOr SymName = Reloc->getSymbol()->getName();
2061 if (std::error_code EC = SymName.getError())
2062 report_fatal_error(EC.message());
2100 Expected SymName = Reloc->getSymbol()->getName();
2101 if (!SymName) {
2102 std::string Buf;
2103 raw_string_ostream OS(Buf);
2104 logAllUnhandledErrors(SymName.takeError(), OS, "");
2105 OS.flush();
2106 report_fatal_error(Buf);
2107 }
20632108 const char *name = SymName->data();
20642109 op_info->AddSymbol.Present = 1;
20652110 op_info->AddSymbol.Name = name;
21872232 if (indirect_symbol < Symtab.nsyms) {
21882233 symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
21892234 SymbolRef Symbol = *Sym;
2190 ErrorOr SymName = Symbol.getName();
2191 if (std::error_code EC = SymName.getError())
2192 report_fatal_error(EC.message());
2235 Expected SymName = Symbol.getName();
2236 if (!SymName) {
2237 std::string Buf;
2238 raw_string_ostream OS(Buf);
2239 logAllUnhandledErrors(SymName.takeError(), OS, "");
2240 OS.flush();
2241 report_fatal_error(Buf);
2242 }
21932243 const char *name = SymName->data();
21942244 return name;
21952245 }
22222272 if (indirect_symbol < Symtab.nsyms) {
22232273 symbol_iterator Sym = info->O->getSymbolByIndex(indirect_symbol);
22242274 SymbolRef Symbol = *Sym;
2225 ErrorOr SymName = Symbol.getName();
2226 if (std::error_code EC = SymName.getError())
2227 report_fatal_error(EC.message());
2275 Expected SymName = Symbol.getName();
2276 if (!SymName) {
2277 std::string Buf;
2278 raw_string_ostream OS(Buf);
2279 logAllUnhandledErrors(SymName.takeError(), OS, "");
2280 OS.flush();
2281 report_fatal_error(Buf);
2282 }
22282283 const char *name = SymName->data();
22292284 return name;
22302285 }
24512506 const char *SymbolName = nullptr;
24522507 if (reloc_found && isExtern) {
24532508 n_value = Symbol.getValue();
2454 ErrorOr NameOrError = Symbol.getName();
2455 if (std::error_code EC = NameOrError.getError())
2456 report_fatal_error(EC.message());
2509 Expected NameOrError = Symbol.getName();
2510 if (!NameOrError) {
2511 std::string Buf;
2512 raw_string_ostream OS(Buf);
2513 logAllUnhandledErrors(NameOrError.takeError(), OS, "");
2514 OS.flush();
2515 report_fatal_error(Buf);
2516 }
24572517 StringRef Name = *NameOrError;
24582518 if (!Name.empty()) {
24592519 SymbolName = Name.data();
60996159 if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
61006160 ST == SymbolRef::ST_Other) {
61016161 uint64_t Address = Symbol.getValue();
6102 ErrorOr SymNameOrErr = Symbol.getName();
6103 if (std::error_code EC = SymNameOrErr.getError())
6104 report_fatal_error(EC.message());
6162 Expected SymNameOrErr = Symbol.getName();
6163 if (!SymNameOrErr) {
6164 std::string Buf;
6165 raw_string_ostream OS(Buf);
6166 logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
6167 OS.flush();
6168 report_fatal_error(Buf);
6169 }
61056170 StringRef SymName = *SymNameOrErr;
61066171 AddrMap[Address] = SymName;
61076172 if (!DisSymName.empty() && DisSymName == SymName)
61416206
61426207 // Disassemble symbol by symbol.
61436208 for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
6144 ErrorOr SymNameOrErr = Symbols[SymIdx].getName();
6145 if (std::error_code EC = SymNameOrErr.getError())
6146 report_fatal_error(EC.message());
6209 Expected SymNameOrErr = Symbols[SymIdx].getName();
6210 if (!SymNameOrErr) {
6211 std::string Buf;
6212 raw_string_ostream OS(Buf);
6213 logAllUnhandledErrors(SymNameOrErr.takeError(), OS, "");
6214 OS.flush();
6215 report_fatal_error(Buf);
6216 }
61476217 StringRef SymName = *SymNameOrErr;
61486218
61496219 ErrorOr STOrErr = Symbols[SymIdx].getType();
64116481 const RelocationRef &Reloc, uint64_t Addr,
64126482 StringRef &Name, uint64_t &Addend) {
64136483 if (Reloc.getSymbol() != Obj->symbol_end()) {
6414 ErrorOr NameOrErr = Reloc.getSymbol()->getName();
6415 if (std::error_code EC = NameOrErr.getError())
6416 report_fatal_error(EC.message());
6484 Expected NameOrErr = Reloc.getSymbol()->getName();
6485 if (!NameOrErr) {
6486 std::string Buf;
6487 raw_string_ostream OS(Buf);
6488 logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
6489 OS.flush();
6490 report_fatal_error(Buf);
6491 }
64176492 Name = *NameOrErr;
64186493 Addend = Addr;
64196494 return;
64396514 section_iterator SymSection = *Sym->second.getSection();
64406515 if (RelocSection == *SymSection) {
64416516 // There's a valid symbol in the same section before this reference.
6442 ErrorOr NameOrErr = Sym->second.getName();
6443 if (std::error_code EC = NameOrErr.getError())
6444 report_fatal_error(EC.message());
6517 Expected NameOrErr = Sym->second.getName();
6518 if (!NameOrErr) {
6519 std::string Buf;
6520 raw_string_ostream OS(Buf);
6521 logAllUnhandledErrors(NameOrErr.takeError(), OS, "");
6522 OS.flush();
6523 report_fatal_error(Buf);
6524 }
64456525 Name = *NameOrErr;
64466526 Addend = Addr - Sym->first;
64476527 return;
493493 return EC;
494494 Target = *SecName;
495495 } else {
496 ErrorOr SymName = symb->getName(StrTab);
496 Expected SymName = symb->getName(StrTab);
497497 if (!SymName)
498 return SymName.getError();
498 return errorToErrorCode(SymName.takeError());
499499 Target = *SymName;
500500 }
501501 switch (EF.getHeader()->e_machine) {
585585 const RelocationRef &Rel,
586586 SmallVectorImpl &Result) {
587587 symbol_iterator SymI = Rel.getSymbol();
588 ErrorOr SymNameOrErr = SymI->getName();
589 if (std::error_code EC = SymNameOrErr.getError())
590 return EC;
588 Expected SymNameOrErr = SymI->getName();
589 if (!SymNameOrErr)
590 return errorToErrorCode(SymNameOrErr.takeError());
591591 StringRef SymName = *SymNameOrErr;
592592 Result.append(SymName.begin(), SymName.end());
593593 return std::error_code();
612612 report_fatal_error(ec.message());
613613 if (*Addr != Val)
614614 continue;
615 ErrorOr Name = Symbol.getName();
616 if (std::error_code EC = Name.getError())
617 report_fatal_error(EC.message());
615 Expected Name = Symbol.getName();
616 if (!Name) {
617 std::string Buf;
618 raw_string_ostream OS(Buf);
619 logAllUnhandledErrors(Name.takeError(), OS, "");
620 OS.flush();
621 report_fatal_error(Buf);
622 }
618623 fmt << *Name;
619624 return;
620625 }
645650 if (isExtern) {
646651 symbol_iterator SI = O->symbol_begin();
647652 advance(SI, Val);
648 ErrorOr SOrErr = SI->getName();
649 error(SOrErr.getError());
653 Expected SOrErr = SI->getName();
654 error(errorToErrorCode(SOrErr.takeError()));
650655 S = *SOrErr;
651656 } else {
652657 section_iterator SI = O->section_begin();
951956 error(AddressOrErr.getError());
952957 uint64_t Address = *AddressOrErr;
953958
954 ErrorOr Name = Symbol.getName();
955 error(Name.getError());
959 Expected Name = Symbol.getName();
960 error(errorToErrorCode(Name.takeError()));
956961 if (Name->empty())
957962 continue;
958963
13571362 if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
13581363 Section->getName(Name);
13591364 } else {
1360 ErrorOr NameOrErr = Symbol.getName();
1361 error(NameOrErr.getError());
1365 Expected NameOrErr = Symbol.getName();
1366 if (!NameOrErr)
1367 report_error(o->getFileName(), NameOrErr.takeError());
13621368 Name = *NameOrErr;
13631369 }
13641370
354354
355355 for (const Elf_Sym &Sym : ELF->symbols(Symtab))
356356 if (Sym.st_shndx == Section && Sym.st_value == Address &&
357 Sym.getType() == ELF::STT_FUNC)
358 return Sym.getName(StrTable);
357 Sym.getType() == ELF::STT_FUNC) {
358 auto NameOrErr = Sym.getName(StrTable);
359 if (!NameOrErr) {
360 // TODO: Actually report errors helpfully.
361 consumeError(NameOrErr.takeError());
362 return readobj_error::unknown_symbol;
363 }
364 return *NameOrErr;
365 }
359366 return readobj_error::unknown_symbol;
360367 }
361368
569569 if (!Symbol)
570570 Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
571571
572 ErrorOr Name = Symbol->getName();
573 if (std::error_code EC = Name.getError())
574 report_fatal_error(EC.message());
572 Expected Name = Symbol->getName();
573 if (!Name) {
574 std::string Buf;
575 llvm::raw_string_ostream OS(Buf);
576 logAllUnhandledErrors(Name.takeError(), OS, "");
577 OS.flush();
578 report_fatal_error(Buf);
579 }
575580
576581 ListScope EHS(SW, "ExceptionHandler");
577582 SW.printString("Routine", formatSymbol(*Name, Address));
603608 StringRef FunctionName;
604609 uint64_t FunctionAddress;
605610 if (Function) {
606 ErrorOr FunctionNameOrErr = Function->getName();
607 if (std::error_code EC = FunctionNameOrErr.getError())
608 report_fatal_error(EC.message());
611 Expected FunctionNameOrErr = Function->getName();
612 if (!FunctionNameOrErr) {
613 std::string Buf;
614 llvm::raw_string_ostream OS(Buf);
615 logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
616 OS.flush();
617 report_fatal_error(Buf);
618 }
609619 FunctionName = *FunctionNameOrErr;
610620 ErrorOr FunctionAddressOrErr = Function->getAddress();
611621 if (std::error_code EC = FunctionAddressOrErr.getError())
621631 SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
622632
623633 if (XDataRecord) {
624 ErrorOr Name = XDataRecord->getName();
625 if (std::error_code EC = Name.getError())
626 report_fatal_error(EC.message());
634 Expected Name = XDataRecord->getName();
635 if (!Name) {
636 std::string Buf;
637 llvm::raw_string_ostream OS(Buf);
638 logAllUnhandledErrors(Name.takeError(), OS, "");
639 OS.flush();
640 report_fatal_error(Buf);
641 }
627642
628643 ErrorOr AddressOrErr = XDataRecord->getAddress();
629644 if (std::error_code EC = AddressOrErr.getError())
670685 StringRef FunctionName;
671686 uint64_t FunctionAddress;
672687 if (Function) {
673 ErrorOr FunctionNameOrErr = Function->getName();
674 if (std::error_code EC = FunctionNameOrErr.getError())
675 report_fatal_error(EC.message());
688 Expected FunctionNameOrErr = Function->getName();
689 if (!FunctionNameOrErr) {
690 std::string Buf;
691 llvm::raw_string_ostream OS(Buf);
692 logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
693 OS.flush();
694 report_fatal_error(Buf);
695 }
676696 FunctionName = *FunctionNameOrErr;
677697 ErrorOr FunctionAddressOrErr = Function->getAddress();
678698 FunctionAddress = *FunctionAddressOrErr;
186186 SymbolRef Symbol;
187187 if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
188188 return EC;
189 ErrorOr NameOrErr = Symbol.getName();
190 if (std::error_code EC = NameOrErr.getError())
191 return EC;
189 Expected NameOrErr = Symbol.getName();
190 if (!NameOrErr)
191 return errorToErrorCode(NameOrErr.takeError());
192192 Name = *NameOrErr;
193193 return std::error_code();
194194 }
26042604 Reloc.getTypeName(RelocName);
26052605 symbol_iterator Symbol = Reloc.getSymbol();
26062606 if (Symbol != Obj->symbol_end()) {
2607 ErrorOr SymbolNameOrErr = Symbol->getName();
2608 error(SymbolNameOrErr.getError());
2607 Expected SymbolNameOrErr = Symbol->getName();
2608 error(errorToErrorCode(SymbolNameOrErr.takeError()));
26092609 SymbolName = *SymbolNameOrErr;
26102610 }
26112611
540540 if (IsExtern) {
541541 symbol_iterator Symbol = Reloc.getSymbol();
542542 if (Symbol != Obj->symbol_end()) {
543 ErrorOr TargetNameOrErr = Symbol->getName();
544 error(TargetNameOrErr.getError());
543 Expected TargetNameOrErr = Symbol->getName();
544 if (!TargetNameOrErr)
545 error(errorToErrorCode(TargetNameOrErr.takeError()));
545546 TargetName = *TargetNameOrErr;
546547 }
547548 } else if (!IsScattered) {
604605
605606 void MachODumper::printSymbol(const SymbolRef &Symbol) {
606607 StringRef SymbolName;
607 if (ErrorOr SymbolNameOrErr = Symbol.getName())
608 Expected SymbolNameOrErr = Symbol.getName();
609 if (!SymbolNameOrErr) {
610 // TODO: Actually report errors helpfully.
611 consumeError(SymbolNameOrErr.takeError());
612 } else
608613 SymbolName = *SymbolNameOrErr;
609614
610615 MachOSymbol MOSymbol;
119119
120120 SymbolRef Symbol;
121121 if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
122 if (ErrorOr Name = Symbol.getName()) {
122 Expected Name = Symbol.getName();
123 if (Name) {
123124 OS << *Name;
124125 if (Displacement > 0)
125126 OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
126127 else
127128 OS << format(" (0x%" PRIX64 ")", Offset);
128129 return OS.str();
130 } else {
131 // TODO: Actually report errors helpfully.
132 consumeError(Name.takeError());
129133 }
130134 }
131135
1212 #include "llvm/Support/CommandLine.h"
1313 #include "llvm/Support/Compiler.h"
1414 #include "llvm/Support/ErrorOr.h"
15 #include "llvm/Support/Error.h"
1516 #include
1617
1718 namespace llvm {
2627 if (EO)
2728 return *EO;
2829 reportError(EO.getError().message());
30 }
31 template T unwrapOrError(Expected EO) {
32 if (EO)
33 return *EO;
34 std::string Buf;
35 raw_string_ostream OS(Buf);
36 logAllUnhandledErrors(EO.takeError(), OS, "");
37 OS.flush();
38 reportError(Buf);
2939 }
3040 bool relocAddressLess(object::RelocationRef A,
3141 object::RelocationRef B);
339339 continue;
340340 SymbolRef::Type Type = *TypeOrErr;
341341 if (Type == object::SymbolRef::ST_Function) {
342 ErrorOr Name = Sym.getName();
343 if (!Name)
342 Expected Name = Sym.getName();
343 if (!Name) {
344 // TODO: Actually report errors helpfully.
345 consumeError(Name.takeError());
344346 continue;
347 }
345348 ErrorOr AddrOrErr = Sym.getAddress();
346349 if (!AddrOrErr)
347350 continue;
120120 const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
121121 COFFYAML::Relocation Rel;
122122 object::symbol_iterator Sym = Reloc.getSymbol();
123 ErrorOr SymbolNameOrErr = Sym->getName();
124 if (std::error_code EC = SymbolNameOrErr.getError())
125 report_fatal_error(EC.message());
123 Expected SymbolNameOrErr = Sym->getName();
124 if (!SymbolNameOrErr) {
125 std::string Buf;
126 raw_string_ostream OS(Buf);
127 logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS, "");
128 OS.flush();
129 report_fatal_error(Buf);
130 }
126131 Rel.SymbolName = *SymbolNameOrErr;
127132 Rel.VirtualAddress = reloc->VirtualAddress;
128133 Rel.Type = reloc->Type;
178178 S.Size = Sym->st_size;
179179 S.Other = Sym->st_other;
180180
181 ErrorOr NameOrErr = Sym->getName(StrTable);
182 if (std::error_code EC = NameOrErr.getError())
183 return EC;
184 S.Name = NameOrErr.get();
181 Expected SymbolNameOrErr = Sym->getName(StrTable);
182 if (!SymbolNameOrErr)
183 return errorToErrorCode(SymbolNameOrErr.takeError());
184 S.Name = SymbolNameOrErr.get();
185185
186186 ErrorOr ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
187187 if (std::error_code EC = ShdrOrErr.getError())
190190 if (!Shdr)
191191 return obj2yaml_error::success;
192192
193 NameOrErr = Obj.getSectionName(Shdr);
193 ErrorOr NameOrErr = Obj.getSectionName(Shdr);
194194 if (std::error_code EC = NameOrErr.getError())
195195 return EC;
196196 S.Section = NameOrErr.get();
216216 return EC;
217217 StringRef StrTab = *StrTabOrErr;
218218
219 ErrorOr NameOrErr = Sym->getName(StrTab);
220 if (std::error_code EC = NameOrErr.getError())
221 return EC;
219 Expected NameOrErr = Sym->getName(StrTab);
220 if (!NameOrErr)
221 return errorToErrorCode(NameOrErr.takeError());
222222 R.Symbol = NameOrErr.get();
223223
224224 return obj2yaml_error::success;
367367 auto sectionContents = Obj.getSectionContents(Shdr);
368368 if (std::error_code ec = sectionContents.getError())
369369 return ec;
370 ErrorOr symbolName = symbol->getName(StrTab);
371 if (std::error_code EC = symbolName.getError())
372 return EC;
370 Expected symbolName = symbol->getName(StrTab);
371 if (!symbolName)
372 return errorToErrorCode(symbolName.takeError());
373373 S->Info = *symbolName;
374374 const Elf_Word *groupMembers =
375375 reinterpret_cast(sectionContents->data());
313313 ErrorOr AddressOrErr = Symbol.getAddress();
314314 FailIfError(AddressOrErr);
315315
316 ErrorOr NameOrErr = Symbol.getName();
317 FailIfError(NameOrErr);
316 Expected NameOrErr = Symbol.getName();
317 FailIfError(errorToErrorCode(NameOrErr.takeError()));
318318 StringRef Name = NameOrErr.get();
319319
320320 if (Name == "__sanitizer_cov" || Name == "__sanitizer_cov_with_check" ||