Always sort by offset first. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 17 Dec 2015 15:08:24 +0000 (15:08 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 17 Dec 2015 15:08:24 +0000 (15:08 +0000)
Every target changing sortRelocs was first calling the parent
implementation. Just run that first.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255898 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
lib/MC/MCELFObjectTargetWriter.cpp
lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp

index df7a606a717fb0a92cb4dfd50178bbedbc6af226..a92b049d8985215db2c158d26a9bc835a17c2d09 100644 (file)
@@ -1046,10 +1046,26 @@ void ELFObjectWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
   WriteWord(EntrySize); // sh_entsize
 }
 
+// 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 ELFObjectWriter::writeRelocations(const MCAssembler &Asm,
                                        const MCSectionELF &Sec) {
   std::vector<ELFRelocationEntry> &Relocs = Relocations[&Sec];
 
+  array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);
+
   // Sort the relocation entries. Most targets just sort by Offset, but some
   // (e.g., MIPS) have additional constraints.
   TargetObjectWriter->sortRelocs(Asm, Relocs);
index bc0ba85a8ff62c10673968484f4115fd54ad4626..de645cac73709f86c73ee75cfcec55d282732bac 100644 (file)
@@ -29,23 +29,7 @@ bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
   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);
 }
index 864188670a9e8cb5083e0b9fe1519f0832851d6e..a01c2f8afe07332d0946e4d684f8eb71e80c95d5 100644 (file)
@@ -332,9 +332,6 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
   if (Relocs.size() < 2)
     return;
 
-  // The default function sorts entries by Offset in descending order.
-  MCELFObjectTargetWriter::sortRelocs(Asm, Relocs);
-
   // Init MipsRelocs from Relocs.
   std::vector<MipsRelocationEntry> MipsRelocs;
   for (unsigned I = 0, E = Relocs.size(); I != E; ++I)
index 76a00fccbef0ff462f6fc5786d827d4e0c6f3f78..2f19127d6869d272499d191cb9e20684fa5295c2 100644 (file)
@@ -156,9 +156,6 @@ unsigned SystemZObjectWriter::GetRelocType(const MCValue &Target,
 
 void SystemZObjectWriter::sortRelocs(const MCAssembler &Asm,
                                      std::vector<ELFRelocationEntry> &Relocs) {
-  // The default function sorts entries by Offset in descending order.
-  MCELFObjectTargetWriter::sortRelocs(Asm, Relocs);
-
   // This is OK for SystemZ, except for R_390_TLS_GDCALL/LDCALL relocs.
   // There is typically another reloc, a R_390_PLT32DBL, on the same
   // instruction.  This other reloc must come *before* the GDCALL reloc,