From 35a5df2de6bd56c95edcd10d6acab040b251238e Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 21 Dec 2023 14:16:37 -0800 Subject: [WebAssembly][Object] Record section start offsets at start of payload (#76188) LLVM ObjectFile currently records the start offsets of sections as the start of the section header, whereas most other tools (WABT, emscripten, wasm-tools) record it as the start of the section content, after the header. This affects binutils tools such as objdump and nm, but not compilation/assembly (since that is driven by symbols and assembler labels which already have their values inside the section payload rather in the header. This patch updates LLVM to match the other tools. --- llvm/lib/Object/WasmObjectFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/Object/WasmObjectFile.cpp') diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 05bd730..dfe86a4 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -265,7 +265,6 @@ static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) { static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, WasmSectionOrderChecker &Checker) { - Section.Offset = Ctx.Ptr - Ctx.Start; Section.Type = readUint8(Ctx); LLVM_DEBUG(dbgs() << "readSection type=" << Section.Type << "\n"); // When reading the section's size, store the size of the LEB used to encode @@ -273,6 +272,7 @@ static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, const uint8_t *PreSizePtr = Ctx.Ptr; uint32_t Size = readVaruint32(Ctx); Section.HeaderSecSizeEncodingLen = Ctx.Ptr - PreSizePtr; + Section.Offset = Ctx.Ptr - Ctx.Start; if (Size == 0) return make_error("zero length section", object_error::parse_failed); -- cgit v1.1