Skip to content

Commit be92aac

Browse files
tvedpgeorge
authored andcommitted
docs/develop: Detail how to add symbols to mp_fun_table for native mods.
1 parent f020eac commit be92aac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/develop/natmod.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ The known limitations are:
6767
So, if your C code has writable data, make sure the data is defined globally,
6868
without an initialiser, and only written to within functions.
6969

70+
Linker limitation: the native module is not linked against the symbol table of the
71+
full MicroPython firmware. Rather, it is linked against an explicit table of exported
72+
symbols found in ``mp_fun_table`` (in ``py/nativeglue.h``), that is fixed at firmware
73+
build time. It is thus not possible to simply call some arbitrary HAL/OS/RTOS/system
74+
function, for example.
75+
76+
New symbols can be added to the end of the table and the firmware rebuilt.
77+
The symbols also need to be added to ``tools/mpy_ld.py``'s ``fun_table`` dict in the
78+
same location. This allows ``mpy_ld.py`` to be able to pick the new symbols up and
79+
provide relocations for them when the mpy is imported. Finally, if the symbol is a
80+
function, a macro or stub should be added to ``py/dynruntime.h`` to make it easy to
81+
call the function.
82+
7083
Defining a native module
7184
------------------------
7285

0 commit comments

Comments
 (0)