proc-macro-srv: make usage of RTLD_DEEPBIND portable
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 16 Jan 2025 15:34:12 +0000 (16:34 +0100)
committerFabian Grünbichler <debian@fabian.gruenbichler.email>
Thu, 24 Apr 2025 15:47:57 +0000 (17:47 +0200)
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).

Forwarded: https://github.com/rust-lang/rust/pull/135591

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Gbp-Pq: Topic behaviour
Gbp-Pq: Name proc-macro-srv-make-usage-of-RTLD_DEEPBIND-portable.patch

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

index 2323fdf5333ea8b4f36c592b5162e2ac1f8c7ed6..9e0a24d133ec1a1c6ad0d831c5c8bceef5e194e5 100644 (file)
@@ -1371,6 +1371,7 @@ version = "0.0.0"
 dependencies = [
  "expect-test",
  "intern",
+ "libc",
  "libloading",
  "memmap2",
  "object 0.33.0",
index 98385969459951056c3fdc00bc4527384389588f..c0881b08e1029506c2c8c24d0845045d0888bd5d 100644 (file)
@@ -14,6 +14,7 @@ doctest = false
 
 [dependencies]
 object.workspace = true
+libc.workspace = true
 libloading.workspace = true
 memmap2.workspace = true
 
index 26f6af84aaeb10463eb5fc570932bcc4ed140a98..4599e655f636b5ff421c966182cd0d3974802c55 100644 (file)
@@ -59,11 +59,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()) }
 }