[WebAssembly] libObject: Don't include the name the size of custom sections
authorSam Clegg <sbc@chromium.org>
Thu, 12 Apr 2018 20:31:12 +0000 (20:31 +0000)
committerSam Clegg <sbc@chromium.org>
Thu, 12 Apr 2018 20:31:12 +0000 (20:31 +0000)
Differential Revision: https://reviews.llvm.org/D45579

llvm-svn: 329947

llvm/lib/Object/WasmObjectFile.cpp
llvm/test/MC/WebAssembly/custom-sections.ll
llvm/test/ObjectYAML/wasm/custom_section.yaml
llvm/test/tools/llvm-objdump/wasm.txt
llvm/test/tools/llvm-readobj/sections.test
llvm/tools/yaml2obj/yaml2wasm.cpp

index 0c78631..b9eba01 100644 (file)
@@ -178,6 +178,11 @@ static Error readSection(WasmSection &Section, const uint8_t *&Ptr,
   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();
@@ -618,7 +623,6 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, const uint8_t *Ptr,
 
 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 b12afbc..f479e3d 100644 (file)
@@ -11,13 +11,13 @@ target triple = "wasm32-unknown-unknown-wasm"
 
 ; 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 c7b87cb..37cdddb 100644 (file)
@@ -5,7 +5,7 @@ FileHeader:
 Sections:
   - Type:            CUSTOM
     Name:            foo
-    Payload:         03666F6F0401020304
+    Payload:         '0401020304'
 ...
 # CHECK: --- !WASM
 # CHECK: FileHeader:
@@ -13,5 +13,5 @@ Sections:
 # CHECK: Sections:
 # CHECK:  - Type:            CUSTOM
 # CHECK:    Name:            foo
-# CHECK:    Payload:         03666F6F0401020304
+# CHECK:    Payload:         '0401020304'
 # CHECK: ...
index ef6265c..622df7b 100644 (file)
@@ -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 a243b7c..a5fa7f5 100644 (file)
@@ -528,13 +528,13 @@ WASM-NEXT:     ]
 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 bd30f88..ab16599 100644 (file)
@@ -240,6 +240,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS,
     if (auto Err = writeSectionContent(OS, *S))
       return Err;
   } else {
+    writeStringRef(Section.Name, OS);
     Section.Payload.writeAsBinary(OS);
   }
   return 0;