Index: lld/trunk/test/wasm/weak-alias.ll
===================================================================
--- lld/trunk/test/wasm/weak-alias.ll
+++ lld/trunk/test/wasm/weak-alias.ll
@@ -35,8 +35,8 @@
 ; CHECK-NEXT:       - ElemType:        ANYFUNC
 ; CHECK-NEXT:         Limits:
 ; CHECK-NEXT:           Flags:           [ HAS_MAX ]
-; CHECK-NEXT:           Initial:         0x00000003
-; CHECK-NEXT:           Maximum:         0x00000003
+; CHECK-NEXT:           Initial:         0x00000002
+; CHECK-NEXT:           Maximum:         0x00000002
 ; CHECK-NEXT:   - Type:            MEMORY
 ; CHECK-NEXT:     Memories:
 ; CHECK-NEXT:       - Initial:         0x00000002
@@ -88,7 +88,7 @@
 ; CHECK-NEXT:       - Offset:
 ; CHECK-NEXT:           Opcode:          I32_CONST
 ; CHECK-NEXT:           Value:           1
-; CHECK-NEXT:         Functions:       [ 1, 1 ]
+; CHECK-NEXT:         Functions:       [ 1 ]
 ; CHECK-NEXT:   - Type:            CODE
 ; CHECK-NEXT:     Functions:
 ; CHECK-NEXT:       - Index:           0
@@ -112,7 +112,7 @@
 ; CHECK-NEXT:         Locals:
 ; CHECK-NEXT:           - Type:            I32
 ; CHECK-NEXT:             Count:           2
-; CHECK-NEXT:         Body:            23808080800041106B220024808080800020004182808080003602081081808080002101200041106A24808080800020010B
+; CHECK-NEXT:         Body:            23808080800041106B220024808080800020004181808080003602081081808080002101200041106A24808080800020010B
 ; CHECK-NEXT:       - Index:           6
 ; CHECK-NEXT:         Locals:
 ; CHECK-NEXT:         Body:            0B
@@ -164,8 +164,8 @@
 ; RELOC-NEXT:       - ElemType:        ANYFUNC
 ; RELOC-NEXT:         Limits:
 ; RELOC-NEXT:           Flags:           [ HAS_MAX ]
-; RELOC-NEXT:           Initial:         0x00000003
-; RELOC-NEXT:           Maximum:         0x00000003
+; RELOC-NEXT:           Initial:         0x00000002
+; RELOC-NEXT:           Maximum:         0x00000002
 ; RELOC-NEXT:   - Type:            MEMORY
 ; RELOC-NEXT:     Memories:
 ; RELOC-NEXT:       - Initial:         0x00000000
@@ -197,7 +197,7 @@
 ; RELOC-NEXT:       - Offset:
 ; RELOC-NEXT:           Opcode:          I32_CONST
 ; RELOC-NEXT:           Value:           1
-; RELOC-NEXT:         Functions:       [ 1, 1 ]
+; RELOC-NEXT:         Functions:       [ 1 ]
 ; RELOC-NEXT:   - Type:            CODE
 ; RELOC-NEXT:     Relocations:
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
@@ -261,7 +261,7 @@
 ; RELOC-NEXT:         Locals:
 ; RELOC-NEXT:           - Type:            I32
 ; RELOC-NEXT:             Count:           2
-; RELOC-NEXT:         Body:            23808080800041106B220024808080800020004182808080003602081081808080002101200041106A24808080800020010B
+; RELOC-NEXT:         Body:            23808080800041106B220024808080800020004181808080003602081081808080002101200041106A24808080800020010B
 ; RELOC-NEXT:   - Type:            CUSTOM
 ; RELOC-NEXT:     Name:            linking
 ; RELOC-NEXT:     DataSize:        0
Index: lld/trunk/wasm/InputChunks.h
===================================================================
--- lld/trunk/wasm/InputChunks.h
+++ lld/trunk/wasm/InputChunks.h
@@ -120,6 +120,9 @@
   uint32_t getOutputIndex() const { return OutputIndex.getValue(); }
   bool hasOutputIndex() const { return OutputIndex.hasValue(); }
   void setOutputIndex(uint32_t Index);
+  uint32_t getTableIndex() const { return TableIndex.getValue(); }
+  bool hasTableIndex() const { return TableIndex.hasValue(); }
+  void setTableIndex(uint32_t Index);
 
   const WasmSignature &Signature;
 
@@ -134,6 +137,7 @@
 
   const WasmFunction *Function;
   llvm::Optional<uint32_t> OutputIndex;
+  llvm::Optional<uint32_t> TableIndex;
 };
 
 class SyntheticFunction : public InputFunction {
Index: lld/trunk/wasm/InputChunks.cpp
===================================================================
--- lld/trunk/wasm/InputChunks.cpp
+++ lld/trunk/wasm/InputChunks.cpp
@@ -117,3 +117,9 @@
   assert(!hasOutputIndex());
   OutputIndex = Index;
 }
+
+void InputFunction::setTableIndex(uint32_t Index) {
+  DEBUG(dbgs() << "InputFunction::setTableIndex " << Index << "\n");
+  assert(!hasTableIndex());
+  TableIndex = Index;
+}
Index: lld/trunk/wasm/Symbols.h
===================================================================
--- lld/trunk/wasm/Symbols.h
+++ lld/trunk/wasm/Symbols.h
@@ -77,10 +77,10 @@
   // space of the output object.
   void setOutputIndex(uint32_t Index);
 
-  uint32_t getTableIndex() const { return TableIndex.getValue(); }
+  uint32_t getTableIndex() const;
 
   // Returns true if a table index has been set for this symbol
-  bool hasTableIndex() const { return TableIndex.hasValue(); }
+  bool hasTableIndex() const;
 
   // Set the table index of the symbol
   void setTableIndex(uint32_t Index);
Index: lld/trunk/wasm/Symbols.cpp
===================================================================
--- lld/trunk/wasm/Symbols.cpp
+++ lld/trunk/wasm/Symbols.cpp
@@ -67,7 +67,26 @@
   OutputIndex = Index;
 }
 
+uint32_t Symbol::getTableIndex() const {
+  if (Function)
+    return Function->getTableIndex();
+  return TableIndex.getValue();
+}
+
+bool Symbol::hasTableIndex() const {
+  if (Function)
+    return Function->hasTableIndex();
+  return TableIndex.hasValue();
+}
+
 void Symbol::setTableIndex(uint32_t Index) {
+  // For imports, we set the table index here on the Symbol; for defined
+  // functions we set the index on the InputFunction so that we don't export
+  // the same thing twice (keeps the table size down).
+  if (Function) {
+    Function->setTableIndex(Index);
+    return;
+  }
   DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
   assert(!TableIndex.hasValue());
   TableIndex = Index;