View Single Post
  #6   (View Single Post)  
Old 9th June 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

TerryP, the OP indicates that the code compiles & executes as expected without specifying -O, but when compiler optimizations are used, execution is going into the weeds as described.

Compiler optimizations incorporate very aggressive algorithms which attempt to reduce code size & execution time of the resulting binary. Techniques such as peephole optimization attempts to substitute more efficient instructions for patterns detected in the machine code generated. Unfortunately, such algorithms can lose context which may result in errant substitutions being made. The segmentation fault mentioned by the OP can be due to an incorrect table entry being referenced, be it a one-off addressing issue or the fact that a table is now being flushed earlier than what was used without optimizations being turned on. Without code, all we can do is guess.

It should be mentioned that some less aggressive optimization techniques are already incorporated into most compilers even when optimizations are not specified. These more conservative methods have been vetted for a long time & are deemed "safe". Harsher algorithms can be specified, but with them comes greater assumptions & more instability. Compiler vendors make them available as knobs to adjust, but they are available as additional switches for a reason.
Reply With Quote