Skip to content
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

Allow foreign rust functions #1170

Closed
elichai opened this issue Feb 9, 2020 · 7 comments · Fixed by #1776
Closed

Allow foreign rust functions #1170

elichai opened this issue Feb 9, 2020 · 7 comments · Fixed by #1776
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement

Comments

@elichai
Copy link
Contributor

elichai commented Feb 9, 2020

Hi,
Is it possible to allow miri to evaluate foreign calls to rust functions?
Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3cddf97b737ae015f92093c9bab2461e

@RalfJung RalfJung added A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement labels Feb 9, 2020
@RalfJung
Copy link
Member

RalfJung commented Feb 9, 2020

It is probably possible, yes. But I do not know the best way to implement this -- somehow, Miri would have to find the function with a given extern name.

@pvdrz
Copy link
Contributor

pvdrz commented Feb 15, 2020

Even though I think this is possible, how do we guarantee that allowing to execute extern code would not compromise miri's capability of detecting UB?

@RalfJung
Copy link
Member

It's not actually extern code. The implementation is Rust code as well so we just go on interpreting.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2020

I have absolutely no idea whether this is the right thing, but we may be able to just iterate over all crates and call https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/query/struct.TyCtxtAt.html#method.exported_symbols in order to collect the name -> DefId map and continue interpretation at the new def ID.

An extern other than "Rust" should also emit an error if unwinding happens across that boundary

@tomtau
Copy link

tomtau commented Feb 19, 2020

I have a similar related question -- will it be possible to allow Miri evaluate foreign statics?

extern "C" {
    pub static something: *const Something;
...
}

@RalfJung
Copy link
Member

RalfJung commented Feb 19, 2020

I'm afraid the question is not very related at all. The issue here is specifically about calling extern fn that are implemented in Rust (somewhere in the current crate tree).

We already emulate one foreign static, and support for others can be added. But this is like function shims: you need to actually write the code that implements whatever interaction with that foreign static would happen in real code. If you have s specific well-known foreign static that you think should be supported, please open a new issue (just like we have issues to support calling specific foreign functions).

For general support for arbitrary foreign statics, I don't even know what that would mean (should Miri just guess their value...?!?), but it seems related to general FFI support so that would be #11.

@tomtau
Copy link

tomtau commented Feb 19, 2020

Thanks, yes, #11 is indeed more relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants