Skip to content

Commit

Permalink
Merge pull request rust-lang#18981 from Fabian-Gruenbichler/proc-macr…
Browse files Browse the repository at this point in the history
…o-srv-portability

proc-macro-srv: make usage of RTLD_DEEPBIND portable
  • Loading branch information
lnicola authored Jan 20, 2025
2 parents 141e53b + 5f4f6fb commit 618b913
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@ version = "0.0.0"
dependencies = [
"expect-test",
"intern",
"libc",
"libloading",
"memmap2",
"object 0.33.0",
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ doctest = false

[dependencies]
object.workspace = true
libc.workspace = true
libloading.workspace = true
memmap2.workspace = true

Expand Down
11 changes: 8 additions & 3 deletions src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> {

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

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

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

0 comments on commit 618b913

Please sign in to comment.