<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 17, 2015 at 7:08 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Dec 17 09:08:24 2015<br>
New Revision: 255898<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255898&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255898&view=rev</a><br>
Log:<br>
Always sort by offset first. NFC.<br>
<br>
Every target changing sortRelocs was first calling the parent<br>
implementation. Just run that first.<br>
<br>
Modified:<br>
llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp<br>
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp<br>
llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp<br>
<br>
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Dec 17 09:08:24 2015<br>
@@ -1046,10 +1046,26 @@ void ELFObjectWriter::WriteSecHdrEntry(u<br>
WriteWord(EntrySize); // sh_entsize<br>
}<br>
<br>
+// ELF doesn't require relocations to be in any order. We sort by the Offset,<br>
+// just to match gnu as for easier comparison. The use type is an arbitrary way<br>
+// of making the sort deterministic.<br>
+static int cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) {<br>
+ const ELFRelocationEntry &A = *AP;<br>
+ const ELFRelocationEntry &B = *BP;<br>
+ if (A.Offset != B.Offset)<br>
+ return B.Offset - A.Offset;<br>
+ if (B.Type != A.Type)<br>
+ return A.Type - B.Type;<br>
+ llvm_unreachable("ELFRelocs might be unstable!");<br>
+ return 0;<br></blockquote><div><br></div><div>Return after unreachable looks bogus.<br><br>Also return as an "else" looks a bit wrong. Perhaps the last 4 lines of this function should be phrased as:<br><br> assert(B.Type != A.Type)<br> return A.Type - B.Type;</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
void ELFObjectWriter::writeRelocations(const MCAssembler &Asm,<br>
const MCSectionELF &Sec) {<br>
std::vector<ELFRelocationEntry> &Relocs = Relocations[&Sec];<br>
<br>
+ array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);<br>
+<br>
// Sort the relocation entries. Most targets just sort by Offset, but some<br>
// (e.g., MIPS) have additional constraints.<br>
TargetObjectWriter->sortRelocs(Asm, Relocs);<br>
<br>
Modified: llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCELFObjectTargetWriter.cpp Thu Dec 17 09:08:24 2015<br>
@@ -29,23 +29,7 @@ bool MCELFObjectTargetWriter::needsReloc<br>
return false;<br>
}<br>
<br>
-// ELF doesn't require relocations to be in any order. We sort by the Offset,<br>
-// just to match gnu as for easier comparison. The use type is an arbitrary way<br>
-// of making the sort deterministic.<br>
-static int cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) {<br>
- const ELFRelocationEntry &A = *AP;<br>
- const ELFRelocationEntry &B = *BP;<br>
- if (A.Offset != B.Offset)<br>
- return B.Offset - A.Offset;<br>
- if (B.Type != A.Type)<br>
- return A.Type - B.Type;<br>
- //llvm_unreachable("ELFRelocs might be unstable!");<br>
- return 0;<br>
-}<br>
-<br>
-<br>
void<br>
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,<br>
std::vector<ELFRelocationEntry> &Relocs) {<br>
- array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);<br>
}<br>
<br>
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp Thu Dec 17 09:08:24 2015<br>
@@ -332,9 +332,6 @@ void MipsELFObjectWriter::sortRelocs(con<br>
if (Relocs.size() < 2)<br>
return;<br>
<br>
- // The default function sorts entries by Offset in descending order.<br>
- MCELFObjectTargetWriter::sortRelocs(Asm, Relocs);<br>
-<br>
// Init MipsRelocs from Relocs.<br>
std::vector<MipsRelocationEntry> MipsRelocs;<br>
for (unsigned I = 0, E = Relocs.size(); I != E; ++I)<br>
<br>
Modified: llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp?rev=255898&r1=255897&r2=255898&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp Thu Dec 17 09:08:24 2015<br>
@@ -156,9 +156,6 @@ unsigned SystemZObjectWriter::GetRelocTy<br>
<br>
void SystemZObjectWriter::sortRelocs(const MCAssembler &Asm,<br>
std::vector<ELFRelocationEntry> &Relocs) {<br>
- // The default function sorts entries by Offset in descending order.<br>
- MCELFObjectTargetWriter::sortRelocs(Asm, Relocs);<br>
-<br>
// This is OK for SystemZ, except for R_390_TLS_GDCALL/LDCALL relocs.<br>
// There is typically another reloc, a R_390_PLT32DBL, on the same<br>
// instruction. This other reloc must come *before* the GDCALL reloc,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>