Put AVR vTables into the flash

Hello,

in the last days I tried to build the following plugin:

It is used to move the vtables of the AVRs into the .progmem instead of .rodata section. The plugin is simply used as compiler Parameter -fplugin=avr-flash-vtbl.so. Unfortunately the path to the plugin has to be absolute. At least, that's the way it was working for me. Perhaps someone can confirm the opposite.

But to build and use the plugin, the compiler had to be configured and compiled with the --enable-plugin. This took some time. For this I used the script from AVR-GCC 11.1.0 for Windows 32 and 64 bit – Zak's Electronics Blog ~* only the option mentioned above was added. After that I still had some troubles with the
plugin. To spare the others, I'll put compiler and the plugin. The plugin is located directly in the archive. Under Linux I did not test the plugin. If someone tried a feedback would be helpful!

Here are compiler Avr-Gcc 9.2.0 and plugin for Linux and Windows:

Best regards Andreas

Can you explain exactly what the benefit of this is?

vtables consume SRAM. They can easily become large / expensive. The data stored in them is read-only. That makes them a good candidate to be moved to Flash.

However, I don't think AVR processors include "indirect jump from address stored in Flash" instructions. Which means making a virtual call from a vtable stored in Flash requires a handful of machine instructions (I think it's three if the vtable is in SRAM). The trade off is a slight performance hit and more code for each virtual call.

AVR processors are cheap so, if SRAM is teetering on exhaustion, upgrading to something with more SRAM seems more practical.

Theoretically they could be stored as “trampolines” - actual branch instructions instead of addresses that have to be loaded indirectly. But I don’t know if you can convince any version of gcc to do that...