0

Though the release note of the GCC 8.3.0.202002-GNURX tells us the following fix, it is still incorrect. Can a future release of GNURX fix it?

1. [Bug Fix] Fixed a bug related to the stack usage calculation

The zip file of all files to reproduce this issue is here and it includes also .lst and .su files. (The following japanese post is written from the view point of e2 studio stack analysis window.)

japan.renesasrulz.com/cafe_rene/f/forum21/5987/e2-studio-v7-5-0-stack-analysis-view-gnurx-1-error/34959#34959

issue_20200509.zip

SUMMARY

(1) The calculation for interrupt attribute function forgets to add 4 bytes for PSW space in case of (at least) -O0 optimization.
(2) The calculation for some functions more than -O0 optimization (at least -O2 and -Og) has 4 bytes difference between the code in .lst file and the value in .su file.

DETAIL

(1) The calculation for interrupt attribute function forgets to add 4 bytes for PSW space in case of (at least) -O0 optimization.

(1-A)

In case of -O0, the .lst file of the following interrupt attribute function shows that the stack usage is 12 bytes but the .su file says it is 8 bytes.

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O0/inthandler.lst

24:../generate/inthandler.c **** void INT_Excep_SuperVisorInst(void){/* brk(){  } */}
12 0000 7E AA                         push.l  r10
14 0002 EF 0A                         mov.L   r0, r10
17 0004 03                            nop
18 0005 7E BA                         pop r10
19 0007 7F 95                         rte

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O0/generate/inthandler.su

inthandler.c:24:6:INT_Excep_SuperVisorInst  8   static

(1-B)

On the other hand, in case of -O2, somehow both are the same 8 bytes.

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/inthandler.lst

24:../generate/inthandler.c **** void INT_Excep_SuperVisorInst(void){/* brk(){  } */}
14 0000 7F 95                         rte

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/generate/inthandler.su

inthandler.c:24:6:INT_Excep_SuperVisorInst  8   static

(2) The calculation for some functions more than -O0 optimization (at least -O2 and -Og) has 4 bytes difference between the code in .lst file and the value in .su file.

(2-A)

The .lst file of the following function shows the stack usage is 4 bytes but the .su file says it is 8 bytes.

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/Test.lst

12:../src/Test.c **** uint32_t func0( void )
13:../src/Test.c **** {
14:../src/Test.c ****     return 0;
15:../src/Test.c **** }
13 0000 66 01                         mov.L   #0, r1
14 0002 02                            rts

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/src/Test.su

Test.c:12:10:func0  8   static

(2-B)

On the other hand, in case of the following function, somehow both are the same 24 bytes.

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/Test.lst

32:../src/Test.c **** uint32_t func8( uint32_t a1,  uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5, uint32_t a6, uint32_t a7, uint32_t a8 )
33:../src/Test.c **** {
75 0000 7E A7                         push.l  r7
77 0002 71 00 F0                      add #-16, r0
33:../src/Test.c ****     return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8;
81 0005 75 47 18                      mov.L   #24, r7
82 0008 4B 07                         add r0, r7
83 000a A8 F5                         mov.L   8[r7], r5
85 000c 06 89 75 03                   add 12[r7].L, r5
86 0010 06 89 75 01                   add 4[r7].L, r5
87 0014 06 88 75                      add [r7].L, r5
88 0017 4B 45                         add r4, r5
89 0019 4B 35                         add r3, r5
90 001b 4B 25                         add r2, r5
35:../src/Test.c **** }
92 001d 4B 51                         add r5, r1
94 001f 3F 77 05                      rtsd    #20, r7-r7

issue_20200509.zip/TestStackAnalysisForGNURX/HardwareDebug.8.3.0.202002.O2/src/Test.su

Test.c:32:10:func8  24  static

Best regards,
NoMaY

Darius Galis answered