Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
761 Views

how to check the NIOSII code footprint size

Dear All, 

what's the best way in SBT 11.0 to analyze NIOSII program memory size? 

Thanks a lot, all.
0 Kudos
4 Replies
Altera_Forum
Honored Contributor I
28 Views

Depends to some extent on what you are tryign to find out. 

The actual sizes of the code/data sections can be found by running 'objdump' on the object and program files. 

The symbol table will give some idea as to the size of each function, and the included functions. 

If you want to know why some functions are included from a library (eg libc) the linker map file will tell you (if generated, and with appropriate linker options).
Altera_Forum
Honored Contributor I
28 Views

Thanks dsl, I will take some time to uderstand objdump. 

At first I'm interested in memory occupation to be sure I can fit in on-chip memories, then I would like to investigate which optimization can be done.
Altera_Forum
Honored Contributor I
28 Views

Assuming that the sections fit statically you should still evaluate if there is enough room for the stack and heap which grow and shrink at run time. I try to avoid using the heap if I can when possible (malloc allocates memory from the heap for example) since it's pretty difficult to determine what the maximum memory utilization is during run time. 

 

If the stack or heap grow too much they'll collide and corrupt eachother. There are tests you can do to detect these like pre-populating your memory with 0xdeadbeef for example, running your code, then inspecting the memory to see if that pattern is still present where the heap and stack are located. If the pattern doesn't appear then the stack and heap either collided or touched. This test isn't perfect since it assumes during the run time of your code it reached it's maximum memory utilization which might not be true depending on outside factors. 

 

If you want to reduce your code footprint, take a look at the hello_world_small software template. It'll show you a limited stdio library and optimizations you can use.
Altera_Forum
Honored Contributor I
28 Views

If you need to fit code into internal memory, it is probably best to avoid as much of libc as possible. The hello_world_small template does some of that - but, IIRC, it still has sizable chunks of libc code. 

 

If you can remove all references to malloc() and free() things will be much safer! but that may require you write your own startup code (about 4 instructions!) and may stop you using any of the jtag uart functions or most of the Altera hardware drivers.