1 //===- lli.cpp - LLVM Interpreter / Dynamic compiler ----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This utility provides a simple wrapper around the LLVM Execution Engines, 10 // which allow the direct execution of LLVM programs through a Just-In-Time 11 // compiler, or through an interpreter if no JIT is available for this platform. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "ExecutionUtils.h" 16 #include "RemoteJITUtils.h" 17 #include "llvm/ADT/StringExtras.h" 18 #include "llvm/ADT/Triple.h" 19 #include "llvm/Bitcode/BitcodeReader.h" 20 #include "llvm/CodeGen/CommandFlags.h" 21 #include "llvm/CodeGen/LinkAllCodegenComponents.h" 22 #include "llvm/Config/llvm-config.h" 23 #include "llvm/ExecutionEngine/GenericValue.h" 24 #include "llvm/ExecutionEngine/Interpreter.h" 25 #include "llvm/ExecutionEngine/JITSymbol.h" 26 #include "llvm/ExecutionEngine/JITEventListener.h" 27 #include "llvm/ExecutionEngine/MCJIT.h" 28 #include "llvm/ExecutionEngine/ObjectCache.h" 29 #include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h" 30 #include "llvm/ExecutionEngine/Orc/DebugUtils.h" 31 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" 32 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" 33 #include "llvm/ExecutionEngine/Orc/LLJIT.h" 34 #include "llvm/ExecutionEngine/Orc/MachOPlatform.h" 35 #include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h" 36 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" 37 #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" 38 #include "llvm/ExecutionEngine/Orc/TPCDebugObjectRegistrar.h" 39 #include "llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h" 40 #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h" 41 #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h" 42 #include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h" 43 #include "llvm/ExecutionEngine/SectionMemoryManager.h" 44 #include "llvm/IR/IRBuilder.h" 45 #include "llvm/IR/LLVMContext.h" 46 #include "llvm/IR/Module.h" 47 #include "llvm/IR/Type.h" 48 #include "llvm/IR/Verifier.h" 49 #include "llvm/IRReader/IRReader.h" 50 #include "llvm/Object/Archive.h" 51 #include "llvm/Object/ObjectFile.h" 52 #include "llvm/Support/CommandLine.h" 53 #include "llvm/Support/Debug.h" 54 #include "llvm/Support/DynamicLibrary.h" 55 #include "llvm/Support/Format.h" 56 #include "llvm/Support/InitLLVM.h" 57 #include "llvm/Support/ManagedStatic.h" 58 #include "llvm/Support/MathExtras.h" 59 #include "llvm/Support/Memory.h" 60 #include "llvm/Support/MemoryBuffer.h" 61 #include "llvm/Support/Path.h" 62 #include "llvm/Support/PluginLoader.h" 63 #include "llvm/Support/Process.h" 64 #include "llvm/Support/Program.h" 65 #include "llvm/Support/SourceMgr.h" 66 #include "llvm/Support/TargetSelect.h" 67 #include "llvm/Support/WithColor.h" 68 #include "llvm/Support/raw_ostream.h" 69 #include "llvm/Transforms/Instrumentation.h" 70 #include <cerrno> 71 72 #ifdef __CYGWIN__ 73 #include <cygwin/version.h> 74 #if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007 75 #define DO_NOTHING_ATEXIT 1 76 #endif 77 #endif 78 79 using namespace llvm; 80 81 static codegen::RegisterCodeGenFlags CGF; 82 83 #define DEBUG_TYPE "lli" 84 85 namespace { 86 87 enum class JITKind { MCJIT, Orc, OrcLazy }; 88 enum class JITLinkerKind { Default, RuntimeDyld, JITLink }; 89 90 cl::opt<std::string> 91 InputFile(cl::desc("<input bitcode>"), cl::Positional, cl::init("-")); 92 93 cl::list<std::string> 94 InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>...")); 95 96 cl::opt<bool> ForceInterpreter("force-interpreter", 97 cl::desc("Force interpretation: disable JIT"), 98 cl::init(false)); 99 100 cl::opt<JITKind> UseJITKind( 101 "jit-kind", cl::desc("Choose underlying JIT kind."), 102 cl::init(JITKind::Orc), 103 cl::values(clEnumValN(JITKind::MCJIT, "mcjit", "MCJIT"), 104 clEnumValN(JITKind::Orc, "orc", "Orc JIT"), 105 clEnumValN(JITKind::OrcLazy, "orc-lazy", 106 "Orc-based lazy JIT."))); 107 108 cl::opt<JITLinkerKind> 109 JITLinker("jit-linker", cl::desc("Choose the dynamic linker/loader."), 110 cl::init(JITLinkerKind::Default), 111 cl::values(clEnumValN(JITLinkerKind::Default, "default", 112 "Default for platform and JIT-kind"), 113 clEnumValN(JITLinkerKind::RuntimeDyld, "rtdyld", 114 "RuntimeDyld"), 115 clEnumValN(JITLinkerKind::JITLink, "jitlink", 116 "Orc-specific linker"))); 117 118 cl::opt<unsigned> 119 LazyJITCompileThreads("compile-threads", 120 cl::desc("Choose the number of compile threads " 121 "(jit-kind=orc-lazy only)"), 122 cl::init(0)); 123 124 cl::list<std::string> 125 ThreadEntryPoints("thread-entry", 126 cl::desc("calls the given entry-point on a new thread " 127 "(jit-kind=orc-lazy only)")); 128 129 cl::opt<bool> PerModuleLazy( 130 "per-module-lazy", 131 cl::desc("Performs lazy compilation on whole module boundaries " 132 "rather than individual functions"), 133 cl::init(false)); 134 135 cl::list<std::string> 136 JITDylibs("jd", 137 cl::desc("Specifies the JITDylib to be used for any subsequent " 138 "-extra-module arguments.")); 139 140 cl::list<std::string> 141 Dylibs("dlopen", cl::desc("Dynamic libraries to load before linking"), 142 cl::ZeroOrMore); 143 144 // The MCJIT supports building for a target address space separate from 145 // the JIT compilation process. Use a forked process and a copying 146 // memory manager with IPC to execute using this functionality. 147 cl::opt<bool> RemoteMCJIT("remote-mcjit", 148 cl::desc("Execute MCJIT'ed code in a separate process."), 149 cl::init(false)); 150 151 // Manually specify the child process for remote execution. This overrides 152 // the simulated remote execution that allocates address space for child 153 // execution. The child process will be executed and will communicate with 154 // lli via stdin/stdout pipes. 155 cl::opt<std::string> 156 ChildExecPath("mcjit-remote-process", 157 cl::desc("Specify the filename of the process to launch " 158 "for remote MCJIT execution. If none is specified," 159 "\n\tremote execution will be simulated in-process."), 160 cl::value_desc("filename"), cl::init("")); 161 162 // Determine optimization level. 163 cl::opt<char> 164 OptLevel("O", 165 cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] " 166 "(default = '-O2')"), 167 cl::Prefix, 168 cl::ZeroOrMore, 169 cl::init(' ')); 170 171 cl::opt<std::string> 172 TargetTriple("mtriple", cl::desc("Override target triple for module")); 173 174 cl::opt<std::string> 175 EntryFunc("entry-function", 176 cl::desc("Specify the entry function (default = 'main') " 177 "of the executable"), 178 cl::value_desc("function"), 179 cl::init("main")); 180 181 cl::list<std::string> 182 ExtraModules("extra-module", 183 cl::desc("Extra modules to be loaded"), 184 cl::value_desc("input bitcode")); 185 186 cl::list<std::string> 187 ExtraObjects("extra-object", 188 cl::desc("Extra object files to be loaded"), 189 cl::value_desc("input object")); 190 191 cl::list<std::string> 192 ExtraArchives("extra-archive", 193 cl::desc("Extra archive files to be loaded"), 194 cl::value_desc("input archive")); 195 196 cl::opt<bool> 197 EnableCacheManager("enable-cache-manager", 198 cl::desc("Use cache manager to save/load modules"), 199 cl::init(false)); 200 201 cl::opt<std::string> 202 ObjectCacheDir("object-cache-dir", 203 cl::desc("Directory to store cached object files " 204 "(must be user writable)"), 205 cl::init("")); 206 207 cl::opt<std::string> 208 FakeArgv0("fake-argv0", 209 cl::desc("Override the 'argv[0]' value passed into the executing" 210 " program"), cl::value_desc("executable")); 211 212 cl::opt<bool> 213 DisableCoreFiles("disable-core-files", cl::Hidden, 214 cl::desc("Disable emission of core files if possible")); 215 216 cl::opt<bool> 217 NoLazyCompilation("disable-lazy-compilation", 218 cl::desc("Disable JIT lazy compilation"), 219 cl::init(false)); 220 221 cl::opt<bool> 222 GenerateSoftFloatCalls("soft-float", 223 cl::desc("Generate software floating point library calls"), 224 cl::init(false)); 225 226 cl::opt<bool> NoProcessSymbols( 227 "no-process-syms", 228 cl::desc("Do not resolve lli process symbols in JIT'd code"), 229 cl::init(false)); 230 231 enum class LLJITPlatform { Inactive, DetectHost, GenericIR, MachO }; 232 233 cl::opt<LLJITPlatform> 234 Platform("lljit-platform", cl::desc("Platform to use with LLJIT"), 235 cl::init(LLJITPlatform::DetectHost), 236 cl::values(clEnumValN(LLJITPlatform::DetectHost, "DetectHost", 237 "Select based on JIT target triple"), 238 clEnumValN(LLJITPlatform::GenericIR, "GenericIR", 239 "Use LLJITGenericIRPlatform"), 240 clEnumValN(LLJITPlatform::MachO, "MachO", 241 "Use LLJITMachOPlatform"), 242 clEnumValN(LLJITPlatform::Inactive, "Inactive", 243 "Disable platform support explicitly")), 244 cl::Hidden); 245 246 enum class DumpKind { 247 NoDump, 248 DumpFuncsToStdOut, 249 DumpModsToStdOut, 250 DumpModsToDisk 251 }; 252 253 cl::opt<DumpKind> OrcDumpKind( 254 "orc-lazy-debug", cl::desc("Debug dumping for the orc-lazy JIT."), 255 cl::init(DumpKind::NoDump), 256 cl::values(clEnumValN(DumpKind::NoDump, "no-dump", 257 "Don't dump anything."), 258 clEnumValN(DumpKind::DumpFuncsToStdOut, "funcs-to-stdout", 259 "Dump function names to stdout."), 260 clEnumValN(DumpKind::DumpModsToStdOut, "mods-to-stdout", 261 "Dump modules to stdout."), 262 clEnumValN(DumpKind::DumpModsToDisk, "mods-to-disk", 263 "Dump modules to the current " 264 "working directory. (WARNING: " 265 "will overwrite existing files).")), 266 cl::Hidden); 267 268 cl::list<BuiltinFunctionKind> GenerateBuiltinFunctions( 269 "generate", 270 cl::desc("Provide built-in functions for access by JITed code " 271 "(jit-kind=orc-lazy only)"), 272 cl::values(clEnumValN(BuiltinFunctionKind::DumpDebugDescriptor, 273 "__dump_jit_debug_descriptor", 274 "Dump __jit_debug_descriptor contents to stdout"), 275 clEnumValN(BuiltinFunctionKind::DumpDebugObjects, 276 "__dump_jit_debug_objects", 277 "Dump __jit_debug_descriptor in-memory debug " 278 "objects as tool output")), 279 cl::Hidden); 280 281 ExitOnError ExitOnErr; 282 } 283 284 LLVM_ATTRIBUTE_USED void linkComponents() { 285 errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper 286 << (void *)&llvm_orc_deregisterEHFrameSectionWrapper 287 << (void *)&llvm_orc_registerJITLoaderGDBWrapper; 288 } 289 290 //===----------------------------------------------------------------------===// 291 // Object cache 292 // 293 // This object cache implementation writes cached objects to disk to the 294 // directory specified by CacheDir, using a filename provided in the module 295 // descriptor. The cache tries to load a saved object using that path if the 296 // file exists. CacheDir defaults to "", in which case objects are cached 297 // alongside their originating bitcodes. 298 // 299 class LLIObjectCache : public ObjectCache { 300 public: 301 LLIObjectCache(const std::string& CacheDir) : CacheDir(CacheDir) { 302 // Add trailing '/' to cache dir if necessary. 303 if (!this->CacheDir.empty() && 304 this->CacheDir[this->CacheDir.size() - 1] != '/') 305 this->CacheDir += '/'; 306 } 307 ~LLIObjectCache() override {} 308 309 void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) override { 310 const std::string &ModuleID = M->getModuleIdentifier(); 311 std::string CacheName; 312 if (!getCacheFilename(ModuleID, CacheName)) 313 return; 314 if (!CacheDir.empty()) { // Create user-defined cache dir. 315 SmallString<128> dir(sys::path::parent_path(CacheName)); 316 sys::fs::create_directories(Twine(dir)); 317 } 318 319 std::error_code EC; 320 raw_fd_ostream outfile(CacheName, EC, sys::fs::OF_None); 321 outfile.write(Obj.getBufferStart(), Obj.getBufferSize()); 322 outfile.close(); 323 } 324 325 std::unique_ptr<MemoryBuffer> getObject(const Module* M) override { 326 const std::string &ModuleID = M->getModuleIdentifier(); 327 std::string CacheName; 328 if (!getCacheFilename(ModuleID, CacheName)) 329 return nullptr; 330 // Load the object from the cache filename 331 ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer = 332 MemoryBuffer::getFile(CacheName, /*IsText=*/false, 333 /*RequiresNullTerminator=*/false); 334 // If the file isn't there, that's OK. 335 if (!IRObjectBuffer) 336 return nullptr; 337 // MCJIT will want to write into this buffer, and we don't want that 338 // because the file has probably just been mmapped. Instead we make 339 // a copy. The filed-based buffer will be released when it goes 340 // out of scope. 341 return MemoryBuffer::getMemBufferCopy(IRObjectBuffer.get()->getBuffer()); 342 } 343 344 private: 345 std::string CacheDir; 346 347 bool getCacheFilename(const std::string &ModID, std::string &CacheName) { 348 std::string Prefix("file:"); 349 size_t PrefixLength = Prefix.length(); 350 if (ModID.substr(0, PrefixLength) != Prefix) 351 return false; 352 353 std::string CacheSubdir = ModID.substr(PrefixLength); 354 #if defined(_WIN32) 355 // Transform "X:\foo" => "/X\foo" for convenience. 356 if (isalpha(CacheSubdir[0]) && CacheSubdir[1] == ':') { 357 CacheSubdir[1] = CacheSubdir[0]; 358 CacheSubdir[0] = '/'; 359 } 360 #endif 361 362 CacheName = CacheDir + CacheSubdir; 363 size_t pos = CacheName.rfind('.'); 364 CacheName.replace(pos, CacheName.length() - pos, ".o"); 365 return true; 366 } 367 }; 368 369 // On Mingw and Cygwin, an external symbol named '__main' is called from the 370 // generated 'main' function to allow static initialization. To avoid linking 371 // problems with remote targets (because lli's remote target support does not 372 // currently handle external linking) we add a secondary module which defines 373 // an empty '__main' function. 374 static void addCygMingExtraModule(ExecutionEngine &EE, LLVMContext &Context, 375 StringRef TargetTripleStr) { 376 IRBuilder<> Builder(Context); 377 Triple TargetTriple(TargetTripleStr); 378 379 // Create a new module. 380 std::unique_ptr<Module> M = std::make_unique<Module>("CygMingHelper", Context); 381 M->setTargetTriple(TargetTripleStr); 382 383 // Create an empty function named "__main". 384 Type *ReturnTy; 385 if (TargetTriple.isArch64Bit()) 386 ReturnTy = Type::getInt64Ty(Context); 387 else 388 ReturnTy = Type::getInt32Ty(Context); 389 Function *Result = 390 Function::Create(FunctionType::get(ReturnTy, {}, false), 391 GlobalValue::ExternalLinkage, "__main", M.get()); 392 393 BasicBlock *BB = BasicBlock::Create(Context, "__main", Result); 394 Builder.SetInsertPoint(BB); 395 Value *ReturnVal = ConstantInt::get(ReturnTy, 0); 396 Builder.CreateRet(ReturnVal); 397 398 // Add this new module to the ExecutionEngine. 399 EE.addModule(std::move(M)); 400 } 401 402 CodeGenOpt::Level getOptLevel() { 403 switch (OptLevel) { 404 default: 405 WithColor::error(errs(), "lli") << "invalid optimization level.\n"; 406 exit(1); 407 case '0': return CodeGenOpt::None; 408 case '1': return CodeGenOpt::Less; 409 case ' ': 410 case '2': return CodeGenOpt::Default; 411 case '3': return CodeGenOpt::Aggressive; 412 } 413 llvm_unreachable("Unrecognized opt level."); 414 } 415 416 LLVM_ATTRIBUTE_NORETURN 417 static void reportError(SMDiagnostic Err, const char *ProgName) { 418 Err.print(ProgName, errs()); 419 exit(1); 420 } 421 422 Error loadDylibs(); 423 int runOrcJIT(const char *ProgName); 424 void disallowOrcOptions(); 425 426 //===----------------------------------------------------------------------===// 427 // main Driver function 428 // 429 int main(int argc, char **argv, char * const *envp) { 430 InitLLVM X(argc, argv); 431 432 if (argc > 1) 433 ExitOnErr.setBanner(std::string(argv[0]) + ": "); 434 435 // If we have a native target, initialize it to ensure it is linked in and 436 // usable by the JIT. 437 InitializeNativeTarget(); 438 InitializeNativeTargetAsmPrinter(); 439 InitializeNativeTargetAsmParser(); 440 441 cl::ParseCommandLineOptions(argc, argv, 442 "llvm interpreter & dynamic compiler\n"); 443 444 // If the user doesn't want core files, disable them. 445 if (DisableCoreFiles) 446 sys::Process::PreventCoreFiles(); 447 448 ExitOnErr(loadDylibs()); 449 450 if (UseJITKind == JITKind::MCJIT) 451 disallowOrcOptions(); 452 else 453 return runOrcJIT(argv[0]); 454 455 // Old lli implementation based on ExecutionEngine and MCJIT. 456 LLVMContext Context; 457 458 // Load the bitcode... 459 SMDiagnostic Err; 460 std::unique_ptr<Module> Owner = parseIRFile(InputFile, Err, Context); 461 Module *Mod = Owner.get(); 462 if (!Mod) 463 reportError(Err, argv[0]); 464 465 if (EnableCacheManager) { 466 std::string CacheName("file:"); 467 CacheName.append(InputFile); 468 Mod->setModuleIdentifier(CacheName); 469 } 470 471 // If not jitting lazily, load the whole bitcode file eagerly too. 472 if (NoLazyCompilation) { 473 // Use *argv instead of argv[0] to work around a wrong GCC warning. 474 ExitOnError ExitOnErr(std::string(*argv) + 475 ": bitcode didn't read correctly: "); 476 ExitOnErr(Mod->materializeAll()); 477 } 478 479 std::string ErrorMsg; 480 EngineBuilder builder(std::move(Owner)); 481 builder.setMArch(codegen::getMArch()); 482 builder.setMCPU(codegen::getCPUStr()); 483 builder.setMAttrs(codegen::getFeatureList()); 484 if (auto RM = codegen::getExplicitRelocModel()) 485 builder.setRelocationModel(RM.getValue()); 486 if (auto CM = codegen::getExplicitCodeModel()) 487 builder.setCodeModel(CM.getValue()); 488 builder.setErrorStr(&ErrorMsg); 489 builder.setEngineKind(ForceInterpreter 490 ? EngineKind::Interpreter 491 : EngineKind::JIT); 492 493 // If we are supposed to override the target triple, do so now. 494 if (!TargetTriple.empty()) 495 Mod->setTargetTriple(Triple::normalize(TargetTriple)); 496 497 // Enable MCJIT if desired. 498 RTDyldMemoryManager *RTDyldMM = nullptr; 499 if (!ForceInterpreter) { 500 if (RemoteMCJIT) 501 RTDyldMM = new ForwardingMemoryManager(); 502 else 503 RTDyldMM = new SectionMemoryManager(); 504 505 // Deliberately construct a temp std::unique_ptr to pass in. Do not null out 506 // RTDyldMM: We still use it below, even though we don't own it. 507 builder.setMCJITMemoryManager( 508 std::unique_ptr<RTDyldMemoryManager>(RTDyldMM)); 509 } else if (RemoteMCJIT) { 510 WithColor::error(errs(), argv[0]) 511 << "remote process execution does not work with the interpreter.\n"; 512 exit(1); 513 } 514 515 builder.setOptLevel(getOptLevel()); 516 517 TargetOptions Options = 518 codegen::InitTargetOptionsFromCodeGenFlags(Triple(TargetTriple)); 519 if (codegen::getFloatABIForCalls() != FloatABI::Default) 520 Options.FloatABIType = codegen::getFloatABIForCalls(); 521 522 builder.setTargetOptions(Options); 523 524 std::unique_ptr<ExecutionEngine> EE(builder.create()); 525 if (!EE) { 526 if (!ErrorMsg.empty()) 527 WithColor::error(errs(), argv[0]) 528 << "error creating EE: " << ErrorMsg << "\n"; 529 else 530 WithColor::error(errs(), argv[0]) << "unknown error creating EE!\n"; 531 exit(1); 532 } 533 534 std::unique_ptr<LLIObjectCache> CacheManager; 535 if (EnableCacheManager) { 536 CacheManager.reset(new LLIObjectCache(ObjectCacheDir)); 537 EE->setObjectCache(CacheManager.get()); 538 } 539 540 // Load any additional modules specified on the command line. 541 for (unsigned i = 0, e = ExtraModules.size(); i != e; ++i) { 542 std::unique_ptr<Module> XMod = parseIRFile(ExtraModules[i], Err, Context); 543 if (!XMod) 544 reportError(Err, argv[0]); 545 if (EnableCacheManager) { 546 std::string CacheName("file:"); 547 CacheName.append(ExtraModules[i]); 548 XMod->setModuleIdentifier(CacheName); 549 } 550 EE->addModule(std::move(XMod)); 551 } 552 553 for (unsigned i = 0, e = ExtraObjects.size(); i != e; ++i) { 554 Expected<object::OwningBinary<object::ObjectFile>> Obj = 555 object::ObjectFile::createObjectFile(ExtraObjects[i]); 556 if (!Obj) { 557 // TODO: Actually report errors helpfully. 558 consumeError(Obj.takeError()); 559 reportError(Err, argv[0]); 560 } 561 object::OwningBinary<object::ObjectFile> &O = Obj.get(); 562 EE->addObjectFile(std::move(O)); 563 } 564 565 for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { 566 ErrorOr<std::unique_ptr<MemoryBuffer>> ArBufOrErr = 567 MemoryBuffer::getFileOrSTDIN(ExtraArchives[i]); 568 if (!ArBufOrErr) 569 reportError(Err, argv[0]); 570 std::unique_ptr<MemoryBuffer> &ArBuf = ArBufOrErr.get(); 571 572 Expected<std::unique_ptr<object::Archive>> ArOrErr = 573 object::Archive::create(ArBuf->getMemBufferRef()); 574 if (!ArOrErr) { 575 std::string Buf; 576 raw_string_ostream OS(Buf); 577 logAllUnhandledErrors(ArOrErr.takeError(), OS); 578 OS.flush(); 579 errs() << Buf; 580 exit(1); 581 } 582 std::unique_ptr<object::Archive> &Ar = ArOrErr.get(); 583 584 object::OwningBinary<object::Archive> OB(std::move(Ar), std::move(ArBuf)); 585 586 EE->addArchive(std::move(OB)); 587 } 588 589 // If the target is Cygwin/MingW and we are generating remote code, we 590 // need an extra module to help out with linking. 591 if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) { 592 addCygMingExtraModule(*EE, Context, Mod->getTargetTriple()); 593 } 594 595 // The following functions have no effect if their respective profiling 596 // support wasn't enabled in the build configuration. 597 EE->RegisterJITEventListener( 598 JITEventListener::createOProfileJITEventListener()); 599 EE->RegisterJITEventListener( 600 JITEventListener::createIntelJITEventListener()); 601 if (!RemoteMCJIT) 602 EE->RegisterJITEventListener( 603 JITEventListener::createPerfJITEventListener()); 604 605 if (!NoLazyCompilation && RemoteMCJIT) { 606 WithColor::warning(errs(), argv[0]) 607 << "remote mcjit does not support lazy compilation\n"; 608 NoLazyCompilation = true; 609 } 610 EE->DisableLazyCompilation(NoLazyCompilation); 611 612 // If the user specifically requested an argv[0] to pass into the program, 613 // do it now. 614 if (!FakeArgv0.empty()) { 615 InputFile = static_cast<std::string>(FakeArgv0); 616 } else { 617 // Otherwise, if there is a .bc suffix on the executable strip it off, it 618 // might confuse the program. 619 if (StringRef(InputFile).endswith(".bc")) 620 InputFile.erase(InputFile.length() - 3); 621 } 622 623 // Add the module's name to the start of the vector of arguments to main(). 624 InputArgv.insert(InputArgv.begin(), InputFile); 625 626 // Call the main function from M as if its signature were: 627 // int main (int argc, char **argv, const char **envp) 628 // using the contents of Args to determine argc & argv, and the contents of 629 // EnvVars to determine envp. 630 // 631 Function *EntryFn = Mod->getFunction(EntryFunc); 632 if (!EntryFn) { 633 WithColor::error(errs(), argv[0]) 634 << '\'' << EntryFunc << "\' function not found in module.\n"; 635 return -1; 636 } 637 638 // Reset errno to zero on entry to main. 639 errno = 0; 640 641 int Result = -1; 642 643 // Sanity check use of remote-jit: LLI currently only supports use of the 644 // remote JIT on Unix platforms. 645 if (RemoteMCJIT) { 646 #ifndef LLVM_ON_UNIX 647 WithColor::warning(errs(), argv[0]) 648 << "host does not support external remote targets.\n"; 649 WithColor::note() << "defaulting to local execution\n"; 650 return -1; 651 #else 652 if (ChildExecPath.empty()) { 653 WithColor::error(errs(), argv[0]) 654 << "-remote-mcjit requires -mcjit-remote-process.\n"; 655 exit(1); 656 } else if (!sys::fs::can_execute(ChildExecPath)) { 657 WithColor::error(errs(), argv[0]) 658 << "unable to find usable child executable: '" << ChildExecPath 659 << "'\n"; 660 return -1; 661 } 662 #endif 663 } 664 665 if (!RemoteMCJIT) { 666 // If the program doesn't explicitly call exit, we will need the Exit 667 // function later on to make an explicit call, so get the function now. 668 FunctionCallee Exit = Mod->getOrInsertFunction( 669 "exit", Type::getVoidTy(Context), Type::getInt32Ty(Context)); 670 671 // Run static constructors. 672 if (!ForceInterpreter) { 673 // Give MCJIT a chance to apply relocations and set page permissions. 674 EE->finalizeObject(); 675 } 676 EE->runStaticConstructorsDestructors(false); 677 678 // Trigger compilation separately so code regions that need to be 679 // invalidated will be known. 680 (void)EE->getPointerToFunction(EntryFn); 681 // Clear instruction cache before code will be executed. 682 if (RTDyldMM) 683 static_cast<SectionMemoryManager*>(RTDyldMM)->invalidateInstructionCache(); 684 685 // Run main. 686 Result = EE->runFunctionAsMain(EntryFn, InputArgv, envp); 687 688 // Run static destructors. 689 EE->runStaticConstructorsDestructors(true); 690 691 // If the program didn't call exit explicitly, we should call it now. 692 // This ensures that any atexit handlers get called correctly. 693 if (Function *ExitF = 694 dyn_cast<Function>(Exit.getCallee()->stripPointerCasts())) { 695 if (ExitF->getFunctionType() == Exit.getFunctionType()) { 696 std::vector<GenericValue> Args; 697 GenericValue ResultGV; 698 ResultGV.IntVal = APInt(32, Result); 699 Args.push_back(ResultGV); 700 EE->runFunction(ExitF, Args); 701 WithColor::error(errs(), argv[0]) 702 << "exit(" << Result << ") returned!\n"; 703 abort(); 704 } 705 } 706 WithColor::error(errs(), argv[0]) << "exit defined with wrong prototype!\n"; 707 abort(); 708 } else { 709 // else == "if (RemoteMCJIT)" 710 711 // Remote target MCJIT doesn't (yet) support static constructors. No reason 712 // it couldn't. This is a limitation of the LLI implementation, not the 713 // MCJIT itself. FIXME. 714 715 // Lanch the remote process and get a channel to it. 716 std::unique_ptr<orc::shared::FDRawByteChannel> C = launchRemote(); 717 if (!C) { 718 WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n"; 719 exit(1); 720 } 721 722 // Create a remote target client running over the channel. 723 llvm::orc::ExecutionSession ES; 724 ES.setErrorReporter([&](Error Err) { ExitOnErr(std::move(Err)); }); 725 typedef orc::remote::OrcRemoteTargetClient MyRemote; 726 auto R = ExitOnErr(MyRemote::Create(*C, ES)); 727 728 // Create a remote memory manager. 729 auto RemoteMM = ExitOnErr(R->createRemoteMemoryManager()); 730 731 // Forward MCJIT's memory manager calls to the remote memory manager. 732 static_cast<ForwardingMemoryManager*>(RTDyldMM)->setMemMgr( 733 std::move(RemoteMM)); 734 735 // Forward MCJIT's symbol resolution calls to the remote. 736 static_cast<ForwardingMemoryManager *>(RTDyldMM)->setResolver( 737 std::make_unique<RemoteResolver<MyRemote>>(*R)); 738 739 // Grab the target address of the JIT'd main function on the remote and call 740 // it. 741 // FIXME: argv and envp handling. 742 JITTargetAddress Entry = EE->getFunctionAddress(EntryFn->getName().str()); 743 EE->finalizeObject(); 744 LLVM_DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" 745 << format("%llx", Entry) << "\n"); 746 Result = ExitOnErr(R->callIntVoid(Entry)); 747 748 // Like static constructors, the remote target MCJIT support doesn't handle 749 // this yet. It could. FIXME. 750 751 // Delete the EE - we need to tear it down *before* we terminate the session 752 // with the remote, otherwise it'll crash when it tries to release resources 753 // on a remote that has already been disconnected. 754 EE.reset(); 755 756 // Signal the remote target that we're done JITing. 757 ExitOnErr(R->terminateSession()); 758 } 759 760 return Result; 761 } 762 763 static std::function<void(Module &)> createDebugDumper() { 764 switch (OrcDumpKind) { 765 case DumpKind::NoDump: 766 return [](Module &M) {}; 767 768 case DumpKind::DumpFuncsToStdOut: 769 return [](Module &M) { 770 printf("[ "); 771 772 for (const auto &F : M) { 773 if (F.isDeclaration()) 774 continue; 775 776 if (F.hasName()) { 777 std::string Name(std::string(F.getName())); 778 printf("%s ", Name.c_str()); 779 } else 780 printf("<anon> "); 781 } 782 783 printf("]\n"); 784 }; 785 786 case DumpKind::DumpModsToStdOut: 787 return [](Module &M) { 788 outs() << "----- Module Start -----\n" << M << "----- Module End -----\n"; 789 }; 790 791 case DumpKind::DumpModsToDisk: 792 return [](Module &M) { 793 std::error_code EC; 794 raw_fd_ostream Out(M.getModuleIdentifier() + ".ll", EC, sys::fs::OF_Text); 795 if (EC) { 796 errs() << "Couldn't open " << M.getModuleIdentifier() 797 << " for dumping.\nError:" << EC.message() << "\n"; 798 exit(1); 799 } 800 Out << M; 801 }; 802 } 803 llvm_unreachable("Unknown DumpKind"); 804 } 805 806 Error loadDylibs() { 807 for (const auto &Dylib : Dylibs) { 808 std::string ErrMsg; 809 if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg)) 810 return make_error<StringError>(ErrMsg, inconvertibleErrorCode()); 811 } 812 813 return Error::success(); 814 } 815 816 static void exitOnLazyCallThroughFailure() { exit(1); } 817 818 Expected<orc::ThreadSafeModule> 819 loadModule(StringRef Path, orc::ThreadSafeContext TSCtx) { 820 SMDiagnostic Err; 821 auto M = parseIRFile(Path, Err, *TSCtx.getContext()); 822 if (!M) { 823 std::string ErrMsg; 824 { 825 raw_string_ostream ErrMsgStream(ErrMsg); 826 Err.print("lli", ErrMsgStream); 827 } 828 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()); 829 } 830 831 if (EnableCacheManager) 832 M->setModuleIdentifier("file:" + M->getModuleIdentifier()); 833 834 return orc::ThreadSafeModule(std::move(M), std::move(TSCtx)); 835 } 836 837 int runOrcJIT(const char *ProgName) { 838 // Start setting up the JIT environment. 839 840 // Parse the main module. 841 orc::ThreadSafeContext TSCtx(std::make_unique<LLVMContext>()); 842 auto MainModule = ExitOnErr(loadModule(InputFile, TSCtx)); 843 844 // Get TargetTriple and DataLayout from the main module if they're explicitly 845 // set. 846 Optional<Triple> TT; 847 Optional<DataLayout> DL; 848 MainModule.withModuleDo([&](Module &M) { 849 if (!M.getTargetTriple().empty()) 850 TT = Triple(M.getTargetTriple()); 851 if (!M.getDataLayout().isDefault()) 852 DL = M.getDataLayout(); 853 }); 854 855 orc::LLLazyJITBuilder Builder; 856 857 Builder.setJITTargetMachineBuilder( 858 TT ? orc::JITTargetMachineBuilder(*TT) 859 : ExitOnErr(orc::JITTargetMachineBuilder::detectHost())); 860 861 TT = Builder.getJITTargetMachineBuilder()->getTargetTriple(); 862 if (DL) 863 Builder.setDataLayout(DL); 864 865 if (!codegen::getMArch().empty()) 866 Builder.getJITTargetMachineBuilder()->getTargetTriple().setArchName( 867 codegen::getMArch()); 868 869 Builder.getJITTargetMachineBuilder() 870 ->setCPU(codegen::getCPUStr()) 871 .addFeatures(codegen::getFeatureList()) 872 .setRelocationModel(codegen::getExplicitRelocModel()) 873 .setCodeModel(codegen::getExplicitCodeModel()); 874 875 // FIXME: Setting a dummy call-through manager in non-lazy mode prevents the 876 // JIT builder to instantiate a default (which would fail with an error for 877 // unsupported architectures). 878 if (UseJITKind != JITKind::OrcLazy) { 879 auto ES = std::make_unique<orc::ExecutionSession>(); 880 Builder.setLazyCallthroughManager( 881 std::make_unique<orc::LazyCallThroughManager>(*ES, 0, nullptr)); 882 Builder.setExecutionSession(std::move(ES)); 883 } 884 885 Builder.setLazyCompileFailureAddr( 886 pointerToJITTargetAddress(exitOnLazyCallThroughFailure)); 887 Builder.setNumCompileThreads(LazyJITCompileThreads); 888 889 // If the object cache is enabled then set a custom compile function 890 // creator to use the cache. 891 std::unique_ptr<LLIObjectCache> CacheManager; 892 if (EnableCacheManager) { 893 894 CacheManager = std::make_unique<LLIObjectCache>(ObjectCacheDir); 895 896 Builder.setCompileFunctionCreator( 897 [&](orc::JITTargetMachineBuilder JTMB) 898 -> Expected<std::unique_ptr<orc::IRCompileLayer::IRCompiler>> { 899 if (LazyJITCompileThreads > 0) 900 return std::make_unique<orc::ConcurrentIRCompiler>(std::move(JTMB), 901 CacheManager.get()); 902 903 auto TM = JTMB.createTargetMachine(); 904 if (!TM) 905 return TM.takeError(); 906 907 return std::make_unique<orc::TMOwningSimpleCompiler>(std::move(*TM), 908 CacheManager.get()); 909 }); 910 } 911 912 // Set up LLJIT platform. 913 { 914 LLJITPlatform P = Platform; 915 if (P == LLJITPlatform::DetectHost) { 916 if (TT->isOSBinFormatMachO()) 917 P = LLJITPlatform::MachO; 918 else 919 P = LLJITPlatform::GenericIR; 920 } 921 922 switch (P) { 923 case LLJITPlatform::GenericIR: 924 // Nothing to do: LLJITBuilder will use this by default. 925 break; 926 case LLJITPlatform::MachO: 927 Builder.setPlatformSetUp(orc::setUpMachOPlatform); 928 ExitOnErr(orc::enableObjCRegistration("libobjc.dylib")); 929 break; 930 case LLJITPlatform::Inactive: 931 Builder.setPlatformSetUp(orc::setUpInactivePlatform); 932 break; 933 default: 934 llvm_unreachable("Unrecognized platform value"); 935 } 936 } 937 938 std::unique_ptr<orc::TargetProcessControl> TPC = nullptr; 939 if (JITLinker == JITLinkerKind::JITLink) { 940 TPC = ExitOnErr(orc::SelfTargetProcessControl::Create( 941 std::make_shared<orc::SymbolStringPool>())); 942 943 Builder.setObjectLinkingLayerCreator([&TPC](orc::ExecutionSession &ES, 944 const Triple &) { 945 auto L = std::make_unique<orc::ObjectLinkingLayer>(ES, TPC->getMemMgr()); 946 L->addPlugin(std::make_unique<orc::EHFrameRegistrationPlugin>( 947 ES, ExitOnErr(orc::TPCEHFrameRegistrar::Create(*TPC)))); 948 L->addPlugin(std::make_unique<orc::DebugObjectManagerPlugin>( 949 ES, ExitOnErr(orc::createJITLoaderGDBRegistrar(*TPC)))); 950 return L; 951 }); 952 } 953 954 auto J = ExitOnErr(Builder.create()); 955 956 auto *ObjLayer = &J->getObjLinkingLayer(); 957 if (auto *RTDyldObjLayer = dyn_cast<orc::RTDyldObjectLinkingLayer>(ObjLayer)) 958 RTDyldObjLayer->registerJITEventListener( 959 *JITEventListener::createGDBRegistrationListener()); 960 961 if (PerModuleLazy) 962 J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule); 963 964 auto Dump = createDebugDumper(); 965 966 J->getIRTransformLayer().setTransform( 967 [&](orc::ThreadSafeModule TSM, 968 const orc::MaterializationResponsibility &R) { 969 TSM.withModuleDo([&](Module &M) { 970 if (verifyModule(M, &dbgs())) { 971 dbgs() << "Bad module: " << &M << "\n"; 972 exit(1); 973 } 974 Dump(M); 975 }); 976 return TSM; 977 }); 978 979 orc::MangleAndInterner Mangle(J->getExecutionSession(), J->getDataLayout()); 980 981 // Unless they've been explicitly disabled, make process symbols available to 982 // JIT'd code. 983 if (!NoProcessSymbols) 984 J->getMainJITDylib().addGenerator( 985 ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess( 986 J->getDataLayout().getGlobalPrefix(), 987 [MainName = Mangle("main")](const orc::SymbolStringPtr &Name) { 988 return Name != MainName; 989 }))); 990 991 if (GenerateBuiltinFunctions.size() > 0) 992 J->getMainJITDylib().addGenerator( 993 std::make_unique<LLIBuiltinFunctionGenerator>(GenerateBuiltinFunctions, 994 Mangle)); 995 996 // Regular modules are greedy: They materialize as a whole and trigger 997 // materialization for all required symbols recursively. Lazy modules go 998 // through partitioning and they replace outgoing calls with reexport stubs 999 // that resolve on call-through. 1000 auto AddModule = [&](orc::JITDylib &JD, orc::ThreadSafeModule M) { 1001 return UseJITKind == JITKind::OrcLazy ? J->addLazyIRModule(JD, std::move(M)) 1002 : J->addIRModule(JD, std::move(M)); 1003 }; 1004 1005 // Add the main module. 1006 ExitOnErr(AddModule(J->getMainJITDylib(), std::move(MainModule))); 1007 1008 // Create JITDylibs and add any extra modules. 1009 { 1010 // Create JITDylibs, keep a map from argument index to dylib. We will use 1011 // -extra-module argument indexes to determine what dylib to use for each 1012 // -extra-module. 1013 std::map<unsigned, orc::JITDylib *> IdxToDylib; 1014 IdxToDylib[0] = &J->getMainJITDylib(); 1015 for (auto JDItr = JITDylibs.begin(), JDEnd = JITDylibs.end(); 1016 JDItr != JDEnd; ++JDItr) { 1017 orc::JITDylib *JD = J->getJITDylibByName(*JDItr); 1018 if (!JD) { 1019 JD = &ExitOnErr(J->createJITDylib(*JDItr)); 1020 J->getMainJITDylib().addToLinkOrder(*JD); 1021 JD->addToLinkOrder(J->getMainJITDylib()); 1022 } 1023 IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] = JD; 1024 } 1025 1026 for (auto EMItr = ExtraModules.begin(), EMEnd = ExtraModules.end(); 1027 EMItr != EMEnd; ++EMItr) { 1028 auto M = ExitOnErr(loadModule(*EMItr, TSCtx)); 1029 1030 auto EMIdx = ExtraModules.getPosition(EMItr - ExtraModules.begin()); 1031 assert(EMIdx != 0 && "ExtraModule should have index > 0"); 1032 auto JDItr = std::prev(IdxToDylib.lower_bound(EMIdx)); 1033 auto &JD = *JDItr->second; 1034 ExitOnErr(AddModule(JD, std::move(M))); 1035 } 1036 1037 for (auto EAItr = ExtraArchives.begin(), EAEnd = ExtraArchives.end(); 1038 EAItr != EAEnd; ++EAItr) { 1039 auto EAIdx = ExtraArchives.getPosition(EAItr - ExtraArchives.begin()); 1040 assert(EAIdx != 0 && "ExtraArchive should have index > 0"); 1041 auto JDItr = std::prev(IdxToDylib.lower_bound(EAIdx)); 1042 auto &JD = *JDItr->second; 1043 JD.addGenerator(ExitOnErr(orc::StaticLibraryDefinitionGenerator::Load( 1044 J->getObjLinkingLayer(), EAItr->c_str(), *TT))); 1045 } 1046 } 1047 1048 // Add the objects. 1049 for (auto &ObjPath : ExtraObjects) { 1050 auto Obj = ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(ObjPath))); 1051 ExitOnErr(J->addObjectFile(std::move(Obj))); 1052 } 1053 1054 // Run any static constructors. 1055 ExitOnErr(J->initialize(J->getMainJITDylib())); 1056 1057 // Run any -thread-entry points. 1058 std::vector<std::thread> AltEntryThreads; 1059 for (auto &ThreadEntryPoint : ThreadEntryPoints) { 1060 auto EntryPointSym = ExitOnErr(J->lookup(ThreadEntryPoint)); 1061 typedef void (*EntryPointPtr)(); 1062 auto EntryPoint = 1063 reinterpret_cast<EntryPointPtr>(static_cast<uintptr_t>(EntryPointSym.getAddress())); 1064 AltEntryThreads.push_back(std::thread([EntryPoint]() { EntryPoint(); })); 1065 } 1066 1067 // Resolve and run the main function. 1068 JITEvaluatedSymbol MainSym = ExitOnErr(J->lookup("main")); 1069 int Result; 1070 1071 if (TPC) { 1072 // TargetProcessControl-based execution with JITLink. 1073 Result = ExitOnErr(TPC->runAsMain(MainSym.getAddress(), InputArgv)); 1074 } else { 1075 // Manual in-process execution with RuntimeDyld. 1076 using MainFnTy = int(int, char *[]); 1077 auto MainFn = jitTargetAddressToFunction<MainFnTy *>(MainSym.getAddress()); 1078 Result = orc::runAsMain(MainFn, InputArgv, StringRef(InputFile)); 1079 } 1080 1081 // Wait for -entry-point threads. 1082 for (auto &AltEntryThread : AltEntryThreads) 1083 AltEntryThread.join(); 1084 1085 // Run destructors. 1086 ExitOnErr(J->deinitialize(J->getMainJITDylib())); 1087 1088 return Result; 1089 } 1090 1091 void disallowOrcOptions() { 1092 // Make sure nobody used an orc-lazy specific option accidentally. 1093 1094 if (LazyJITCompileThreads != 0) { 1095 errs() << "-compile-threads requires -jit-kind=orc-lazy\n"; 1096 exit(1); 1097 } 1098 1099 if (!ThreadEntryPoints.empty()) { 1100 errs() << "-thread-entry requires -jit-kind=orc-lazy\n"; 1101 exit(1); 1102 } 1103 1104 if (PerModuleLazy) { 1105 errs() << "-per-module-lazy requires -jit-kind=orc-lazy\n"; 1106 exit(1); 1107 } 1108 } 1109 1110 std::unique_ptr<orc::shared::FDRawByteChannel> launchRemote() { 1111 #ifndef LLVM_ON_UNIX 1112 llvm_unreachable("launchRemote not supported on non-Unix platforms"); 1113 #else 1114 int PipeFD[2][2]; 1115 pid_t ChildPID; 1116 1117 // Create two pipes. 1118 if (pipe(PipeFD[0]) != 0 || pipe(PipeFD[1]) != 0) 1119 perror("Error creating pipe: "); 1120 1121 ChildPID = fork(); 1122 1123 if (ChildPID == 0) { 1124 // In the child... 1125 1126 // Close the parent ends of the pipes 1127 close(PipeFD[0][1]); 1128 close(PipeFD[1][0]); 1129 1130 1131 // Execute the child process. 1132 std::unique_ptr<char[]> ChildPath, ChildIn, ChildOut; 1133 { 1134 ChildPath.reset(new char[ChildExecPath.size() + 1]); 1135 std::copy(ChildExecPath.begin(), ChildExecPath.end(), &ChildPath[0]); 1136 ChildPath[ChildExecPath.size()] = '\0'; 1137 std::string ChildInStr = utostr(PipeFD[0][0]); 1138 ChildIn.reset(new char[ChildInStr.size() + 1]); 1139 std::copy(ChildInStr.begin(), ChildInStr.end(), &ChildIn[0]); 1140 ChildIn[ChildInStr.size()] = '\0'; 1141 std::string ChildOutStr = utostr(PipeFD[1][1]); 1142 ChildOut.reset(new char[ChildOutStr.size() + 1]); 1143 std::copy(ChildOutStr.begin(), ChildOutStr.end(), &ChildOut[0]); 1144 ChildOut[ChildOutStr.size()] = '\0'; 1145 } 1146 1147 char * const args[] = { &ChildPath[0], &ChildIn[0], &ChildOut[0], nullptr }; 1148 int rc = execv(ChildExecPath.c_str(), args); 1149 if (rc != 0) 1150 perror("Error executing child process: "); 1151 llvm_unreachable("Error executing child process"); 1152 } 1153 // else we're the parent... 1154 1155 // Close the child ends of the pipes 1156 close(PipeFD[0][0]); 1157 close(PipeFD[1][1]); 1158 1159 // Return an RPC channel connected to our end of the pipes. 1160 return std::make_unique<orc::shared::FDRawByteChannel>(PipeFD[1][0], 1161 PipeFD[0][1]); 1162 #endif 1163 } 1164