As I understand it these are the .section directives:
awxMSGT
The "old" directives if COFF format was used had "read only".
How do I make a .section in ELF format read only? No specifier at all?
Yes, empty flags makes it read only (any flags without an explicit w for writeable makes it read only) as you can verify for example using objdump.
So, .section foo or .section bar, "" both create a read-only section. You probably want to make it allocatable, though, so something like .section baz, "a". This also seems to automatically turn on @progbits (marked LOAD in objdump) to actually read the data from the file into memory. You can also specify that manually to be on the safe side. See the GAS documentation for more details.
EDIT: Taking a look at the GNU AS info, what I wrote below kind of answers it. I'm pretty sure that just like in my linker script example, leaving the w out will note this section as being non-writeable.
Sorry if this is completely not what you were asking. It sounded right so I took a stab at it!
So if you're talking about the linker then I think what your looking for is the MEMORY area of the linker script.
For example:
MEMORY
{
flash (rx) : org = 0x00000000 , len = 0x00080000
sram (rwx) : org = 0x40000000 , len = 0x00010000
}
The fact that I left the w out of my flash segment implies that it is read-only. Then in the section specification later I use:
SECTIONS
{
/* .text section (executable code) */
.text :
{
blah blah blah
} > flash
_etext = . ;
PROVIDE ( etext = . );
/* .data section (read/write initialized variables) */
.data : AT (_etext)
{
blah blah blah
} > sram
}
I specify where each section is stored in memory in the section specification with the > flash or > sram to delineate if it is in read-only memory or not (and the AT (_etext) is to specify that it starts in read-only and is copied later).
I know you were specifically asking about the assembler, but this sounded like what I thought you were asking for.
Hope it helps!
readelf -S:-)? - Ciro Santilli 新疆再教育营六四事件法轮功郝海东