[PATCH] D31660: [LLD][ELF] Allow multiple thunks to be added for a symbol.

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 04:08:42 PDT 2017


peter.smith created this revision.

This change permits there to be more than one thunk to be associated with a symbol. For interworking thunks we only require one thunk, but range extension thunks may require more than one.


https://reviews.llvm.org/D31660

Files:
  ELF/Relocations.cpp
  ELF/Relocations.h


Index: ELF/Relocations.h
===================================================================
--- ELF/Relocations.h
+++ ELF/Relocations.h
@@ -131,14 +131,16 @@
   ThunkSection *addThunkSection(OutputSection *OS, uint64_t Off);
 
   uint32_t Pass = 0;
-  // Track Symbols that already have a Thunk
-  llvm::DenseMap<SymbolBody *, Thunk *> ThunkedSymbols;
+  // Record all the available Thunks for a Symbol
+  llvm::DenseMap<SymbolBody *, std::vector<Thunk *>> ThunkedSymbols;
   // Find a Thunk from the Thunks symbol definition, we can use this to find
   // the Thunk from a relocation to the Thunks symbol definition.
   llvm::DenseMap<SymbolBody *, Thunk *> Thunks;
-  // Track InputSections that have a ThunkSection placed in front
+  // Track InputSections that have an inline ThunkSection placed in front
+  // an inline ThunkSection may have control fall through to the section below
+  // so we need to make sure that there is only one of them.
+  // The Mips LA25 Thunk is an example of an inline ThunkSection.
   llvm::DenseMap<InputSection *, ThunkSection *> ThunkedSections;
-
   // All the ThunkSections that we have created, organised by OutputSection
   // will contain a mix of ThunkSections that have been created this pass, and
   // ThunkSections that have been merged into the OutputSection on previous
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -1000,10 +1000,20 @@
 template <class ELFT>
 std::pair<Thunk *, bool> ThunkCreator<ELFT>::getThunk(SymbolBody &Body,
                                                       uint32_t Type) {
-  auto res = ThunkedSymbols.insert({&Body, nullptr});
-  if (res.second == true || !res.first->second->compatibleWith(Type))
-    res.first->second = addThunk<ELFT>(Type, Body);
-  return std::make_pair(res.first->second, res.second);
+  Thunk *T = nullptr;
+  auto Res = ThunkedSymbols.insert({&Body, std::vector<Thunk *>()});
+  if (Res.second == false) {
+    // Check existing Thunks for Body to see if they can be reused
+    for (Thunk *ET : Res.first->second)
+      if (ET->compatibleWith(Type)) {
+        T = ET;
+        return std::make_pair(T, Res.second);
+      }
+  }
+  // No existing compatible Thunk in range, create a new one
+  T = addThunk<ELFT>(Type, Body);
+  Res.first->second.push_back(T);
+  return std::make_pair(T, true);
 }
 
 // Make a new ThunkSection at offset Off and it to the persistent and per pass


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31660.94039.patch
Type: text/x-patch
Size: 2494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/1a2b797e/attachment.bin>


More information about the llvm-commits mailing list