Skip to content

Specification of FFI #421

Open
Open
@chorman0773

Description

@chorman0773

What are the operational semantics of the following rust program:

extern "C"{
   fn foo();
}

fn main(){
    foo()
}

Two specific questions are asked here:

  1. What is the behaviour of calling a "foreign" function that is defined and exported (#[no_mangle] or #[export_name]) in the same program and "accessible" via a (potentially-indirectly) linked rlib or dylib
    a. A subquestion is what is the behaviour of calling a "foreign" function defined and exported in Rust that is linked via a staticlib/cdylib
  2. What is the behaviour of calling a "foreign" function that isn't defined in Rust (but in some other, potentially assembly) language.

The answer to question (1) is obvious: It's equivalent to a call to that function. (1)(a) and (2) are a bit more interesting.

A previously discussed answer is that the the AM performs an implementation-defined AM operation, paramaterized by the link_name of the external function, and if it matches the export_name of an exported function defined by the program, it behaves as an equivalent operation to a call to that function. Does this handle every case? What about signature mismatch in the (1), (1)(a), and (2) cases? What happens if it's exported from a dylib, but also defined in a staticlib (either rust or non-rust)? Or defined in two dylib or a dylib+cdyib.

@rustbot label +S-pending-design +A-ffi

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ffiTopic: Related to FFIS-pending-designStatus: Resolving this issue requires addressing some open design questions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions