PPC: Fix offset calculation when returning from C Function

This CL makes sure the offset is calculated correctly to be
the return address from a C Function. Checking the size
of generated code is also fixed to take into account the extra
instruction we have from LoadPC.

Change-Id: I585c11efbe4342bc5a0d3068683b54cb563a3bc5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3257206
Reviewed-by: Junliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/main@{#77666}
This commit is contained in:
Milad Fa 2021-11-02 16:36:16 -04:00 committed by V8 LUCI CQ
parent 36cff05fea
commit 059cd3cddd

View File

@ -904,13 +904,13 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
int const fp_param_field = FPParamField::decode(instr->opcode());
int num_fp_parameters = fp_param_field;
bool has_function_descriptor = false;
int offset = 20 * kInstrSize;
int offset = 19 * kInstrSize;
if (instr->InputAt(0)->IsImmediate() &&
!FLAG_enable_embedded_constant_pool) {
// If loading an immediate without constant pool then 4 instructions get
// emitted instead of a single load (which makes it 3 extra).
offset = 23 * kInstrSize;
offset = 22 * kInstrSize;
}
if (!instr->InputAt(0)->IsImmediate() && !ABI_CALL_VIA_IP) {
// On Linux and Sim, there will be an extra
@ -939,8 +939,8 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
linkage()->GetIncomingDescriptor()->IsWasmCapiFunction();
if (isWasmCapiFunction) {
__ mflr(r0);
__ bind(&start_call);
__ LoadPC(kScratchReg);
__ bind(&start_call);
__ addi(kScratchReg, kScratchReg, Operand(offset));
__ StoreU64(kScratchReg,
MemOperand(fp, WasmExitFrameConstants::kCallingPCOffset));
@ -963,7 +963,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
// More info on f5ab7d3.
#if V8_ENABLE_WEBASSEMBLY
if (isWasmCapiFunction) {
CHECK_EQ(offset, __ SizeOfCodeGeneratedSince(&start_call));
// The offset calculated is from pc returned by LoadPC above, until this
// location.
// LoadPC emits two instructions and pc is the address of its
// second emitted instruction. `start_call` is binding to the address
// right after the above retrieved pc, therefore there is one less
// instruction to count when summing the total size of generated code.
int generated_size = offset - kInstrSize;
CHECK_EQ(generated_size, __ SizeOfCodeGeneratedSince(&start_call));
RecordSafepoint(instr->reference_map());
}
#endif // V8_ENABLE_WEBASSEMBLY