Skip to content

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

Merged
merged 1 commit into from
Jun 17, 2014

Conversation

pcwalton
Copy link
Contributor

#[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

`#[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]
@alexcrichton
Copy link
Member

Could you add a test for TLS? I think those may need to be inline(never).

// 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.

@pcwalton
Copy link
Contributor Author

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.

@brson
Copy link
Contributor

brson commented Jun 17, 2014

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?

@brson
Copy link
Contributor

brson commented Jun 17, 2014

I guess you just put #[inline(never)] on them.

bors added a commit that referenced this pull request Jun 17, 2014
…brson

`#[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
@bors bors closed this Jun 17, 2014
@bors bors merged commit cad760b into rust-lang:master Jun 17, 2014
@thestinger
Copy link
Contributor

@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.

@thestinger
Copy link
Contributor

There's no reason this couldn't also applied be to static mut too, it just wouldn't be very useful because LLVM would only be able to merge the globals if they were never actually written to.

@pcwalton pcwalton deleted the address-insignificant-reform branch June 17, 2014 22:50
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2023
To re-enable this, use

    "rust-analyzer.runnables.problemMatcher": [
        "$rustc",
        "$rust-panic"
    ],

setting.

closes: rust-lang#14977
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decide whether global addresses should be significant by default
5 participants