Commit 7cb97c6
fix(callgrind): correct AArch64/PPC call-return detection for SP-equal frames
On AArch64/PPC the call instruction leaves SP unchanged (return address in the
link register), so a callee's shadow-stack entry frame sits at SP *equal* to
its return target rather than strictly below it as on x86. Three defects in the
call/return classifier corrupted Simulation flamegraphs on AArch64 only
(malloc -> driftsort_main, dealloc/sin parenting the workload, etc.) by
inverting call edges and fabricating '2 recursion clones:
1. CLG_(unwind_call_stack): minpops is meant to bound only SP-equal pops, but
was decremented for SP-lower pops too. A callee's still-open sub-call frames
exhausted the budget before its own SP-equal entry frame was reached,
leaving it stuck. SP-lower frames now pop unconditionally without consuming
the budget.
2. setup_bbcc return classifier: when the returning function had made SP-lower
sub-calls, popcount_on_return defaulted to 1 and left a PLT stub+callee pair
or a tail-call chain (which all share the SP-equal block) stuck. It now skips
the SP-lower frames and pops the SP-equal block down to the deepest frame
matching the return target. Keyed on where the top frame sits, so the x86
paths (SP-lower-top return, SP-deeper jump) are preserved exactly; only the
AArch64/PPC SP-equal case is changed.
3. reconstruct_call_stack_from_native: seeded ret_addr was ips[frame+1], i.e.
return_PC - 1 (VG_(get_StackTrace) reports the call insn, not the return
PC), but the classifier matches against the return PC. Normalize with +1 so
returns across mid-run-seeded frames are not demoted to jumps.
COD-2985.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent ce9d871 commit 7cb97c6
2 files changed
Lines changed: 111 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
657 | | - | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
658 | 665 | | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
682 | 715 | | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
683 | 726 | | |
684 | | - | |
685 | 727 | | |
686 | 728 | | |
687 | | - | |
| 729 | + | |
| 730 | + | |
688 | 731 | | |
689 | 732 | | |
690 | 733 | | |
| |||
789 | 832 | | |
790 | 833 | | |
791 | 834 | | |
792 | | - | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
793 | 841 | | |
794 | 842 | | |
795 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
437 | 458 | | |
438 | 459 | | |
439 | 460 | | |
440 | | - | |
441 | 461 | | |
442 | 462 | | |
443 | 463 | | |
| |||
521 | 541 | | |
522 | 542 | | |
523 | 543 | | |
524 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
525 | 556 | | |
526 | 557 | | |
527 | 558 | | |
| |||
0 commit comments