Skip to content

[vm/ffi] Explore using FfiNative for static linking #49418

Open
@dcharkes

Description

@dcharkes

Given a dart file

@FfiNative<Int64 Function(Int64, Int64)>("FfiNative_Sum", isLeaf:true)
external int sum(int a, int b);

main(){
  print(sum(40, 2));
}

And a C file:

#include <stdint.h>

uint64_t FfiNative_Sum(uint64_t a, uint64_t b) { return a + b; }

It should be possible to compile this to a pc relative call if we use the native linker.

  1. Compile the dart program to a (a) an assembly file with a call FfiNative_Sum or (b) to an ELF file with relocation records (a static library in ELF format rather than a dynamic library in ELF format).
  2. Compile the C program to a relocatable file (static library or object file).
  3. Link them together with the native linker to a dynamic library in ELF format.
  4. Run with dartaotruntime passing in the dynamic library or appending it.

There is a huge design space.

For example we should add asset tags to disambiguate native symbols.
And we could use the same syntax for dynamic linking using these assets.
I will not write these up here, but wanted to have a bug to point to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions