summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/test/wasm/visibility-hidden.ll18
-rw-r--r--lld/wasm/Config.h1
-rw-r--r--lld/wasm/Driver.cpp2
-rw-r--r--lld/wasm/Options.td4
-rw-r--r--lld/wasm/Symbols.cpp3
5 files changed, 26 insertions, 2 deletions
diff --git a/lld/test/wasm/visibility-hidden.ll b/lld/test/wasm/visibility-hidden.ll
index f553c08159c..d1a83cdf407 100644
--- a/lld/test/wasm/visibility-hidden.ll
+++ b/lld/test/wasm/visibility-hidden.ll
@@ -2,11 +2,17 @@
; RUN: llc -filetype=obj %S/Inputs/hidden.ll -o %t2.o
; RUN: rm -f %t2.a
; RUN: llvm-ar rcs %t2.a %t2.o
-; RUN: wasm-ld %t.o %t2.a -o %t.wasm
-; RUN: obj2yaml %t.wasm | FileCheck %s
; 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
+; 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
+; RUN: obj2yaml %t.nodef.wasm | FileCheck %s -check-prefix=NO-DEFAULT
+
target triple = "wasm32-unknown-unknown"
@@ -53,3 +59,11 @@ entry:
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 5
; CHECK-NEXT: - Type:
+
+
+; NO-DEFAULT: - Type: EXPORT
+; NO-DEFAULT-NEXT: Exports:
+; NO-DEFAULT-NEXT: - Name: memory
+; NO-DEFAULT-NEXT: Kind: MEMORY
+; NO-DEFAULT-NEXT: Index: 0
+; NO-DEFAULT-NEXT: - Type:
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 76a78056707..ae8989f15d7 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -24,6 +24,7 @@ struct Configuration {
bool Demangle;
bool DisableVerify;
bool ExportAll;
+ bool ExportDefault;
bool ExportTable;
bool GcSections;
bool ImportMemory;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index f477ba3b235..789bda90b1a 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -373,6 +373,8 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
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->ExportTable = Args.hasArg(OPT_export_table);
errorHandler().FatalWarnings =
Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index e2922c24c90..e98b1b9f89a 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -30,6 +30,10 @@ defm demangle: B<"demangle",
"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">;
+
def entry: S<"entry">, MetaVarName<"<entry>">,
HelpText<"Name of entry point symbol">;
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index a11081cbcf7..68bcadbb9af 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -105,6 +105,9 @@ bool Symbol::isExported() const {
if (ForceExport || Config->ExportAll)
return true;
+ if (!Config->ExportDefault)
+ return false;
+
return !isHidden();
}
OpenPOWER on IntegriCloud