[lld][WebAssembly] Honor --no-export-dynamic even with -shared
authorSam Clegg <sbc@chromium.org>
Mon, 19 Aug 2019 16:34:51 +0000 (16:34 +0000)
committerSam Clegg <sbc@chromium.org>
Mon, 19 Aug 2019 16:34:51 +0000 (16:34 +0000)
Differential Revision: https://reviews.llvm.org/D66359

llvm-svn: 369276

lld/test/wasm/shared-export-dynamic.ll [new file with mode: 0644]
lld/wasm/Driver.cpp

diff --git a/lld/test/wasm/shared-export-dynamic.ll b/lld/test/wasm/shared-export-dynamic.ll
new file mode 100644 (file)
index 0000000..c2c4a9f
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o
+
+; By default all `default` symbols should be exported
+; RUN: wasm-ld -shared -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=DEFAULT
+; DEFAULT: foo
+
+; Verify that `--no-export-dynamic` works with `-shared`
+; RUN: wasm-ld -shared --no-export-dynamic -o %t2.wasm %t.o
+; RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=NO-EXPORT
+; NO-EXPORT-NOT: foo
+
+target triple = "wasm32-unknown-emscripten"
+
+define default i32 @foo() {
+entry:
+  ret i32 0
+}
index 13b9e3c..a28b85d 100644 (file)
@@ -313,8 +313,6 @@ static void readConfigs(opt::InputArgList &args) {
   config->emitRelocs = args.hasArg(OPT_emit_relocs);
   config->entry = getEntry(args);
   config->exportAll = args.hasArg(OPT_export_all);
-  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);
@@ -358,6 +356,10 @@ static void readConfigs(opt::InputArgList &args) {
   config->zStackSize =
       args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
 
+  // Default value of exportDynamic depends on `-shared`
+  config->exportDynamic =
+      args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, config->shared);
+
   if (auto *arg = args.getLastArg(OPT_features)) {
     config->features =
         llvm::Optional<std::vector<std::string>>(std::vector<std::string>());
@@ -381,7 +383,6 @@ static void setConfigs() {
 
   if (config->shared) {
     config->importMemory = true;
-    config->exportDynamic = true;
     config->allowUndefined = true;
   }
 }