From c551522d250ae53d7cac031f91f9c605c02893e7 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 17 Dec 2017 17:50:07 +0000 Subject: [PATCH] [WebAssembly] Export some more info on wasm funtions Summary: These fields are useful for lld's gc-sections support Also remove an unused field. Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish Differential Revision: https://reviews.llvm.org/D41320 llvm-svn: 320946 --- llvm/include/llvm/BinaryFormat/Wasm.h | 2 ++ llvm/include/llvm/Object/Wasm.h | 2 -- llvm/lib/Object/WasmObjectFile.cpp | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index a21f28c41965..48847002c82a 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -91,6 +91,8 @@ struct WasmLocalDecl { struct WasmFunction { std::vector Locals; ArrayRef Body; + size_t CodeSectionOffset; + size_t Size; }; struct WasmDataSegment { diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h index a129aeef4f49..5bb1a3fca3d1 100644 --- a/llvm/include/llvm/Object/Wasm.h +++ b/llvm/include/llvm/Object/Wasm.h @@ -140,7 +140,6 @@ public: 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 @@ private: std::vector DataSegments; std::vector Functions; std::vector Symbols; - ArrayRef CodeSection; uint32_t StartFunction = -1; bool HasLinkingSection = false; wasm::WasmLinkingData LinkingData; diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 41377579ae0f..7a0c05ed8a15 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -684,18 +684,21 @@ Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) } 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);