]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Fix getSymbolValue for exported globals
authorSam Clegg <sbc@chromium.org>
Fri, 1 Sep 2017 17:24:19 +0000 (17:24 +0000)
committerSam Clegg <sbc@chromium.org>
Fri, 1 Sep 2017 17:24:19 +0000 (17:24 +0000)
The code wasn't previously taking into account that the
global index space is not same as the into in the Globals
array since the latter does not include imported globals.

This fixes the WebAssembly waterfall failures.

Differential Revision: https://reviews.llvm.org/D37384

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312340 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/WasmObjectFile.cpp
test/tools/llvm-nm/wasm/exports.yaml
test/tools/llvm-nm/wasm/imports.yaml
test/tools/llvm-nm/wasm/weak-symbols.yaml

index ad8c2b706de22af6362bcb6d5e35458c5c8aebbc..e1bab727f17602670f157a3ac7d7a58022ca7d89 100644 (file)
@@ -788,7 +788,7 @@ uint64_t WasmObjectFile::getSymbolValueImpl(DataRefImpl Symb) const {
   case WasmSymbol::SymbolType::FUNCTION_EXPORT:
     return Exports[Sym.ElementIndex].Index;
   case WasmSymbol::SymbolType::GLOBAL_EXPORT: {
-    uint32_t GlobalIndex = Exports[Sym.ElementIndex].Index;
+    uint32_t GlobalIndex = Exports[Sym.ElementIndex].Index - NumImportedGlobals;
     assert(GlobalIndex < Globals.size());
     const wasm::WasmGlobal& Global = Globals[GlobalIndex];
     return Global.InitExpr.Value.Int32;
index 420cc2f5dbb6ff45c22140c402b6465c248267ca..953d17f6ad7bd19aa3dab8e0fa40b4ac19184d1d 100644 (file)
@@ -1,4 +1,4 @@
-# RUN: yaml2obj < %s | llvm-nm - | FileCheck %s
+# RUN: yaml2obj < %s | llvm-nm - | FileCheck -strict-whitespace %s
 
 # That wasm exports of functions and globals are displayed as global data and
 # code symbols.
@@ -31,6 +31,17 @@ Sections:
         InitExpr:
           Opcode:          I64_CONST
           Value:           1024
+  - Type:            IMPORT
+    Imports:
+      - Module:          env
+        Field:           fimport
+        Kind:            FUNCTION
+        SigIndex:        0
+      - Module:          env
+        Field:           gimport
+        Kind:            GLOBAL
+        GlobalType:      I32
+        GlobalMutable:   false
   - Type:            EXPORT
     Exports:
       - Name:            foo
@@ -38,7 +49,9 @@ Sections:
         Index:           0x00000004
       - Name:            bar
         Kind:            GLOBAL
-        Index:           0x00000002
+        Index:           0x00000003
 
-# CHECK: 00000400 D bar
-# CHECK: 00000004 T foo
+# CHECK:      00000400 D bar
+# CHECK-NEXT:          U fimport
+# CHECK-NEXT: 00000004 T foo
+# CHECK-NEXT:          U gimport
index 3842d678ca7fbff6cd9d0ca34e9da928b42b1cb0..5122c2cae77dafcb03edf99ef6e8bf573fb7ab09 100644 (file)
@@ -1,4 +1,4 @@
-# RUN: yaml2obj < %s | llvm-nm - | FileCheck %s
+# RUN: yaml2obj < %s | llvm-nm - | FileCheck -strict-whitespace %s
 
 --- !WASM
 FileHeader:
index 91c4dd6262a778ba929ccbcb02c6cb8dacff3fd0..8f0b47f6239466fef58d9f12076c441adbe3eff4 100644 (file)
@@ -1,4 +1,4 @@
-# RUN: yaml2obj < %s | llvm-nm - | FileCheck %s
+# RUN: yaml2obj < %s | llvm-nm - | FileCheck -strict-whitespace %s
 
 # That wasm exports of functions and globals are displayed as global data and
 # code symbols.
@@ -49,7 +49,7 @@ Sections:
         Index:           0x00000004
       - Name:            weak_global_data
         Kind:            GLOBAL
-        Index:           0x00000002
+        Index:           0x00000003
   - Type:            CUSTOM
     Name:            linking
     DataSize:        0