Skip to content

Indirect calls: how do they work? #89

@jfbastien

Description

@jfbastien

The current AST semantics document states:

Indirect calls may be made to a value of function-pointer type. A function- pointer value may be obtained for a given function as specified by its index in the function table.

  • CallIndirect - call function indirectly
  • AddressOf - obtain a function pointer value for a given function
    Function-pointer values are comparable for equality and the AddressOf operator is monomorphic. Function-pointer values can be explicitly coerced to and from integers (which, in particular, is necessary when loading/storing to the heap since the heap only provides integer types). For security and safety reasons, the integer value of a coerced function-pointer value is an abstract index and does not reveal the actual machine code address of the target function.

In v.1 function pointer values are local to a single module. The dynamic linking feature is necessary for two modules to pass function pointers back and forth.

IIUC this basically is what Emscripten does.

I'd like us to discuss this a bit more to make sure we consider alternatives before choosing a specific approach:

  • Are different implementations of Web Assembly allowed to return different abstract integers for a function pointer?
  • What's the performance cost?
  • Does this have caveats with C++ UB on function pointers that happen to work on most implementations?
  • Does this support C++ pointer to member function sufficiently?
  • How does this interact with dynamic linking, late binding, and relocations?
  • Is this sufficient for non-C++ languages?
    • Does ObjectiveC work properly / efficiently?
    • Multimethods?
  • Can sanitizers (such as control-flow sanitizer) be implemented efficiently (without Web Assembly runtime involvement)?
  • Can the Web Assembly implementation use a sandboxing approach that doesn't rely on a language VM for security?
    • Can this target NaCl efficiently?
    • can this target MinSFI efficiently?
    • Are we hindering future sandboxing research?

Anything else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions