forked from OSchip/llvm-project
[WebAssembly] Allow undefined symbols when building shared libraries
Differential Revision: https://reviews.llvm.org/D55043 llvm-svn: 347909
This commit is contained in:
parent
80fabab677
commit
0f90191faa
|
@ -4,27 +4,34 @@
|
|||
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
@used_data = hidden global i32 2, align 4
|
||||
@data = hidden global i32 2, align 4
|
||||
@indirect_func = local_unnamed_addr global void ()* @foo, align 4
|
||||
@indirect_func_external = local_unnamed_addr global void ()* @func_external, align 4
|
||||
|
||||
define default void @foo() {
|
||||
entry:
|
||||
; To ensure we use __stack_pointer
|
||||
%ptr = alloca i32
|
||||
%0 = load i32, i32* @used_data, align 4
|
||||
%1 = load void ()*, void ()** @indirect_func, align 4
|
||||
call void %1()
|
||||
%0 = load i32, i32* @data, align 4
|
||||
%1 = load i32, i32* @data_external, align 4
|
||||
%2 = load void ()*, void ()** @indirect_func, align 4
|
||||
call void %2()
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @func_external()
|
||||
|
||||
@data_external = external global i32
|
||||
|
||||
|
||||
; check for dylink section at start
|
||||
|
||||
; CHECK: Sections:
|
||||
; CHECK-NEXT: - Type: CUSTOM
|
||||
; CHECK-NEXT: Name: dylink
|
||||
; CHECK-NEXT: MemorySize: 4
|
||||
; CHECK-NEXT: MemorySize: 8
|
||||
; CHECK-NEXT: MemoryAlignment: 2
|
||||
; CHECK-NEXT: TableSize: 1
|
||||
; CHECK-NEXT: TableSize: 2
|
||||
; CHECK-NEXT: TableAlignment: 0
|
||||
|
||||
; check for import of __table_base and __memory_base globals
|
||||
|
@ -38,8 +45,8 @@ entry:
|
|||
; CHECK-NEXT: ElemType: ANYFUNC
|
||||
; CHECK-NEXT: Limits:
|
||||
; CHECK-NEXT: Flags: [ HAS_MAX ]
|
||||
; CHECK-NEXT: Initial: 0x00000001
|
||||
; CHECK-NEXT: Maximum: 0x00000001
|
||||
; CHECK-NEXT: Initial: 0x00000002
|
||||
; CHECK-NEXT: Maximum: 0x00000002
|
||||
; CHECK-NEXT: - Module: env
|
||||
; CHECK-NEXT: Field: __stack_pointer
|
||||
; CHECK-NEXT: Kind: GLOBAL
|
||||
|
@ -63,7 +70,7 @@ entry:
|
|||
; CHECK-NEXT: - Offset:
|
||||
; CHECK-NEXT: Opcode: GET_GLOBAL
|
||||
; CHECK-NEXT: Index: 2
|
||||
; CHECK-NEXT: Functions: [ 1 ]
|
||||
; CHECK-NEXT: Functions: [ 2, 0 ]
|
||||
|
||||
; check the data segment initialized with __memory_base global as offset
|
||||
|
||||
|
@ -74,4 +81,4 @@ entry:
|
|||
; CHECK-NEXT: Offset:
|
||||
; CHECK-NEXT: Opcode: GET_GLOBAL
|
||||
; CHECK-NEXT: Index: 1
|
||||
; CHECK-NEXT: Content: '00000000'
|
||||
; CHECK-NEXT: Content: '0000000001000000'
|
||||
|
|
|
@ -313,8 +313,7 @@ static void handleWeakUndefines() {
|
|||
// be GC'd if not used as the target of any "call" instructions.
|
||||
std::string SymName = toString(*Sym);
|
||||
StringRef DebugName = Saver.save("undefined function " + SymName);
|
||||
SyntheticFunction *Func =
|
||||
make<SyntheticFunction>(Sig, Sym->getName(), DebugName);
|
||||
auto *Func = make<SyntheticFunction>(Sig, Sym->getName(), DebugName);
|
||||
Func->setBody(UnreachableFn);
|
||||
// Ensure it compares equal to the null pointer, and so that table relocs
|
||||
// don't pull in the stub body (only call-operand relocs should do that).
|
||||
|
@ -448,9 +447,10 @@ static void createSyntheticSymbols() {
|
|||
static llvm::wasm::WasmGlobalType MutableGlobalTypeI32 = {WASM_TYPE_I32,
|
||||
true};
|
||||
|
||||
WasmSym::CallCtors = Symtab->addSyntheticFunction(
|
||||
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
|
||||
make<SyntheticFunction>(NullSignature, "__wasm_call_ctors"));
|
||||
if (!Config->Relocatable)
|
||||
WasmSym::CallCtors = Symtab->addSyntheticFunction(
|
||||
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
|
||||
make<SyntheticFunction>(NullSignature, "__wasm_call_ctors"));
|
||||
|
||||
// The __stack_pointer is imported in the shared library case, and exported
|
||||
// in the non-shared (executable) case.
|
||||
|
@ -463,7 +463,7 @@ static void createSyntheticSymbols() {
|
|||
Global.InitExpr.Value.Int32 = 0;
|
||||
Global.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
|
||||
Global.SymbolName = "__stack_pointer";
|
||||
InputGlobal *StackPointer = make<InputGlobal>(Global, nullptr);
|
||||
auto *StackPointer = make<InputGlobal>(Global, nullptr);
|
||||
StackPointer->Live = true;
|
||||
// For non-PIC code
|
||||
// TODO(sbc): Remove WASM_SYMBOL_VISIBILITY_HIDDEN when the mutable global
|
||||
|
@ -543,8 +543,10 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
Config->ImportTable = true;
|
||||
}
|
||||
|
||||
if (Config->Shared)
|
||||
if (Config->Shared) {
|
||||
Config->ExportDynamic = true;
|
||||
Config->AllowUndefined = true;
|
||||
}
|
||||
|
||||
if (!Config->Relocatable)
|
||||
createSyntheticSymbols();
|
||||
|
|
Loading…
Reference in New Issue