[lld] r321105 - [WebAssembly] Apply data relocations in parallel. NFC.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 12:45:15 PST 2017
Author: sbc
Date: Tue Dec 19 12:45:15 2017
New Revision: 321105
URL: http://llvm.org/viewvc/llvm-project?rev=321105&view=rev
Log:
[WebAssembly] Apply data relocations in parallel. NFC.
Store data relocations with their respective segment.
This allows relocations to be applied as each segment
is written (and therefore in parallel).
Differential Revision: https://reviews.llvm.org/D41410
Modified:
lld/trunk/wasm/InputSegment.h
lld/trunk/wasm/OutputSections.cpp
lld/trunk/wasm/OutputSections.h
lld/trunk/wasm/OutputSegment.h
Modified: lld/trunk/wasm/InputSegment.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputSegment.h?rev=321105&r1=321104&r2=321105&view=diff
==============================================================================
--- lld/trunk/wasm/InputSegment.h (original)
+++ lld/trunk/wasm/InputSegment.h Tue Dec 19 12:45:15 2017
@@ -21,6 +21,7 @@
#ifndef LLD_WASM_INPUT_SEGMENT_H
#define LLD_WASM_INPUT_SEGMENT_H
+#include "WriterUtils.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Object/Wasm.h"
@@ -62,6 +63,7 @@ public:
const WasmSegment *Segment;
const ObjFile *File;
std::vector<WasmRelocation> Relocations;
+ std::vector<OutputRelocation> OutRelocations;
protected:
const OutputSegment *OutputSeg = nullptr;
Modified: lld/trunk/wasm/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.cpp?rev=321105&r1=321104&r2=321105&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.cpp (original)
+++ lld/trunk/wasm/OutputSections.cpp Tue Dec 19 12:45:15 2017
@@ -109,10 +109,11 @@ static void applyRelocation(uint8_t *Buf
}
static void applyRelocations(uint8_t *Buf, ArrayRef<OutputRelocation> Relocs) {
+ if (!Relocs.size())
+ return;
log("applyRelocations: count=" + Twine(Relocs.size()));
- for (const OutputRelocation &Reloc : Relocs) {
+ for (const OutputRelocation &Reloc : Relocs)
applyRelocation(Buf, Reloc);
- }
}
// Relocations contain an index into the function, global or table index
@@ -251,8 +252,7 @@ void CodeSection::writeTo(uint8_t *Buf)
PayloadSize);
log("applying relocations for: " + File->getName());
- if (File->CodeRelocations.size())
- applyRelocations(ContentsStart, File->CodeRelocations);
+ applyRelocations(ContentsStart, File->CodeRelocations);
});
}
@@ -288,13 +288,13 @@ DataSection::DataSection(ArrayRef<Output
Segment->setSectionOffset(BodySize);
BodySize += Segment->Header.size();
log("Data segment: size=" + Twine(Segment->Size));
- for (const InputSegment *InputSeg : Segment->InputSegments) {
+ for (InputSegment *InputSeg : Segment->InputSegments) {
uint32_t InputOffset = InputSeg->getInputSectionOffset();
uint32_t OutputOffset = Segment->getSectionOffset() +
Segment->Header.size() +
InputSeg->getOutputSegmentOffset();
- calcRelocations(*InputSeg->File, InputSeg->Relocations, Relocations,
- OutputOffset - InputOffset);
+ calcRelocations(*InputSeg->File, InputSeg->Relocations,
+ InputSeg->OutRelocations, OutputOffset - InputOffset);
}
BodySize += Segment->Size;
}
@@ -327,13 +327,22 @@ void DataSection::writeTo(uint8_t *Buf)
memcpy(SegStart + Segment->Header.size() +
Input->getOutputSegmentOffset(),
Content.data(), Content.size());
+ applyRelocations(ContentsStart, Input->OutRelocations);
}
});
+}
- applyRelocations(ContentsStart, Relocations);
+uint32_t DataSection::numRelocations() const {
+ uint32_t Count = 0;
+ for (const OutputSegment *Seg : Segments)
+ for (const InputSegment *InputSeg : Seg->InputSegments)
+ Count += InputSeg->OutRelocations.size();
+ return Count;
}
void DataSection::writeRelocations(raw_ostream &OS) const {
- for (const OutputRelocation &Reloc : Relocations)
- writeReloc(OS, Reloc);
+ for (const OutputSegment *Seg : Segments)
+ for (const InputSegment *InputSeg : Seg->InputSegments)
+ for (const OutputRelocation &Reloc : InputSeg->OutRelocations)
+ writeReloc(OS, Reloc);
}
Modified: lld/trunk/wasm/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.h?rev=321105&r1=321104&r2=321105&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.h (original)
+++ lld/trunk/wasm/OutputSections.h Tue Dec 19 12:45:15 2017
@@ -126,11 +126,10 @@ public:
explicit DataSection(ArrayRef<OutputSegment *> Segments);
size_t getSize() const override { return Header.size() + BodySize; }
void writeTo(uint8_t *Buf) override;
- uint32_t numRelocations() const override { return Relocations.size(); }
+ uint32_t numRelocations() const override;
void writeRelocations(raw_ostream &OS) const override;
protected:
- std::vector<OutputRelocation> Relocations;
ArrayRef<OutputSegment *> Segments;
std::string DataSectionHeader;
size_t BodySize = 0;
Modified: lld/trunk/wasm/OutputSegment.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSegment.h?rev=321105&r1=321104&r2=321105&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSegment.h (original)
+++ lld/trunk/wasm/OutputSegment.h Tue Dec 19 12:45:15 2017
@@ -38,7 +38,7 @@ public:
StringRef Name;
uint32_t Alignment = 0;
uint32_t StartVA = 0;
- std::vector<const InputSegment *> InputSegments;
+ std::vector<InputSegment *> InputSegments;
// Sum of the size of the all the input segments
uint32_t Size = 0;
More information about the llvm-commits
mailing list