What is 'Stack locally' and 'Stack prev' in the .map file?

Technical Note 24702






2018-05-31 09:14


If the Static overlay system map (-xo) linker option (IAR XLINK Linker) has been specified, the list file includes the following information:

"Stack locally" is the number of bytes the function uses. "Stack prev" is the number of bytes that the "children" (the functions called from the function in question, recursively all the way down to the leaves that don't call anything) uses.

The key to understanding how the values are summed is that each level X entry only bothers with the entries that are listed immediately prior to itself and are of level X+1 or higher. It is similar to files and directories in the file system of an operating system. Each level is a directory that contains other directories and some data of disk usage. Each directory is only concerned with itself and the directories it contain.

Toy example

Level Name
4 foo
6 bar
5 baz
5 frotz
4 qwerty

In this example qwerty will contain the stack usage from frotz, baz and bar, but not foo as foo does not have a higher level (qwerty does not call foo). frotz does not make any calls (those would be listed as level 6 entries preceeding frotz if they did exist). That bar is level 6 and also placed in the qwerty tree does not matter as bar belongs to baz.

Real example

                    Stack prev        Stack locally

4 getA 0 0 4 0
4 getB 0 0 4 0
4 getC 0 0 2 0
4 getD 0 0 2 0
4 getE 0 0 2 0
3 Foo2 4 0 2 17
2 Foo1 6 17 2 8

In this example, main (level 1) calls Foo1(level 2) which in turn calls Foo2 (level 3) which in turn calls several leaves (level 4).

Some of the leaves use 4 bytes of RSTACK, while others use 2. This matters in the "Stack prev" column on level 3. "Stack prev" on level X is the highest sum of "Stack prev" + "Stack locally" for level X+1.

For level 3 in this example, it is 0+4, 0+4, 0+2, 0+2, 0+2. The maximum is 4 so level 3 gets an RSTACK prev of 4 and a CSTACK prev of 0.

For level 2 in this example it is 4 + 2 = 6 and 0+17 = 17 as there only is one alternative.


All product names are trademarks or registered trademarks of their respective owners.

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av iar.com rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.