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

Rust runtime fails trying to create threads with requested stack size < TLS size #6233

Closed
kalenedrael opened this issue May 4, 2013 · 7 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@kalenedrael
Copy link

Linking with certain external libraries can inflate the required amount of thread local storage to astronomical proportions. When the Rust runtime tries to create its threads, it requests a stack size independent of the TLS size, which can lead to pthread_create() failing with EINVAL when the stack size is smaller than the TLS size. This was apparently an issue for the Go runtime as well (http://sourceware.org/ml/libc-alpha/2012-06/msg00175.html).

A potential workaround is to add __static_tls_size (+ possibly a guard page) to the requested stack size, but it's arguably a bug in glibc that TLS comes out of the requested stack, instead of being added to it. This solution is also admittedly not very pleasing...

@kalenedrael
Copy link
Author

I made a mistake. The workaround should actually be to add __pthread_get_minstack(&attr) to the requested size in src/rt/sync/rust_thread.cpp. It's still not very pleasing.

@luqmana
Copy link
Member

luqmana commented May 4, 2013

This is the bug in glibc http://sourceware.org/bugzilla/show_bug.cgi?id=11787

@emberian
Copy link
Member

Still relevant, but it's an upstream bug. Removing E-easy

@huonw
Copy link
Member

huonw commented Aug 28, 2013

Triage: we still call pthread_attr_setstacksize without adjusting for __pthread_get_minstack so I assume that the work-around hasn't been implemented, and the upstream bug is still open (and without activity for more than 3 months).

@huonw
Copy link
Member

huonw commented Jan 3, 2014

Triage: still a bug even with the pure Rust runtime.

#[feature(thread_local)];
#[allow(dead_code)];

#[cfg(crash)]
static SIZE: uint = 1 << 20; // 1 MB

#[cfg(not(crash))]
static SIZE: uint = 1 << 10; // 1 KB

#[thread_local]
static FOO: [u8, .. SIZE] = [0, .. SIZE];

fn main() {}

With --cfg crash it crashes with:

task '<unnamed>' failed at 'assertion failed: `(left == right) && (right == left)` (left: `22i32`, right: `0i32`)', /home/huon/rust/src/libstd/rt/thread.rs:211
failed at 'called `Option::unwrap()` on a `None` value', /home/huon/rust/src/libstd/option.rs:133

and without that --cfg it runs fine.

I'll attempt to fix it now.

@huonw
Copy link
Member

huonw commented Jan 3, 2014

(The above crash appears to not happen on Mac OSX; I'm on Linux.)

I opened #11284; but I don't think that work-around is complete enough to close this.

huonw added a commit to huonw/rust that referenced this issue Jan 4, 2014
If there is a lot of data in thread-local storage some implementations
of pthreads (e.g. glibc) fail if you don't request a stack large enough
-- by adjusting for the minimum size we guarantee that our stacks are
always large enough. Issue rust-lang#6233.
bors added a commit that referenced this issue Jan 4, 2014
If there is a lot of data in thread-local storage some implementations
of pthreads (e.g. glibc) fail if you don't request a stack large enough
-- by adjusting for the minimum size we guarantee that our stacks are
always large enough. Issue #6233.
@huonw
Copy link
Member

huonw commented Jan 5, 2014

My patch caused people linking errors (__pthread_get_minstack is apparently not in all versions of glibc (works in 2.17, fails with 2.13), being a private function), so I'm reverting it in #11331.

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 I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

4 participants