From 7993f4820995c9b26d73e8a58bb8f3c0e2e79d47 Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Sun, 26 Aug 2012 22:40:21 +1000 Subject: jit: Add custom memory manager (still segfaulting) --- src/rustc/back/link.rs | 33 ++++++++++++++++++++++++++++----- src/rustc/lib/llvm.rs | 10 ++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src/rustc') diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs index 04c38c11d62..06d90e982c1 100644 --- a/src/rustc/back/link.rs +++ b/src/rustc/back/link.rs @@ -160,14 +160,37 @@ mod write { llvm::LLVMAddCFGSimplificationPass(pm.llpm);*/ // JIT execution takes ownership of the module, - // so don't dispose and return. + // so don't dispose and return. Due to a weird bug + // with dynamic libraries, we need to separate jitting + // into two functions and load crates inbetween. + + if !llvm::LLVMRustPrepareJIT(pm.llpm, + llmod, + CodeGenOptLevel, + true) { + llvm_err(sess, ~"Could not JIT"); + } + + // We need to tell LLVM where to resolve all linked + // symbols from. The equivalent of -lstd, -lcore, etc. + /*let cstore = sess.cstore; + for cstore::get_used_crate_files(cstore).each |cratepath| { + debug!{"linking: %s", cratepath}; + + let _: () = str::as_c_str( + cratepath, + |buf_t| { + if !llvm::LLVMRustLoadLibrary(buf_t) { + llvm_err(sess, ~"Could not link"); + } + debug!{"linked: %s", cratepath}; + }); + }*/ - if !llvm::LLVMRustJIT(pm.llpm, - llmod, - CodeGenOptLevel, - true) { + if !llvm::LLVMRustExecuteJIT() { llvm_err(sess, ~"Could not JIT"); } + if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); } return; } diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs index 5c8bab166ec..ec9c669501b 100644 --- a/src/rustc/lib/llvm.rs +++ b/src/rustc/lib/llvm.rs @@ -986,12 +986,18 @@ extern mod llvm { call. */ fn LLVMRustGetLastError() -> *c_char; - /** JIT the module. **/ - fn LLVMRustJIT(PM: PassManagerRef, + /** Load a shared library to resolve symbols against. */ + fn LLVMRustLoadLibrary(Filename: *c_char) -> bool; + + /** Create the JIT engine. */ + fn LLVMRustPrepareJIT(PM: PassManagerRef, M: ModuleRef, OptLevel: c_int, EnableSegmentedStacks: bool) -> bool; + /** Execute the JIT engine. */ + fn LLVMRustExecuteJIT() -> bool; + /** Parses the bitcode in the given memory buffer. */ fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef; -- cgit 1.4.1-3-g733a5