tools/mpy_ld.py: automatically provide memset/memmove/memcpy if they are undefined#19357
tools/mpy_ld.py: automatically provide memset/memmove/memcpy if they are undefined#19357dpgeorge wants to merge 2 commits into
Conversation
|
@agatti I thought I'd have a go at this, and it turned out pretty easy: the native linker allows direct relocation of memset/memmove, so the trampoline functions for them are very simple. This should work on Thumb2. Just need to extend it to all other archs. Then we no longer need any special cases to handle these libc functions. |
|
Code size report: |
|
Looks interesting! For RV32/RV64 you should get by with this: assuming that T6 can be trashed there (it should, but you never know). There are different opcode sequences depending on the distance between PC and the offset, but this one should always work assuming a ±2GiB range. If you get stuck on RISC-V let me know and I'll look at it. |
5eb8663 to
8b65eee
Compare
Thanks for the hint, but the runtime linker (in (where the absolute pointer is filled in at runtime upon loading the .mpy) CI is showing that works on RV32, but fails on RV64... not sure why. |
|
I'm on mobile right now but I seem to recall that c.lw won't load the upper 32 bits of the register. I guess you either need to use another opcode or clear the register beforehand. |
Ah, you're right. LW is sign-extending to 6-bits, LWU is zero-extending. I need to use LD instead on RV64. |
4a261d6 to
07e6a5a
Compare
Using a direct pointer to `mp_fun_table.memset_`. TODO: get working on all archs. Signed-off-by: Damien George <damien@micropython.org>
They are now provided by `mpy_ld.py`. Signed-off-by: Damien George <damien@micropython.org>
07e6a5a to
534cd8d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19357 +/- ##
=======================================
Coverage 98.51% 98.51%
=======================================
Files 176 176
Lines 22904 22904
=======================================
Hits 22563 22563
Misses 341 341 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Native modules sometimes need
memset/memmove/memcpy. This is currently handled by explicitly providing wrapper functions for these that call into the provided native glue API, namelymp_fun_table.memset_etc.This PR improves the situation by automatically providing wrapper/trampoline functions when they are needed by the native code.
This is WIP. It currently works only for ARM Thumb2.
Testing
Tested on PYBD_SF6 (armv7emdp arch).
Will be tested by CI.
Trade-offs and Alternatives
TBD.
Generative AI
Not used.