Re: VMA vs LMA?



dspfun wrote:
Hi!

What is the difference between VMA (Virtual Memory Address) and LMA
(Load Memory Address)?


Your quotation from the ld documentation explains that pretty well, I thought.

The Gnu ld documentation has the following explanation:
"Every loadable or allocatable output section has two addresses. The
first is the VMA, or virtual memory address. This is the address the
section will have when the output file is run. The second is the LMA,
or load memory address. This is the address at which the section will
be loaded. In most cases the two addresses will be the same. An
example of when they might be different is when a data section is
loaded into ROM, and then copied into RAM when the program starts up
(this technique is often used to initialize global variables in a ROM
based system). In this case the ROM address would be the LMA, and the
RAM address would be the VMA. "

In the above, "who" copies the data section from ROM to RAM? Isn't
this the same as when a program that is started from a shell is copied
from the harddrive to RAM by a loader, i.e. normal procedure?


No, these are different situations. When an OS loads code from a file, the OS does the copying. Usually the VMA and LMA are the same, so that the OS loads the initialised data section directly into place. With a ROM'ed program, where the program is run directly from the ROM rather than being first copied into RAM (in which case you have the same situation as an OS and a file), the code at the beginning of the program copies the data across and also clears the bss - this is part of the crt0 startup code.

As far as I have understood things the loader loads the executable
into RAM (from secondary storage) and then execution starts. So to me
the address of a section when it is run (VMA) is the same as the
address to where the section is loaded (LMA)?


That is the case *if* the program is copied into RAM before running.

If a section can be loaded to one address and then moved to another
section when run, who then moves the section from the load address
(LMA) to the run address (VMA)?

When is the LMA referenced (and by who) and when is the VMA referenced
(and by who)?


See above.


BRs!

.



Relevant Pages

  • VMA vs LMA?
    ... What is the difference between VMA (Virtual Memory Address) and LMA ... or load memory address. ...
    (comp.arch.embedded)
  • Re: VMA vs LMA?
    ... What confused me most is the fact that the real flash address is ... According to you, the LMA now becomes RAM address, but the VMA ... Since the codes will run in Flash, how and what the LMA functions? ... VMA and then load it when i need using LMA. ...
    (comp.arch.embedded)
  • Re: VMA vs LMA?
    ... LMA/VMA are the same, because you are running entirely from RAM. ... the LMA and the VMA are the same - the program runs directly from the flash it resides in. ... The only exception is that the startup code also refers to the LMA of the data section, so that it can do the initial copy. ...
    (comp.arch.embedded)
  • Re: VMA vs LMA?
    ... When writing a program where one wants different LMA and VMA sections ... Why does crt0 have code that copies data from LMA to ...
    (comp.arch.embedded)
  • Re: VMA vs LMA?
    ... than being first copied into RAM (in which case you have the same ... The other place where it's common to see VMA!= LMA (and code that ... first few bytes set up the MMU and execution then passes to a new VMA. ...
    (comp.arch.embedded)