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

-C rpath does not work on OS X #17219

Closed
comex opened this issue Sep 13, 2014 · 5 comments
Closed

-C rpath does not work on OS X #17219

comex opened this issue Sep 13, 2014 · 5 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-macos Operating system: macOS

Comments

@comex
Copy link
Contributor

comex commented Sep 13, 2014

With just rustc -C prefer-dynamic test.rs, I get a binary with load commands that look like this:

          cmd LC_LOAD_DYLIB
      cmdsize 112
         name x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 0.0.0
compatibility version 0.0.0

This is not an absolute path, and in fact does not even exist - since I downloaded rustc from a nightly, the real path is /Users/comex/rust-nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.dylib. The pre-install path comes from that library's LC_ID_DYLIB.

The binary does not run, but so far that's expected behavior and setting DYLD_LIBRARY_PATH works. However, as far as I can tell, -C rpath is supposed to make a binary with the correct path built in. It does not. It adds a -rpath entry, but on OS X, -rpath is documented as follows:

     -rpath path
                 Add path to the runpath search path list for image being created.  At runtime, dyld uses the runpath when searching for dylibs whose load path begins with
                 @rpath/.

While LC_RPATH shows up in the binary, the LC_LOAD_DYLIB load paths are the same old x86_64-apple-darwin/etc/etc, so the rpath is not used and nothing changes.

@Nashenas88
Copy link
Contributor

I'm running into this when trying to build something with the rustc_private feature. I'm using multirust, and it's currently bound to the nightly toolchain. I have the exact same output as @comex. It's impossible to proceed without rebuilding rustc from scratch.

@durka
Copy link
Contributor

durka commented Aug 17, 2015

Confirmed here as well. It happens when trying to build rustbook as well as other things. Somehow cargo run is able to paper over the bogus library paths, but it would be nice if the binary worked on its own.

@steveklabnik
Copy link
Member

Triage: I do not have a mac, so I cannot try to reproduce again today. Anyone?

@durka
Copy link
Contributor

durka commented Feb 7, 2017

I don't know how to get output like what @comex pasted with the load commands. However, I have this:

Alexs-MacBook-Air-3:rust alex$ cat xx.rs
fn main() {
    println!("hi");
}

Alexs-MacBook-Air-3:rust alex$ rustc -C prefer-dynamic xx.rs
Alexs-MacBook-Air-3:rust alex$ ./xx
dyld: Library not loaded: @rpath/libstd-a38e14755045bae4.dylib
  Referenced from: /Users/alex/Programming/rust/rust/./xx
  Reason: image not found
Trace/BPT trap: 5
Alexs-MacBook-Air-3:rust alex$ otool -L xx
xx:
	@rpath/libstd-a38e14755045bae4.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
Alexs-MacBook-Air-3:rust alex$ rustc -C prefer-dynamic -C rpath xx.rs
Alexs-MacBook-Air-3:rust alex$ ./xx
hi
Alexs-MacBook-Air-3:rust alex$ otool -L xx
xx:
	@rpath/libstd-a38e14755045bae4.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

That is, -C prefer-dynamic produces a broken binary, -C rpath fixes it, but they seem to be referring to the same libs as far as otool is concerned.

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. A-linkage Area: linking into static, shared libraries and binaries labels Jul 22, 2017
@comex
Copy link
Contributor Author

comex commented Oct 25, 2019

There is still weirdness in this area, but -C rpath does have an effect now, so closing.

@comex comex closed this as completed Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-macos Operating system: macOS
Projects
None yet
Development

No branches or pull requests

6 participants