[lld] r343034 - [WebAssembly] Add --export-default/--no-export-default options
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 25 14:50:15 PDT 2018
Author: sbc
Date: Tue Sep 25 14:50:15 2018
New Revision: 343034
URL: http://llvm.org/viewvc/llvm-project?rev=343034&view=rev
Log:
[WebAssembly] Add --export-default/--no-export-default options
These option control weather or not symbols marked as visibility
default are exported in the output binary.
By default this is true, but emscripten prefers to control the
exported symbol list explicitly at link time and ignore the
symbol attributes.
Differential Revision: https://reviews.llvm.org/D52003
Modified:
lld/trunk/test/wasm/visibility-hidden.ll
lld/trunk/wasm/Config.h
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/Options.td
lld/trunk/wasm/Symbols.cpp
Modified: lld/trunk/test/wasm/visibility-hidden.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/visibility-hidden.ll?rev=343034&r1=343033&r2=343034&view=diff
==============================================================================
--- lld/trunk/test/wasm/visibility-hidden.ll (original)
+++ lld/trunk/test/wasm/visibility-hidden.ll Tue Sep 25 14:50:15 2018
@@ -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:
Modified: lld/trunk/wasm/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=343034&r1=343033&r2=343034&view=diff
==============================================================================
--- lld/trunk/wasm/Config.h (original)
+++ lld/trunk/wasm/Config.h Tue Sep 25 14:50:15 2018
@@ -24,6 +24,7 @@ struct Configuration {
bool Demangle;
bool DisableVerify;
bool ExportAll;
+ bool ExportDefault;
bool ExportTable;
bool GcSections;
bool ImportMemory;
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=343034&r1=343033&r2=343034&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Tue Sep 25 14:50:15 2018
@@ -373,6 +373,8 @@ void LinkerDriver::link(ArrayRef<const c
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);
Modified: lld/trunk/wasm/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Options.td?rev=343034&r1=343033&r2=343034&view=diff
==============================================================================
--- lld/trunk/wasm/Options.td (original)
+++ lld/trunk/wasm/Options.td Tue Sep 25 14:50:15 2018
@@ -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">;
Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=343034&r1=343033&r2=343034&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Tue Sep 25 14:50:15 2018
@@ -105,6 +105,9 @@ bool Symbol::isExported() const {
if (ForceExport || Config->ExportAll)
return true;
+ if (!Config->ExportDefault)
+ return false;
+
return !isHidden();
}
More information about the llvm-commits
mailing list