public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* The meaning of LMA and location counter in GNU ld
@ 2011-01-24 15:06 ali hagigat
  2011-01-24 17:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: ali hagigat @ 2011-01-24 15:06 UTC (permalink / raw)
  To: binutils

What is the real meaning of LMA? is it a physical address?
When we assign some numbers to the location counter, what these
numbers mean? Are they physical addresses? or virtual addresses? or
they are just local addresses for ld?
When we use some addresses in a linker command file, are they final
physical addresses? or they show a range of 4 GB virtual addresses for
a 32 bit Intel machine?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-24 15:06 The meaning of LMA and location counter in GNU ld ali hagigat
@ 2011-01-24 17:46 ` Ian Lance Taylor
  2011-01-26  5:45   ` ali hagigat
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-01-24 17:46 UTC (permalink / raw)
  To: ali hagigat; +Cc: binutils

ali hagigat <hagigatali@gmail.com> writes:

> What is the real meaning of LMA? is it a physical address?
> When we assign some numbers to the location counter, what these
> numbers mean? Are they physical addresses? or virtual addresses? or
> they are just local addresses for ld?
> When we use some addresses in a linker command file, are they final
> physical addresses? or they show a range of 4 GB virtual addresses for
> a 32 bit Intel machine?

The LMA is the load address, as distinguished from the VMA which is the
virtual address.  It's easiest to understand the difference if you think
of a system without virtual memory.  The LMA is intended to specify the
address where the section should be loaded.  However, all references to
the section will be resolved as though the section were loaded at the
VMA.  In a typical use, the LMA will be in ROM and the VMA of the data
segment will be in RAM.  You will load the program into RAM at the LMA.
At program startup time, the contents of the data segment will be copied
from the LMA to the VMA.  It will thus be initialized and also be
writable.

As I say, that is the typical usage.  The exact meaning of the numbers
is ultimately going to depend on the mechanism used to load the program
when the program starts, whether that means jumping to an address in ROM
or loading some bytes of a disk or a network.  So there is no precise
way to answer some of your questions; the only answer is: it depends.

Ian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-24 17:46 ` Ian Lance Taylor
@ 2011-01-26  5:45   ` ali hagigat
  2011-01-26  6:28     ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: ali hagigat @ 2011-01-26  5:45 UTC (permalink / raw)
  To: Ian Lance Taylor, binutils

