Skip to content

Fix ARM64 profile disassembly CFG parsing#54

Open
jhpohovey with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-arm64-binaries-build-issue
Open

Fix ARM64 profile disassembly CFG parsing#54
jhpohovey with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-arm64-binaries-build-issue

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

ARM64 binaries loaded from profiles could be parsed using the session’s default x64 ASM IR mode. That prevented ARM64 branches from being recognized, so basic blocks and CFG edges were not built correctly.

  • Architecture-aware disassembly parsing
    • Selects the ASM parser mode from the loaded PE binary architecture for binary-backed disassembly sections.
    • Uses IRMode.ARM64 for ARM64 binaries even when the profile session initially defaults to x64.
return binaryInfo?.Architecture switch {
  Machine.Arm64 => new ASMCompilerIRInfo(IRMode.ARM64),
  Machine.I386  => new ASMCompilerIRInfo(IRMode.x86_64),
  Machine.Amd64 => new ASMCompilerIRInfo(IRMode.x86_64),
  _             => compilerInfo.IR
};
  • Regression coverage
    • Adds an ARM64 parser test for a conditional branch.
    • Verifies the parser creates separate basic blocks and connects both branch target and fall-through CFG edges.

Copilot AI and others added 2 commits May 7, 2026 21:59
Copilot AI changed the title [WIP] Fix build of basic blocks and control flow graph for ARM64 binaries Fix ARM64 profile disassembly CFG parsing May 7, 2026
Copilot AI requested a review from jhpohovey May 7, 2026 22:03
@jhpohovey

Copy link
Copy Markdown
Member

Made a small test arm64 binary to test this; first image is off of the current HEAD of main, we see that the Flow graph is just one node.

image-1779123740069

Rebuilding with the changes in this PR, we now see that there are the individual blocks all showing up in the flow graph view:
image-1779123936170

This appears to solve the linked issue.

@jhpohovey jhpohovey marked this pull request as ready for review May 18, 2026 17:11
Copilot AI review requested due to automatic review settings May 18, 2026 17:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes ARM64 disassembly parsing by selecting the ASM IR mode based on the loaded PE binary's architecture, so ARM64 branches are correctly recognized when building basic blocks and CFG edges.

Changes:

  • Add SelectIRInfo helper to pick IRMode.ARM64 or IRMode.x86_64 based on PE architecture.
  • Initialize DisassemblerSectionLoader with the architecture-appropriate ICompilerIRInfo.
  • Add ARM64 conditional branch parser test verifying basic block split and CFG edges.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/ProfileExplorerCore/Compilers/ASM/DisassemblerSectionLoader.cs Selects IR info based on PE architecture before Initialize.
src/ProfileExplorerCoreTests/ASMParserTests.cs New test covering ARM64 conditional branch CFG creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


return binaryInfo?.Architecture switch {
Machine.Arm64 => new ASMCompilerIRInfo(IRMode.ARM64),
Machine.I386 => new ASMCompilerIRInfo(IRMode.x86_64),
Comment on lines +41 to +42
private static ICompilerIRInfo SelectIRInfo(ICompilerInfoProvider compilerInfo, string binaryFilePath) {
var binaryInfo = PEBinaryInfoProvider.GetBinaryFileInfo(binaryFilePath);
private static ICompilerIRInfo SelectIRInfo(ICompilerInfoProvider compilerInfo, string binaryFilePath) {
var binaryInfo = PEBinaryInfoProvider.GetBinaryFileInfo(binaryFilePath);

return binaryInfo?.Architecture switch {
1008: d65f03c0 ret
""";

var function = ParseARM64(text, 12);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New version fails to build basic blocks and control flow graph for ARM64 binaries

3 participants