-
Notifications
You must be signed in to change notification settings - Fork 346
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
Rustup for panic changes #1048
Rustup for panic changes #1048
Conversation
Do we need to wait for the nightly? |
No but the rustc PR hasn't landed yet ;) |
This gets Miri working again, but doesn't actually implement unwinding
18bd5f7
to
cf5b53e
Compare
@RalfJung: Updated |
@Aaron1011 now that your main PR landed (:tada: ), could you update the |
@bors r+ |
📌 Commit 7bb3052 has been approved by |
Rustup for panic changes This gets Miri working again, but doesn't actually implement unwinding
💔 Test failed - status-appveyor |
This seems to be caused by the fact that we're trying to build actual bytecode for our custom Specifically, we end up missing |
We only need crate metadata and MIR, not the built object files, so this allows us to skip unecessary work when building `libstd`. It also prevents us from trying to codegen the `try` panicking intrinsic, which assumes that `libpanic_unwind` is being compiled for the target platform. We built `libpanic_unwind` with `cfg(miri)`, which may invalidate these assumptions (e.g. the `eh_catch_typeinfo` lang item is no longer defined).
I just discovered This should cause us to skip codegen entirely, thus avoiding the Windows-specific panic intrinsic codegen issue. |
@RalfJung: This should be ready to merge. |
Nice catch! Does that mean you can remove the @bors r+ |
📌 Commit c6d3179 has been approved by |
Rustup for panic changes This gets Miri working again, but doesn't actually implement unwinding
💔 Test failed - status-appveyor |
@bors delegate+ @Aaron1011 with this you can now issue try builds if you want to test/debug a bit more. Please don't |
✌️ @Aaron1011 can now approve this pull request |
This works fine for me on Linux - there must be a difference in how linking and/or codegen happens on Windows. |
This reverts commit c6d3179.
This gives us crate metadata without running any codegen
@bors try |
Rustup for panic changes This gets Miri working again, but doesn't actually implement unwinding
💔 Test failed - status-appveyor |
@bors try |
Rustup for panic changes This gets Miri working again, but doesn't actually implement unwinding
☀️ Try build successful - checks-travis, status-appveyor |
This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048
This PR has evolved significantly from what was originally a simple update to the latest The issuePrior to the Rustc panic changes in rust-lang/rust#60026 being merged, Miri's custom With rust-lang/rust#60026 merged, there is a significant difference between a On Linux, this works fine: we are able to run all of our tests, and On Windows (and maybe any MSVC target), it's a different story. During codegen, we attempt to lookup the The root causeUp until now, Miri has been using Xargo to build its custom At first, I thought that these compiled libraries were never being used. However, it turns out that This doesn't appear to have cauesd any problems up until now (though it's certainly pretty weird). However, this approach is no longer possible with the most recent The solutionThe quickest solution for this issue, as @RalfJung mentioned, would be make However, this is not an idea long-term solution. First of all, we are still left with the problem of build dependencies being unable to panic. Most users will probably not run into this - but when they do, it will be extremely frustrating, since a build script will appear to abruptly segfault without any error message. Second, nothing prevents the compiler from adding other target-specific lang items, or making other assumptions about exports from The long-term solution is to switch to using However, this turned out to be more complicated than I anticipated. There are several moving parts here:
Currently,
This is complicated by the fact that we currently run To work around this issue, I've added a hack to serialize arguments to an environment variable. When we compile the final crate, we deserialize these arguments from the environment variable, and manually pass them to the
This is by far the trickiest part of this entire PR. When Cargo invokes our
Handles these three cases ensures that build dependencies are built using the normal platform Unfortunately, distinguishing between these three cases is a huge pain. I'm currently relying on the following tricks:
The However, this fails to distinguish between a
This trick relies on the fact that we are using When we are building normal dependencies, the By checking for the presence of Adding more information to CargoWhile I believe assumptions behind the above Cargo hacks are fairly sound, this is not really a viable long-term solution. For example, Cargo could choose to stop passing the Ideally, Cargo would set an environment variable to let us know which of the three cases we are in - target crate, build dependency, or normal dependency. I'm currently working on a PR that does just that. ConclusionI think our best path forward is to:
|
// that `cargo check` has exactly the behavior that we want: | ||
// it emits crate metadata (including MIR) without running any | ||
// codegen. | ||
command.arg("check").arg("-q"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check
vs build
here just affects the empty "fake crate" that we have for xargo, right? This comment here should be attached to the cargo_mode
line above, not the command invocation down here.
prefixed_args += &arg.len().to_string(); | ||
prefixed_args.push(';'); | ||
prefixed_args += &arg; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When inventing a serialization scheme, at the very least please put this into separate functions.
Though maybe at this point we should just use serde and serialize this as JSON, or so?
@Aaron1011 thanks for the detailed write-up! This is a lot. I am somewhat concerned about the amount of hacks that are needed, given in particular that this is to avoid other hacks... one core problem seems to be that cargo is not very "instrumentable". I have heard plans before to improve that; this might be useful input for that discussion. Cc @ehuss. It would be good to be able to work on this "in due time", without the pressure of Miri master being broken and, worse, without blocking any other update of Miri to sync it with rustc changes. So I think short-term I'd prefer either a less invasive hack, such as exposing the required lang items even with For a "less hacky"/"more proper" solution, I think we should have a "project issue" here in the Miri repo, with the project being something like "avoid codegen for Miri-interpreted crates". This has plenty of benefits as you said, but it is also non-trivial. Most of your excellent summary should be put into that project description. I have some thoughts on the details of that approach, but that project issue seems like a better place for discussion then, so I will hold off on these for now. Does that seem like a reasonable plan? I will prepare a rustc PR along the lines of what I suggested earlier. EDIT: rust-lang/rust#66441 |
libpanic_unwind for Miri: make sure we have the SEH lang items when needed r? @oli-obk @alexcrichton This is required to fix the Miri toolstate. Turns out rustc complains when doing codegen for MSVC and these lang items do not exist. For now `cfg(miri)` needs to still be able to codegen (we [plan to change that](rust-lang/miri#1048 (comment)) but that's a larger project requiring improvements to xargo and maybe also cargo; that should not block fixing the toolstate). Yes, this is a hack, but it is inside `cfg(miri)` so I hope this is okay. Cc @Aaron1011
libpanic_unwind for Miri: make sure we have the SEH lang items when needed r? @oli-obk @alexcrichton This is required to fix the Miri toolstate. Turns out rustc complains when doing codegen for MSVC and these lang items do not exist. For now `cfg(miri)` needs to still be able to codegen (we [plan to change that](rust-lang/miri#1048 (comment)) but that's a larger project requiring improvements to xargo and maybe also cargo; that should not block fixing the toolstate). Yes, this is a hack, but it is inside `cfg(miri)` so I hope this is okay. Cc @Aaron1011
This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048
This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048
267: Add `xargo-check` command r=RalfJung a=Aaron1011 This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048 Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
267: Add `xargo-check` command r=RalfJung a=Aaron1011 This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048 Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
267: Add `xargo-check` command r=RalfJung a=Aaron1011 This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048 Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
Fixes rust-lang#1057 I'm using my original approach from PR rust-lang#1048. Ideally, we would distinguish between build-deps/dependencies/'final crate' via a different approach (e.g. the target directory). However, I haven't been able to get that to work just yet. However, everything should be working with the approach I'm using. At a minimum, we can use this PR to verify that everything works as expected when we don't actually produce native build outputs.
Fixes rust-lang#1057 I'm using my original approach from PR rust-lang#1048. Ideally, we would distinguish between build-deps/dependencies/'final crate' via a different approach (e.g. the target directory). However, I haven't been able to get that to work just yet. However, everything should be working with the approach I'm using. At a minimum, we can use this PR to verify that everything works as expected when we don't actually produce native build outputs.
Fixes rust-lang#1057 I'm using my original approach from PR rust-lang#1048. Ideally, we would distinguish between build-deps/dependencies/'final crate' via a different approach (e.g. the target directory). However, I haven't been able to get that to work just yet. However, everything should be working with the approach I'm using. At a minimum, we can use this PR to verify that everything works as expected when we don't actually produce native build outputs.
Use 'cargo check' to build the sysroot and target crate Fixes #1057 I'm using my original approach from PR #1048. Ideally, we would distinguish between build-deps/dependencies/'final crate' via a different approach (e.g. the target directory). However, I haven't been able to get that to work just yet. However, everything should be working with the approach I'm using. At a minimum, we can use this PR to verify that everything works as expected when we don't actually produce native build outputs.
Use 'cargo check' to build the sysroot and target crate Fixes #1057 I'm using my original approach from PR #1048. Ideally, we would distinguish between build-deps/dependencies/'final crate' via a different approach (e.g. the target directory). However, I haven't been able to get that to work just yet. However, everything should be working with the approach I'm using. At a minimum, we can use this PR to verify that everything works as expected when we don't actually produce native build outputs.
This gets Miri working again, but doesn't actually implement unwinding