[llvm] r312340 - [WebAssembly] Fix getSymbolValue for exported globals

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 10:24:19 PDT 2017


Author: sbc
Date: Fri Sep  1 10:24:19 2017
New Revision: 312340

URL: http://llvm.org/viewvc/llvm-project?rev=312340&view=rev
Log:
[WebAssembly] Fix getSymbolValue for exported globals

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

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

Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=312340&r1=312339&r2=312340&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Fri Sep  1 10:24:19 2017
@@ -788,7 +788,7 @@ uint64_t WasmObjectFile::getSymbolValueI
   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;

Modified: llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml?rev=312340&r1=312339&r2=312340&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml (original)
+++ llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml Fri Sep  1 10:24:19 2017
@@ -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

Modified: llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml?rev=312340&r1=312339&r2=312340&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml (original)
+++ llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml Fri Sep  1 10:24:19 2017
@@ -1,4 +1,4 @@
-# RUN: yaml2obj < %s | llvm-nm - | FileCheck %s
+# RUN: yaml2obj < %s | llvm-nm - | FileCheck -strict-whitespace %s
 
 --- !WASM
 FileHeader:

Modified: llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml?rev=312340&r1=312339&r2=312340&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml (original)
+++ llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml Fri Sep  1 10:24:19 2017
@@ -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




More information about the llvm-commits mailing list