All of lore.kernel.org
 help / color / mirror / Atom feed
From: ablacktshirt@gmail.com (Yubin Ruan)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Questions about the LMA and VMA in a linker script
Date: Thu, 14 Jul 2016 16:45:17 +0800	[thread overview]
Message-ID: <5787511D.4020505@gmail.com> (raw)
In-Reply-To: <CABi1daG_njveuMocp=_Bcs+4CsG3KG0zWY=mpJc2N_nzw=m03Q@mail.gmail.com>

> On Wed, Jul 13, 2016 at 7:33 PM, Yubin Ruan <ablacktshirt@gmail.com
> <mailto:ablacktshirt@gmail.com>> wrote:
>
>     Hi,
>     I got some question about the AT directive in linker script. I have
>     post this question to binutils{at}sourceware.org
>     <http://sourceware.org> with no reply.
>     Hopefully someone can help me out.
>
>     After some searching and asking, I finally know that the AT directive
>     tell the linker about LMA of  a section.
>
>     For example there is some linker script like this:
>
>          SECTIONS
>          {
>              . = 0X80100000;
>              .text : AT(0x100000) {
>                  *(.text .stub .text.* .gnu.linkonce.t.*)
>              }
>
>            ... blah blah ...
>          }
>
>     Now 0x8010000 is a VMA, and 0x100000 is a LMA.
>
>     My question is, is LMA the same as the physical address in a ELF
>     program header ? A typical ELF declaration would be something like
>     this:
>
>     typedef struct
>     {
>        Elf32_Word    p_type;                 /* Segment type */
>        Elf32_Off     p_offset;               /* Segment file offset */
>        Elf32_Addr    p_vaddr;                /* Segment virtual address */
>        Elf32_Addr    p_paddr;                /* Segment physical address */
>        Elf32_Word    p_filesz;               /* Segment size in file */
>        Elf32_Word    p_memsz;                /* Segment size in memory */
>        Elf32_Word    p_flags;                /* Segment flags */
>        Elf32_Word    p_align;                /* Segment alignment */
>     } Elf32_Phdr;
>
>     Is LMA just **p_paddr** in the program header?
>
>     My understanding is, when the linker link all the object files
>     together and then output a executable file of ELF format, those LMA
>     declare in the linker script would be the **p_paddr** in the
>     executable file, so the loader can correspondingly put that program on
>     the physical address as declared by **p_paddr**. Is that correct?
>     Please correct me if you may. I'm reading some low level code and is
>     not really familiar with those low level stuff.
>
>     Thanks in advance!
>     Ruan.
>
> On 2016, July 14, at 14:07, Dave Hylands wrote:
> Replying to all this time.
>
> Currently, I'm most recently familiar with small non-MMU processors (not
> running linux), and in that case, the VMA is the final address
> (typically in RAM) that the section will be loaded to.
> The LMA is the address (typically in ROM) that the section will be at
> when the program starts execution.
>
> A typical example of this is initialized data. In the image, this
> "initialized data" section will be stored in ROM and copied to RAM by
> the C runtime library before calling main.
>
> In the linux kernel, the kernel image will be linked against its final
> virtual address (the VMA) and the LMA would correspond to the physical
> address that the kernel will be loaded at (since the MMU is typically
> off when the kernel image is loaded).
>
> There are lots of variations and reasons why things might not be exactly
> like I described (different architectures have different conventions),
> but that's the jist of things.
>
>
>
>
> --
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com

Thank you for replying. I think I understand what you mean.
But I still want the answer to my question, that is, is LMA just 
**p_paddr** in the program header?

Regards,
Ruan

  reply	other threads:[~2016-07-14  8:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14  2:33 Questions about the LMA and VMA in a linker script walker lala
2016-07-14  6:07 ` Dave Hylands
2016-07-14  8:45   ` Yubin Ruan [this message]
2016-07-15 18:42     ` Dave Hylands
2016-07-16  1:23       ` Yubin Ruan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5787511D.4020505@gmail.com \
    --to=ablacktshirt@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.