You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inner statics in generic fns aren't handled correctly. #9186
It turns out that an inner static is only generated once. Hence if you have a generic function and the static somehow takes the generic type into account, the static will have the same address for all instantiations. Turns out this is a soundness problem with TLS:
$ rust run foo.rs
warning: no debug symbols in executable (-arch x86_64)
0x3ff0000000000000
1
Notably, the inner static foo has the same address each time the function foo is instantiated, hence k1 and k2 are the same value, so the first local_data::get is actually printing the hex representation of 1f.
Naturally this allows arbitrary coercion of types via TLS in safe code, this is a definite soundness issue.
You can't declare inner functions with the type parameters declared in outer functions, so perhaps the same rule should apply to statics as well? If not, then this is a codegen problem.
Activity
alexcrichton commentedon Sep 16, 2013
Nominating for the well-defined milestone (whether type parameters can appear in statics).
catamorphism commentedon Sep 19, 2013
accepted backwards-compatible
nikomatsakis commentedon Oct 10, 2013
I think that the generic types etc should not be in scope for the static -- that is, trans et al are doing the right thing, just not resolve
Forbid type parameters in inner statics
auto merge of #10189 : alexcrichton/rust/inner-statics, r=cmr
Auto merge of rust-lang#9187 - sgued:iter-once, r=flip1995
Merge rust-lang#9186