Skip to content

Commit e993f53

Browse files
agattidpgeorge
authored andcommitted
docs/develop/natmod: Add notes on Picolibc and natmods.
This commit adds some documentation on what are the limitations of using Picolibc as a standard C library for native modules. This also contains a reference to the "errno" issue when building natmods on RV32 that the PR this commit is part of, as it is not obvious how to approach this issue when encountered for the first time. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent b63e528 commit e993f53

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/develop/natmod.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ The known limitations are:
6767

6868
* static BSS variables are not supported; workaround: use global BSS variables
6969

70+
* thread-local storage variables are not supported on rv32imc; workaround: use
71+
global BSS variables or allocate some space on the heap to store them
72+
7073
So, if your C code has writable data, make sure the data is defined globally,
7174
without an initialiser, and only written to within functions.
7275

@@ -225,6 +228,26 @@ other module, for example::
225228
print(factorial.factorial(10))
226229
# should display 3628800
227230

231+
Using Picolibc when building modules
232+
------------------------------------
233+
234+
Using `Picolibc <https://github.com/picolibc/picolibc>`_ as your C standard
235+
library is not only supported, but in fact it is the default for the rv32imc
236+
platform. However, there are a couple of things worth mentioning to make sure
237+
you don't run into problems later when building code.
238+
239+
Some pre-built Picolibc versions (for example, those provided by Ubuntu Linux
240+
as the ``picolibc-arm-none-eabi``, ``picolibc-riscv64-unknown-elf``, and
241+
``picolibc-xtensa-lx106-elf`` packages) assume thread-local storage (TLS) is
242+
available at runtime, but unfortunately MicroPython modules do not support that
243+
on some architectures (namely ``rv32imc``). This means that some
244+
functionalities provided by Picolibc will default to use TLS, returning an
245+
error either during compilation or during linking.
246+
247+
For an example on how this may affect you, the ``examples/natmod/btree``
248+
example module contains a workaround to make sure ``errno`` works (look for
249+
``__PICOLIBC_ERRNO_FUNCTION`` in the Makefile and follow the trail from there).
250+
228251
Further examples
229252
----------------
230253

0 commit comments

Comments
 (0)