Skip to content

rpath is incorrect when crate links against compiler libraries #58343

Open
@RalfJung

Description

@RalfJung

When compiling something like Miri that links against librustc and other compiler libraries, even with rpath = true in my Cargo.toml, the resulting binary does not work without LD_LIBRARY_PATH:

$ target/release/miri
target/release/miri: error while loading shared libraries: librustc_driver-e8ad12ee87dce48b.so: cannot open shared object file: No such file or directory

Looking at the bianary, I noticed a RUNPATH and no RPATH and learned that RPATH got deprecated in favor of RUNPATH:

$ readelf -d target/release/miri | egrep 'R(UN)?PATH'
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../../../../rustc.2/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/r/src/rust/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib]

However, after some research, two things strike me about this:

  • First of all, the number of "../" is wrong -- there is one too much. Starting at the directory containing the binary (~/src/rust/miri/target/release), going up 4 times leads to ~/src, while the rustc.2 directory is at ~/src/rust/rustc.2.

  • Second, according to this, the binary needs to have the ORIGIN flag set for $ORIGIN to actually work, and that flag is not set: I verified this locally and that flag does not seem to be needed.

    $ readelf -d target/release/miri | egrep -i flag
     0x000000000000001e (FLAGS)              BIND_NOW
     0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
    

I am also really surprised that it encodes the path to the sysroot as relative to the binary, but the path to other libs compiled in the same crate as absolute to the binary. Shouldn't it rather be the other way around?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-miriArea: The miri toolC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions