rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.39k stars 340 forks source link

When building miri from source, all executions fail with `could not create LLVM TargetMachine` #2912

Closed icmccorm closed 5 months ago

icmccorm commented 1 year ago

When building Miri from source, we've encountered the following error:

error: could not create LLVM TargetMachine for triple: x86_64-unknown-linux-gnu: 
Unable to find target for this triple (no targets are registered)', src/setup.rs:36:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This occurs when running the test suite with ./miri test or running cargo miri <subcommand> in any context after ./miri install.

We've been able to reproduce this error after fully uninstalling the entirety of Rust, deleting and recloning the repository, and following the steps listed in CONTRIBUTING.md.

Only the stable toolchain (stable-x86_64-unknown-linux-gnu) is installed aside from miri. The machine we're using is running Arch (6/1 release). The native C/C++ compiler is clang 15.0.7. We're building a fork of miri, which is up to date with commit 1a80d1 on May 13th. We've seen the same error appear when running cargo miri setup in latest release of miri in nightly, but this error does not occur in that configuration when running cargo miri run or cargo miri test.

Are there any configuration options we should try and modify to fix this? Thanks!

saethlin commented 1 year ago

You seem to be pretty deep into this, if you'd like to have more of a conversation than GitHub accommodates we have a #miri stream in the Rust Zulip: https://rust-lang.zulipchat.com/

I can't figure out how to build your fork of Miri, the normal process complains:

error: No suitable version of LLVM was found system-wide or pointed
              to by LLVM_SYS_160_PREFIX.

I suspect the problem you're running into is related to the fact that the miri executable is always linked to librustc_driver which is always linked to libLLVM. I guess you're coordinating LLVM versions between your rustc_driver and inkwell? How?


And just to get this out of the way, I'm an Arch user, Miri development works great on Arch.

icmccorm commented 1 year ago

Thanks for your response!

The purpose of the fork is to explore executing foreign functions in Miri using the LLI interpreter. That's why we have the llvm-project submodule; we needed to add a few C API functions to LLVM's ExecutionEngine to be able to use Miri's memory operations in place of LLI's.

We set the LLVM_SYS_160_PREFIX variable to llvm-project/build. This build is only used for Miri, and shouldn't be installed anywhere else.

I'm pretty new to using the llvm toolchain, so I'm entirely unsure if our build of LLVM could be conflicting with what librustc_driver expects. I'm attempting to recreate this issue on a different machine, and I'll follow up on the Zulip channel!

RalfJung commented 1 year ago

So to be clear, if you are trying to build unpatched Miri, that works or doesn't work? Note that Miri needs a nightly version of Rust. The recommendation is to use ./miri toolchain to set up the right version.

If you want to change LLVM, you'll have to build a custom rustc and then build Miri against that. Otherwise you'll likely end up with 2 copies of LLVM, one in rustc and one in Miri, and I can't imagine that going well.

RalfJung commented 5 months ago

https://github.com/icmccorm/miri/ does not exist any more, and I don't think there's anything actionable for us here.