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

rustbuild: rustc's -Crpath does not work #32886

Closed
alexcrichton opened this issue Apr 11, 2016 · 3 comments · Fixed by #32903
Closed

rustbuild: rustc's -Crpath does not work #32886

alexcrichton opened this issue Apr 11, 2016 · 3 comments · Fixed by #32903
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@alexcrichton
Copy link
Member

The way the compiler emits rpath directives is relative to the output directory structure, but with rustbuild we output in one structure and then copy over into another. This means that -Crpath basically doesn't work, and things like LD_LIBRARY_PATH need to be specified manually.

This is a pretty tricky bug to fix as it will involve something like:

  • Glorious hacks in the src/bootstrap/rustc.rs script to manually pass rpath directives
  • Modifying the -C rpath argument to take some sort of value indicating what should be passed to the linker, this is an API change to the compiler, however.
  • Use some sort of tool to modify this metadata in the executable after it's generated

I'm somewhat leaning towards the "glorious hacks" method for now to get something working and avoid changing the compiler, but there are other reasons why we would want to modify the -C rpath argument to the compiler as well perhaps.

@alexcrichton alexcrichton added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Apr 11, 2016
@nagisa
Copy link
Member

nagisa commented Apr 11, 2016

Why relative rpaths are not enough? The libraries can still be found at ../lib/* relative to the binary.

@alexcrichton
Copy link
Member Author

The problem is that we generate relative rpaths with the expectation that the directory structure at compile time is the same as that at runtime. With the makefiles we do that but with rustbuild we just take whatever Cargo outputs and massage it into the directory structure we later ship.

For example:

$ readelf -d ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/deps:$ORIGIN/../../../stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib:/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib]

When compared to a normal build:

$ readelf -d ./x86_64-unknown-linux-gnu/stage1/bin/rustc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib]

Namely, the compiler relies on $ORIGIN/../lib to be in rpath on Linux, but it's not there (we'd have to specify that manually)

@brson
Copy link
Contributor

brson commented Apr 12, 2016

Maybe a new -Z flag?

Hacks also fine.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 12, 2016
This commit fixes the `--enable-rpath` configure flag in rustbuild to work
despite the compile-time directories being different than the runtime
directories. This unfortunately means that we can't use `-C rpath` out of the
box but hopefully the portability story here isn't too bad as
`src/librustc_back/rpath.rs` isn't *too* complicated.

Closes rust-lang#32886
bors added a commit that referenced this issue Apr 20, 2016
rustbuild: Fix --enable-rpath usage

This commit fixes the `--enable-rpath` configure flag in rustbuild to work
despite the compile-time directories being different than the runtime
directories. This unfortunately means that we can't use `-C rpath` out of the
box but hopefully the portability story here isn't too bad as
`src/librustc_back/rpath.rs` isn't *too* complicated.

Closes #32886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants