m126-lts_liftoff_fix_clobbered_scratch_register.patch 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Clemens Backes <[email protected]>
  3. Date: Fri, 15 Nov 2024 16:00:15 +0100
  4. Subject: Fix clobbered scratch register
  5. `GetMemOp` returns an `Operand` which can contain `kScratchRegister`. We
  6. should hence not clobber that register until after the last use of the
  7. `Operand`.
  8. This CL changes the scratch register to `kScratchRegister2` which has
  9. much fewer uses, and in particular none which collides with `GetMemOp`.
  10. [email protected]
  11. (cherry picked from commit 57a017e611a5abfb0e4b59f6de028bc4070a3615)
  12. Fixed: 378779897, 378701682
  13. Change-Id: Id1ed25edfe76200d069ac2ab54e5000eed313c8f
  14. Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6022072
  15. Reviewed-by: Matthias Liedtke <[email protected]>
  16. Commit-Queue: Clemens Backes <[email protected]>
  17. Cr-Original-Commit-Position: refs/heads/main@{#97224}
  18. Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6056706
  19. Reviewed-by: Clemens Backes <[email protected]>
  20. Commit-Queue: Gyuyoung Kim (xWF) <[email protected]>
  21. Reviewed-by: Daniel Lehmann <[email protected]>
  22. Cr-Commit-Position: refs/branch-heads/12.6@{#82}
  23. Cr-Branched-From: 3c9fa12db3183a6f4ea53d2675adb66ea1194529-refs/heads/12.6.228@{#2}
  24. Cr-Branched-From: 981bb15ba4dbf9e2381dfc94ec2c4af0b9c6a0b6-refs/heads/main@{#93835}
  25. diff --git a/src/wasm/baseline/x64/liftoff-assembler-x64-inl.h b/src/wasm/baseline/x64/liftoff-assembler-x64-inl.h
  26. index b20867d7ec2a5724653ebe9baca8c8949d70cd74..be01772c27382e2c10314777e4058cf326327ba3 100644
  27. --- a/src/wasm/baseline/x64/liftoff-assembler-x64-inl.h
  28. +++ b/src/wasm/baseline/x64/liftoff-assembler-x64-inl.h
  29. @@ -50,6 +50,8 @@ constexpr Operand kInstanceDataOperand =
  30. constexpr Operand kOSRTargetSlot = GetStackSlot(kOSRTargetOffset);
  31. +// Note: The returned Operand might contain {kScratchRegister2}; make sure not
  32. +// to clobber that until after the last use of the Operand.
  33. inline Operand GetMemOp(LiftoffAssembler* assm, Register addr,
  34. Register offset_reg, uintptr_t offset_imm,
  35. ScaleFactor scale_factor = times_1) {
  36. @@ -60,7 +62,7 @@ inline Operand GetMemOp(LiftoffAssembler* assm, Register addr,
  37. : Operand(addr, offset_reg, scale_factor, offset_imm32);
  38. }
  39. // Offset immediate does not fit in 31 bits.
  40. - Register scratch = kScratchRegister;
  41. + Register scratch = kScratchRegister2;
  42. assm->MacroAssembler::Move(scratch, offset_imm);
  43. if (offset_reg != no_reg) assm->addq(scratch, offset_reg);
  44. return Operand(addr, scratch, scale_factor, 0);
  45. diff --git a/test/mjsunit/regress/wasm/regress-378779897.js b/test/mjsunit/regress/wasm/regress-378779897.js
  46. new file mode 100644
  47. index 0000000000000000000000000000000000000000..fed1bc807165e1b9e83195a2df30aac33a544470
  48. --- /dev/null
  49. +++ b/test/mjsunit/regress/wasm/regress-378779897.js
  50. @@ -0,0 +1,22 @@
  51. +// Copyright 2024 the V8 project authors. All rights reserved.
  52. +// Use of this source code is governed by a BSD-style license that can be
  53. +// found in the LICENSE file.
  54. +
  55. +d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
  56. +
  57. +const builder = new WasmModuleBuilder();
  58. +builder.addMemory(49149);
  59. +
  60. +builder.addFunction('main', kSig_i_v).addBody([
  61. + ...wasmI32Const(-1118406780),
  62. + ...wasmI32Const(-1),
  63. + kAtomicPrefix, kExprI32AtomicOr8U, 0, 0
  64. +]).exportFunc();
  65. +
  66. +let instance;
  67. +try {
  68. + instance = builder.instantiate();
  69. +} catch (e) {
  70. + assertException(e, RangeError, /Out of memory/);
  71. +}
  72. +if (instance) instance.exports.main();