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

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

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


From: Matthijs Kooijman
Subject: Re: Why are switch statement tables in section .rodata which gets copied to RAM with avr-gcc?
Date: Tue, 31 Mar 2020 16:59:37 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

Hi Peter,

> 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.
.rodata is copied to RAM, because flash and RAM are not in the same
address space on AVR. This means that, without special treatment, a
pointer to read-only data will be dereferenced the same as a pointer to
read-write data, reading from RAM, so the compiler has no choice but to
copy rodata to RAM.

To circumvent that, data can be marked with PROGMEM, to instruct the
compiler to leave it it flash, but then it is up to the programmer to
distinguish such pointers and use pgm_read_... functions to read them
from flash instead of RAM.

Having said that: Compiler-generated switch tables (just like
vtables, btw), *could* very well be kept in flash by putting them in an
appropriate section and generating the right code for loading data from
them, but I suspect this simply was not implemented (since this is a
rather specialcase for avr, on most other platforms putting data in
.rodata is sufficient to keep it in flash).

Does this answer your question?

Gr.

Matthijs

Attachment: signature.asc
Description: PGP signature


reply via email to

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