Commit e4a9a790 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][liftoff][x64] Align frame size

The GC requires all slots in a stack frame that store a reference to be
aligned. This alignment was not provided for spill slots in OOL code.

R=thibaudm@chromium.org

Change-Id: I17492362318623aecc4c54635407d0c8badf3d36
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2649025Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72324}
parent 7e2f1108
......@@ -190,7 +190,9 @@ void LiftoffAssembler::PrepareTailCall(int num_callee_stack_params,
popq(rbp);
}
void LiftoffAssembler::AlignFrameSize() {}
void LiftoffAssembler::AlignFrameSize() {
max_used_spill_offset_ = RoundUp(max_used_spill_offset_, kSystemPointerSize);
}
void LiftoffAssembler::PatchPrepareStackFrame(int offset) {
// The frame_size includes the frame marker. The frame marker has already been
......@@ -198,7 +200,7 @@ void LiftoffAssembler::PatchPrepareStackFrame(int offset) {
// anymore.
int frame_size = GetTotalFrameSize() - kSystemPointerSize;
// Need to align sp to system pointer size.
frame_size = RoundUp(frame_size, kSystemPointerSize);
DCHECK_EQ(frame_size, RoundUp(frame_size, kSystemPointerSize));
// We can't run out of space, just pass anything big enough to not cause the
// assembler to try to grow the buffer.
constexpr int kAvailableSpace = 64;
......
......@@ -288,3 +288,48 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
instance.exports.main({hello: 4}, 5, {world: 6}, null, {bar: 7});
})();
(function testGCInStackCheckUnalignedFrameSize() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
const gc_sig = builder.addType(kSig_v_v);
const mysig = makeSig(
[
kWasmExternRef, kWasmI32, kWasmExternRef, kWasmExternRef, kWasmExternRef
],
[]);
const func_sig = builder.addType(mysig);
const triggerGC_index = builder.addImport('q', 'triggerGC', gc_sig);
const func_index = builder.addImport('q', 'func', func_sig);
const foo = builder.addFunction('foo', func_sig).addBody([
kExprLocalGet, 0, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kExprLocalGet, 3, // --
kExprLocalGet, 4, // --
kExprCallFunction, func_index
]).addLocals(kWasmI32, 1);
builder.addFunction('main', func_sig)
.addBody([
kExprCallFunction, triggerGC_index, // --
kExprLocalGet, 0, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kExprLocalGet, 3, // --
kExprLocalGet, 4, // --
kExprCallFunction, foo.index
])
.exportFunc();
const instance = builder.instantiate({
q: {
triggerGC: () => %ScheduleGCInStackCheck(),
func: (ref) => assertEquals(ref.hello, 4)
}
});
instance.exports.main({hello: 4}, 5, {world: 6}, null, {bar: 7});
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment