Add method to programmatically view disassembly of Wasm exported function
Categories
(Core :: JavaScript: WebAssembly, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox70 | --- | fixed |
People
(Reporter: rhunt, Assigned: rhunt)
Details
Attachments
(4 files)
Through debugging Wasm codegen I've used IONFLAGS=codegen to view the generated assembly. It's really noisy though, and it seemed useful to be able to wasmDis(wasmFunc) so I wrote a patch to be able to do this.
I'm unsure whether this is useful for other people, so this bug is just to solicit opinions.
Example: (IONFLAGS is filtered)
js> let fib = wasmRun('fib.wat').instance.exports.fib;
[Codegen] # ========================================
[Codegen] # Emitting wasm baseline code
[Codegen] # beginFunction: start of function prologue for index 1
[Codegen] [6] 71008d5f cmp w10, #0x23 (35)
[Codegen] [6] 54000000 b.eq -> 1000f
[Codegen] [6] d45bd600 hlt #0xdeb0
[Codegen] [6] 1000:
[Codegen] [6] d10083ff sub sp, sp, #0x20 (32)
[Codegen] [6] f9000ffe str x30, [sp, #24]
[Codegen] [6] f90007f7 str x23, [sp, #8]
[Codegen] [6] f90003fd str x29, [sp]
[Codegen] [6] 910003fd mov x29, sp
[Codegen] [6] d2800010 mov x16, #0x0
[Codegen] [6] f2a00010 movk x16, #0x0, lsl #16
[Codegen] [6] cb3063e8 sub x8, sp, x16
[Codegen] [6] f94016f0 ldr x16, [x23, #40]
[Codegen] [6] eb08021f cmp x16, x8
[Codegen] [6] 54000003 b.lo -> 1001f
[Codegen] [6] d45bd600 hlt #0xdeb0
[Codegen] [6] 1001:
[Codegen] [6] d10143ff sub sp, sp, #0x50 (80)
[Codegen] [6] b9004fe0 str w0, [sp, #76]
[Codegen] # beginFunction: enter body with masm.framePushed = 80
[Codegen] [6] b9404fe0 ldr w0, [sp, #76]
[Codegen] [6] 7100041f cmp w0, #0x1 (1)
[Codegen] [6] 54000008 b.hi -> 1002f
[Codegen] [6] 52800020 mov w0, #0x1
[Codegen] [6] 14000000 b -> 1003f
[Codegen] [6] 1002:
[Codegen] [6] b9404fe0 ldr w0, [sp, #76]
[Codegen] [6] 51000400 sub w0, w0, #0x1 (1)
[Codegen] [6] f9001fe0 str x0, [sp, #56]
[Codegen] [6] b9403be0 ldr w0, [sp, #56]
[Codegen] [6] f9402ff7 ldr x23, [sp, #88]
[Codegen] [6] 94000000 bl #+0x0 (addr 0x11631f0b8)-> (link-time target)
[Codegen] [6] b9404fe1 ldr w1, [sp, #76]
[Codegen] [6] 51000821 sub w1, w1, #0x2 (2)
[Codegen] [6] f9001fe0 str x0, [sp, #56]
[Codegen] [6] f9001be1 str x1, [sp, #48]
[Codegen] [6] b94033e0 ldr w0, [sp, #48]
[Codegen] [6] f9402ff7 ldr x23, [sp, #88]
[Codegen] [6] 94000000 bl #+0x0 (addr 0x11631f0d4)-> (link-time target)
[Codegen] [6] f9401fe1 ldr x1, [sp, #56]
[Codegen] [6] 0b000021 add w1, w1, w0
[Codegen] [6] 2a0103e0 mov w0, w1
[Codegen] [6] 17ffffef b -> 1003f
[Codegen] # endFunction: start of function epilogue
[Codegen] [6] d4200000 brk #0x0
[Codegen] [6] 1003:
[Codegen] [6] 910143ff add sp, sp, #0x50 (80)
[Codegen] [6] f94003fd ldr x29, [sp]
[Codegen] [6] f94007f7 ldr x23, [sp, #8]
[Codegen] [6] f9400ffe ldr x30, [sp, #24]
[Codegen] [6] 910083ff add sp, sp, #0x20 (32)
[Codegen] [6] d65f03c0 ret
[Codegen] # endFunction: end of function epilogue
[Codegen] # endFunction: start of OOL code
[Codegen] # endFunction: end of OOL code for index 1
8
js> wasmDis(fib)
0x27d6e95c3090 71008d5f cmp w10, #0x23 (35)
0x27d6e95c3094 540000e0 b.eq #+0x1c (addr 0x27d6e95c30b0)
0x27d6e95c3098 d45bd600 hlt #0xdeb0
0x27d6e95c309c 14000003 b #+0xc (addr 0x27d6e95c30a8)
0x27d6e95c30a0 ffff0001 unallocated (Unallocated)
0x27d6e95c30a4 14000003 b #+0xc (addr 0x27d6e95c30b0)
0x27d6e95c30a8 d503201f nop
0x27d6e95c30ac d503201f nop
0x27d6e95c30b0 d10083ff sub sp, sp, #0x20 (32)
0x27d6e95c30b4 f9000ffe str x30, [sp, #24]
0x27d6e95c30b8 f90007f7 str x23, [sp, #8]
0x27d6e95c30bc f90003fd str x29, [sp]
0x27d6e95c30c0 910003fd mov x29, sp
0x27d6e95c30c4 d2800a10 mov x16, #0x50
0x27d6e95c30c8 f2a00010 movk x16, #0x0, lsl #16
0x27d6e95c30cc cb3063e8 sub x8, sp, x16
0x27d6e95c30d0 f94016f0 ldr x16, [x23, #40]
0x27d6e95c30d4 eb08021f cmp x16, x8
0x27d6e95c30d8 54000043 b.lo #+0x8 (addr 0x27d6e95c30e0)
0x27d6e95c30dc d45bd600 hlt #0xdeb0
0x27d6e95c30e0 d10143ff sub sp, sp, #0x50 (80)
0x27d6e95c30e4 b9004fe0 str w0, [sp, #76]
0x27d6e95c30e8 b9404fe0 ldr w0, [sp, #76]
0x27d6e95c30ec 7100041f cmp w0, #0x1 (1)
0x27d6e95c30f0 54000068 b.hi #+0xc (addr 0x27d6e95c30fc)
0x27d6e95c30f4 52800020 mov w0, #0x1
0x27d6e95c30f8 14000013 b #+0x4c (addr 0x27d6e95c3144)
0x27d6e95c30fc b9404fe0 ldr w0, [sp, #76]
0x27d6e95c3100 51000400 sub w0, w0, #0x1 (1)
0x27d6e95c3104 f9001fe0 str x0, [sp, #56]
0x27d6e95c3108 b9403be0 ldr w0, [sp, #56]
0x27d6e95c310c f9402ff7 ldr x23, [sp, #88]
0x27d6e95c3110 97ffffe8 bl #-0x60 (addr 0x27d6e95c30b0)
0x27d6e95c3114 b9404fe1 ldr w1, [sp, #76]
0x27d6e95c3118 51000821 sub w1, w1, #0x2 (2)
0x27d6e95c311c f9001fe0 str x0, [sp, #56]
0x27d6e95c3120 f9001be1 str x1, [sp, #48]
0x27d6e95c3124 b94033e0 ldr w0, [sp, #48]
0x27d6e95c3128 f9402ff7 ldr x23, [sp, #88]
0x27d6e95c312c 97ffffe1 bl #-0x7c (addr 0x27d6e95c30b0)
0x27d6e95c3130 f9401fe1 ldr x1, [sp, #56]
0x27d6e95c3134 0b000021 add w1, w1, w0
0x27d6e95c3138 2a0103e0 mov w0, w1
0x27d6e95c313c 14000002 b #+0x8 (addr 0x27d6e95c3144)
0x27d6e95c3140 d4200000 brk #0x0
0x27d6e95c3144 910143ff add sp, sp, #0x50 (80)
0x27d6e95c3148 f94003fd ldr x29, [sp]
0x27d6e95c314c f94007f7 ldr x23, [sp, #8]
0x27d6e95c3150 f9400ffe ldr x30, [sp, #24]
0x27d6e95c3154 910083ff add sp, sp, #0x20 (32)
0x27d6e95c3158 d65f03c0 ret
| Assignee | ||
Comment 1•6 years ago
|
||
Comment 2•6 years ago
|
||
Seems useful to me. Too bad about the disappearing labels, but I guess the addresses work out OK.
| Assignee | ||
Comment 3•6 years ago
|
||
Okay. The only controversial change might be building Zydis even if Cranelift isn't enabled so that this works on x86/x64. But if it's still behind a #ifdef JS_JITSPEW that might not affect too many people?
Either way, I'll polish up the patch a bit and put it up for review.
| Assignee | ||
Comment 4•6 years ago
|
||
| Assignee | ||
Comment 5•6 years ago
|
||
The #ifdef(JS_JITSPEW) restriction is still kept.
Updated•6 years ago
|
| Assignee | ||
Comment 6•6 years ago
|
||
Depends on D42052
| Assignee | ||
Comment 7•6 years ago
|
||
Depends on D42223
Updated•6 years ago
|
Comment 8•6 years ago
|
||
Yeah, behind the JS_JITSPEW flag should be just fine.
Comment 10•6 years ago
|
||
Backed out 4 changesets (bug 1574002) for causing spidermonkey bustage on Disassemble.h CLOSED TREE
Backout revision https://hg.mozilla.org/integration/autoland/rev/9c344fdaa44483e5ca18d343ac5fb4af7c0e0127
Failure log https://treeherder.mozilla.org/logviewer.html#?job_id=262320183&repo=autoland
Ryan can you please take a look?
Comment 11•6 years ago
|
||
Comment 13•6 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7ed2f4ec0cc2
https://hg.mozilla.org/mozilla-central/rev/6d1f82ea2d92
https://hg.mozilla.org/mozilla-central/rev/b4ca080d3c7b
https://hg.mozilla.org/mozilla-central/rev/3eb184cc45d5
Updated•6 years ago
|
Description
•