ExternalFunctions.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //===-- ExternalFunctions.cpp - Implement External Functions --------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains both code to deal with invoking "external" functions, but
  11. // also contains code that implements "exported" external functions.
  12. //
  13. // There are currently two mechanisms for handling external functions in the
  14. // Interpreter. The first is to implement lle_* wrapper functions that are
  15. // specific to well-known library functions which manually translate the
  16. // arguments from GenericValues and make the call. If such a wrapper does
  17. // not exist, and libffi is available, then the Interpreter will attempt to
  18. // invoke the function using libffi, after finding its address.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #include "Interpreter.h"
  22. #include "llvm/DerivedTypes.h"
  23. #include "llvm/Module.h"
  24. #include "llvm/Config/config.h" // Detect libffi
  25. #include "llvm/Support/ErrorHandling.h"
  26. #include "llvm/Support/Streams.h"
  27. #include "llvm/System/DynamicLibrary.h"
  28. #include "llvm/Target/TargetData.h"
  29. #include "llvm/Support/ManagedStatic.h"
  30. #include "llvm/System/Mutex.h"
  31. #include <csignal>
  32. #include <cstdio>
  33. #include <map>
  34. #include <cmath>
  35. #include <cstring>
  36. #ifdef HAVE_FFI_CALL
  37. #ifdef HAVE_FFI_H
  38. #include <ffi.h>
  39. #define USE_LIBFFI
  40. #elif HAVE_FFI_FFI_H
  41. #include <ffi/ffi.h>
  42. #define USE_LIBFFI
  43. #endif
  44. #endif
  45. using namespace llvm;
  46. static ManagedStatic<sys::Mutex> FunctionsLock;
  47. typedef GenericValue (*ExFunc)(const FunctionType *,
  48. const std::vector<GenericValue> &);
  49. static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
  50. static std::map<std::string, ExFunc> FuncNames;
  51. #ifdef USE_LIBFFI
  52. typedef void (*RawFunc)();
  53. static ManagedStatic<std::map<const Function *, RawFunc> > RawFunctions;
  54. #endif
  55. static Interpreter *TheInterpreter;
  56. static char getTypeID(const Type *Ty) {
  57. switch (Ty->getTypeID()) {
  58. case Type::VoidTyID: return 'V';
  59. case Type::IntegerTyID:
  60. switch (cast<IntegerType>(Ty)->getBitWidth()) {
  61. case 1: return 'o';
  62. case 8: return 'B';
  63. case 16: return 'S';
  64. case 32: return 'I';
  65. case 64: return 'L';
  66. default: return 'N';
  67. }
  68. case Type::FloatTyID: return 'F';
  69. case Type::DoubleTyID: return 'D';
  70. case Type::PointerTyID: return 'P';
  71. case Type::FunctionTyID:return 'M';
  72. case Type::StructTyID: return 'T';
  73. case Type::ArrayTyID: return 'A';
  74. case Type::OpaqueTyID: return 'O';
  75. default: return 'U';
  76. }
  77. }
  78. // Try to find address of external function given a Function object.
  79. // Please note, that interpreter doesn't know how to assemble a
  80. // real call in general case (this is JIT job), that's why it assumes,
  81. // that all external functions has the same (and pretty "general") signature.
  82. // The typical example of such functions are "lle_X_" ones.
  83. static ExFunc lookupFunction(const Function *F) {
  84. // Function not found, look it up... start by figuring out what the
  85. // composite function name should be.
  86. std::string ExtName = "lle_";
  87. const FunctionType *FT = F->getFunctionType();
  88. for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
  89. ExtName += getTypeID(FT->getContainedType(i));
  90. ExtName + "_" + F->getNameStr();
  91. sys::ScopedLock Writer(*FunctionsLock);
  92. ExFunc FnPtr = FuncNames[ExtName];
  93. if (FnPtr == 0)
  94. FnPtr = FuncNames["lle_X_" + F->getNameStr()];
  95. if (FnPtr == 0) // Try calling a generic function... if it exists...
  96. FnPtr = (ExFunc)(intptr_t)
  97. sys::DynamicLibrary::SearchForAddressOfSymbol("lle_X_"+F->getNameStr());
  98. if (FnPtr != 0)
  99. ExportedFunctions->insert(std::make_pair(F, FnPtr)); // Cache for later
  100. return FnPtr;
  101. }
  102. #ifdef USE_LIBFFI
  103. static ffi_type *ffiTypeFor(const Type *Ty) {
  104. switch (Ty->getTypeID()) {
  105. case Type::VoidTyID: return &ffi_type_void;
  106. case Type::IntegerTyID:
  107. switch (cast<IntegerType>(Ty)->getBitWidth()) {
  108. case 8: return &ffi_type_sint8;
  109. case 16: return &ffi_type_sint16;
  110. case 32: return &ffi_type_sint32;
  111. case 64: return &ffi_type_sint64;
  112. }
  113. case Type::FloatTyID: return &ffi_type_float;
  114. case Type::DoubleTyID: return &ffi_type_double;
  115. case Type::PointerTyID: return &ffi_type_pointer;
  116. default: break;
  117. }
  118. // TODO: Support other types such as StructTyID, ArrayTyID, OpaqueTyID, etc.
  119. llvm_report_error("Type could not be mapped for use with libffi.");
  120. return NULL;
  121. }
  122. static void *ffiValueFor(const Type *Ty, const GenericValue &AV,
  123. void *ArgDataPtr) {
  124. switch (Ty->getTypeID()) {
  125. case Type::IntegerTyID:
  126. switch (cast<IntegerType>(Ty)->getBitWidth()) {
  127. case 8: {
  128. int8_t *I8Ptr = (int8_t *) ArgDataPtr;
  129. *I8Ptr = (int8_t) AV.IntVal.getZExtValue();
  130. return ArgDataPtr;
  131. }
  132. case 16: {
  133. int16_t *I16Ptr = (int16_t *) ArgDataPtr;
  134. *I16Ptr = (int16_t) AV.IntVal.getZExtValue();
  135. return ArgDataPtr;
  136. }
  137. case 32: {
  138. int32_t *I32Ptr = (int32_t *) ArgDataPtr;
  139. *I32Ptr = (int32_t) AV.IntVal.getZExtValue();
  140. return ArgDataPtr;
  141. }
  142. case 64: {
  143. int64_t *I64Ptr = (int64_t *) ArgDataPtr;
  144. *I64Ptr = (int64_t) AV.IntVal.getZExtValue();
  145. return ArgDataPtr;
  146. }
  147. }
  148. case Type::FloatTyID: {
  149. float *FloatPtr = (float *) ArgDataPtr;
  150. *FloatPtr = AV.DoubleVal;
  151. return ArgDataPtr;
  152. }
  153. case Type::DoubleTyID: {
  154. double *DoublePtr = (double *) ArgDataPtr;
  155. *DoublePtr = AV.DoubleVal;
  156. return ArgDataPtr;
  157. }
  158. case Type::PointerTyID: {
  159. void **PtrPtr = (void **) ArgDataPtr;
  160. *PtrPtr = GVTOP(AV);
  161. return ArgDataPtr;
  162. }
  163. default: break;
  164. }
  165. // TODO: Support other types such as StructTyID, ArrayTyID, OpaqueTyID, etc.
  166. llvm_report_error("Type value could not be mapped for use with libffi.");
  167. return NULL;
  168. }
  169. static bool ffiInvoke(RawFunc Fn, Function *F,
  170. const std::vector<GenericValue> &ArgVals,
  171. const TargetData *TD, GenericValue &Result) {
  172. ffi_cif cif;
  173. const FunctionType *FTy = F->getFunctionType();
  174. const unsigned NumArgs = F->arg_size();
  175. // TODO: We don't have type information about the remaining arguments, because
  176. // this information is never passed into ExecutionEngine::runFunction().
  177. if (ArgVals.size() > NumArgs && F->isVarArg()) {
  178. llvm_report_error("Calling external var arg function '" + F->getName()
  179. + "' is not supported by the Interpreter.");
  180. }
  181. unsigned ArgBytes = 0;
  182. std::vector<ffi_type*> args(NumArgs);
  183. for (Function::const_arg_iterator A = F->arg_begin(), E = F->arg_end();
  184. A != E; ++A) {
  185. const unsigned ArgNo = A->getArgNo();
  186. const Type *ArgTy = FTy->getParamType(ArgNo);
  187. args[ArgNo] = ffiTypeFor(ArgTy);
  188. ArgBytes += TD->getTypeStoreSize(ArgTy);
  189. }
  190. uint8_t *ArgData = (uint8_t*) alloca(ArgBytes);
  191. uint8_t *ArgDataPtr = ArgData;
  192. std::vector<void*> values(NumArgs);
  193. for (Function::const_arg_iterator A = F->arg_begin(), E = F->arg_end();
  194. A != E; ++A) {
  195. const unsigned ArgNo = A->getArgNo();
  196. const Type *ArgTy = FTy->getParamType(ArgNo);
  197. values[ArgNo] = ffiValueFor(ArgTy, ArgVals[ArgNo], ArgDataPtr);
  198. ArgDataPtr += TD->getTypeStoreSize(ArgTy);
  199. }
  200. const Type *RetTy = FTy->getReturnType();
  201. ffi_type *rtype = ffiTypeFor(RetTy);
  202. if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, &args[0]) == FFI_OK) {
  203. void *ret = NULL;
  204. if (RetTy->getTypeID() != Type::VoidTyID)
  205. ret = alloca(TD->getTypeStoreSize(RetTy));
  206. ffi_call(&cif, Fn, ret, &values[0]);
  207. switch (RetTy->getTypeID()) {
  208. case Type::IntegerTyID:
  209. switch (cast<IntegerType>(RetTy)->getBitWidth()) {
  210. case 8: Result.IntVal = APInt(8 , *(int8_t *) ret); break;
  211. case 16: Result.IntVal = APInt(16, *(int16_t*) ret); break;
  212. case 32: Result.IntVal = APInt(32, *(int32_t*) ret); break;
  213. case 64: Result.IntVal = APInt(64, *(int64_t*) ret); break;
  214. }
  215. break;
  216. case Type::FloatTyID: Result.FloatVal = *(float *) ret; break;
  217. case Type::DoubleTyID: Result.DoubleVal = *(double*) ret; break;
  218. case Type::PointerTyID: Result.PointerVal = *(void **) ret; break;
  219. default: break;
  220. }
  221. return true;
  222. }
  223. return false;
  224. }
  225. #endif // USE_LIBFFI
  226. GenericValue Interpreter::callExternalFunction(Function *F,
  227. const std::vector<GenericValue> &ArgVals) {
  228. TheInterpreter = this;
  229. FunctionsLock->acquire();
  230. // Do a lookup to see if the function is in our cache... this should just be a
  231. // deferred annotation!
  232. std::map<const Function *, ExFunc>::iterator FI = ExportedFunctions->find(F);
  233. if (ExFunc Fn = (FI == ExportedFunctions->end()) ? lookupFunction(F)
  234. : FI->second) {
  235. FunctionsLock->release();
  236. return Fn(F->getFunctionType(), ArgVals);
  237. }
  238. #ifdef USE_LIBFFI
  239. std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
  240. RawFunc RawFn;
  241. if (RF == RawFunctions->end()) {
  242. RawFn = (RawFunc)(intptr_t)
  243. sys::DynamicLibrary::SearchForAddressOfSymbol(F->getName());
  244. if (RawFn != 0)
  245. RawFunctions->insert(std::make_pair(F, RawFn)); // Cache for later
  246. } else {
  247. RawFn = RF->second;
  248. }
  249. FunctionsLock->release();
  250. GenericValue Result;
  251. if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
  252. return Result;
  253. #endif // USE_LIBFFI
  254. if (F->getName() == "__main")
  255. cerr << "Tried to execute an unknown external function: "
  256. << F->getType()->getDescription() << " __main\n";
  257. else
  258. llvm_report_error("Tried to execute an unknown external function: " +
  259. F->getType()->getDescription() + " " +F->getName());
  260. return GenericValue();
  261. }
  262. //===----------------------------------------------------------------------===//
  263. // Functions "exported" to the running application...
  264. //
  265. // Visual Studio warns about returning GenericValue in extern "C" linkage
  266. #ifdef _MSC_VER
  267. #pragma warning(disable : 4190)
  268. #endif
  269. extern "C" { // Don't add C++ manglings to llvm mangling :)
  270. // void atexit(Function*)
  271. GenericValue lle_X_atexit(const FunctionType *FT,
  272. const std::vector<GenericValue> &Args) {
  273. assert(Args.size() == 1);
  274. TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
  275. GenericValue GV;
  276. GV.IntVal = 0;
  277. return GV;
  278. }
  279. // void exit(int)
  280. GenericValue lle_X_exit(const FunctionType *FT,
  281. const std::vector<GenericValue> &Args) {
  282. TheInterpreter->exitCalled(Args[0]);
  283. return GenericValue();
  284. }
  285. // void abort(void)
  286. GenericValue lle_X_abort(const FunctionType *FT,
  287. const std::vector<GenericValue> &Args) {
  288. //FIXME: should we report or raise here?
  289. //llvm_report_error("Interpreted program raised SIGABRT");
  290. raise (SIGABRT);
  291. return GenericValue();
  292. }
  293. // int sprintf(char *, const char *, ...) - a very rough implementation to make
  294. // output useful.
  295. GenericValue lle_X_sprintf(const FunctionType *FT,
  296. const std::vector<GenericValue> &Args) {
  297. char *OutputBuffer = (char *)GVTOP(Args[0]);
  298. const char *FmtStr = (const char *)GVTOP(Args[1]);
  299. unsigned ArgNo = 2;
  300. // printf should return # chars printed. This is completely incorrect, but
  301. // close enough for now.
  302. GenericValue GV;
  303. GV.IntVal = APInt(32, strlen(FmtStr));
  304. while (1) {
  305. switch (*FmtStr) {
  306. case 0: return GV; // Null terminator...
  307. default: // Normal nonspecial character
  308. sprintf(OutputBuffer++, "%c", *FmtStr++);
  309. break;
  310. case '\\': { // Handle escape codes
  311. sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
  312. FmtStr += 2; OutputBuffer += 2;
  313. break;
  314. }
  315. case '%': { // Handle format specifiers
  316. char FmtBuf[100] = "", Buffer[1000] = "";
  317. char *FB = FmtBuf;
  318. *FB++ = *FmtStr++;
  319. char Last = *FB++ = *FmtStr++;
  320. unsigned HowLong = 0;
  321. while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
  322. Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
  323. Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
  324. Last != 'p' && Last != 's' && Last != '%') {
  325. if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
  326. Last = *FB++ = *FmtStr++;
  327. }
  328. *FB = 0;
  329. switch (Last) {
  330. case '%':
  331. strcpy(Buffer, "%"); break;
  332. case 'c':
  333. sprintf(Buffer, FmtBuf, uint32_t(Args[ArgNo++].IntVal.getZExtValue()));
  334. break;
  335. case 'd': case 'i':
  336. case 'u': case 'o':
  337. case 'x': case 'X':
  338. if (HowLong >= 1) {
  339. if (HowLong == 1 &&
  340. TheInterpreter->getTargetData()->getPointerSizeInBits() == 64 &&
  341. sizeof(long) < sizeof(int64_t)) {
  342. // Make sure we use %lld with a 64 bit argument because we might be
  343. // compiling LLI on a 32 bit compiler.
  344. unsigned Size = strlen(FmtBuf);
  345. FmtBuf[Size] = FmtBuf[Size-1];
  346. FmtBuf[Size+1] = 0;
  347. FmtBuf[Size-1] = 'l';
  348. }
  349. sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal.getZExtValue());
  350. } else
  351. sprintf(Buffer, FmtBuf,uint32_t(Args[ArgNo++].IntVal.getZExtValue()));
  352. break;
  353. case 'e': case 'E': case 'g': case 'G': case 'f':
  354. sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
  355. case 'p':
  356. sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
  357. case 's':
  358. sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
  359. default: cerr << "<unknown printf code '" << *FmtStr << "'!>";
  360. ArgNo++; break;
  361. }
  362. strcpy(OutputBuffer, Buffer);
  363. OutputBuffer += strlen(Buffer);
  364. }
  365. break;
  366. }
  367. }
  368. return GV;
  369. }
  370. // int printf(const char *, ...) - a very rough implementation to make output
  371. // useful.
  372. GenericValue lle_X_printf(const FunctionType *FT,
  373. const std::vector<GenericValue> &Args) {
  374. char Buffer[10000];
  375. std::vector<GenericValue> NewArgs;
  376. NewArgs.push_back(PTOGV((void*)&Buffer[0]));
  377. NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
  378. GenericValue GV = lle_X_sprintf(FT, NewArgs);
  379. cout << Buffer;
  380. return GV;
  381. }
  382. static void ByteswapSCANFResults(LLVMContext &C,
  383. const char *Fmt, void *Arg0, void *Arg1,
  384. void *Arg2, void *Arg3, void *Arg4, void *Arg5,
  385. void *Arg6, void *Arg7, void *Arg8) {
  386. void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
  387. // Loop over the format string, munging read values as appropriate (performs
  388. // byteswaps as necessary).
  389. unsigned ArgNo = 0;
  390. while (*Fmt) {
  391. if (*Fmt++ == '%') {
  392. // Read any flag characters that may be present...
  393. bool Suppress = false;
  394. bool Half = false;
  395. bool Long = false;
  396. bool LongLong = false; // long long or long double
  397. while (1) {
  398. switch (*Fmt++) {
  399. case '*': Suppress = true; break;
  400. case 'a': /*Allocate = true;*/ break; // We don't need to track this
  401. case 'h': Half = true; break;
  402. case 'l': Long = true; break;
  403. case 'q':
  404. case 'L': LongLong = true; break;
  405. default:
  406. if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
  407. goto Out;
  408. }
  409. }
  410. Out:
  411. // Read the conversion character
  412. if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
  413. unsigned Size = 0;
  414. const Type *Ty = 0;
  415. switch (Fmt[-1]) {
  416. case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
  417. case 'd':
  418. if (Long || LongLong) {
  419. Size = 8; Ty = Type::getInt64Ty(C);
  420. } else if (Half) {
  421. Size = 4; Ty = Type::getInt16Ty(C);
  422. } else {
  423. Size = 4; Ty = Type::getInt32Ty(C);
  424. }
  425. break;
  426. case 'e': case 'g': case 'E':
  427. case 'f':
  428. if (Long || LongLong) {
  429. Size = 8; Ty = Type::getDoubleTy(C);
  430. } else {
  431. Size = 4; Ty = Type::getFloatTy(C);
  432. }
  433. break;
  434. case 's': case 'c': case '[': // No byteswap needed
  435. Size = 1;
  436. Ty = Type::getInt8Ty(C);
  437. break;
  438. default: break;
  439. }
  440. if (Size) {
  441. GenericValue GV;
  442. void *Arg = Args[ArgNo++];
  443. memcpy(&GV, Arg, Size);
  444. TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. // int sscanf(const char *format, ...);
  451. GenericValue lle_X_sscanf(const FunctionType *FT,
  452. const std::vector<GenericValue> &args) {
  453. assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
  454. char *Args[10];
  455. for (unsigned i = 0; i < args.size(); ++i)
  456. Args[i] = (char*)GVTOP(args[i]);
  457. GenericValue GV;
  458. GV.IntVal = APInt(32, sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
  459. Args[5], Args[6], Args[7], Args[8], Args[9]));
  460. ByteswapSCANFResults(FT->getContext(),
  461. Args[1], Args[2], Args[3], Args[4],
  462. Args[5], Args[6], Args[7], Args[8], Args[9], 0);
  463. return GV;
  464. }
  465. // int scanf(const char *format, ...);
  466. GenericValue lle_X_scanf(const FunctionType *FT,
  467. const std::vector<GenericValue> &args) {
  468. assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
  469. char *Args[10];
  470. for (unsigned i = 0; i < args.size(); ++i)
  471. Args[i] = (char*)GVTOP(args[i]);
  472. GenericValue GV;
  473. GV.IntVal = APInt(32, scanf( Args[0], Args[1], Args[2], Args[3], Args[4],
  474. Args[5], Args[6], Args[7], Args[8], Args[9]));
  475. ByteswapSCANFResults(FT->getContext(),
  476. Args[0], Args[1], Args[2], Args[3], Args[4],
  477. Args[5], Args[6], Args[7], Args[8], Args[9]);
  478. return GV;
  479. }
  480. // int fprintf(FILE *, const char *, ...) - a very rough implementation to make
  481. // output useful.
  482. GenericValue lle_X_fprintf(const FunctionType *FT,
  483. const std::vector<GenericValue> &Args) {
  484. assert(Args.size() >= 2);
  485. char Buffer[10000];
  486. std::vector<GenericValue> NewArgs;
  487. NewArgs.push_back(PTOGV(Buffer));
  488. NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
  489. GenericValue GV = lle_X_sprintf(FT, NewArgs);
  490. fputs(Buffer, (FILE *) GVTOP(Args[0]));
  491. return GV;
  492. }
  493. } // End extern "C"
  494. // Done with externals; turn the warning back on
  495. #ifdef _MSC_VER
  496. #pragma warning(default: 4190)
  497. #endif
  498. void Interpreter::initializeExternalFunctions() {
  499. sys::ScopedLock Writer(*FunctionsLock);
  500. FuncNames["lle_X_atexit"] = lle_X_atexit;
  501. FuncNames["lle_X_exit"] = lle_X_exit;
  502. FuncNames["lle_X_abort"] = lle_X_abort;
  503. FuncNames["lle_X_printf"] = lle_X_printf;
  504. FuncNames["lle_X_sprintf"] = lle_X_sprintf;
  505. FuncNames["lle_X_sscanf"] = lle_X_sscanf;
  506. FuncNames["lle_X_scanf"] = lle_X_scanf;
  507. FuncNames["lle_X_fprintf"] = lle_X_fprintf;
  508. }