如果手工编码的汇编代码包含违反平台的汇编调用约定,汇编器(或静态分析器)是否有办法发出警告?
我使用的平台是带有 GNU GAS 汇编器的 ARMv7A。问题的原因是我写的一个错误,我的函数没有推送/弹出所需的寄存器(ARM 上的 r4-r11)upun 进入/退出。寄存器被丢弃,导致调用者崩溃(幸运的是,自动化测试检测到了这个错误)。简化程序:
my_function:
mov r4, #42 @Trash register r4 in violation of calling convention
bx lr @Return from function
caller:
...
mov r4, #4 @Initialise register r4, to be used later
bl my_function @Call my_function with no arguments
mov r0, r4 @Set argument r0 as r4 (== 42, but should be 4)
bl other_function @Call other_function with (the now trashed) argument r0
ARM 调用约定:http: //infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf