[asan] adding support of 32-bit address sanitizer for MIPS

Summary: The patch supports both the clang cross-compiler and native compiler

Patch by Kumar Sukhani <Kumar.Sukhani@imgtec.com>

Test Plan:
Kumar had the following asan test results when compiled on a MIPS board:

  Expected Passes    : 96
  Expected Failures  : 2
  Unsupported Tests  : 84
  Unexpected Passes  : 4
  Unexpected Failures: 19

The list of unexpected failures can be found in the review.

Reviewers: kcc, petarj, dsanders

Reviewed By: kcc

Subscribers: farazs, kcc, llvm-commits

Differential Revision: http://reviews.llvm.org/D4208

llvm-svn: 211587
This commit is contained in:
Daniel Sanders 2014-06-24 12:08:18 +00:00
parent 6ea28bdef5
commit 4dc8a78b04
5 changed files with 56 additions and 11 deletions

View File

@ -226,6 +226,8 @@ else()
test_target_arch(i386 ${TARGET_32_BIT_CFLAGS})
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
test_target_arch(powerpc64 ${TARGET_64_BIT_CFLAGS})
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
test_target_arch(mips "")
endif()
# Build ARM libraries if we are configured to test on ARM
@ -362,8 +364,8 @@ endif()
# Architectures supported by Sanitizer runtimes. Specific sanitizers may
# support only subset of these (e.g. TSan works on x86_64 only).
filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
x86_64 i386 powerpc64 arm aarch64)
filter_available_targets(ASAN_SUPPORTED_ARCH x86_64 i386 powerpc64 arm)
x86_64 i386 powerpc64 arm aarch64 mips)
filter_available_targets(ASAN_SUPPORTED_ARCH x86_64 i386 powerpc64 arm mips)
filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
filter_available_targets(MSAN_SUPPORTED_ARCH x86_64)

View File

@ -19,7 +19,7 @@ set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# The common files need to build on every arch supported by ASan.
# (Even if they build into dummy object files.)
filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
x86_64 i386 powerpc64 arm aarch64)
x86_64 i386 powerpc64 arm aarch64 mips)
add_custom_target(lsan)

View File

@ -29,7 +29,7 @@
// are not defined anywhere in userspace headers. Fake them. This seems to work
// fine with newer headers, too.
#include <asm/posix_types.h>
#if defined(__x86_64__)
#if defined(__x86_64__) || defined(__mips__)
#include <sys/stat.h>
#else
#define ino_t __kernel_ino_t
@ -64,7 +64,8 @@ namespace __sanitizer {
unsigned struct_statfs64_sz = sizeof(struct statfs64);
} // namespace __sanitizer
#if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)
#if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
&& !defined(__mips__)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif

View File

@ -67,6 +67,13 @@ namespace __sanitizer {
#elif defined(__powerpc64__)
const unsigned struct_kernel_stat_sz = 144;
const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__mips__)
#if SANITIZER_WORDSIZE == 64
const unsigned struct_kernel_stat_sz = 216;
#else
const unsigned struct_kernel_stat_sz = 144;
#endif
const unsigned struct_kernel_stat64_sz = 104;
#endif
struct __sanitizer_perf_event_attr {
unsigned type;
@ -162,6 +169,12 @@ namespace __sanitizer {
unsigned __seq;
u64 __unused1;
u64 __unused2;
#elif defined(__mips__)
unsigned int mode;
unsigned short __seq;
unsigned short __pad1;
unsigned long __unused1;
unsigned long __unused2;
#else
unsigned short mode;
unsigned short __pad1;
@ -190,15 +203,15 @@ namespace __sanitizer {
u64 shm_ctime;
#else
uptr shm_atime;
#ifndef _LP64
#if !defined(_LP64) && !defined(__mips__)
uptr __unused1;
#endif
uptr shm_dtime;
#ifndef _LP64
#if !defined(_LP64) && !defined(__mips__)
uptr __unused2;
#endif
uptr shm_ctime;
#ifndef _LP64
#if !defined(_LP64) && !defined(__mips__)
uptr __unused3;
#endif
#endif
@ -445,7 +458,8 @@ namespace __sanitizer {
#endif
#if SANITIZER_LINUX || SANITIZER_FREEBSD
#if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)
#if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)\
|| defined(__mips__)
typedef unsigned __sanitizer___kernel_uid_t;
typedef unsigned __sanitizer___kernel_gid_t;
#else
@ -458,7 +472,7 @@ namespace __sanitizer {
typedef long __sanitizer___kernel_off_t;
#endif
#if defined(__powerpc__) || defined(__aarch64__)
#if defined(__powerpc__) || defined(__aarch64__) || defined(__mips__)
typedef unsigned int __sanitizer___kernel_old_uid_t;
typedef unsigned int __sanitizer___kernel_old_gid_t;
#else
@ -498,6 +512,9 @@ namespace __sanitizer {
// Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
struct __sanitizer_sigaction {
#if defined(__mips__) && !SANITIZER_FREEBSD
unsigned int sa_flags;
#endif
union {
void (*sigaction)(int sig, void *siginfo, void *uctx);
void (*handler)(int sig);
@ -507,10 +524,15 @@ namespace __sanitizer {
__sanitizer_sigset_t sa_mask;
#else
__sanitizer_sigset_t sa_mask;
#ifndef __mips__
int sa_flags;
#endif
#endif
#if SANITIZER_LINUX
void (*sa_restorer)();
#endif
#if defined(__mips__) && (SANITIZER_WORDSIZE == 32)
int sa_resv[1];
#endif
};
@ -725,7 +747,7 @@ struct __sanitizer_obstack {
#define IOC_NRBITS 8
#define IOC_TYPEBITS 8
#if defined(__powerpc__) || defined(__powerpc64__)
#if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__)
#define IOC_SIZEBITS 13
#define IOC_DIRBITS 3
#define IOC_NONE 1U

View File

@ -90,6 +90,26 @@ if(CAN_TARGET_i386)
endif()
endif()
if(CAN_TARGET_mips)
set(ASAN_TEST_CONFIG_SUFFIX "32")
set(ASAN_TEST_BITS "32")
set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
set(ASAN_TEST_DYNAMIC False)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
)
list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
if(COMPILER_RT_BUILD_SHARED_ASAN)
set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
set(ASAN_TEST_DYNAMIC True)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
endif()
endif()
if(COMPILER_RT_INCLUDE_TESTS)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in