Monday, May 2, 2011

iBurg

Grandpa code generator-generator in LCC


Linker Scripts VMA vs LMA


VMA is virtual memory address while LMA is load memory address. If both are not equal, which one of the addresses does linker consider while resolving symbols' addresses?

Let us consider a simple program test.c:

int i=10;
int main() {
return i++;
}

After compiling it to ELF-executable, dump the output sections. (I am compiling for AVR target using avr-gcc)

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000040  00000000  00000000  00000074  2**1
                    CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000002  00800060  00000040  000000b4  2**0
                     CONTENTS, ALLOC, LOAD, DATA

Notice the values in bold. VMA and LMA of .data section differ? Since 'i' is the only variable, what address will 'i' have? VMA or LMA ? When the text section is disassembled, what will be the address of memory accessed by instructions to read and write the value of variable 'i'?


Reference for linker script file:  Linker Script Documentation