diff options
-rw-r--r-- | lld/ELF/Target.cpp | 8 | ||||
-rw-r--r-- | lld/ELF/Target.h | 5 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 4 | ||||
-rw-r--r-- | lld/test/ELF/mips-jalr.test | 4 |
4 files changed, 21 insertions, 0 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 10ce7255037..9aa804c6c5a 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -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 Type, const SymbolBody &S) const { 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(uint8_t *Loc, uint8_t *BufEnd, } 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: diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index e9c5f4b31ae..a3040831685 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -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 diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index fbecfc601ac..5c00eb5c4a5 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -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; diff --git a/lld/test/ELF/mips-jalr.test b/lld/test/ELF/mips-jalr.test index 4bdf8b6e7f0..fca82e836a5 100644 --- a/lld/test/ELF/mips-jalr.test +++ b/lld/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 |