if (Ptr + Size > Eof)
return make_error<StringError>("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<uint8_t>(Ptr, Size);
Ptr += Size;
return Error::success();
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;
; 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: }
Sections:
- Type: CUSTOM
Name: foo
- Payload: 03666F6F0401020304
+ Payload: '0401020304'
...
# CHECK: --- !WASM
# CHECK: FileHeader:
# CHECK: Sections:
# CHECK: - Type: CUSTOM
# CHECK: Name: foo
-# CHECK: Payload: 03666F6F0401020304
+# CHECK: Payload: '0401020304'
# CHECK: ...
# 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
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: }
if (auto Err = writeSectionContent(OS, *S))
return Err;
} else {
+ writeStringRef(Section.Name, OS);
Section.Payload.writeAsBinary(OS);
}
return 0;