diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -218,11 +218,8 @@ // Relocations for fixing up references in the code section. std::vector CodeRelocations; - uint32_t CodeSectionIndex; - // Relocations for fixing up references in the data section. std::vector DataRelocations; - uint32_t DataSectionIndex; // Index values to use for fixing up call_indirect type indices. // Maps function symbols to the index of the type of the function @@ -329,9 +326,9 @@ void writeExportSection(ArrayRef Exports); void writeElemSection(ArrayRef TableElems); void writeDataCountSection(); - void writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, - ArrayRef Functions); - void writeDataSection(); + uint32_t writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, + ArrayRef Functions); + uint32_t writeDataSection(); void writeEventSection(ArrayRef Events); void writeGlobalSection(ArrayRef Globals); void writeRelocSection(uint32_t SectionIndex, StringRef Name, @@ -876,15 +873,14 @@ endSection(Section); } -void WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, - const MCAsmLayout &Layout, - ArrayRef Functions) { +uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, + const MCAsmLayout &Layout, + ArrayRef Functions) { if (Functions.empty()) - return; + return 0; SectionBookkeeping Section; startSection(Section, wasm::WASM_SEC_CODE); - CodeSectionIndex = Section.Index; encodeULEB128(Functions.size(), W.OS); @@ -904,15 +900,15 @@ applyRelocations(CodeRelocations, Section.ContentsOffset); endSection(Section); + return Section.Index; } -void WasmObjectWriter::writeDataSection() { +uint32_t WasmObjectWriter::writeDataSection() { if (DataSegments.empty()) - return; + return 0; SectionBookkeeping Section; startSection(Section, wasm::WASM_SEC_DATA); - DataSectionIndex = Section.Index; encodeULEB128(DataSegments.size(), W.OS); // count @@ -934,6 +930,7 @@ applyRelocations(DataRelocations, Section.ContentsOffset); endSection(Section); + return Section.Index; } void WasmObjectWriter::writeRelocSection( @@ -1661,8 +1658,8 @@ writeExportSection(Exports); writeElemSection(TableElems); writeDataCountSection(); - writeCodeSection(Asm, Layout, Functions); - writeDataSection(); + uint32_t CodeSectionIndex = writeCodeSection(Asm, Layout, Functions); + uint32_t DataSectionIndex = writeDataSection(); for (auto &CustomSection : CustomSections) writeCustomSection(CustomSection, Asm, Layout); writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats);