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

Kuba Brecka kuba.brecka at gmail.com
Sun Feb 22 05:36:35 PST 2015


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.

http://reviews.llvm.org/D7815

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc

Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1029,6 +1029,8 @@
 #if SANITIZER_INTERCEPT_IOCTL
 #include "sanitizer_common_interceptors_ioctl.inc"
 INTERCEPTOR(int, ioctl, int d, unsigned long request, ...) {
+  ENABLE_FRAME_POINTER;
+
   void *ctx;
   va_list ap;
   va_start(ap, request);

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7815.20475.patch
Type: text/x-patch
Size: 497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150222/8e99ad61/attachment.bin>


More information about the llvm-commits mailing list