summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCELFObjectTargetWriter.cpp
diff options
context:
space:
mode:
authorPetar Jovanovic <petar.jovanovic@imgtec.com>2015-04-14 13:23:34 +0000
committerPetar Jovanovic <petar.jovanovic@imgtec.com>2015-04-14 13:23:34 +0000
commit0380d0b88f8f5101a9b9ec366b769c61e54e1217 (patch)
tree70379c8c9e7bf85694a250e73364167d2b6dc6e0 /llvm/lib/MC/MCELFObjectTargetWriter.cpp
parent1dbc317736ce52ce7239d6a1099456e8eac7bcd8 (diff)
downloadbcm5719-llvm-0380d0b88f8f5101a9b9ec366b769c61e54e1217.tar.gz
bcm5719-llvm-0380d0b88f8f5101a9b9ec366b769c61e54e1217.zip
Re-enable target-specific relocation table sorting and use it for Mips
Some targets (ie. Mips) have additional rules for ordering the relocation table entries. Allow them to override generic sortRelocs(), which sorts entries by Offset. Then override this function for Mips, to emit HI16 and GOT16 relocations against the local symbol in pair with the corresponding LO16 relocation. Patch by Vladimir Stefanovic. Differential Revision: http://reviews.llvm.org/D7414 llvm-svn: 234883
Diffstat (limited to 'llvm/lib/MC/MCELFObjectTargetWriter.cpp')
-rw-r--r--llvm/lib/MC/MCELFObjectTargetWriter.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCELFObjectTargetWriter.cpp b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
index 84176dc1e90..dc3d6c35489 100644
--- a/llvm/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
@@ -28,3 +28,24 @@ bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCSymbolData &SD,
unsigned Type) const {
return false;
}
+
+// ELF doesn't require relocations to be in any order. We sort by the Offset,
+// just to match gnu as for easier comparison. The use type is an arbitrary way
+// of making the sort deterministic.
+static int cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) {
+ const ELFRelocationEntry &A = *AP;
+ const ELFRelocationEntry &B = *BP;
+ if (A.Offset != B.Offset)
+ return B.Offset - A.Offset;
+ if (B.Type != A.Type)
+ return A.Type - B.Type;
+ //llvm_unreachable("ELFRelocs might be unstable!");
+ return 0;
+}
+
+
+void
+MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
+ std::vector<ELFRelocationEntry> &Relocs) {
+ array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);
+}
OpenPOWER on IntegriCloud