On 08/27/2013 12:43 AM, Minh Do wrote:
My name is Do Nhat Minh, currently a final year Computer Science
student at Nanyang Technological University in Singapore. I have
played with Rust and found the experience to be very pleasant. I think
Rust make sensible trade-offs and managed to stay small, compared to C++.
I have been granted permission by my university supervisor to work on
rusti as my final year project. I hope with this contribution, Rust
will be even stronger a competitor to Go and D.
This will be my first time working on something this size and this
long a duration. I would love to hear your advice or experience
implementing rusti.
Thank you for your time.
Regards,
Minh
Hi,
I'm working on figuring out why rusti segfaults. So far, I'm able to
extract very little information.
Attached is a backtrace from rusti using gdb. SIGSEGV is signaled inside
jemalloc's tcache_alloc_easy, line 286. Below is the piece code where it
fails.
274 JEMALLOC_ALWAYS_INLINE void *
275 tcache_alloc_easy(tcache_bin_t *tbin)
276 {
277 void *ret;
278
279 if (tbin->ncached == 0) {
280 tbin->low_water = -1;
281 return (NULL);
282 }
283 tbin->ncached--;
284 if ((int)tbin->ncached < tbin->low_water)
285 tbin->low_water = tbin->ncached;
286 ret = tbin->avail[tbin->ncached]; // <- XXX fail here
287 return (ret);
288 }
jemalloc is trying to read from tbin->avail at tbin->ncached.
tbin->ncached was 1227353920 (or 0x4927ef40) which is too big in my
opinion. All the other values in tbin were unusually high or low, which
leads me to suspect tbin is uninitialized or there is a memory overrun.
I run valgrind on rusti in the hope of catching memory overruns, but it
does not help much. Valgrind only prints some warning about conditional
jumps depending on uninitialized variables and then reports an invalid
read with the identical backtrace. However, at the top, valgrind prints
the below text, which I find quite interesting.
==31583== Syscall param read(buf) points to unaddressable byte(s)
==31583== at 0x40170C7: read (in /usr/lib/ld-2.18.so)
==31583== by 0x400586C: open_verify (in /usr/lib/ld-2.18.so)
==31583== by 0x4005CA6: open_path (in /usr/lib/ld-2.18.so)
==31583== by 0x4008495: _dl_map_object (in /usr/lib/ld-2.18.so)
==31583== by 0x400C281: openaux (in /usr/lib/ld-2.18.so)
==31583== by 0x400E773: _dl_catch_error (in /usr/lib/ld-2.18.so)
==31583== by 0x400C4E4: _dl_map_object_deps (in /usr/lib/ld-2.18.so)
==31583== by 0x4002E93: dl_main (in /usr/lib/ld-2.18.so)
==31583== by 0x4015174: _dl_sysdep_start (in /usr/lib/ld-2.18.so)
==31583== by 0x4004AE5: _dl_start (in /usr/lib/ld-2.18.so)
==31583== by 0x4001277: ??? (in /usr/lib/ld-2.18.so)
==31583== Address 0x7fec7f700 is on thread 1's stack
I then try linking directly with Rust's libstd (since it's the first
thing that's linked with the code being compiled) in rusti's main()
before anything is done. Below is the addition.
diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs
index 8d61a97..2f72cfa 100644
--- a/src/librusti/rusti.rs
+++ b/src/librusti/rusti.rs
@@ -84,6 +84,9 @@ use syntax::print::pprust;
use program::Program;
use utils::*;
+use rustc::lib::llvm::llvm;
+use std::unstable::intrinsics;
+
mod program;
pub mod utils;
@@ -505,6 +508,17 @@ pub fn main() {
pub fn main_args(args: &[~str]) {
#[fixed_stack_segment]; #[inline(never)];
+ unsafe {
+ let manager =
llvm::LLVMRustPrepareJIT(intrinsics::morestack_addr());
+ let path =
"/path/to/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8-pre.so";
+ do path.with_c_str |buf_t| {
+ if !llvm::LLVMRustLoadCrate(manager, buf_t) {
+ debug!(~"Could not link");
+ }
+ debug!("linked: %s", path);
+ }
+ }
+
let input = io::stdin();
let out = io::stdout();
let mut repl = Repl {
Rusti now also fails in the scheduler sometimes if it happens to switch
threads while LLVMRustLoadCrate is being executed. Below is the backtrace.
#0 rust_thread_start (ptr=0x7ffff1c1f5e0) at src/rt/sync/rust_thread.cpp:36
#1 0x00007ffff548b0a2 in start_thread () from /usr/lib/libpthread.so.0
#2 0x00007ffff3217a2d in clone () from /usr/lib/libc.so.6
The above failure in the scheduler and the curious message by valgrind
makes me wonder about the scheduler and the runtime. However, when git
grep-ing for rust_thread, I don't see how it is hooked into Rust. Could
someone enlighten me on this?
More importantly, does anyone have any suggestion about my approach or
any leads on this?
Regards,
Minh
#0 0x00007f43cecc7737 in SignalHandler(int) ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustllvm.so
#1 <signal handler called>
#2 0x00007f43cdb1fd9d in tcache_alloc_easy (tbin=0x7f43ca8062e8) at
../../../../src/rt/jemalloc/include/jemalloc/internal/tcache.h:286
#3 tcache_alloc_small (zero=true, size=1315, tcache=0x7f43ca806000) at
../../../../src/rt/jemalloc/include/jemalloc/internal/tcache.h:300
#4 arena_malloc (try_tcache=true, zero=true, size=1315, arena=0x0) at
../../../../src/rt/jemalloc/include/jemalloc/internal/arena.h:916
#5 icallocx (arena=0x0, try_tcache=true, size=1315) at
include/jemalloc/internal/jemalloc_internal.h:803
#6 icalloc (size=1315) at include/jemalloc/internal/jemalloc_internal.h:812
#7 calloc (num=<optimized out>, size=<optimized out>) at
../../../../src/rt/jemalloc/src/jemalloc.c:1079
#8 0x00007f43d1b0f75f in _dl_new_object () from /lib64/ld-linux-x86-64.so.2
#9 0x00007f43d1b0b204 in _dl_map_object_from_fd () from
/lib64/ld-linux-x86-64.so.2
#10 0x00007f43d1b0cff5 in _dl_map_object () from /lib64/ld-linux-x86-64.so.2
#11 0x00007f43d1b17917 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#12 0x00007f43d1b13774 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#13 0x00007f43d1b1732b in _dl_open () from /lib64/ld-linux-x86-64.so.2
#14 0x00007f43cd4dc02b in ?? () from /usr/lib/libdl.so.2
#15 0x00007f43d1b13774 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#16 0x00007f43cd4dc5dd in ?? () from /usr/lib/libdl.so.2
#17 0x00007f43cd4dc0c1 in dlopen () from /usr/lib/libdl.so.2
#18 0x00007f43cecb12e7 in llvm::sys::DynamicLibrary::getPermanentLibrary(char
const*, std::string*) ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustllvm.so
#19 0x00007f43cdfdf46c in RustMCJITMemoryManager::loadCrate
(this=this@entry=0x7f43ca85e100,
file=file@entry=0x7f43c2220020
"/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8-pre.so",
err=err@entry=0x7f43caa48070) at src/rustllvm/RustWrapper.cpp:132
#20 0x00007f43cdfdfcfb in LLVMRustLoadCrate (mem=0x7f43ca85e100,
crate=0x7f43c2220020
"/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8-pre.so")
at src/rustllvm/RustWrapper.cpp:271
#21 0x00007f43d02c385e in back::link::jit::exec::_c689f4ad2731ee34::v0.8$x2dpre
()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#22 0x00007f43d02c5a27 in
back::link::write::run_passes::_8982e8a461f435::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#23 0x00007f43d0335568 in
driver::driver::phase_5_run_llvm_passes::anon::expr_fn_97090 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#24 0x00007f43d00538e1 in
util::common::time_72396::_c4d0513e54dc658e::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#25 0x00007f43d03352d2 in
driver::driver::phase_5_run_llvm_passes::_af1696f6788ce06d::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#26 0x00007f43cf87f799 in run::_bdca1c883dbff4c::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librusti-53e0ef2ae196aaff-0.8-pre.so
#27 0x00007f43cf8a17c5 in run_line::anon::expr_fn_17258 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librusti-53e0ef2ae196aaff-0.8-pre.so
#28 0x00007f43cf89ecb1 in task::__extensions__::try_16906::anon::expr_fn_17066
()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/librusti-53e0ef2ae196aaff-0.8-pre.so
#29 0x00007f43d147b6b0 in task::spawn::spawn_raw::anon::expr_fn_37755 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#30 0x00007f43d14c25c0 in
rt::task::__extensions__::build_start_wrapper::anon::anon::expr_fn_44126 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#31 0x00007f43d14c0ab7 in rt::task::__extensions__::run::anon::expr_fn_44054 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#32 0x00007f43cdb12834 in rust_try (f=<optimized out>, fptr=<optimized out>,
env=<optimized out>) at src/rt/rust_builtin.cpp:523
#33 0x00007f43d14c09ec in
rt::task::Unwinder::try::_199ab8d6eb226980EIaH::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#34 0x00007f43d14c0861 in
rt::task::Task::run::_199ab8d6eb22698022aG::v0.8$x2dpre ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#35 0x00007f43d14c21ac in
rt::task::__extensions__::build_start_wrapper::anon::expr_fn_44111 ()
from
/home/minh/Documents/Workplace/rust/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libstd-6c65cf4b443341b1-0.8-pre.so
#36 0x0000000000000000 in ?? ()
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev