<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 14, 2016 at 1:45 AM, Yubin Ruan <span dir="ltr"><<a href="mailto:ablacktshirt@gmail.com" target="_blank">ablacktshirt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span class="">
On Wed, Jul 13, 2016 at 7:33 PM, Yubin Ruan <<a href="mailto:ablacktshirt@gmail.com" target="_blank">ablacktshirt@gmail.com</a><br>
<mailto:<a href="mailto:ablacktshirt@gmail.com" target="_blank">ablacktshirt@gmail.com</a>>> wrote:<br>
<br>
Hi,<br>
I got some question about the AT directive in linker script. I have<br>
post this question to binutils{at}<a href="http://sourceware.org" rel="noreferrer" target="_blank">sourceware.org</a><br></span>
<<a href="http://sourceware.org" rel="noreferrer" target="_blank">http://sourceware.org</a>> with no reply.<div><div class="h5"><br>
Hopefully someone can help me out.<br>
<br>
After some searching and asking, I finally know that the AT directive<br>
tell the linker about LMA of a section.<br>
<br>
For example there is some linker script like this:<br>
<br>
SECTIONS<br>
{<br>
. = 0X80100000;<br>
.text : AT(0x100000) {<br>
*(.text .stub .text.* .gnu.linkonce.t.*)<br>
}<br>
<br>
... blah blah ...<br>
}<br>
<br>
Now 0x8010000 is a VMA, and 0x100000 is a LMA.<br>
<br>
My question is, is LMA the same as the physical address in a ELF<br>
program header ? A typical ELF declaration would be something like<br>
this:<br>
<br>
typedef struct<br>
{<br>
Elf32_Word p_type; /* Segment type */<br>
Elf32_Off p_offset; /* Segment file offset */<br>
Elf32_Addr p_vaddr; /* Segment virtual address */<br>
Elf32_Addr p_paddr; /* Segment physical address */<br>
Elf32_Word p_filesz; /* Segment size in file */<br>
Elf32_Word p_memsz; /* Segment size in memory */<br>
Elf32_Word p_flags; /* Segment flags */<br>
Elf32_Word p_align; /* Segment alignment */<br>
} Elf32_Phdr;<br>
<br>
Is LMA just **p_paddr** in the program header?<br>
<br></div></div></blockquote></blockquote><div>...snip... </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="h5"></div></div></blockquote>
Thank you for replying. I think I understand what you mean.<br>
But I still want the answer to my question, that is, is LMA just **p_paddr** in the program header?<br></blockquote><div><br></div><div>I'm pretty sure that's the case. There are actually 2 sets of headers. You can use:</div><div><br></div><div>objdump -p foo.elf</div><div><br></div><div>to view the "private" headers which shows you the p_vaddr and p_paddr fields.</div><div><br></div><div>And you can use</div><div><br></div><div>objdump -h foo.elf</div><div><br></div><div>to view the section headers.</div><div><br></div><div>Here's some example output for a typical embedded program:<br></div><div><br></div><div><div>2216 >objdump -p firmware.elf <br></div><div><br></div><div>firmware.elf: file format elf32-little</div><div><br></div><div>Program Header:</div><div> LOAD off 0x00008000 vaddr 0x08000000 paddr 0x08000000 align 2**15</div><div> filesz 0x0000288c memsz 0x0000288c flags r-x</div><div> LOAD off 0x00010000 vaddr 0x08020000 paddr 0x08020000 align 2**15</div><div> filesz 0x00040470 memsz 0x00040470 flags r-x</div><div> LOAD off 0x00058000 vaddr 0x20000000 paddr 0x08060470 align 2**15</div><div> filesz 0x00000108 memsz 0x000064f0 flags rw-</div><div> LOAD off 0x0005e4f0 vaddr 0x200064f0 paddr 0x08060578 align 2**15</div><div> filesz 0x00000000 memsz 0x00004000 flags rw-</div><div> LOAD off 0x0005a4f0 vaddr 0x2000a4f0 paddr 0x08060578 align 2**15</div><div> filesz 0x00000000 memsz 0x00000800 flags rw-</div><div><br></div><div>2217 >objdump -h firmware.elf <br></div><div><br></div><div>firmware.elf: file format elf32-little</div><div><br></div><div>Sections:</div><div>Idx Name Size VMA LMA File off Algn</div><div> 0 .isr_vector 0000288c 08000000 08000000 00008000 2**2</div><div> CONTENTS, ALLOC, LOAD, READONLY, CODE</div><div> 1 .text 00040470 08020000 08020000 00010000 2**2</div><div> CONTENTS, ALLOC, LOAD, READONLY, CODE</div><div> 2 .data 00000108 20000000 08060470 00058000 2**2</div><div> CONTENTS, ALLOC, LOAD, DATA</div><div> 3 .bss 000063e8 20000108 08060578 00058108 2**2</div><div> ALLOC</div><div> 4 .heap 00004000 200064f0 08060578 0005e4f0 2**0</div><div> ALLOC</div><div> 5 .stack 00000800 2000a4f0 08060578 0005a4f0 2**0</div><div> ALLOC</div><div> 6 .ARM.attributes 00000037 00000000 00000000 00058108 2**0</div><div> CONTENTS, READONLY</div><div> 7 .comment 000000e0 00000000 00000000 0005813f 2**0</div><div> CONTENTS, READONLY</div></div></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Dave Hylands<br>Shuswap, BC, Canada<br><a href="http://www.davehylands.com" target="_blank">http://www.davehylands.com</a></div>
</div></div>