Home > OS >  How to keep stack frame right in ARM with GNU -Os?
How to keep stack frame right in ARM with GNU -Os?

Time:01-23

I am building and running an application with arm-linux-gnueabi-gcc, and I am testing a stack backtrace function in Linux.
Then I found if the application is built with -Os option, the stack backtrace does NOT work as expected. Without -Os, it can show the backtrace well.

I want to keep the compiled code as small as possible, but still need the stack backtrace to work as expected. So which GCC option(s) should I use to achieve this?

I referred to GCC optimization options at GCC optimization options , as it says the -Os includes options of -O1 and -O2 (excludes 7 options). I worked out a BASH script to add those options one by one to GCC compiling, and check backtrace results, but I did NOT find which option causes the error, did I miss something in -Os of GCC?

CodePudding user response:

I think I found the cause of problem.
With GCC -O1, the backtrace does NOT work as expected, and by adding -fno-inline the problem can be fixed.
With GCC -Os, adding -fno-inline can NOT work well. Instead, -fkeep-static-functions can help backtrace working well in this case.

So -fkeep-static-functions is the key option in this case to both make backtrace work and keep execution size as small as possible.

  • Related