Index: llvm/trunk/include/llvm/BinaryFormat/Wasm.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Wasm.h +++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h @@ -91,6 +91,8 @@ struct WasmFunction { std::vector Locals; ArrayRef Body; + size_t CodeSectionOffset; + size_t Size; }; struct WasmDataSegment { Index: llvm/trunk/include/llvm/Object/Wasm.h =================================================================== --- llvm/trunk/include/llvm/Object/Wasm.h +++ llvm/trunk/include/llvm/Object/Wasm.h @@ -140,7 +140,6 @@ ArrayRef elements() const { return ElemSegments; } ArrayRef dataSegments() const { return DataSegments; } ArrayRef functions() const { return Functions; } - const ArrayRef& code() const { return CodeSection; } uint32_t startFunction() const { return StartFunction; } void moveSymbolNext(DataRefImpl &Symb) const override; @@ -242,7 +241,6 @@ std::vector DataSegments; std::vector Functions; std::vector Symbols; - ArrayRef CodeSection; uint32_t StartFunction = -1; bool HasLinkingSection = false; wasm::WasmLinkingData LinkingData; Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -684,18 +684,21 @@ } Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) { + const uint8_t *CodeSectionStart = Ptr; uint32_t FunctionCount = readVaruint32(Ptr); if (FunctionCount != FunctionTypes.size()) { return make_error("Invalid function count", object_error::parse_failed); } - CodeSection = ArrayRef(Ptr, End - Ptr); - while (FunctionCount--) { wasm::WasmFunction Function; - uint32_t FunctionSize = readVaruint32(Ptr); - const uint8_t *FunctionEnd = Ptr + FunctionSize; + const uint8_t *FunctionStart = Ptr; + uint32_t Size = readVaruint32(Ptr); + const uint8_t *FunctionEnd = Ptr + Size; + + Function.CodeSectionOffset = FunctionStart - CodeSectionStart; + Function.Size = FunctionEnd - FunctionStart; uint32_t NumLocalDecls = readVaruint32(Ptr); Function.Locals.reserve(NumLocalDecls);