[PATCH] D24298: [ELF] Linkerscript: Implement LOADADDR

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 03:19:22 PDT 2016


evgeny777 added inline comments.

================
Comment at: ELF/LinkerScript.cpp:435
@@ -425,2 +434,3 @@
 
+    Sec->setLMAOffset(LMAOff);
     if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
----------------
ruiu wrote:
> Do you need to set an LMA to sections without AT command?
Yes, because LMA and VMA might not be the same, even if there is no AT command for a section. See summary for this patch

================
Comment at: ELF/Writer.cpp:993-994
@@ -992,3 +992,4 @@
     uintX_t NewFlags = Sec->getPhdrFlags();
-    if (Script<ELFT>::X->getLma(Sec->getName()) || Flags != NewFlags) {
+    bHasLma = bHasLma || Script<ELFT>::X->hasLma(Sec->getName());
+    if (bHasLma || Flags != NewFlags) {
       Load = AddHdr(PT_LOAD, NewFlags);
----------------
grimar wrote:
> ruiu wrote:
> > Why do we have to create a new segment if there's a section with a LMA?
> You can write this as:
> 
> ```
> bHasLma |= Script<ELFT>::X->hasLma(Sec->getName())
> ```
There is no straight way to get LMA for section from section header. The header field sh_addr is VMA, not LMA. However tools like objdump and objcopy still can fetch LMA. They are doing this by examining segment table and fetching segment physical address in case segment virtual address matches section VMA. This means that if section LMA doesn't match VMA, it should have separate load segment in order to properly calculate LMA for them.


Repository:
  rL LLVM

https://reviews.llvm.org/D24298





More information about the llvm-commits mailing list