summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCELFObjectTargetWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-05-15 18:22:01 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-05-15 18:22:01 +0000
commit0f2a6fe613a6b5f196e84412baa1251a0b5e4ff0 (patch)
tree84ee2135830220103cdce35775a3cf57fa9fcfb4 /llvm/lib/MC/MCELFObjectTargetWriter.cpp
parent519188414e9a2a1999887c56b6aa5fefc0cc826f (diff)
downloadbcm5719-llvm-0f2a6fe613a6b5f196e84412baa1251a0b5e4ff0.tar.gz
bcm5719-llvm-0f2a6fe613a6b5f196e84412baa1251a0b5e4ff0.zip
Cleanup relocation sorting for ELF.
We want the order to be deterministic on all platforms. NAKAMURA Takumi fixed that in r181864. This patch is just two small cleanups: * Move the function to the cpp file. It is only passed to array_pod_sort. * Remove the ppc implementation which is now redundant llvm-svn: 181910
Diffstat (limited to 'llvm/lib/MC/MCELFObjectTargetWriter.cpp')
-rw-r--r--llvm/lib/MC/MCELFObjectTargetWriter.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCELFObjectTargetWriter.cpp b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
index dc2a949807b..ec7397d748f 100644
--- a/llvm/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
@@ -39,9 +39,23 @@ const MCSymbol *MCELFObjectTargetWriter::undefinedExplicitRelSym(const MCValue &
return &Symbol.AliasedSymbol();
}
+// ELF doesn't require relocations to be in any order. We sort by the r_offset,
+// just to match gnu as for easier comparison. The use type and index is an
+// arbitrary way of making the sort deterministic.
+static int cmpRel(const void *AP, const void *BP) {
+ const ELFRelocationEntry &A = *(const ELFRelocationEntry *)AP;
+ const ELFRelocationEntry &B = *(const ELFRelocationEntry *)BP;
+ if (A.r_offset != B.r_offset)
+ return B.r_offset - A.r_offset;
+ if (B.Type != A.Type)
+ return A.Type - B.Type;
+ if (B.Index != A.Index)
+ return B.Index - A.Index;
+ llvm_unreachable("ELFRelocs might be unstable!");
+}
+
void
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
std::vector<ELFRelocationEntry> &Relocs) {
- // Sort by the r_offset, just like gnu as does.
- array_pod_sort(Relocs.begin(), Relocs.end());
+ array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);
}
OpenPOWER on IntegriCloud