[PATCH] D155535: [WebAssembly][Objcopy] Write output section headers identically to inputs

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 17:33:20 PDT 2023


aheejin updated this revision to Diff 544160.
aheejin marked 4 inline comments as done.
aheejin added a comment.

Address comments + fix errors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155535/new/

https://reviews.llvm.org/D155535

Files:
  llvm/lib/ObjectYAML/WasmEmitter.cpp
  llvm/test/ObjectYAML/wasm/invalid_section_header_size.yaml
  llvm/test/ObjectYAML/wasm/section_header_size.yaml


Index: llvm/test/ObjectYAML/wasm/section_header_size.yaml
===================================================================
--- llvm/test/ObjectYAML/wasm/section_header_size.yaml
+++ llvm/test/ObjectYAML/wasm/section_header_size.yaml
@@ -68,4 +68,4 @@
 # CHECK-NEXT:     Functions:
 # CHECK-NEXT:       - Index:           0
 # CHECK-NEXT:         Locals:          []
-# CHECK-NEXT:         Body:            200020016A0B
\ No newline at end of file
+# CHECK-NEXT:         Body:            200020016A0B
Index: llvm/test/ObjectYAML/wasm/invalid_section_header_size.yaml
===================================================================
--- /dev/null
+++ llvm/test/ObjectYAML/wasm/invalid_section_header_size.yaml
@@ -0,0 +1,20 @@
+## Test if we correctly error out if the provided section header size is less
+## than the size required.
+# RUN: not yaml2obj %s -o /dev/null 2>&1 | FileCheck %s
+
+--- !WASM
+FileHeader:
+  Version:         0x1
+Sections:
+  - Type:            TYPE
+  # CHECK: yaml2obj: error: section length can't be encoded in an LEB of size 0
+    HeaderSecSizeEncodingLen:   0
+    Signatures:
+      - Index:           0
+        ParamTypes:
+          - I32
+          - I32
+        ReturnTypes:
+          - I32
+...
+
Index: llvm/lib/ObjectYAML/WasmEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/WasmEmitter.cpp
+++ llvm/lib/ObjectYAML/WasmEmitter.cpp
@@ -647,10 +647,11 @@
     StringStream.flush();
 
     unsigned HeaderSecSizeEncodingLen =
-        Sec->HeaderSecSizeEncodingLen ? *Sec->HeaderSecSizeEncodingLen : 0;
+        Sec->HeaderSecSizeEncodingLen ? *Sec->HeaderSecSizeEncodingLen : 5;
     if (HeaderSecSizeEncodingLen < getULEB128Size(OutString.size())) {
-      reportError("Section length can't be encoded in an LEB of size " +
+      reportError("section length can't be encoded in an LEB of size " +
                   Twine(HeaderSecSizeEncodingLen));
+      return false;
     }
     // Write the section size followed by the content
     encodeULEB128(OutString.size(), OS, HeaderSecSizeEncodingLen);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155535.544160.patch
Type: text/x-patch
Size: 2106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/5a08b7b4/attachment.bin>


More information about the llvm-commits mailing list