[PATCH] D44201: [WebAssembly] Disallow weak undefined globals in the object format

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 7 04:15:30 PST 2018


ncw created this revision.
ncw added a reviewer: sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.

This implements https://github.com/WebAssembly/tool-conventions/pull/47

---

Split out of https://reviews.llvm.org/D44028


Repository:
  rL LLVM

https://reviews.llvm.org/D44201

Files:
  lib/Object/WasmObjectFile.cpp
  test/tools/llvm-nm/wasm/weak-symbols.yaml


Index: test/tools/llvm-nm/wasm/weak-symbols.yaml
===================================================================
--- test/tools/llvm-nm/wasm/weak-symbols.yaml
+++ test/tools/llvm-nm/wasm/weak-symbols.yaml
@@ -18,16 +18,11 @@
         Field:           weak_import_func
         Kind:            FUNCTION
         SigIndex:        0
-      - Module:          env
-        Field:           weak_import_global
-        Kind:            GLOBAL
-        GlobalType:      I32
-        GlobalMutable:   false
   - Type:            FUNCTION
     FunctionTypes: [ 0 ]
   - Type:            GLOBAL
     Globals:
-      - Index:       1
+      - Index:       0
         Type:        I32
         Mutable:     false
         InitExpr:
@@ -64,7 +59,7 @@
          Kind:            GLOBAL
          Name:            weak_defined_global
          Flags:           [ BINDING_WEAK ]
-         Global:          1
+         Global:          0
        - Index:           3
          Kind:            DATA
          Name:            weak_import_data
@@ -74,11 +69,6 @@
          Name:            weak_import_func
          Flags:           [ BINDING_WEAK, UNDEFINED ]
          Function:        0
-       - Index:           5
-         Kind:            GLOBAL
-         Name:            weak_import_global
-         Flags:           [ BINDING_WEAK, UNDEFINED ]
-         Global:          0
     SegmentInfo:
       - Index:           0
         Name:            .rodata.constantData
@@ -88,7 +78,6 @@
 
 # CHECK:      00000000 W weak_defined_data
 # CHECK-NEXT: 00000001 W weak_defined_func
-# CHECK-NEXT: 00000001 W weak_defined_global
+# CHECK-NEXT: 00000000 W weak_defined_global
 # CHECK-NEXT:          w weak_import_data
 # CHECK-NEXT:          w weak_import_func
-# CHECK-NEXT:          w weak_import_global
Index: lib/Object/WasmObjectFile.cpp
===================================================================
--- lib/Object/WasmObjectFile.cpp
+++ lib/Object/WasmObjectFile.cpp
@@ -422,6 +422,11 @@
           IsDefined != isDefinedGlobalIndex(Info.ElementIndex))
         return make_error<GenericBinaryError>("invalid global symbol index",
                                               object_error::parse_failed);
+      if (!IsDefined &&
+          (Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) ==
+              wasm::WASM_SYMBOL_BINDING_WEAK)
+        return make_error<GenericBinaryError>("invalid global symbol flag",
+                                              object_error::parse_failed);
       if (IsDefined) {
         Info.Name = readString(Ptr);
         unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44201.137361.patch
Type: text/x-patch
Size: 2628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180307/fb6f2175/attachment.bin>


More information about the llvm-commits mailing list