summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.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/MC/ELFObjectWriter.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/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index a92b049d898..e6552beefd0 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1046,28 +1046,17 @@ 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);
+ // We record relocations by pushing to the end of a vector. Reverse the vector
+ // to get the relocations in the order they were created.
+ // In most cases that is not important, but it can be for special sections
+ // (.eh_frame) or specific relocations (TLS optimizations on SystemZ).
+ std::reverse(Relocs.begin(), Relocs.end());
- // Sort the relocation entries. Most targets just sort by Offset, but some
- // (e.g., MIPS) have additional constraints.
+ // Sort the relocation entries. MIPS needs this.
TargetObjectWriter->sortRelocs(Asm, Relocs);
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
OpenPOWER on IntegriCloud