Search code examples
linkerembeddedarmfirmwarethumb

How to minimize or eliminate ARM/Thumb far call patching?


I'm working on a product where both flash space (for firmware storage) and memory (for execution) are at a premium. Therefore I want the resulting ELF to be as small as possible without noticeably sacrificing product performance. The code is compiled as a mix of ARM and Thumb, basically using Thumb mode when I can get away with it. I've been tweaking compiler/linker options to reduce size (optimize for space, delete unused functions, etc). One thing I've noticed is that I'm getting a lot of (about 180) generated far call patches, which takes up a bit of space.

Long story short, anyone know a good way to minimize or eliminate these patches (presumably by avoiding most/all far calls)? Seems to me there should be a way to reorganize and optimize the order of how everything is stored/linked in its respective memory sections so far calls are unnecessary or at least minimized.

EDIT: I no longer require an answer to this question. As it turns out, the far calls are unavoidable in this product because they are required for calls between ITCM and SRAM (which are unfortunately located far from each other in address space). Thanks for the comments and answers.


Solution

  • If you're using the RVCT linker, armlink, you can try the different section sorting algorithms mentioned in the documentaton for --sort.