Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DYLD_FALLBACK_LIBRARY_PATH for dylib_path_envvar on macOS #1752

Merged
merged 1 commit into from Apr 19, 2019

Conversation

Projects
None yet
4 participants
@glandium
Copy link
Contributor

glandium commented Apr 11, 2019

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

@ehuss

This comment has been minimized.

Copy link

ehuss commented Apr 11, 2019

I've been meaning to look at making this change, but never got around to it. This also has a benefit that it improves performance on MacOS 10.13 and newer, though that probably doesn't affect most people.

You have to be careful when setting DYLD_FALLBACK_LIBRARY_PATH because it overrides the default of $(HOME)/lib:/usr/local/lib:/lib:/usr/lib. That means anything that was relying on that default fallback will now fail. See rust-lang/cargo#6625. I think this will probably need to retain the default and append to it.

I'm also curious if setting the library path is necessary at all. rustc uses @rpath, so it shouldn't have trouble finding its own libraries. Alex mentioned it might be due to plugins here. Probably not worth removing, but it would be good to know why this is set at all.

Testing this will be difficult. rustup doesn't really have a nightly testing channel, so it's difficult to pre-flight a change like this. It'll be tough to know who it will affect.

@kinnison

This comment has been minimized.

Copy link
Collaborator

kinnison commented Apr 12, 2019

@ehuss Does that mean you'd recommend we wait to merge this until it can be amended, or should we consider merging this anyway and perhaps opening an issue to look at doing the append approach?

@ehuss

This comment has been minimized.

Copy link

ehuss commented Apr 12, 2019

I think it would be safer to include the defaults.

@kinnison

This comment has been minimized.

Copy link
Collaborator

kinnison commented Apr 12, 2019

@glandium Are you able to amend the PR according to @ehuss 's suggestion?

@glandium

This comment has been minimized.

Copy link
Contributor Author

glandium commented Apr 13, 2019

I'll get to it next week.

@kinnison

This comment has been minimized.

Copy link
Collaborator

kinnison commented Apr 14, 2019

@glandium Awesome. Thank you for doing this.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 14, 2019

☔️ The latest upstream changes (presumably #1754) made this pull request unmergeable. Please resolve the merge conflicts.

@kinnison kinnison added this to the 1.18.0 milestone Apr 14, 2019

@glandium glandium force-pushed the glandium:master branch from 4739361 to 8a527c4 Apr 16, 2019

Use DYLD_FALLBACK_LIBRARY_PATH for dylib_path_envvar on macOS
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

See also rust-lang/cargo#6625 and
rust-lang/cargo#6625
@kinnison
Copy link
Collaborator

kinnison left a comment

Thank you @glandium for your work here. LGTM.

@kinnison kinnison merged commit 438bc19 into rust-lang:master Apr 19, 2019

1 check passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.