avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why are switch statement tables in section .rodata which gets copied to


From: Peter Sommerlad (C++)
Subject: Why are switch statement tables in section .rodata which gets copied to RAM with avr-gcc?
Date: Tue, 31 Mar 2020 15:50:57 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 PostboxApp/7.0.12

Hi,

as a newbie to AVR programming, I am porting Arduino Core code to modern C++17. I wanted to get rid of ugly large lookup tables that in PROGMEM that require separate assembly macro magic to access by normal C++ code.

My naïve assumption was that the compiler-generated tables for switch statement would end up in flash memory, because they are immutable.

It turns out, that avr-gcc or the linker for the Arduino processor that I have access to, generate code to copy .rodata to .data in RAM. This is bad, and may have been the reason for these PROGMEM tables.

For some of the smaller processors the smaller switch statements would not end up using the table lookup, but especially the ATmega2560 has dense large number of cases.

Any ideas to circumvent it with standard code?

I am using avr-gcc 9.3.0

Regards
Peter.

--
Peter Sommerlad

Better Software: Consulting, Training, Reviews
Modern, Safe & Agile C++

address@hidden
+41 79 432 23 32



reply via email to

[Prev in Thread] Current Thread [Next in Thread]