Skip to content

Commit

Permalink
Use DYLD_FALLBACK_LIBRARY_PATH for dylib_path_envvar on macOS
Browse files Browse the repository at this point in the history
When loading and linking a dynamic library or bundle, dlopen
searches in LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PWD, and
DYLD_FALLBACK_LIBRARY_PATH.
In the Mach-O format, a dynamic library has an "install path."
Clients linking against the library record this path, and the
dynamic linker, dyld, uses it to locate the library.
dyld searches DYLD_LIBRARY_PATH *before* the install path.
dyld searches DYLD_FALLBACK_LIBRARY_PATH only if it cannot
find the library in the install path.
Setting DYLD_LIBRARY_PATH can easily have unintended
consequences.

See https://users.rust-lang.org/t/subprocess-and-dynamic-library-linking-problem-interaction/7873/10
See https://trac.macports.org/ticket/57692
See https://bugzilla.mozilla.org/show_bug.cgi?id=1536486

This is the same change as was applied to cargo in
rust-lang/cargo#6355
  • Loading branch information
glandium committed Apr 11, 2019
1 parent c954c57 commit 4739361
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,18 @@ impl<'a> Toolchain<'a> {
}
#[cfg(target_os = "macos")]
mod sysenv {
pub const LOADER_PATH: &'static str = "DYLD_LIBRARY_PATH";
// When loading and linking a dynamic library or bundle, dlopen
// searches in LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PWD, and
// DYLD_FALLBACK_LIBRARY_PATH.
// In the Mach-O format, a dynamic library has an "install path."
// Clients linking against the library record this path, and the
// dynamic linker, dyld, uses it to locate the library.
// dyld searches DYLD_LIBRARY_PATH *before* the install path.
// dyld searches DYLD_FALLBACK_LIBRARY_PATH only if it cannot
// find the library in the install path.
// Setting DYLD_LIBRARY_PATH can easily have unintended
// consequences.
pub const LOADER_PATH: &'static str = "DYLD_FALLBACK_LIBRARY_PATH";
}
env_var::prepend_path(sysenv::LOADER_PATH, vec![new_path.clone()], cmd);

Expand Down

0 comments on commit 4739361

Please sign in to comment.