因为公司项目需要,需要用aarch64工具链交叉编译谷歌v8引擎,在编译push_registers_asm.cc文件时会报如下错误:
[2024-08-12 11:46:03] /tmp/ccTq2onR.s: Assembler messages:
[2024-08-12 11:46:03] /tmp/ccTq2onR.s:14: operand 1 should be a floating-point register -- `stp fp,lr,[sp,#-16]!'
[2024-08-12 11:46:03] /tmp/ccTq2onR.s:15: operand 1 should be an integer register -- `mov fp,sp'
[2024-08-12 11:46:03] /tmp/ccTq2onR.s:19: operand 1 should be an integer register -- `ldr lr,[sp,#8]'
[2024-08-12 11:46:03] /tmp/ccTq2onR.s:20: operand 1 should be an integer register -- `ldr fp,[sp],#96'
通过查找相关资料,发现出现错误的原因是因为编译器无法识别汇编指令fp和lr,需要将其替换成x29和x30,要修改v8 engine的源码:
--- a/platform/JS/V8/v8/src/heap/base/asm/arm64/push_registers_asm.cc
+++ b/platform/JS/V8/v8/src/heap/base/asm/arm64/push_registers_asm.cc
@@ -37,9 +37,9 @@ asm(
" stp x23, x24, [sp, #-16]! \n"
" stp x25, x26, [sp, #-16]! \n"
" stp x27, x28, [sp, #-16]! \n"
- " stp fp, lr, [sp, #-16]! \n"
+ " stp x29, x30, [sp, #-16]! \n"
// Maintain frame pointer.
- " mov fp, sp \n"
+ " mov x29, sp \n"
// Pass 1st parameter (x0) unchanged (Stack*).
// Pass 2nd parameter (x1) unchanged (StackVisitor*).
// Save 3rd parameter (x2; IterateStackCallback)
@@ -48,7 +48,7 @@ asm(
" mov x2, sp \n"
" blr x7 \n"
// Load return address.
- " ldr lr, [sp, #8] \n"
+ " ldr x30, [sp, #8] \n"
// Restore frame pointer and pop all callee-saved registers.
- " ldr fp, [sp], #96 \n"
+ " ldr x29, [sp], #96 \n"
" ret \n");
如上图所示,把fp和lr分别替换成x29和x30,编译器就可以识别,可以正常编译通过