<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 17, 2015 at 8:22 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 10:22:06 2015<br>
New Revision: 255902<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255902&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255902&view=rev</a><br>
Log:<br>
Avoid explicit relocation sorting most of the time.<br>
<br>
These days relocations are created and stored in a deterministic way.<br>
The order they are created is also suitable for the .o file, so we don't<br>
need an explicit sort.<br>
<br>
The last remaining exception is MIPS.<br>
<br>
Modified:<br>
llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp<br>
llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp<br>
llvm/trunk/test/MC/ARM/eh-compact-pr0.s<br>
llvm/trunk/test/MC/ARM/eh-compact-pr1.s<br>
llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s<br>
llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s<br>
llvm/trunk/test/MC/ARM/eh-directive-text-section.s<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=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Dec 17 10:22:06 2015<br>
@@ -1046,28 +1046,17 @@ 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>
-}<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>
+ // We record relocations by pushing to the end of a vector. Reverse the vector<br>
+ // to get the relocations in the order they were created.<br>
+ // In most cases that is not important, but it can be for special sections<br>
+ // (.eh_frame) or specific relocations (TLS optimizations on SystemZ).<br>
+ std::reverse(Relocs.begin(), Relocs.end());<br>
<br>
- // Sort the relocation entries. Most targets just sort by Offset, but some<br>
- // (e.g., MIPS) have additional constraints.<br>
+ // Sort the relocation entries. MIPS needs this.<br>
TargetObjectWriter->sortRelocs(Asm, Relocs);<br>
<br>
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {<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=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=255902&r1=255901&r2=255902&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 10:22:06 2015<br>
@@ -327,11 +327,25 @@ static void setMatch(MipsRelocationEntry<br>
// matching LO;<br>
// - prefer LOs without a pair;<br>
// - prefer LOs with higher offset;<br>
+<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>
+ return 0;<br></blockquote><div><br></div><div>This dropped the unreachable present in the prior version (which I just commented on as well) - intentionally?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,<br>
std::vector<ELFRelocationEntry> &Relocs) {<br>
if (Relocs.size() < 2)<br>
return;<br>
<br>
+ // Sorts entries by Offset in descending order.<br>
+ array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);<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=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp?rev=255902&r1=255901&r2=255902&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 10:22:06 2015<br>
@@ -26,8 +26,6 @@ protected:<br>
// Override MCELFObjectTargetWriter.<br>
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
bool IsPCRel) const override;<br>
- void sortRelocs(const MCAssembler &Asm,<br>
- std::vector<ELFRelocationEntry> &Relocs) override;<br>
};<br>
} // end anonymous namespace<br>
<br>
@@ -154,20 +152,6 @@ unsigned SystemZObjectWriter::GetRelocTy<br>
}<br>
}<br>
<br>
-void SystemZObjectWriter::sortRelocs(const MCAssembler &Asm,<br>
- std::vector<ELFRelocationEntry> &Relocs) {<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>
- // or else the TLS linker optimization may generate incorrect code.<br>
- for (unsigned i = 0, e = Relocs.size(); i + 1 < e; ++i) {<br>
- if ((Relocs[i + 1].Type == ELF::R_390_TLS_GDCALL ||<br>
- Relocs[i + 1].Type == ELF::R_390_TLS_LDCALL) &&<br>
- Relocs[i].Offset == Relocs[i + 1].Offset + 2)<br>
- std::swap(Relocs[i], Relocs[i + 1]);<br>
- }<br>
-}<br>
-<br>
MCObjectWriter *llvm::createSystemZObjectWriter(raw_pwrite_stream &OS,<br>
uint8_t OSABI) {<br>
MCELFObjectTargetWriter *MOTW = new SystemZObjectWriter(OSABI);<br>
<br>
Modified: llvm/trunk/test/MC/ARM/eh-compact-pr0.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-compact-pr0.s?rev=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-compact-pr0.s?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/eh-compact-pr0.s (original)<br>
+++ llvm/trunk/test/MC/ARM/eh-compact-pr0.s Thu Dec 17 10:22:06 2015<br>
@@ -68,8 +68,8 @@ func2:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.TEST1<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
@@ -105,7 +105,7 @@ func2:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.TEST2<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .TEST2 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .TEST2 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
Modified: llvm/trunk/test/MC/ARM/eh-compact-pr1.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-compact-pr1.s?rev=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-compact-pr1.s?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/eh-compact-pr1.s (original)<br>
+++ llvm/trunk/test/MC/ARM/eh-compact-pr1.s Thu Dec 17 10:22:06 2015<br>
@@ -68,7 +68,7 @@ func1:<br>
@ will keep __aeabi_unwind_cpp_pr1.<br>
@-------------------------------------------------------------------------------<br>
@ CHECK: Relocations [<br>
-@ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0<br>
+@ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0<br>
@ CHECK: ]<br>
<br>
Modified: llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s?rev=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s (original)<br>
+++ llvm/trunk/test/MC/ARM/eh-directive-handlerdata.s Thu Dec 17 10:22:06 2015<br>
@@ -48,8 +48,8 @@ func1:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.TEST1<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .TEST1 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
@@ -108,8 +108,8 @@ func2:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.TEST2<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .TEST2 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .TEST2 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.TEST2 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
Modified: llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s?rev=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s (original)<br>
+++ llvm/trunk/test/MC/ARM/eh-directive-personalityindex.s Thu Dec 17 10:22:06 2015<br>
@@ -28,8 +28,8 @@ pr0:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr0<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr0 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr0 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
@@ -57,8 +57,8 @@ pr0_nontrivial:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr0.nontrivial<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr0.nontrivial 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr0.nontrivial 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
@@ -90,8 +90,8 @@ pr1:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr1<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr1 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr1 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.pr1 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
@@ -127,8 +127,8 @@ pr1_nontrivial:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr1.nontrivial<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr1.nontrivial 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr1.nontrivial 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.pr1.nontrivial 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
@@ -161,8 +161,8 @@ pr2:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr2<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr2 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr2 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr2 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.pr2 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
@@ -196,8 +196,8 @@ pr2_nontrivial:<br>
@ RELOC: Section {<br>
@ RELOC: Name: .rel.ARM.exidx.pr2.nontrivial<br>
@ RELOC: Relocations [<br>
-@ RELOC: 0x0 R_ARM_PREL31 .pr2.nontrivial 0x0<br>
@ RELOC: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr2 0x0<br>
+@ RELOC: 0x0 R_ARM_PREL31 .pr2.nontrivial 0x0<br>
@ RELOC: 0x4 R_ARM_PREL31 .ARM.extab.pr2.nontrivial 0x0<br>
@ RELOC: ]<br>
@ RELOC: }<br>
<br>
Modified: llvm/trunk/test/MC/ARM/eh-directive-text-section.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-text-section.s?rev=255902&r1=255901&r2=255902&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-directive-text-section.s?rev=255902&r1=255901&r2=255902&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/eh-directive-text-section.s (original)<br>
+++ llvm/trunk/test/MC/ARM/eh-directive-text-section.s Thu Dec 17 10:22:06 2015<br>
@@ -77,6 +77,6 @@ func1:<br>
@ add an relocation to __aeabi_unwind_cpp_pr0.<br>
@-------------------------------------------------------------------------------<br>
@ CHECK: Relocations [<br>
-@ CHECK: 0x0 R_ARM_PREL31 .text 0x0<br>
@ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0<br>
+@ CHECK: 0x0 R_ARM_PREL31 .text 0x0<br>
@ CHECK: ]<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>