From b49fffc6546ecca49a4586afa55522c4d217996c Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 14 Feb 2024 14:25:10 +0100 Subject: [PATCH] fix: forcibly add rpath on macos and make some warning -> info (#637) --- src/linux/link.rs | 9 ++------- src/macos/link.rs | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/linux/link.rs b/src/linux/link.rs index 873ea120f..e8b97bdaa 100644 --- a/src/linux/link.rs +++ b/src/linux/link.rs @@ -205,7 +205,7 @@ impl Relinker for SharedObject { tracing::info!("rpath ({:?}) for {:?} found in allowlist", rpath, self.path); final_rpaths.push(rpath.clone()); } else { - tracing::warn!( + tracing::info!( "rpath ({:?}) is outside of prefix ({:?}) for {:?} - removing it", rpath, encoded_prefix, @@ -218,12 +218,7 @@ impl Relinker for SharedObject { final_rpaths = final_rpaths.into_iter().unique().collect(); // run builtin relink. if it fails, try patchelf - if let Err(e) = builtin_relink(&self.path, &final_rpaths) { - tracing::warn!( - "\n\nbuiltin relink failed for {}: {}. Please file an issue on Github!\n\n", - &self.path.display(), - e - ); + if builtin_relink(&self.path, &final_rpaths).is_err() { call_patchelf(&self.path, &final_rpaths, system_tools)?; } diff --git a/src/macos/link.rs b/src/macos/link.rs index bee7a98f9..bbd338bed 100644 --- a/src/macos/link.rs +++ b/src/macos/link.rs @@ -155,18 +155,24 @@ impl Relinker for Dylib { let mut changes = DylibChanges::default(); let mut modified = false; - let mut rpaths = self.rpaths.clone(); + let resolved_rpaths = self + .rpaths + .iter() + .map(|rpath| self.resolve_rpath(rpath, prefix, encoded_prefix)) + .collect::>(); + let mut new_rpaths = self.rpaths.clone(); for rpath in custom_rpaths.iter().rev() { let rpath = encoded_prefix.join(rpath); - if !rpaths.contains(&rpath) { - rpaths.insert(0, rpath); + if !resolved_rpaths.contains(&rpath) { + tracing::debug!("Adding rpath: {:?}", rpath); + new_rpaths.insert(0, rpath); } } let mut final_rpaths = Vec::new(); - for rpath in &self.rpaths { + for rpath in &new_rpaths { if rpath.starts_with("@loader_path") { let resolved = self.resolve_rpath(rpath, prefix, encoded_prefix); if resolved.starts_with(encoded_prefix) { @@ -253,12 +259,7 @@ impl Relinker for Dylib { if modified { // run builtin relink. if it fails, try install_name_tool - if let Err(e) = relink(&self.path, &changes) { - tracing::warn!( - "\n\nbuiltin relink failed for {}: {}. Please file an issue on Github!\n\n", - &self.path.display(), - e - ); + if relink(&self.path, &changes).is_err() { install_name_tool(&self.path, &changes, system_tools)?; } codesign(&self.path, system_tools)?;