mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[WebAssembly] Model weakly defined symbols as wasm exports
Previously these were being included as both imports and exports, with the import being satisfied by the export (or some strong symbol) at runtime. However proved unnecessary and actually complicated linking as it meant there was not a 1-to-1 mapping between a wasm function /global index and a linker symbol. Differential Revision: https://reviews.llvm.org/D38246 llvm-svn: 314245
This commit is contained in:
parent
e023b2c5fa
commit
ea471eb2d8
@ -1036,7 +1036,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
|
|||||||
registerFunctionType(WS);
|
registerFunctionType(WS);
|
||||||
|
|
||||||
// If the symbol is not defined in this translation unit, import it.
|
// If the symbol is not defined in this translation unit, import it.
|
||||||
if (!WS.isDefined(/*SetUsed=*/false) || WS.isVariable()) {
|
if (!WS.isDefined(/*SetUsed=*/false)) {
|
||||||
WasmImport Import;
|
WasmImport Import;
|
||||||
Import.ModuleName = WS.getModuleName();
|
Import.ModuleName = WS.getModuleName();
|
||||||
Import.FieldName = WS.getName();
|
Import.FieldName = WS.getName();
|
||||||
@ -1268,6 +1268,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
|
|||||||
uint32_t Index = SymbolIndices.find(ResolvedSym)->second;
|
uint32_t Index = SymbolIndices.find(ResolvedSym)->second;
|
||||||
DEBUG(dbgs() << " -> index:" << Index << "\n");
|
DEBUG(dbgs() << " -> index:" << Index << "\n");
|
||||||
|
|
||||||
|
SymbolIndices[&WS] = Index;
|
||||||
WasmExport Export;
|
WasmExport Export;
|
||||||
Export.FieldName = WS.getName();
|
Export.FieldName = WS.getName();
|
||||||
Export.Index = Index;
|
Export.Index = Index;
|
||||||
|
@ -337,19 +337,11 @@ void WasmObjectFile::populateSymbolTable() {
|
|||||||
Export.Kind == wasm::WASM_EXTERNAL_FUNCTION
|
Export.Kind == wasm::WASM_EXTERNAL_FUNCTION
|
||||||
? WasmSymbol::SymbolType::FUNCTION_EXPORT
|
? WasmSymbol::SymbolType::FUNCTION_EXPORT
|
||||||
: WasmSymbol::SymbolType::GLOBAL_EXPORT;
|
: WasmSymbol::SymbolType::GLOBAL_EXPORT;
|
||||||
auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size());
|
SymbolMap.try_emplace(Export.Name, Symbols.size());
|
||||||
if (Pair.second) {
|
Symbols.emplace_back(Export.Name, ExportType,
|
||||||
Symbols.emplace_back(Export.Name, ExportType,
|
ExportSection, Export.Index);
|
||||||
ExportSection, Export.Index);
|
DEBUG(dbgs() << "Adding export: " << Symbols.back()
|
||||||
DEBUG(dbgs() << "Adding export: " << Symbols.back()
|
<< " sym index:" << Symbols.size() << "\n");
|
||||||
<< " sym index:" << Symbols.size() << "\n");
|
|
||||||
} else {
|
|
||||||
uint32_t SymIndex = Pair.first->second;
|
|
||||||
Symbols[SymIndex] =
|
|
||||||
WasmSymbol(Export.Name, ExportType, ExportSection, Export.Index);
|
|
||||||
DEBUG(dbgs() << "Replacing existing symbol: " << Symbols[SymIndex]
|
|
||||||
<< " sym index:" << SymIndex << "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,42 +29,48 @@ entry:
|
|||||||
; CHECK-NEXT: - Index: 0
|
; CHECK-NEXT: - Index: 0
|
||||||
; CHECK-NEXT: ReturnType: I32
|
; CHECK-NEXT: ReturnType: I32
|
||||||
; CHECK-NEXT: ParamTypes:
|
; CHECK-NEXT: ParamTypes:
|
||||||
|
; CHECK-NEXT: - Type: FUNCTION
|
||||||
; CHECK: - Type: IMPORT
|
|
||||||
; CHECK-NEXT: Imports:
|
|
||||||
; CHECK-NEXT: - Module: env
|
|
||||||
; CHECK-NEXT: Field: foo_alias
|
|
||||||
; CHECK-NEXT: Kind: FUNCTION
|
|
||||||
; CHECK-NEXT: SigIndex: 0
|
|
||||||
; CHECK-NEXT: - Module: env
|
|
||||||
; CHECK-NEXT: Field: bar_alias
|
|
||||||
; CHECK-NEXT: Kind: GLOBAL
|
|
||||||
; CHECK-NEXT: GlobalType: I32
|
|
||||||
; CHECK-NEXT: GlobalMutable: false
|
|
||||||
|
|
||||||
; CHECK: - Type: FUNCTION
|
|
||||||
; CHECK-NEXT: FunctionTypes: [ 0, 0 ]
|
; CHECK-NEXT: FunctionTypes: [ 0, 0 ]
|
||||||
|
; CHECK-NEXT: - Type: TABLE
|
||||||
; CHECK: - Type: EXPORT
|
; CHECK-NEXT: Tables:
|
||||||
|
; CHECK-NEXT: - ElemType: ANYFUNC
|
||||||
|
; CHECK-NEXT: Limits:
|
||||||
|
; CHECK-NEXT: Initial: 0x00000000
|
||||||
|
; CHECK-NEXT: - Type: MEMORY
|
||||||
|
; CHECK-NEXT: Memories:
|
||||||
|
; CHECK-NEXT: - Initial: 0x00000001
|
||||||
|
; CHECK-NEXT: - Type: GLOBAL
|
||||||
|
; CHECK-NEXT: Globals:
|
||||||
|
; CHECK-NEXT: - Type: I32
|
||||||
|
; CHECK-NEXT: Mutable: false
|
||||||
|
; CHECK-NEXT: InitExpr:
|
||||||
|
; CHECK-NEXT: Opcode: I32_CONST
|
||||||
|
; CHECK-NEXT: Value: 0
|
||||||
|
; CHECK-NEXT: - Type: I32
|
||||||
|
; CHECK-NEXT: Mutable: false
|
||||||
|
; CHECK-NEXT: InitExpr:
|
||||||
|
; CHECK-NEXT: Opcode: I32_CONST
|
||||||
|
; CHECK-NEXT: Value: 8
|
||||||
|
; CHECK-NEXT: - Type: EXPORT
|
||||||
; CHECK-NEXT: Exports:
|
; CHECK-NEXT: Exports:
|
||||||
; CHECK-NEXT: - Name: call_alias
|
; CHECK-NEXT: - Name: call_alias
|
||||||
; CHECK-NEXT: Kind: FUNCTION
|
; CHECK-NEXT: Kind: FUNCTION
|
||||||
; CHECK-NEXT: Index: 1
|
; CHECK-NEXT: Index: 0
|
||||||
; CHECK-NEXT: - Name: foo
|
; CHECK-NEXT: - Name: foo
|
||||||
; CHECK-NEXT: Kind: FUNCTION
|
; CHECK-NEXT: Kind: FUNCTION
|
||||||
; CHECK-NEXT: Index: 2
|
; CHECK-NEXT: Index: 1
|
||||||
; CHECK-NEXT: - Name: bar
|
; CHECK-NEXT: - Name: bar
|
||||||
; CHECK-NEXT: Kind: GLOBAL
|
; CHECK-NEXT: Kind: GLOBAL
|
||||||
; CHECK-NEXT: Index: 1
|
; CHECK-NEXT: Index: 0
|
||||||
; CHECK-NEXT: - Name: bar_alias_address
|
; CHECK-NEXT: - Name: bar_alias_address
|
||||||
; CHECK-NEXT: Kind: GLOBAL
|
; CHECK-NEXT: Kind: GLOBAL
|
||||||
; CHECK-NEXT: Index: 2
|
; CHECK-NEXT: Index: 1
|
||||||
; CHECK-NEXT: - Name: foo_alias
|
; CHECK-NEXT: - Name: foo_alias
|
||||||
; CHECK-NEXT: Kind: FUNCTION
|
; CHECK-NEXT: Kind: FUNCTION
|
||||||
; CHECK-NEXT: Index: 2
|
; CHECK-NEXT: Index: 1
|
||||||
; CHECK-NEXT: - Name: bar_alias
|
; CHECK-NEXT: - Name: bar_alias
|
||||||
; CHECK-NEXT: Kind: GLOBAL
|
; CHECK-NEXT: Kind: GLOBAL
|
||||||
; CHECK-NEXT: Index: 1
|
; CHECK-NEXT: Index: 0
|
||||||
|
|
||||||
; CHECK: - Type: DATA
|
; CHECK: - Type: DATA
|
||||||
; CHECK-NEXT: Relocations:
|
; CHECK-NEXT: Relocations:
|
||||||
@ -89,10 +95,8 @@ entry:
|
|||||||
; CHECK-NEXT: Name: name
|
; CHECK-NEXT: Name: name
|
||||||
; CHECK-NEXT: FunctionNames:
|
; CHECK-NEXT: FunctionNames:
|
||||||
; CHECK-NEXT: - Index: 0
|
; CHECK-NEXT: - Index: 0
|
||||||
; CHECK-NEXT: Name: foo_alias
|
|
||||||
; CHECK-NEXT: - Index: 1
|
|
||||||
; CHECK-NEXT: Name: call_alias
|
; CHECK-NEXT: Name: call_alias
|
||||||
; CHECK-NEXT: - Index: 2
|
; CHECK-NEXT: - Index: 1
|
||||||
; CHECK-NEXT: Name: foo
|
; CHECK-NEXT: Name: foo
|
||||||
; CHECK-NEXT: - Type: CUSTOM
|
; CHECK-NEXT: - Type: CUSTOM
|
||||||
; CHECK-NEXT: Name: linking
|
; CHECK-NEXT: Name: linking
|
||||||
@ -111,12 +115,11 @@ entry:
|
|||||||
; CHECK-NEXT: ...
|
; CHECK-NEXT: ...
|
||||||
|
|
||||||
; CHECK-SYMS: SYMBOL TABLE:
|
; CHECK-SYMS: SYMBOL TABLE:
|
||||||
; CHECK-SYMS-NEXT: 00000000 g F name foo_alias
|
; CHECK-SYMS-NEXT: 00000000 g F name call_alias
|
||||||
; CHECK-SYMS-NEXT: 00000001 g F name call_alias
|
; CHECK-SYMS-NEXT: 00000001 g F name foo
|
||||||
; CHECK-SYMS-NEXT: 00000002 g F name foo
|
; CHECK-SYMS-NEXT: 00000000 g F EXPORT call_alias
|
||||||
; CHECK-SYMS-NEXT: 00000002 gw F EXPORT foo_alias
|
; CHECK-SYMS-NEXT: 00000001 g F EXPORT foo
|
||||||
; CHECK-SYMS-NEXT: 00000000 gw EXPORT bar_alias
|
|
||||||
; CHECK-SYMS-NEXT: 00000001 g F EXPORT call_alias
|
|
||||||
; CHECK-SYMS-NEXT: 00000002 g F EXPORT foo
|
|
||||||
; CHECK-SYMS-NEXT: 00000000 g EXPORT bar
|
; CHECK-SYMS-NEXT: 00000000 g EXPORT bar
|
||||||
; CHECK-SYMS-NEXT: 00000008 g EXPORT bar_alias_address
|
; CHECK-SYMS-NEXT: 00000008 g EXPORT bar_alias_address
|
||||||
|
; CHECK-SYMS-NEXT: 00000001 gw F EXPORT foo_alias
|
||||||
|
; CHECK-SYMS-NEXT: 00000000 gw EXPORT bar_alias
|
||||||
|
Loading…
Reference in New Issue
Block a user