Implementing A Custom ESP32 Runtime Linker
Posted: Mon Jan 22, 2018 3:00 am
I would like to make a runtime linker which runs on the ESP32, and can receive ELF binaries from the network, perform the necessary relocations to addresses (via a symbol table), and then jump to the relocated code and begin execution.
(I have done this before for ARM Thumb architecture and it worked great!) When I did this before, for development I had a script which exported all functions/globals (I get this from the output of `nm` applied to a previous ELF build). Later, I can strip the table to a list of allowed symbols.
I recall the hard parts being:
https://0x04.net/~mwk/doc/xtensa.pdf
(I have done this before for ARM Thumb architecture and it worked great!) When I did this before, for development I had a script which exported all functions/globals (I get this from the output of `nm` applied to a previous ELF build). Later, I can strip the table to a list of allowed symbols.
I recall the hard parts being:
- Determining the arithmetic for the possible relocations (R_XTENSA_32, R_XTENSA_NONE, etc)
- Creating a minimal linker script for producing sane binaries (long-calls, single section, etc)
- Figuring out the best compilation options (-pie, -mlongcalls)
https://0x04.net/~mwk/doc/xtensa.pdf