Index: lld/trunk/ELF/Target.h =================================================================== --- lld/trunk/ELF/Target.h +++ lld/trunk/ELF/Target.h @@ -57,6 +57,11 @@ 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 Index: lld/trunk/ELF/Target.cpp =================================================================== --- lld/trunk/ELF/Target.cpp +++ lld/trunk/ELF/Target.cpp @@ -239,6 +239,7 @@ 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::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 @@ } template +bool MipsTargetInfo::isHintReloc(uint32_t Type) const { + return Type == R_MIPS_JALR; +} + +template bool MipsTargetInfo::isRelRelative(uint32_t Type) const { switch (Type) { default: Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -210,6 +210,10 @@ 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; Index: lld/trunk/test/ELF/mips-jalr.test =================================================================== --- lld/trunk/test/ELF/mips-jalr.test +++ lld/trunk/test/ELF/mips-jalr.test @@ -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