summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-12-17 16:22:06 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-12-17 16:22:06 +0000
commitf44db24e1fd948c75c87aea017646f16553d3361 (patch)
treecf2e624f47b525837a756f0a601cf301cbdf92e2 /llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
parentad579928878bffb2ba8899e7f6e311ef8dcdccdb (diff)
downloadbcm5719-llvm-f44db24e1fd948c75c87aea017646f16553d3361.tar.gz
bcm5719-llvm-f44db24e1fd948c75c87aea017646f16553d3361.zip
Avoid explicit relocation sorting most of the time.
These days relocations are created and stored in a deterministic way. The order they are created is also suitable for the .o file, so we don't need an explicit sort. The last remaining exception is MIPS. llvm-svn: 255902
Diffstat (limited to 'llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp')
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index a01c2f8afe0..5b9f02b89be 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -327,11 +327,25 @@ static void setMatch(MipsRelocationEntry &Hi, MipsRelocationEntry &Lo) {
// matching LO;
// - prefer LOs without a pair;
// - prefer LOs with higher offset;
+
+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;
+ return 0;
+}
+
void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
std::vector<ELFRelocationEntry> &Relocs) {
if (Relocs.size() < 2)
return;
+ // Sorts entries by Offset in descending order.
+ array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);
+
// Init MipsRelocs from Relocs.
std::vector<MipsRelocationEntry> MipsRelocs;
for (unsigned I = 0, E = Relocs.size(); I != E; ++I)
OpenPOWER on IntegriCloud