Index: wasm/InputChunks.h =================================================================== --- wasm/InputChunks.h +++ wasm/InputChunks.h @@ -56,7 +56,7 @@ InputChunk(const ObjFile *F) : File(F) {} virtual ~InputChunk() = default; void calcRelocations(); - virtual const uint8_t *getData() const = 0; + virtual ArrayRef data() const = 0; virtual uint32_t getInputSectionOffset() const = 0; std::vector Relocations; @@ -88,9 +88,6 @@ OutputSegmentOffset = Offset; } - const uint8_t *getData() const override { - return Segment.Data.Content.data(); - } uint32_t getSize() const override { return Segment.Data.Content.size(); } uint32_t getAlignment() const { return Segment.Data.Alignment; } uint32_t startVA() const { return Segment.Data.Offset.Value.Int32; } @@ -101,6 +98,7 @@ int32_t OutputSegmentOffset = 0; protected: + ArrayRef data() const override { return Segment.Data.Content; } uint32_t getInputSectionOffset() const override { return Segment.SectionOffset; } @@ -118,9 +116,6 @@ : InputChunk(F), Signature(S), WrittenToNameSec(false), Function(Func) {} uint32_t getSize() const override { return Function->Size; } - const uint8_t *getData() const override { - return File->CodeSection->Content.data() + getInputSectionOffset(); - } StringRef getComdat() const override { return Function->Comdat; } uint32_t getOutputIndex() const { return OutputIndex.getValue(); }; bool hasOutputIndex() const { return OutputIndex.hasValue(); }; @@ -131,25 +126,28 @@ unsigned WrittenToNameSec : 1; protected: + ArrayRef data() const override { + return File->CodeSection->Content.slice(getInputSectionOffset(), getSize()); + } uint32_t getInputSectionOffset() const override { return Function->CodeSectionOffset; } + const WasmFunction *Function; llvm::Optional OutputIndex; }; class SyntheticFunction : public InputFunction { public: - SyntheticFunction(const WasmSignature &S, StringRef Body) + SyntheticFunction(const WasmSignature &S, ArrayRef Body) : InputFunction(S, nullptr, nullptr), Body(Body) {} uint32_t getSize() const override { return Body.size(); } - const uint8_t *getData() const override { - return reinterpret_cast(Body.data()); - } protected: - StringRef Body; + ArrayRef data() const override { return Body; } + + ArrayRef Body; }; } // namespace wasm Index: wasm/InputChunks.cpp =================================================================== --- wasm/InputChunks.cpp +++ wasm/InputChunks.cpp @@ -86,7 +86,7 @@ } void InputChunk::writeTo(uint8_t *SectionStart) const { - memcpy(SectionStart + getOutputOffset(), getData(), getSize()); + memcpy(SectionStart + getOutputOffset(), data().data(), data().size()); applyRelocations(SectionStart, OutRelocations); } Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -770,8 +770,10 @@ writeUleb128(OS, FunctionBody.size(), "function size"); OS.flush(); CtorFunctionBody += FunctionBody; - CtorFunction = - llvm::make_unique(Signature, CtorFunctionBody); + ArrayRef BodyArray( + reinterpret_cast(CtorFunctionBody.data()), + CtorFunctionBody.size()); + CtorFunction = llvm::make_unique(Signature, BodyArray); DefinedFunctions.emplace_back(CtorFunction.get()); }