OSDN Git Service

[WebAssembly] Provide WasmFunction content offset information.
authorSam Clegg <sbc@chromium.org>
Tue, 15 May 2018 21:49:58 +0000 (21:49 +0000)
committerSam Clegg <sbc@chromium.org>
Tue, 15 May 2018 21:49:58 +0000 (21:49 +0000)
WasmObjectWriter mostly operates with function segments offsets that do
not include their size fields. WasmObjectFile needs to have and provide
this information to the lld to maintain proper
R_WEBASSEMBLY_FUNCTION_OFFSET_I32 relocations entries.

Patch by Yury Delendik

Differential Revision: https://reviews.llvm.org/D46763

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332406 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/BinaryFormat/Wasm.h
lib/Object/WasmObjectFile.cpp

index 9212fe8..fa5448d 100644 (file)
@@ -102,6 +102,7 @@ struct WasmFunction {
   ArrayRef<uint8_t> Body;
   uint32_t CodeSectionOffset;
   uint32_t Size;
+  uint32_t CodeOffset;  // start of Locals and Body
   StringRef SymbolName; // from the "linking" section
   StringRef DebugName; // from the "name" section
   uint32_t Comdat; // from the "comdat info" section
index 2a2f165..8b31c04 100644 (file)
@@ -875,6 +875,7 @@ Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) {
     uint32_t Size = readVaruint32(Ptr);
     const uint8_t *FunctionEnd = Ptr + Size;
 
+    Function.CodeOffset = Ptr - FunctionStart;
     Function.Index = NumImportedFunctions + Functions.size();
     Function.CodeSectionOffset = FunctionStart - CodeSectionStart;
     Function.Size = FunctionEnd - FunctionStart;