Hi There
I'm in the process of debugging some of my code, which I discovered works sometimes it is compiled and other times it doesn't. Anyway, I got side tracked and experimented with gcc optimizations on my kernel. Using GCC 4.1, -O worked fine, -O2 and -O3 the keyboard stopped working. So I am wondering, when optimizations break my code does that mean that there is some bug I haven't discovered yet in my code, or it is optimizing something it shouldn't and I shouldn't play with optimizations in the first place?
Andrew
GCC Optimzations
Re:GCC Optimzations
Generally, GCC is very well-tested. Actually, it is better tested with optimizations than without.
Chances you did soemthing fishy in your code: 99.5%
Chances GCC optimization broke: 0.5%
My first guess would be you forgot "volatile" in important places, or did some strange polling things that GCC optimized away.
Chances you did soemthing fishy in your code: 99.5%
Chances GCC optimization broke: 0.5%
My first guess would be you forgot "volatile" in important places, or did some strange polling things that GCC optimized away.
Every good solution is obvious once you've found it.
- spix
- Member
- Posts: 128
- Joined: Mon Jun 26, 2006 8:41 am
- Location: Millicent, South Australia
- Contact:
Re:GCC Optimzations
Thanks for that, you're probably right with the volatile, I've missed those in the past.
I was wondering about the optimizations because sometimes I've read posts on other boards with regards to linux and how compiling with too much optimizations can be bad - I think it was a gentoo forum, and also there was a lot of code that needed to be fixed to work in gcc 4.0 when it came out.
I guess I was wondering mostly because, I can use this as a debugging tool, if it breaks with some optimization but usually works, there must be a hidden bug.
Anyway, thanks for that
Andrew
I was wondering about the optimizations because sometimes I've read posts on other boards with regards to linux and how compiling with too much optimizations can be bad - I think it was a gentoo forum, and also there was a lot of code that needed to be fixed to work in gcc 4.0 when it came out.
I guess I was wondering mostly because, I can use this as a debugging tool, if it breaks with some optimization but usually works, there must be a hidden bug.
Anyway, thanks for that
Andrew
Re:GCC Optimzations
Correct. That is because most of the software available for Linux is pretty sh*tty. Gee, mommy, look at all those compiler warnings... needless to say, if your code is badly written, running an aggressive optimizer on it won't improve things.spix wrote: I was wondering about the optimizations because sometimes I've read posts on other boards with regards to linux and how compiling with too much optimizations can be bad - I think it was a gentoo forum, and also there was a lot of code that needed to be fixed to work in gcc 4.0 when it came out.
But that's not GCC's fault...
Start with enabling as many compiler warnings as you can find, and also do -Werror so you don't get lazy with warnings. Then make sure you understood the language details (like 'volatile'). The optimizer is about the last tool I would trust to find my bugs for me.I guess I was wondering mostly because, I can use this as a debugging tool, if it breaks with some optimization but usually works, there must be a hidden bug.
Every good solution is obvious once you've found it.