[WebAssembly] Fix symbol exports under -r/--relocatable

This change cleans up the way wasm exports and globals
are generated, particualrly for -r/--relocatable where
globals need to be created and exported in order for
output relocations which reference them.

Remove the need for a per file GlobalIndexOffset and
instead set the output index for each symbol directly.
This simplifies the code in several places.

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

llvm-svn: 320001
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index c6cbc4c..5b65de8 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -34,8 +34,7 @@
 
 void SymbolTable::reportRemainingUndefines() {
   std::unordered_set<Symbol *> Undefs;
-  for (auto &I : SymMap) {
-    Symbol *Sym = I.second;
+  for (Symbol *Sym : SymVector) {
     if (Sym->isUndefined() && !Sym->isWeak() &&
         Config->AllowUndefinedSymbols.count(Sym->getName()) == 0) {
       Undefs.insert(Sym);
@@ -67,6 +66,7 @@
   if (Sym)
     return {Sym, false};
   Sym = make<Symbol>(Name, false);
+  SymVector.emplace_back(Sym);
   return {Sym, true};
 }