From f50f96be5dc098d05c47aaaded0d58ed6393847c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 17 Dec 2015 15:08:24 +0000 Subject: [PATCH] Always sort by offset first. NFC. 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 | 16 ++++++++++++++++ lib/MC/MCELFObjectTargetWriter.cpp | 16 ---------------- .../Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 3 --- .../MCTargetDesc/SystemZMCObjectWriter.cpp | 3 --- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index df7a606a717..a92b049d898 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -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 &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); diff --git a/lib/MC/MCELFObjectTargetWriter.cpp b/lib/MC/MCELFObjectTargetWriter.cpp index bc0ba85a8ff..de645cac737 100644 --- a/lib/MC/MCELFObjectTargetWriter.cpp +++ b/lib/MC/MCELFObjectTargetWriter.cpp @@ -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 &Relocs) { - array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel); } diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 864188670a9..a01c2f8afe0 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -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 MipsRelocs; for (unsigned I = 0, E = Relocs.size(); I != E; ++I) diff --git a/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp b/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp index 76a00fccbef..2f19127d686 100644 --- a/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp +++ b/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp @@ -156,9 +156,6 @@ unsigned SystemZObjectWriter::GetRelocType(const MCValue &Target, void SystemZObjectWriter::sortRelocs(const MCAssembler &Asm, std::vector &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, -- 2.34.1