Skip to content

Commit

Permalink
fix: forcibly add rpath on macos and make some warning -> info (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Feb 14, 2024
1 parent 93b9efe commit b49fffc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
9 changes: 2 additions & 7 deletions src/linux/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)?;
}

Expand Down
21 changes: 11 additions & 10 deletions src/macos/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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) {
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit b49fffc

Please sign in to comment.