RE:(2) [PATCH 3/4] scripts/checkstack.pl: add arm push handling for stack usage
From: Vaneet Narang
Date: Thu May 07 2020 - 10:35:56 EST
Hi Masahiro,Â
>>ÂToÂcountÂstackÂusageÂofÂpushÂ{*,Âfp,Âip,Âlr,Âpc}ÂinstructionÂinÂARM,
>>ÂifÂFRAMEÂPOINTERÂisÂenabled.
>>Âe.g.Âc01f0d48:Âe92ddff0ÂpushÂ{r4,Âr5,Âr6,Âr7,Âr8,Âr9,Âsl,Âfp,Âip,Âlr,Âpc}
>>
>>Âc01f0d50Â<Y>:
>>Âc01f0d44:ÂÂÂÂÂÂÂe1a0c00dÂÂÂÂÂÂÂÂmovÂÂÂÂÂip,Âsp
>>Âc01f0d48:ÂÂÂÂÂÂÂe92ddff0ÂÂÂÂÂÂÂÂpushÂÂÂÂ{r4,Âr5,Âr6,Âr7,Âr8,Âr9,Âsl,Âfp,Âip,Âlr,Âpc}
>>Âc01f0d4c:ÂÂÂÂÂÂÂe24cb004ÂÂÂÂÂÂÂÂsubÂÂÂÂÂfp,Âip,Â#4
>>Âc01f0d50:ÂÂÂÂÂÂÂe24dd094ÂÂÂÂÂÂÂÂsubÂÂÂÂÂsp,Âsp,Â#448ÂÂÂÂ;Â0x1C0
>>
>>Â$ÂcatÂdumpÂ|Âscripts/checkstack.plÂarm
>>Â0xc01f0d50ÂYÂ[]:ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ448
>>
>>ÂaddedÂsubroutineÂframeÂworkÂforÂthis.
>>ÂAfterÂchange:
>>Â0xc01f0d500ÂYÂ[]:ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ492
ÂÂ
Â
> DoÂyouÂknowÂCONFIG_FRAME_WARN?
ÂYes we know this and we use it to get compilation error if some function is using more stack.
This config will report issue at compilation.
Â
>IÂknowÂcheckstack.plÂdumpsÂtheÂstackÂsize
>ofÂfunctions,ÂwhichÂisÂdifferentÂfromÂwhat
>-Wframe-larger-thanÂdoes,ÂbutÂtheÂgoalÂis
>quiteÂsimilar,ÂIÂthink.
>Â
>IÂjustÂwonderedÂifÂweÂneedÂboth.
Â
We feel purpose of this patch is different from CONFIG_FRAME_WARN.
This patch is specific to ARM and fixes bug in stack usage calculation.
We were comparing stack usage of ARM with ARM64 and found big gap.
We realised ARM is not calculating stack usage properly.
It only considers stack used by local variables but it doesn't consider
stack used to store register context at the start of functions.
This is not the case with ARM64. It seems ARM64 considers both.
We found even stack variables are of same size on both target but
arm64 stack usage is high.
Considering below assembly, Actual stack usage is 492 but current script reports 448.
push instruction uses 44 bytes of stack to take backup of registers as per ARM calling
convention.
c01f0d44: e1a0c00d mov ip, sp
c01f0d48: e92ddff0 push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc}
c01f0d4c: e24cb004 sub fp, ip, #4
c01f0d50: e24dd094 sub sp, sp, #448 ; 0x1C0
Thanks & Regards,
Vaneet Narang
Â
ÂÂ