Skip to content

Commit

Permalink
fix: prevent macOS from linking to old libs
Browse files Browse the repository at this point in the history
macOS seems to use a shared library's install_name when opening a shared
library. Previously we stored the full path, which caused the OS to
always point to the same file even when copies were made.
  • Loading branch information
Wodann committed Apr 19, 2020
1 parent 3c35158 commit 32b8bf2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/mun_codegen/src/code_gen/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ impl Linker for Ld64Linker {
.to_str()
.ok_or_else(|| LinkerError::PathError(path.to_owned()))?;

let filename_str = path
.file_name()
.expect("path must have a filename")
.to_str()
.ok_or_else(|| LinkerError::PathError(path.to_owned()))?;

// Link as dynamic library
self.args.push("-dylib".to_owned());
self.args.push("-lsystem".to_owned());
Expand All @@ -119,6 +125,11 @@ impl Linker for Ld64Linker {
self.args.push("-o".to_owned());
self.args.push(path_str.to_owned());

// Ensure that the `install_name` is not a full path as it is used as a unique identifier on
// MacOS
self.args.push("-install_name".to_owned());
self.args.push(filename_str.to_owned());

Ok(())
}

Expand Down

0 comments on commit 32b8bf2

Please sign in to comment.