Skip to content

rustc proxy may fail to invoke a rustc using shared libraries even when LD_LIBRARY_PATH is set. #9474

Open
@cr1901

Description

@cr1901

Problem
I have a custom Rust toolchain for development installed locally, call it rust-shared. I run it by setting LD_LIBRARY_PATH whenever I need to e.g. invoke the rustup cargo proxy. In the past, rustup has been able to call my custom Rust toolchain just fine, including locating its shared libraries. However, as of a recent release (I don't know which), I've found that rustup is inconsistent as to whether invoking my custom rustc will succeed or fail to find its shared libraries even when LD_LIBRARY_PATH has been set previously.

This behavior is inconsistent, but I've found a way to trigger the problem consistently via a contrived sequence.

Steps
Prerequisites

  1. Compile a rustc using a shared LLVM :).
  2. Add this toolchain to rustup via rustup toolchain link shared-rust /path/to/rust/root
  3. Create a sample crate, e.g. cargo init --lib testing
  4. Compile the crate using your shared toolchain: LD_LIBRARY_PATH=/path/to/llvm/libs cargo +shared-rust build. This should succeed.

rustup Seems To Find Shared Libraries Without LD_LIBRARY_PATH
Up to this point, all commands have expected behavior for me. Steps 5 and 6 have odd behavior to me.

  1. Run cargo +shared-rust clean once without setting LD_LIBRARY_PATH. This succeeds on my machine. I would not expect this to succeed because I didn't specify where the shared libraries for rustc live. I've accidentally forgotten to set LD_LIBRARY_PATH a number of times in normal usage :).
  2. Run cargo +shared-rust clean again without setting LD_LIBRARY_PATH. This fails with "error while loading shared libraries", which is the behavior I expected in step 5.

rustup Seems To Disregard LD_LIBRARY_PATH
If I rebuild the crate using +shared-rust at this point, compilation will still succeed. However, the next set of commands will result in shared-rust not finding its shared libraries.

  1. Run cargo +nightly build. This should succeed just fine.

  2. Run cargo +shared-rust clean once without setting LD_LIBRARY_PATH. This fails with "error while loading shared libraries" on my machine, as I would expect.

  3. We've already shown in step 4 that compilation with shared-rust works. However, when I attempt to run LD_LIBRARY_PATH=/path/to/llvm/libs cargo +shared-rust build or LD_LIBRARY_PATH=/path/to/llvm/libs cargo +shared-rust clean after running steps 7 and 8, I get the following error:

    william@xubuntu-dtrain:~/Projects/toolchains/testing$ LD_LIBRARY_PATH=$SHARED_LLVM_LIBS cargo +shared-rust build
    error: process didn't exit successfully: `rustc -vV` (exit status: 127)
    --- stderr
    /home/william/.rustup/toolchains/shared-rust/bin/rustc: error while loading shared libraries: libLLVMX86AsmParser.so.12: cannot open shared object file: No such file or directory
    

    Notice that I explicitly set LD_LIBRARY_PATH, yet rustc still can't find its shared libraries!

  4. Running cargo +nightly clean or cargo +nightly build makes compilation with shared-rust functional again, like in step 4.

Possible Solution(s)
I'm personally unsure how to debug this further. It seems that cargo +toolchain clean is the trigger to switch rustup's state between "will find the shared libraries" versus "will not find the shared libraries". I think the inconsistent behavior I saw in step 5 and 6 is related, as its perhaps "toggling" some internal state in rustup?

Running LD_LIBRARY_PATH=/path/to/llvm/libs cargo +shared-rust clean does not trigger the above behavior in steps 5 and beyond, unless we're already in the "rustc has decided not to find its shared libraries" state, like in step 9.

Notes

System Information:

william@xubuntu-dtrain:~/Projects/toolchains/rust$ uname -a
Linux xubuntu-dtrain 5.4.0-72-generic rust-lang/rustup#80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

william@xubuntu-dtrain:~/Projects/toolchains/rust$ rustup -V
rustup 1.24.1 (a01bd6b0d 2021-04-27)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.53.0-nightly (9d9c2c92b 2021-04-19)`

william@xubuntu-dtrain:~/Projects/toolchains/rust$ cargo +nightly -Vv
cargo 1.53.0-nightly (65d57e6f3 2021-04-04)
release: 1.53.0
commit-hash: 65d57e6f384c2317f76626eac116f683e2b63665
commit-date: 2021-04-04

william@xubuntu-dtrain:~/Projects/toolchains/rust$ rustc +nightly -Vv
rustc 1.53.0-nightly (9d9c2c92b 2021-04-19)
binary: rustc
commit-hash: 9d9c2c92b834c430f102ea96f65119e37320776e
commit-date: 2021-04-19
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

william@xubuntu-dtrain:~/Projects/toolchains/rust$ LD_LIBRARY_PATH=$SHARED_LLVM_LIBS rustc +shared-rust -Vv
rustc 1.54.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.54.0-dev
LLVM version: 12.0.0

shared-rust is rustc 1.54.0-dev, commit e5f83d24aee. I can provide cmake invocations for LLVM and the config.toml I used to build upon request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cachingArea: caching of dependencies, repositories, and build artifactsC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions