diff options
Diffstat (limited to 'lld/wasm/OutputSections.cpp')
-rw-r--r-- | lld/wasm/OutputSections.cpp | 230 |
1 files changed, 115 insertions, 115 deletions
diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp index d5434b102cc..c019d89e447 100644 --- a/lld/wasm/OutputSections.cpp +++ b/lld/wasm/OutputSections.cpp @@ -23,8 +23,8 @@ using namespace llvm::wasm; using namespace lld; using namespace lld::wasm; -static StringRef sectionTypeToString(uint32_t SectionType) { - switch (SectionType) { +static StringRef sectionTypeToString(uint32_t sectionType) { + switch (sectionType) { case WASM_SEC_CUSTOM: return "CUSTOM"; case WASM_SEC_TYPE: @@ -59,192 +59,192 @@ static StringRef sectionTypeToString(uint32_t SectionType) { } // Returns a string, e.g. "FUNCTION(.text)". -std::string lld::toString(const OutputSection &Sec) { - if (!Sec.Name.empty()) - return (Sec.getSectionName() + "(" + Sec.Name + ")").str(); - return Sec.getSectionName(); +std::string lld::toString(const OutputSection &sec) { + if (!sec.name.empty()) + return (sec.getSectionName() + "(" + sec.name + ")").str(); + return sec.getSectionName(); } StringRef OutputSection::getSectionName() const { - return sectionTypeToString(Type); + return sectionTypeToString(type); } -void OutputSection::createHeader(size_t BodySize) { - raw_string_ostream OS(Header); - debugWrite(OS.tell(), "section type [" + getSectionName() + "]"); - encodeULEB128(Type, OS); - writeUleb128(OS, BodySize, "section size"); - OS.flush(); - log("createHeader: " + toString(*this) + " body=" + Twine(BodySize) + +void OutputSection::createHeader(size_t bodySize) { + raw_string_ostream os(header); + debugWrite(os.tell(), "section type [" + getSectionName() + "]"); + encodeULEB128(type, os); + writeUleb128(os, bodySize, "section size"); + os.flush(); + log("createHeader: " + toString(*this) + " body=" + Twine(bodySize) + " total=" + Twine(getSize())); } void CodeSection::finalizeContents() { - raw_string_ostream OS(CodeSectionHeader); - writeUleb128(OS, Functions.size(), "function count"); - OS.flush(); - BodySize = CodeSectionHeader.size(); - - for (InputFunction *Func : Functions) { - Func->OutputOffset = BodySize; - Func->calculateSize(); - BodySize += Func->getSize(); + raw_string_ostream os(codeSectionHeader); + writeUleb128(os, functions.size(), "function count"); + os.flush(); + bodySize = codeSectionHeader.size(); + + for (InputFunction *func : functions) { + func->outputOffset = bodySize; + func->calculateSize(); + bodySize += func->getSize(); } - createHeader(BodySize); + createHeader(bodySize); } -void CodeSection::writeTo(uint8_t *Buf) { +void CodeSection::writeTo(uint8_t *buf) { log("writing " + toString(*this)); log(" size=" + Twine(getSize())); - log(" headersize=" + Twine(Header.size())); - log(" codeheadersize=" + Twine(CodeSectionHeader.size())); - Buf += Offset; + log(" headersize=" + Twine(header.size())); + log(" codeheadersize=" + Twine(codeSectionHeader.size())); + buf += offset; // Write section header - memcpy(Buf, Header.data(), Header.size()); - Buf += Header.size(); + memcpy(buf, header.data(), header.size()); + buf += header.size(); // Write code section headers - memcpy(Buf, CodeSectionHeader.data(), CodeSectionHeader.size()); + memcpy(buf, codeSectionHeader.data(), codeSectionHeader.size()); // Write code section bodies - for (const InputChunk *Chunk : Functions) - Chunk->writeTo(Buf); + for (const InputChunk *chunk : functions) + chunk->writeTo(buf); } uint32_t CodeSection::getNumRelocations() const { - uint32_t Count = 0; - for (const InputChunk *Func : Functions) - Count += Func->getNumRelocations(); - return Count; + uint32_t count = 0; + for (const InputChunk *func : functions) + count += func->getNumRelocations(); + return count; } -void CodeSection::writeRelocations(raw_ostream &OS) const { - for (const InputChunk *C : Functions) - C->writeRelocations(OS); +void CodeSection::writeRelocations(raw_ostream &os) const { + for (const InputChunk *c : functions) + c->writeRelocations(os); } void DataSection::finalizeContents() { - raw_string_ostream OS(DataSectionHeader); + raw_string_ostream os(dataSectionHeader); - writeUleb128(OS, Segments.size(), "data segment count"); - OS.flush(); - BodySize = DataSectionHeader.size(); + writeUleb128(os, segments.size(), "data segment count"); + os.flush(); + bodySize = dataSectionHeader.size(); - assert((!Config->Pic || Segments.size() <= 1) && + assert((!config->isPic || segments.size() <= 1) && "Currenly only a single data segment is supported in PIC mode"); - for (OutputSegment *Segment : Segments) { - raw_string_ostream OS(Segment->Header); - writeUleb128(OS, Segment->InitFlags, "init flags"); - if (Segment->InitFlags & WASM_SEGMENT_HAS_MEMINDEX) - writeUleb128(OS, 0, "memory index"); - if ((Segment->InitFlags & WASM_SEGMENT_IS_PASSIVE) == 0) { - WasmInitExpr InitExpr; - if (Config->Pic) { - InitExpr.Opcode = WASM_OPCODE_GLOBAL_GET; - InitExpr.Value.Global = WasmSym::MemoryBase->getGlobalIndex(); + for (OutputSegment *segment : segments) { + raw_string_ostream os(segment->header); + writeUleb128(os, segment->initFlags, "init flags"); + if (segment->initFlags & WASM_SEGMENT_HAS_MEMINDEX) + writeUleb128(os, 0, "memory index"); + if ((segment->initFlags & WASM_SEGMENT_IS_PASSIVE) == 0) { + WasmInitExpr initExpr; + if (config->isPic) { + initExpr.Opcode = WASM_OPCODE_GLOBAL_GET; + initExpr.Value.Global = WasmSym::memoryBase->getGlobalIndex(); } else { - InitExpr.Opcode = WASM_OPCODE_I32_CONST; - InitExpr.Value.Int32 = Segment->StartVA; + initExpr.Opcode = WASM_OPCODE_I32_CONST; + initExpr.Value.Int32 = segment->startVA; } - writeInitExpr(OS, InitExpr); + writeInitExpr(os, initExpr); } - writeUleb128(OS, Segment->Size, "segment size"); - OS.flush(); + writeUleb128(os, segment->size, "segment size"); + os.flush(); - Segment->SectionOffset = BodySize; - BodySize += Segment->Header.size() + Segment->Size; - log("Data segment: size=" + Twine(Segment->Size) + ", startVA=" + - Twine::utohexstr(Segment->StartVA) + ", name=" + Segment->Name); + segment->sectionOffset = bodySize; + bodySize += segment->header.size() + segment->size; + log("Data segment: size=" + Twine(segment->size) + ", startVA=" + + Twine::utohexstr(segment->startVA) + ", name=" + segment->name); - for (InputSegment *InputSeg : Segment->InputSegments) - InputSeg->OutputOffset = Segment->SectionOffset + Segment->Header.size() + - InputSeg->OutputSegmentOffset; + for (InputSegment *inputSeg : segment->inputSegments) + inputSeg->outputOffset = segment->sectionOffset + segment->header.size() + + inputSeg->outputSegmentOffset; } - createHeader(BodySize); + createHeader(bodySize); } -void DataSection::writeTo(uint8_t *Buf) { +void DataSection::writeTo(uint8_t *buf) { log("writing " + toString(*this) + " size=" + Twine(getSize()) + - " body=" + Twine(BodySize)); - Buf += Offset; + " body=" + Twine(bodySize)); + buf += offset; // Write section header - memcpy(Buf, Header.data(), Header.size()); - Buf += Header.size(); + memcpy(buf, header.data(), header.size()); + buf += header.size(); // Write data section headers - memcpy(Buf, DataSectionHeader.data(), DataSectionHeader.size()); + memcpy(buf, dataSectionHeader.data(), dataSectionHeader.size()); - for (const OutputSegment *Segment : Segments) { + for (const OutputSegment *segment : segments) { // Write data segment header - uint8_t *SegStart = Buf + Segment->SectionOffset; - memcpy(SegStart, Segment->Header.data(), Segment->Header.size()); + uint8_t *segStart = buf + segment->sectionOffset; + memcpy(segStart, segment->header.data(), segment->header.size()); // Write segment data payload - for (const InputChunk *Chunk : Segment->InputSegments) - Chunk->writeTo(Buf); + for (const InputChunk *chunk : segment->inputSegments) + chunk->writeTo(buf); } } uint32_t DataSection::getNumRelocations() const { - uint32_t Count = 0; - for (const OutputSegment *Seg : Segments) - for (const InputChunk *InputSeg : Seg->InputSegments) - Count += InputSeg->getNumRelocations(); - return Count; + uint32_t count = 0; + for (const OutputSegment *seg : segments) + for (const InputChunk *inputSeg : seg->inputSegments) + count += inputSeg->getNumRelocations(); + return count; } -void DataSection::writeRelocations(raw_ostream &OS) const { - for (const OutputSegment *Seg : Segments) - for (const InputChunk *C : Seg->InputSegments) - C->writeRelocations(OS); +void DataSection::writeRelocations(raw_ostream &os) const { + for (const OutputSegment *seg : segments) + for (const InputChunk *c : seg->inputSegments) + c->writeRelocations(os); } void CustomSection::finalizeContents() { - raw_string_ostream OS(NameData); - encodeULEB128(Name.size(), OS); - OS << Name; - OS.flush(); - - for (InputSection *Section : InputSections) { - Section->OutputOffset = PayloadSize; - Section->OutputSec = this; - PayloadSize += Section->getSize(); + raw_string_ostream os(nameData); + encodeULEB128(name.size(), os); + os << name; + os.flush(); + + for (InputSection *section : inputSections) { + section->outputOffset = payloadSize; + section->outputSec = this; + payloadSize += section->getSize(); } - createHeader(PayloadSize + NameData.size()); + createHeader(payloadSize + nameData.size()); } -void CustomSection::writeTo(uint8_t *Buf) { +void CustomSection::writeTo(uint8_t *buf) { log("writing " + toString(*this) + " size=" + Twine(getSize()) + - " chunks=" + Twine(InputSections.size())); + " chunks=" + Twine(inputSections.size())); - assert(Offset); - Buf += Offset; + assert(offset); + buf += offset; // Write section header - memcpy(Buf, Header.data(), Header.size()); - Buf += Header.size(); - memcpy(Buf, NameData.data(), NameData.size()); - Buf += NameData.size(); + memcpy(buf, header.data(), header.size()); + buf += header.size(); + memcpy(buf, nameData.data(), nameData.size()); + buf += nameData.size(); // Write custom sections payload - for (const InputSection *Section : InputSections) - Section->writeTo(Buf); + for (const InputSection *section : inputSections) + section->writeTo(buf); } uint32_t CustomSection::getNumRelocations() const { - uint32_t Count = 0; - for (const InputSection *InputSect : InputSections) - Count += InputSect->getNumRelocations(); - return Count; + uint32_t count = 0; + for (const InputSection *inputSect : inputSections) + count += inputSect->getNumRelocations(); + return count; } -void CustomSection::writeRelocations(raw_ostream &OS) const { - for (const InputSection *S : InputSections) - S->writeRelocations(OS); +void CustomSection::writeRelocations(raw_ostream &os) const { + for (const InputSection *s : inputSections) + s->writeRelocations(os); } |