[PATCH] D16193: [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 08:57:16 PST 2016
atanasyan created this revision.
atanasyan added reviewers: ruiu, rafael.
atanasyan added a subscriber: llvm-commits.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
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.
Repository:
rL LLVM
http://reviews.llvm.org/D16193
Files:
ELF/Target.cpp
ELF/Target.h
ELF/Writer.cpp
test/ELF/mips-jalr.test
Index: test/ELF/mips-jalr.test
===================================================================
--- test/ELF/mips-jalr.test
+++ 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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -212,6 +212,9 @@
SymbolBody *Body = File.getSymbolBody(SymIndex);
uint32_t Type = RI.getType(Config->Mips64EL);
+ if (Target->isHintReloc(Type))
+ continue;
+
if (Target->isGotRelative(Type))
HasGotOffRel = true;
Index: ELF/Target.h
===================================================================
--- ELF/Target.h
+++ 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: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ 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 <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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16193.44892.patch
Type: text/x-patch
Size: 2768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160114/0bb273db/attachment.bin>
More information about the llvm-commits
mailing list