This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix the ASan ioctl.cc test when using COMPILER_RT_DEBUG=On
ClosedPublic

Authored by kubamracek on Feb 22 2015, 5:36 AM.

Details

Reviewers
samsonov
Summary

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.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 20475.Feb 22 2015, 5:36 AM
kubamracek retitled this revision from to [compiler-rt] Fix the ASan ioctl.cc test when using COMPILER_RT_DEBUG=On.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added subscribers: Unknown Object (MLST), zaks.anna, kcc and 2 others.
samsonov accepted this revision.Feb 23 2015, 11:55 AM
samsonov added a reviewer: samsonov.

LGTM. Please add a comment that we need frame pointer in ioctl interceptor to be able to unwind through it, and we might not have frame pointer in debug mode on Mac.

This revision is now accepted and ready to land.Feb 23 2015, 11:55 AM
kubamracek closed this revision.Feb 24 2015, 2:14 AM

Landed in r230318.