Question

I have some code that is being compiled with GCC for a micro. I noticed that when compiling the debug build, the system works just fine. But when I compile the release build, the system does not boot up.

After working on the issue for awhile, I narrowed down the problem to one function where if I specify a lesser optimization level (-O0 instead of -Os), the system will boot up just fine in the release build. So there is presumably a flag that -Os sets that is causing the code in that particular function to not work.

I had planned to track down the underlying issue by taking all the flags that -Os sets, and finding the one that causes the system not to boot.

I was trying to do the following:

__attribute__ ((optimize("-fauto-inc-dec", "-fcompare-elim", "-fcprop-registers", "-fdce", "-fdefer-pop", "-fdelayed-branch", "-fdse", "-fguess-branch-probability", "-fif-conversion2", "-fif-conversion", "-fipa-pure-const", "-fipa-profile", "-fipa-reference", "-fmerge-constants", "-fsplit-wide-types", "-ftree-bit-ccp", "-ftree-builtin-call-dce", "-ftree-ccp", "-ftree-ch", "-ftree-copyrename", "-ftree-dce", "-ftree-dominator-opts", "-ftree-dse", "-ftree-forwprop", "-ftree-fre", "-ftree-phiprop", "-ftree-sra", "-ftree-pta", "-ftree-ter", "-funit-at-a-time")))

and then eliminate flags until the system would boot. The problem is, is that I kept narrowing it down and narrowing it down, until I discovered that I can't get even set a single flag and get the system to boot.

So now I'm thinking that I'm doing something wrong with the way that I'm setting the optimization. If I put in a superfluous non-existent flag somewhere in the middle of those flags, like -fiam-fake-flag, the compiler detects it and spits out an error (which at first made me feel like I was setting these flags correctly).

I don't want to use pragma, because:

" Each function that is defined after this point is as if attribute((optimize("STRING"))) was specified for that function. "

and I only want the optimization on this one function so I can narrow down the problem.

So, am I setting these flags incorrectly? Is there a better way to specify a whole bunch of compiler flags for only 1 specific function?

If it weren't going on a micro, I could just specify all the flags I want in the Makefile and apply it to all functions, but doing so makes the program too big to fit on the micro.

Was it helpful?

Solution

Is your flag declared as volatile? Try posting the problematic function. – egur

that is TOTALLY what it was. Thank you, egur. – Mike Gibson

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top