[WebAssembly] Add --[no]-export-dynamic to replace --export-default
In a very recent change I introduced a --no-export-default flag but after conferring with others it seems that this feature already exists in gnu GNU ld and lld in the form the --export-dynamic flag which is off by default. This change replaces export-default with export-dynamic and also changes the default to match the traditional linker behaviour. Now, by default, only the entry point is exported. If other symbols are required by the embedder then --export-dynamic or --export can be used to export all visibility hidden symbols or individual symbols respectively. This change touches a lot of tests that were relying on symbols being exported by default. I imagine it will also effect many users but do think the change is worth it match of the traditional behaviour and flag names. Differential Revision: https://reviews.llvm.org/D52587 llvm-svn: 343265
This commit is contained in:
parent
5f1b8181ad
commit
305b0343ce
|
@ -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"
|
||||
|
|
|
@ -5,9 +5,9 @@ RUN: llc -filetype=obj %S/Inputs/archive1.ll -o %t.a1.o
|
|||
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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 @@ entry:
|
|||
; 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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; 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: ...
|
||||
|
|
|
@ -22,7 +22,8 @@ define i32* @get_address_of_global_var() #0 {
|
|||
|
||||
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 @@ entry:
|
|||
; 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 @@ entry:
|
|||
; CHECK-NEXT: Body: 4180808080000B
|
||||
; CHECK-NEXT: - Index: 3
|
||||
; CHECK-NEXT: Locals:
|
||||
; CHECK-NEXT: Body: 1082808080001A0B
|
||||
; CHECK-NEXT: Body: 1082808080001A1081808080001A0B
|
||||
; CHECK-NEXT: ...
|
||||
|
|
|
@ -24,7 +24,7 @@ struct Configuration {
|
|||
bool Demangle;
|
||||
bool DisableVerify;
|
||||
bool ExportAll;
|
||||
bool ExportDefault;
|
||||
bool ExportDynamic;
|
||||
bool ExportTable;
|
||||
bool GcSections;
|
||||
bool ImportMemory;
|
||||
|
|
|
@ -373,8 +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->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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ 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">;
|
||||
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<"<entry>">,
|
||||
HelpText<"Name of entry point symbol">;
|
||||
|
@ -144,12 +144,13 @@ defm whole_archive: B<"whole-archive",
|
|||
"Do not force load of all members in a static library (default)">;
|
||||
|
||||
// Aliases
|
||||
def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
|
||||
def alias_entry_entry: J<"entry=">, Alias<entry>;
|
||||
def alias_initial_memory_i: Flag<["-"], "i">, Alias<initial_memory>;
|
||||
def alias_max_memory_m: Flag<["-"], "m">, Alias<max_memory>;
|
||||
def alias_relocatable_r: Flag<["-"], "r">, Alias<relocatable>;
|
||||
def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
|
||||
def: JoinedOrSeparate<["-"], "e">, Alias<entry>;
|
||||
def: J<"entry=">, Alias<entry>;
|
||||
def: Flag<["-"], "E">, Alias<export_dynamic>, HelpText<"Alias for --export-dynamic">;
|
||||
def: Flag<["-"], "i">, Alias<initial_memory>;
|
||||
def: Flag<["-"], "m">, Alias<max_memory>;
|
||||
def: Flag<["-"], "r">, Alias<relocatable>;
|
||||
def: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
|
||||
|
||||
// LTO-related options.
|
||||
def lto_O: J<"lto-O">, MetaVarName<"<opt-level>">,
|
||||
|
|
|
@ -105,10 +105,10 @@ bool Symbol::isExported() const {
|
|||
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 {
|
||||
|
|
Loading…
Reference in New Issue