Skip to content

Commit c8a5a8d

Browse files
Fabian-GruenbichlerFabian Grünbichler
authored and
Fabian Grünbichler
committed
proc-macro-srv: make usage of RTLD_DEEPBIND portable
the constant is wrong on some platforms (e.g., on mips64el it's 0x10, and 0x8 is RTLD_NOLOAD which makes all this functionality broken), the libc crate takes care of those differences for us. fallback to old hard-coded value for non-glibc environments (which might or might not of DEEPBIND support). Signed-off-by: Fabian Grünbichler <[email protected]>
1 parent d8a6409 commit c8a5a8d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/tools/rust-analyzer/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ version = "0.0.0"
13711371
dependencies = [
13721372
"expect-test",
13731373
"intern",
1374+
"libc",
13741375
"libloading",
13751376
"memmap2",
13761377
"object 0.33.0",

src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ doctest = false
1414

1515
[dependencies]
1616
object.workspace = true
17+
libc.workspace = true
1718
libloading.workspace = true
1819
memmap2.workspace = true
1920

src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> {
2828

2929
#[cfg(unix)]
3030
fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> {
31+
// not defined by POSIX, different values on mips vs other targets
32+
#[cfg(target_env = "gnu")]
33+
use libc::RTLD_DEEPBIND;
3134
use libloading::os::unix::Library as UnixLibrary;
32-
use std::os::raw::c_int;
35+
// defined by POSIX
36+
use libloading::os::unix::RTLD_NOW;
3337

34-
const RTLD_NOW: c_int = 0x00002;
35-
const RTLD_DEEPBIND: c_int = 0x00008;
38+
// MUSL and bionic don't have it..
39+
#[cfg(not(target_env = "gnu"))]
40+
const RTLD_DEEPBIND: std::os::raw::c_int = 0x0;
3641

3742
unsafe { UnixLibrary::open(Some(file), RTLD_NOW | RTLD_DEEPBIND).map(|lib| lib.into()) }
3843
}

0 commit comments

Comments
 (0)