rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.81k stars 12.66k forks source link

llvm-tools/llvm-tools-preview is installed in a target-specific directory instead of target-agnostic directory #119202

Open briansmith opened 10 months ago

briansmith commented 10 months ago

On an x86-64 Linux system, I ran:

$ rustup toolchain install --component=llvm-tools-preview stable
$ find ~/.rustup -name "llvm-nm"
/home/whatever/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-nm

The problem: The LLVM tools are installed at in the target-specific directory library directory "lib/rustlib/x86_64-unknown-linux-gnu/" under the toolchain directory ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu. Instead they should be installed directly in the toolchain directory, so that the result above would be ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/llvm-nm.

When originally announced at https://internals.rust-lang.org/t/llvm-tools-a-new-rustup-component-for-binary-inspection-objdump-nm-size-and-profiling-profdata/7830, it was said that:

The main advantage of these LLVM tools is that they support all the architectures that the Rust compiler supports. For example, llvm-objdump con disassemble object files containing machine code for architectures ranging from ARM Cortex-M (THUMB) all the way to WASM (*) and x86_64. OTOH, if you were to use the GNU tools you would have to install one set of binutils for each architecture you are working with (e.g. avr-binutils, arm-none-eabi-binutils, msp430-elf-binutils, etc.).

Thus, it seems to me that the tools should be per-host, not per-target.

bjorn3 commented 10 months ago

I believe the reason it is in the target-specific directory is to avoid conflicts with a system install of the respective tools. With rustup the rust version would take precedence if in the target-agnostic directory, while for a system installation it would overwrite the system installation which will cause the change to be reverted again on the next update of LLVM by the distro. Note that we actually always install them in the directory with a name matching the host architecture on which the tools can actually run. So for an x86_64-unknown-linux-gnu toolchain you will always find them in $SYSROOT/lib/rustlib/x86_64-unknown-linux-gnu/bin even if you are cross-compiling to for example aarch64-apple-darwin.