Skip to content

Commit be2811d

Browse files
leonbettv8-internal-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[wasm] Derive the typer's Wasm exports from a WasmModuleInterface
The typer predicts which objects a Wasm module imports and under which names the lifted module re-exports them, but it used its own copy of the lifter's rules. For JS functions, these had drifted: the lifter imports a JS function once per Wasm signature of the wasmJsCalls that call it and once per signature type of the table entries that hold it, while the typer registered it once per JS signature. So the typer's iw<n> exports could differ from the actual ones. This CL adds WasmModuleInterface, which records the imports and definitions of a module with the **lifter's** rules and derives the export names from them. The JSTyper records it while typing the module and derives the type of the exports object from it. The subsequent CL will make WasmLifter reuse the typer's results, so that the two can't get out of sync anymore. Misc: - Re-exported JS functions are now typed with their import's Wasm signature converted to JS, instead of the JS function's own signature, as the re-export converts arguments and results according to the import's signature. - The typer doesn't need its DefUseAnalyzer anymore, so this also removes it and the isBundle parameter that only served it. Bug: 555602358 Change-Id: I3d97343782bf8160a0260a625c892e6c3981f377 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9910835 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Leon Bettscheider <bettscheider@chromium.org>
1 parent d01e5fe commit be2811d

11 files changed

Lines changed: 354 additions & 256 deletions

File tree

‎Sources/Fuzzilli/Base/ProgramBuilder.swift‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public class ProgramBuilder {
226226
/// Constructs a new program builder for the given fuzzer.
227227
init(for fuzzer: Fuzzer, parent: Program?, isBundle: Bool) {
228228
self.fuzzer = fuzzer
229-
self.jsTyper = JSTyper(for: fuzzer.environment, isBundle: isBundle)
229+
self.jsTyper = JSTyper(for: fuzzer.environment)
230230
self.parent = parent
231231
self.isBundle = isBundle
232232

@@ -1842,7 +1842,7 @@ public class ProgramBuilder {
18421842
// Step (2): determine which instructions can be part of the slice and attempt to find replacement variables for the outputs of instructions that cannot be included.
18431843
//
18441844
// We need a typer to be able to find compatible replacement variables if we are merging the dataflows of the two programs.
1845-
var typer = JSTyper(for: fuzzer.environment, isBundle: program.code.isBundle)
1845+
var typer = JSTyper(for: fuzzer.environment)
18461846
// The set of variables that are available for a slice. A variable is available either because the instruction that outputs
18471847
// it can be part of the slice or because the variable has been remapped to a host variable.
18481848
var availableVariables = VariableSet()
@@ -8122,7 +8122,9 @@ public class ProgramBuilder {
81228122
activeWasmModule!.setModuleVariable(variable: instr.output)
81238123
activeWasmModule = nil
81248124
case .endWasmFunction:
8125-
activeWasmModule!.methods.append("w\(activeWasmModule!.methods.count)")
8125+
activeWasmModule!.methods.append(
8126+
WasmModuleInterface.exportName(
8127+
of: .function, index: activeWasmModule!.methods.count, isImport: false))
81268128
case .wasmDefineGlobal(_),
81278129
.wasmDefineTable(_),
81288130
.wasmDefineMemory(_),

‎Sources/Fuzzilli/CodeGen/ProgramTemplates.swift‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,9 @@ public let ProgramTemplates = [
599599

600600
// 2. In JavaScript, obtain references to the exported Wasm function and memory.
601601
let exports = module.loadExports()
602-
let wasmFunc = b.getProperty("w0", of: exports)
603-
let exportedMem = b.getProperty("wm0", of: exports)
602+
let wasmFunc = b.getProperty(module.getExportedMethod(at: 0), of: exports)
603+
let exportedMem = b.getProperty(
604+
WasmModuleInterface.exportName(of: .memory, index: 0, isImport: false), of: exports)
604605

605606
// 3. Create a ResizableArrayBuffer (RAB) and a random TypedArray view on the Wasm memory.
606607
let rab = b.callMethod("toResizableBuffer", on: exportedMem)
@@ -652,8 +653,9 @@ public let ProgramTemplates = [
652653
}
653654
}
654655
let exports = module.loadExports()
655-
let memory = b.getProperty("wm0", of: exports)
656-
let wasmGrow = b.getProperty("w0", of: exports)
656+
let memory = b.getProperty(
657+
WasmModuleInterface.exportName(of: .memory, index: 0, isImport: false), of: exports)
658+
let wasmGrow = b.getProperty(module.getExportedMethod(at: 0), of: exports)
657659

658660
// 2. JS Loop
659661
b.buildRepeatLoop(n: 20) { _ in

‎Sources/Fuzzilli/FuzzIL/Analyzer.swift‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,15 @@ extension Analyzer {
3737
struct DefUseAnalyzer: Analyzer {
3838
private var assignments = VariableMap<[Int]>()
3939
private var uses = VariableMap<[Int]>()
40-
private var code: Code
41-
private var isRunning = true
40+
private let code: Code
4241
private var analysisDone = false
4342

4443
init(for program: Program) {
4544
self.code = program.code
46-
self.isRunning = false
47-
}
48-
49-
init(isBundle: Bool) {
50-
self.code = Code(isBundle: isBundle)
5145
}
5246

5347
mutating func finishAnalysis() {
5448
analysisDone = true
55-
isRunning = false
5649
}
5750

5851
mutating func analyze() {
@@ -61,9 +54,6 @@ struct DefUseAnalyzer: Analyzer {
6154
}
6255

6356
mutating func analyze(_ instr: Instruction) {
64-
if isRunning {
65-
code.append(instr)
66-
}
6757
assert(code[instr.index].op === instr.op) // Must be operating on the program passed in during construction
6858
assert(!analysisDone)
6959
for v in instr.allOutputs {

0 commit comments

Comments
 (0)