diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-02-07 07:37:12 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-02-07 07:37:12 +0000 |
commit | 8268785f44dd24968414504b7f8b88f16e2dd7f7 (patch) | |
tree | fa34fa0f1a5086235c21eb82db2b7ceba713427c /compiler-rt/lib/interception | |
parent | ac4f444e399089b1496c783ea2bd93f09a097f4a (diff) | |
download | bcm5719-llvm-8268785f44dd24968414504b7f8b88f16e2dd7f7.tar.gz bcm5719-llvm-8268785f44dd24968414504b7f8b88f16e2dd7f7.zip |
[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.
llvm-svn: 174593
Diffstat (limited to 'compiler-rt/lib/interception')
-rw-r--r-- | compiler-rt/lib/interception/CMakeLists.txt | 1 | ||||
-rw-r--r-- | compiler-rt/lib/interception/interception.h | 5 | ||||
-rw-r--r-- | compiler-rt/lib/interception/interception_type_test.cc | 34 |
3 files changed, 39 insertions, 1 deletions
diff --git a/compiler-rt/lib/interception/CMakeLists.txt b/compiler-rt/lib/interception/CMakeLists.txt index 9d60932c5d6..cd9e6e75504 100644 --- a/compiler-rt/lib/interception/CMakeLists.txt +++ b/compiler-rt/lib/interception/CMakeLists.txt @@ -4,6 +4,7 @@ set(INTERCEPTION_SOURCES interception_linux.cc interception_mac.cc interception_win.cc + interception_type_test.cc ) include_directories(..) diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h index ccebf14c167..c8a0543dcb6 100644 --- a/compiler-rt/lib/interception/interception.h +++ b/compiler-rt/lib/interception/interception.h @@ -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: diff --git a/compiler-rt/lib/interception/interception_type_test.cc b/compiler-rt/lib/interception/interception_type_test.cc new file mode 100644 index 00000000000..c26df4f411d --- /dev/null +++ b/compiler-rt/lib/interception/interception_type_test.cc @@ -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 |