Open
Description
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.
- 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). - Compile the C program to a relocatable file (static library or object file).
- Link them together with the native linker to a dynamic library in ELF format.
- 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.