Index: lld/trunk/test/wasm/alias.ll =================================================================== --- lld/trunk/test/wasm/alias.ll +++ lld/trunk/test/wasm/alias.ll @@ -58,18 +58,18 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: _start -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: start_alias -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: __heap_base ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __data_end ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: _start +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: start_alias +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 0 Index: lld/trunk/test/wasm/call-indirect.ll =================================================================== --- lld/trunk/test/wasm/call-indirect.ll +++ lld/trunk/test/wasm/call-indirect.ll @@ -93,6 +93,15 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: _start +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: - Name: bar ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 @@ -102,18 +111,9 @@ ; CHECK-NEXT: - Name: foo ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 -; CHECK-NEXT: - Name: _start -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 3 ; CHECK-NEXT: - Name: call_ptr ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 4 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/comdats.ll =================================================================== --- lld/trunk/test/wasm/comdats.ll +++ lld/trunk/test/wasm/comdats.ll @@ -39,6 +39,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 @@ -51,12 +57,6 @@ ; CHECK-NEXT: - Name: callInline2 ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 3 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/entry.ll =================================================================== --- lld/trunk/test/wasm/entry.ll +++ lld/trunk/test/wasm/entry.ll @@ -17,9 +17,16 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: entry ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Type: ; The __wasm_call_ctors is somewhat special. Make sure we can use it ; as the entry point if we choose @@ -34,3 +41,10 @@ ; CHECK-CTOR-NEXT: - Name: __wasm_call_ctors ; CHECK-CTOR-NEXT: Kind: FUNCTION ; CHECK-CTOR-NEXT: Index: 0 +; CHECK-CTOR-NEXT: - Name: __heap_base +; CHECK-CTOR-NEXT: Kind: GLOBAL +; CHECK-CTOR-NEXT: Index: 1 +; CHECK-CTOR-NEXT: - Name: __data_end +; CHECK-CTOR-NEXT: Kind: GLOBAL +; CHECK-CTOR-NEXT: Index: 2 +; CHECK-CTOR-NEXT: - Type: Index: lld/trunk/test/wasm/export.ll =================================================================== --- lld/trunk/test/wasm/export.ll +++ lld/trunk/test/wasm/export.ll @@ -22,16 +22,16 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: hidden_function -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: _start -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __heap_base ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __data_end ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: _start +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: hidden_function +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Type: CODE Index: lld/trunk/test/wasm/load-undefined.test =================================================================== --- lld/trunk/test/wasm/load-undefined.test +++ lld/trunk/test/wasm/load-undefined.test @@ -13,6 +13,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 @@ -22,12 +28,6 @@ ; CHECK-NEXT: - Name: ret64 ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: Index: lld/trunk/test/wasm/local-symbols.ll =================================================================== --- lld/trunk/test/wasm/local-symbols.ll +++ lld/trunk/test/wasm/local-symbols.ll @@ -68,15 +68,15 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: _start -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __heap_base ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __data_end ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: _start +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 0 Index: lld/trunk/test/wasm/locals-duplicate.test =================================================================== --- lld/trunk/test/wasm/locals-duplicate.test +++ lld/trunk/test/wasm/locals-duplicate.test @@ -53,6 +53,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: colliding_func2 ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 @@ -95,12 +101,6 @@ ; CHECK-NEXT: - Name: get_func3B ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 17 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/visibility-hidden.ll =================================================================== --- lld/trunk/test/wasm/visibility-hidden.ll +++ lld/trunk/test/wasm/visibility-hidden.ll @@ -36,19 +36,19 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: objectDefault -; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: objectDefault +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: archiveDefault ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 4 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: Index: lld/trunk/test/wasm/weak-alias-overide.ll =================================================================== --- lld/trunk/test/wasm/weak-alias-overide.ll +++ lld/trunk/test/wasm/weak-alias-overide.ll @@ -68,12 +68,18 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: alias_fn -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: alias_fn +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: direct_fn ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 @@ -89,12 +95,6 @@ ; CHECK-NEXT: - Name: call_direct_ptr ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 6 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/weak-alias.ll =================================================================== --- lld/trunk/test/wasm/weak-alias.ll +++ lld/trunk/test/wasm/weak-alias.ll @@ -65,9 +65,18 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: alias_fn +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: direct_fn ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 @@ -77,21 +86,12 @@ ; CHECK-NEXT: - Name: call_alias ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 3 -; CHECK-NEXT: - Name: alias_fn -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: call_alias_ptr ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 4 ; CHECK-NEXT: - Name: call_direct_ptr ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 5 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/weak-symbols.ll =================================================================== --- lld/trunk/test/wasm/weak-symbols.ll +++ lld/trunk/test/wasm/weak-symbols.ll @@ -65,6 +65,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: __heap_base +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Name: __data_end +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 @@ -77,12 +83,6 @@ ; CHECK-NEXT: - Name: exportWeak2 ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 4 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: lld/trunk/test/wasm/weak-undefined.ll =================================================================== --- lld/trunk/test/wasm/weak-undefined.ll +++ lld/trunk/test/wasm/weak-undefined.ll @@ -75,21 +75,21 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: get_address_of_foo -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: get_address_of_global_var -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: _start -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: __heap_base ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __data_end ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: _start +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Name: get_address_of_foo +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: get_address_of_global_var +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 0 Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -669,13 +669,13 @@ if (Config->Relocatable) return; - auto ExportSym = [&](Symbol *Sym) { + for (Symbol *Sym : Symtab->getSymbols()) { if (!Sym->isDefined()) - return; + continue; if (Sym->isHidden() || Sym->isLocal()) - return; + continue; if (!Sym->isLive()) - return; + continue; DEBUG(dbgs() << "exporting sym: " << Sym->getName() << "\n"); @@ -684,27 +684,11 @@ // used only to create fake-global exports for the synthetic symbols. Fix // this in a future commit if (Sym != WasmSym::DataEnd && Sym != WasmSym::HeapBase) - return; + continue; DefinedFakeGlobals.emplace_back(D); } ExportedSymbols.emplace_back(Sym); - }; - - // TODO The two loops below should be replaced with this single loop, with - // ExportSym inlined: - // for (Symbol *Sym : Symtab->getSymbols()) - // ExportSym(Sym); - // Making that change would reorder the output though, so it should be done as - // a separate commit. - - for (ObjFile *File : Symtab->ObjectFiles) - for (Symbol *Sym : File->getSymbols()) - if (File == Sym->getFile()) - ExportSym(Sym); - - for (Symbol *Sym : Symtab->getSymbols()) - if (Sym->getFile() == nullptr) - ExportSym(Sym); + } } void Writer::assignSymtab() {