Skip to content

Commit 6faf787

Browse files
Doga YükselV8-internal LUCI CQ
authored andcommitted
[wasm] Add WasmRefEq operation and generator
Adds support for ref.eq instruction to be generated Bug: 474940922 Change-Id: I7b88ceffed5252878132406da30a570be01f13ad Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8933276 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Doga Yüksel <dyuksel@google.com>
1 parent 83d4fac commit 6faf787

16 files changed

Lines changed: 137 additions & 2 deletions

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,6 +4374,12 @@ public class ProgramBuilder {
43744374
return b.emit(WasmRefIsNull(), withInputs: [ref], types: [.wasmGenericRef]).output
43754375
}
43764376

4377+
@discardableResult
4378+
// TODO(pawkra): Support shared references.
4379+
public func wasmRefEq(_ lhs: Variable, _ rhs: Variable) -> Variable {
4380+
return b.emit(WasmRefEq(), withInputs: [lhs, rhs], types: [.wasmEqRef(), .wasmEqRef()]).output
4381+
}
4382+
43774383
@discardableResult
43784384
public func wasmRefI31(_ number: Variable, shared: Bool = false) -> Variable {
43794385
return b.emit(WasmRefI31(isShared: shared), withInputs: [number], types: [.wasmi32]).output

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public let codeGeneratorWeights = [
371371
"WasmStructSetGenerator": 5,
372372
"WasmRefNullGenerator": 5,
373373
"WasmRefIsNullGenerator": 5,
374+
"WasmRefEqGenerator": 5,
374375
"WasmRefI31Generator": 5,
375376
"WasmI31GetGenerator": 5,
376377
"WasmAnyConvertExternGenerator": 5,

Sources/Fuzzilli/CodeGen/WasmCodeGenerators.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ public let WasmCodeGenerators: [CodeGenerator] = [
312312
b.currentWasmModule.currentWasmFunction.wasmRefIsNull(ref)
313313
},
314314

315+
CodeGenerator(
316+
"WasmRefEqGenerator", inContext: .single(.wasmFunction),
317+
inputs: .required(.wasmEqRef(), .wasmEqRef()),
318+
produces: [.wasmi32]
319+
) { b, lhs, rhs in
320+
b.currentWasmModule.currentWasmFunction.wasmRefEq(lhs, rhs)
321+
},
322+
315323
// TODO(pawkra): add shared variant.
316324
CodeGenerator("WasmRefI31Generator", inContext: .single(.wasmFunction), inputs: .required(.wasmi32)) { b, value in
317325
b.currentWasmModule.currentWasmFunction.wasmRefI31(value, shared: false)

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,8 @@ extension Instruction: ProtobufConvertible {
16171617
}
16181618
case .wasmRefIsNull(_):
16191619
$0.wasmRefIsNull = Fuzzilli_Protobuf_WasmRefIsNull()
1620+
case .wasmRefEq(_):
1621+
$0.wasmRefEq = Fuzzilli_Protobuf_WasmRefEq()
16201622
case .wasmRefI31(let op):
16211623
$0.wasmRefI31 = Fuzzilli_Protobuf_WasmRefI31.with {
16221624
$0.isShared = op.isShared
@@ -2599,6 +2601,8 @@ extension Instruction: ProtobufConvertible {
25992601
op = p.hasType ? WasmRefNull(type: WasmTypeEnumToILType(p.type)) : WasmRefNull(type: nil)
26002602
case .wasmRefIsNull(_):
26012603
op = WasmRefIsNull()
2604+
case .wasmRefEq(_):
2605+
op = WasmRefEq()
26022606
case .wasmRefI31(let p):
26032607
op = WasmRefI31(isShared: p.isShared)
26042608
case .wasmI31Get(let p):

Sources/Fuzzilli/FuzzIL/JSTyper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ public struct JSTyper: Analyzer {
915915
}
916916
case .wasmRefIsNull(_):
917917
setType(of: instr.output, to: .wasmi32)
918+
case .wasmRefEq(_):
919+
setType(of: instr.output, to: .wasmi32)
918920
case .wasmRefI31(let op):
919921
setType(of: instr.output, to: .wasmRefI31(shared: op.isShared))
920922
case .wasmI31Get(_):

Sources/Fuzzilli/FuzzIL/Opcodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,5 @@ enum Opcode {
365365
case createNamedAsyncDisposableVariable(CreateNamedAsyncDisposableVariable)
366366
case wasmDefineAdHocSignatureType(WasmDefineAdHocSignatureType)
367367
case wasmStructNew(WasmStructNew)
368+
case wasmRefEq(WasmRefEq)
368369
}

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,14 @@ class WasmRefIsNull: WasmOperation {
22832283
}
22842284
}
22852285

2286+
class WasmRefEq: WasmOperation {
2287+
override var opcode: Opcode { .wasmRefEq(self) }
2288+
2289+
init() {
2290+
super.init(numInputs: 2, numOutputs: 1, requiredContext: [.wasmFunction])
2291+
}
2292+
}
2293+
22862294
class WasmRefI31: WasmOperation {
22872295
override var opcode: Opcode { .wasmRefI31(self) }
22882296
let isShared: Bool

Sources/Fuzzilli/Lifting/FuzzILLifter.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,9 @@ public class FuzzILLifter: Lifter {
13301330
case .wasmRefIsNull(_):
13311331
w.emit("\(output()) <- WasmRefIsNull \(input(0))")
13321332

1333+
case .wasmRefEq(_):
1334+
w.emit("\(output()) <- WasmRefEq \(input(0)) \(input(1))")
1335+
13331336
case .wasmRefI31(_):
13341337
w.emit("\(output()) <- WasmRefI31 \(input(0))")
13351338

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@ public class JavaScriptLifter: Lifter {
17891789
.wasmStructSet(_),
17901790
.wasmRefNull(_),
17911791
.wasmRefIsNull(_),
1792+
.wasmRefEq(_),
17921793
.wasmRefI31(_),
17931794
.wasmI31Get(_),
17941795
.wasmAnyConvertExtern(_),

Sources/Fuzzilli/Lifting/WasmLifter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,8 @@ public class WasmLifter {
21852185
return try Data([0xD0]) + encodeHeapType(typer.type(of: wasmInstruction.output))
21862186
case .wasmRefIsNull(_):
21872187
return Data([0xD1])
2188+
case .wasmRefEq(_):
2189+
return Data([0xD3])
21882190
case .wasmRefI31(let op):
21892191
return Data([Prefix.GC.rawValue, op.isShared ? 0x1F : 0x1C])
21902192
case .wasmI31Get(let op):

0 commit comments

Comments
 (0)