http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51846
Bug #: 51846 Summary: Compiled programs suffer from infinite recursion when using -finstrument-functions with optimizations Classification: Unclassified Product: gcc Version: 4.5.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: dan...@totalueberwachung.de Created attachment 26313 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26313 Testcase While trying to debug a different issue I've been having with instrumentation I've run into this problem. It seems that with any sort of optimization enabled the compiler doesn't obey the no_instrument_function attribute. Attached is a small testcase. The output I get when compiling with and without optimization or instrumentation is this: $ gcc -O0 -o main main.c $ ./main Start End $ gcc -Os -o main main.c $ ./main Start End $ gcc -Os -finstrument-functions -o main main.c $ ./main Segmentation fault $ gcc -O0 -finstrument-functions -o main main.c $ ./main -> 0x400674 0x7fcbd75eb09d Start -> 0x400652 0x4006a1 <- 0x400652 0x4006a1 End <- 0x400674 0x7fcbd75eb09d Attached to a debugger or when looking at the assembly you can easily see that the __cyg_profile_func_enter function has a call to itself when compiled with any optimization setting other than O0.