Skip to content
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

What are our guarantees regarding pointer identity on consts #406

Open
chorman0773 opened this issue May 23, 2023 · 8 comments
Open

What are our guarantees regarding pointer identity on consts #406

chorman0773 opened this issue May 23, 2023 · 8 comments
Labels
A-ptr-eq Topic: pointer equality

Comments

@chorman0773
Copy link
Contributor

We don't currently guarantee that pub const FOO: &'static u32 = &0; has a stable address (same with string literals). This has had some suprising results in the past (I cannot find the miri issue I was looking for). What, if anything, do we want to guarantee with respect to this (and code like pub const FOO: *const u32 = &0 as *const u32;)

@RalfJung
Copy link
Member

This is not just for promoteds, this is generally about addresses of constants.

@RalfJung RalfJung changed the title What are our guarantees surrounding Promoted Constants in consts What are our guarantees regarding pointer identity on consts May 24, 2023
@RalfJung RalfJung added the A-ptr-eq Topic: pointer equality label May 24, 2023
@RalfJung
Copy link
Member

This is also tracked in #239 (not sure how fine-grained we want to go with issues here)

@chorman0773
Copy link
Contributor Author

chorman0773 commented May 24, 2023 via email

@chorman0773
Copy link
Contributor Author

FWIW, lccc's abi gives an external name to the address of a constant iff it is part of the initializer of a const, which gives it a stable and unique address (except cross FLT, when a generic const is involved b/c windows).

@bjorn3
Copy link
Member

bjorn3 commented May 24, 2023

cg_clif intentionally duplicates anonymous const allocations between mono items (functions, statics, global asm) to allow codegening every mono item independently even within a single cgu. For non-generic consts it did be possible to give them a unique name and treat them as separate mono items, but requiring that generic consts have to be deduplicated has the same issues as for generic statics.

@chorman0773
Copy link
Contributor Author

chorman0773 commented May 24, 2023 via email

@bjorn3
Copy link
Member

bjorn3 commented May 24, 2023

What would the symbol name of the linkonce group be? Rust currently doesn't expose any stable id for anonymous allocations. It only has an AllocId which is different across multiple compiler sessions. For statics tcx.global_alloc(alloc_id) returns a DefId, but for anonymous allocations it directly returns the allocation data itself. If this fixed, it should be quite easy to implement by handling it like a static with a mono item and fixed symbol name, even without linkonce.

@chorman0773
Copy link
Contributor Author

chorman0773 commented May 24, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ptr-eq Topic: pointer equality
Projects
None yet
Development

No branches or pull requests

3 participants