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

Non-ZST stop static is probably unsound #98

Open
GoldsteinE opened this issue Aug 19, 2024 · 3 comments
Open

Non-ZST stop static is probably unsound #98

GoldsteinE opened this issue Aug 19, 2024 · 3 comments

Comments

@GoldsteinE
Copy link

GoldsteinE commented Aug 19, 2024

Currently linkme generates an extern static of Element type for the “stop section” symbol:

#[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), link_name = #linux_section_stop)]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_name = #macho_section_stop)]
#[cfg_attr(target_os = "illumos", link_name = #illumos_section_stop)]
#[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), link_name = #bsd_section_stop)]
static LINKME_STOP: <#ty as #linkme_path::__private::Slice>::Element;

As pointed out in rust-lang/rust#46188 (comment), statics are considered always-dereferenceable, so it’s probably unsound. As the stop static is never actually read from, I think it could be made zero-sized to remove the unsoundness?

@RalfJung
Copy link

Yes, this is indeed unsound and should be made zero-sized.

LINKME_START is also unsound if the array ends up being empty.

@GoldsteinE
Copy link
Author

Yes, this is indeed unsound and should be made zero-sized.

Are zero-sized extern statics portable? I’m unsure because C/++ doesn’t have ZSTs, so I don’t know if LLVM portably supports it.

@RalfJung
Copy link

Yes they are. LLVM supports them just fine.

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

No branches or pull requests

2 participants