-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
illegal hardware instruction when using ffi+luajit on beta and nightly >=2021-03-11 #83541
Comments
You have declared run_me as a C ABI function, which Rust currently does not allow to unwind. However, LuaJIT is throwing an exception. The change in beta/nightly is to inject some code to cause the process to abort if the thread unwinds through a C ABI function: #52652. There is a |
For reference, this diff fixes the UB: diff --git a/src/main.rs b/src/main.rs
index c66bd3d..58d322f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,9 @@
+#![feature(c_unwind)]
+
mod ffi {
use std::os::raw::{c_int, c_void};
- type LuaCFn = unsafe extern "C" fn(L: *mut c_void) -> c_int;
+ type LuaCFn = unsafe extern "C-unwind" fn(L: *mut c_void) -> c_int;
extern "C" {
pub fn luaL_newstate() -> *mut c_void;
@@ -21,7 +23,7 @@ pub unsafe fn test_me() {
let state = ffi::luaL_newstate();
assert!(!state.is_null());
- unsafe extern "C" fn run_me(state: *mut std::os::raw::c_void) -> std::os::raw::c_int {
+ unsafe extern "C-unwind" fn run_me(state: *mut std::os::raw::c_void) -> std::os::raw::c_int {
ffi::lua_pushnil(state);
ffi::lua_pushnil(state);
ffi::lua_gettable2(state, -2); // Changing this to `ffi::lua_gettable` solves the problem |
Thanks Steven for the explanation! What is confuses me that it's reproducible only when using LuaJIT. I ran a full test suit on Linux/Windows/MacOS and nightly rust (excluding LuaJIT) and it passed (https://github.com/khvzak/mlua/actions/runs/692598095) I expected the same behaviour regardless of Lua version, they all should use setjmp/longjmp for exception handling. UPD: I'm definitely wrong, LuaJIT uses it's own frame unwinding implementation not based on setjmp/longjmp. |
Yeah, it is using the C++ unwinding API:
|
Seems I have time only till the 6th of May to solve it (when Rust 1.52 will be released with changed "C" unwinding compatibility).
|
👋 Hi! I've opened #84158, which aims to keep this change in behavior behind the |
To be clear, once |
I already addressed this issue in commit mlua-rs/mlua@ba375fa |
…t-of-84158, r=Mark-Simulacrum backport: move new c abi abort behavior behind feature gate This is a backport of PR rust-lang#84158 to the beta branch. The original T-compiler plan was to revert PR rust-lang#76570 in its entirety, as was attempted in PR rust-lang#84672. But the revert did not go smoothly (details below). Therefore, we are backporting PR rust-lang#84158 instead, which was our established backup plan if a revert did not go smoothly. I have manually confirmed that this backport fixes the luajit issue described on issue rust-lang#83541 <details> <summary>Click for details as to why revert of PR rust-lang#76570 did not go smoothly.</summary> It turns out that Miri had been subsequently updated to reflect changes to `rustc_target` that landed in PR rust-lang#76570. This meant that the attempt to land PR rust-lang#84672 broke Miri builds. Normally we allow tools to break when landing PR's (and just expect follow-up PR's to fix the tools), but we don't allow it for tools in the run-up to a release. (We shouldn't be using that uniform policy for all tools. Miri should be allow to break during the week before a release; but currently we cannot express that, due to issue rust-lang#74709.) Therefore, its a lot of pain to try to revert PR rust-lang#76570. And we're going with the backup plan. </details> Original commit message follows: ---- *Background* In rust-lang#76570, new ABI strings including `C-unwind` were introduced. Their behavior is specified in RFC 2945 <sup>[1]</sup>. However, it was reported in the #ffi-unwind stream of the Rust community Zulip that this had altered the way that `extern "C"` functions behaved even when the `c_unwind` feature gate was not active. <sup>[2]</sup> *Overview* This makes a small patch to `rustc_mir_build::build::should_abort_on_panic`, so that the same behavior from before is in place when the `c_unwind` gate is not active. `rustc_middle::ty::layout::fn_can_unwind` is not touched, as the visible behavior should not differ before/after rust-lang#76570. <sup>[3]</sup> ### Footnotes 1.: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md 2.: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/Is.20unwinding.20through.20extern.20C.20UB.3F/near/230112325 3.: https://github.com/rust-lang/rust/pull/76570/files#diff-b0320c2b8868f325d83c027fc5d71732636e9763551e35895488f30fe057c6e9L2599-R2617 [1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md [2]: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/Is.20unwinding.20through.20extern.20C.20UB.3F/near/230112325 [3]: https://github.com/rust-lang/rust/pull/76570/files#diff-b0320c2b8868f325d83c027fc5d71732636e9763551e35895488f30fe057c6e9L2599-R2617
Fixed on beta by #84722. Closing this. |
Hello, I'm
mlua
maintainer and found a regression when running tests for the library on the latest beta and nightly.I narrowed it down to a minimal example:
Code
main.rs
Cargo.toml
build.rs
Repo: https://github.com/khvzak/luajit_bug
It works on stable rust, but fails on beta and nightly with
illegal hardware instruction
on macos 10.15 and linux (at least).It works if uncomment
#[inline(always)]
OR replaceffi::lua_gettable2
call withffi::lua_gettable
.Reproducible only using LuaJIT, but not on Lua 5.1.
Version it worked on
It most recently worked on: nightly-2021-03-10. Does not work on nightly-2021-03-11.
Version with regression
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: