diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index 172b15021560..e138faeed342 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -43,18 +43,28 @@ public:
   };
 
   WasmSymbol(StringRef Name, SymbolType Type, uint32_t Section,
-             uint32_t ElementIndex)
-      : Name(Name), Type(Type), Section(Section), ElementIndex(ElementIndex) {}
+             uint32_t ElementIndex, uint32_t ImportIndex = 0)
+      : Name(Name), Type(Type), Section(Section), ElementIndex(ElementIndex),
+        ImportIndex(ImportIndex) {}
 
   StringRef Name;
   SymbolType Type;
   uint32_t Section;
   uint32_t Flags = 0;
 
-  // Index into the imports, exports or functions array of the object depending
-  // on the type
+  // Index into either the function or global index space.
   uint32_t ElementIndex;
 
+  // For imports, the index into the import table
+  uint32_t ImportIndex;
+
+  bool isFunction() const {
+    return Type == WasmSymbol::SymbolType::FUNCTION_IMPORT ||
+           Type == WasmSymbol::SymbolType::FUNCTION_EXPORT ||
+           Type == WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME;
+  }
+
+
   bool isWeak() const {
     return getBinding() == wasm::WASM_SYMBOL_BINDING_WEAK;
   }
@@ -73,7 +83,8 @@ public:
 
   void print(raw_ostream &Out) const {
     Out << "Name=" << Name << ", Type=" << static_cast<int>(Type)
-        << ", Flags=" << Flags << " ElemIndex=" << ElementIndex;
+        << ", Flags=" << Flags << " ElemIndex=" << ElementIndex
+        << ", ImportIndex=" << ImportIndex;
   }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 77fcac5578b1..c320b9153717 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -303,13 +303,15 @@ Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) {
 void WasmObjectFile::populateSymbolTable() {
   // Add imports to symbol table
   size_t ImportIndex = 0;
+  size_t GlobalIndex = 0;
+  size_t FunctionIndex = 0;
   for (const wasm::WasmImport& Import : Imports) {
     switch (Import.Kind) {
     case wasm::WASM_EXTERNAL_GLOBAL:
       assert(Import.Global.Type == wasm::WASM_TYPE_I32);
       SymbolMap.try_emplace(Import.Field, Symbols.size());
       Symbols.emplace_back(Import.Field, WasmSymbol::SymbolType::GLOBAL_IMPORT,
-                           ImportSection, ImportIndex);
+                           ImportSection, GlobalIndex++, ImportIndex);
       DEBUG(dbgs() << "Adding import: " << Symbols.back()
                    << " sym index:" << Symbols.size() << "\n");
       break;
@@ -317,7 +319,7 @@ void WasmObjectFile::populateSymbolTable() {
       SymbolMap.try_emplace(Import.Field, Symbols.size());
       Symbols.emplace_back(Import.Field,
                            WasmSymbol::SymbolType::FUNCTION_IMPORT,
-                           ImportSection, ImportIndex);
+                           ImportSection, FunctionIndex++, ImportIndex);
       DEBUG(dbgs() << "Adding import: " << Symbols.back()
                    << " sym index:" << Symbols.size() << "\n");
       break;
@@ -328,7 +330,6 @@ void WasmObjectFile::populateSymbolTable() {
   }
 
   // Add exports to symbol table
-  size_t ExportIndex = 0;
   for (const wasm::WasmExport& Export : Exports) {
     if (Export.Kind == wasm::WASM_EXTERNAL_FUNCTION ||
         Export.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
@@ -339,18 +340,17 @@ void WasmObjectFile::populateSymbolTable() {
       auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size());
       if (Pair.second) {
         Symbols.emplace_back(Export.Name, ExportType,
-                             ExportSection, ExportIndex);
+                             ExportSection, Export.Index);
         DEBUG(dbgs() << "Adding export: " << Symbols.back()
                      << " sym index:" << Symbols.size() << "\n");
       } else {
         uint32_t SymIndex = Pair.first->second;
         Symbols[SymIndex] =
-            WasmSymbol(Export.Name, ExportType, ExportSection, ExportIndex);
+            WasmSymbol(Export.Name, ExportType, ExportSection, Export.Index);
         DEBUG(dbgs() << "Replacing existing symbol:  " << Symbols[SymIndex]
                      << " sym index:" << SymIndex << "\n");
       }
     }
-    ExportIndex++;
   }
 }
 
@@ -825,19 +825,17 @@ uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol& Sym) const {
   switch (Sym.Type) {
   case WasmSymbol::SymbolType::FUNCTION_IMPORT:
   case WasmSymbol::SymbolType::GLOBAL_IMPORT:
-    return 0;
   case WasmSymbol::SymbolType::FUNCTION_EXPORT:
-    return Exports[Sym.ElementIndex].Index;
+  case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME:
+    return Sym.ElementIndex;
   case WasmSymbol::SymbolType::GLOBAL_EXPORT: {
-    uint32_t GlobalIndex = Exports[Sym.ElementIndex].Index - NumImportedGlobals;
+    uint32_t GlobalIndex = Sym.ElementIndex - NumImportedGlobals;
     assert(GlobalIndex < Globals.size());
     const wasm::WasmGlobal& Global = Globals[GlobalIndex];
     // WasmSymbols correspond only to I32_CONST globals
     assert(Global.InitExpr.Opcode == wasm::WASM_OPCODE_I32_CONST);
     return Global.InitExpr.Value.Int32;
   }
-  case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME:
-    return Sym.ElementIndex;
   }
   llvm_unreachable("invalid symbol type");
 }