Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/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: llvm/trunk/test/MC/WebAssembly/custom-sections.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/custom-sections.ll +++ llvm/trunk/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: } Index: llvm/trunk/test/ObjectYAML/wasm/custom_section.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/wasm/custom_section.yaml +++ llvm/trunk/test/ObjectYAML/wasm/custom_section.yaml @@ -5,7 +5,7 @@ Sections: - Type: CUSTOM Name: foo - Payload: 03666F6F0401020304 + Payload: '0401020304' ... # CHECK: --- !WASM # CHECK: FileHeader: @@ -13,5 +13,5 @@ # CHECK: Sections: # CHECK: - Type: CUSTOM # CHECK: Name: foo -# CHECK: Payload: 03666F6F0401020304 +# CHECK: Payload: '0401020304' # CHECK: ... Index: llvm/trunk/test/tools/llvm-objdump/wasm.txt =================================================================== --- llvm/trunk/test/tools/llvm-objdump/wasm.txt +++ llvm/trunk/test/tools/llvm-objdump/wasm.txt @@ -7,8 +7,8 @@ # CHECK-NEXT: 2 FUNCTION 00000002 0000000000000000 # CHECK-NEXT: 3 CODE 00000019 0000000000000000 TEXT # CHECK-NEXT: 4 DATA 0000001c 0000000000000000 DATA -# CHECK-NEXT: 5 linking 00000055 0000000000000000 -# CHECK-NEXT: 6 reloc.CODE 00000017 0000000000000000 +# CHECK-NEXT: 5 linking 0000004d 0000000000000000 +# CHECK-NEXT: 6 reloc.CODE 0000000c 0000000000000000 # RUN: llvm-objdump -p %p/Inputs/trivial.obj.wasm | FileCheck %s -check-prefix CHECK-HEADER Index: llvm/trunk/test/tools/llvm-readobj/sections.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/sections.test +++ llvm/trunk/test/tools/llvm-readobj/sections.test @@ -528,13 +528,13 @@ WASM-NEXT: } WASM-NEXT: Section { WASM-NEXT: Type: CUSTOM (0x0) -WASM-NEXT: Size: 65 +WASM-NEXT: Size: 57 WASM-NEXT: Offset: 191 WASM-NEXT: Name: linking WASM-NEXT: } WASM-NEXT: Section { WASM-NEXT: Type: CUSTOM (0x0) -WASM-NEXT: Size: 23 +WASM-NEXT: Size: 12 WASM-NEXT: Offset: 262 WASM-NEXT: Name: reloc.CODE WASM-NEXT: } Index: llvm/trunk/tools/yaml2obj/yaml2wasm.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2wasm.cpp +++ llvm/trunk/tools/yaml2obj/yaml2wasm.cpp @@ -240,6 +240,7 @@ if (auto Err = writeSectionContent(OS, *S)) return Err; } else { + writeStringRef(Section.Name, OS); Section.Payload.writeAsBinary(OS); } return 0;