[PATCH] D34345: [LLD][ELF] Reset any accumulated state before calculating addresses

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 03:49:37 PDT 2017


peter.smith created this revision.
Herald added a subscriber: emaste.

The assignAddresses() function accumulates state that prevents it from being called multiple times. This change resets any cached state before the calculation.

Together with https://reviews.llvm.org/D34344 this permits assignAddresses() to be called multiple times. It can then be used to calculate the addresses needed for range extension thunks. I've tested that this is sufficient by applying the changes in https://reviews.llvm.org/D34344 and making an additional redundant call to assignAddresses().


https://reviews.llvm.org/D34345

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h


Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -281,6 +281,7 @@
   void assignOffsets(OutputSectionCommand *Cmd);
   void createOrphanCommands();
   void processNonSectionCommands();
+  void resetAddressState();
   void assignAddresses();
   void allocateHeaders(std::vector<PhdrEntry> &Phdrs);
   void addSymbol(SymbolAssignment *Cmd);
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -834,9 +834,23 @@
   return;
 }
 
+// Reset the members associated with address assigment to their initial values
+// this permits addressAssignment to be run again.
+void LinkerScript::resetAddressState() {
+  LMAOffset = 0;
+  CurOutSec = nullptr;
+  CurMemRegion = nullptr;
+  ThreadBssOffset = 0;
+  for (auto &MRI : Opt.MemoryRegions) {
+    MemoryRegion &MR = MRI.second;
+    MR.Offset = MR.Origin;
+  }
+}
+
 void LinkerScript::assignAddresses() {
   // Assign addresses as instructed by linker script SECTIONS sub-commands.
   Dot = 0;
+  resetAddressState();
   ErrorOnMissingSection = true;
   switchTo(Aether);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34345.103008.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170619/4f1f5bd2/attachment.bin>


More information about the llvm-commits mailing list