-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
dlclose() does not behave properly on Mac #47974
Comments
Your main.rs includes |
Ah, that's a good call. Unfortunately, it looks like removing |
Can you capture any information about the segfault? Perhaps a debugger backtrace? |
Likely a duplicate of #28794. |
A quick look at your Rust code reveals it invoking undefined behaviour. You use CString to null-terminate your literals, however This could also be a cause for different behaviour. |
Here's what the debugger says when I run it:
And the full backtrace:
|
That's not true -- But that does highlight to me that the other The other Generally speaking, allocating in one domain and freeing in another is fraught with danger. |
I have a somewhat similar problem with my library, so I tried the repository above. I ran it with It (reloading) actually worked correctly.
When I changed it to
This is quite weird, since the problem I have with my library is the opposite: unloading worked in Sierra, but stopped working in High Sierra (regardless of |
I'm experiencing this problem as well, on High Sierra (10.13.4). I noticed the following: When
When I try the same exact thing again with an identical cdylib written in Rust, To my knowledge, If that's the case, then the question is, where do these pointers come from? If not, what the hell else is going on? |
Ok, I think I found something - I tried two more things with my Rust cdylib:
|
There’s a recent change in OS X that has "improved" |
Historically, thread local storage (__thread) is what causes rust dylibs to not get unloaded or generally not work right with I don’t know of a full list though. |
This is very likely to be related to the issues described in #88737 and #88737 (comment). Fixing this will likely not result in the behavior the user wants though -- the fact that dlclose works anywhere is kind of a bug, it failing to unload is actually macOS doing the right thing. In general you should not dlclose rust libraries that use libstd. There's no way for us to support this on many targets (and we don't quite support it correctly on all the platforms where we could, which is why sometimes it will unload, which can be unsound). Unfortunately, dlclose is just not really coherent in programs which have thread local storage (in particular if destructors to be run on that TLS data). See that issue for an explanation of why. |
Musl libc doesn't even implement dlclose at all. It returns without doing anything. |
This report will reference this repository which reproduces the issue: https://github.com/dradtke/rust-dylib-issues
The Issue
The repository contains an application library, built as a
dylib
, and two example main programs, one in Rust and one in C. Each main application runs in a loop, loading the library withdlopen()
, calling a method, and then closing withdlclose()
. The expectation is that any changes to the library will be picked up immediately by the main application when it is recompiled.However, the behavior between the two programs differs. If I run the two main programs side-by-side, then make a change to the returned message and recompile the library, only the C program immediately reflects the change. The Rust main program won't reflect any changes until it is fully restarted.
It appears that this is Mac-specific behavior. When the same test is run on Debian, the two main programs behave identically.
The Environment
Operating System: macOS Sierra 10.12.6
Rust Version:
C Compiler:
The text was updated successfully, but these errors were encountered: