Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime segfault on freebsd #13427

Closed
alexcrichton opened this issue Apr 9, 2014 · 14 comments
Closed

Runtime segfault on freebsd #13427

alexcrichton opened this issue Apr 9, 2014 · 14 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

Comments

@alexcrichton
Copy link
Member

This code will segfault quickly on freebsd. Apparently something in phread_cond_signal is dereferencing NULL.

I have been unable to reproduce yet with equivalent C code, so I'm assuming this is a problem with the runtime somewhere.

extern crate libc;

unsafe fn test() {
  use libc::funcs::posix01::wait;
  let mut status = 0;
  match libc::fork() {
    -1 => { println!("failed fork"); }
     0 => { libc::_exit(0); }
     n => { assert!(wait::waitpid(n, &mut status, 0) != -1); }
  }
}

fn main() {
    spawn(proc() { unsafe { test() } });
    unsafe { test() }
}
$ rm *.core; for i in {1..10000}; do; echo $i; ./foo || break; done
1
2
3
$
GNU gdb (GDB) 7.6 [GDB v7.6 for FreeBSD]
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd9.1".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/home/alex/rust/foo...done.
[New process 100832]
[New process 100740]
[New Thread 801c06800 (LWP 100832)]
[New Thread 801c06400 (LWP 100740)]
Core was generated by `foo'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000800b4e3a3 in ?? () from /lib/libthr.so.3

Thread 2 (Thread 801c06400 (LWP 100740)):
#0  0x0000000800b5589c in ?? () from /lib/libthr.so.3
#1  0x0000000800b4bedc in ?? () from /lib/libthr.so.3
#2  0x0000000800b53d5c in ?? () from /lib/libthr.so.3
#3  0x00000000004d9707 in rt::cleanup::h82e5897460229b1bUob::v0.11.pre ()
#4  0x0000000000434041 in start::h33b829529c2e0e97epd::v0.11.pre ()
#5  0x0000000000433e14 in lang_start::h60adb6d42985a1f5yod::v0.11.pre ()
#6  0x000000000040599f in main ()

Thread 1 (Thread 801c06800 (LWP 100832)):
#0  0x0000000800b4e3a3 in ?? () from /lib/libthr.so.3
#1  0x0000000800b53fb4 in pthread_cond_signal () from /lib/libthr.so.3
#2  0x00000000004d87d4 in rt::bookkeeping::decrement::hf3ae6ac93e6a5febaib::v0.11.pre ()
#3  0x0000000000433b3d in task::spawn_opts::closure.7683 ()
#4  0x00000000004d216f in rt::thread::thread_start::h6d417d8e1de153f3WJ8::v0.11.pre ()
#5  0x0000000800b4a4a4 in ?? () from /lib/libthr.so.3
#6  0x0000000000000000 in ?? ()
@alexcrichton alexcrichton changed the title Segfault on freebsd Runtime segfault on freebsd Apr 9, 2014
@alexcrichton
Copy link
Member Author

I am unconvinced that this is a rust bug. This C program exhibits the same bug:

#include <assert.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

static pthread_mutex_t lock;
static pthread_cond_t cond;
static volatile int cnt = 0;

static void test() {
  int p = fork();
  assert(p >= 0);
  if (p == 0) {
    _exit(0);
  }
  int a = 1;
  assert(waitpid(p, &a, 0) == p);
  assert(WEXITSTATUS(a) == 0);
}

static void *child(void *arg) {
  test();

  assert(pthread_mutex_lock(&lock) == 0);
  cnt -= 1;
  if (cnt == 0) {
    assert(pthread_cond_signal(&cond) == 0);
  }
  assert(pthread_mutex_unlock(&lock) == 0);
  return arg;
}

int main() {
  assert(pthread_mutex_init(&lock, NULL) == 0);
  assert(pthread_cond_init(&cond, NULL) == 0);

  pthread_t c1, c2;
  cnt = 2;
  assert(pthread_create(&c1, NULL, child, NULL) == 0);
  assert(pthread_create(&c2, NULL, child, NULL) == 0);

  assert(pthread_mutex_lock(&lock) == 0);
  while (cnt != 0) {
    assert(pthread_cond_wait(&cond, &lock) == 0);
  }
  assert(pthread_mutex_unlock(&lock) == 0);

  pthread_join(c1, NULL);
  pthread_join(c2, NULL);
}

@alexcrichton
Copy link
Member Author

I have submitted an upstream bug: http://www.freebsd.org/cgi/query-pr.cgi?pr=188425

bors added a commit that referenced this issue Apr 19, 2014
This is a bit of an interesting upgrade to LLVM. Upstream LLVM has started using C++11 features, so they require a C++11 compiler to build. I've updated all the bots to have a C++11 compiler, and they appear to be building LLVM successfully:

* Linux bots - I added gcc/g++ 4.7 (good enough)
* Android bots - same as the linux ones
* Mac bots - I installed the most recent command line tools for Lion which gives us clang 3.2, but LLVM wouldn't build unless it was explicitly asked to link to `libc++` instead of `libstdc++`. This involved tweaking `mklldeps.py` and the `configure` script to get things to work out
* Windows bots - mingw-w64 has gcc 4.8.1 which is sufficient for building LLVM (hurray!)
* BSD bots - I updated FreeBSD to 10.0 which brought with it a relevant version of clang.

The largest fallout I've seen so far is that the test suite doesn't work at all on FreeBSD 10. We've already stopped gating on FreeBSD due to #13427 (we used to be on freebsd 9), so I don't think this puts us in too bad of a situation. I will continue to attempt to fix FreeBSD and the breakage on there.

The LLVM update brings with it all of the recently upstreamed LLVM patches. We only have one local patch now which is just an optimization, and isn't required to use upstream LLVM. I want to maintain compatibility with LLVM 3.3 and 3.4 while we can, and this upgrade is keeping us up to date with the 3.5 release. Once 3.5 is release we will in theory no longer require a bundled LLVM.
@ebfe
Copy link
Contributor

ebfe commented Oct 13, 2014

Can't reproduce this anymore (FreeBSD 10.1-RC2). Apart from the debuginfo tests (gdb too old and no utf-8 support) and a probably bogus failure in run-pass/tcp-stress.rs make check passes.

@alexcrichton
Copy link
Member Author

Our FreeBSD bot is still segfaulting regularly (http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/), but perhaps it was a bug fixed upstream? They're running FreeBSD 10.0-RELEASE-p1, so perhaps we just need to upgrade?

@ebfe
Copy link
Contributor

ebfe commented Oct 13, 2014

@alexcrichton Upgrading seems a good idea. I have been running rust on FreeBSD for a few weeks now without major problems. I'm not sure at what point the random segfaults disappeared, but it might have happened before I upgraded to a 10.1 prerelease. Upgarding to the latest 10.0 patch level might be worth a try.

@alexcrichton
Copy link
Member Author

I've upgraded our buildbot to 10.1-RC2 and I'll watch the queue for a few days to see if it's all green, and then we can close this and re-gate on bsd.

@alexcrichton
Copy link
Member Author

The bot is a whole lot more green than before, but it seems to be suffering from a spurious out-of-stack error on stdtest (this is the second time I've seen this)

test path::windows::tests::test_with_helpers ... ok
test rand::os::test::test_os_rng ... ok
test rand::reader::test::test_reader_rng_u32 ... ok
test rand::reader::test::test_reader_rng_insufficient_bytes ... ok
test rand::reader::test::test_reader_rng_u64 ... ok
test rand::reader::test::test_reader_rng_fill_bytes ... ok
test rand::test::test_fill_bytes_default ... ok
test rand::test::test_choose ... ok
test rand::test::test_gen_ascii_str ... ok
test rand::test::test_gen_f64 ... ok
test rand::test::test_gen_range ... ok
test rand::test::test_gen_range_fail_int ... ok
test rand::os::test::test_os_rng_tasks ... ok
test rand::test::test_random ... ok
test rand::test::test_gen_weighted_bool ... ok
test rand::test::test_sample ... ok
test rand::test::test_gen_vec ... ok
test rand::test::test_shuffle ... ok
test rand::test::test_std_rng_seeded ... ok
test rand::test::test_std_rng_reseed ... ok
test rt::backtrace::test::demangle ... ok
test rt::backtrace::test::demangle_many_dollars ... ok
test sync::future::test::test_dropped_future_doesnt_fail ... ok
test rt::backtrace::test::demangle_dollars ... ok
test sync::future::test::test_from_fn ... ok
test rand::test::test_gen_range_fail_uint ... ok
test sync::future::test::test_from_receiver ... ok
test sync::future::test::test_from_value ... ok
test sync::future::test::test_interface_get ... ok
test sync::future::test::test_get_ref_method ... ok
test io::process::tests::test_wait_with_output_once ... ok
test sync::future::test::test_spawn ... oktask '<unnamed>' failed at 'explicit failure', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/sync/future.rs:197

test sync::future::test::test_sendable_future ... ok
test rand::test::test_task_rng ... ok
test sync::future::test::test_interface_unwrap ... ok
Hello from thread 1!
Hello from thread 0!
Hello from thread 0!
Hello from thread 1!
Hello from thread 3!
Hello from thread 3!
Hello from thread 2!
Hello from thread 2!
test sync::task_pool::test_zero_tasks_failure ... ok
test sync::task_pool::test_task_pool ... ok
test sync::future::test::test_futurefail ... ok
test task::test::test_avoid_copying_the_body_task_spawn ... ok
test task::test::test_avoid_copying_the_body_spawn ... ok
test task::test::test_child_doesnt_ref_parent ... ok
test task::test::test_owned_named_task ... ok
test task::test::test_run_basic ... ok
test task::test::test_simple_newsched_spawn ... ok
test task::test::test_send_named_task ... ok
test task::test::test_avoid_copying_the_body_try ... ok
test task::test::test_static_named_task ... ok
test task::test::test_spawn_sched_childs_on_default_sched ... ok
task 'task '<unnamed>' failed at 'explicit failure', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rs:487
<unnamed>' failed at 'Box<Any>', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rs:620
test task::test::test_try_fail_message_any ... ok
task 'test task::test::test_stdout ... <unnamed>' failed at 'owned string', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rs:606
ok
test task::test::test_try_fail_message_owned_str ... ok
task '<unnamed>' failed at 'Box<Any>', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rs:638
test task::test::test_try_fail_message_unit_struct ... ok
task '<unnamed>' failed at 'static string', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rs:592
test task::test::test_try_fail_message_static_str ... ok
test io::process::tests::wait_timeout2 ... ok
task 'test task::test::test_try_success ... ok
<unnamed>test task::test::test_spawn_sched ... ok
' failed at 'explicit failuretest task::test::test_unnamed_task ... ok
test time::duration::tests::test_duration ... ok
', /usr/home/rustbuild/src/rust-buildbot/slave/auto-bsd-64-opt/build/src/libstd/task.rstest task::test::test_with_wrapper ... :ok
test time::duration::tests::test_duration_div ... ok
test time::duration::tests::test_duration_checked_ops ... ok
469
test task::test::test_try_fail ... ok
test task::test::test_try_future ... ok
test time::duration::tests::test_duration_fmt ... ok
test time::duration::tests::test_duration_mul ... ok
test time::duration::tests::test_duration_num_days ... ok
test time::duration::tests::test_duration_num_microseconds ... ok
test time::duration::tests::test_duration_num_seconds ... ok
test time::duration::tests::test_duration_num_nanoseconds ... ok
test to_string::tests::test_vectors ... ok
test time::duration::tests::test_duration_num_milliseconds ... ok
test u16::tests::test_from_str ... ok
test to_string::tests::test_simple_types ... ok
test u16::tests::test_parse_bytes ... ok
test u16::tests::test_uint_to_str_overflow ... ok
test u16::tests::test_uint_from_str_overflow ... ok
test u16::tests::test_to_string ... ok
task 'test u16::tests::to_str_radix37 ... ok
test u32::tests::test_to_string ... <unknown>ok
test u32::tests::test_uint_from_str_overflow ... ok
test u16::tests::to_str_radix1 ... ok
test io::process::tests::test_process_status ... ok
test u32::tests::test_uint_to_str_overflow ... ok
test u32::tests::to_str_radix1 ... ok
test u32::tests::test_parse_bytes ... ok
test u64::tests::test_from_str ... ok
test u64::tests::test_parse_bytes ... ok
test u64::tests::test_to_string ... ok
test u32::tests::to_str_radix37 ... ok
test u64::tests::test_uint_from_str_overflow ... ok
test u64::tests::test_uint_to_str_overflow ... ok
' has overflowed its stack
Illegal instruction (core dumped)
gmake: *** [tmp/check-stage2-T-x86_64-unknown-freebsd-H-x86_64-unknown-freebsd-std.ok] Error 132
program finished with exit code 2
elapsedTime=218.331498

@0X1A
Copy link

0X1A commented Dec 4, 2014

@alexcrichton Any updates on when/if this is going to be resolved?

@alexcrichton
Copy link
Member Author

Sadly no, but it sounds like another FreeBSD upgrade may be promising.

@0X1A
Copy link

0X1A commented Dec 4, 2014

Unfortunately building on 10.1-RELEASE still results in a segfault

@frewsxcv
Copy link
Member

Can anyone confirm if this is still an issue?

@0X1A
Copy link

0X1A commented Jul 13, 2015

@frewsxcv I can't say but I believe there are unofficial builds of cargo and rustc floating around some user's repository

@dhuseby
Copy link

dhuseby commented Jul 28, 2015

@alexcrichton it appears that this is no longer an issue on FreeBSD. The new buildbot is solidly green. I vote we close this.

@alexcrichton
Copy link
Member Author

🎊

compiler-errors pushed a commit to compiler-errors/rust that referenced this issue Oct 26, 2022
feat: Make flycheck workdone progress reports cancellable

In clients that support this (like VSCode), the clients will now render a cancel button on the notification message which can be clicked to cancel the flycheck instead.

Closes rust-lang/rust-analyzer#6895
![Code_VbXgP3SbFD](https://user-images.githubusercontent.com/3757771/196205329-2df93451-c143-4d1b-a700-d988edf55efa.gif)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
Projects
None yet
Development

No branches or pull requests

5 participants