forked from OSchip/llvm-project
Adding Msan support to FreeBSD
Summary: Enabling the memory sanitizer support for FreeBSD, most of unit tests are compatible. - Adding fstat and stressor_r interceptors. - Updating the struct link_map access since most likely the struct Obj_Entry had been updated since. - Disabling few unit tests until further work is needed (or we can assume it can work in real world code). Patch by: David CARLIER Reviewers: vitalybuka, krytarowski Reviewed By: vitalybuka Subscribers: eugenis, dim, srhines, emaste, kubamracek, mgorny, fedor.sergeev, hintonda, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D43080 llvm-svn: 326644
This commit is contained in:
parent
a8f7cc8ec9
commit
3d7fbb052f
|
@ -530,7 +530,7 @@ else()
|
|||
endif()
|
||||
|
||||
if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
|
||||
OS_NAME MATCHES "Linux|NetBSD")
|
||||
OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
|
||||
set(COMPILER_RT_HAS_MSAN TRUE)
|
||||
else()
|
||||
set(COMPILER_RT_HAS_MSAN FALSE)
|
||||
|
|
|
@ -17,8 +17,11 @@ set(MSAN_RTL_CXX_SOURCES
|
|||
|
||||
|
||||
set(MSAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
||||
append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC -ftls-model=initial-exec MSAN_RTL_CFLAGS)
|
||||
append_rtti_flag(OFF MSAN_RTL_CFLAGS)
|
||||
append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE MSAN_RTL_CFLAGS)
|
||||
if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE MSAN_RTL_CFLAGS)
|
||||
endif()
|
||||
# Prevent clang from generating libc calls.
|
||||
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding MSAN_RTL_CFLAGS)
|
||||
|
||||
|
|
|
@ -681,7 +681,7 @@ INTERCEPTOR(int, putenv, char *string) {
|
|||
return res;
|
||||
}
|
||||
|
||||
#if SANITIZER_NETBSD
|
||||
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
|
||||
INTERCEPTOR(int, fstat, int fd, void *buf) {
|
||||
ENSURE_MSAN_INITED();
|
||||
int res = REAL(fstat)(fd, buf);
|
||||
|
|
|
@ -3590,7 +3590,7 @@ INTERCEPTOR(char *, strerror, int errnum) {
|
|||
// * GNU version returns message pointer, which points to either buf or some
|
||||
// static storage.
|
||||
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || \
|
||||
SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD
|
||||
SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD || SANITIZER_FREEBSD
|
||||
// POSIX version. Spec is not clear on whether buf is NULL-terminated.
|
||||
// At least on OSX, buf contents are valid even when the call fails.
|
||||
INTERCEPTOR(int, strerror_r, int errnum, char *buf, SIZE_T buflen) {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
|
||||
// incorporates the map structure.
|
||||
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
|
||||
((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
|
||||
((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 560)))
|
||||
// Get sys/_types.h, because that tells us whether 64-bit inodes are
|
||||
// used in struct dirent below.
|
||||
#include <sys/_types.h>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
Regression test for a bug in msan/glibc integration,
|
||||
see https://sourceware.org/bugzilla/show_bug.cgi?id=16291
|
||||
and https://github.com/google/sanitizers/issues/547
|
||||
|
||||
XFAIL: freebsd
|
||||
*/
|
||||
|
||||
#ifndef BUILD_SO
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
|
||||
|
||||
#ifndef __FreeBSD__
|
||||
#include <utmp.h>
|
||||
#endif
|
||||
#include <utmpx.h>
|
||||
#include <sanitizer/msan_interface.h>
|
||||
|
||||
int main(void) {
|
||||
#ifndef __FreeBSD__
|
||||
setutent();
|
||||
while (struct utmp *ut = getutent())
|
||||
__msan_check_mem_is_initialized(ut, sizeof(*ut));
|
||||
endutent();
|
||||
#endif
|
||||
|
||||
setutxent();
|
||||
while (struct utmpx *utx = getutxent())
|
||||
|
|
|
@ -15,7 +15,7 @@ int main(void) {
|
|||
char inbuf_[100];
|
||||
strcpy(inbuf_, "sample text");
|
||||
char outbuf_[100];
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
#if defined(__NetBSD__)
|
||||
// Some OSes expect the 2nd argument of iconv(3) to be of type const char **
|
||||
const char *inbuf = inbuf_;
|
||||
#else
|
||||
|
|
|
@ -29,7 +29,7 @@ config.substitutions.append( ("%clangxx_msan ", build_invocation(clang_msan_cxxf
|
|||
# Default test suffixes.
|
||||
config.suffixes = ['.c', '.cc', '.cpp']
|
||||
|
||||
if config.host_os not in ['Linux', 'NetBSD']:
|
||||
if config.host_os not in ['Linux', 'NetBSD', 'FreeBSD']:
|
||||
config.unsupported = True
|
||||
|
||||
# For mips64, mips64el we have forced store_context_size to 1 because these
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t
|
||||
|
||||
// Regression test for a deadlock in pthread_getattr_np
|
||||
// UNSUPPORTED: freebsd
|
||||
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t psm1 2>&1 | FileCheck %s
|
||||
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 %run %t psm1 2>&1
|
||||
|
||||
// pvalloc is Linux only
|
||||
// UNSUPPORTED: win32, freebsd, netbsd
|
||||
|
||||
// Checks that pvalloc overflows are caught. If the allocator is allowed to
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
// Check that strlen() and similar intercepted functions can be called on shadow
|
||||
// memory.
|
||||
// The mem_to_shadow's part might need rework
|
||||
// XFAIL: freebsd
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
|
||||
// textdomain() is not a part of libc on FreeBSD and NetBSD.
|
||||
// UNSUPPORTED: netbsd, freebsd
|
||||
|
||||
#include <libintl.h>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
|
||||
|
||||
// Check that when TLS block is reused between threads, its shadow is cleaned.
|
||||
// XFAIL: freebsd
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
|
||||
|
||||
// tdestroy is a GNU extension
|
||||
// UNSUPPORTED: netbsd
|
||||
// UNSUPPORTED: netbsd, freebsd
|
||||
|
||||
#include <assert.h>
|
||||
#include <search.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
|
||||
// XFAIL: freebsd
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
Loading…
Reference in New Issue