Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ obj/
launchsettings.json

artifacts/

.DS_Store
5 changes: 3 additions & 2 deletions Cpp2IL.Core/IlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ private static List<CilInstruction> GenerateInstructions(Instruction instruction
}

// Load normal params
var callParams = instruction.Operands.Skip(thisParamIndex + (targetMethod.IsStatic ? 0 : -1));
var callParamIndex = instruction.OpCode == OpCode.Call ? (targetMethod.IsStatic ? 2 : 3) : (targetMethod.IsStatic ? 1 : 2);
var callParams = instruction.Operands.Skip(callParamIndex);
foreach (var param in callParams)
LoadOperand(param, method, locals, writeLine, stringCtor);

Expand Down Expand Up @@ -414,7 +415,7 @@ private static void LoadOperand(object operand, MethodDefinition method,
break;
}
instructions.Add(CilOpCodes.Ldstr, "Unmanaged memory load: " + operand.ToString());
instructions.Add(CilOpCodes.Newobj, importer.ImportMethod(stringCtor));
instructions.Add(CilOpCodes.Call, importer.ImportMethod(writeLine));
break;
case RuntimeMethodInfoAnalysisContext:
//Not fully implemented, these basically shouldn't actually ever exist in the final IL.
Expand Down
14 changes: 13 additions & 1 deletion Cpp2IL.Core/InstructionSets/NewArmV8InstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,19 @@ void AddCall(MethodAnalysisContext context, object? returnRegister2, ulong addre
Add(address, OpCode.Move, dest2, mem2);
break;
case Arm64Mnemonic.BL:
AddCall(context, GetReturnRegisterForContext(context), address, instruction.BranchTarget);
if (context.AppContext.MethodsByAddress.TryGetValue(instruction.BranchTarget, out var possibleMethods))
{
if (possibleMethods.Count == 1)
AddCall(context, GetReturnRegisterForContext(possibleMethods[0]), address, instruction.BranchTarget);
else
// TODO: Properly fix this case where branch address is potentially more than 1 method
AddCall(context, GetReturnRegisterForContext(context), address, instruction.BranchTarget);
}
else
{
// TODO: properly handle unmanaged/API function
AddCall(context, GetReturnRegisterForContext(context), address, instruction.BranchTarget);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This will silently drop the call if it's to an unmanaged/API function, need to handle it in an else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had previously else that defaulted to the "incorrect" behavior, but I can do some testing and figure out the cases where the else might be hit 👍

break;
case Arm64Mnemonic.RET:
var returnRegister = GetReturnRegisterForContext(context);
Expand Down
Loading