diff options
Diffstat (limited to 'wasm/OutputSections.cpp')
-rw-r--r-- | wasm/OutputSections.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/wasm/OutputSections.cpp b/wasm/OutputSections.cpp index 256a9884f947..4123d63b7466 100644 --- a/wasm/OutputSections.cpp +++ b/wasm/OutputSections.cpp @@ -40,6 +40,8 @@ static StringRef sectionTypeToString(uint32_t SectionType) { return "MEMORY"; case WASM_SEC_GLOBAL: return "GLOBAL"; + case WASM_SEC_EVENT: + return "EVENT"; case WASM_SEC_EXPORT: return "EXPORT"; case WASM_SEC_START: @@ -136,9 +138,17 @@ DataSection::DataSection(ArrayRef<OutputSegment *> Segments) for (OutputSegment *Segment : Segments) { raw_string_ostream OS(Segment->Header); writeUleb128(OS, 0, "memory index"); - writeUleb128(OS, WASM_OPCODE_I32_CONST, "opcode:i32const"); - writeSleb128(OS, Segment->StartVA, "memory offset"); - writeUleb128(OS, WASM_OPCODE_END, "opcode:end"); + WasmInitExpr InitExpr; + if (Config->Pic) { + assert(Segments.size() <= 1 && + "Currenly only a single data segment is supported in PIC mode"); + InitExpr.Opcode = WASM_OPCODE_GLOBAL_GET; + InitExpr.Value.Global = WasmSym::MemoryBase->getGlobalIndex(); + } else { + InitExpr.Opcode = WASM_OPCODE_I32_CONST; + InitExpr.Value.Int32 = Segment->StartVA; + } + writeInitExpr(OS, InitExpr); writeUleb128(OS, Segment->Size, "segment size"); OS.flush(); |