-
Notifications
You must be signed in to change notification settings - Fork 13.3k
librustc: Make addresses of immutable statics insignificant unless #14977
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
Conversation
`#[inline(never)]` is used. Closes rust-lang#8958. This can break some code that relied on the addresses of statics being distinct; add `#[inline(never)]` to the affected statics. [breaking-change]
Could you add a test for TLS? I think those may need to be // foo.rs
local_data_key!(foo: int);
fn set_foo() { foo.replace(Some(3)); }
fn get_foo() { *foo.get().unwrap() }
// bar.rs
extern crate foo;
fn main() {
foo::set_foo();
assert_eq!(foo::get_foo(), 3);
assert_eq!(*foo::foo.get().unwrap(), 3);
} I don't think that trans will inline the static for other reasons, but I don't think that there's an existing test for this. |
This PR is actually somewhat misleading, as it doesn't inline statics unless they're marked inline. Doing so by default exposed a plethora of linking and reachability bugs. :( I will file bugs and update the PR with comments specifying links to them. I think it's worth landing this with those changes just to get rid of address_insignificant, but more work is required to get to precisely where we want to be. |
Aren't there cases where we need 'immutable' statics to be significant, like where they contain interior mutability? Or in those cases do you just put them in mutable locations anyway? |
I guess you just put |
@brson: The address being insignificant is unrelated to mutability. It will never merge two globals with insignificant addresses if it would change program behaviour related to mutation. The only thing it does is assume that the address of the global is not being used in the application's logic, such as treating the address of globals as a valid unique identifier. |
There's no reason this couldn't also applied be to |
To re-enable this, use "rust-analyzer.runnables.problemMatcher": [ "$rustc", "$rust-panic" ], setting. closes: rust-lang#14977
feat: don't add panics to error jump list by default To re-enable this, use "rust-analyzer.runnables.problemMatcher": [ "$rustc", "$rust-panic" ], setting. closes: rust-lang#14977
#[inline(never)]
is used.Closes #8958.
This can break some code that relied on the addresses of statics
being distinct; add
#[inline(never)]
to the affected statics.[breaking-change]
r? @brson