Re: Questions about the LMA and VMA in a linker script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Wed, Jul 13, 2016 at 7:33 PM, Yubin Ruan <ablacktshirt@xxxxxxxxx
> <mailto:ablacktshirt@xxxxxxxxx>> 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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux