On OS X, when building the ASan runtime with COMPILER_RT_DEBUG=On (i.e. with -O0 and -g), there is a test failure in Posix/ioctl.cc test. When the ioctl interceptor generates a report, the test expects to find a stack frame with main and line 17 in the backtrace. In the optimized runtime (-O3), this works fine, and the backtrace looks like:
READ of size 4 at 0xbff398f4 thread T0 #0 0xe7e47 in wrap_ioctl (.../libclang_rt.asan_osx_dynamic.dylib+0x1ae47) #1 0xc7b06 in main .../asan/TestCases/Posix/ioctl.cc:17:13 #2 0x955936d8 in start (/usr/lib/system/libdyld.dylib+0x36d8)
However, with COMPILER_RT_DEBUG=On we get:
READ of size 4 at 0xbff44914 thread T0 #0 0xf73bf in ioctl_common_pre (.../libclang_rt.asan_osx_dynamic.dylib+0x383bf) #1 0xf69e6 in wrap_ioctl (.../libclang_rt.asan_osx_dynamic.dylib+0x379e6) #2 0x955936d8 in start (/usr/lib/system/libdyld.dylib+0x36d8)
This is because we still build with -fomit-frame-pointer and wrap_ioctl doesn't set up a proper stack frame. The reason why the optimized build works is because ioctl_common_pre gets inlined into wrap_ioctl and it uses the COMMON_INTERCEPTOR_READ_RANGE macro which in the end calls GET_CURRENT_FRAME and that forces the compiler to generate a stack frame for the function.
This patch tries to fix this with an easy solution that just adds ENABLE_FRAME_POINTER into the ioctl interceptor. However, it looks to me that we should make all interceptors have frames pointers, regardless of the optimization level. This should not affect performance, because in the optimized build, they are already forced to have stack frame pointers.