-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
As described in oneapi-src/unified-runtime#803, the use of RTLD_DEEPBIND in dylib.rs [1] can cause rust-analyzer-proc-macro-srv to crash when a custom memory allocator is preloaded. The LD_PRELOAD environment variable is not propagated from Visual Studio Code to the rust-analyzer-proc-macro-srv process that eventually gets spawned, so on my machine, this issue only manifests when a custom allocator is specified in /etc/ld.so.preload.
Since it looks like the RTLD_DEEPBIND flag was deliberately added to address an issue, I would assume nothing can be done about this, and this issue can just serve as documentation.
Some of the error messages relating to this issue that I've seen:
proc-macro panicked: proc-macro server did not respond with data: proc-macro server did not respond with data
munmap_chunk(): invalid pointer
proc-macro server exited with signal: 6 (SIGABRT) (core dumped)
Depending on the custom allocator that is preloaded, these errors can vary. I think I also saw a SIGSEGV.
[1]
rust-analyzer/crates/proc-macro-srv/src/dylib.rs
Lines 51 to 75 in c54a827
| /// Loads dynamic library in platform dependent manner. | |
| /// | |
| /// For unix, you have to use RTLD_DEEPBIND flag to escape problems described | |
| /// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample) | |
| /// and [here](https://github.com/rust-lang/rust/issues/60593). | |
| /// | |
| /// Usage of RTLD_DEEPBIND | |
| /// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample/issues/1) | |
| /// | |
| /// It seems that on Windows that behaviour is default, so we do nothing in that case. | |
| #[cfg(windows)] | |
| fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> { | |
| unsafe { Library::new(file) } | |
| } | |
| #[cfg(unix)] | |
| fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> { | |
| use libloading::os::unix::Library as UnixLibrary; | |
| use std::os::raw::c_int; | |
| const RTLD_NOW: c_int = 0x00002; | |
| const RTLD_DEEPBIND: c_int = 0x00008; | |
| unsafe { UnixLibrary::open(Some(file), RTLD_NOW | RTLD_DEEPBIND).map(|lib| lib.into()) } | |
| } |