summaryrefslogtreecommitdiff
path: root/lib/MC
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
commit4ef61f2ad4ff509ee05c7051d359009511f81226 (patch)
treee6c816c11259d210dbe2c5518f3c4d217d1d5a59 /lib/MC
parent9d86f9cc3ab4db75b388c2761bf3dd205f84a6d8 (diff)
downloadllvm-4ef61f2ad4ff509ee05c7051d359009511f81226.tar.gz
llvm-4ef61f2ad4ff509ee05c7051d359009511f81226.tar.bz2
llvm-4ef61f2ad4ff509ee05c7051d359009511f81226.tar.xz
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181910 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCELFObjectTargetWriter.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/MC/MCELFObjectTargetWriter.cpp b/lib/MC/MCELFObjectTargetWriter.cpp
index dc2a949807..ec7397d748 100644
--- a/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/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);
}