3.4.4 Assign alias names to memory regions
SECTIONS
{
     .text :
     {
         *(.text)
     } > REGION_TEXT
    .rodata :
    {
        *(.rodata)
        rodata_end = .;
    } > REGION_RODATA
    .data : AT (rodata_end)
    {
        data_start = .;
        *(.data)
     } > REGION_DATA
     data_size = SIZEOF(.data);
     data_load_start = LOADADDR(.data);
     .bss :
     {
         *(.bss)
     } > REGION_BSS
}
---------------------------------------------------------------
I have copied part of the manual for ld.
In front of .data, there is an AT command: AT (rodata_end)
Is it necessary to write it? If I do not write it, any ways the load
address for .data section will be after .rodata regardless of
REGION_RODATA. Is that right?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-26  5:45   ` ali hagigat
@ 2011-01-26  6:28     ` Ian Lance Taylor
  2011-01-26  7:21       ` ali hagigat
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-01-26  6:28 UTC (permalink / raw)
  To: ali hagigat; +Cc: binutils

ali hagigat <hagigatali@gmail.com> writes:

> 3.4.4 Assign alias names to memory regions
> SECTIONS
> {
>      .text :
>      {
>          *(.text)
>      } > REGION_TEXT
>     .rodata :
>     {
>         *(.rodata)
>         rodata_end = .;
>     } > REGION_RODATA
>     .data : AT (rodata_end)
>     {
>         data_start = .;
>         *(.data)
>      } > REGION_DATA
>      data_size = SIZEOF(.data);
>      data_load_start = LOADADDR(.data);
>      .bss :
>      {
>          *(.bss)
>      } > REGION_BSS
> }
> ---------------------------------------------------------------
> I have copied part of the manual for ld.
> In front of .data, there is an AT command: AT (rodata_end)
> Is it necessary to write it? If I do not write it, any ways the load
> address for .data section will be after .rodata regardless of
> REGION_RODATA. Is that right?

In this specific example, yes, that's right.

Ian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-26  6:28     ` Ian Lance Taylor
@ 2011-01-26  7:21       ` ali hagigat
  2011-01-26  8:10         ` ali hagigat
  2011-01-26 14:52         ` Ian Lance Taylor
  0 siblings, 2 replies; 8+ messages in thread
From: ali hagigat @ 2011-01-26  7:21 UTC (permalink / raw)
  To: Ian Lance Taylor, binutils

3.6.8.2 Output Section LMA
If there is no preceding output section or the section is
not allocatable, the linker will set the LMA equal to the VMA.
----------------------------------------------
What is the meaning of "the section is not allocatable" in the above
sentence of ld manual?
Regards

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-26  7:21       ` ali hagigat
@ 2011-01-26  8:10         ` ali hagigat
  2011-01-26 14:56           ` Ian Lance Taylor
  2011-01-26 14:52         ` Ian Lance Taylor
  1 sibling, 1 reply; 8+ messages in thread
From: ali hagigat @ 2011-01-26  8:10 UTC (permalink / raw)
  To: Ian Lance Taylor, binutils

3.6.8.2 Output Section LMA
If neither AT nor AT> is specified for an allocatable section, the
linker will set the LMA such that the difference between VMA and LMA
for the section is the same as the preceding output section in the
same region.
---------------------------------------------------------------
I wonder if you can give an example regarding to the above lines of the manual.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-26  7:21       ` ali hagigat
  2011-01-26  8:10         ` ali hagigat
@ 2011-01-26 14:52         ` Ian Lance Taylor
  1 sibling, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-01-26 14:52 UTC (permalink / raw)
  To: ali hagigat; +Cc: binutils

ali hagigat <hagigatali@gmail.com> writes:

> 3.6.8.2 Output Section LMA
> If there is no preceding output section or the section is
> not allocatable, the linker will set the LMA equal to the VMA.
> ----------------------------------------------
> What is the meaning of "the section is not allocatable" in the above
> sentence of ld manual?

In ELF, a section for which SHF_ALLOC is not set.  In general, a section
which is not loaded at runtime.  A typical example would be a section
containing debug information.

Ian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: The meaning of LMA and location counter in GNU ld
  2011-01-26  8:10         ` ali hagigat
@ 2011-01-26 14:56           ` Ian Lance Taylor
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-01-26 14:56 UTC (permalink / raw)
  To: ali hagigat; +Cc: binutils

ali hagigat <hagigatali@gmail.com> writes:

> 3.6.8.2 Output Section LMA
> If neither AT nor AT> is specified for an allocatable section, the
> linker will set the LMA such that the difference between VMA and LMA
> for the section is the same as the preceding output section in the
> same region.
> ---------------------------------------------------------------
> I wonder if you can give an example regarding to the above lines of the manual.

This seems like a question that you can answer yourself, by simply
writing a script which omits AT and AT>.  The words seem completely
clear in any case, so I don't know how to answer except to repeat the
text that you have quoted.

You are asking a lot of questions.  I'm willing to answer specific
questions.  But I would like to encourage you to take some time to think
about this stuff, and to experiment with it.  While there is certainly a
lot of terminology to learn, it's not that hard to figure out the
basics.  If you work with it yourself, you will most likely learn it
better.  It will also give you the chance to ask more specific
questions, like "I tried this, I expected X, but instead I saw Y; why?".

Ian

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-01-26 14:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 15:06 The meaning of LMA and location counter in GNU ld ali hagigat
2011-01-24 17:46 ` Ian Lance Taylor
2011-01-26  5:45   ` ali hagigat
2011-01-26  6:28     ` Ian Lance Taylor
2011-01-26  7:21       ` ali hagigat
2011-01-26  8:10         ` ali hagigat
2011-01-26 14:56           ` Ian Lance Taylor
2011-01-26 14:52         ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).