Commit baa6b27
authored
Cranelift: rework MachBuffer to handle very short-deadline jumps. (#12842)
* Cranelift: rework MachBuffer to handle very short-deadline jumps.
In #12811 it was reported that riscv64 compressed jumps (`c.j`
instructions), with a +/- 2048-byte range, could cause panics when
combined with queued-up/deferred constants in a constant pool during
binary emission.
Our `MachBuffer` handles single-pass machine code emission, resolution
of labels, and upgrading of label ranges via "veneers" (jumps that a
shorter jump can reach that themselves have a longer range). We track a
pending "deadline" of all unresolved branches, and when the deadline is
too close (including the max size of all veneers yet to be emitted), we
emit an "island" of all veneers to resolve the deadline.
After its initial design, we added support for deferred traps and
constants to the `MachBuffer`. These worked by emitting their contents
*before* the "island" of veneers, which turns out to be slightly nicer
for code layout in some cases.
Unfortunately the full implications of those additions weren't realized
against the invariants of the deadline-resolution algorithm. In
particular, when a new branch is added with a very short range (e.g.,
`c.j`), it is possible that there are *already* too many queued-up
traps/constants for the range of that just-emitted branch to reach even
the first possible veneer site if we start an island right away.
Thus it is strictly necessary to emit the veneers before
constants/traps. Unfortunately this requires some alterations to other
aspects of label resolution as well: in particular, we can't resolve
fixups for label references to constants before we emit those constants,
and likewise for traps. Note that we do a fixpoint loop over emitting
island(s) at the end of emission, so all constants/traps *will* be
emitted and label references to them *will* be resolved eventually; just
in the opposite order, now.
No compile test because the particular reduced testcase in #12811 only
worked in the `release-36.0.0` branch, and not on `main`, and it was too
hard to tweak the test to hit the right case on `main` as well. In lieu
of that, I've added a unit test directly to the `MachBuffer`
implementation to exercise this case.
Fixes #12811.
* fix filetest with errant comments confusing precise-output check1 parent 82ebbd5 commit baa6b27
2 files changed
Lines changed: 8362 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
771 | 771 | | |
772 | 772 | | |
773 | 773 | | |
774 | | - | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
775 | 780 | | |
776 | 781 | | |
777 | 782 | | |
| |||
1280 | 1285 | | |
1281 | 1286 | | |
1282 | 1287 | | |
1283 | | - | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
1284 | 1297 | | |
1285 | 1298 | | |
1286 | 1299 | | |
| |||
1320 | 1333 | | |
1321 | 1334 | | |
1322 | 1335 | | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
1323 | 1341 | | |
1324 | 1342 | | |
1325 | 1343 | | |
| |||
1336 | 1354 | | |
1337 | 1355 | | |
1338 | 1356 | | |
1339 | | - | |
1340 | | - | |
1341 | | - | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1342 | 1365 | | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
1369 | 1370 | | |
1370 | 1371 | | |
1371 | 1372 | | |
1372 | 1373 | | |
1373 | 1374 | | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
1374 | 1380 | | |
1375 | 1381 | | |
1376 | 1382 | | |
| |||
1380 | 1386 | | |
1381 | 1387 | | |
1382 | 1388 | | |
1383 | | - | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
1384 | 1394 | | |
1385 | 1395 | | |
1386 | 1396 | | |
| |||
1395 | 1405 | | |
1396 | 1406 | | |
1397 | 1407 | | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
1398 | 1439 | | |
1399 | 1440 | | |
1400 | 1441 | | |
1401 | 1442 | | |
1402 | 1443 | | |
1403 | 1444 | | |
1404 | 1445 | | |
1405 | | - | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1406 | 1460 | | |
1407 | 1461 | | |
1408 | 1462 | | |
| |||
1525 | 1579 | | |
1526 | 1580 | | |
1527 | 1581 | | |
1528 | | - | |
| 1582 | + | |
1529 | 1583 | | |
1530 | 1584 | | |
1531 | 1585 | | |
| |||
1991 | 2045 | | |
1992 | 2046 | | |
1993 | 2047 | | |
| 2048 | + | |
1994 | 2049 | | |
1995 | 2050 | | |
1996 | 2051 | | |
| |||
0 commit comments