Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -178,6 +178,11 @@ if (Ptr + Size > Eof) return make_error("Section too large", object_error::parse_failed); + if (Section.Type == wasm::WASM_SEC_CUSTOM) { + const uint8_t *NameStart = Ptr; + Section.Name = readString(Ptr); + Size -= Ptr - NameStart; + } Section.Content = ArrayRef(Ptr, Size); Ptr += Size; return Error::success(); @@ -618,7 +623,6 @@ Error WasmObjectFile::parseCustomSection(WasmSection &Sec, const uint8_t *Ptr, const uint8_t *End) { - Sec.Name = readString(Ptr); if (Sec.Name == "name") { if (Error Err = parseNameSection(Ptr, End)) return Err; Index: test/MC/WebAssembly/custom-sections.ll =================================================================== --- test/MC/WebAssembly/custom-sections.ll +++ test/MC/WebAssembly/custom-sections.ll @@ -11,13 +11,13 @@ ; CHECK: Section { ; CHECK: Type: CUSTOM (0x0) -; CHECK: Size: 7 +; CHECK: Size: 3 ; CHECK: Offset: 72 ; CHECK: Name: red ; CHECK: } ; CHECK: Section { ; CHECK: Type: CUSTOM (0x0) -; CHECK: Size: 12 +; CHECK: Size: 6 ; CHECK: Offset: 85 ; CHECK: Name: green ; CHECK: }