[lld] r257798 - [ELF][MIPS] Ignore 'hint' relocations like R_MIPS_JALR in the `scanRelocs` method

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 12:42:10 PST 2016


Author: atanasyan
Date: Thu Jan 14 14:42:09 2016
New Revision: 257798

URL: http://llvm.org/viewvc/llvm-project?rev=257798&view=rev
Log:
[ELF][MIPS] Ignore 'hint' relocations like R_MIPS_JALR in the `scanRelocs` method

MIPS ABI has relocations like R_MIPS_JALR which is just a hint for
linker to make some code optimization. Such relocations should not be
handled as a regular ones and lead to say dynamic relocation creation.

The patch introduces new virtual `Target::isHintReloc` method, overrides
it in the `MipsTargetInfo` class and calls it in the `Writer<ELFT>::scanRelocs`
method.

Differential Revision: http://reviews.llvm.org/D16193

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/mips-jalr.test

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=257798&r1=257797&r2=257798&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Jan 14 14:42:09 2016
@@ -239,6 +239,7 @@ public:
   void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
                    uint64_t SA, uint64_t ZA = 0,
                    uint8_t *PairedLoc = nullptr) const override;
+  bool isHintReloc(uint32_t Type) const override;
   bool isRelRelative(uint32_t Type) const override;
 };
 } // anonymous namespace
@@ -284,6 +285,8 @@ bool TargetInfo::needsCopyRel(uint32_t T
 
 bool TargetInfo::isGotRelative(uint32_t Type) const { return false; }
 
+bool TargetInfo::isHintReloc(uint32_t Type) const { return false; }
+
 bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
 
 bool TargetInfo::isSizeReloc(uint32_t Type) const { return false; }
@@ -1581,6 +1584,11 @@ void MipsTargetInfo<ELFT>::relocateOne(u
 }
 
 template <class ELFT>
+bool MipsTargetInfo<ELFT>::isHintReloc(uint32_t Type) const {
+  return Type == R_MIPS_JALR;
+}
+
+template <class ELFT>
 bool MipsTargetInfo<ELFT>::isRelRelative(uint32_t Type) const {
   switch (Type) {
   default:

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=257798&r1=257797&r2=257798&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Jan 14 14:42:09 2016
@@ -57,6 +57,11 @@ public:
                              uint64_t GotEntryAddr, uint64_t PltEntryAddr,
                              int32_t Index, unsigned RelOff) const = 0;
 
+  // Returns true if a relocation is just a hint for linker to make for example
+  // some code optimization. Such relocations should not be handled as a regular
+  // ones and lead to dynamic relocation creation etc.
+  virtual bool isHintReloc(uint32_t Type) const;
+
   // Returns true if a relocation is relative to the place being relocated,
   // such as relocations used for PC-relative instructions. Such relocations
   // need not be fixed up if an image is loaded to a different address than

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=257798&r1=257797&r2=257798&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Jan 14 14:42:09 2016
@@ -210,6 +210,10 @@ void Writer<ELFT>::scanRelocs(
     SymbolBody *Body = File.getSymbolBody(SymIndex);
     uint32_t Type = RI.getType(Config->Mips64EL);
 
+    // Ignore "hint" relocation because it is for optional code optimization.
+    if (Target->isHintReloc(Type))
+      continue;
+
     if (Target->isGotRelative(Type))
       HasGotOffRel = true;
 

Modified: lld/trunk/test/ELF/mips-jalr.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-jalr.test?rev=257798&r1=257797&r2=257798&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-jalr.test (original)
+++ lld/trunk/test/ELF/mips-jalr.test Thu Jan 14 14:42:09 2016
@@ -3,11 +3,15 @@
 # RUN: yaml2obj -format elf %s -o %t.o
 # RUN: ld.lld %t.o -o %t.so -shared
 # RUN: llvm-objdump -d %t.so | FileCheck %s
+# RUN: llvm-readobj -relocations %t.so | FileCheck -check-prefix=REL %s
 
 # REQUIRES: mips
 
 # CHECK: 10000:   09 f8 20 03   jalr    $25
 
+# REL:      Relocations [
+# REL-NEXT: ]
+
 FileHeader:
   Class:    ELFCLASS32
   Data:     ELFDATA2LSB




More information about the llvm-commits mailing list