Skip to content

-C rpath does not work on OS X #17219

Closed
Closed
@comex

Description

@comex

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-macosOperating system: macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions