Daniel Scocco
Daniel Scocco

Reputation: 7266

Are .text and .data required in ARM Assembly?

Most ARM assembly programs I come across use the .data and .text section directives. However, I noticed two things:

  1. 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.

  2. 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

Answers (1)

Étienne
Étienne

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

Related Questions