2

I have a C program (hey, I'm cheating here, its generated C code) that crashes (segmentation fault) whenever I compile it with gcc -O2 optimization flag. (gcc 4.6.0)

Do you have an idea how I could debug this?

I think I could test by removing the optimizations one by one to see which one makes my program crash ... but this could potentially take a long time. Do you have any better idea?

The optimization that causes the problem is -fstrict-overflow. I'll continue to put new information as I have them.

Thanks

Mildred
  • 3,887
  • 4
  • 36
  • 44
  • 2
    A lot of double underscores in that code - is gcc OK with that? http://stackoverflow.com/questions/1449181/what-does-double-underscore-const-mean-in-c/1449301#1449301 – paperjam Apr 26 '11 at 10:16
  • 1
    Auhm, it's a 247 *thousand* lines of program you're asking us to look into. I would suggest that you try to cut it down to, say, 10 or 20 lines, then it would be possible to see if it's a compiler problem or if the program is broken. – Lindydancer Apr 27 '11 at 12:38

1 Answers1

0

There are some recent reports of compiler issues with that flag (e.g. http://lists.debian.org/debian-gcc/2009/07/msg00168.html) - it would be worth compiling with the latest GCC (or some other compiler if possible) and seeing if that resolves the issue. You could also run with debug symbols, under the debugger if helpful, and see where it crashes. If that surrounding code is clearly bullet proof then that's even more reason to suspect the compiler, otherwise you've somewhere to start your investigations.

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252