Commit 1374eb0
committed
Unwind: separate the "set frame reg" and "define new frame" operations to fix metadata bug related to stack checks.
In #3859 we discovered that the unwind metadata info on Windows is
placed slightly incorrectly in the presence of explicit stack checks in
function prologues. In particular, if the stack check fails, then we
start the process of backtracing from a state where we have actually
updated rbp (the frame pointer) but we have not emitted the metadata
saying we have done so.
The fix is to emit the `SetFPReg` Win32 unwind op exactly at the offset
of the `mov rbp, rsp` instruction, not after the stack check. However,
actually achieving this output given our current unwind design (which
abstracts over SysV and Win32) is slightly tricky, because:
- We previously had a single `DefineNewFrame` op that both indicated
where the FP was set, and gave the size of the clobbers;
- We don't know the size of the clobbers until we generate the
clobber-save sequence; and
- The clobber-save sequence is generated after any explicit stack check.
To resolve the problem, this PR splits the `DefineNewFrame` op into two
pieces: `SetFrameReg` and `DefineNewFrame`. On x86-64 and aarch64 this
is emitted in the appropriate place. (`s390x` does not use a frame
register, so has no need for this op.) This should resolve the issue we
were seeing with Windows-2022 and unwinding.
(Thanks to @alexcrichton, @iximeow and @peterhuene for help debugging
this!)1 parent 29ebfa4 commit 1374eb0
File tree
7 files changed
+228
-193
lines changed- .github/workflows
- cranelift
- codegen/src/isa
- aarch64
- unwind
- x64
- filetests/filetests/isa/x64
7 files changed
+228
-193
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
| 220 | + | |
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
676 | 683 | | |
677 | 684 | | |
678 | 685 | | |
| |||
734 | 741 | | |
735 | 742 | | |
736 | 743 | | |
737 | | - | |
738 | 744 | | |
| 745 | + | |
739 | 746 | | |
740 | 747 | | |
741 | 748 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
| 121 | + | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
149 | 154 | | |
150 | | - | |
151 | | - | |
| 155 | + | |
| 156 | + | |
152 | 157 | | |
153 | | - | |
154 | | - | |
| 158 | + | |
| 159 | + | |
155 | 160 | | |
156 | 161 | | |
157 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 205 | + | |
209 | 206 | | |
210 | 207 | | |
211 | 208 | | |
212 | 209 | | |
213 | 210 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
284 | 287 | | |
285 | | - | |
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
466 | 473 | | |
467 | 474 | | |
468 | 475 | | |
| |||
513 | 520 | | |
514 | 521 | | |
515 | 522 | | |
516 | | - | |
517 | 523 | | |
| 524 | + | |
518 | 525 | | |
519 | 526 | | |
520 | 527 | | |
| |||
0 commit comments