[PATCH] D20378: [lld] Wrong section VMA/LMA in case of using linker scripts

Dima Stepanov via llvm-commits llvm-commits at lists.llvm.org
Wed May 18 11:40:17 PDT 2016


dstepanov created this revision.
dstepanov added reviewers: rafael, ruiu.
dstepanov added a subscriber: llvm-commits.
dstepanov set the repository for this revision to rL LLVM.

This changes are introduced to fix the problem described in:
https://llvm.org/bugs/show_bug.cgi?id=27805
The idea is to add the cycle in the ELF/LinkerScript.cpp:assignAddresses() routine to go through all the sections and set all the addresses correctly.

Repository:
  rL LLVM

http://reviews.llvm.org/D20378

Files:
  ELF/LinkerScript.cpp

Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -239,23 +239,27 @@
       continue;
     }
 
-    OutputSectionBase<ELFT> *Sec = findSection<ELFT>(Sections, Cmd.SectionName);
-    if (!Sec)
-      continue;
-
-    if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
-      uintX_t TVA = Dot + ThreadBssOffset;
-      TVA = alignTo(TVA, Sec->getAlign());
-      Sec->setVA(TVA);
-      ThreadBssOffset = TVA - Dot + Sec->getSize();
-      continue;
-    }
+    // Find all the sections with required name. There can be more than
+    // ont section with such name, if the alignment, flags or type
+    // attribute differs.
+    for (OutputSectionBase<ELFT> *Sec : Sections) {
+      if (Sec->getName() != Cmd.SectionName)
+        continue;
+
+      if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
+        uintX_t TVA = Dot + ThreadBssOffset;
+        TVA = alignTo(TVA, Sec->getAlign());
+        Sec->setVA(TVA);
+        ThreadBssOffset = TVA - Dot + Sec->getSize();
+        continue;
+      }
 
-    if (Sec->getFlags() & SHF_ALLOC) {
-      Dot = alignTo(Dot, Sec->getAlign());
-      Sec->setVA(Dot);
-      Dot += Sec->getSize();
-      continue;
+      if (Sec->getFlags() & SHF_ALLOC) {
+        Dot = alignTo(Dot, Sec->getAlign());
+        Sec->setVA(Dot);
+        Dot += Sec->getSize();
+        continue;
+      }
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20378.57655.patch
Type: text/x-patch
Size: 1480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160518/3e4150a2/attachment.bin>


More information about the llvm-commits mailing list