9

I'm trying to understand a third party linker script.

At the beginning of the script it defines two memory (using MEMORY {...}) called iram and dram.

Then there are a few sections defined that have the following syntax:

.data{
...
} > dram AT > iram

I know that > dram at the end means to position that section (.data in this case) in the dram region. However I don't understand what the "AT > iram" means.

aarelovich
  • 5,140
  • 11
  • 55
  • 106

1 Answers1

13

The dram part of the .data definition in your example specifies the virtual memory address (VMA) of the .data section, whereas the the iram part specifies the load memory address (LMA).

The VMA is the address the section will have when the program is run. The LMA is the address of the section when program is being loaded. As an example this can be used to provide initial values for global variables in non-volatile memory which are copied to RAM during program load.

More information can also be found in the manual for the GNU linker ld: https://sourceware.org/binutils/docs/ld/Output-Section-Attributes.html#Output-Section-Attributes

AJM
  • 1,317
  • 2
  • 15
  • 30
baggio
  • 246
  • 3
  • 6
  • 1
    The startup code that uses this linker script copies the .data section from ROM to RAM. So, if I undestand you correctly, when you know this is going to happen you need the > ram AT > rom parameters? And sorry I can't see this link. And one other thing the sentence in "The address is the address of the section when program is being loaded" you are referring to LMA, right? – aarelovich Mar 11 '15 at 14:56
  • Yes, sorry, my intention was to write LMA(I edited my answer above). Another stackoverflow question also explains a similar example: [link](http://stackoverflow.com/questions/13831462/understanding-the-location-counter-of-gnu-linker-scripts). – baggio Mar 12 '15 at 20:08
  • Let me just make something clear. After you compile the program, you can inspect the binary `.elf` file using a command `objdump -D *.elf` which will show you all the sections and their addresses (LMA). Then this is loaded to the device and device starts executing. It is programmer's duty to make sure that one of the first things that device does is to copy the section from LMA to VMA. Programmers usually implement this kind of code in the startup `.s` files. It is just important to know that linker will not do this for you. You as a programmer need to move the section. – 71GA Dec 22 '22 at 22:33
  • One more thing. In order to do this, section, e.g. `data` will usually have two labels e.g. `_sdata` *(at start of data section)* and `_edata` *(at end of data section)* and these two labels will enable programmers to implement an assembly routine that will move the entire section. It wouldn't be possible without these labels. So you might locate these labels in the `.ld` file and then search for them in the `.s` file to quickly find the routine that moves the section. – 71GA Dec 22 '22 at 22:38