-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rust 1.83.0 Sync with dyn Traits Regression #134014
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
Comments
What is the regression here? I don't think you mentioned what the problem actually is. |
Compilation happens fine but on execution a segfault happens, which didn't happen on previous versions. My bets are on: #128778 i am currently testing. |
@compiler-errors I Just made my lib oss, and updated issue to have code to recreate the bug. |
@IGN-Styly can you please update your report adding how do you build your library. That would help in reproducing more quickly the issue. Thank you. |
More specifically, can you also make your example self-contained, e.g. in a repo, so that we can confirm what we try to run is the same as what you try to run? |
yes will do asap |
Have Updated to include a repo to easily recreate the bug. |
Can reproduce, working on minimizing this. @rustbot label: -S-needs-repro -S-needs-info |
https://github.com/cyrgani/issue-134014 is a reduction that still keeps the original behavior of not segfaulting on 1.82 but on 1.83 and needs no external crates. However, removing the simple Additionally interesting is that the original unmodified code segfaults on 1.80 and below too, but not on 1.81. |
is it haunted?( i know my code is shitty but i haven't found a better solution) might be lifetime related, and if you dont mind ill add the minimized repro into the inial repo. |
I am removing the regression status because based on @cyrgani's report it seems very likely that what happened here is difficult to classify as a regression. |
@cyrgani's minimal repro from #134014 (comment) has UB by reading from a vtable that is located in a dynamic library that has been dynamically unloaded. The reduced example looks roughly like this:
where pub trait Task {}
pub struct FibTask {}
impl Task for FibTask {}
#[no_mangle]
pub fn run(api: &mut Option<Box<dyn Task>>) {
// here, the vtable is set to a pointer to a global variable in the `engine_core.so` file
*api = Some(Box::new(FibTask {}) as Box<dyn Task>);
} and fn main() {
let mut api: Option<Box<dyn Task> = None;
unsafe {
let lib = Library::open(); // load `engine_core.so`
let run: Symbol<unsafe extern "Rust" fn(reg: &mut EngineAPI)> = lib.get();
run(&mut api); // sets vtable pointer to a vtable located in `engine_core.so`
// `lib` goes out of scope, `engine_core.so` is unloaded
}
// `api` goes out of scope and the destructor of `dyn Task` is executed, which will attempt to load the
// `drop_in_place` function from the vtable, but here the vtable is a danging pointer, because the global
// variable that it points to has been freed by unloading `engine_core`! 💥
} This works in 1.82, because for some reason the Anyway, I'm inclined to say that this is probably not a compiler bug: When dynamic libraries are dynamically unloaded, then global variables (including vtables!) are suddenly not so global anymore, and it is the responsibility of the programmer to ensure that they aren't used after they have been freed. |
Thanks for the analysis @lukas-code and the reduction @cyrgani! I'm going to close this as not-a-compiler-bug. |
Code
Problematic Version: rustc 1.83.0 (90b35a6 2024-11-26)
Works on rust rustc 1.82.0 (f6e511e 2024-10-15)
Using my lib, here's a short example causing the segfault.
Issue Demo Requires Submodule!
SegFault
Rust 1.83 seems just leak. #128778 may be the cause but i can't seem to compile rust at all.
The text was updated successfully, but these errors were encountered: