Index: test/wasm/export-all.ll =================================================================== --- /dev/null +++ test/wasm/export-all.ll @@ -0,0 +1,45 @@ +; RUN: llc -O0 -filetype=obj %s -o %t.o + +; RUN: wasm-ld -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s + +; RUN: wasm-ld --export-all -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=EXPORT + +; RUN: wasm-ld --export-all --no-gc-sections -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=NOGC + +; Verify the --export-all flag exports hidden symbols + +target triple = "wasm32-unknown-unknown" + +define hidden void @bar() local_unnamed_addr { +entry: + ret void +} + +define hidden void @foo() local_unnamed_addr { +entry: + ret void +} + +define hidden void @_start() local_unnamed_addr { +entry: + call void @foo() + ret void +} + +; CHECK: - Type: EXPORT +; CHECK: - Name: _start +; CHECK-NOT: - Name: bar +; CHECK-NOT: - Name: foo + +; EXPORT: - Type: EXPORT +; EXPORT: - Name: _start +; EXPORT-NOT: - Name: bar +; EXPORT: - Name: foo + +; NOGC: - Type: EXPORT +; NOGC: - Name: _start +; NOGC: - Name: bar +; NOGC: - Name: foo Index: wasm/Config.h =================================================================== --- wasm/Config.h +++ wasm/Config.h @@ -23,6 +23,7 @@ bool CompressRelocTargets; bool Demangle; bool DisableVerify; + bool ExportAll; bool ExportTable; bool GcSections; bool ImportMemory; Index: wasm/Driver.cpp =================================================================== --- wasm/Driver.cpp +++ wasm/Driver.cpp @@ -319,6 +319,7 @@ Config->Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true); Config->DisableVerify = Args.hasArg(OPT_disable_verify); Config->Entry = getEntry(Args, Args.hasArg(OPT_relocatable) ? "" : "_start"); + Config->ExportAll = Args.hasArg(OPT_export_all); Config->ExportTable = Args.hasArg(OPT_export_table); errorHandler().FatalWarnings = Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); Index: wasm/Options.td =================================================================== --- wasm/Options.td +++ wasm/Options.td @@ -105,6 +105,9 @@ defm export: Eq<"export">, HelpText<"Force a symbol to be exported">; +def export_all: F<"export-all">, + HelpText<"Export all symbols (normally combined with --no-gc-sections)">; + def export_table: F<"export-table">, HelpText<"Export function table to the environment">; Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -742,7 +742,9 @@ for (Symbol *Sym : Symtab->getSymbols()) { if (!Sym->isDefined()) continue; - if (Sym->isHidden() || Sym->isLocal()) + if (Sym->isHidden() && !Config->ExportAll) + continue; + if (Sym->isLocal()) continue; if (!Sym->isLive()) continue; @@ -752,6 +754,9 @@ if (auto *F = dyn_cast(Sym)) { Export = {Name, WASM_EXTERNAL_FUNCTION, F->getFunctionIndex()}; } else if (auto *G = dyn_cast(Sym)) { + // Cannot yet export mutable globals + if (G->getGlobalType()->Mutable) + continue; Export = {Name, WASM_EXTERNAL_GLOBAL, G->getGlobalIndex()}; } else { auto *D = cast(Sym);