[lld] r221539 - [Mips] Do not hard-code the paired relocation type

Simon Atanasyan simon at atanasyan.com
Fri Nov 7 11:32:08 PST 2014


Author: atanasyan
Date: Fri Nov  7 13:32:08 2014
New Revision: 221539

URL: http://llvm.org/viewvc/llvm-project?rev=221539&view=rev
Log:
[Mips] Do not hard-code the paired relocation type

Request `getPairRelocation()` function to get paired relocation type.
That allows us to look up another pairs like R_MICROMIPS_HI16/LO16
in the future.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=221539&r1=221538&r2=221539&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Fri Nov  7 13:32:08 2014
@@ -180,9 +180,10 @@ private:
           rit->getType(isMips64EL()), rit->getSymbol(isMips64EL())));
 
       auto addend = readAddend(*rit, secContent);
-      if (needsMatchingRelocation(*rit)) {
+      auto pairRelType = getPairRelocation(*rit);
+      if (pairRelType != llvm::ELF::R_MIPS_NONE) {
         addend <<= 16;
-        auto mit = findMatchingRelocation(rit, eit);
+        auto mit = findMatchingRelocation(pairRelType, rit, eit);
         if (mit != eit)
           addend += int16_t(readAddend(*mit, secContent));
         else
@@ -219,21 +220,24 @@ private:
     }
   }
 
-  bool needsMatchingRelocation(const Elf_Rel &rel) {
-    auto rType = rel.getType(isMips64EL());
-    if (rType == llvm::ELF::R_MIPS_HI16)
-      return true;
-    if (rType == llvm::ELF::R_MIPS_GOT16) {
+  uint32_t getPairRelocation(const Elf_Rel &rel) {
+    switch (rel.getType(isMips64EL())) {
+    case llvm::ELF::R_MIPS_HI16:
+      return llvm::ELF::R_MIPS_LO16;
+    case llvm::ELF::R_MIPS_GOT16: {
       const Elf_Sym *symbol =
           this->_objFile->getSymbol(rel.getSymbol(isMips64EL()));
-      return symbol->getBinding() == llvm::ELF::STB_LOCAL;
+      if (symbol->getBinding() == llvm::ELF::STB_LOCAL)
+        return llvm::ELF::R_MIPS_LO16;
+    }
     }
-    return false;
+    return llvm::ELF::R_MIPS_NONE;
   }
 
-  Elf_Rel_Iter findMatchingRelocation(Elf_Rel_Iter rit, Elf_Rel_Iter eit) {
+  Elf_Rel_Iter findMatchingRelocation(uint32_t pairRelType, Elf_Rel_Iter rit,
+                                      Elf_Rel_Iter eit) {
     return std::find_if(rit, eit, [&](const Elf_Rel &rel) {
-      return rel.getType(isMips64EL()) == llvm::ELF::R_MIPS_LO16 &&
+      return rel.getType(isMips64EL()) == pairRelType &&
              rel.getSymbol(isMips64EL()) == rit->getSymbol(isMips64EL());
     });
   }





More information about the llvm-commits mailing list