-
Notifications
You must be signed in to change notification settings - Fork 356
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
Improve error message of calling unsupported non-"C"/"system"-ABI foreign function #1745
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghost
commented
Mar 17, 2021
ghost
commented
Mar 17, 2021
oli-obk
reviewed
Mar 17, 2021
bjorn3
reviewed
Mar 17, 2021
Thanks a lot, looking good. :-) |
📌 Commit 7ec919d has been approved by |
☀️ Test successful - checks-actions |
ghost
deleted the
unsup-foreign-calls-are-not-ub
branch
March 17, 2021 18:10
ghost
mentioned this pull request
Aug 5, 2021
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this pull request
Aug 6, 2021
Use `C-unwind` ABI for `__rust_start_panic` in `panic_abort` The function originally has `C` ABI but is called using `C-unwind` ABI in `std`: https://github.com/rust-lang/rust/blob/d4ad1cfc63ba5824196bfb2370451ddb5af2e020/library/std/src/panicking.rs#L49-L54 Which might be [problematic](rust-lang/miri#1745 (comment)) and triggers this [Miri error](rust-lang#87778 (comment)): ``` error: Undefined Behavior: calling a function with ABI C using caller ABI C-unwind --> /home/hyd-dev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:672:9 | 672 | __rust_start_panic(obj) | ^^^^^^^^^^^^^^^^^^^^^^^ calling a function with ABI C using caller ABI C-unwind | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information ``` Changing the ABI of the function to `C-unwind` fixes the error above.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Miri currently reports the following
foo()
call has ABI-mismatch UB:Output when targeting Linux (and maybe also macOS):
Output when targeting Windows:
However, to my knowledge, that's not UB -- it's just unsupported by Miri (and Miri can't assume the function has
"C"
or"system"
ABI since Miri doesn't know about it). I believe that is because of the overzealouscheck_abi()
call before the longmatch
insrc/shims/{posix,windows}/foreign_items.rs
. The ABI is checked to match the system one ("system"
on Windows,"C"
otherwise) no matter the callee is recognized as a shim or an unsupported foreign function.Therefore, this PR removes the
check_abi()
call before thematch
and inserts acheck_abi()
call to each non-wildcard match.