-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Using thread_local!
with Drop
from GlobalAlloc::alloc
causes crashes
#116390
Comments
thread_local!
from GlobalAlloc
causes crash and undefined behaviorthread_local!
with Drop
from GlobalAlloc
causes crash and undefined behavior
I created a workaround for my needs where I instead access the |
thread_local!
with Drop
from GlobalAlloc
causes crash and undefined behaviorthread_local!
with Drop
from GlobalAlloc::alloc
causes crash and undefined behavior
This seems to be Mac-specific looking through the code, and neither am I able to reproduce this on Linux. |
@rustbot label A-allocators I-unsound |
I don't think we'll be able to avoid crashes in this situation entirely. TLS fundamentally needs to allocate on some platforms, so unless we unconditionally use the system allocator for this, there will always be crashes here. In #116402 I removed the UB part of this (I hope), so after merging that, this will probably be more of a documentation problem. This seems to fall in the same category as #110708; it's another edge-case where |
(Repeating for visibility) I think an ideal long term solution would be to make It's not uncommon for custom allocators to take advantage of thread local storage to improve performance. My personal use case is to efficiently profile allocations by keeping counters specific to each thread. |
WG-prioritization assigning priority (Zulip discussion). As per this comment, probably fixed by #116402 (at least the UB part). @rustbot label -I-prioritize +P-high |
…s, r=thomcc Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in rust-lang#116390 and reduces the amount of `unsafe` code in the codebase.
… r=thomcc Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in rust-lang#116390 and reduces the amount of `unsafe` code in the codebase.
… r=thomcc,workingjubilee Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in rust-lang#116390 and reduces the amount of `unsafe` code in the codebase.
… r=thomcc,workingjubilee Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in rust-lang#116390 and reduces the amount of `unsafe` code in the codebase.
… r=thomcc,workingjubilee Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in rust-lang#116390 and reduces the amount of `unsafe` code in the codebase.
thread_local!
with Drop
from GlobalAlloc::alloc
causes crash and undefined behaviorthread_local!
with Drop
from GlobalAlloc::alloc
causes crashes
I tried this code:
I expected to see this happen: it prints
Hello, world!
.Instead, this happened: terminated by signal SIGILL (Illegal instruction)
When run under Miri, it reports undefined behavior:
It appears the UB is caused by
register_dtor
callingVec::push
and thus getting multiple mutable references simultaneously.Meta
rustc --version --verbose
:rustc +nightly --version --verbose
:The text was updated successfully, but these errors were encountered: