mirror of
https://github.com/intel/llvm.git
synced 2026-01-21 04:14:03 +08:00
[WebAssembly] 64-bit (function) pointer fixes.
Accounting for the fact that Wasm function indices are 32-bit, but in wasm64 we want uniform 64-bit pointers. Includes reloc types for 64-bit table indices. Differential Revision: https://reviews.llvm.org/D83729
This commit is contained in:
@@ -72,6 +72,7 @@ void InputChunk::verifyRelocTargets() const {
|
||||
existingValue = decodeULEB128(loc, &bytesRead);
|
||||
break;
|
||||
case R_WASM_TABLE_INDEX_SLEB:
|
||||
case R_WASM_TABLE_INDEX_SLEB64:
|
||||
case R_WASM_TABLE_INDEX_REL_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_SLEB64:
|
||||
@@ -86,6 +87,7 @@ void InputChunk::verifyRelocTargets() const {
|
||||
case R_WASM_GLOBAL_INDEX_I32:
|
||||
existingValue = read32le(loc);
|
||||
break;
|
||||
case R_WASM_TABLE_INDEX_I64:
|
||||
case R_WASM_MEMORY_ADDR_I64:
|
||||
existingValue = read64le(loc);
|
||||
break;
|
||||
@@ -151,6 +153,7 @@ void InputChunk::writeTo(uint8_t *buf) const {
|
||||
case R_WASM_MEMORY_ADDR_REL_SLEB:
|
||||
encodeSLEB128(static_cast<int32_t>(value), loc, 5);
|
||||
break;
|
||||
case R_WASM_TABLE_INDEX_SLEB64:
|
||||
case R_WASM_MEMORY_ADDR_SLEB64:
|
||||
case R_WASM_MEMORY_ADDR_REL_SLEB64:
|
||||
encodeSLEB128(static_cast<int64_t>(value), loc, 10);
|
||||
@@ -162,6 +165,7 @@ void InputChunk::writeTo(uint8_t *buf) const {
|
||||
case R_WASM_GLOBAL_INDEX_I32:
|
||||
write32le(loc, value);
|
||||
break;
|
||||
case R_WASM_TABLE_INDEX_I64:
|
||||
case R_WASM_MEMORY_ADDR_I64:
|
||||
write64le(loc, value);
|
||||
break;
|
||||
@@ -219,6 +223,7 @@ static unsigned writeCompressedReloc(uint8_t *buf, const WasmRelocation &rel,
|
||||
case R_WASM_MEMORY_ADDR_LEB64:
|
||||
return encodeULEB128(value, buf);
|
||||
case R_WASM_TABLE_INDEX_SLEB:
|
||||
case R_WASM_TABLE_INDEX_SLEB64:
|
||||
case R_WASM_MEMORY_ADDR_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_SLEB64:
|
||||
return encodeSLEB128(static_cast<int64_t>(value), buf);
|
||||
@@ -237,6 +242,7 @@ static unsigned getRelocWidthPadded(const WasmRelocation &rel) {
|
||||
case R_WASM_TABLE_INDEX_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_SLEB:
|
||||
return 5;
|
||||
case R_WASM_TABLE_INDEX_SLEB64:
|
||||
case R_WASM_MEMORY_ADDR_LEB64:
|
||||
case R_WASM_MEMORY_ADDR_SLEB64:
|
||||
return 10;
|
||||
@@ -382,7 +388,8 @@ void InputSegment::generateRelocationCode(raw_ostream &os) const {
|
||||
}
|
||||
} else {
|
||||
const GlobalSymbol* baseSymbol = WasmSym::memoryBase;
|
||||
if (rel.Type == R_WASM_TABLE_INDEX_I32)
|
||||
if (rel.Type == R_WASM_TABLE_INDEX_I32 ||
|
||||
rel.Type == R_WASM_TABLE_INDEX_I64)
|
||||
baseSymbol = WasmSym::tableBase;
|
||||
writeU8(os, WASM_OPCODE_GLOBAL_GET, "GLOBAL_GET");
|
||||
writeUleb128(os, baseSymbol->getGlobalIndex(), "base");
|
||||
|
||||
Reference in New Issue
Block a user