From 8268785f44dd24968414504b7f8b88f16e2dd7f7 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 7 Feb 2013 07:37:12 +0000 Subject: [PATCH] [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 --- compiler-rt/lib/interception/CMakeLists.txt | 1 + compiler-rt/lib/interception/interception.h | 5 +++- .../lib/interception/interception_type_test.cc | 34 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 compiler-rt/lib/interception/interception_type_test.cc diff --git a/compiler-rt/lib/interception/CMakeLists.txt b/compiler-rt/lib/interception/CMakeLists.txt index 9d60932..cd9e6e7 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 ccebf14..c8a0543 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 0000000..c26df4f --- /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 + +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 -- 2.7.4