[compiler-rt] r174593 - [sanitizer] Fix wrong size of OFF_T on 32-bit platforms.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Wed Feb 6 23:37:12 PST 2013


Author: eugenis
Date: Thu Feb  7 01:37:12 2013
New Revision: 174593

URL: http://llvm.org/viewvc/llvm-project?rev=174593&view=rev
Log:
[sanitizer] Fix wrong size of OFF_T on 32-bit platforms.

This broke pread/pwrite interceptors when building without
-D_FILE_OFFSET_BITS=64, and always on Android.

Added:
    compiler-rt/trunk/lib/interception/interception_type_test.cc   (with props)
Modified:
    compiler-rt/trunk/lib/interception/CMakeLists.txt
    compiler-rt/trunk/lib/interception/interception.h

Modified: compiler-rt/trunk/lib/interception/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=174593&r1=174592&r2=174593&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/interception/CMakeLists.txt Thu Feb  7 01:37:12 2013
@@ -4,6 +4,7 @@ set(INTERCEPTION_SOURCES
   interception_linux.cc
   interception_mac.cc
   interception_win.cc
+  interception_type_test.cc
   )
 
 include_directories(..)

Modified: compiler-rt/trunk/lib/interception/interception.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception.h?rev=174593&r1=174592&r2=174593&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception.h (original)
+++ compiler-rt/trunk/lib/interception/interception.h Thu Feb  7 01:37:12 2013
@@ -27,7 +27,10 @@ typedef __sanitizer::uptr SIZE_T;
 typedef __sanitizer::sptr SSIZE_T;
 typedef __sanitizer::sptr PTRDIFF_T;
 typedef __sanitizer::s64  INTMAX_T;
-typedef __sanitizer::u64  OFF_T;
+// WARNING: OFF_T may be different from OS type off_t, depending on the value of
+// _FILE_OFFSET_BITS. This definition of OFF_T matches the ABI of system calls
+// like pread and mmap, as opposed to pread64 and mmap64.
+typedef __sanitizer::uptr OFF_T;
 typedef __sanitizer::u64  OFF64_T;
 
 // How to add an interceptor:

Added: compiler-rt/trunk/lib/interception/interception_type_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_type_test.cc?rev=174593&view=auto
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_type_test.cc (added)
+++ compiler-rt/trunk/lib/interception/interception_type_test.cc Thu Feb  7 01:37:12 2013
@@ -0,0 +1,34 @@
+//===-- interception_type_test.cc -------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Compile-time tests of the internal type definitions.
+//===----------------------------------------------------------------------===//
+
+#if defined(__linux__) || defined(__APPLE__)
+
+#include "interception.h"
+#include <sys/types.h>
+
+COMPILER_CHECK(sizeof(SIZE_T) == sizeof(size_t));
+COMPILER_CHECK(sizeof(SSIZE_T) == sizeof(ssize_t));
+COMPILER_CHECK(sizeof(PTRDIFF_T) == sizeof(ptrdiff_t));
+COMPILER_CHECK(sizeof(INTMAX_T) == sizeof(intmax_t));
+COMPILER_CHECK(sizeof(OFF64_T) == sizeof(off64_t));
+
+// The following are the cases when pread (and friends) is used instead of
+// pread64. In those cases we need OFF_T to match off_t. We don't care about the
+// rest (they depend on _FILE_OFFSET_BITS setting when building an application).
+# if defined(__ANDROID__) || !defined _FILE_OFFSET_BITS || \
+  _FILE_OFFSET_BITS != 64
+COMPILER_CHECK(sizeof(OFF_T) == sizeof(off_t));
+# endif
+
+#endif

Propchange: compiler-rt/trunk/lib/interception/interception_type_test.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list