mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-04 03:06:28 +00:00
[WebAssembly] MC: Include unnamed data when writing wasm files
Also, include global entries for all data symbols, not just external ones, since these are referenced by the relocation records. Add a test case that includes unnamed data. Differential Revision: https://reviews.llvm.org/D33079 llvm-svn: 303915
This commit is contained in:
parent
d610ac22c2
commit
3355039d68
@ -422,6 +422,7 @@ static void ApplyRelocations(
|
||||
RelEntry.Offset;
|
||||
switch (RelEntry.Type) {
|
||||
case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: {
|
||||
assert(SymbolIndices.count(RelEntry.Symbol));
|
||||
uint32_t Index = SymbolIndices[RelEntry.Symbol];
|
||||
assert(RelEntry.Addend == 0);
|
||||
|
||||
@ -429,6 +430,7 @@ static void ApplyRelocations(
|
||||
break;
|
||||
}
|
||||
case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: {
|
||||
assert(SymbolIndices.count(RelEntry.Symbol));
|
||||
uint32_t Index = SymbolIndices[RelEntry.Symbol];
|
||||
assert(RelEntry.Addend == 0);
|
||||
|
||||
@ -448,6 +450,7 @@ static void ApplyRelocations(
|
||||
break;
|
||||
}
|
||||
case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: {
|
||||
assert(SymbolIndices.count(RelEntry.Symbol));
|
||||
uint32_t Index = SymbolIndices[RelEntry.Symbol];
|
||||
assert(RelEntry.Addend == 0);
|
||||
|
||||
@ -478,6 +481,7 @@ WriteRelocations(ArrayRef<WasmRelocationEntry> Relocations,
|
||||
|
||||
uint64_t Offset = RelEntry.Offset +
|
||||
RelEntry.FixupSection->getSectionOffset() + HeaderSize;
|
||||
assert(SymbolIndices.count(RelEntry.Symbol));
|
||||
uint32_t Index = SymbolIndices[RelEntry.Symbol];
|
||||
int64_t Addend = RelEntry.Addend;
|
||||
|
||||
@ -726,10 +730,6 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
|
||||
if (IsAddressTaken.count(&WS))
|
||||
TableElems.push_back(Index);
|
||||
} else {
|
||||
// For now, ignore temporary non-function symbols.
|
||||
if (S.isTemporary())
|
||||
continue;
|
||||
|
||||
if (WS.getOffset() != 0)
|
||||
report_fatal_error("data sections must contain one variable each");
|
||||
if (!WS.getSize())
|
||||
@ -777,20 +777,18 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
|
||||
}
|
||||
}
|
||||
|
||||
// For each external global, prepare a corresponding wasm global
|
||||
// holding its address.
|
||||
if (WS.isExternal()) {
|
||||
Index = NumGlobalImports + Globals.size();
|
||||
// For each global, prepare a corresponding wasm global holding its
|
||||
// address. For externals these will also be named exports.
|
||||
Index = NumGlobalImports + Globals.size();
|
||||
|
||||
WasmGlobal Global;
|
||||
Global.Type = PtrType;
|
||||
Global.IsMutable = false;
|
||||
Global.HasImport = false;
|
||||
Global.InitialValue = DataSection.getSectionOffset();
|
||||
Global.ImportIndex = 0;
|
||||
SymbolIndices[&WS] = Index;
|
||||
Globals.push_back(Global);
|
||||
}
|
||||
WasmGlobal Global;
|
||||
Global.Type = PtrType;
|
||||
Global.IsMutable = false;
|
||||
Global.HasImport = false;
|
||||
Global.InitialValue = DataSection.getSectionOffset();
|
||||
Global.ImportIndex = 0;
|
||||
SymbolIndices[&WS] = Index;
|
||||
Globals.push_back(Global);
|
||||
}
|
||||
}
|
||||
|
||||
|
53
test/MC/WebAssembly/unnamed-data.ll
Normal file
53
test/MC/WebAssembly/unnamed-data.ll
Normal file
@ -0,0 +1,53 @@
|
||||
; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s
|
||||
|
||||
@.str1 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
|
||||
@.str2 = private unnamed_addr constant [6 x i8] c"world\00", align 1
|
||||
|
||||
@a = global i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str1, i32 0, i32 0), align 8
|
||||
@b = global i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str2, i32 0, i32 0), align 8
|
||||
|
||||
|
||||
; CHECK: - Type: GLOBAL
|
||||
; CHECK: Globals:
|
||||
; CHECK: - Type: I32
|
||||
; CHECK: Mutable: false
|
||||
; CHECK: InitExpr:
|
||||
; CHECK: Opcode: I32_CONST
|
||||
; CHECK: Value: 0
|
||||
; CHECK: - Type: I32
|
||||
; CHECK: Mutable: false
|
||||
; CHECK: InitExpr:
|
||||
; CHECK: Opcode: I32_CONST
|
||||
; CHECK: Value: 6
|
||||
; CHECK: - Type: I32
|
||||
; CHECK: Mutable: false
|
||||
; CHECK: InitExpr:
|
||||
; CHECK: Opcode: I32_CONST
|
||||
; CHECK: Value: 16
|
||||
; CHECK: - Type: I32
|
||||
; CHECK: Mutable: false
|
||||
; CHECK: InitExpr:
|
||||
; CHECK: Opcode: I32_CONST
|
||||
; CHECK: Value: 24
|
||||
; CHECK: - Type: EXPORT
|
||||
; CHECK: Exports:
|
||||
; CHECK: - Name: a
|
||||
; CHECK: Kind: GLOBAL
|
||||
; CHECK: Index: 2
|
||||
; CHECK: - Name: b
|
||||
; CHECK: Kind: GLOBAL
|
||||
; CHECK: Index: 3
|
||||
; CHECK: - Type: DATA
|
||||
; CHECK: Relocations:
|
||||
; CHECK: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
|
||||
; CHECK: Index: 0
|
||||
; CHECK: Offset: 0x00000016
|
||||
; CHECK: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
|
||||
; CHECK: Index: 1
|
||||
; CHECK: Offset: 0x0000001E
|
||||
; CHECK: Segments:
|
||||
; CHECK: - Index: 0
|
||||
; CHECK: Offset:
|
||||
; CHECK: Opcode: I32_CONST
|
||||
; CHECK: Value: 0
|
||||
; CHECK: Content: 68656C6C6F00776F726C640000000000000000000000000006000000
|
Loading…
x
Reference in New Issue
Block a user