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

rust-analyzer-proc-macro-srv crashes when a custom allocator is preloaded #18098

Open
andrewliebenow opened this issue Sep 11, 2024 · 1 comment
Labels
A-proc-macro proc macro C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@andrewliebenow
Copy link

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]

/// 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()) }
}

@andrewliebenow andrewliebenow added the C-bug Category: bug label Sep 11, 2024
@Veykril Veykril added the A-proc-macro proc macro label Sep 11, 2024
@Veykril
Copy link
Member

Veykril commented Sep 11, 2024

It says right on the comment why, following the links in there it seems that this is a problem with the proc-macro bridge implementation, so there isn't really much we can do about that right now

@Veykril Veykril added S-unactionable Issue requires feedback, design decisions or is blocked on other work C-support Category: support questions and removed C-bug Category: bug labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

2 participants