[lld] r273346 - Do not scan relocations twice for MIPS.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 17:57:09 PDT 2016


Author: ruiu
Date: Tue Jun 21 19:57:09 2016
New Revision: 273346

URL: http://llvm.org/viewvc/llvm-project?rev=273346&view=rev
Log:
Do not scan relocations twice for MIPS.

Previously, relocations for MIPS were scanned twice; once in regular
scanRelocs() and the other is in scanRelocsForThunks. In the former
function, we computed types of relocations and skipped R_THUNK relocations.
In the latter function, we computed the same value again and skipped
all but R_THUNK relocations. It was wasteful. This patch fixes that.
Now R_THUNK relocations are handled in the regular manner.

Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=273346&r1=273345&r2=273346&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jun 21 19:57:09 2016
@@ -179,23 +179,6 @@ static unsigned handleTlsRelocation(uint
   return 0;
 }
 
-// Some targets might require creation of thunks for relocations. Now we
-// support only MIPS which requires LA25 thunk to call PIC code from non-PIC
-// one. Scan relocations to find each one requires thunk.
-template <class ELFT, class RelTy>
-static void scanRelocsForThunks(const elf::ObjectFile<ELFT> &File,
-                                ArrayRef<RelTy> Rels) {
-  for (const RelTy &RI : Rels) {
-    uint32_t Type = RI.getType(Config->Mips64EL);
-    SymbolBody &Body = File.getRelocTargetSym(RI);
-    if (Body.hasThunk() || !Target->needsThunk(Type, File, Body))
-      continue;
-    auto *D = cast<DefinedRegular<ELFT>>(&Body);
-    auto *S = cast<InputSection<ELFT>>(D->Section);
-    S->addThunk(Body);
-  }
-}
-
 template <endianness E> static int16_t readSignedLo16(const uint8_t *Loc) {
   return read32<E>(Loc) & 0xffff;
 }
@@ -577,8 +560,17 @@ static void scanRelocs(InputSectionBase<
       continue;
     }
 
-    if (Expr == R_THUNK)
+    // Some targets might require creation of thunks for relocations.
+    // Now we support only MIPS which requires LA25 thunk to call PIC
+    // code from non-PIC one.
+    if (Expr == R_THUNK) {
+      if (!Body.hasThunk()) {
+        auto *Sec = cast<InputSection<ELFT>>(
+            cast<DefinedRegular<ELFT>>(&Body)->Section);
+        Sec->addThunk(Body);
+      }
       continue;
+    }
 
     // At this point we are done with the relocated position. Some relocations
     // also require us to create a got or plt entry.
@@ -631,10 +623,6 @@ static void scanRelocs(InputSectionBase<
       continue;
     }
   }
-
-  // Scan relocations for necessary thunks.
-  if (Config->EMachine == EM_MIPS)
-    scanRelocsForThunks<ELFT>(File, Rels);
 }
 
 template <class ELFT> void scanRelocations(InputSection<ELFT> &C) {




More information about the llvm-commits mailing list