Hi
I was just wondering what optimisation level in GCC you compile your OSs with.
With what I have so far, I don't have any. Is it unsafe to use optinisation levels when still developing the kernel, driver etc etc in the first place.
srg
GCC Optimisations
Re:GCC Optimisations
Optimizations should never break anything. Increasing optimization levels are not more risky, they usually just trade off more space for less execution time.
Higher optimization levels also tend to confuse debuggers, but unless you provide remote-gdb-stubs, that isn't an issue in kernel land.
Also note that not setting optimization levels explicitly simply tells gcc to use *default* optimizations.
Generally, -O2 is considered to be a "sane" setting. What that implies has changed significantly in recent GCC versions.
Higher optimization levels also tend to confuse debuggers, but unless you provide remote-gdb-stubs, that isn't an issue in kernel land.
Also note that not setting optimization levels explicitly simply tells gcc to use *default* optimizations.
Generally, -O2 is considered to be a "sane" setting. What that implies has changed significantly in recent GCC versions.
Every good solution is obvious once you've found it.
Re:GCC Optimisations
Well, with my new configure system you just specify it yourself. Min is -O1 (so it at least inlines the inline funcs, otherwise it screws that up & produces multiple outputs) and max is -O3, although I usually run with -O2. O2 outputs the most readable code imo.srg wrote: Hi
I was just wondering what optimisation level in GCC you compile your OSs with.
With what I have so far, I don't have any. Is it unsafe to use optinisation levels when still developing the kernel, driver etc etc in the first place.
srg
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC Optimisations
i personnally use -O3 or -O2 to enforce small functions inlining. The reason why people generally don't want to debug optimized code is because debuggers like GDB will be completely confused if some variable have been moved to registers, etc.
But since GDB will be of little use for debugging your kernel anyway, you could enable optimizations right from the start
But since GDB will be of little use for debugging your kernel anyway, you could enable optimizations right from the start
Re:GCC Optimisations
I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
GCC is 3.2.2
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC Optimisations
maybe needing volatiles here and there ?Neur0m'ancer wrote: I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
Re:GCC Optimisations
while it may work, this is generally not a good thing to have in your code. I have seen code that breaks aliasing rules do things like that. (for example, taking an unsigned short and casting it to a char * so you can get the hi/low byte..clever, but technically the compiler is allowed to output garbage for that).I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
I would compile with as many warnings enabled as possible to find that. (-W -Wall for starters)
proxy
Re:GCC Optimisations
That's -Wextra for later versions of GCC; -W is deprecated if memory serves.
You might also consider adding -Werror, so that you do not fall into the trap of thinking "ah, it's just a warning".
You might also consider adding -Werror, so that you do not fall into the trap of thinking "ah, it's just a warning".
Every good solution is obvious once you've found it.