Index: lld/trunk/test/wasm/alias.ll =================================================================== --- lld/trunk/test/wasm/alias.ll +++ lld/trunk/test/wasm/alias.ll @@ -1,5 +1,5 @@ ; RUN: llc -filetype=obj -o %t.o %s -; RUN: wasm-ld %t.o -o %t.wasm +; RUN: wasm-ld --export=start_alias %t.o -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" Index: lld/trunk/test/wasm/archive-export.ll =================================================================== --- lld/trunk/test/wasm/archive-export.ll +++ lld/trunk/test/wasm/archive-export.ll @@ -5,9 +5,9 @@ RUN: llc -filetype=obj %S/Inputs/archive2.ll -o %t.a2.o RUN: rm -f %t.a RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o -RUN: wasm-ld --export=archive2_symbol -o %t.wasm %t.a %t.o +RUN: wasm-ld --export-dynamic --export=archive2_symbol -o %t.wasm %t.a %t.o RUN: obj2yaml %t.wasm | FileCheck %s -RUN: wasm-ld -o %t.wasm %t.a %t.o +RUN: wasm-ld --export-dynamic -o %t.wasm %t.a %t.o RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=NOEXPORT CHECK: Exports: Index: lld/trunk/test/wasm/call-indirect.ll =================================================================== --- lld/trunk/test/wasm/call-indirect.ll +++ lld/trunk/test/wasm/call-indirect.ll @@ -1,6 +1,6 @@ ; RUN: llc -filetype=obj %p/Inputs/call-indirect.ll -o %t2.o ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld -o %t.wasm %t2.o %t.o +; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s ; bitcode generated from the following C code: Index: lld/trunk/test/wasm/comdats.ll =================================================================== --- lld/trunk/test/wasm/comdats.ll +++ lld/trunk/test/wasm/comdats.ll @@ -1,7 +1,7 @@ ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %p/Inputs/comdat1.ll -o %t1.o ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %p/Inputs/comdat2.ll -o %t2.o ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %s -o %t.o -; RUN: wasm-ld -o %t.wasm %t.o %t1.o %t2.o +; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o %t1.o %t2.o ; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" Index: lld/trunk/test/wasm/compress-relocs.ll =================================================================== --- lld/trunk/test/wasm/compress-relocs.ll +++ lld/trunk/test/wasm/compress-relocs.ll @@ -1,11 +1,11 @@ ; RUN: llc -filetype=obj %p/Inputs/call-indirect.ll -o %t2.o ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld -o %t.wasm %t2.o %t.o +; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s -; RUN: wasm-ld -O2 -o %t-opt.wasm %t2.o %t.o +; RUN: wasm-ld --export-dynamic -O2 -o %t-opt.wasm %t2.o %t.o ; RUN: obj2yaml %t-opt.wasm | FileCheck %s ; RUN: not wasm-ld --compress-relocations -o %t-compressed.wasm %t2.o %t.o 2>&1 | FileCheck %s -check-prefix=ERROR -; RUN: wasm-ld --strip-debug --compress-relocations -o %t-compressed.wasm %t2.o %t.o +; RUN: wasm-ld --export-dynamic --strip-debug --compress-relocations -o %t-compressed.wasm %t2.o %t.o ; RUN: obj2yaml %t-compressed.wasm | FileCheck %s -check-prefix=COMPRESS target triple = "wasm32-unknown-unknown-wasm" Index: lld/trunk/test/wasm/cxx-mangling.ll =================================================================== --- lld/trunk/test/wasm/cxx-mangling.ll +++ lld/trunk/test/wasm/cxx-mangling.ll @@ -1,7 +1,7 @@ ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld --demangle -o %t_demangle.wasm %t.o +; RUN: wasm-ld --export=_Z3fooi --demangle -o %t_demangle.wasm %t.o ; RUN: obj2yaml %t_demangle.wasm | FileCheck %s -; RUN: wasm-ld --no-demangle -o %t_nodemangle.wasm %t.o +; RUN: wasm-ld --export=_Z3fooi --no-demangle -o %t_nodemangle.wasm %t.o ; RUN: obj2yaml %t_nodemangle.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" Index: lld/trunk/test/wasm/local-symbols.ll =================================================================== --- lld/trunk/test/wasm/local-symbols.ll +++ lld/trunk/test/wasm/local-symbols.ll @@ -1,5 +1,6 @@ +; Test that internal symbols can still be GC'd when with --export-dynamic. ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld -o %t.wasm %t.o +; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" Index: lld/trunk/test/wasm/locals-duplicate.test =================================================================== --- lld/trunk/test/wasm/locals-duplicate.test +++ lld/trunk/test/wasm/locals-duplicate.test @@ -1,6 +1,6 @@ ; RUN: llc -filetype=obj %p/Inputs/locals-duplicate1.ll -o %t1.o ; RUN: llc -filetype=obj %p/Inputs/locals-duplicate2.ll -o %t2.o -; RUN: wasm-ld --no-entry -o %t.wasm %t1.o %t2.o +; RUN: wasm-ld --export-dynamic --no-entry -o %t.wasm %t1.o %t2.o ; RUN: obj2yaml %t.wasm | FileCheck %s ; CHECK: --- !WASM Index: lld/trunk/test/wasm/lto/archive.ll =================================================================== --- lld/trunk/test/wasm/lto/archive.ll +++ lld/trunk/test/wasm/lto/archive.ll @@ -2,7 +2,7 @@ ; RUN: rm -f %t.a ; RUN: llvm-ar rcs %t.a %t1.o ; RUN: llvm-as %s -o %t2.o -; RUN: wasm-ld %t2.o %t.a -o %t3 +; RUN: wasm-ld --export-dynamic %t2.o %t.a -o %t3 ; RUN: obj2yaml %t3 | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" Index: lld/trunk/test/wasm/undefined-weak-call.ll =================================================================== --- lld/trunk/test/wasm/undefined-weak-call.ll +++ lld/trunk/test/wasm/undefined-weak-call.ll @@ -1,5 +1,5 @@ ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld --no-entry --print-gc-sections %t.o \ +; RUN: wasm-ld --entry=callWeakFuncs --print-gc-sections %t.o \ ; RUN: -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-GC %s ; RUN: obj2yaml %t.wasm | FileCheck %s Index: lld/trunk/test/wasm/visibility-hidden.ll =================================================================== --- lld/trunk/test/wasm/visibility-hidden.ll +++ lld/trunk/test/wasm/visibility-hidden.ll @@ -3,14 +3,14 @@ ; RUN: rm -f %t2.a ; RUN: llvm-ar rcs %t2.a %t2.o -; Test that hidden symbols are not exported, whether pulled in from an archive -; or directly. -; RUN: wasm-ld %t.o %t2.a -o %t.wasm +; Test that symbols with hidden visitiblity are not export, even with +; --export-dynamic +; RUN: wasm-ld --export-dynamic %t.o %t2.a -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s -; Test that symbols with default visitiblity are not exported when -; --no-export-default is passed. -; RUN: wasm-ld --no-export-default %t.o %t2.a -o %t.nodef.wasm +; Test that symbols with default visitiblity are not exported without +; --export-dynamic +; RUN: wasm-ld %t.o %t2.a -o %t.nodef.wasm ; RUN: obj2yaml %t.nodef.wasm | FileCheck %s -check-prefix=NO-DEFAULT @@ -66,4 +66,13 @@ ; NO-DEFAULT-NEXT: - Name: memory ; NO-DEFAULT-NEXT: Kind: MEMORY ; NO-DEFAULT-NEXT: Index: 0 +; NO-DEFAULT-NEXT: - Name: __heap_base +; NO-DEFAULT-NEXT: Kind: GLOBAL +; NO-DEFAULT-NEXT: Index: 1 +; NO-DEFAULT-NEXT: - Name: __data_end +; NO-DEFAULT-NEXT: Kind: GLOBAL +; NO-DEFAULT-NEXT: Index: 2 +; NO-DEFAULT-NEXT: - Name: _start +; NO-DEFAULT-NEXT: Kind: FUNCTION +; NO-DEFAULT-NEXT: Index: 3 ; NO-DEFAULT-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 @@ -1,6 +1,6 @@ ; RUN: llc -filetype=obj -o %t.o %s ; RUN: llc -filetype=obj %S/Inputs/weak-alias.ll -o %t2.o -; RUN: wasm-ld %t.o %t2.o -o %t.wasm +; RUN: wasm-ld --export-dynamic %t.o %t2.o -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s ; Test that the strongly defined alias_fn from this file is used both here Index: lld/trunk/test/wasm/weak-alias.ll =================================================================== --- lld/trunk/test/wasm/weak-alias.ll +++ lld/trunk/test/wasm/weak-alias.ll @@ -1,6 +1,6 @@ ; RUN: llc -filetype=obj -o %t.o %s ; RUN: llc -filetype=obj %S/Inputs/weak-alias.ll -o %t2.o -; RUN: wasm-ld %t.o %t2.o -o %t.wasm +; RUN: wasm-ld --export-dynamic %t.o %t2.o -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s ; Test that weak aliases (alias_fn is a weak alias of direct_fn) are linked correctly Index: lld/trunk/test/wasm/weak-symbols.ll =================================================================== --- lld/trunk/test/wasm/weak-symbols.ll +++ lld/trunk/test/wasm/weak-symbols.ll @@ -1,7 +1,7 @@ ; RUN: llc -filetype=obj %p/Inputs/weak-symbol1.ll -o %t1.o ; RUN: llc -filetype=obj %p/Inputs/weak-symbol2.ll -o %t2.o ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld -no-gc-sections -o %t.wasm %t.o %t1.o %t2.o +; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o %t1.o %t2.o ; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" @@ -29,7 +29,7 @@ ; CHECK-NEXT: ReturnType: I32 ; CHECK-NEXT: ParamTypes: ; CHECK-NEXT: - Type: FUNCTION -; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 1, 1, 1 ] +; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 1, 1 ] ; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: Tables: ; CHECK-NEXT: - ElemType: ANYFUNC @@ -59,7 +59,7 @@ ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1032 +; CHECK-NEXT: Value: 1028 ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false @@ -91,7 +91,7 @@ ; CHECK-NEXT: Index: 3 ; CHECK-NEXT: - Name: exportWeak2 ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 5 +; CHECK-NEXT: Index: 4 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: @@ -114,9 +114,6 @@ ; CHECK-NEXT: Body: 4181808080000B ; CHECK-NEXT: - Index: 4 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 41020B -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 4181808080000B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Segments: @@ -125,7 +122,7 @@ ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1024 -; CHECK-NEXT: Content: '0100000002000000' +; CHECK-NEXT: Content: '01000000' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: @@ -138,7 +135,5 @@ ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Name: exportWeak1 ; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Name: weakFn -; CHECK-NEXT: - Index: 5 ; CHECK-NEXT: Name: exportWeak2 ; CHECK-NEXT: ... Index: lld/trunk/test/wasm/weak-undefined.ll =================================================================== --- lld/trunk/test/wasm/weak-undefined.ll +++ lld/trunk/test/wasm/weak-undefined.ll @@ -22,7 +22,8 @@ define void @_start() #0 { entry: - %call = call i32* @get_address_of_global_var() + %call1 = call i32* @get_address_of_global_var() + %call2 = call i8* @get_address_of_foo() ret void } @@ -81,12 +82,6 @@ ; CHECK-NEXT: - Name: __data_end ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 2 -; CHECK-NEXT: - Name: get_address_of_foo -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: get_address_of_global_var -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 3 @@ -103,5 +98,5 @@ ; CHECK-NEXT: Body: 4180808080000B ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 1082808080001A0B +; CHECK-NEXT: Body: 1082808080001A1081808080001A0B ; CHECK-NEXT: ... Index: lld/trunk/wasm/Config.h =================================================================== --- lld/trunk/wasm/Config.h +++ lld/trunk/wasm/Config.h @@ -24,7 +24,7 @@ bool Demangle; bool DisableVerify; bool ExportAll; - bool ExportDefault; + bool ExportDynamic; bool ExportTable; bool GcSections; bool ImportMemory; Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -373,8 +373,8 @@ Config->DisableVerify = Args.hasArg(OPT_disable_verify); Config->Entry = getEntry(Args, Args.hasArg(OPT_relocatable) ? "" : "_start"); Config->ExportAll = Args.hasArg(OPT_export_all); - Config->ExportDefault = Args.hasFlag(OPT_export_default, - OPT_no_export_default, true); + Config->ExportDynamic = Args.hasFlag(OPT_export_dynamic, + OPT_no_export_dynamic, false); Config->ExportTable = Args.hasArg(OPT_export_table); errorHandler().FatalWarnings = Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); @@ -473,6 +473,11 @@ WasmSym::DsoHandle = Symtab->addSyntheticDataSymbol( "__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN); WasmSym::DataEnd = Symtab->addSyntheticDataSymbol("__data_end", 0); + + // These two synthetic symbols exist purely for the embedder so we always + // want to export them. + WasmSym::HeapBase->ForceExport = true; + WasmSym::DataEnd->ForceExport = true; } createFiles(Args); @@ -507,7 +512,9 @@ if (!Config->Entry.empty()) { EntrySym = handleUndefined(Config->Entry); - if (!EntrySym) + if (EntrySym && EntrySym->isDefined()) + EntrySym->ForceExport = true; + else error("entry symbol not defined (pass --no-entry to supress): " + Config->Entry); } Index: lld/trunk/wasm/Options.td =================================================================== --- lld/trunk/wasm/Options.td +++ lld/trunk/wasm/Options.td @@ -30,9 +30,9 @@ "Demangle symbol names", "Do not demangle symbol names">; -defm export_default: B<"export-default", - "Export symbols marked as 'default' visibility (default)", - "Do not export symbols marked as 'default' visibility">; +defm export_dynamic: B<"export-dynamic", + "Put symbols in the dynamic symbol table", + "Do not put symbols in the dynamic symbol table (default)">; def entry: S<"entry">, MetaVarName<"">, HelpText<"Name of entry point symbol">; @@ -144,12 +144,13 @@ "Do not force load of all members in a static library (default)">; // Aliases -def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias; -def alias_entry_entry: J<"entry=">, Alias; -def alias_initial_memory_i: Flag<["-"], "i">, Alias; -def alias_max_memory_m: Flag<["-"], "m">, Alias; -def alias_relocatable_r: Flag<["-"], "r">, Alias; -def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias; +def: JoinedOrSeparate<["-"], "e">, Alias; +def: J<"entry=">, Alias; +def: Flag<["-"], "E">, Alias, HelpText<"Alias for --export-dynamic">; +def: Flag<["-"], "i">, Alias; +def: Flag<["-"], "m">, Alias; +def: Flag<["-"], "r">, Alias; +def: JoinedOrSeparate<["-"], "u">, Alias; // LTO-related options. def lto_O: J<"lto-O">, MetaVarName<"">, Index: lld/trunk/wasm/Symbols.cpp =================================================================== --- lld/trunk/wasm/Symbols.cpp +++ lld/trunk/wasm/Symbols.cpp @@ -105,10 +105,10 @@ if (ForceExport || Config->ExportAll) return true; - if (!Config->ExportDefault) - return false; + if (Config->ExportDynamic && !isHidden()) + return true; - return !isHidden(); + return false; } uint32_t FunctionSymbol::getFunctionIndex() const {