Skip to content

Commit f6d29eb

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
WasmLifter: Handle non-local inputs based on types, not instructions
Change-Id: I42108ee26f2e9485148c6255bd77d7d162a15713 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/7967830 Commit-Queue: Matthias Liedtke <[email protected]> Reviewed-by: Carl Smith <[email protected]>
1 parent 6a13d68 commit f6d29eb

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/Fuzzilli/FuzzIL/TypeSystem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ public struct ILType: Hashable {
405405
return wasmType as? WasmTagType
406406
}
407407

408+
public var isWasmTagType: Bool {
409+
return wasmTagType != nil && ext?.group == "WasmTag"
410+
}
411+
408412
public var properties: Set<String> {
409413
return ext?.properties ?? Set()
410414
}

Sources/Fuzzilli/Lifting/WasmLifter.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ public class WasmLifter {
945945
// Check if instruction input is a parameter or if we have an expression for it, if so, we need to load it now.
946946
for input in instr.inputs {
947947
// Skip "internal" inputs, i.e. ones that don't map to a slot, such as .label variables
948-
if typer.type(of: input).Is(.label) {
948+
let inputType = typer.type(of: input)
949+
if inputType.Is(.label) || inputType.Is(.exceptionLabel) {
949950
continue
950951
}
951952

@@ -962,19 +963,16 @@ public class WasmLifter {
962963
continue
963964
}
964965

965-
// TODO(mliedtke): Make this an attribute.
966-
// Instruction has to be a glue instruction now, maybe add an attribute to the instruction that it may have non-wasm inputs, i.e. inputs that do not have a local slot.
967-
if instr.op is WasmLoadGlobal || instr.op is WasmStoreGlobal || instr.op is WasmJsCall
968-
|| instr.op is WasmMemoryStore || instr.op is WasmMemoryLoad || instr.op is WasmTableGet
969-
|| instr.op is WasmTableSet || instr.op is WasmBeginCatch || instr.op is WasmThrow
970-
|| instr.op is WasmRethrow || instr.op is WasmBeginBlock || instr.op is WasmBeginTry
971-
|| instr.op is WasmI64x2LoadSplat || instr.op is WasmBeginTryDelegate
972-
|| instr.op is WasmBeginIf || instr.op is WasmBeginElse {
973-
continue
966+
// Special inputs that aren't locals (e.g. memories, functions, tags, ...)
967+
let isLocallyDefined = inputType.isWasmTagType && tags.contains(input)
968+
|| inputType.isWasmTableType && tables.contains(where: {$0.output == input})
969+
|| inputType.Is(.wasmFuncRef) && functions.contains(where: {$0.outputVariable == input})
970+
|| inputType.isWasmGlobalType && globals.contains(where: {$0.output == input})
971+
|| inputType.isWasmMemoryType && memories.contains(where: {$0.output == input})
972+
if !isLocallyDefined {
973+
assert(self.imports.contains(where: {$0.0 == input}), "Variable \(input) needs to be imported during importAnalysis()")
974974
}
975-
fatalError("unreachable")
976975
}
977-
978976
}
979977

980978
private func emitBytesForInstruction(forInstruction instr: Instruction) throws {

0 commit comments

Comments
 (0)