summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2017-09-01 17:24:19 +0000
committerSam Clegg <sbc@chromium.org>2017-09-01 17:24:19 +0000
commit4194fb706279c1de6c059d2a57ade5f9fb623fde (patch)
tree4f12459972f308397ff1aa5d53d553c02456a441
parent2928375cd25d6b02c8b5f54115636be8a62292f3 (diff)
downloadbcm5719-llvm-4194fb706279c1de6c059d2a57ade5f9fb623fde.tar.gz
bcm5719-llvm-4194fb706279c1de6c059d2a57ade5f9fb623fde.zip
[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 llvm-svn: 312340
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp2
-rw-r--r--llvm/test/tools/llvm-nm/wasm/exports.yaml21
-rw-r--r--llvm/test/tools/llvm-nm/wasm/imports.yaml2
-rw-r--r--llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml4
4 files changed, 21 insertions, 8 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index ad8c2b706de..e1bab727f17 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -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;
diff --git a/llvm/test/tools/llvm-nm/wasm/exports.yaml b/llvm/test/tools/llvm-nm/wasm/exports.yaml
index 420cc2f5dbb..953d17f6ad7 100644
--- a/llvm/test/tools/llvm-nm/wasm/exports.yaml
+++ b/llvm/test/tools/llvm-nm/wasm/exports.yaml
@@ -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
diff --git a/llvm/test/tools/llvm-nm/wasm/imports.yaml b/llvm/test/tools/llvm-nm/wasm/imports.yaml
index 3842d678ca7..5122c2cae77 100644
--- a/llvm/test/tools/llvm-nm/wasm/imports.yaml
+++ b/llvm/test/tools/llvm-nm/wasm/imports.yaml
@@ -1,4 +1,4 @@
-# RUN: yaml2obj < %s | llvm-nm - | FileCheck %s
+# RUN: yaml2obj < %s | llvm-nm - | FileCheck -strict-whitespace %s
--- !WASM
FileHeader:
diff --git a/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml b/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml
index 91c4dd6262a..8f0b47f6239 100644
--- a/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml
+++ b/llvm/test/tools/llvm-nm/wasm/weak-symbols.yaml
@@ -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
OpenPOWER on IntegriCloud