1
0
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:
Sam Clegg 2017-09-26 21:10:09 +00:00
parent e023b2c5fa
commit ea471eb2d8
3 changed files with 42 additions and 46 deletions

View File

@ -1036,7 +1036,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
registerFunctionType(WS);
// 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;
Import.ModuleName = WS.getModuleName();
Import.FieldName = WS.getName();
@ -1268,6 +1268,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
uint32_t Index = SymbolIndices.find(ResolvedSym)->second;
DEBUG(dbgs() << " -> index:" << Index << "\n");
SymbolIndices[&WS] = Index;
WasmExport Export;
Export.FieldName = WS.getName();
Export.Index = Index;

View File

@ -337,19 +337,11 @@ void WasmObjectFile::populateSymbolTable() {
Export.Kind == wasm::WASM_EXTERNAL_FUNCTION
? WasmSymbol::SymbolType::FUNCTION_EXPORT
: WasmSymbol::SymbolType::GLOBAL_EXPORT;
auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size());
if (Pair.second) {
SymbolMap.try_emplace(Export.Name, Symbols.size());
Symbols.emplace_back(Export.Name, ExportType,
ExportSection, Export.Index);
DEBUG(dbgs() << "Adding export: " << Symbols.back()
<< " 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");
}
}
}
}

View File

@ -29,42 +29,48 @@ entry:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ReturnType: I32
; CHECK-NEXT: ParamTypes:
; 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: - Type: FUNCTION
; CHECK-NEXT: FunctionTypes: [ 0, 0 ]
; CHECK: - Type: EXPORT
; CHECK-NEXT: - Type: TABLE
; 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: - Name: call_alias
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: foo
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: bar
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 1
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: bar_alias_address
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: foo_alias
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: bar_alias
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 1
; CHECK-NEXT: Index: 0
; CHECK: - Type: DATA
; CHECK-NEXT: Relocations:
@ -89,10 +95,8 @@ entry:
; CHECK-NEXT: Name: name
; CHECK-NEXT: FunctionNames:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: foo_alias
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: call_alias
; CHECK-NEXT: - Index: 2
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: foo
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
@ -111,12 +115,11 @@ entry:
; CHECK-NEXT: ...
; CHECK-SYMS: SYMBOL TABLE:
; CHECK-SYMS-NEXT: 00000000 g F name foo_alias
; CHECK-SYMS-NEXT: 00000001 g F name call_alias
; CHECK-SYMS-NEXT: 00000002 g F name foo
; CHECK-SYMS-NEXT: 00000002 gw F EXPORT foo_alias
; 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 F name call_alias
; CHECK-SYMS-NEXT: 00000001 g F name foo
; CHECK-SYMS-NEXT: 00000000 g F EXPORT call_alias
; CHECK-SYMS-NEXT: 00000001 g F EXPORT foo
; CHECK-SYMS-NEXT: 00000000 g EXPORT bar
; 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