-
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
Don't inherit codegen attrs from parent static #123310
Don't inherit codegen attrs from parent static #123310
Conversation
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Hm. I would expect that if nested statics inside ...I may be wrong about how the nesting would work out, but I swear that I have indeed seen code like |
Well it doesn't seem to matter with this PR: #![feature(thread_local)]
use std::cell::RefCell;
#[thread_local]
static FOO: RefCell<RefCell<i32>> = RefCell::new(RefCell::new(0));
fn main() {
*FOO.borrow_mut().borrow_mut() = 1;
let _ = std::thread::spawn(|| {
let y = *FOO.borrow().borrow();
println!("{y}");
}).join();
let y = *FOO.borrow().borrow();
println!("{y}");
} This continues to print I think even "thread locals" are a bit misleading here -- the attr seems to only affect MIR building and the creation of thread-local shims. This doesn't seem really relevant to static items that are anonymous. |
Huh, weird/neat! |
Nested statics only get created when there are indirections. I need to check how thread local statics work in detail, maybe we can just hard error when we try to have mutable nested statics in thread local statics. |
This ICEs in const eval during validation #![feature(const_refs_to_cell)]
#![feature(thread_local)]
use std::cell::RefCell;
#[thread_local]
static mut FOO: &mut u32 = &mut 42;
fn main() {
unsafe {
*FOO = 1;
let _ = std::thread::spawn(|| {
let y = *;
println!("{y}");
}).join();
let y = *FOO;
println!("{y}");
}
} |
I wonder what to do about link-section. If there are nested mutable statics, I'd potentially expect them to live in the same link section. More and more it feels like we will want to error when there are some flags on the parent, but that's orthogonal to this PR. After this PR we get back the original behaviour, no matter how fishy @bors r+ |
Oh yeah thread-locals are fun. Even without mutability they will cause problems I think. Could you open an issue for that? |
☀️ Test successful - checks-actions |
Finished benchmarking commit (3d5528c): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.778s -> 669.305s (0.23%) |
…s, r=estebank Check that nested statics in thread locals are duplicated per thread. follow-up to rust-lang#123310 cc `@compiler-errors` `@RalfJung` fwiw: I have no idea how thread local statics make that work under LLVM, and miri fails on this example, which I would have expected to be the correct behaviour. Since the `#[thread_local]` attribute is just an internal implementation detail, I'm just going to start hard erroring on nested mutable statics in thread locals.
…s, r=estebank Check that nested statics in thread locals are duplicated per thread. follow-up to rust-lang#123310 cc ``@compiler-errors`` ``@RalfJung`` fwiw: I have no idea how thread local statics make that work under LLVM, and miri fails on this example, which I would have expected to be the correct behaviour. Since the `#[thread_local]` attribute is just an internal implementation detail, I'm just going to start hard erroring on nested mutable statics in thread locals.
Rollup merge of rust-lang#123362 - oli-obk:thread_local_nested_statics, r=estebank Check that nested statics in thread locals are duplicated per thread. follow-up to rust-lang#123310 cc ``@compiler-errors`` ``@RalfJung`` fwiw: I have no idea how thread local statics make that work under LLVM, and miri fails on this example, which I would have expected to be the correct behaviour. Since the `#[thread_local]` attribute is just an internal implementation detail, I'm just going to start hard erroring on nested mutable statics in thread locals.
[beta] backports - Fix f16 and f128 feature gates in editions other than 2015 rust-lang#123307 / rust-lang#123445 - Update to LLVM 18.1.2 rust-lang#122772 - unix fs: Make hurd using explicit new rather than From rust-lang#123057 - Don't inherit codegen attrs from parent static rust-lang#123310 - Make sure to insert Sized bound first into clauses list rust-lang#123302 r? cuviper
[beta] backports - Fix f16 and f128 feature gates in editions other than 2015 rust-lang#123307 / rust-lang#123445 - Update to LLVM 18.1.2 rust-lang#122772 - unix fs: Make hurd using explicit new rather than From rust-lang#123057 - Don't inherit codegen attrs from parent static rust-lang#123310 - Make sure to insert Sized bound first into clauses list rust-lang#123302 r? cuviper
Putting this up partly for discussion and partly for review. Specifically, in #121644, @oli-obk designed a system that creates new static items for representing nested allocations in statics. However, in that PR, oli made it so that these statics inherited the codegen attrs from the parent.
This causes problems such as colliding symbols with
#[export_name]
and ICEs with#[no_mangle]
since these synthetic statics have notcx.item_name(..)
.So the question is, is there any case where we do want to inherit codegen attrs from the parent? The only one that seems a bit suspicious is the thread-local attribute. And there may be some interesting interactions with the coverage attributes as well...
Fixes (after backport) #123274. Fixes #123243. cc #121644.
r? @oli-obk cc @nnethercote @RalfJung (reviewers on that pr)