llvm.org GIT mirror llvm / 3e22297
[Object] Start threading Error through MachOObjectFile construction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264425 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
5 changed file(s) with 213 addition(s) and 115 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_OBJECT_ERROR_H
1414 #define LLVM_OBJECT_ERROR_H
1515
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/Support/Error.h"
1618 #include
1719
1820 namespace llvm {
1921 namespace object {
22
23 class Binary;
2024
2125 const std::error_category &object_category();
2226
3842 return std::error_code(static_cast(e), object_category());
3943 }
4044
45 /// Base class for all errors indicating malformed binary files.
46 ///
47 /// Having a subclass for all malformed binary files allows archive-walking
48 /// code to skip malformed files without having to understand every possible
49 /// way that a binary file might be malformed.
50 ///
51 /// Currently inherits from ECError for easy interoperability with
52 /// std::error_code, but this will be removed in the future.
53 class BinaryError : public ErrorInfo {
54 public:
55 static char ID;
56 BinaryError() {
57 // Default to parse_failed, can be overridden with setErrorCode.
58 setErrorCode(make_error_code(object_error::parse_failed));
59 }
60 private:
61 };
62
63 /// Generic binary error.
64 ///
65 /// For errors that don't require their own specific sub-error (most errors)
66 /// this class can be used to describe the error via a string message.
67 class GenericBinaryError : public ErrorInfo {
68 public:
69 static char ID;
70 GenericBinaryError(std::string FileName, Twine Msg);
71 GenericBinaryError(std::string FileName, Twine Msg, object_error ECOverride);
72 const std::string &getFileName() const { return FileName; }
73 const std::string &getMessage() const { return Msg; }
74 void log(raw_ostream &OS) const override;
75 private:
76 std::string FileName;
77 std::string Msg;
78 };
79
4180 } // end namespace object.
4281
4382 } // end namespace llvm.
193193 typedef LoadCommandList::const_iterator load_command_iterator;
194194
195195 MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
196 std::error_code &EC);
196 Error &Err);
197197
198198 void moveSymbolNext(DataRefImpl &Symb) const override;
199199
5757 "defined.");
5858 }
5959
60 char BinaryError::ID = 0;
61 char GenericBinaryError::ID = 0;
62
63 GenericBinaryError::GenericBinaryError(std::string FileName, Twine Msg)
64 : FileName(std::move(FileName)), Msg(Msg.str()) {}
65
66 GenericBinaryError::GenericBinaryError(std::string FileName, Twine Msg, object_error ECOverride)
67 : FileName(std::move(FileName)), Msg(Msg.str()) {
68 setErrorCode(make_error_code(ECOverride));
69 }
70
71 void GenericBinaryError::log(raw_ostream &OS) const {
72 OS << "Error in " << FileName << ": " << Msg;
73 }
74
6075 static ManagedStatic<_object_error_category> error_category;
6176
6277 const std::error_category &object::object_category() {
3737 };
3838 }
3939
40 // FIXME: Remove ECOverride once Error has been plumbed down to obj tool code.
41 static Error
42 malformedError(std::string FileName, std::string Msg,
43 object_error ECOverride = object_error::parse_failed) {
44 return make_error(std::move(FileName), std::move(Msg),
45 ECOverride);
46 }
47
48
49 // FIXME: Remove ECOverride once Error has been plumbed down to obj tool code.
50 static Error
51 malformedError(const MachOObjectFile &Obj, std::string Msg,
52 object_error ECOverride = object_error::parse_failed) {
53 return malformedError(Obj.getFileName(), std::move(Msg), ECOverride);
54 }
55
4056 // FIXME: Replace all uses of this function with getStructOrErr.
4157 template
4258 static T getStruct(const MachOObjectFile *O, const char *P) {
5268 }
5369
5470 template
55 static ErrorOr getStructOrErr(const MachOObjectFile *O, const char *P) {
71 static Expected getStructOrErr(const MachOObjectFile *O, const char *P) {
5672 // Don't read before the beginning or past the end of the file
5773 if (P < O->getData().begin() || P + sizeof(T) > O->getData().end())
58 return object_error::parse_failed;
74 return malformedError(*O, "Structure read out-of-range");
5975
6076 T Cmd;
6177 memcpy(&Cmd, P, sizeof(T));
160176 return Sect.flags;
161177 }
162178
163 static ErrorOr
179 static Expected
164180 getLoadCommandInfo(const MachOObjectFile *Obj, const char *Ptr) {
165 auto CmdOrErr = getStructOrErr(Obj, Ptr);
166 if (!CmdOrErr)
167 return CmdOrErr.getError();
168 if (CmdOrErr->cmdsize < 8)
169 return object_error::macho_small_load_command;
170 MachOObjectFile::LoadCommandInfo Load;
171 Load.Ptr = Ptr;
172 Load.C = CmdOrErr.get();
173 return Load;
174 }
175
176 static ErrorOr
181 if (auto CmdOrErr = getStructOrErr(Obj, Ptr)) {
182 if (CmdOrErr->cmdsize < 8)
183 return malformedError(*Obj, "Mach-O load command with size < 8 bytes",
184 object_error::macho_small_load_command);
185 return MachOObjectFile::LoadCommandInfo({Ptr, *CmdOrErr});
186 } else
187 return CmdOrErr.takeError();
188 }
189
190 static Expected
177191 getFirstLoadCommandInfo(const MachOObjectFile *Obj) {
178192 unsigned HeaderSize = Obj->is64Bit() ? sizeof(MachO::mach_header_64)
179193 : sizeof(MachO::mach_header);
180194 return getLoadCommandInfo(Obj, getPtr(Obj, HeaderSize));
181195 }
182196
183 static ErrorOr
197 static Expected
184198 getNextLoadCommandInfo(const MachOObjectFile *Obj,
185199 const MachOObjectFile::LoadCommandInfo &L) {
186200 return getLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize);
188202
189203 template
190204 static void parseHeader(const MachOObjectFile *Obj, T &Header,
191 std::error_code &EC) {
192 auto HeaderOrErr = getStructOrErr(Obj, getPtr(Obj, 0));
193 if (HeaderOrErr)
194 Header = HeaderOrErr.get();
205 Error &Err) {
206 if (auto HeaderOrErr = getStructOrErr(Obj, getPtr(Obj, 0)))
207 Header = *HeaderOrErr;
195208 else
196 EC = HeaderOrErr.getError();
209 Err = HeaderOrErr.takeError();
197210 }
198211
199212 // Parses LC_SEGMENT or LC_SEGMENT_64 load command, adds addresses of all
200213 // sections to \param Sections, and optionally sets
201214 // \param IsPageZeroSegment to true.
202215 template
203 static std::error_code parseSegmentLoadCommand(
216 static Error parseSegmentLoadCommand(
204217 const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load,
205218 SmallVectorImpl &Sections, bool &IsPageZeroSegment) {
206219 const unsigned SegmentLoadSize = sizeof(SegmentCmd);
207220 if (Load.C.cmdsize < SegmentLoadSize)
208 return object_error::macho_load_segment_too_small;
209 auto SegOrErr = getStructOrErr(Obj, Load.Ptr);
210 if (!SegOrErr)
211 return SegOrErr.getError();
212 SegmentCmd S = SegOrErr.get();
213 const unsigned SectionSize =
221 return malformedError(*Obj,
222 "Mach-O segment load command size is too small",
223 object_error::macho_load_segment_too_small);
224 if (auto SegOrErr = getStructOrErr(Obj, Load.Ptr)) {
225 SegmentCmd S = SegOrErr.get();
226 const unsigned SectionSize =
214227 Obj->is64Bit() ? sizeof(MachO::section_64) : sizeof(MachO::section);
215 if (S.nsects > std::numeric_limits::max() / SectionSize ||
216 S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize)
217 return object_error::macho_load_segment_too_many_sections;
218 for (unsigned J = 0; J < S.nsects; ++J) {
219 const char *Sec = getSectionPtr(Obj, Load, J);
220 Sections.push_back(Sec);
221 }
222 IsPageZeroSegment |= StringRef("__PAGEZERO").equals(S.segname);
223 return std::error_code();
228 if (S.nsects > std::numeric_limits::max() / SectionSize ||
229 S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize)
230 return malformedError(*Obj,
231 "Mach-O segment load command contains too many "
232 "sections",
233 object_error::macho_load_segment_too_many_sections);
234 for (unsigned J = 0; J < S.nsects; ++J) {
235 const char *Sec = getSectionPtr(Obj, Load, J);
236 Sections.push_back(Sec);
237 }
238 IsPageZeroSegment |= StringRef("__PAGEZERO").equals(S.segname);
239 } else
240 return SegOrErr.takeError();
241
242 return Error::success();
224243 }
225244
226245 MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
227 bool Is64bits, std::error_code &EC)
246 bool Is64bits, Error &Err)
228247 : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
229248 SymtabLoadCmd(nullptr), DysymtabLoadCmd(nullptr),
230249 DataInCodeLoadCmd(nullptr), LinkOptHintsLoadCmd(nullptr),
231250 DyldInfoLoadCmd(nullptr), UuidLoadCmd(nullptr),
232251 HasPageZeroSegment(false) {
252
253 // We have to check Err before it's assigned to.
254 if (Err)
255 llvm_unreachable("Err should be in success state at entry to constructor.");
256
233257 if (is64Bit())
234 parseHeader(this, Header64, EC);
258 parseHeader(this, Header64, Err);
235259 else
236 parseHeader(this, Header, EC);
237 if (EC)
260 parseHeader(this, Header, Err);
261 if (Err)
238262 return;
239263
240264 uint32_t LoadCommandCount = getHeader().ncmds;
241265 if (LoadCommandCount == 0)
242266 return;
243267
244 auto LoadOrErr = getFirstLoadCommandInfo(this);
245 if (!LoadOrErr) {
246 EC = LoadOrErr.getError();
268 LoadCommandInfo Load;
269 if (auto LoadOrErr = getFirstLoadCommandInfo(this))
270 Load = *LoadOrErr;
271 else {
272 Err = LoadOrErr.takeError();
247273 return;
248274 }
249 LoadCommandInfo Load = LoadOrErr.get();
275
250276 for (unsigned I = 0; I < LoadCommandCount; ++I) {
251277 LoadCommands.push_back(Load);
252278 if (Load.C.cmd == MachO::LC_SYMTAB) {
253279 // Multiple symbol tables
254280 if (SymtabLoadCmd) {
255 EC = object_error::parse_failed;
281 Err = malformedError(*this, "Multiple symbol tables");
256282 return;
257283 }
258284 SymtabLoadCmd = Load.Ptr;
259285 } else if (Load.C.cmd == MachO::LC_DYSYMTAB) {
260286 // Multiple dynamic symbol tables
261287 if (DysymtabLoadCmd) {
262 EC = object_error::parse_failed;
288 Err = malformedError(*this, "Multiple dynamic symbol tables");
263289 return;
264290 }
265291 DysymtabLoadCmd = Load.Ptr;
266292 } else if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
267293 // Multiple data in code tables
268294 if (DataInCodeLoadCmd) {
269 EC = object_error::parse_failed;
295 Err = malformedError(*this, "Multiple data-in-code tables");
270296 return;
271297 }
272298 DataInCodeLoadCmd = Load.Ptr;
273299 } else if (Load.C.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) {
274300 // Multiple linker optimization hint tables
275301 if (LinkOptHintsLoadCmd) {
276 EC = object_error::parse_failed;
302 Err = malformedError(*this, "Multiple linker optimization hint tables");
277303 return;
278304 }
279305 LinkOptHintsLoadCmd = Load.Ptr;
281307 Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
282308 // Multiple dyldinfo load commands
283309 if (DyldInfoLoadCmd) {
284 EC = object_error::parse_failed;
310 Err = malformedError(*this, "Multiple dyldinfo load commands");
285311 return;
286312 }
287313 DyldInfoLoadCmd = Load.Ptr;
288314 } else if (Load.C.cmd == MachO::LC_UUID) {
289315 // Multiple UUID load commands
290316 if (UuidLoadCmd) {
291 EC = object_error::parse_failed;
317 Err = malformedError(*this, "Multiple UUID load commands");
292318 return;
293319 }
294320 UuidLoadCmd = Load.Ptr;
295321 } else if (Load.C.cmd == MachO::LC_SEGMENT_64) {
296 if ((EC = parseSegmentLoadCommand(
297 this, Load, Sections, HasPageZeroSegment)))
322 if ((Err = parseSegmentLoadCommand(
323 this, Load, Sections, HasPageZeroSegment)))
298324 return;
299325 } else if (Load.C.cmd == MachO::LC_SEGMENT) {
300 if ((EC = parseSegmentLoadCommand(
301 this, Load, Sections, HasPageZeroSegment)))
326 if ((Err = parseSegmentLoadCommand(
327 this, Load, Sections, HasPageZeroSegment)))
302328 return;
303329 } else if (Load.C.cmd == MachO::LC_LOAD_DYLIB ||
304330 Load.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
308334 Libraries.push_back(Load.Ptr);
309335 }
310336 if (I < LoadCommandCount - 1) {
311 auto LoadOrErr = getNextLoadCommandInfo(this, Load);
312 if (!LoadOrErr) {
313 EC = LoadOrErr.getError();
337 if (auto LoadOrErr = getNextLoadCommandInfo(this, Load))
338 Load = *LoadOrErr;
339 else {
340 Err = LoadOrErr.takeError();
314341 return;
315342 }
316 Load = LoadOrErr.get();
317343 }
318344 }
319345 if (!SymtabLoadCmd) {
320346 if (DysymtabLoadCmd) {
321 // Diagnostic("truncated or malformed object (contains LC_DYSYMTAB load "
322 // "command without a LC_SYMTAB load command)");
323 EC = object_error::parse_failed;
347 Err = malformedError(*this,
348 "truncated or malformed object (contains "
349 "LC_DYSYMTAB load command without a LC_SYMTAB load "
350 "command)");
324351 return;
325352 }
326353 } else if (DysymtabLoadCmd) {
329356 MachO::dysymtab_command Dysymtab =
330357 getStruct(this, DysymtabLoadCmd);
331358 if (Dysymtab.nlocalsym != 0 && Dysymtab.ilocalsym > Symtab.nsyms) {
332 // Diagnostic("truncated or malformed object (ilocalsym in LC_DYSYMTAB "
333 // "load command extends past the end of the symbol table)"
334 EC = object_error::parse_failed;
359 Err = malformedError(*this,
360 "truncated or malformed object (iolocalsym in "
361 "LC_DYSYMTAB load command extends past the end of "
362 "the symbol table)");
335363 return;
336364 }
337365 uint64_t big_size = Dysymtab.ilocalsym;
338366 big_size += Dysymtab.nlocalsym;
339367 if (Dysymtab.nlocalsym != 0 && big_size > Symtab.nsyms) {
340 // Diagnostic("truncated or malformed object (ilocalsym plus nlocalsym "
341 // "in LC_DYSYMTAB load command extends past the end of the symbol table)"
342 EC = object_error::parse_failed;
368 Err = malformedError(*this,
369 "truncated or malformed object (ilocalsym plus "
370 "nlocalsym in LC_DYSYMTAB load command extends past "
371 "the end of the symbol table)");
343372 return;
344373 }
345374 if (Dysymtab.nextdefsym != 0 && Dysymtab.ilocalsym > Symtab.nsyms) {
346 // Diagnostic("truncated or malformed object (nextdefsym in LC_DYSYMTAB "
347 // "load command extends past the end of the symbol table)"
348 EC = object_error::parse_failed;
375 Err = malformedError(*this,
376 "truncated or malformed object (nextdefsym in "
377 "LC_DYSYMTAB load command extends past the end of "
378 "the symbol table)");
349379 return;
350380 }
351381 big_size = Dysymtab.iextdefsym;
352382 big_size += Dysymtab.nextdefsym;
353383 if (Dysymtab.nextdefsym != 0 && big_size > Symtab.nsyms) {
354 // Diagnostic("truncated or malformed object (iextdefsym plus nextdefsym "
355 // "in LC_DYSYMTAB load command extends past the end of the symbol table)"
356 EC = object_error::parse_failed;
384 Err = malformedError(*this,
385 "truncated or malformed object (iextdefsym plus "
386 "nextdefsym in LC_DYSYMTAB load command extends "
387 "past the end of the symbol table)");
357388 return;
358389 }
359390 if (Dysymtab.nundefsym != 0 && Dysymtab.iundefsym > Symtab.nsyms) {
360 // Diagnostic("truncated or malformed object (nundefsym in LC_DYSYMTAB "
361 // "load command extends past the end of the symbol table)"
362 EC = object_error::parse_failed;
391 Err = malformedError(*this,
392 "truncated or malformed object (nundefsym in "
393 "LC_DYSYMTAB load command extends past the end of "
394 "the symbol table)");
363395 return;
364396 }
365397 big_size = Dysymtab.iundefsym;
366398 big_size += Dysymtab.nundefsym;
367399 if (Dysymtab.nundefsym != 0 && big_size > Symtab.nsyms) {
368 // Diagnostic("truncated or malformed object (iundefsym plus nundefsym "
369 // "in LC_DYSYMTAB load command extends past the end of the symbol table)"
370 EC = object_error::parse_failed;
400 Err = malformedError(*this,
401 "truncated or malformed object (iundefsym plus "
402 "nundefsym in LC_DYSYMTAB load command extends past "
403 "the end of the symbol table");
371404 return;
372405 }
373406 }
374407 assert(LoadCommands.size() == LoadCommandCount);
408
409 Err = Error::success();
375410 }
376411
377412 void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
23802415 ErrorOr>
23812416 ObjectFile::createMachOObjectFile(MemoryBufferRef Buffer) {
23822417 StringRef Magic = Buffer.getBuffer().slice(0, 4);
2383 std::error_code EC;
23842418 std::unique_ptr Ret;
2385 if (Magic == "\xFE\xED\xFA\xCE")
2386 Ret.reset(new MachOObjectFile(Buffer, false, false, EC));
2387 else if (Magic == "\xCE\xFA\xED\xFE")
2388 Ret.reset(new MachOObjectFile(Buffer, true, false, EC));
2389 else if (Magic == "\xFE\xED\xFA\xCF")
2390 Ret.reset(new MachOObjectFile(Buffer, false, true, EC));
2391 else if (Magic == "\xCF\xFA\xED\xFE")
2392 Ret.reset(new MachOObjectFile(Buffer, true, true, EC));
2393 else
2419 if (Magic == "\xFE\xED\xFA\xCE") {
2420 Error Err;
2421 Ret.reset(new MachOObjectFile(Buffer, false, false, Err));
2422 if (Err)
2423 return errorToErrorCode(std::move(Err));
2424 } else if (Magic == "\xCE\xFA\xED\xFE") {
2425 Error Err;
2426 Ret.reset(new MachOObjectFile(Buffer, true, false, Err));
2427 if (Err)
2428 return errorToErrorCode(std::move(Err));
2429 } else if (Magic == "\xFE\xED\xFA\xCF") {
2430 Error Err;
2431 Ret.reset(new MachOObjectFile(Buffer, false, true, Err));
2432 if (Err)
2433 return errorToErrorCode(std::move(Err));
2434 } else if (Magic == "\xCF\xFA\xED\xFE") {
2435 Error Err;
2436 Ret.reset(new MachOObjectFile(Buffer, true, true, Err));
2437 if (Err)
2438 return errorToErrorCode(std::move(Err));
2439 } else
23942440 return object_error::parse_failed;
23952441
2396 if (EC)
2397 return EC;
23982442 return std::move(Ret);
23992443 }
253253
254254 static const char *ProgramName;
255255
256 static int Error(const Twine &Msg) {
256 static int ErrorAndExit(const Twine &Msg) {
257257 errs() << ProgramName << ": error: " << Msg << "\n";
258 return 1;
258 exit(1);
259259 }
260260
261261 static void loadDylibs() {
289289 ErrorOr> InputBuffer =
290290 MemoryBuffer::getFileOrSTDIN(File);
291291 if (std::error_code EC = InputBuffer.getError())
292 return Error("unable to read input: '" + EC.message() + "'");
292 ErrorAndExit("unable to read input: '" + EC.message() + "'");
293293
294294 ErrorOr> MaybeObj(
295295 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
296296
297297 if (std::error_code EC = MaybeObj.getError())
298 return Error("unable to create object file: '" + EC.message() + "'");
298 ErrorAndExit("unable to create object file: '" + EC.message() + "'");
299299
300300 ObjectFile &Obj = **MaybeObj;
301301
308308 Dyld.loadObject(Obj);
309309
310310 if (Dyld.hasError())
311 return Error(Dyld.getErrorString());
311 ErrorAndExit(Dyld.getErrorString());
312312
313313 // Resolve all the relocations we can.
314314 Dyld.resolveRelocations();
399399 ErrorOr> InputBuffer =
400400 MemoryBuffer::getFileOrSTDIN(File);
401401 if (std::error_code EC = InputBuffer.getError())
402 return Error("unable to read input: '" + EC.message() + "'");
402 ErrorAndExit("unable to read input: '" + EC.message() + "'");
403403 ErrorOr> MaybeObj(
404404 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
405405
406406 if (std::error_code EC = MaybeObj.getError())
407 return Error("unable to create object file: '" + EC.message() + "'");
407 ErrorAndExit("unable to create object file: '" + EC.message() + "'");
408408
409409 ObjectFile &Obj = **MaybeObj;
410410
411411 // Load the object file
412412 Dyld.loadObject(Obj);
413413 if (Dyld.hasError()) {
414 return Error(Dyld.getErrorString());
414 ErrorAndExit(Dyld.getErrorString());
415415 }
416416 }
417417
422422 // Get the address of the entry point (_main by default).
423423 void *MainAddress = Dyld.getSymbolLocalAddress(EntryPoint);
424424 if (!MainAddress)
425 return Error("no definition for '" + EntryPoint + "'");
425 ErrorAndExit("no definition for '" + EntryPoint + "'");
426426
427427 // Invalidate the instruction cache for each loaded function.
428428 for (auto &FM : MemMgr.FunctionMemory) {
431431 // setExecutable will call InvalidateInstructionCache.
432432 std::string ErrorStr;
433433 if (!sys::Memory::setExecutable(FM, &ErrorStr))
434 return Error("unable to mark function executable: '" + ErrorStr + "'");
434 ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'");
435435 }
436436
437437 // Dispatch to _main().
451451 ErrorOr> CheckerFileBuf =
452452 MemoryBuffer::getFileOrSTDIN(CheckerFileName);
453453 if (std::error_code EC = CheckerFileBuf.getError())
454 return Error("unable to read input '" + CheckerFileName + "': " +
454 ErrorAndExit("unable to read input '" + CheckerFileName + "': " +
455455 EC.message());
456456
457457 if (!Checker.checkAllRulesInBuffer("# rtdyld-check:",
458458 CheckerFileBuf.get().get()))
459 return Error("some checks in '" + CheckerFileName + "' failed");
459 ErrorAndExit("some checks in '" + CheckerFileName + "' failed");
460460 }
461461 return 0;
462462 }
605605
606606 // Check for missing triple.
607607 if (TripleName == "")
608 return Error("-triple required when running in -verify mode.");
608 ErrorAndExit("-triple required when running in -verify mode.");
609609
610610 // Look up the target and build the disassembler.
611611 Triple TheTriple(Triple::normalize(TripleName));
613613 const Target *TheTarget =
614614 TargetRegistry::lookupTarget("", TheTriple, ErrorStr);
615615 if (!TheTarget)
616 return Error("Error accessing target '" + TripleName + "': " + ErrorStr);
616 ErrorAndExit("Error accessing target '" + TripleName + "': " + ErrorStr);
617617
618618 TripleName = TheTriple.getTriple();
619619
620620 std::unique_ptr STI(
621621 TheTarget->createMCSubtargetInfo(TripleName, MCPU, ""));
622622 if (!STI)
623 return Error("Unable to create subtarget info!");
623 ErrorAndExit("Unable to create subtarget info!");
624624
625625 std::unique_ptr MRI(TheTarget->createMCRegInfo(TripleName));
626626 if (!MRI)
627 return Error("Unable to create target register info!");
627 ErrorAndExit("Unable to create target register info!");
628628
629629 std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
630630 if (!MAI)
631 return Error("Unable to create target asm info!");
631 ErrorAndExit("Unable to create target asm info!");
632632
633633 MCContext Ctx(MAI.get(), MRI.get(), nullptr);
634634
635635 std::unique_ptr Disassembler(
636636 TheTarget->createMCDisassembler(*STI, Ctx));
637637 if (!Disassembler)
638 return Error("Unable to create disassembler!");
638 ErrorAndExit("Unable to create disassembler!");
639639
640640 std::unique_ptr MII(TheTarget->createMCInstrInfo());
641641
662662 MemoryBuffer::getFileOrSTDIN(Filename);
663663
664664 if (std::error_code EC = InputBuffer.getError())
665 return Error("unable to read input: '" + EC.message() + "'");
665 ErrorAndExit("unable to read input: '" + EC.message() + "'");
666666
667667 ErrorOr> MaybeObj(
668668 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
669669
670670 if (std::error_code EC = MaybeObj.getError())
671 return Error("unable to create object file: '" + EC.message() + "'");
671 ErrorAndExit("unable to create object file: '" + EC.message() + "'");
672672
673673 ObjectFile &Obj = **MaybeObj;
674674
675675 // Load the object file
676676 Dyld.loadObject(Obj);
677677 if (Dyld.hasError()) {
678 return Error(Dyld.getErrorString());
678 ErrorAndExit(Dyld.getErrorString());
679679 }
680680 }
681681
691691
692692 int ErrorCode = checkAllExpressions(Checker);
693693 if (Dyld.hasError())
694 return Error("RTDyld reported an error applying relocations:\n " +
694 ErrorAndExit("RTDyld reported an error applying relocations:\n " +
695695 Dyld.getErrorString());
696696
697697 return ErrorCode;