Reputation: 7266
Most ARM assembly programs I come across use the .data and .text section directives. However, I noticed two things:
Many times the assembly code generated by the GCC compiler itself will only use the .text directive, grouping the variables somewhere in the code by without the .data directive.
Even if I don't use the .text section my programs still compile and run fine.
My question: are those directives required? If yes, why? If yes, how come my programs still works without them?
Upvotes: 4
Views: 6492
Reputation: 5023
It is sometimes necessary to use those section directives when you want to decide where to place the sections you defined when you transfer your program and where they get executed, in ROM, in RAM, etc. Then you can write your own linker script like in the following example (in ld
linker script format):
MEMORY
{
RAM (rw) : ORIGIN = 0x00000000, LENGTH = 128M
ROM (rx) : ORIGIN = 0xffff0000, LENGTH = 64K
}
SECTIONS
{
.startup :
{
*(.text.vectors)
sdram_init.o(.sdram_init)
main.o(.text_main)
} > ROM
.data :
{
*(.data*)
} > RAM
}
If you use the default linker behaviour I don't think you will need to explicitly declare your sections with directives.
Upvotes: 6