From e7ca9a186b212bf65f1ae5cd103458461ea3864f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 9 Sep 2018 14:45:23 +0200 Subject: [PATCH] Fix jit --- build.sh | 9 ++++++--- examples/mini_core_hello_world.rs | 12 ++++++++++-- src/constant.rs | 4 +--- src/lib.rs | 13 +++++-------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/build.sh b/build.sh index 86cefa83971b..eb39e5749027 100755 --- a/build.sh +++ b/build.sh @@ -35,7 +35,7 @@ build_lib() { } run_bin() { - SHOULD_RUN=1 $RUSTC $1 --crate-type bin + SHOULD_RUN=1 $RUSTC $@ --crate-type bin } build_example_bin() { @@ -58,15 +58,18 @@ RUSTC="rustc -Zcodegen-backend=$(pwd)/target/$channel/librustc_codegen_cranelift rm -r target/out || true mkdir -p target/out/clif +echo "[BUILD] mini_core" build_lib mini_core examples/mini_core.rs $RUSTC examples/example.rs --crate-type lib -# SimpleJIT is broken -# run_bin examples/mini_core_hello_world.rs +echo "[JIT] mini_core_hello_world" +run_bin examples/mini_core_hello_world.rs --cfg jit +echo "[AOT] mini_core_hello_world" build_example_bin mini_core_hello_world examples/mini_core_hello_world.rs +echo "[BUILD] core" time $RUSTC target/libcore/src/libcore/lib.rs --crate-type lib --crate-name core -Cincremental=target/incremental_core cat target/out/log.txt | sort | uniq -c #extract_data libcore.rlib core.o diff --git a/examples/mini_core_hello_world.rs b/examples/mini_core_hello_world.rs index b9614cf00a7a..9c08269d60ba 100644 --- a/examples/mini_core_hello_world.rs +++ b/examples/mini_core_hello_world.rs @@ -17,6 +17,10 @@ unsafe extern "C" fn my_puts(s: *const u8) { puts(s); } +// TODO remove when jit supports linking rlibs +#[cfg(jit)] +fn panic(_: T) { loop {} } + #[lang = "termination"] trait Termination { fn report(self) -> i32; @@ -61,8 +65,12 @@ fn main() { let ptr: *const u8 = hello as *const [u8] as *const u8; puts(ptr); - let world = box "World!\0"; - puts(*world as *const str as *const u8); + // TODO remove when jit supports linking rlibs + #[cfg(not(jit))] + { + let world = box "World!\0"; + puts(*world as *const str as *const u8); + } if intrinsics::size_of_val(hello) as u8 != 6 { panic(&("", "", 0, 0)); diff --git a/src/constant.rs b/src/constant.rs index 26afe046ac17..9bb89b88b217 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -27,9 +27,7 @@ impl ConstantCx { //println!("todo {:?}", self.todo); define_all_allocs(tcx, module, &mut self); //println!("done {:?}", self.done); - for data_id in self.done.drain() { - module.finalize_data(data_id); - } + self.done.clear(); } } diff --git a/src/lib.rs b/src/lib.rs index 7e8f5ac0e47e..82754fc47418 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -230,9 +230,8 @@ impl CodegenBackend for CraneliftCodegenBackend { codegen_mono_items(tcx, &mut jit_module, &mono_items); tcx.sess.abort_if_errors(); - tcx.sess.warn("Compiled everything"); - - tcx.sess.warn("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set"); + println!("Compiled everything"); + println!("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set"); let sig = Signature { params: vec![ @@ -246,14 +245,14 @@ impl CodegenBackend for CraneliftCodegenBackend { .declare_function("main", Linkage::Import, &sig) .unwrap(); - let finalized_main: *const u8 = jit_module.finalize_function(main_func_id); jit_module.finalize_all(); - tcx.sess.warn("Finalized everything"); + let finalized_main: *const u8 = jit_module.get_finalized_function(main_func_id); + println!("🎉 Finalized everything"); let f: extern "C" fn(isize, *const *const u8) -> isize = unsafe { ::std::mem::transmute(finalized_main) }; let res = f(0, 0 as *const _); - tcx.sess.warn(&format!("main returned {}", res)); + tcx.sess.warn(&format!("🚀 main returned {}", res)); jit_module.finish(); ::std::process::exit(0); @@ -271,11 +270,9 @@ impl CodegenBackend for CraneliftCodegenBackend { codegen_mono_items(tcx, &mut faerie_module, &mono_items); tcx.sess.abort_if_errors(); - tcx.sess.warn("Compiled everything"); if should_codegen(tcx.sess) { faerie_module.finalize_all(); - tcx.sess.warn("Finalized everything"); } return Box::new(OngoingCodegen {